* doc/autoconf.texi (Shellology): pdksh 5.2.14 is still the
[autoconf.git] / doc / autoconf.texi
blobf4db9d553643da5ea9560a1d1572b27c092dec47
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 @ifnothtml
9 @setcontentsaftertitlepage
10 @end ifnothtml
11 @finalout
13 @c @ovar(ARG, DEFAULT)
14 @c -------------------
15 @c The ARG is an optional argument.  To be used for macro arguments in
16 @c their documentation (@defmac).
17 @macro ovar{varname}
18 @r{[}@var{\varname\}@r{]}
19 @end macro
21 @c @dvar(ARG, DEFAULT)
22 @c -------------------
23 @c The ARG is an optional argument, defaulting to DEFAULT.  To be used
24 @c for macro arguments in their documentation (@defmac).
25 @macro dvar{varname, default}
26 @r{[}@var{\varname\} = @samp{\default\}@r{]}
27 @end macro
29 @c Handling the indexes with Texinfo yields several different problems.
31 @c Because we want to drop out the AC_ part of the macro names in the
32 @c printed manual, but not in the other outputs, we need a layer above
33 @c the usual @acindex{} etc.  That's why we first define indexes such as
34 @c acx meant to become the macro @acindex.  First of all, using ``ac_''
35 @c does not work with makeinfo, and using ``ac1'' doesn't work with TeX.
36 @c So use something more regular ``acx''.  Then you finish with a printed
37 @c index saying ``index is not existent''.  Of course: you ought to use
38 @c two letters :(  So you use capitals.
40 @c Second, when defining a macro in the TeX world, following spaces are
41 @c eaten.  But then, since we embed @acxindex commands that use the end
42 @c of line as an end marker, the whole things wrecks itself.  So make
43 @c sure you do *force* an additional end of line, add a ``@c''.
45 @c Finally, you might want to get rid of TeX expansion, using --expand
46 @c with texi2dvi.  But then you wake up an old problem: we use macros
47 @c in @defmac etc. where TeX does perform the expansion, but not makeinfo.
49 @c Define an environment variable index.
50 @defcodeindex ev
51 @c Define an output variable index.
52 @defcodeindex ov
53 @c Define a CPP variable index.
54 @defcodeindex cv
55 @c Define an Autoconf macro index that @defmac doesn't write to.
56 @defcodeindex AC
57 @c Define an Autotest macro index that @defmac doesn't write to.
58 @defcodeindex AT
59 @c Define an M4sugar macro index that @defmac doesn't write to.
60 @defcodeindex MS
61 @c Define an index for *foreign* programs: `mv' etc.  Used for the
62 @c portability sections and so on.
63 @defindex pr
65 @c shortindexflag
66 @c --------------
67 @c Shall we factor AC_ out of the Autoconf macro index etc.?
68 @iftex
69 @set shortindexflag
70 @end iftex
72 @c @acindex{MACRO}
73 @c ---------------
74 @c Registering an AC_\MACRO\.
75 @ifset shortindexflag
76 @macro acindex{macro}
77 @ACindex \macro\
79 @end macro
80 @end ifset
81 @ifclear shortindexflag
82 @macro acindex{macro}
83 @ACindex AC_\macro\
84 @end macro
85 @end ifclear
87 @c @ahindex{MACRO}
88 @c ---------------
89 @c Registering an AH_\MACRO\.
90 @macro ahindex{macro}
91 @ACindex AH_\macro\
93 @end macro
95 @c @asindex{MACRO}
96 @c ---------------
97 @c Registering an AS_\MACRO\.
98 @ifset shortindexflag
99 @macro asindex{macro}
100 @MSindex \macro\
102 @end macro
103 @end ifset
104 @ifclear shortindexflag
105 @macro asindex{macro}
106 @MSindex AS_\macro\
107 @end macro
108 @end ifclear
110 @c @atindex{MACRO}
111 @c ---------------
112 @c Registering an AT_\MACRO\.
113 @ifset shortindexflag
114 @macro atindex{macro}
115 @ATindex \macro\
117 @end macro
118 @end ifset
119 @ifclear shortindexflag
120 @macro atindex{macro}
121 @ATindex AT_\macro\
122 @end macro
123 @end ifclear
125 @c @auindex{MACRO}
126 @c ---------------
127 @c Registering an AU_\MACRO\.
128 @macro auindex{macro}
129 @ACindex AU_\macro\
131 @end macro
133 @c @hdrindex{MACRO}
134 @c ----------------
135 @c Indexing a header.
136 @macro hdrindex{macro}
137 @prindex @file{\macro\}
139 @end macro
141 @c @msindex{MACRO}
142 @c ---------------
143 @c Registering an m4_\MACRO\.
144 @ifset shortindexflag
145 @macro msindex{macro}
146 @MSindex \macro\
148 @end macro
149 @end ifset
150 @ifclear shortindexflag
151 @macro msindex{macro}
152 @MSindex m4_\macro\
153 @end macro
154 @end ifclear
157 @c Define an index for functions: `alloca' etc.  Used for the
158 @c portability sections and so on.  We can't use `fn' (aka `fnindex),
159 @c since `@defmac' goes into it => we'd get all the macros too.
161 @c   FIXME: Aaarg!  It seems there are too many indices for TeX :(
163 @c   ! No room for a new @write .
164 @c   l.112 @defcodeindex fu
166 @c   so don't define yet another one :(  Just put some tags before each
167 @c   @prindex which is actually a @funindex.
169 @c   @defcodeindex fu
172 @c   @c Put the programs and functions into their own index.
173 @c   @syncodeindex fu pr
175 @comment %**end of header
176 @comment ========================================================
178 @copying
180 This manual is for @acronym{GNU} Autoconf
181 (version @value{VERSION}, @value{UPDATED}),
182 a package for creating scripts to configure source code packages using
183 templates and an M4 macro package.
185 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
186 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
188 @quotation
189 Permission is granted to copy, distribute and/or modify this document
190 under the terms of the @acronym{GNU} Free Documentation License,
191 Version 1.2 or any later version published by the Free Software
192 Foundation; with no Invariant Sections, with the Front-Cover texts
193 being ``A @acronym{GNU} Manual,'' and with the Back-Cover Texts as in
194 (a) below.  A copy of the license is included in the section entitled
195 ``@acronym{GNU} Free Documentation License.''
197 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and
198 modify this @acronym{GNU} Manual, like @acronym{GNU} software.  Copies
199 published by the Free Software Foundation raise funds for
200 @acronym{GNU} development.''
201 @end quotation
202 @end copying
206 @dircategory Software development
207 @direntry
208 * Autoconf: (autoconf).         Create source code configuration scripts.
209 @end direntry
211 @dircategory Individual utilities
212 @direntry
213 * autoscan: (autoconf)autoscan Invocation.
214                                 Semi-automatic @file{configure.ac} writing
215 * ifnames: (autoconf)ifnames Invocation.        Listing conditionals in source.
216 * autoconf invocation: (autoconf)autoconf Invocation.
217                                 How to create configuration scripts
218 * autoreconf: (autoconf)autoreconf Invocation.
219                                 Remaking multiple @command{configure} scripts
220 * autoheader: (autoconf)autoheader Invocation.
221                                 How to create configuration templates
222 * autom4te: (autoconf)autom4te Invocation.
223                                 The Autoconf executables backbone
224 * configure: (autoconf)configure Invocation.    Configuring a package.
225 * autoupdate: (autoconf)autoupdate Invocation.
226                                 Automatic update of @file{configure.ac}
227 * config.status: (autoconf)config.status Invocation. Recreating configurations.
228 * testsuite: (autoconf)testsuite Invocation.    Running an Autotest test suite.
229 @end direntry
231 @titlepage
232 @title Autoconf
233 @subtitle Creating Automatic Configuration Scripts
234 @subtitle for version @value{VERSION}, @value{UPDATED}
235 @author David MacKenzie
236 @author Ben Elliston
237 @author Akim Demaille
238 @page
239 @vskip 0pt plus 1filll
240 @insertcopying
241 @end titlepage
243 @contents
246 @ifnottex
247 @node Top
248 @top Autoconf
249 @insertcopying
250 @end ifnottex
252 @c The master menu, created with texinfo-master-menu, goes here.
254 @menu
255 * Introduction::                Autoconf's purpose, strengths, and weaknesses
256 * The GNU Build System::        A set of tools for portable software packages
257 * Making configure Scripts::    How to organize and produce Autoconf scripts
258 * Setup::                       Initialization and output
259 * Existing Tests::              Macros that check for particular features
260 * Writing Tests::               How to write new feature checks
261 * Results::                     What to do with results from feature checks
262 * Programming in M4::           Layers on top of which Autoconf is written
263 * Writing Autoconf Macros::     Adding new macros to Autoconf
264 * Portable Shell::              Shell script portability pitfalls
265 * Portable Make::               Makefile portability pitfalls
266 * Portable C and C++::          C and C++ portability pitfalls
267 * Manual Configuration::        Selecting features that can't be guessed
268 * Site Configuration::          Local defaults for @command{configure}
269 * Running configure Scripts::   How to use the Autoconf output
270 * config.status Invocation::    Recreating a configuration
271 * Obsolete Constructs::         Kept for backward compatibility
272 * Using Autotest::              Creating portable test suites
273 * FAQ::                         Frequent Autoconf Questions, with answers
274 * History::                     History of Autoconf
275 * Copying This Manual::         How to make copies of this manual
276 * Indices::                     Indices of symbols, concepts, etc.
278 @detailmenu
279  --- The Detailed Node Listing ---
281 The @acronym{GNU} Build System
283 * Automake::                    Escaping makefile hell
284 * Gnulib::                      The @acronym{GNU} portability library
285 * Libtool::                     Building libraries portably
286 * Pointers::                    More info on the @acronym{GNU} build system
288 Making @command{configure} Scripts
290 * Writing Autoconf Input::      What to put in an Autoconf input file
291 * autoscan Invocation::         Semi-automatic @file{configure.ac} writing
292 * ifnames Invocation::          Listing the conditionals in source code
293 * autoconf Invocation::         How to create configuration scripts
294 * autoreconf Invocation::       Remaking multiple @command{configure} scripts
296 Writing @file{configure.ac}
298 * Shell Script Compiler::       Autoconf as solution of a problem
299 * Autoconf Language::           Programming in Autoconf
300 * Autoconf Input Layout::       Standard organization of @file{configure.ac}
302 Initialization and Output Files
304 * Initializing configure::      Option processing etc.
305 * Notices::                     Copyright, version numbers in @command{configure}
306 * Input::                       Where Autoconf should find files
307 * Output::                      Outputting results from the configuration
308 * Configuration Actions::       Preparing the output based on results
309 * Configuration Files::         Creating output files
310 * Makefile Substitutions::      Using output variables in makefiles
311 * Configuration Headers::       Creating a configuration header file
312 * Configuration Commands::      Running arbitrary instantiation commands
313 * Configuration Links::         Links depending on the configuration
314 * Subdirectories::              Configuring independent packages together
315 * Default Prefix::              Changing the default installation prefix
317 Substitutions in Makefiles
319 * Preset Output Variables::     Output variables that are always set
320 * Installation Directory Variables::  Other preset output variables
321 * Changed Directory Variables:: Warnings about @file{datarootdir}
322 * Build Directories::           Supporting multiple concurrent compiles
323 * Automatic Remaking::          Makefile rules for configuring
325 Configuration Header Files
327 * Header Templates::            Input for the configuration headers
328 * autoheader Invocation::       How to create configuration templates
329 * Autoheader Macros::           How to specify CPP templates
331 Existing Tests
333 * Common Behavior::             Macros' standard schemes
334 * Alternative Programs::        Selecting between alternative programs
335 * Files::                       Checking for the existence of files
336 * Libraries::                   Library archives that might be missing
337 * Library Functions::           C library functions that might be missing
338 * Header Files::                Header files that might be missing
339 * Declarations::                Declarations that may be missing
340 * Structures::                  Structures or members that might be missing
341 * Types::                       Types that might be missing
342 * Compilers and Preprocessors::  Checking for compiling programs
343 * System Services::             Operating system services
344 * Posix Variants::              Special kludges for specific Posix variants
345 * Erlang Libraries::            Checking for the existence of Erlang libraries
347 Common Behavior
349 * Standard Symbols::            Symbols defined by the macros
350 * Default Includes::            Includes used by the generic macros
352 Alternative Programs
354 * Particular Programs::         Special handling to find certain programs
355 * Generic Programs::            How to find other programs
357 Library Functions
359 * Function Portability::        Pitfalls with usual functions
360 * Particular Functions::        Special handling to find certain functions
361 * Generic Functions::           How to find other functions
363 Header Files
365 * Header Portability::          Collected knowledge on common headers
366 * Particular Headers::          Special handling to find certain headers
367 * Generic Headers::             How to find other headers
369 Declarations
371 * Particular Declarations::     Macros to check for certain declarations
372 * Generic Declarations::        How to find other declarations
374 Structures
376 * Particular Structures::       Macros to check for certain structure members
377 * Generic Structures::          How to find other structure members
379 Types
381 * Particular Types::            Special handling to find certain types
382 * Generic Types::               How to find other types
384 Compilers and Preprocessors
386 * Specific Compiler Characteristics::  Some portability issues
387 * Generic Compiler Characteristics::  Language independent tests and features
388 * C Compiler::                  Checking its characteristics
389 * C++ Compiler::                Likewise
390 * Objective C Compiler::        Likewise
391 * Erlang Compiler and Interpreter::  Likewise
392 * Fortran Compiler::            Likewise
394 Writing Tests
396 * Language Choice::             Selecting which language to use for testing
397 * Writing Test Programs::       Forging source files for compilers
398 * Running the Preprocessor::    Detecting preprocessor symbols
399 * Running the Compiler::        Detecting language or header features
400 * Running the Linker::          Detecting library features
401 * Runtime::                     Testing for runtime features
402 * Systemology::                 A zoology of operating systems
403 * Multiple Cases::              Tests for several possible values
405 Writing Test Programs
407 * Guidelines::                  General rules for writing test programs
408 * Test Functions::              Avoiding pitfalls in test programs
409 * Generating Sources::          Source program boilerplate
411 Results of Tests
413 * Defining Symbols::            Defining C preprocessor symbols
414 * Setting Output Variables::    Replacing variables in output files
415 * Special Chars in Variables::  Characters to beware of in variables
416 * Caching Results::             Speeding up subsequent @command{configure} runs
417 * Printing Messages::           Notifying @command{configure} users
419 Caching Results
421 * Cache Variable Names::        Shell variables used in caches
422 * Cache Files::                 Files @command{configure} uses for caching
423 * Cache Checkpointing::         Loading and saving the cache file
425 Programming in M4
427 * M4 Quotation::                Protecting macros from unwanted expansion
428 * Using autom4te::              The Autoconf executables backbone
429 * Programming in M4sugar::      Convenient pure M4 macros
430 * Programming in M4sh::         Common shell Constructs
431 * File Descriptor Macros::      File descriptor macros for input and output
433 M4 Quotation
435 * Active Characters::           Characters that change the behavior of M4
436 * One Macro Call::              Quotation and one macro call
437 * Quotation and Nested Macros::  Macros calling macros
438 * Changequote is Evil::         Worse than INTERCAL: M4 + changequote
439 * Quadrigraphs::                Another way to escape special characters
440 * Quotation Rule Of Thumb::     One parenthesis, one quote
442 Using @command{autom4te}
444 * autom4te Invocation::         A @acronym{GNU} M4 wrapper
445 * Customizing autom4te::        Customizing the Autoconf package
447 Programming in M4sugar
449 * Redefined M4 Macros::         M4 builtins changed in M4sugar
450 * Looping constructs::          Iteration in M4
451 * Evaluation Macros::           More quotation and evaluation control
452 * Text processing Macros::      String manipulation in M4
453 * Forbidden Patterns::          Catching unexpanded macros
455 Writing Autoconf Macros
457 * Macro Definitions::           Basic format of an Autoconf macro
458 * Macro Names::                 What to call your new macros
459 * Reporting Messages::          Notifying @command{autoconf} users
460 * Dependencies Between Macros::  What to do when macros depend on other macros
461 * Obsoleting Macros::           Warning about old ways of doing things
462 * Coding Style::                Writing Autoconf macros @`a la Autoconf
464 Dependencies Between Macros
466 * Prerequisite Macros::         Ensuring required information
467 * Suggested Ordering::          Warning about possible ordering problems
468 * One-Shot Macros::             Ensuring a macro is called only once
470 Portable Shell Programming
472 * Shellology::                  A zoology of shells
473 * Here-Documents::              Quirks and tricks
474 * File Descriptors::            FDs and redirections
475 * File System Conventions::     File names
476 * Shell Substitutions::         Variable and command expansions
477 * Assignments::                 Varying side effects of assignments
478 * Parentheses::                 Parentheses in shell scripts
479 * Slashes::                     Slashes in shell scripts
480 * Special Shell Variables::     Variables you should not change
481 * Limitations of Builtins::     Portable use of not so portable /bin/sh
482 * Limitations of Usual Tools::  Portable use of portable tools
484 Portable Make Programming
486 * $< in Ordinary Make Rules::   $< in ordinary rules
487 * Failure in Make Rules::       Failing portably in rules
488 * Special Chars in Names::      Special Characters in Macro Names
489 * Backslash-Newline-Newline::   Empty last lines in macro definitions
490 * Backslash-Newline Comments::  Spanning comments across line boundaries
491 * Long Lines in Makefiles::     Line length limitations
492 * Macros and Submakes::         @code{make macro=value} and submakes
493 * The Make Macro MAKEFLAGS::    @code{$(MAKEFLAGS)} portability issues
494 * The Make Macro SHELL::        @code{$(SHELL)} portability issues
495 * Comments in Make Rules::      Other problems with Make comments
496 * obj/ and Make::               Don't name a subdirectory @file{obj}
497 * make -k Status::              Exit status of @samp{make -k}
498 * VPATH and Make::              @code{VPATH} woes
499 * Single Suffix Rules::         Single suffix rules and separated dependencies
500 * Timestamps and Make::         Subsecond timestamp resolution
502 @code{VPATH} and Make
504 * VPATH and Double-colon::      Problems with @samp{::} on ancient hosts
505 * $< in Explicit Rules::        @code{$<} does not work in ordinary rules
506 * Automatic Rule Rewriting::    @code{VPATH} goes wild on Solaris
507 * Tru64 Directory Magic::       @command{mkdir} goes wild on Tru64
508 * Make Target Lookup::          More details about @code{VPATH} lookup
510 Portable C and C++ Programming
512 * Varieties of Unportability::  How to make your programs unportable
513 * Integer Overflow::            When integers get too large
514 * Null Pointers::               Properties of null pointers
515 * Buffer Overruns::             Subscript errors and the like
516 * Volatile Objects::            @code{volatile} and signals
517 * Floating Point Portability::  Portable floating-point arithmetic
518 * Exiting Portably::            Exiting and the exit status
520 Manual Configuration
522 * Specifying Names::            Specifying the system type
523 * Canonicalizing::              Getting the canonical system type
524 * Using System Type::           What to do with the system type
526 Site Configuration
528 * Help Formatting::             Customizing @samp{configure --help}
529 * External Software::           Working with other optional software
530 * Package Options::             Selecting optional features
531 * Pretty Help Strings::         Formatting help string
532 * Option Checking::             Controlling checking of @command{configure} options
533 * Site Details::                Configuring site details
534 * Transforming Names::          Changing program names when installing
535 * Site Defaults::               Giving @command{configure} local defaults
537 Transforming Program Names When Installing
539 * Transformation Options::      @command{configure} options to transform names
540 * Transformation Examples::     Sample uses of transforming names
541 * Transformation Rules::        Makefile uses of transforming names
543 Running @command{configure} Scripts
545 * Basic Installation::          Instructions for typical cases
546 * Compilers and Options::       Selecting compilers and optimization
547 * Multiple Architectures::      Compiling for multiple architectures at once
548 * Installation Names::          Installing in different directories
549 * Optional Features::           Selecting optional features
550 * System Type::                 Specifying the system type
551 * Sharing Defaults::            Setting site-wide defaults for @command{configure}
552 * Defining Variables::          Specifying the compiler etc.
553 * configure Invocation::        Changing how @command{configure} runs
555 Obsolete Constructs
557 * Obsolete config.status Use::  Obsolete convention for @command{config.status}
558 * acconfig Header::             Additional entries in @file{config.h.in}
559 * autoupdate Invocation::       Automatic update of @file{configure.ac}
560 * Obsolete Macros::             Backward compatibility macros
561 * Autoconf 1::                  Tips for upgrading your files
562 * Autoconf 2.13::               Some fresher tips
564 Upgrading From Version 1
566 * Changed File Names::          Files you might rename
567 * Changed Makefiles::           New things to put in @file{Makefile.in}
568 * Changed Macros::              Macro calls you might replace
569 * Changed Results::             Changes in how to check test results
570 * Changed Macro Writing::       Better ways to write your own macros
572 Upgrading From Version 2.13
574 * Changed Quotation::           Broken code which used to work
575 * New Macros::                  Interaction with foreign macros
576 * Hosts and Cross-Compilation::  Bugward compatibility kludges
577 * AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token
578 * AC_FOO_IFELSE vs AC_TRY_FOO::  A more generic scheme for testing sources
580 Generating Test Suites with Autotest
582 * Using an Autotest Test Suite::  Autotest and the user
583 * Writing Testsuites::          Autotest macros
584 * testsuite Invocation::        Running @command{testsuite} scripts
585 * Making testsuite Scripts::    Using autom4te to create @command{testsuite}
587 Using an Autotest Test Suite
589 * testsuite Scripts::           The concepts of Autotest
590 * Autotest Logs::               Their contents
592 Frequent Autoconf Questions, with answers
594 * Distributing::                Distributing @command{configure} scripts
595 * Why GNU M4::                  Why not use the standard M4?
596 * Bootstrapping::               Autoconf and @acronym{GNU} M4 require each other?
597 * Why Not Imake::               Why @acronym{GNU} uses @command{configure} instead of Imake
598 * Defining Directories::        Passing @code{datadir} to program
599 * Autom4te Cache::              What is it?  Can I remove it?
600 * Present But Cannot Be Compiled::  Compiler and Preprocessor Disagree
602 History of Autoconf
604 * Genesis::                     Prehistory and naming of @command{configure}
605 * Exodus::                      The plagues of M4 and Perl
606 * Leviticus::                   The priestly code of portability arrives
607 * Numbers::                     Growth and contributors
608 * Deuteronomy::                 Approaching the promises of easy configuration
610 Copying This Manual
612 * GNU Free Documentation License::  License for copying this manual
614 Indices
616 * Environment Variable Index::  Index of environment variables used
617 * Output Variable Index::       Index of variables set in output files
618 * Preprocessor Symbol Index::   Index of C preprocessor symbols defined
619 * Autoconf Macro Index::        Index of Autoconf macros
620 * M4 Macro Index::              Index of M4, M4sugar, and M4sh macros
621 * Autotest Macro Index::        Index of Autotest macros
622 * Program & Function Index::    Index of those with portability problems
623 * Concept Index::               General index
625 @end detailmenu
626 @end menu
628 @c ============================================================= Introduction.
630 @node Introduction
631 @chapter Introduction
632 @cindex Introduction
634 @flushright
635 A physicist, an engineer, and a computer scientist were discussing the
636 nature of God.  ``Surely a Physicist,'' said the physicist, ``because
637 early in the Creation, God made Light; and you know, Maxwell's
638 equations, the dual nature of electromagnetic waves, the relativistic
639 consequences@dots{}'' ``An Engineer!,'' said the engineer, ``because
640 before making Light, God split the Chaos into Land and Water; it takes a
641 hell of an engineer to handle that big amount of mud, and orderly
642 separation of solids from liquids@dots{}'' The computer scientist
643 shouted: ``And the Chaos, where do you think it was coming from, hmm?''
645 ---Anonymous
646 @end flushright
647 @c (via Franc,ois Pinard)
649 Autoconf is a tool for producing shell scripts that automatically
650 configure software source code packages to adapt to many kinds of
651 Posix-like systems.  The configuration scripts produced by Autoconf
652 are independent of Autoconf when they are run, so their users do not
653 need to have Autoconf.
655 The configuration scripts produced by Autoconf require no manual user
656 intervention when run; they do not normally even need an argument
657 specifying the system type.  Instead, they individually test for the
658 presence of each feature that the software package they are for might need.
659 (Before each check, they print a one-line message stating what they are
660 checking for, so the user doesn't get too bored while waiting for the
661 script to finish.)  As a result, they deal well with systems that are
662 hybrids or customized from the more common Posix variants.  There is
663 no need to maintain files that list the features supported by each
664 release of each variant of Posix.
666 For each software package that Autoconf is used with, it creates a
667 configuration script from a template file that lists the system features
668 that the package needs or can use.  After the shell code to recognize
669 and respond to a system feature has been written, Autoconf allows it to
670 be shared by many software packages that can use (or need) that feature.
671 If it later turns out that the shell code needs adjustment for some
672 reason, it needs to be changed in only one place; all of the
673 configuration scripts can be regenerated automatically to take advantage
674 of the updated code.
676 The Metaconfig package is similar in purpose to Autoconf, but the
677 scripts it produces require manual user intervention, which is quite
678 inconvenient when configuring large source trees.  Unlike Metaconfig
679 scripts, Autoconf scripts can support cross-compiling, if some care is
680 taken in writing them.
682 Autoconf does not solve all problems related to making portable
683 software packages---for a more complete solution, it should be used in
684 concert with other @acronym{GNU} build tools like Automake and
685 Libtool.  These other tools take on jobs like the creation of a
686 portable, recursive makefile with all of the standard targets,
687 linking of shared libraries, and so on.  @xref{The GNU Build System},
688 for more information.
690 Autoconf imposes some restrictions on the names of macros used with
691 @code{#if} in C programs (@pxref{Preprocessor Symbol Index}).
693 Autoconf requires @acronym{GNU} M4 in order to generate the scripts.  It uses
694 features that some versions of M4, including @acronym{GNU} M4 1.3,
695 do not have.  You should use version 1.4.7 or later of @acronym{GNU} M4.
697 @xref{Autoconf 1}, for information about upgrading from version 1.
698 @xref{History}, for the story of Autoconf's development.  @xref{FAQ},
699 for answers to some common questions about Autoconf.
701 See the @uref{http://www.gnu.org/software/autoconf/,
702 Autoconf web page} for up-to-date information, details on the mailing
703 lists, pointers to a list of known bugs, etc.
705 Mail suggestions to @email{autoconf@@gnu.org, the Autoconf mailing
706 list}.  Past suggestions are
707 @uref{http://lists.gnu.org/archive/html/autoconf/, archived}.
709 Mail bug reports to @email{bug-autoconf@@gnu.org, the
710 Autoconf Bugs mailing list}.  Past bug reports are
711 @uref{http://lists.gnu.org/archive/html/bug-autoconf/, archived}.
713 If possible, first check that your bug is
714 not already solved in current development versions, and that it has not
715 been reported yet.  Be sure to include all the needed information and a
716 short @file{configure.ac} that demonstrates the problem.
718 Autoconf's development tree is accessible via anonymous @acronym{CVS}; see the
719 @uref{http://savannah.gnu.org/projects/autoconf/, Autoconf
720 Summary} for details.  Patches relative to the
721 current @acronym{CVS} version can be sent for review to the
722 @email{autoconf-patches@@gnu.org, Autoconf Patches mailing list}.
723 Past patches are
724 @uref{http://lists.gnu.org/@/archive/@/html/@/autoconf-patches/, archived}.
726 Because of its mission, the Autoconf package itself
727 includes only a set of often-used
728 macros that have already demonstrated their usefulness.  Nevertheless,
729 if you wish to share your macros, or find existing ones, see the
730 @uref{http://autoconf-archive.cryp.to/, Autoconf Macro
731 Archive}, which is kindly run by @email{simons@@cryp.to,
732 Peter Simons}.
735 @c ================================================= The GNU Build System
737 @node The GNU Build System
738 @chapter The @acronym{GNU} Build System
739 @cindex @acronym{GNU} build system
741 Autoconf solves an important problem---reliable discovery of
742 system-specific build and runtime information---but this is only one
743 piece of the puzzle for the development of portable software.  To this
744 end, the @acronym{GNU} project has developed a suite of integrated
745 utilities to finish the job Autoconf started: the @acronym{GNU} build
746 system, whose most important components are Autoconf, Automake, and
747 Libtool.  In this chapter, we introduce you to those tools, point you
748 to sources of more information, and try to convince you to use the
749 entire @acronym{GNU} build system for your software.
751 @menu
752 * Automake::                    Escaping makefile hell
753 * Gnulib::                      The @acronym{GNU} portability library
754 * Libtool::                     Building libraries portably
755 * Pointers::                    More info on the @acronym{GNU} build system
756 @end menu
758 @node Automake
759 @section Automake
761 The ubiquity of @command{make} means that a makefile is almost the
762 only viable way to distribute automatic build rules for software, but
763 one quickly runs into its numerous limitations.  Its lack of
764 support for automatic dependency tracking, recursive builds in
765 subdirectories, reliable timestamps (e.g., for network file systems), and
766 so on, mean that developers must painfully (and often incorrectly)
767 reinvent the wheel for each project.  Portability is non-trivial, thanks
768 to the quirks of @command{make} on many systems.  On top of all this is the
769 manual labor required to implement the many standard targets that users
770 have come to expect (@code{make install}, @code{make distclean},
771 @code{make uninstall}, etc.).  Since you are, of course, using Autoconf,
772 you also have to insert repetitive code in your @code{Makefile.in} to
773 recognize @code{@@CC@@}, @code{@@CFLAGS@@}, and other substitutions
774 provided by @command{configure}.  Into this mess steps @dfn{Automake}.
775 @cindex Automake
777 Automake allows you to specify your build needs in a @code{Makefile.am}
778 file with a vastly simpler and more powerful syntax than that of a plain
779 makefile, and then generates a portable @code{Makefile.in} for
780 use with Autoconf.  For example, the @code{Makefile.am} to build and
781 install a simple ``Hello world'' program might look like:
783 @example
784 bin_PROGRAMS = hello
785 hello_SOURCES = hello.c
786 @end example
788 @noindent
789 The resulting @code{Makefile.in} (~400 lines) automatically supports all
790 the standard targets, the substitutions provided by Autoconf, automatic
791 dependency tracking, @code{VPATH} building, and so on.  @command{make}
792 builds the @code{hello} program, and @code{make install} installs it
793 in @file{/usr/local/bin} (or whatever prefix was given to
794 @command{configure}, if not @file{/usr/local}).
796 The benefits of Automake increase for larger packages (especially ones
797 with subdirectories), but even for small programs the added convenience
798 and portability can be substantial.  And that's not all@enddots{}
800 @node Gnulib
801 @section Gnulib
803 @acronym{GNU} software has a well-deserved reputation for running on
804 many different types of systems.  While our primary goal is to write
805 software for the @acronym{GNU} system, many users and developers have
806 been introduced to us through the systems that they were already using.
808 @cindex Gnulib
809 Gnulib is a central location for common @acronym{GNU} code, intended to
810 be shared among free software packages.  Its components are typically
811 shared at the source level, rather than being a library that gets built,
812 installed, and linked against.  The idea is to copy files from Gnulib
813 into your own source tree.  There is no distribution tarball; developers
814 should just grab source modules from the repository.  The source files
815 are available online, under various licenses, mostly @acronym{GNU}
816 @acronym{GPL} or @acronym{GNU} @acronym{LGPL}.
818 Gnulib modules typically contain C source code along with Autoconf
819 macros used to configure the source code.  For example, the Gnulib
820 @code{stdbool} module implements a @file{stdbool.h} header that nearly
821 conforms to C99, even on old-fashioned hosts that lack @file{stdbool.h}.
822 This module contains a source file for the replacement header, along
823 with an Autoconf macro that arranges to use the replacement header on
824 old-fashioned systems.
826 @node Libtool
827 @section Libtool
829 Often, one wants to build not only programs, but libraries, so that
830 other programs can benefit from the fruits of your labor.  Ideally, one
831 would like to produce @emph{shared} (dynamically linked) libraries,
832 which can be used by multiple programs without duplication on disk or in
833 memory and can be updated independently of the linked programs.
834 Producing shared libraries portably, however, is the stuff of
835 nightmares---each system has its own incompatible tools, compiler flags,
836 and magic incantations.  Fortunately, @acronym{GNU} provides a solution:
837 @dfn{Libtool}.
838 @cindex Libtool
840 Libtool handles all the requirements of building shared libraries for
841 you, and at this time seems to be the @emph{only} way to do so with any
842 portability.  It also handles many other headaches, such as: the
843 interaction of Make rules with the variable suffixes of
844 shared libraries, linking reliably with shared libraries before they are
845 installed by the superuser, and supplying a consistent versioning system
846 (so that different versions of a library can be installed or upgraded
847 without breaking binary compatibility).  Although Libtool, like
848 Autoconf, can be used without Automake, it is most simply utilized in
849 conjunction with Automake---there, Libtool is used automatically
850 whenever shared libraries are needed, and you need not know its syntax.
852 @node Pointers
853 @section Pointers
855 Developers who are used to the simplicity of @command{make} for small
856 projects on a single system might be daunted at the prospect of
857 learning to use Automake and Autoconf.  As your software is
858 distributed to more and more users, however, you otherwise
859 quickly find yourself putting lots of effort into reinventing the
860 services that the @acronym{GNU} build tools provide, and making the
861 same mistakes that they once made and overcame.  (Besides, since
862 you're already learning Autoconf, Automake is a piece of cake.)
864 There are a number of places that you can go to for more information on
865 the @acronym{GNU} build tools.
867 @itemize @minus
869 @item Web
871 The home pages for
872 @uref{http://www.gnu.org/@/software/@/autoconf/, Autoconf},
873 @uref{http://www.gnu.org/@/software/@/automake/, Automake},
874 @uref{http://www.gnu.org/@/software/@/gnulib/, Gnulib}, and
875 @uref{http://www.gnu.org/@/software/@/libtool/, Libtool}.
877 @item Automake Manual
879 @xref{Top, , Automake, automake, @acronym{GNU} Automake}, for more
880 information on Automake.
882 @item Books
884 The book @cite{@acronym{GNU} Autoconf, Automake and
885 Libtool}@footnote{@cite{@acronym{GNU} Autoconf, Automake and Libtool},
886 by G. V. Vaughan, B. Elliston, T. Tromey, and I. L. Taylor.  SAMS (originally
887 New Riders), 2000, ISBN 1578701902.} describes the complete @acronym{GNU}
888 build environment.  You can also find
889 @uref{http://sources.redhat.com/@/autobook/, the entire book on-line}.
891 @end itemize
893 @c ================================================= Making configure Scripts.
895 @node Making configure Scripts
896 @chapter Making @command{configure} Scripts
897 @cindex @file{aclocal.m4}
898 @cindex @command{configure}
900 The configuration scripts that Autoconf produces are by convention
901 called @command{configure}.  When run, @command{configure} creates several
902 files, replacing configuration parameters in them with appropriate
903 values.  The files that @command{configure} creates are:
905 @itemize @minus
906 @item
907 one or more @file{Makefile} files, usually one in each subdirectory of the
908 package (@pxref{Makefile Substitutions});
910 @item
911 optionally, a C header file, the name of which is configurable,
912 containing @code{#define} directives (@pxref{Configuration Headers});
914 @item
915 a shell script called @file{config.status} that, when run, recreates
916 the files listed above (@pxref{config.status Invocation});
918 @item
919 an optional shell script normally called @file{config.cache}
920 (created when using @samp{configure --config-cache}) that
921 saves the results of running many of the tests (@pxref{Cache Files});
923 @item
924 a file called @file{config.log} containing any messages produced by
925 compilers, to help debugging if @command{configure} makes a mistake.
926 @end itemize
928 @cindex @file{configure.in}
929 @cindex @file{configure.ac}
930 To create a @command{configure} script with Autoconf, you need to write an
931 Autoconf input file @file{configure.ac} (or @file{configure.in}) and run
932 @command{autoconf} on it.  If you write your own feature tests to
933 supplement those that come with Autoconf, you might also write files
934 called @file{aclocal.m4} and @file{acsite.m4}.  If you use a C header
935 file to contain @code{#define} directives, you might also run
936 @command{autoheader}, and you can distribute the generated file
937 @file{config.h.in} with the package.
939 Here is a diagram showing how the files that can be used in
940 configuration are produced.  Programs that are executed are suffixed by
941 @samp{*}.  Optional files are enclosed in square brackets (@samp{[]}).
942 @command{autoconf} and @command{autoheader} also read the installed Autoconf
943 macro files (by reading @file{autoconf.m4}).
945 @noindent
946 Files used in preparing a software package for distribution:
947 @example
948 your source files --> [autoscan*] --> [configure.scan] --> configure.ac
950 @group
951 configure.ac --.
952                |   .------> autoconf* -----> configure
953 [aclocal.m4] --+---+
954                |   `-----> [autoheader*] --> [config.h.in]
955 [acsite.m4] ---'
956 @end group
958 Makefile.in -------------------------------> Makefile.in
959 @end example
961 @noindent
962 Files used in configuring a software package:
963 @example
964 @group
965                        .-------------> [config.cache]
966 configure* ------------+-------------> config.log
967                        |
968 [config.h.in] -.       v            .-> [config.h] -.
969                +--> config.status* -+               +--> make*
970 Makefile.in ---'                    `-> Makefile ---'
971 @end group
972 @end example
974 @menu
975 * Writing Autoconf Input::      What to put in an Autoconf input file
976 * autoscan Invocation::         Semi-automatic @file{configure.ac} writing
977 * ifnames Invocation::          Listing the conditionals in source code
978 * autoconf Invocation::         How to create configuration scripts
979 * autoreconf Invocation::       Remaking multiple @command{configure} scripts
980 @end menu
982 @node Writing Autoconf Input
983 @section Writing @file{configure.ac}
985 To produce a @command{configure} script for a software package, create a
986 file called @file{configure.ac} that contains invocations of the
987 Autoconf macros that test the system features your package needs or can
988 use.  Autoconf macros already exist to check for many features; see
989 @ref{Existing Tests}, for their descriptions.  For most other features,
990 you can use Autoconf template macros to produce custom checks; see
991 @ref{Writing Tests}, for information about them.  For especially tricky
992 or specialized features, @file{configure.ac} might need to contain some
993 hand-crafted shell commands; see @ref{Portable Shell}.  The
994 @command{autoscan} program can give you a good start in writing
995 @file{configure.ac} (@pxref{autoscan Invocation}, for more information).
997 Previous versions of Autoconf promoted the name @file{configure.in},
998 which is somewhat ambiguous (the tool needed to process this file is not
999 described by its extension), and introduces a slight confusion with
1000 @file{config.h.in} and so on (for which @samp{.in} means ``to be
1001 processed by @command{configure}'').  Using @file{configure.ac} is now
1002 preferred.
1004 @menu
1005 * Shell Script Compiler::       Autoconf as solution of a problem
1006 * Autoconf Language::           Programming in Autoconf
1007 * Autoconf Input Layout::       Standard organization of @file{configure.ac}
1008 @end menu
1010 @node Shell Script Compiler
1011 @subsection A Shell Script Compiler
1013 Just as for any other computer language, in order to properly program
1014 @file{configure.ac} in Autoconf you must understand @emph{what} problem
1015 the language tries to address and @emph{how} it does so.
1017 The problem Autoconf addresses is that the world is a mess.  After all,
1018 you are using Autoconf in order to have your package compile easily on
1019 all sorts of different systems, some of them being extremely hostile.
1020 Autoconf itself bears the price for these differences: @command{configure}
1021 must run on all those systems, and thus @command{configure} must limit itself
1022 to their lowest common denominator of features.
1024 Naturally, you might then think of shell scripts; who needs
1025 @command{autoconf}?  A set of properly written shell functions is enough to
1026 make it easy to write @command{configure} scripts by hand.  Sigh!
1027 Unfortunately, shell functions do not belong to the least common
1028 denominator; therefore, where you would like to define a function and
1029 use it ten times, you would instead need to copy its body ten times.
1031 So, what is really needed is some kind of compiler, @command{autoconf},
1032 that takes an Autoconf program, @file{configure.ac}, and transforms it
1033 into a portable shell script, @command{configure}.
1035 How does @command{autoconf} perform this task?
1037 There are two obvious possibilities: creating a brand new language or
1038 extending an existing one.  The former option is attractive: all
1039 sorts of optimizations could easily be implemented in the compiler and
1040 many rigorous checks could be performed on the Autoconf program
1041 (e.g., rejecting any non-portable construct).  Alternatively, you can
1042 extend an existing language, such as the @code{sh} (Bourne shell)
1043 language.
1045 Autoconf does the latter: it is a layer on top of @code{sh}.  It was
1046 therefore most convenient to implement @command{autoconf} as a macro
1047 expander: a program that repeatedly performs @dfn{macro expansions} on
1048 text input, replacing macro calls with macro bodies and producing a pure
1049 @code{sh} script in the end.  Instead of implementing a dedicated
1050 Autoconf macro expander, it is natural to use an existing
1051 general-purpose macro language, such as M4, and implement the extensions
1052 as a set of M4 macros.
1055 @node Autoconf Language
1056 @subsection The Autoconf Language
1057 @cindex quotation
1059 The Autoconf language differs from many other computer
1060 languages because it treats actual code the same as plain text.  Whereas
1061 in C, for instance, data and instructions have different syntactic
1062 status, in Autoconf their status is rigorously the same.  Therefore, we
1063 need a means to distinguish literal strings from text to be expanded:
1064 quotation.
1066 When calling macros that take arguments, there must not be any white
1067 space between the macro name and the open parenthesis.  Arguments should
1068 be enclosed within the M4 quote characters @samp{[} and @samp{]}, and be
1069 separated by commas.  Any leading blanks or newlines in arguments are ignored,
1070 unless they are quoted.  You should always quote an argument that
1071 might contain a macro name, comma, parenthesis, or a leading blank or
1072 newline.  This rule applies recursively for every macro
1073 call, including macros called from other macros.
1075 For instance:
1077 @example
1078 AC_CHECK_HEADER([stdio.h],
1079                 [AC_DEFINE([HAVE_STDIO_H], [1],
1080                    [Define to 1 if you have <stdio.h>.])],
1081                 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1082 @end example
1084 @noindent
1085 is quoted properly.  You may safely simplify its quotation to:
1087 @example
1088 AC_CHECK_HEADER([stdio.h],
1089                 [AC_DEFINE([HAVE_STDIO_H], 1,
1090                    [Define to 1 if you have <stdio.h>.])],
1091                 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1092 @end example
1094 @noindent
1095 because @samp{1} cannot contain a macro call.  Here, the argument of
1096 @code{AC_MSG_ERROR} must be quoted; otherwise, its comma would be
1097 interpreted as an argument separator.  Also, the second and third arguments
1098 of @samp{AC_CHECK_HEADER} must be quoted, since they contain
1099 macro calls.  The three arguments @samp{HAVE_STDIO_H}, @samp{stdio.h},
1100 and @samp{Define to 1 if you have <stdio.h>.} do not need quoting, but
1101 if you unwisely defined a macro with a name like @samp{Define} or
1102 @samp{stdio} then they would need quoting.  Cautious Autoconf users
1103 would keep the quotes, but many Autoconf users find such precautions
1104 annoying, and would rewrite the example as follows:
1106 @example
1107 AC_CHECK_HEADER(stdio.h,
1108                 [AC_DEFINE(HAVE_STDIO_H, 1,
1109                    [Define to 1 if you have <stdio.h>.])],
1110                 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1111 @end example
1113 @noindent
1114 This is safe, so long as you adopt good naming conventions and do not
1115 define macros with names like @samp{HAVE_STDIO_H}, @samp{stdio}, or
1116 @samp{h}.  Though it is also safe here to omit the quotes around
1117 @samp{Define to 1 if you have <stdio.h>.} this is not recommended, as
1118 message strings are more likely to inadvertently contain commas.
1120 The following example is wrong and dangerous, as it is underquoted:
1122 @example
1123 AC_CHECK_HEADER(stdio.h,
1124                 AC_DEFINE(HAVE_STDIO_H, 1,
1125                    Define to 1 if you have <stdio.h>.),
1126                 AC_MSG_ERROR([Sorry, can't do anything for you]))
1127 @end example
1129 In other cases, you may have to use text that also resembles a macro
1130 call.  You must quote that text even when it is not passed as a macro
1131 argument:
1133 @example
1134 echo "Hard rock was here!  --[AC_DC]"
1135 @end example
1137 @noindent
1138 which results in:
1140 @example
1141 echo "Hard rock was here!  --AC_DC"
1142 @end example
1144 @noindent
1145 When you use the same text in a macro argument, you must therefore have
1146 an extra quotation level (since one is stripped away by the macro
1147 substitution).  In general, then, it is a good idea to @emph{use double
1148 quoting for all literal string arguments}:
1150 @example
1151 AC_MSG_WARN([[AC_DC stinks  --Iron Maiden]])
1152 @end example
1154 You are now able to understand one of the constructs of Autoconf that
1155 has been continually misunderstood@dots{}  The rule of thumb is that
1156 @emph{whenever you expect macro expansion, expect quote expansion};
1157 i.e., expect one level of quotes to be lost.  For instance:
1159 @example
1160 AC_COMPILE_IFELSE([char b[10];], [], [AC_MSG_ERROR([you lose])])
1161 @end example
1163 @noindent
1164 is incorrect: here, the first argument of @code{AC_COMPILE_IFELSE} is
1165 @samp{char b[10];} and is expanded once, which results in
1166 @samp{char b10;}.  (There was an idiom common in Autoconf's past to
1167 address this issue via the M4 @code{changequote} primitive, but do not
1168 use it!)  Let's take a closer look: the author meant the first argument
1169 to be understood as a literal, and therefore it must be quoted twice:
1171 @example
1172 AC_COMPILE_IFELSE([[char b[10];]], [], [AC_MSG_ERROR([you lose])])
1173 @end example
1175 @noindent
1176 Voil@`a, you actually produce @samp{char b[10];} this time!
1178 On the other hand, descriptions (e.g., the last parameter of
1179 @code{AC_DEFINE} or @code{AS_HELP_STRING}) are not literals---they
1180 are subject to line breaking, for example---and should not be double quoted.
1181 Even if these descriptions are short and are not actually broken, double
1182 quoting them yields weird results.
1184 Some macros take optional arguments, which this documentation represents
1185 as @ovar{arg} (not to be confused with the quote characters).  You may
1186 just leave them empty, or use @samp{[]} to make the emptiness of the
1187 argument explicit, or you may simply omit the trailing commas.  The
1188 three lines below are equivalent:
1190 @example
1191 AC_CHECK_HEADERS([stdio.h], [], [], [])
1192 AC_CHECK_HEADERS([stdio.h],,,)
1193 AC_CHECK_HEADERS([stdio.h])
1194 @end example
1196 It is best to put each macro call on its own line in
1197 @file{configure.ac}.  Most of the macros don't add extra newlines; they
1198 rely on the newline after the macro call to terminate the commands.
1199 This approach makes the generated @command{configure} script a little
1200 easier to read by not inserting lots of blank lines.  It is generally
1201 safe to set shell variables on the same line as a macro call, because
1202 the shell allows assignments without intervening newlines.
1204 You can include comments in @file{configure.ac} files by starting them
1205 with the @samp{#}.  For example, it is helpful to begin
1206 @file{configure.ac} files with a line like this:
1208 @example
1209 # Process this file with autoconf to produce a configure script.
1210 @end example
1212 @node Autoconf Input Layout
1213 @subsection Standard @file{configure.ac} Layout
1215 The order in which @file{configure.ac} calls the Autoconf macros is not
1216 important, with a few exceptions.  Every @file{configure.ac} must
1217 contain a call to @code{AC_INIT} before the checks, and a call to
1218 @code{AC_OUTPUT} at the end (@pxref{Output}).  Additionally, some macros
1219 rely on other macros having been called first, because they check
1220 previously set values of some variables to decide what to do.  These
1221 macros are noted in the individual descriptions (@pxref{Existing
1222 Tests}), and they also warn you when @command{configure} is created if they
1223 are called out of order.
1225 To encourage consistency, here is a suggested order for calling the
1226 Autoconf macros.  Generally speaking, the things near the end of this
1227 list are those that could depend on things earlier in it.  For example,
1228 library functions could be affected by types and libraries.
1230 @display
1231 @group
1232 Autoconf requirements
1233 @code{AC_INIT(@var{package}, @var{version}, @var{bug-report-address})}
1234 information on the package
1235 checks for programs
1236 checks for libraries
1237 checks for header files
1238 checks for types
1239 checks for structures
1240 checks for compiler characteristics
1241 checks for library functions
1242 checks for system services
1243 @code{AC_CONFIG_FILES(@r{[}@var{file@dots{}}@r{]})}
1244 @code{AC_OUTPUT}
1245 @end group
1246 @end display
1249 @node autoscan Invocation
1250 @section Using @command{autoscan} to Create @file{configure.ac}
1251 @cindex @command{autoscan}
1253 The @command{autoscan} program can help you create and/or maintain a
1254 @file{configure.ac} file for a software package.  @command{autoscan}
1255 examines source files in the directory tree rooted at a directory given
1256 as a command line argument, or the current directory if none is given.
1257 It searches the source files for common portability problems and creates
1258 a file @file{configure.scan} which is a preliminary @file{configure.ac}
1259 for that package, and checks a possibly existing @file{configure.ac} for
1260 completeness.
1262 When using @command{autoscan} to create a @file{configure.ac}, you
1263 should manually examine @file{configure.scan} before renaming it to
1264 @file{configure.ac}; it probably needs some adjustments.
1265 Occasionally, @command{autoscan} outputs a macro in the wrong order
1266 relative to another macro, so that @command{autoconf} produces a warning;
1267 you need to move such macros manually.  Also, if you want the package to
1268 use a configuration header file, you must add a call to
1269 @code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers}).  You might
1270 also have to change or add some @code{#if} directives to your program in
1271 order to make it work with Autoconf (@pxref{ifnames Invocation}, for
1272 information about a program that can help with that job).
1274 When using @command{autoscan} to maintain a @file{configure.ac}, simply
1275 consider adding its suggestions.  The file @file{autoscan.log}
1276 contains detailed information on why a macro is requested.
1278 @command{autoscan} uses several data files (installed along with Autoconf)
1279 to determine which macros to output when it finds particular symbols in
1280 a package's source files.  These data files all have the same format:
1281 each line consists of a symbol, one or more blanks, and the Autoconf macro to
1282 output if that symbol is encountered.  Lines starting with @samp{#} are
1283 comments.
1285 @command{autoscan} accepts the following options:
1287 @table @option
1288 @item --help
1289 @itemx -h
1290 Print a summary of the command line options and exit.
1292 @item --version
1293 @itemx -V
1294 Print the version number of Autoconf and exit.
1296 @item --verbose
1297 @itemx -v
1298 Print the names of the files it examines and the potentially interesting
1299 symbols it finds in them.  This output can be voluminous.
1301 @item --include=@var{dir}
1302 @itemx -I @var{dir}
1303 Append @var{dir} to the include path.  Multiple invocations accumulate.
1305 @item --prepend-include=@var{dir}
1306 @item -B @var{dir}
1307 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
1308 @end table
1310 @node ifnames Invocation
1311 @section Using @command{ifnames} to List Conditionals
1312 @cindex @command{ifnames}
1314 @command{ifnames} can help you write @file{configure.ac} for a software
1315 package.  It prints the identifiers that the package already uses in C
1316 preprocessor conditionals.  If a package has already been set up to have
1317 some portability, @command{ifnames} can thus help you figure out what its
1318 @command{configure} needs to check for.  It may help fill in some gaps in a
1319 @file{configure.ac} generated by @command{autoscan} (@pxref{autoscan
1320 Invocation}).
1322 @command{ifnames} scans all of the C source files named on the command line
1323 (or the standard input, if none are given) and writes to the standard
1324 output a sorted list of all the identifiers that appear in those files
1325 in @code{#if}, @code{#elif}, @code{#ifdef}, or @code{#ifndef}
1326 directives.  It prints each identifier on a line, followed by a
1327 space-separated list of the files in which that identifier occurs.
1329 @noindent
1330 @command{ifnames} accepts the following options:
1332 @table @option
1333 @item --help
1334 @itemx -h
1335 Print a summary of the command line options and exit.
1337 @item --version
1338 @itemx -V
1339 Print the version number of Autoconf and exit.
1340 @end table
1342 @node autoconf Invocation
1343 @section Using @command{autoconf} to Create @command{configure}
1344 @cindex @command{autoconf}
1346 To create @command{configure} from @file{configure.ac}, run the
1347 @command{autoconf} program with no arguments.  @command{autoconf} processes
1348 @file{configure.ac} with the M4 macro processor, using the
1349 Autoconf macros.  If you give @command{autoconf} an argument, it reads that
1350 file instead of @file{configure.ac} and writes the configuration script
1351 to the standard output instead of to @command{configure}.  If you give
1352 @command{autoconf} the argument @option{-}, it reads from the standard
1353 input instead of @file{configure.ac} and writes the configuration script
1354 to the standard output.
1356 The Autoconf macros are defined in several files.  Some of the files are
1357 distributed with Autoconf; @command{autoconf} reads them first.  Then it
1358 looks for the optional file @file{acsite.m4} in the directory that
1359 contains the distributed Autoconf macro files, and for the optional file
1360 @file{aclocal.m4} in the current directory.  Those files can contain
1361 your site's or the package's own Autoconf macro definitions
1362 (@pxref{Writing Autoconf Macros}, for more information).  If a macro is
1363 defined in more than one of the files that @command{autoconf} reads, the
1364 last definition it reads overrides the earlier ones.
1366 @command{autoconf} accepts the following options:
1368 @table @option
1369 @item --help
1370 @itemx -h
1371 Print a summary of the command line options and exit.
1373 @item --version
1374 @itemx -V
1375 Print the version number of Autoconf and exit.
1377 @item --verbose
1378 @itemx -v
1379 Report processing steps.
1381 @item --debug
1382 @itemx -d
1383 Don't remove the temporary files.
1385 @item --force
1386 @itemx -f
1387 Remake @file{configure} even if newer than its input files.
1389 @item --include=@var{dir}
1390 @itemx -I @var{dir}
1391 Append @var{dir} to the include path.  Multiple invocations accumulate.
1393 @item --prepend-include=@var{dir}
1394 @item -B @var{dir}
1395 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
1397 @item --output=@var{file}
1398 @itemx -o @var{file}
1399 Save output (script or trace) to @var{file}.  The file @option{-} stands
1400 for the standard output.
1402 @item --warnings=@var{category}
1403 @itemx -W @var{category}
1404 @evindex WARNINGS
1405 Report the warnings related to @var{category} (which can actually be a
1406 comma separated list).  @xref{Reporting Messages}, macro
1407 @code{AC_DIAGNOSE}, for a comprehensive list of categories.  Special
1408 values include:
1410 @table @samp
1411 @item all
1412 report all the warnings
1414 @item none
1415 report none
1417 @item error
1418 treats warnings as errors
1420 @item no-@var{category}
1421 disable warnings falling into @var{category}
1422 @end table
1424 Warnings about @samp{syntax} are enabled by default, and the environment
1425 variable @env{WARNINGS}, a comma separated list of categories, is
1426 honored as well.  Passing @option{-W @var{category}} actually behaves as if
1427 you had passed @option{--warnings=syntax,$WARNINGS,@var{category}}.  If
1428 you want to disable the defaults and @env{WARNINGS}, but (for example)
1429 enable the warnings about obsolete constructs, you would use @option{-W
1430 none,obsolete}.
1432 @cindex Back trace
1433 @cindex Macro invocation stack
1434 Because @command{autoconf} uses @command{autom4te} behind the scenes, it
1435 displays a back trace for errors, but not for warnings; if you want
1436 them, just pass @option{-W error}.  @xref{autom4te Invocation}, for some
1437 examples.
1439 @item --trace=@var{macro}[:@var{format}]
1440 @itemx -t @var{macro}[:@var{format}]
1441 Do not create the @command{configure} script, but list the calls to
1442 @var{macro} according to the @var{format}.  Multiple @option{--trace}
1443 arguments can be used to list several macros.  Multiple @option{--trace}
1444 arguments for a single macro are not cumulative; instead, you should
1445 just make @var{format} as long as needed.
1447 The @var{format} is a regular string, with newlines if desired, and
1448 several special escape codes.  It defaults to @samp{$f:$l:$n:$%}; see
1449 @ref{autom4te Invocation}, for details on the @var{format}.
1451 @item --initialization
1452 @itemx -i
1453 By default, @option{--trace} does not trace the initialization of the
1454 Autoconf macros (typically the @code{AC_DEFUN} definitions).  This
1455 results in a noticeable speedup, but can be disabled by this option.
1456 @end table
1459 It is often necessary to check the content of a @file{configure.ac}
1460 file, but parsing it yourself is extremely fragile and error-prone.  It
1461 is suggested that you rely upon @option{--trace} to scan
1462 @file{configure.ac}.  For instance, to find the list of variables that
1463 are substituted, use:
1465 @example
1466 @group
1467 $ @kbd{autoconf -t AC_SUBST}
1468 configure.ac:2:AC_SUBST:ECHO_C
1469 configure.ac:2:AC_SUBST:ECHO_N
1470 configure.ac:2:AC_SUBST:ECHO_T
1471 @i{More traces deleted}
1472 @end group
1473 @end example
1475 @noindent
1476 The example below highlights the difference between @samp{$@@},
1477 @samp{$*}, and @samp{$%}.
1479 @example
1480 @group
1481 $ @kbd{cat configure.ac}
1482 AC_DEFINE(This, is, [an
1483 [example]])
1484 $ @kbd{autoconf -t 'AC_DEFINE:@@: $@@}
1485 *: $*
1486 %: $%'
1487 @@: [This],[is],[an
1488 [example]]
1489 *: This,is,an
1490 [example]
1491 %: This:is:an [example]
1492 @end group
1493 @end example
1495 @noindent
1496 The @var{format} gives you a lot of freedom:
1498 @example
1499 @group
1500 $ @kbd{autoconf -t 'AC_SUBST:$$ac_subst@{"$1"@} = "$f:$l";'}
1501 $ac_subst@{"ECHO_C"@} = "configure.ac:2";
1502 $ac_subst@{"ECHO_N"@} = "configure.ac:2";
1503 $ac_subst@{"ECHO_T"@} = "configure.ac:2";
1504 @i{More traces deleted}
1505 @end group
1506 @end example
1508 @noindent
1509 A long @var{separator} can be used to improve the readability of complex
1510 structures, and to ease their parsing (for instance when no single
1511 character is suitable as a separator):
1513 @example
1514 @group
1515 $ @kbd{autoconf -t 'AM_MISSING_PROG:$@{|:::::|@}*'}
1516 ACLOCAL|:::::|aclocal|:::::|$missing_dir
1517 AUTOCONF|:::::|autoconf|:::::|$missing_dir
1518 AUTOMAKE|:::::|automake|:::::|$missing_dir
1519 @i{More traces deleted}
1520 @end group
1521 @end example
1523 @node autoreconf Invocation
1524 @section Using @command{autoreconf} to Update @command{configure} Scripts
1525 @cindex @command{autoreconf}
1527 Installing the various components of the @acronym{GNU} Build System can be
1528 tedious: running @command{autopoint} for Gettext, @command{automake} for
1529 @file{Makefile.in} etc.@: in each directory.  It may be needed either
1530 because some tools such as @command{automake} have been updated on your
1531 system, or because some of the sources such as @file{configure.ac} have
1532 been updated, or finally, simply in order to install the @acronym{GNU} Build
1533 System in a fresh tree.
1535 @command{autoreconf} runs @command{autoconf}, @command{autoheader},
1536 @command{aclocal}, @command{automake}, @command{libtoolize}, and
1537 @command{autopoint} (when appropriate) repeatedly to update the
1538 @acronym{GNU} Build System in the specified directories and their
1539 subdirectories (@pxref{Subdirectories}).  By default, it only remakes
1540 those files that are older than their sources.
1542 If you install a new version of some tool, you can make
1543 @command{autoreconf} remake @emph{all} of the files by giving it the
1544 @option{--force} option.
1546 @xref{Automatic Remaking}, for Make rules to automatically
1547 remake @command{configure} scripts when their source files change.  That
1548 method handles the timestamps of configuration header templates
1549 properly, but does not pass @option{--autoconf-dir=@var{dir}} or
1550 @option{--localdir=@var{dir}}.
1552 @cindex Gettext
1553 @cindex @command{autopoint}
1554 Gettext supplies the @command{autopoint} command to add translation
1555 infrastructure to a source package.  If you use @command{autopoint},
1556 your @file{configure.ac} should invoke both @code{AM_GNU_GETTEXT} and
1557 @code{AM_GNU_GETTEXT_VERSION(@var{gettext-version})}.  @xref{autopoint
1558 Invocation, , Invoking the @code{autopoint} Program, gettext,
1559 @acronym{GNU} @code{gettext} utilities}, for further details.
1561 @noindent
1562 @command{autoreconf} accepts the following options:
1564 @table @option
1565 @item --help
1566 @itemx -h
1567 Print a summary of the command line options and exit.
1569 @item --version
1570 @itemx -V
1571 Print the version number of Autoconf and exit.
1573 @item --verbose
1574 Print the name of each directory @command{autoreconf} examines and the
1575 commands it runs.  If given two or more times, pass @option{--verbose}
1576 to subordinate tools that support it.
1578 @item --debug
1579 @itemx -d
1580 Don't remove the temporary files.
1582 @item --force
1583 @itemx -f
1584 Remake even @file{configure} scripts and configuration headers that are
1585 newer than their input files (@file{configure.ac} and, if present,
1586 @file{aclocal.m4}).
1588 @item --install
1589 @itemx -i
1590 Install the missing auxiliary files in the package.  By default, files
1591 are copied; this can be changed with @option{--symlink}.
1593 If deemed appropriate, this option triggers calls to
1594 @samp{automake --add-missing},
1595 @samp{libtoolize}, @samp{autopoint}, etc.
1597 @item --no-recursive
1598 Do not rebuild files in subdirectories to configure (see @ref{Subdirectories},
1599 macro @code{AC_CONFIG_SUBDIRS}).
1601 @item --symlink
1602 @itemx -s
1603 When used with @option{--install}, install symbolic links to the missing
1604 auxiliary files instead of copying them.
1606 @item --make
1607 @itemx -m
1608 When the directories were configured, update the configuration by
1609 running @samp{./config.status --recheck && ./config.status}, and then
1610 run @samp{make}.
1612 @item --include=@var{dir}
1613 @itemx -I @var{dir}
1614 Append @var{dir} to the include path.  Multiple invocations accumulate.
1615 Passed on to @command{autoconf} and @command{autoheader} internally.
1617 @item --prepend-include=@var{dir}
1618 @item -B @var{dir}
1619 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
1620 Passed on to @command{autoconf} and @command{autoheader} internally.
1622 @item --warnings=@var{category}
1623 @itemx -W @var{category}
1624 @evindex WARNINGS
1625 Report the warnings related to @var{category} (which can actually be a
1626 comma separated list).
1628 @table @samp
1629 @item cross
1630 related to cross compilation issues.
1632 @item obsolete
1633 report the uses of obsolete constructs.
1635 @item portability
1636 portability issues
1638 @item syntax
1639 dubious syntactic constructs.
1641 @item all
1642 report all the warnings
1644 @item none
1645 report none
1647 @item error
1648 treats warnings as errors
1650 @item no-@var{category}
1651 disable warnings falling into @var{category}
1652 @end table
1654 Warnings about @samp{syntax} are enabled by default, and the environment
1655 variable @env{WARNINGS}, a comma separated list of categories, is
1656 honored as well.  Passing @option{-W @var{category}} actually behaves as if
1657 you had passed @option{--warnings=syntax,$WARNINGS,@var{category}}.  If
1658 you want to disable the defaults and @env{WARNINGS}, but (for example)
1659 enable the warnings about obsolete constructs, you would use @option{-W
1660 none,obsolete}.
1661 @end table
1663 If you want @command{autoreconf} to pass flags that are not listed here
1664 on to @command{aclocal}, set @code{ACLOCAL_AMFLAGS} in your @file{Makefile.am}.
1666 @c ========================================= Initialization and Output Files.
1668 @node Setup
1669 @chapter Initialization and Output Files
1671 Autoconf-generated @command{configure} scripts need some information about
1672 how to initialize, such as how to find the package's source files and
1673 about the output files to produce.  The following sections describe the
1674 initialization and the creation of output files.
1676 @menu
1677 * Initializing configure::      Option processing etc.
1678 * Notices::                     Copyright, version numbers in @command{configure}
1679 * Input::                       Where Autoconf should find files
1680 * Output::                      Outputting results from the configuration
1681 * Configuration Actions::       Preparing the output based on results
1682 * Configuration Files::         Creating output files
1683 * Makefile Substitutions::      Using output variables in makefiles
1684 * Configuration Headers::       Creating a configuration header file
1685 * Configuration Commands::      Running arbitrary instantiation commands
1686 * Configuration Links::         Links depending on the configuration
1687 * Subdirectories::              Configuring independent packages together
1688 * Default Prefix::              Changing the default installation prefix
1689 @end menu
1691 @node Initializing configure
1692 @section Initializing @command{configure}
1694 Every @command{configure} script must call @code{AC_INIT} before doing
1695 anything else.  The only other required macro is @code{AC_OUTPUT}
1696 (@pxref{Output}).
1698 @defmac AC_INIT (@var{package}, @var{version}, @ovar{bug-report}, @ovar{tarname})
1699 @acindex{INIT}
1700 Process any command-line arguments and perform various initializations
1701 and verifications.
1703 Set the name of the @var{package} and its @var{version}.  These are
1704 typically used in @option{--version} support, including that of
1705 @command{configure}.  The optional argument @var{bug-report} should be
1706 the email to which users should send bug reports.  The package
1707 @var{tarname} differs from @var{package}: the latter designates the full
1708 package name (e.g., @samp{GNU Autoconf}), while the former is meant for
1709 distribution tar ball names (e.g., @samp{autoconf}).  It defaults to
1710 @var{package} with @samp{GNU } stripped, lower-cased, and all characters
1711 other than alphanumerics and underscores are changed to @samp{-}.
1713 It is preferable that the arguments of @code{AC_INIT} be static, i.e.,
1714 there should not be any shell computation, but they can be computed by
1717 The following M4 macros (e.g., @code{AC_PACKAGE_NAME}), output variables
1718 (e.g., @code{PACKAGE_NAME}), and preprocessor symbols (e.g.,
1719 @code{PACKAGE_NAME}) are defined by @code{AC_INIT}:
1721 @table @asis
1722 @item @code{AC_PACKAGE_NAME}, @code{PACKAGE_NAME}
1723 @acindex{PACKAGE_NAME}
1724 @ovindex PACKAGE_NAME
1725 @cvindex PACKAGE_NAME
1726 Exactly @var{package}.
1728 @item @code{AC_PACKAGE_TARNAME}, @code{PACKAGE_TARNAME}
1729 @acindex{PACKAGE_TARNAME}
1730 @ovindex PACKAGE_TARNAME
1731 @cvindex PACKAGE_TARNAME
1732 Exactly @var{tarname}.
1734 @item @code{AC_PACKAGE_VERSION}, @code{PACKAGE_VERSION}
1735 @acindex{PACKAGE_VERSION}
1736 @ovindex PACKAGE_VERSION
1737 @cvindex PACKAGE_VERSION
1738 Exactly @var{version}.
1740 @item @code{AC_PACKAGE_STRING}, @code{PACKAGE_STRING}
1741 @acindex{PACKAGE_STRING}
1742 @ovindex PACKAGE_STRING
1743 @cvindex PACKAGE_STRING
1744 Exactly @samp{@var{package} @var{version}}.
1746 @item @code{AC_PACKAGE_BUGREPORT}, @code{PACKAGE_BUGREPORT}
1747 @acindex{PACKAGE_BUGREPORT}
1748 @ovindex PACKAGE_BUGREPORT
1749 @cvindex PACKAGE_BUGREPORT
1750 Exactly @var{bug-report}.
1751 @end table
1752 @end defmac
1754 If your @command{configure} script does its own option processing, it
1755 should inspect @samp{$@@} or @samp{$*} immediately after calling
1756 @code{AC_INIT}, because other Autoconf macros liberally use the
1757 @command{set} command to process strings, and this has the side effect
1758 of updating @samp{$@@} and @samp{$*}.  However, we suggest that you use
1759 standard macros like @code{AC_ARG_ENABLE} instead of attempting to
1760 implement your own option processing.  @xref{Site Configuration}.
1763 @node Notices
1764 @section Notices in @command{configure}
1765 @cindex Notices in @command{configure}
1767 The following macros manage version numbers for @command{configure}
1768 scripts.  Using them is optional.
1770 @c FIXME: AC_PREREQ should not be here
1771 @defmac AC_PREREQ (@var{version})
1772 @acindex{PREREQ}
1773 @cindex Version
1774 Ensure that a recent enough version of Autoconf is being used.  If the
1775 version of Autoconf being used to create @command{configure} is
1776 earlier than @var{version}, print an error message to the standard
1777 error output and exit with failure (exit status is 63).  For example:
1779 @example
1780 AC_PREREQ([@value{VERSION}])
1781 @end example
1783 This macro is the only macro that may be used before @code{AC_INIT}, but
1784 for consistency, you are invited not to do so.
1785 @end defmac
1787 @defmac AC_COPYRIGHT (@var{copyright-notice})
1788 @acindex{COPYRIGHT}
1789 @cindex Copyright Notice
1790 State that, in addition to the Free Software Foundation's copyright on
1791 the Autoconf macros, parts of your @command{configure} are covered by the
1792 @var{copyright-notice}.
1794 The @var{copyright-notice} shows up in both the head of
1795 @command{configure} and in @samp{configure --version}.
1796 @end defmac
1799 @defmac AC_REVISION (@var{revision-info})
1800 @acindex{REVISION}
1801 @cindex Revision
1802 Copy revision stamp @var{revision-info} into the @command{configure}
1803 script, with any dollar signs or double-quotes removed.  This macro lets
1804 you put a revision stamp from @file{configure.ac} into @command{configure}
1805 without @acronym{RCS} or @acronym{CVS} changing it when you check in
1806 @command{configure}.  That way, you can determine easily which revision of
1807 @file{configure.ac} a particular @command{configure} corresponds to.
1809 For example, this line in @file{configure.ac}:
1811 @c The asis prevents RCS from changing the example in the manual.
1812 @example
1813 AC_REVISION([$@asis{Revision: 1.30 }$])
1814 @end example
1816 @noindent
1817 produces this in @command{configure}:
1819 @example
1820 #!/bin/sh
1821 # From configure.ac Revision: 1.30
1822 @end example
1823 @end defmac
1826 @node Input
1827 @section Finding @command{configure} Input
1830 @defmac AC_CONFIG_SRCDIR (@var{unique-file-in-source-dir})
1831 @acindex{CONFIG_SRCDIR}
1832 @var{unique-file-in-source-dir} is some file that is in the package's
1833 source directory; @command{configure} checks for this file's existence to
1834 make sure that the directory that it is told contains the source code in
1835 fact does.  Occasionally people accidentally specify the wrong directory
1836 with @option{--srcdir}; this is a safety check.  @xref{configure
1837 Invocation}, for more information.
1838 @end defmac
1841 @c FIXME: Remove definitively once --install explained.
1843 @c Small packages may store all their macros in @code{aclocal.m4}.  As the
1844 @c set of macros grows, or for maintenance reasons, a maintainer may prefer
1845 @c to split the macros in several files.  In this case, Autoconf must be
1846 @c told which files to load, and in which order.
1848 @c @defmac AC_INCLUDE (@var{file}@dots{})
1849 @c @acindex{INCLUDE}
1850 @c @c FIXME: There is no longer shell globbing.
1851 @c Read the macro definitions that appear in the listed files.  A list of
1852 @c space-separated file names or shell globbing patterns is expected.  The
1853 @c files are read in the order they're listed.
1855 @c Because the order of definition of macros is important (only the last
1856 @c definition of a macro is used), beware that it is @code{AC_INIT} that
1857 @c loads @file{acsite.m4} and @file{aclocal.m4}.  Note that
1858 @c @code{AC_INCLUDE}ing a file before @code{AC_INIT} or within
1859 @c @file{aclocal.m4} is different from doing so after @code{AC_INIT}: in
1860 @c the latter case, non-macro lines from included files may end up in the
1861 @c @file{configure} script, whereas in the former case, they'd be discarded
1862 @c just like any text that appear before @code{AC_INIT}.
1863 @c @end defmac
1865 Packages that do manual configuration or use the @command{install} program
1866 might need to tell @command{configure} where to find some other shell
1867 scripts by calling @code{AC_CONFIG_AUX_DIR}, though the default places
1868 it looks are correct for most cases.
1870 @defmac AC_CONFIG_AUX_DIR (@var{dir})
1871 @acindex{CONFIG_AUX_DIR}
1872 Use the auxiliary build tools (e.g., @file{install-sh},
1873 @file{config.sub}, @file{config.guess}, Cygnus @command{configure},
1874 Automake and Libtool scripts, etc.)@: that are in directory @var{dir}.
1875 These are auxiliary files used in configuration.  @var{dir} can be
1876 either absolute or relative to @file{@var{srcdir}}.  The default is
1877 @file{@var{srcdir}} or @file{@var{srcdir}/..} or
1878 @file{@var{srcdir}/../..}, whichever is the first that contains
1879 @file{install-sh}.  The other files are not checked for, so that using
1880 @code{AC_PROG_INSTALL} does not automatically require distributing the
1881 other auxiliary files.  It checks for @file{install.sh} also, but that
1882 name is obsolete because some @code{make} have a rule that creates
1883 @file{install} from it if there is no makefile.
1885 The auxiliary directory is commonly named @file{build-aux}.
1886 If you need portability to @acronym{DOS} variants, do not name the
1887 auxiliary directory @file{aux}.  @xref{File System Conventions}.
1888 @end defmac
1890 @defmac AC_REQUIRE_AUX_FILE (@var{file})
1891 @acindex{REQUIRE_AUX_FILE}
1892 Declares that @var{file} is expected in the directory defined above.  In
1893 Autoconf proper, this macro does nothing: its sole purpose is to be
1894 traced by third-party tools to produce a list of expected auxiliary
1895 files.  For instance it is called by macros like @code{AC_PROG_INSTALL}
1896 (@pxref{Particular Programs}) or @code{AC_CANONICAL_BUILD}
1897 (@pxref{Canonicalizing}) to register the auxiliary files they need.
1898 @end defmac
1900 Similarly, packages that use @command{aclocal} should declare where
1901 local macros can be found using @code{AC_CONFIG_MACRO_DIR}.
1903 @defmac AC_CONFIG_MACRO_DIR (@var{dir})
1904 @acindex{CONFIG_MACRO_DIR}
1905 Specify @var{dir} as the location of additional local Autoconf macros.
1906 This macro is intended for use by future versions of commands like
1907 @command{autoreconf} that trace macro calls.  It should be called
1908 directly from @file{configure.ac} so that tools that install macros for
1909 @command{aclocal} can find the macros' declarations.
1910 @end defmac
1913 @node Output
1914 @section Outputting Files
1915 @cindex Outputting files
1917 Every Autoconf script, e.g., @file{configure.ac}, should finish by
1918 calling @code{AC_OUTPUT}.  That is the macro that generates and runs
1919 @file{config.status}, which in turn creates the makefiles and any
1920 other files resulting from configuration.  This is the only required
1921 macro besides @code{AC_INIT} (@pxref{Input}).
1923 @defmac AC_OUTPUT
1924 @acindex{OUTPUT}
1925 @cindex Instantiation
1926 Generate @file{config.status} and launch it.  Call this macro once, at
1927 the end of @file{configure.ac}.
1929 @file{config.status} performs all the configuration actions: all the
1930 output files (see @ref{Configuration Files}, macro
1931 @code{AC_CONFIG_FILES}), header files (see @ref{Configuration Headers},
1932 macro @code{AC_CONFIG_HEADERS}), commands (see @ref{Configuration
1933 Commands}, macro @code{AC_CONFIG_COMMANDS}), links (see
1934 @ref{Configuration Links}, macro @code{AC_CONFIG_LINKS}), subdirectories
1935 to configure (see @ref{Subdirectories}, macro @code{AC_CONFIG_SUBDIRS})
1936 are honored.
1938 The location of your @code{AC_OUTPUT} invocation is the exact point
1939 where configuration actions are taken: any code afterwards is
1940 executed by @code{configure} once @command{config.status} was run.  If
1941 you want to bind actions to @command{config.status} itself
1942 (independently of whether @command{configure} is being run), see
1943 @ref{Configuration Commands, , Running Arbitrary Configuration
1944 Commands}.
1945 @end defmac
1947 Historically, the usage of @code{AC_OUTPUT} was somewhat different.
1948 @xref{Obsolete Macros}, for a description of the arguments that
1949 @code{AC_OUTPUT} used to support.
1952 If you run @command{make} in subdirectories, you should run it using the
1953 @code{make} variable @code{MAKE}.  Most versions of @command{make} set
1954 @code{MAKE} to the name of the @command{make} program plus any options it
1955 was given.  (But many do not include in it the values of any variables
1956 set on the command line, so those are not passed on automatically.)
1957 Some old versions of @command{make} do not set this variable.  The
1958 following macro allows you to use it even with those versions.
1960 @defmac AC_PROG_MAKE_SET
1961 @acindex{PROG_MAKE_SET}
1962 @ovindex SET_MAKE
1963 If the Make command, @code{$MAKE} if set or else @samp{make}, predefines
1964 @code{$(MAKE)}, define output variable @code{SET_MAKE} to be empty.
1965 Otherwise, define @code{SET_MAKE} to a macro definition that sets
1966 @code{$(MAKE)}, such as @samp{MAKE=make}.  Calls @code{AC_SUBST} for
1967 @code{SET_MAKE}.
1968 @end defmac
1970 If you use this macro, place a line like this in each @file{Makefile.in}
1971 that runs @code{MAKE} on other directories:
1973 @example
1974 @@SET_MAKE@@
1975 @end example
1979 @node Configuration Actions
1980 @section Performing Configuration Actions
1981 @cindex Configuration actions
1983 @file{configure} is designed so that it appears to do everything itself,
1984 but there is actually a hidden slave: @file{config.status}.
1985 @file{configure} is in charge of examining your system, but it is
1986 @file{config.status} that actually takes the proper actions based on the
1987 results of @file{configure}.  The most typical task of
1988 @file{config.status} is to @emph{instantiate} files.
1990 This section describes the common behavior of the four standard
1991 instantiating macros: @code{AC_CONFIG_FILES}, @code{AC_CONFIG_HEADERS},
1992 @code{AC_CONFIG_COMMANDS} and @code{AC_CONFIG_LINKS}.  They all
1993 have this prototype:
1995 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
1996 @c awful.
1997 @example
1998 AC_CONFIG_FOOS(@var{tag}@dots{}, [@var{commands}], [@var{init-cmds}])
1999 @end example
2001 @noindent
2002 where the arguments are:
2004 @table @var
2005 @item tag@dots{}
2006 A blank-or-newline-separated list of tags, which are typically the names of
2007 the files to instantiate.
2009 You are encouraged to use literals as @var{tags}.  In particular, you
2010 should avoid
2012 @example
2013 @dots{} && my_foos="$my_foos fooo"
2014 @dots{} && my_foos="$my_foos foooo"
2015 AC_CONFIG_FOOS([$my_foos])
2016 @end example
2018 @noindent
2019 and use this instead:
2021 @example
2022 @dots{} && AC_CONFIG_FOOS([fooo])
2023 @dots{} && AC_CONFIG_FOOS([foooo])
2024 @end example
2026 The macros @code{AC_CONFIG_FILES} and @code{AC_CONFIG_HEADERS} use
2027 special @var{tag} values: they may have the form @samp{@var{output}} or
2028 @samp{@var{output}:@var{inputs}}.  The file @var{output} is instantiated
2029 from its templates, @var{inputs} (defaulting to @samp{@var{output}.in}).
2031 @samp{AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk)]},
2032 for example, asks for
2033 the creation of the file @file{Makefile} that contains the expansion of the
2034 output variables in the concatenation of @file{boiler/top.mk} and
2035 @file{boiler/bot.mk}.
2037 The special value @samp{-} might be used to denote the standard output
2038 when used in @var{output}, or the standard input when used in the
2039 @var{inputs}.  You most probably don't need to use this in
2040 @file{configure.ac}, but it is convenient when using the command line
2041 interface of @file{./config.status}, see @ref{config.status Invocation},
2042 for more details.
2044 The @var{inputs} may be absolute or relative file names.  In the latter
2045 case they are first looked for in the build tree, and then in the source
2046 tree.
2048 @item commands
2049 Shell commands output literally into @file{config.status}, and
2050 associated with a tag that the user can use to tell @file{config.status}
2051 which the commands to run.  The commands are run each time a @var{tag}
2052 request is given to @file{config.status}, typically each time the file
2053 @file{@var{tag}} is created.
2055 The variables set during the execution of @command{configure} are
2056 @emph{not} available here: you first need to set them via the
2057 @var{init-cmds}.  Nonetheless the following variables are precomputed:
2059 @table @code
2060 @item srcdir
2061 The name of the top source directory, assuming that the working
2062 directory is the top build directory.  This
2063 is what the @command{configure} option @option{--srcdir} sets.
2065 @item ac_top_srcdir
2066 The name of the top source directory, assuming that the working
2067 directory is the current build directory.
2070 @item ac_top_build_prefix
2071 The name of the top build directory, assuming that the working
2072 directory is the current build directory.
2073 It can be empty, or else ends with a slash, so that you may concatenate
2076 @item ac_srcdir
2077 The name of the corresponding source directory, assuming that the
2078 working directory is the current build directory.
2079 @end table
2081 @noindent
2082 The @dfn{current} directory refers to the directory (or
2083 pseudo-directory) containing the input part of @var{tags}.  For
2084 instance, running
2086 @example
2087 AC_CONFIG_COMMANDS([deep/dir/out:in/in.in], [@dots{}], [@dots{}])
2088 @end example
2090 @noindent
2091  with @option{--srcdir=../package} produces the following values:
2093 @example
2094 # Argument of --srcdir
2095 srcdir='../package'
2096 # Reversing deep/dir
2097 ac_top_build_prefix='../../'
2098 # Concatenation of $ac_top_build_prefix and srcdir
2099 ac_top_srcdir='../../../package'
2100 # Concatenation of $ac_top_srcdir and deep/dir
2101 ac_srcdir='../../../package/deep/dir'
2102 @end example
2104 @noindent
2105 independently of @samp{in/in.in}.
2107 @item init-cmds
2108 Shell commands output @emph{unquoted} near the beginning of
2109 @file{config.status}, and executed each time @file{config.status} runs
2110 (regardless of the tag).  Because they are unquoted, for example,
2111 @samp{$var} is output as the value of @code{var}.  @var{init-cmds}
2112 is typically used by @file{configure} to give @file{config.status} some
2113 variables it needs to run the @var{commands}.
2115 You should be extremely cautious in your variable names: all the
2116 @var{init-cmds} share the same name space and may overwrite each other
2117 in unpredictable ways.  Sorry@enddots{}
2118 @end table
2120 All these macros can be called multiple times, with different
2121 @var{tag} values, of course!
2124 @node Configuration Files
2125 @section Creating Configuration Files
2126 @cindex Creating configuration files
2127 @cindex Configuration file creation
2129 Be sure to read the previous section, @ref{Configuration Actions}.
2131 @defmac AC_CONFIG_FILES (@var{file}@dots{}, @ovar{cmds}, @ovar{init-cmds})
2132 @acindex{CONFIG_FILES}
2133 Make @code{AC_OUTPUT} create each @file{@var{file}} by copying an input
2134 file (by default @file{@var{file}.in}), substituting the output variable
2135 values.
2136 @c Before we used to have this feature, which was later rejected
2137 @c because it complicates the writing of makefiles:
2138 @c If the file would be unchanged, it is left untouched, to preserve
2139 @c timestamp.
2140 This macro is one of the instantiating macros; see @ref{Configuration
2141 Actions}.  @xref{Makefile Substitutions}, for more information on using
2142 output variables.  @xref{Setting Output Variables}, for more information
2143 on creating them.  This macro creates the directory that the file is in
2144 if it doesn't exist.  Usually, makefiles are created this way,
2145 but other files, such as @file{.gdbinit}, can be specified as well.
2147 Typical calls to @code{AC_CONFIG_FILES} look like this:
2149 @example
2150 AC_CONFIG_FILES([Makefile src/Makefile man/Makefile X/Imakefile])
2151 AC_CONFIG_FILES([autoconf], [chmod +x autoconf])
2152 @end example
2154 You can override an input file name by appending to @var{file} a
2155 colon-separated list of input files.  Examples:
2157 @example
2158 AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk]
2159                 [lib/Makefile:boiler/lib.mk])
2160 @end example
2162 @noindent
2163 Doing this allows you to keep your file names acceptable to
2164 @acronym{DOS} variants, or
2165 to prepend and/or append boilerplate to the file.
2166 @end defmac
2170 @node Makefile Substitutions
2171 @section Substitutions in Makefiles
2172 @cindex Substitutions in makefiles
2173 @cindex Makefile substitutions
2175 Each subdirectory in a distribution that contains something to be
2176 compiled or installed should come with a file @file{Makefile.in}, from
2177 which @command{configure} creates a file @file{Makefile} in that directory.
2178 To create @file{Makefile}, @command{configure} performs a simple variable
2179 substitution, replacing occurrences of @samp{@@@var{variable}@@} in
2180 @file{Makefile.in} with the value that @command{configure} has determined
2181 for that variable.  Variables that are substituted into output files in
2182 this way are called @dfn{output variables}.  They are ordinary shell
2183 variables that are set in @command{configure}.  To make @command{configure}
2184 substitute a particular variable into the output files, the macro
2185 @code{AC_SUBST} must be called with that variable name as an argument.
2186 Any occurrences of @samp{@@@var{variable}@@} for other variables are
2187 left unchanged.  @xref{Setting Output Variables}, for more information
2188 on creating output variables with @code{AC_SUBST}.
2190 A software package that uses a @command{configure} script should be
2191 distributed with a file @file{Makefile.in}, but no makefile; that
2192 way, the user has to properly configure the package for the local system
2193 before compiling it.
2195 @xref{Makefile Conventions, , Makefile Conventions, standards, The
2196 @acronym{GNU} Coding Standards}, for more information on what to put in
2197 makefiles.
2199 @menu
2200 * Preset Output Variables::     Output variables that are always set
2201 * Installation Directory Variables::  Other preset output variables
2202 * Changed Directory Variables:: Warnings about @file{datarootdir}
2203 * Build Directories::           Supporting multiple concurrent compiles
2204 * Automatic Remaking::          Makefile rules for configuring
2205 @end menu
2207 @node Preset Output Variables
2208 @subsection Preset Output Variables
2209 @cindex Output variables
2211 Some output variables are preset by the Autoconf macros.  Some of the
2212 Autoconf macros set additional output variables, which are mentioned in
2213 the descriptions for those macros.  @xref{Output Variable Index}, for a
2214 complete list of output variables.  @xref{Installation Directory
2215 Variables}, for the list of the preset ones related to installation
2216 directories.  Below are listed the other preset ones.  They all are
2217 precious variables (@pxref{Setting Output Variables},
2218 @code{AC_ARG_VAR}).
2220 @c Just say no to ASCII sorting!  We're humans, not computers.
2221 @c These variables are listed as they would be in a dictionary:
2222 @c actor
2223 @c Actress
2224 @c actress
2226 @defvar CFLAGS
2227 @ovindex CFLAGS
2228 Debugging and optimization options for the C compiler.  If it is not set
2229 in the environment when @command{configure} runs, the default value is set
2230 when you call @code{AC_PROG_CC} (or empty if you don't).  @command{configure}
2231 uses this variable when compiling or linking programs to test for C features.
2233 If a compiler option affects only the behavior of the preprocessor
2234 (e.g., @option{-D @var{name}}), it should be put into @code{CPPFLAGS}
2235 instead.  If it affects only the linker (e.g., @option{-L
2236 @var{directory}}), it should be put into @code{LDFLAGS} instead.  If it
2237 affects only the compiler proper, @code{CFLAGS} is the natural home for
2238 it.  If an option affects multiple phases of the compiler, though,
2239 matters get tricky.  One approach to put such options directly into
2240 @code{CC}, e.g., @code{CC='gcc -m64'}.  Another is to put them into both
2241 @code{CPPFLAGS} and @code{LDFLAGS}, but not into @code{CFLAGS}.
2243 @end defvar
2245 @defvar configure_input
2246 @ovindex configure_input
2247 A comment saying that the file was generated automatically by
2248 @command{configure} and giving the name of the input file.
2249 @code{AC_OUTPUT} adds a comment line containing this variable to the top
2250 of every makefile it creates.  For other files, you should
2251 reference this variable in a comment at the top of each input file.  For
2252 example, an input shell script should begin like this:
2254 @example
2255 #!/bin/sh
2256 # @@configure_input@@
2257 @end example
2259 @noindent
2260 The presence of that line also reminds people editing the file that it
2261 needs to be processed by @command{configure} in order to be used.
2262 @end defvar
2264 @defvar CPPFLAGS
2265 @ovindex CPPFLAGS
2266 Preprocessor options for the C, C++, and Objective C preprocessors and
2267 compilers.  If
2268 it is not set in the environment when @command{configure} runs, the default
2269 value is empty.  @command{configure} uses this variable when preprocessing
2270 or compiling programs to test for C, C++, and Objective C features.
2272 This variable's contents should contain options like @option{-I},
2273 @option{-D}, and @option{-U} that affect only the behavior of the
2274 preprocessor.  Please see the explanation of @code{CFLAGS} for what you
2275 can do if an option affects other phases of the compiler as well.
2277 Currently, @command{configure} always links as part of a single
2278 invocation of the compiler that also preprocesses and compiles, so it
2279 uses this variable also when linking programs.  However, it is unwise to
2280 depend on this behavior because the @acronym{GNU} coding standards do
2281 not require it and many packages do not use @code{CPPFLAGS} when linking
2282 programs.
2284 @xref{Special Chars in Variables}, for limitations that @code{CPPFLAGS}
2285 might run into.
2286 @end defvar
2288 @defvar CXXFLAGS
2289 @ovindex CXXFLAGS
2290 Debugging and optimization options for the C++ compiler.  It acts like
2291 @code{CFLAGS}, but for C++ instead of C.
2292 @end defvar
2294 @defvar DEFS
2295 @ovindex DEFS
2296 @option{-D} options to pass to the C compiler.  If @code{AC_CONFIG_HEADERS}
2297 is called, @command{configure} replaces @samp{@@DEFS@@} with
2298 @option{-DHAVE_CONFIG_H} instead (@pxref{Configuration Headers}).  This
2299 variable is not defined while @command{configure} is performing its tests,
2300 only when creating the output files.  @xref{Setting Output Variables}, for
2301 how to check the results of previous tests.
2302 @end defvar
2304 @defvar ECHO_C
2305 @defvarx ECHO_N
2306 @defvarx ECHO_T
2307 @ovindex ECHO_C
2308 @ovindex ECHO_N
2309 @ovindex ECHO_T
2310 How does one suppress the trailing newline from @command{echo} for
2311 question-answer message pairs?  These variables provide a way:
2313 @example
2314 echo $ECHO_N "And the winner is... $ECHO_C"
2315 sleep 100000000000
2316 echo "$@{ECHO_T@}dead."
2317 @end example
2319 @noindent
2320 Some old and uncommon @command{echo} implementations offer no means to
2321 achieve this, in which case @code{ECHO_T} is set to tab.  You might not
2322 want to use it.
2323 @end defvar
2325 @defvar ERLCFLAGS
2326 @ovindex ERLCFLAGS
2327 Debugging and optimization options for the Erlang compiler.  If it is not set
2328 in the environment when @command{configure} runs, the default value is empty.
2329 @command{configure} uses this variable when compiling
2330 programs to test for Erlang features.
2331 @end defvar
2333 @defvar FCFLAGS
2334 @ovindex FCFLAGS
2335 Debugging and optimization options for the Fortran compiler.  If it
2336 is not set in the environment when @command{configure} runs, the default
2337 value is set when you call @code{AC_PROG_FC} (or empty if you don't).
2338 @command{configure} uses this variable when compiling or linking
2339 programs to test for Fortran features.
2340 @end defvar
2342 @defvar FFLAGS
2343 @ovindex FFLAGS
2344 Debugging and optimization options for the Fortran 77 compiler.  If it
2345 is not set in the environment when @command{configure} runs, the default
2346 value is set when you call @code{AC_PROG_F77} (or empty if you don't).
2347 @command{configure} uses this variable when compiling or linking
2348 programs to test for Fortran 77 features.
2349 @end defvar
2351 @defvar LDFLAGS
2352 @ovindex LDFLAGS
2353 Options for the linker.  If it is not set
2354 in the environment when @command{configure} runs, the default value is empty.
2355 @command{configure} uses this variable when linking programs to test for
2356 C, C++, Objective C, and Fortran features.
2358 This variable's contents should contain options like @option{-s} and
2359 @option{-L} that affect only the behavior of the linker.  Please see the
2360 explanation of @code{CFLAGS} for what you can do if an option also
2361 affects other phases of the compiler.
2363 Don't use this variable to pass library names
2364 (@option{-l}) to the linker; use @code{LIBS} instead.
2365 @end defvar
2367 @defvar LIBS
2368 @ovindex LIBS
2369 @option{-l} options to pass to the linker.  The default value is empty,
2370 but some Autoconf macros may prepend extra libraries to this variable if
2371 those libraries are found and provide necessary functions, see
2372 @ref{Libraries}.  @command{configure} uses this variable when linking
2373 programs to test for C, C++, and Fortran features.
2374 @end defvar
2376 @defvar OBJCFLAGS
2377 @ovindex OBJCFLAGS
2378 Debugging and optimization options for the Objective C compiler.  It
2379 acts like @code{CFLAGS}, but for Objective C instead of C.
2380 @end defvar
2382 @defvar builddir
2383 @ovindex builddir
2384 Rigorously equal to @samp{.}.  Added for symmetry only.
2385 @end defvar
2387 @defvar abs_builddir
2388 @ovindex abs_builddir
2389 Absolute name of @code{builddir}.
2390 @end defvar
2392 @defvar top_builddir
2393 @ovindex top_builddir
2394 The relative name of the top level of the current build tree.  In the
2395 top-level directory, this is the same as @code{builddir}.
2396 @end defvar
2398 @defvar abs_top_builddir
2399 @ovindex abs_top_builddir
2400 Absolute name of @code{top_builddir}.
2401 @end defvar
2403 @defvar srcdir
2404 @ovindex srcdir
2405 The name of the directory that contains the source code for
2406 that makefile.
2407 @end defvar
2409 @defvar abs_srcdir
2410 @ovindex abs_srcdir
2411 Absolute name of @code{srcdir}.
2412 @end defvar
2414 @defvar top_srcdir
2415 @ovindex top_srcdir
2416 The name of the top-level source code directory for the
2417 package.  In the top-level directory, this is the same as @code{srcdir}.
2418 @end defvar
2420 @defvar abs_top_srcdir
2421 @ovindex abs_top_srcdir
2422 Absolute name of @code{top_srcdir}.
2423 @end defvar
2425 @node Installation Directory Variables
2426 @subsection Installation Directory Variables
2427 @cindex Installation directories
2428 @cindex Directories, installation
2430 The following variables specify the directories for
2431 package installation, see @ref{Directory Variables, , Variables for
2432 Installation Directories, standards, The @acronym{GNU} Coding
2433 Standards}, for more information.  See the end of this section for
2434 details on when and how to use these variables.
2436 @defvar bindir
2437 @ovindex bindir
2438 The directory for installing executables that users run.
2439 @end defvar
2441 @defvar datadir
2442 @ovindex datadir
2443 The directory for installing idiosyncratic read-only
2444 architecture-independent data.
2445 @end defvar
2447 @defvar datarootdir
2448 @ovindex datarootdir
2449 The root of the directory tree for read-only architecture-independent
2450 data files.
2451 @end defvar
2453 @defvar docdir
2454 @ovindex docdir
2455 The directory for installing documentation files (other than Info and
2456 man).
2457 @end defvar
2459 @defvar dvidir
2460 @ovindex dvidir
2461 The directory for installing documentation files in DVI format.
2462 @end defvar
2464 @defvar exec_prefix
2465 @ovindex exec_prefix
2466 The installation prefix for architecture-dependent files.  By default
2467 it's the same as @var{prefix}.  You should avoid installing anything
2468 directly to @var{exec_prefix}.  However, the default value for
2469 directories containing architecture-dependent files should be relative
2470 to @var{exec_prefix}.
2471 @end defvar
2473 @defvar htmldir
2474 @ovindex htmldir
2475 The directory for installing HTML documentation.
2476 @end defvar
2478 @defvar includedir
2479 @ovindex includedir
2480 The directory for installing C header files.
2481 @end defvar
2483 @defvar infodir
2484 @ovindex infodir
2485 The directory for installing documentation in Info format.
2486 @end defvar
2488 @defvar libdir
2489 @ovindex libdir
2490 The directory for installing object code libraries.
2491 @end defvar
2493 @defvar libexecdir
2494 @ovindex libexecdir
2495 The directory for installing executables that other programs run.
2496 @end defvar
2498 @defvar localedir
2499 @ovindex localedir
2500 The directory for installing locale-dependent but
2501 architecture-independent data, such as message catalogs.  This directory
2502 usually has a subdirectory per locale.
2503 @end defvar
2505 @defvar localstatedir
2506 @ovindex localstatedir
2507 The directory for installing modifiable single-machine data.
2508 @end defvar
2510 @defvar mandir
2511 @ovindex mandir
2512 The top-level directory for installing documentation in man format.
2513 @end defvar
2515 @defvar oldincludedir
2516 @ovindex oldincludedir
2517 The directory for installing C header files for non-@acronym{GCC} compilers.
2518 @end defvar
2520 @defvar pdfdir
2521 @ovindex pdfdir
2522 The directory for installing PDF documentation.
2523 @end defvar
2525 @defvar prefix
2526 @ovindex prefix
2527 The common installation prefix for all files.  If @var{exec_prefix}
2528 is defined to a different value, @var{prefix} is used only for
2529 architecture-independent files.
2530 @end defvar
2532 @defvar psdir
2533 @ovindex psdir
2534 The directory for installing PostScript documentation.
2535 @end defvar
2537 @defvar sbindir
2538 @ovindex sbindir
2539 The directory for installing executables that system
2540 administrators run.
2541 @end defvar
2543 @defvar sharedstatedir
2544 @ovindex sharedstatedir
2545 The directory for installing modifiable architecture-independent data.
2546 @end defvar
2548 @defvar sysconfdir
2549 @ovindex sysconfdir
2550 The directory for installing read-only single-machine data.
2551 @end defvar
2554 Most of these variables have values that rely on @code{prefix} or
2555 @code{exec_prefix}.  It is deliberate that the directory output
2556 variables keep them unexpanded: typically @samp{@@datarootdir@@} is
2557 replaced by @samp{$@{prefix@}/share}, not @samp{/usr/local/share}, and
2558 @samp{@@datadir@@} is replaced by @samp{$@{datarootdir@}}.
2560 This behavior is mandated by the @acronym{GNU} coding standards, so that when
2561 the user runs:
2563 @table @samp
2564 @item make
2565 she can still specify a different prefix from the one specified to
2566 @command{configure}, in which case, if needed, the package should hard
2567 code dependencies corresponding to the make-specified prefix.
2569 @item make install
2570 she can specify a different installation location, in which case the
2571 package @emph{must} still depend on the location which was compiled in
2572 (i.e., never recompile when @samp{make install} is run).  This is an
2573 extremely important feature, as many people may decide to install all
2574 the files of a package grouped together, and then install links from
2575 the final locations to there.
2576 @end table
2578 In order to support these features, it is essential that
2579 @code{datarootdir} remains being defined as @samp{$@{prefix@}/share} to
2580 depend upon the current value of @code{prefix}.
2582 A corollary is that you should not use these variables except in
2583 makefiles.  For instance, instead of trying to evaluate @code{datadir}
2584 in @file{configure} and hard-coding it in makefiles using
2585 e.g., @samp{AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])},
2586 you should add
2587 @option{-DDATADIR='$(datadir)'} to your makefile's definition of
2588 @code{CPPFLAGS} (@code{AM_CPPFLAGS} if you are also using Automake).
2590 Similarly, you should not rely on @code{AC_CONFIG_FILES} to replace
2591 @code{datadir} and friends in your shell scripts and other files; instead,
2592 let @command{make} manage their replacement.  For instance Autoconf
2593 ships templates of its shell scripts ending with @samp{.in}, and uses a
2594 makefile snippet similar to the following to build scripts like
2595 @command{autoheader} and @command{autom4te}:
2597 @example
2598 @group
2599 edit = sed \
2600         -e 's|@@datadir[@@]|$(pkgdatadir)|g' \
2601         -e 's|@@prefix[@@]|$(prefix)|g'
2602 @end group
2604 @group
2605 autoheader autom4te: Makefile
2606         rm -f $@@ $@@.tmp
2607         $(edit) '$(srcdir)/$@@.in' >$@@.tmp
2608         chmod +x $@@.tmp
2609         chmod a-w $@@.tmp
2610         mv $@@.tmp $@@
2611 @end group
2613 @group
2614 autoheader: $(srcdir)/autoheader.in
2615 autom4te: $(srcdir)/autom4te.in
2616 @end group
2617 @end example
2619 Some details are noteworthy:
2621 @table @asis
2622 @item @samp{@@datadir[@@]}
2623 The brackets prevent @command{configure} from replacing
2624 @samp{@@datadir@@} in the Sed expression itself.
2625 Brackets are preferable to a backslash here, since
2626 Posix says @samp{\@@} is not portable.
2628 @item @samp{$(pkgdatadir)}
2629 Don't use @samp{@@pkgdatadir@@}!  Use the matching makefile variable
2630 instead.
2632 @item @samp{/}
2633 Don't use @samp{/} in the Sed expressions that replace file names since
2634 most likely the
2635 variables you use, such as @samp{$(pkgdatadir)}, contain @samp{/}.
2636 Use a shell metacharacter instead, such as @samp{|}.
2638 @item special characters
2639 File names, file name components, and the value of @code{VPATH} should
2640 not contain shell metacharacters or white
2641 space.  @xref{Special Chars in Variables}.
2643 @item dependency on @file{Makefile}
2644 Since @code{edit} uses values that depend on the configuration specific
2645 values (@code{prefix}, etc.)@: and not only on @code{VERSION} and so forth,
2646 the output depends on @file{Makefile}, not @file{configure.ac}.
2648 @item @samp{$@@}
2649 The main rule is generic, and uses @samp{$@@} extensively to
2650 avoid the need for multiple copies of the rule.
2652 @item Separated dependencies and single suffix rules
2653 You can't use them!  The above snippet cannot be (portably) rewritten
2656 @example
2657 autoconf autoheader: Makefile
2658 @group
2659 .in:
2660         rm -f $@@ $@@.tmp
2661         $(edit) $< >$@@.tmp
2662         chmod +x $@@.tmp
2663         mv $@@.tmp $@@
2664 @end group
2665 @end example
2667 @xref{Single Suffix Rules}, for details.
2669 @item @samp{$(srcdir)}
2670 Be sure to specify the name of the source directory,
2671 otherwise the package won't support separated builds.
2672 @end table
2674 For the more specific installation of Erlang libraries, the following variables
2675 are defined:
2677 @defvar ERLANG_INSTALL_LIB_DIR
2678 @ovindex ERLANG_INSTALL_LIB_DIR
2679 @acindex{ERLANG_SUBST_INSTALL_LIB_DIR}
2680 The common parent directory of Erlang library installation directories.
2681 This variable is set by calling the @code{AC_ERLANG_SUBST_INSTALL_LIB_DIR}
2682 macro in @file{configure.ac}.
2683 @end defvar
2685 @defvar ERLANG_INSTALL_LIB_DIR_@var{library}
2686 @ovindex ERLANG_INSTALL_LIB_DIR_@var{library}
2687 @acindex{ERLANG_SUBST_INSTALL_LIB_SUBDIR}
2688 The installation directory for Erlang library @var{library}.
2689 This variable is set by calling the
2690 @samp{AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(@var{library}, @var{version}}
2691 macro in @file{configure.ac}.
2692 @end defvar
2694 @xref{Erlang Libraries}, for details.
2697 @node Changed Directory Variables
2698 @subsection Changed Directory Variables
2699 @cindex @file{datarootdir}
2701 In Autoconf 2.60, the set of directory variables has changed, and the
2702 defaults of some variables have been adjusted
2703 (@pxref{Installation Directory Variables}) to changes in the
2704 @acronym{GNU} Coding Standards.  Notably, @file{datadir}, @file{infodir}, and
2705 @file{mandir} are now expressed in terms of @file{datarootdir}.  If you are
2706 upgrading from an earlier Autoconf version, you may need to adjust your files
2707 to ensure that the directory variables are substituted correctly
2708 (@pxref{Defining Directories}), and that a definition of @file{datarootdir} is
2709 in place.  For example, in a @file{Makefile.in}, adding
2711 @example
2712 datarootdir = @@datarootdir@@
2713 @end example
2715 @noindent
2716 is usually sufficient.  If you use Automake to create @file{Makefile.in},
2717 it will add this for you.
2719 To help with the transition, Autoconf warns about files that seem to use
2720 @code{datarootdir} without defining it.  In some cases, it then expands
2721 the value of @code{$datarootdir} in substitutions of the directory
2722 variables.  The following example shows such a warning:
2724 @example
2725 $ @kbd{cat configure.ac}
2726 AC_INIT
2727 AC_CONFIG_FILES([Makefile])
2728 AC_OUTPUT
2729 $ @kbd{cat Makefile.in}
2730 prefix = @@prefix@@
2731 datadir = @@datadir@@
2732 $ @kbd{autoconf}
2733 $ @kbd{configure}
2734 configure: creating ./config.status
2735 config.status: creating Makefile
2736 config.status: WARNING:
2737                Makefile.in seems to ignore the --datarootdir setting
2738 $ @kbd{cat Makefile}
2739 prefix = /usr/local
2740 datadir = $@{prefix@}/share
2741 @end example
2743 Usually one can easily change the file to accommodate both older and newer
2744 Autoconf releases:
2746 @example
2747 $ @kbd{cat Makefile.in}
2748 prefix = @@prefix@@
2749 datarootdir = @@datarootdir@@
2750 datadir = @@datadir@@
2751 $ @kbd{configure}
2752 configure: creating ./config.status
2753 config.status: creating Makefile
2754 $ @kbd{cat Makefile}
2755 prefix = /usr/local
2756 datarootdir = $@{prefix@}/share
2757 datadir = $@{datarootdir@}
2758 @end example
2760 @acindex{DATAROOTDIR_CHECKED}
2761 In some cases, however, the checks may not be able to detect that a suitable
2762 initialization of @code{datarootdir} is in place, or they may fail to detect
2763 that such an initialization is necessary in the output file.  If, after
2764 auditing your package, there are still spurious @file{configure} warnings about
2765 @code{datarootdir}, you may add the line
2767 @example
2768 AC_DEFUN([AC_DATAROOTDIR_CHECKED])
2769 @end example
2771 @noindent
2772 to your @file{configure.ac} to disable the warnings.  This is an exception
2773 to the usual rule that you should not define a macro whose name begins with
2774 @code{AC_} (@pxref{Macro Names}).
2778 @node Build Directories
2779 @subsection Build Directories
2780 @cindex Build directories
2781 @cindex Directories, build
2783 You can support compiling a software package for several architectures
2784 simultaneously from the same copy of the source code.  The object files
2785 for each architecture are kept in their own directory.
2787 To support doing this, @command{make} uses the @code{VPATH} variable to
2788 find the files that are in the source directory.  @acronym{GNU} Make
2789 can do this.  Most other recent @command{make} programs can do this as
2790 well, though they may have difficulties and it is often simpler to
2791 recommend @acronym{GNU} @command{make} (@pxref{VPATH and Make}).  Older
2792 @command{make} programs do not support @code{VPATH}; when using them, the
2793 source code must be in the same directory as the object files.
2795 To support @code{VPATH}, each @file{Makefile.in} should contain two
2796 lines that look like:
2798 @example
2799 srcdir = @@srcdir@@
2800 VPATH = @@srcdir@@
2801 @end example
2803 Do not set @code{VPATH} to the value of another variable, for example
2804 @samp{VPATH = $(srcdir)}, because some versions of @command{make} do not do
2805 variable substitutions on the value of @code{VPATH}.
2807 @command{configure} substitutes the correct value for @code{srcdir} when
2808 it produces @file{Makefile}.
2810 Do not use the @code{make} variable @code{$<}, which expands to the
2811 file name of the file in the source directory (found with @code{VPATH}),
2812 except in implicit rules.  (An implicit rule is one such as @samp{.c.o},
2813 which tells how to create a @file{.o} file from a @file{.c} file.)  Some
2814 versions of @command{make} do not set @code{$<} in explicit rules; they
2815 expand it to an empty value.
2817 Instead, Make command lines should always refer to source
2818 files by prefixing them with @samp{$(srcdir)/}.  For example:
2820 @example
2821 time.info: time.texinfo
2822         $(MAKEINFO) '$(srcdir)/time.texinfo'
2823 @end example
2825 @node Automatic Remaking
2826 @subsection Automatic Remaking
2827 @cindex Automatic remaking
2828 @cindex Remaking automatically
2830 You can put rules like the following in the top-level @file{Makefile.in}
2831 for a package to automatically update the configuration information when
2832 you change the configuration files.  This example includes all of the
2833 optional files, such as @file{aclocal.m4} and those related to
2834 configuration header files.  Omit from the @file{Makefile.in} rules for
2835 any of these files that your package does not use.
2837 The @samp{$(srcdir)/} prefix is included because of limitations in the
2838 @code{VPATH} mechanism.
2840 The @file{stamp-} files are necessary because the timestamps of
2841 @file{config.h.in} and @file{config.h} are not changed if remaking
2842 them does not change their contents.  This feature avoids unnecessary
2843 recompilation.  You should include the file @file{stamp-h.in} your
2844 package's distribution, so that @command{make} considers
2845 @file{config.h.in} up to date.  Don't use @command{touch}
2846 (@pxref{Limitations of Usual Tools}); instead, use @command{echo} (using
2847 @command{date} would cause needless differences, hence @acronym{CVS}
2848 conflicts, etc.).
2850 @example
2851 @group
2852 $(srcdir)/configure: configure.ac aclocal.m4
2853         cd '$(srcdir)' && autoconf
2855 # autoheader might not change config.h.in, so touch a stamp file.
2856 $(srcdir)/config.h.in: stamp-h.in
2857 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
2858         cd '$(srcdir)' && autoheader
2859         echo timestamp > '$(srcdir)/stamp-h.in'
2861 config.h: stamp-h
2862 stamp-h: config.h.in config.status
2863         ./config.status
2865 Makefile: Makefile.in config.status
2866         ./config.status
2868 config.status: configure
2869         ./config.status --recheck
2870 @end group
2871 @end example
2873 @noindent
2874 (Be careful if you copy these lines directly into your makefile, as you
2875 need to convert the indented lines to start with the tab character.)
2877 In addition, you should use
2879 @example
2880 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
2881 @end example
2883 @noindent
2884 so @file{config.status} ensures that @file{config.h} is considered up to
2885 date.  @xref{Output}, for more information about @code{AC_OUTPUT}.
2887 @xref{config.status Invocation}, for more examples of handling
2888 configuration-related dependencies.
2890 @node Configuration Headers
2891 @section Configuration Header Files
2892 @cindex Configuration Header
2893 @cindex @file{config.h}
2895 When a package contains more than a few tests that define C preprocessor
2896 symbols, the command lines to pass @option{-D} options to the compiler
2897 can get quite long.  This causes two problems.  One is that the
2898 @command{make} output is hard to visually scan for errors.  More
2899 seriously, the command lines can exceed the length limits of some
2900 operating systems.  As an alternative to passing @option{-D} options to
2901 the compiler, @command{configure} scripts can create a C header file
2902 containing @samp{#define} directives.  The @code{AC_CONFIG_HEADERS}
2903 macro selects this kind of output.  Though it can be called anywhere
2904 between @code{AC_INIT} and @code{AC_OUTPUT}, it is customary to call
2905 it right after @code{AC_INIT}.
2907 The package should @samp{#include} the configuration header file before
2908 any other header files, to prevent inconsistencies in declarations (for
2909 example, if it redefines @code{const}).
2911 To provide for VPATH builds, remember to pass the C compiler a @option{-I.}
2912 option (or @option{-I..}; whichever directory contains @file{config.h}).
2913 Even if you use @samp{#include "config.h"}, the preprocessor searches only
2914 the directory of the currently read file, i.e., the source directory, not
2915 the build directory.
2917 With the appropriate @option{-I} option, you can use
2918 @samp{#include <config.h>}.  Actually, it's a good habit to use it,
2919 because in the rare case when the source directory contains another
2920 @file{config.h}, the build directory should be searched first.
2923 @defmac AC_CONFIG_HEADERS (@var{header} @dots{}, @ovar{cmds}, @ovar{init-cmds})
2924 @acindex{CONFIG_HEADERS}
2925 @cvindex HAVE_CONFIG_H
2926 This macro is one of the instantiating macros; see @ref{Configuration
2927 Actions}.  Make @code{AC_OUTPUT} create the file(s) in the
2928 blank-or-newline-separated list @var{header} containing C preprocessor
2929 @code{#define} statements, and replace @samp{@@DEFS@@} in generated
2930 files with @option{-DHAVE_CONFIG_H} instead of the value of @code{DEFS}.
2931 The usual name for @var{header} is @file{config.h}.
2933 If @var{header} already exists and its contents are identical to what
2934 @code{AC_OUTPUT} would put in it, it is left alone.  Doing this allows
2935 making some changes in the configuration without needlessly causing
2936 object files that depend on the header file to be recompiled.
2938 Usually the input file is named @file{@var{header}.in}; however, you can
2939 override the input file name by appending to @var{header} a
2940 colon-separated list of input files.  For example, you might need to make
2941 the input file name acceptable to @acronym{DOS} variants:
2943 @example
2944 AC_CONFIG_HEADERS([config.h:config.hin])
2945 @end example
2947 @end defmac
2949 @defmac AH_HEADER
2950 @ahindex{HEADER}
2951 This macro is defined as the name of the first declared config header
2952 and undefined if no config headers have been declared up to this point.
2953 A third-party macro may, for example, require use of a config header
2954 without invoking AC_CONFIG_HEADERS twice, like this:
2956 @example
2957 AC_CONFIG_COMMANDS_PRE(
2958         [m4_ifndef([AH_HEADER], [AC_CONFIG_HEADERS([config.h])])])
2959 @end example
2961 @end defmac
2963 @xref{Configuration Actions}, for more details on @var{header}.
2965 @menu
2966 * Header Templates::            Input for the configuration headers
2967 * autoheader Invocation::       How to create configuration templates
2968 * Autoheader Macros::           How to specify CPP templates
2969 @end menu
2971 @node Header Templates
2972 @subsection Configuration Header Templates
2973 @cindex Configuration Header Template
2974 @cindex Header templates
2975 @cindex @file{config.h.in}
2977 Your distribution should contain a template file that looks as you want
2978 the final header file to look, including comments, with @code{#undef}
2979 statements which are used as hooks.  For example, suppose your
2980 @file{configure.ac} makes these calls:
2982 @example
2983 AC_CONFIG_HEADERS([conf.h])
2984 AC_CHECK_HEADERS([unistd.h])
2985 @end example
2987 @noindent
2988 Then you could have code like the following in @file{conf.h.in}.  On
2989 systems that have @file{unistd.h}, @command{configure} defines
2990 @samp{HAVE_UNISTD_H} to 1.  On other systems, the whole line is
2991 commented out (in case the system predefines that symbol).
2993 @example
2994 @group
2995 /* Define as 1 if you have unistd.h.  */
2996 #undef HAVE_UNISTD_H
2997 @end group
2998 @end example
3000 Pay attention that @samp{#undef} is in the first column, and there is
3001 nothing after @samp{HAVE_UNISTD_H}, not even white space.  You can
3002 then decode the configuration header using the preprocessor directives:
3004 @example
3005 @group
3006 #include <conf.h>
3008 #ifdef HAVE_UNISTD_H
3009 # include <unistd.h>
3010 #else
3011 /* We are in trouble.  */
3012 #endif
3013 @end group
3014 @end example
3016 The use of old form templates, with @samp{#define} instead of
3017 @samp{#undef} is strongly discouraged.  Similarly with old templates
3018 with comments on the same line as the @samp{#undef}.  Anyway, putting
3019 comments in preprocessor macros has never been a good idea.
3021 Since it is a tedious task to keep a template header up to date, you may
3022 use @command{autoheader} to generate it, see @ref{autoheader Invocation}.
3025 @node autoheader Invocation
3026 @subsection Using @command{autoheader} to Create @file{config.h.in}
3027 @cindex @command{autoheader}
3029 The @command{autoheader} program can create a template file of C
3030 @samp{#define} statements for @command{configure} to use.
3031 It searches for the first invocation of @code{AC_CONFIG_HEADERS} in
3032 @file{configure} sources to determine the name of the template.
3033 (If the first call of @code{AC_CONFIG_HEADERS} specifies more than one
3034 input file name, @command{autoheader} uses the first one.)
3036 It is recommended that only one input file is used.  If you want to append
3037 a boilerplate code, it is preferable to use
3038 @samp{AH_BOTTOM([#include <conf_post.h>])}.
3039 File @file{conf_post.h} is not processed during the configuration then,
3040 which make things clearer.  Analogically, @code{AH_TOP} can be used to
3041 prepend a boilerplate code.
3043 In order to do its job, @command{autoheader} needs you to document all
3044 of the symbols that you might use.  Typically this is done via an
3045 @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED} call whose first argument
3046 is a literal symbol and whose third argument describes the symbol
3047 (@pxref{Defining Symbols}).  Alternatively, you can use
3048 @code{AH_TEMPLATE} (@pxref{Autoheader Macros}), or you can supply a
3049 suitable input file for a subsequent configuration header file.
3050 Symbols defined by Autoconf's builtin tests are already documented properly;
3051 you need to document only those that you
3052 define yourself.
3054 You might wonder why @command{autoheader} is needed: after all, why
3055 would @command{configure} need to ``patch'' a @file{config.h.in} to
3056 produce a @file{config.h} instead of just creating @file{config.h} from
3057 scratch?  Well, when everything rocks, the answer is just that we are
3058 wasting our time maintaining @command{autoheader}: generating
3059 @file{config.h} directly is all that is needed.  When things go wrong,
3060 however, you'll be thankful for the existence of @command{autoheader}.
3062 The fact that the symbols are documented is important in order to
3063 @emph{check} that @file{config.h} makes sense.  The fact that there is a
3064 well-defined list of symbols that should be defined (or not) is
3065 also important for people who are porting packages to environments where
3066 @command{configure} cannot be run: they just have to @emph{fill in the
3067 blanks}.
3069 But let's come back to the point: the invocation of @command{autoheader}@dots{}
3071 If you give @command{autoheader} an argument, it uses that file instead
3072 of @file{configure.ac} and writes the header file to the standard output
3073 instead of to @file{config.h.in}.  If you give @command{autoheader} an
3074 argument of @option{-}, it reads the standard input instead of
3075 @file{configure.ac} and writes the header file to the standard output.
3077 @command{autoheader} accepts the following options:
3079 @table @option
3080 @item --help
3081 @itemx -h
3082 Print a summary of the command line options and exit.
3084 @item --version
3085 @itemx -V
3086 Print the version number of Autoconf and exit.
3088 @item --verbose
3089 @itemx -v
3090 Report processing steps.
3092 @item --debug
3093 @itemx -d
3094 Don't remove the temporary files.
3096 @item --force
3097 @itemx -f
3098 Remake the template file even if newer than its input files.
3100 @item --include=@var{dir}
3101 @itemx -I @var{dir}
3102 Append @var{dir} to the include path.  Multiple invocations accumulate.
3104 @item --prepend-include=@var{dir}
3105 @item -B @var{dir}
3106 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
3108 @item --warnings=@var{category}
3109 @itemx -W @var{category}
3110 @evindex WARNINGS
3111 Report the warnings related to @var{category} (which can actually be a
3112 comma separated list).  Current categories include:
3114 @table @samp
3115 @item obsolete
3116 report the uses of obsolete constructs
3118 @item all
3119 report all the warnings
3121 @item none
3122 report none
3124 @item error
3125 treats warnings as errors
3127 @item no-@var{category}
3128 disable warnings falling into @var{category}
3129 @end table
3131 @end table
3135 @node Autoheader Macros
3136 @subsection Autoheader Macros
3137 @cindex Autoheader macros
3139 @command{autoheader} scans @file{configure.ac} and figures out which C
3140 preprocessor symbols it might define.  It knows how to generate
3141 templates for symbols defined by @code{AC_CHECK_HEADERS},
3142 @code{AC_CHECK_FUNCS} etc., but if you @code{AC_DEFINE} any additional
3143 symbol, you must define a template for it.  If there are missing
3144 templates, @command{autoheader} fails with an error message.
3146 The template for a @var{symbol} is created
3147 by @command{autoheader} from
3148 the @var{description} argument to an @code{AC_DEFINE};
3149 see @ref{Defining Symbols}.
3151 For special needs, you can use the following macros.
3154 @defmac AH_TEMPLATE (@var{key}, @var{description})
3155 @ahindex{TEMPLATE}
3156 Tell @command{autoheader} to generate a template for @var{key}.  This macro
3157 generates standard templates just like @code{AC_DEFINE} when a
3158 @var{description} is given.
3160 For example:
3162 @example
3163 AH_TEMPLATE([CRAY_STACKSEG_END],
3164             [Define to one of _getb67, GETB67, getb67
3165              for Cray-2 and Cray-YMP systems.  This
3166              function is required for alloca.c support
3167              on those systems.])
3168 @end example
3170 @noindent
3171 generates the following template, with the description properly
3172 justified.
3174 @example
3175 /* Define to one of _getb67, GETB67, getb67 for Cray-2 and
3176    Cray-YMP systems.  This function is required for alloca.c
3177    support on those systems.  */
3178 #undef CRAY_STACKSEG_END
3179 @end example
3180 @end defmac
3183 @defmac AH_VERBATIM (@var{key}, @var{template})
3184 @ahindex{VERBATIM}
3185 Tell @command{autoheader} to include the @var{template} as-is in the header
3186 template file.  This @var{template} is associated with the @var{key},
3187 which is used to sort all the different templates and guarantee their
3188 uniqueness.  It should be a symbol that can be defined via @code{AC_DEFINE}.
3189 @end defmac
3192 @defmac AH_TOP (@var{text})
3193 @ahindex{TOP}
3194 Include @var{text} at the top of the header template file.
3195 @end defmac
3198 @defmac AH_BOTTOM (@var{text})
3199 @ahindex{BOTTOM}
3200 Include @var{text} at the bottom of the header template file.
3201 @end defmac
3204 Please note that @var{text} gets included ``verbatim'' to the template file,
3205 not to the resulting config header, so it can easily get mangled when the
3206 template is processed.  There is rarely a need for something other than
3208 @example
3209 AH_BOTTOM([#include <custom.h>])
3210 @end example
3214 @node Configuration Commands
3215 @section Running Arbitrary Configuration Commands
3216 @cindex Configuration commands
3217 @cindex Commands for configuration
3219 You can execute arbitrary commands before, during, and after
3220 @file{config.status} is run.  The three following macros accumulate the
3221 commands to run when they are called multiple times.
3222 @code{AC_CONFIG_COMMANDS} replaces the obsolete macro
3223 @code{AC_OUTPUT_COMMANDS}; see @ref{Obsolete Macros}, for details.
3225 @defmac AC_CONFIG_COMMANDS (@var{tag}@dots{}, @ovar{cmds}, @ovar{init-cmds})
3226 @acindex{CONFIG_COMMANDS}
3227 Specify additional shell commands to run at the end of
3228 @file{config.status}, and shell commands to initialize any variables
3229 from @command{configure}.  Associate the commands with @var{tag}.
3230 Since typically the @var{cmds} create a file, @var{tag} should
3231 naturally be the name of that file.  If needed, the directory hosting
3232 @var{tag} is created.  This macro is one of the instantiating macros;
3233 see @ref{Configuration Actions}.
3235 Here is an unrealistic example:
3236 @example
3237 fubar=42
3238 AC_CONFIG_COMMANDS([fubar],
3239                    [echo this is extra $fubar, and so on.],
3240                    [fubar=$fubar])
3241 @end example
3243 Here is a better one:
3244 @example
3245 AC_CONFIG_COMMANDS([timestamp], [date >timestamp])
3246 @end example
3247 @end defmac
3249 The following two macros look similar, but in fact they are not of the same
3250 breed: they are executed directly by @file{configure}, so you cannot use
3251 @file{config.status} to rerun them.
3253 @c Yet it is good to leave them here.  The user sees them together and
3254 @c decides which best fits their needs.
3256 @defmac AC_CONFIG_COMMANDS_PRE (@var{cmds})
3257 @acindex{CONFIG_COMMANDS_PRE}
3258 Execute the @var{cmds} right before creating @file{config.status}.
3260 This macro presents the last opportunity to call @code{AC_SUBST},
3261 @code{AC_DEFINE}, or @code{AC_CONFIG_FOOS} macros.
3262 @end defmac
3264 @defmac AC_CONFIG_COMMANDS_POST (@var{cmds})
3265 @acindex{CONFIG_COMMANDS_POST}
3266 Execute the @var{cmds} right after creating @file{config.status}.
3267 @end defmac
3272 @node Configuration Links
3273 @section Creating Configuration Links
3274 @cindex Configuration links
3275 @cindex Links for configuration
3277 You may find it convenient to create links whose destinations depend upon
3278 results of tests.  One can use @code{AC_CONFIG_COMMANDS} but the
3279 creation of relative symbolic links can be delicate when the package is
3280 built in a directory different from the source directory.
3282 @defmac AC_CONFIG_LINKS (@var{dest}:@var{source}@dots{}, @ovar{cmds}, @ovar{init-cmds})
3283 @acindex{CONFIG_LINKS}
3284 @cindex Links
3285 Make @code{AC_OUTPUT} link each of the existing files @var{source} to
3286 the corresponding link name @var{dest}.  Makes a symbolic link if
3287 possible, otherwise a hard link if possible, otherwise a copy.  The
3288 @var{dest} and @var{source} names should be relative to the top level
3289 source or build directory.  This macro is one of the instantiating
3290 macros; see @ref{Configuration Actions}.
3292 For example, this call:
3294 @example
3295 AC_CONFIG_LINKS([host.h:config/$machine.h
3296                 object.h:config/$obj_format.h])
3297 @end example
3299 @noindent
3300 creates in the current directory @file{host.h} as a link to
3301 @file{@var{srcdir}/config/$machine.h}, and @file{object.h} as a
3302 link to @file{@var{srcdir}/config/$obj_format.h}.
3304 The tempting value @samp{.} for @var{dest} is invalid: it makes it
3305 impossible for @samp{config.status} to guess the links to establish.
3307 One can then run:
3308 @example
3309 ./config.status host.h object.h
3310 @end example
3311 @noindent
3312 to create the links.
3313 @end defmac
3317 @node Subdirectories
3318 @section Configuring Other Packages in Subdirectories
3319 @cindex Configure subdirectories
3320 @cindex Subdirectory configure
3322 In most situations, calling @code{AC_OUTPUT} is sufficient to produce
3323 makefiles in subdirectories.  However, @command{configure} scripts
3324 that control more than one independent package can use
3325 @code{AC_CONFIG_SUBDIRS} to run @command{configure} scripts for other
3326 packages in subdirectories.
3328 @defmac AC_CONFIG_SUBDIRS (@var{dir} @dots{})
3329 @acindex{CONFIG_SUBDIRS}
3330 @ovindex subdirs
3331 Make @code{AC_OUTPUT} run @command{configure} in each subdirectory
3332 @var{dir} in the given blank-or-newline-separated list.  Each @var{dir} should
3333 be a literal, i.e., please do not use:
3335 @example
3336 if test "$package_foo_enabled" = yes; then
3337   $my_subdirs="$my_subdirs foo"
3339 AC_CONFIG_SUBDIRS([$my_subdirs])
3340 @end example
3342 @noindent
3343 because this prevents @samp{./configure --help=recursive} from
3344 displaying the options of the package @code{foo}.  Instead, you should
3345 write:
3347 @example
3348 if test "$package_foo_enabled" = yes; then
3349   AC_CONFIG_SUBDIRS([foo])
3351 @end example
3353 If a given @var{dir} is not found, an error is reported: if the
3354 subdirectory is optional, write:
3356 @example
3357 if test -d "$srcdir/foo"; then
3358   AC_CONFIG_SUBDIRS([foo])
3360 @end example
3362 @c NB: Yes, below we mean configure.in, not configure.ac.
3363 If a given @var{dir} contains @command{configure.gnu}, it is run instead
3364 of @command{configure}.  This is for packages that might use a
3365 non-Autoconf script @command{Configure}, which can't be called through a
3366 wrapper @command{configure} since it would be the same file on
3367 case-insensitive file systems.  Likewise, if a @var{dir} contains
3368 @file{configure.in} but no @command{configure}, the Cygnus
3369 @command{configure} script found by @code{AC_CONFIG_AUX_DIR} is used.
3371 The subdirectory @command{configure} scripts are given the same command
3372 line options that were given to this @command{configure} script, with minor
3373 changes if needed, which include:
3375 @itemize @minus
3376 @item
3377 adjusting a relative name for the cache file;
3379 @item
3380 adjusting a relative name for the source directory;
3382 @item
3383 propagating the current value of @code{$prefix}, including if it was
3384 defaulted, and if the default values of the top level and of the subdirectory
3385 @file{configure} differ.
3386 @end itemize
3388 This macro also sets the output variable @code{subdirs} to the list of
3389 directories @samp{@var{dir} @dots{}}.  Make rules can use
3390 this variable to determine which subdirectories to recurse into.
3392 This macro may be called multiple times.
3393 @end defmac
3395 @node Default Prefix
3396 @section Default Prefix
3397 @cindex Install prefix
3398 @cindex Prefix for install
3400 By default, @command{configure} sets the prefix for files it installs to
3401 @file{/usr/local}.  The user of @command{configure} can select a different
3402 prefix using the @option{--prefix} and @option{--exec-prefix} options.
3403 There are two ways to change the default: when creating
3404 @command{configure}, and when running it.
3406 Some software packages might want to install in a directory other than
3407 @file{/usr/local} by default.  To accomplish that, use the
3408 @code{AC_PREFIX_DEFAULT} macro.
3410 @defmac AC_PREFIX_DEFAULT (@var{prefix})
3411 @acindex{PREFIX_DEFAULT}
3412 Set the default installation prefix to @var{prefix} instead of
3413 @file{/usr/local}.
3414 @end defmac
3416 It may be convenient for users to have @command{configure} guess the
3417 installation prefix from the location of a related program that they
3418 have already installed.  If you wish to do that, you can call
3419 @code{AC_PREFIX_PROGRAM}.
3421 @defmac AC_PREFIX_PROGRAM (@var{program})
3422 @acindex{PREFIX_PROGRAM}
3423 If the user did not specify an installation prefix (using the
3424 @option{--prefix} option), guess a value for it by looking for
3425 @var{program} in @env{PATH}, the way the shell does.  If @var{program}
3426 is found, set the prefix to the parent of the directory containing
3427 @var{program}, else default the prefix as described above
3428 (@file{/usr/local} or @code{AC_PREFIX_DEFAULT}).  For example, if
3429 @var{program} is @code{gcc} and the @env{PATH} contains
3430 @file{/usr/local/gnu/bin/gcc}, set the prefix to @file{/usr/local/gnu}.
3431 @end defmac
3435 @c ======================================================== Existing tests
3437 @node Existing Tests
3438 @chapter Existing Tests
3440 These macros test for particular system features that packages might
3441 need or want to use.  If you need to test for a kind of feature that
3442 none of these macros check for, you can probably do it by calling
3443 primitive test macros with appropriate arguments (@pxref{Writing
3444 Tests}).
3446 These tests print messages telling the user which feature they're
3447 checking for, and what they find.  They cache their results for future
3448 @command{configure} runs (@pxref{Caching Results}).
3450 Some of these macros set output variables.  @xref{Makefile
3451 Substitutions}, for how to get their values.  The phrase ``define
3452 @var{name}'' is used below as a shorthand to mean ``define the C
3453 preprocessor symbol @var{name} to the value 1''.  @xref{Defining
3454 Symbols}, for how to get those symbol definitions into your program.
3456 @menu
3457 * Common Behavior::             Macros' standard schemes
3458 * Alternative Programs::        Selecting between alternative programs
3459 * Files::                       Checking for the existence of files
3460 * Libraries::                   Library archives that might be missing
3461 * Library Functions::           C library functions that might be missing
3462 * Header Files::                Header files that might be missing
3463 * Declarations::                Declarations that may be missing
3464 * Structures::                  Structures or members that might be missing
3465 * Types::                       Types that might be missing
3466 * Compilers and Preprocessors::  Checking for compiling programs
3467 * System Services::             Operating system services
3468 * Posix Variants::              Special kludges for specific Posix variants
3469 * Erlang Libraries::            Checking for the existence of Erlang libraries
3470 @end menu
3472 @node Common Behavior
3473 @section Common Behavior
3474 @cindex Common autoconf behavior
3476 Much effort has been expended to make Autoconf easy to learn.  The most
3477 obvious way to reach this goal is simply to enforce standard interfaces
3478 and behaviors, avoiding exceptions as much as possible.  Because of
3479 history and inertia, unfortunately, there are still too many exceptions
3480 in Autoconf; nevertheless, this section describes some of the common
3481 rules.
3483 @menu
3484 * Standard Symbols::            Symbols defined by the macros
3485 * Default Includes::            Includes used by the generic macros
3486 @end menu
3488 @node Standard Symbols
3489 @subsection Standard Symbols
3490 @cindex Standard symbols
3492 All the generic macros that @code{AC_DEFINE} a symbol as a result of
3493 their test transform their @var{argument} values to a standard alphabet.
3494 First, @var{argument} is converted to upper case and any asterisks
3495 (@samp{*}) are each converted to @samp{P}.  Any remaining characters
3496 that are not alphanumeric are converted to underscores.
3498 For instance,
3500 @example
3501 AC_CHECK_TYPES([struct $Expensive*])
3502 @end example
3504 @noindent
3505 defines the symbol @samp{HAVE_STRUCT__EXPENSIVEP} if the check
3506 succeeds.
3509 @node Default Includes
3510 @subsection Default Includes
3511 @cindex Default includes
3512 @cindex Includes, default
3514 Several tests depend upon a set of header files.  Since these headers
3515 are not universally available, tests actually have to provide a set of
3516 protected includes, such as:
3518 @example
3519 @group
3520 #ifdef TIME_WITH_SYS_TIME
3521 # include <sys/time.h>
3522 # include <time.h>
3523 #else
3524 # ifdef HAVE_SYS_TIME_H
3525 #  include <sys/time.h>
3526 # else
3527 #  include <time.h>
3528 # endif
3529 #endif
3530 @end group
3531 @end example
3533 @noindent
3534 Unless you know exactly what you are doing, you should avoid using
3535 unconditional includes, and check the existence of the headers you
3536 include beforehand (@pxref{Header Files}).
3538 Most generic macros use the following macro to provide the default set
3539 of includes:
3541 @defmac AC_INCLUDES_DEFAULT (@ovar{include-directives})
3542 @acindex{INCLUDES_DEFAULT}
3543 Expand to @var{include-directives} if defined, otherwise to:
3545 @example
3546 @group
3547 #include <stdio.h>
3548 #ifdef HAVE_SYS_TYPES_H
3549 # include <sys/types.h>
3550 #endif
3551 #ifdef HAVE_SYS_STAT_H
3552 # include <sys/stat.h>
3553 #endif
3554 #ifdef STDC_HEADERS
3555 # include <stdlib.h>
3556 # include <stddef.h>
3557 #else
3558 # ifdef HAVE_STDLIB_H
3559 #  include <stdlib.h>
3560 # endif
3561 #endif
3562 #ifdef HAVE_STRING_H
3563 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
3564 #  include <memory.h>
3565 # endif
3566 # include <string.h>
3567 #endif
3568 #ifdef HAVE_STRINGS_H
3569 # include <strings.h>
3570 #endif
3571 #ifdef HAVE_INTTYPES_H
3572 # include <inttypes.h>
3573 #endif
3574 #ifdef HAVE_STDINT_H
3575 # include <stdint.h>
3576 #endif
3577 #ifdef HAVE_UNISTD_H
3578 # include <unistd.h>
3579 #endif
3580 @end group
3581 @end example
3583 If the default includes are used, then check for the presence of these
3584 headers and their compatibility, i.e., you don't need to run
3585 @code{AC_HEADER_STDC}, nor check for @file{stdlib.h} etc.
3587 These headers are checked for in the same order as they are included.
3588 For instance, on some systems @file{string.h} and @file{strings.h} both
3589 exist, but conflict.  Then @code{HAVE_STRING_H} is defined, not
3590 @code{HAVE_STRINGS_H}.
3591 @end defmac
3593 @node Alternative Programs
3594 @section Alternative Programs
3595 @cindex Programs, checking
3597 These macros check for the presence or behavior of particular programs.
3598 They are used to choose between several alternative programs and to
3599 decide what to do once one has been chosen.  If there is no macro
3600 specifically defined to check for a program you need, and you don't need
3601 to check for any special properties of it, then you can use one of the
3602 general program-check macros.
3604 @menu
3605 * Particular Programs::         Special handling to find certain programs
3606 * Generic Programs::            How to find other programs
3607 @end menu
3609 @node Particular Programs
3610 @subsection Particular Program Checks
3612 These macros check for particular programs---whether they exist, and
3613 in some cases whether they support certain features.
3615 @defmac AC_PROG_AWK
3616 @acindex{PROG_AWK}
3617 @ovindex AWK
3618 Check for @code{gawk}, @code{mawk}, @code{nawk}, and @code{awk}, in that
3619 order, and set output variable @code{AWK} to the first one that is found.
3620 It tries @code{gawk} first because that is reported to be the
3621 best implementation.
3622 @end defmac
3624 @defmac AC_PROG_GREP
3625 @acindex{PROG_GREP}
3626 @ovindex GREP
3627 Look for the best available @code{grep} or @code{ggrep} that accepts the
3628 longest input lines possible, and that supports multiple @option{-e} options.
3629 Set the output variable @code{GREP} to whatever is chosen.
3630 @xref{Limitations of Usual Tools}, for more information about
3631 portability problems with the @command{grep} command family.
3632 @end defmac
3634 @defmac AC_PROG_EGREP
3635 @acindex{PROG_EGREP}
3636 @ovindex EGREP
3637 Check whether @code{$GREP -E} works, or else look for the best available
3638 @code{egrep} or @code{gegrep} that accepts the longest input lines possible.
3639 Set the output variable @code{EGREP} to whatever is chosen.
3640 @end defmac
3642 @defmac AC_PROG_FGREP
3643 @acindex{PROG_FGREP}
3644 @ovindex FGREP
3645 Check whether @code{$GREP -F} works, or else look for the best available
3646 @code{fgrep} or @code{gfgrep} that accepts the longest input lines possible.
3647 Set the output variable @code{FGREP} to whatever is chosen.
3648 @end defmac
3650 @defmac AC_PROG_INSTALL
3651 @acindex{PROG_INSTALL}
3652 @ovindex INSTALL
3653 @ovindex INSTALL_PROGRAM
3654 @ovindex INSTALL_DATA
3655 @ovindex INSTALL_SCRIPT
3656 Set output variable @code{INSTALL} to the name of a @acronym{BSD}-compatible
3657 @command{install} program, if one is found in the current @env{PATH}.
3658 Otherwise, set @code{INSTALL} to @samp{@var{dir}/install-sh -c},
3659 checking the directories specified to @code{AC_CONFIG_AUX_DIR} (or its
3660 default directories) to determine @var{dir} (@pxref{Output}).  Also set
3661 the variables @code{INSTALL_PROGRAM} and @code{INSTALL_SCRIPT} to
3662 @samp{$@{INSTALL@}} and @code{INSTALL_DATA} to @samp{$@{INSTALL@} -m 644}.
3664 @samp{@@INSTALL@@} is special, as its value may vary for different
3665 configuration files.
3667 This macro screens out various instances of @command{install} known not to
3668 work.  It prefers to find a C program rather than a shell script, for
3669 speed.  Instead of @file{install-sh}, it can also use @file{install.sh},
3670 but that name is obsolete because some @command{make} programs have a rule
3671 that creates @file{install} from it if there is no makefile.
3673 Autoconf comes with a copy of @file{install-sh} that you can use.  If
3674 you use @code{AC_PROG_INSTALL}, you must include either
3675 @file{install-sh} or @file{install.sh} in your distribution; otherwise
3676 @command{configure} produces an error message saying it can't find
3677 them---even if the system you're on has a good @command{install} program.
3678 This check is a safety measure to prevent you from accidentally leaving
3679 that file out, which would prevent your package from installing on
3680 systems that don't have a @acronym{BSD}-compatible @command{install} program.
3682 If you need to use your own installation program because it has features
3683 not found in standard @command{install} programs, there is no reason to use
3684 @code{AC_PROG_INSTALL}; just put the file name of your program into your
3685 @file{Makefile.in} files.
3686 @end defmac
3688 @defmac AC_PROG_MKDIR_P
3689 @acindex{AC_PROG_MKDIR_P}
3690 @ovindex MKDIR_P
3691 Set output variable @code{MKDIR_P} to a program that ensures that for
3692 each argument, a directory named by this argument exists, creating it
3693 and its parent directories if needed, and without race conditions when
3694 two instances of the program attempt to make the same directory at
3695 nearly the same time.
3697 This macro uses the @samp{mkdir -p} command if possible.  Otherwise, it
3698 falls back on invoking @command{install-sh} with the @option{-d} option,
3699 so your package should
3700 contain @file{install-sh} as described under @code{AC_PROG_INSTALL}.
3701 An @file{install-sh} file that predates Autoconf 2.60 or Automake 1.10
3702 is vulnerable to race conditions, so if you want to support parallel
3703 installs from
3704 different packages into the same directory you need to make sure you
3705 have an up-to-date @file{install-sh}.  In particular, be careful about
3706 using @samp{autoreconf -if} if your Automake predates Automake 1.10.
3708 This macro is related to the @code{AS_MKDIR_P} macro (@pxref{Programming
3709 in M4sh}), but it sets an output variable intended for use in other
3710 files, whereas @code{AS_MKDIR_P} is intended for use in scripts like
3711 @command{configure}.  Also, @code{AS_MKDIR_P} does not accept options,
3712 but @code{MKDIR_P} supports the @option{-m} option, e.g., a makefile
3713 might invoke @code{$(MKDIR_P) -m 0 dir} to create an inaccessible
3714 directory, and conversely a makefile should use @code{$(MKDIR_P) --
3715 $(FOO)} if @var{FOO} might yield a value that begins with @samp{-}.
3716 Finally, @code{AS_MKDIR_P} does not check for race condition
3717 vulnerability, whereas @code{AC_PROG_MKDIR_P} does.
3719 @samp{@@MKDIR_P@@} is special, as its value may vary for different
3720 configuration files.
3721 @end defmac
3723 @defmac AC_PROG_LEX
3724 @acindex{PROG_LEX}
3725 @ovindex LEX
3726 @ovindex LEXLIB
3727 @cvindex YYTEXT_POINTER
3728 @ovindex LEX_OUTPUT_ROOT
3729 If @code{flex} is found, set output variable @code{LEX} to @samp{flex}
3730 and @code{LEXLIB} to @option{-lfl}, if that library is in a standard
3731 place.  Otherwise set @code{LEX} to @samp{lex} and @code{LEXLIB} to
3732 @option{-ll}.
3734 Define @code{YYTEXT_POINTER} if @code{yytext} defaults to @samp{char *} instead
3735 of to @samp{char []}.  Also set output variable @code{LEX_OUTPUT_ROOT} to
3736 the base of the file name that the lexer generates; usually
3737 @file{lex.yy}, but sometimes something else.  These results vary
3738 according to whether @code{lex} or @code{flex} is being used.
3740 You are encouraged to use Flex in your sources, since it is both more
3741 pleasant to use than plain Lex and the C source it produces is portable.
3742 In order to ensure portability, however, you must either provide a
3743 function @code{yywrap} or, if you don't use it (e.g., your scanner has
3744 no @samp{#include}-like feature), simply include a @samp{%noyywrap}
3745 statement in the scanner's source.  Once this done, the scanner is
3746 portable (unless @emph{you} felt free to use nonportable constructs) and
3747 does not depend on any library.  In this case, and in this case only, it
3748 is suggested that you use this Autoconf snippet:
3750 @example
3751 AC_PROG_LEX
3752 if test "$LEX" != flex; then
3753   LEX="$SHELL $missing_dir/missing flex"
3754   AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
3755   AC_SUBST([LEXLIB], [''])
3757 @end example
3759 The shell script @command{missing} can be found in the Automake
3760 distribution.
3762 To ensure backward compatibility, Automake's @code{AM_PROG_LEX} invokes
3763 (indirectly) this macro twice, which causes an annoying but benign
3764 ``@code{AC_PROG_LEX} invoked multiple times'' warning.  Future versions
3765 of Automake will fix this issue; meanwhile, just ignore this message.
3767 As part of running the test, this macro may delete any file in the
3768 configuration directory named @file{lex.yy.c} or @file{lexyy.c}.
3769 @end defmac
3771 @defmac AC_PROG_LN_S
3772 @acindex{PROG_LN_S}
3773 @ovindex LN_S
3774 If @samp{ln -s} works on the current file system (the operating system
3775 and file system support symbolic links), set the output variable
3776 @code{LN_S} to @samp{ln -s}; otherwise, if @samp{ln} works, set
3777 @code{LN_S} to @samp{ln}, and otherwise set it to @samp{cp -p}.
3779 If you make a link in a directory other than the current directory, its
3780 meaning depends on whether @samp{ln} or @samp{ln -s} is used.  To safely
3781 create links using @samp{$(LN_S)}, either find out which form is used
3782 and adjust the arguments, or always invoke @code{ln} in the directory
3783 where the link is to be created.
3785 In other words, it does not work to do:
3786 @example
3787 $(LN_S) foo /x/bar
3788 @end example
3790 Instead, do:
3792 @example
3793 (cd /x && $(LN_S) foo bar)
3794 @end example
3795 @end defmac
3797 @defmac AC_PROG_RANLIB
3798 @acindex{PROG_RANLIB}
3799 @ovindex RANLIB
3800 Set output variable @code{RANLIB} to @samp{ranlib} if @code{ranlib}
3801 is found, and otherwise to @samp{:} (do nothing).
3802 @end defmac
3804 @defmac AC_PROG_SED
3805 @acindex{PROG_SED}
3806 @ovindex SED
3807 Set output variable @code{SED} to a Sed implementation that conforms to
3808 Posix and does not have arbitrary length limits.  Report an error if no
3809 acceptable Sed is found.  @xref{Limitations of Usual Tools}, for more
3810 information about portability problems with Sed.
3811 @end defmac
3813 @defmac AC_PROG_YACC
3814 @acindex{PROG_YACC}
3815 @ovindex YACC
3816 If @code{bison} is found, set output variable @code{YACC} to @samp{bison
3817 -y}.  Otherwise, if @code{byacc} is found, set @code{YACC} to
3818 @samp{byacc}.  Otherwise set @code{YACC} to @samp{yacc}.
3819 @end defmac
3821 @node Generic Programs
3822 @subsection Generic Program and File Checks
3824 These macros are used to find programs not covered by the ``particular''
3825 test macros.  If you need to check the behavior of a program as well as
3826 find out whether it is present, you have to write your own test for it
3827 (@pxref{Writing Tests}).  By default, these macros use the environment
3828 variable @env{PATH}.  If you need to check for a program that might not
3829 be in the user's @env{PATH}, you can pass a modified path to use
3830 instead, like this:
3832 @example
3833 AC_PATH_PROG([INETD], [inetd], [/usr/libexec/inetd],
3834              [$PATH:/usr/libexec:/usr/sbin:/usr/etc:/etc])
3835 @end example
3837 You are strongly encouraged to declare the @var{variable} passed to
3838 @code{AC_CHECK_PROG} etc.@: as precious, @xref{Setting Output Variables},
3839 @code{AC_ARG_VAR}, for more details.
3841 @defmac AC_CHECK_PROG (@var{variable}, @var{prog-to-check-for}, @var{value-if-found}, @ovar{value-if-not-found}, @ovar{path},  @ovar{reject})
3842 @acindex{CHECK_PROG}
3843 Check whether program @var{prog-to-check-for} exists in @env{PATH}.  If
3844 it is found, set @var{variable} to @var{value-if-found}, otherwise to
3845 @var{value-if-not-found}, if given.  Always pass over @var{reject} (an
3846 absolute file name) even if it is the first found in the search path; in
3847 that case, set @var{variable} using the absolute file name of the
3848 @var{prog-to-check-for} found that is not @var{reject}.  If
3849 @var{variable} was already set, do nothing.  Calls @code{AC_SUBST} for
3850 @var{variable}.
3851 @end defmac
3853 @defmac AC_CHECK_PROGS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3854 @acindex{CHECK_PROGS}
3855 Check for each program in the blank-separated list
3856 @var{progs-to-check-for} existing in the @env{PATH}.  If one is found, set
3857 @var{variable} to the name of that program.  Otherwise, continue
3858 checking the next program in the list.  If none of the programs in the
3859 list are found, set @var{variable} to @var{value-if-not-found}; if
3860 @var{value-if-not-found} is not specified, the value of @var{variable}
3861 is not changed.  Calls @code{AC_SUBST} for @var{variable}.
3862 @end defmac
3864 @defmac AC_CHECK_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3865 @acindex{CHECK_TARGET_TOOL}
3866 Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
3867 with a prefix of the target type as determined by
3868 @code{AC_CANONICAL_TARGET}, followed by a dash (@pxref{Canonicalizing}).
3869 If the tool cannot be found with a prefix, and if the build and target
3870 types are equal, then it is also searched for without a prefix.
3872 As noted in @ref{Specifying Names, , Specifying the system type}, the
3873 target is rarely specified, because most of the time it is the same
3874 as the host: it is the type of system for which any compiler tool in
3875 the package produces code.  What this macro looks for is,
3876 for example, @emph{a tool @r{(assembler, linker, etc.)}@: that the
3877 compiler driver @r{(@command{gcc} for the @acronym{GNU} C Compiler)}
3878 uses to produce objects, archives or executables}.
3879 @end defmac
3881 @defmac AC_CHECK_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3882 @acindex{CHECK_TOOL}
3883 Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
3884 with a prefix of the host type as determined by
3885 @code{AC_CANONICAL_HOST}, followed by a dash (@pxref{Canonicalizing}).
3886 For example, if the user runs @samp{configure --host=i386-gnu}, then
3887 this call:
3888 @example
3889 AC_CHECK_TOOL([RANLIB], [ranlib], [:])
3890 @end example
3891 @noindent
3892 sets @code{RANLIB} to @file{i386-gnu-ranlib} if that program exists in
3893 @env{PATH}, or otherwise to @samp{ranlib} if that program exists in
3894 @env{PATH}, or to @samp{:} if neither program exists.
3896 In the future, when cross-compiling this macro will @emph{only}
3897 accept program names that are prefixed with the host type.
3898 For more information, see @ref{Specifying Names, , Specifying the
3899 system type}.
3900 @end defmac
3902 @defmac AC_CHECK_TARGET_TOOLS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3903 @acindex{CHECK_TARGET_TOOLS}
3904 Like @code{AC_CHECK_TARGET_TOOL}, each of the tools in the list
3905 @var{progs-to-check-for} are checked with a prefix of the target type as
3906 determined by @code{AC_CANONICAL_TARGET}, followed by a dash
3907 (@pxref{Canonicalizing}).  If none of the tools can be found with a
3908 prefix, and if the build and target types are equal, then the first one
3909 without a prefix is used.  If a tool is found, set @var{variable} to
3910 the name of that program.  If none of the tools in the list are found,
3911 set @var{variable} to @var{value-if-not-found}; if @var{value-if-not-found}
3912 is not specified, the value of @var{variable} is not changed.  Calls
3913 @code{AC_SUBST} for @var{variable}.
3914 @end defmac
3916 @defmac AC_CHECK_TOOLS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3917 @acindex{CHECK_TOOLS}
3918 Like @code{AC_CHECK_TOOL}, each of the tools in the list
3919 @var{progs-to-check-for} are checked with a prefix of the host type as
3920 determined by @code{AC_CANONICAL_HOST}, followed by a dash
3921 (@pxref{Canonicalizing}).  If none of the tools can be found with a
3922 prefix, then the first one without a prefix is used.  If a tool is found,
3923 set @var{variable} to the name of that program.  If none of the tools in
3924 the list are found, set @var{variable} to @var{value-if-not-found}; if
3925 @var{value-if-not-found} is not specified, the value of @var{variable}
3926 is not changed.  Calls @code{AC_SUBST} for @var{variable}.
3928 In the future, when cross-compiling this macro will @emph{not}
3929 accept program names that are not prefixed with the host type.
3930 @end defmac
3932 @defmac AC_PATH_PROG (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3933 @acindex{PATH_PROG}
3934 Like @code{AC_CHECK_PROG}, but set @var{variable} to the absolute
3935 name of @var{prog-to-check-for} if found.
3936 @end defmac
3938 @defmac AC_PATH_PROGS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3939 @acindex{PATH_PROGS}
3940 Like @code{AC_CHECK_PROGS}, but if any of @var{progs-to-check-for}
3941 are found, set @var{variable} to the absolute name of the program
3942 found.
3943 @end defmac
3945 @defmac AC_PATH_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3946 @acindex{PATH_TARGET_TOOL}
3947 Like @code{AC_CHECK_TARGET_TOOL}, but set @var{variable} to the absolute
3948 name of the program if it is found.
3949 @end defmac
3951 @defmac AC_PATH_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3952 @acindex{PATH_TOOL}
3953 Like @code{AC_CHECK_TOOL}, but set @var{variable} to the absolute
3954 name of the program if it is found.
3956 In the future, when cross-compiling this macro will @emph{not}
3957 accept program names that are not prefixed with the host type.
3958 @end defmac
3961 @node Files
3962 @section Files
3963 @cindex File, checking
3965 You might also need to check for the existence of files.  Before using
3966 these macros, ask yourself whether a runtime test might not be a better
3967 solution.  Be aware that, like most Autoconf macros, they test a feature
3968 of the host machine, and therefore, they die when cross-compiling.
3970 @defmac AC_CHECK_FILE (@var{file}, @ovar{action-if-found}, @ovar{action-if-not-found})
3971 @acindex{CHECK_FILE}
3972 Check whether file @var{file} exists on the native system.  If it is
3973 found, execute @var{action-if-found}, otherwise do
3974 @var{action-if-not-found}, if given.
3975 @end defmac
3977 @defmac AC_CHECK_FILES (@var{files}, @ovar{action-if-found}, @ovar{action-if-not-found})
3978 @acindex{CHECK_FILES}
3979 Executes @code{AC_CHECK_FILE} once for each file listed in @var{files}.
3980 Additionally, defines @samp{HAVE_@var{file}} (@pxref{Standard Symbols})
3981 for each file found.
3982 @end defmac
3985 @node Libraries
3986 @section Library Files
3987 @cindex Library, checking
3989 The following macros check for the presence of certain C, C++, or Fortran
3990 library archive files.
3992 @defmac AC_CHECK_LIB (@var{library}, @var{function}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
3993 @acindex{CHECK_LIB}
3994 Test whether the library @var{library} is available by trying to link
3995 a test program that calls function @var{function} with the library.
3996 @var{function} should be a function provided by the library.
3997 Use the base
3998 name of the library; e.g., to check for @option{-lmp}, use @samp{mp} as
3999 the @var{library} argument.
4001 @var{action-if-found} is a list of shell commands to run if the link
4002 with the library succeeds; @var{action-if-not-found} is a list of shell
4003 commands to run if the link fails.  If @var{action-if-found} is not
4004 specified, the default action prepends @option{-l@var{library}} to
4005 @code{LIBS} and defines @samp{HAVE_LIB@var{library}} (in all
4006 capitals).  This macro is intended to support building @code{LIBS} in
4007 a right-to-left (least-dependent to most-dependent) fashion such that
4008 library dependencies are satisfied as a natural side effect of
4009 consecutive tests.  Linkers are sensitive to library ordering
4010 so the order in which @code{LIBS} is generated is important to reliable
4011 detection of libraries.
4013 If linking with @var{library} results in unresolved symbols that would
4014 be resolved by linking with additional libraries, give those libraries
4015 as the @var{other-libraries} argument, separated by spaces:
4016 e.g., @option{-lXt -lX11}.  Otherwise, this macro fails to detect
4017 that @var{library} is present, because linking the test program
4018 always fails with unresolved symbols.  The @var{other-libraries} argument
4019 should be limited to cases where it is desirable to test for one library
4020 in the presence of another that is not already in @code{LIBS}.
4022 @code{AC_CHECK_LIB} requires some care in usage, and should be avoided
4023 in some common cases.  Many standard functions like @code{gethostbyname}
4024 appear the standard C library on some hosts, and in special libraries
4025 like @code{nsl} on other hosts.  On some hosts the special libraries
4026 contain variant implementations that you may not want to use.  These
4027 days it is normally better to use @code{AC_SEARCH_LIBS([gethostbyname],
4028 [nsl])} instead of @code{AC_CHECK_LIB([nsl], [gethostbyname])}.
4029 @end defmac
4032 @defmac AC_SEARCH_LIBS (@var{function}, @var{search-libs}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
4033 @acindex{SEARCH_LIBS}
4034 Search for a library defining @var{function} if it's not already
4035 available.  This equates to calling
4036 @samp{AC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])])} first with
4037 no libraries, then for each library listed in @var{search-libs}.
4039 Add @option{-l@var{library}} to @code{LIBS} for the first library found
4040 to contain @var{function}, and run @var{action-if-found}.  If the
4041 function is not found, run @var{action-if-not-found}.
4043 If linking with @var{library} results in unresolved symbols that would
4044 be resolved by linking with additional libraries, give those libraries
4045 as the @var{other-libraries} argument, separated by spaces:
4046 e.g., @option{-lXt -lX11}.  Otherwise, this macro fails to detect
4047 that @var{function} is present, because linking the test program
4048 always fails with unresolved symbols.
4049 @end defmac
4053 @node Library Functions
4054 @section Library Functions
4056 The following macros check for particular C library functions.
4057 If there is no macro specifically defined to check for a function you need,
4058 and you don't need to check for any special properties of
4059 it, then you can use one of the general function-check macros.
4061 @menu
4062 * Function Portability::        Pitfalls with usual functions
4063 * Particular Functions::        Special handling to find certain functions
4064 * Generic Functions::           How to find other functions
4065 @end menu
4067 @node Function Portability
4068 @subsection Portability of C Functions
4069 @cindex Portability of C functions
4070 @cindex C function portability
4072 Most usual functions can either be missing, or be buggy, or be limited
4073 on some architectures.  This section tries to make an inventory of these
4074 portability issues.  By definition, this list always requires
4075 additions.  Please help us keeping it as complete as possible.
4077 @table @asis
4078 @item @code{exit}
4079 @c @fuindex exit
4080 @prindex @code{exit}
4081 On ancient hosts, @code{exit} returned @code{int}.
4082 This is because @code{exit} predates @code{void}, and there was a long
4083 tradition of it returning @code{int}.
4085 On current hosts, the problem more likely is that @code{exit} is not
4086 declared, due to C++ problems of some sort or another.  For this reason
4087 we suggest that test programs not invoke @code{exit}, but return from
4088 @code{main} instead.
4090 @item @code{free}
4091 @c @fuindex free
4092 @prindex @code{free}
4093 The C standard says a call @code{free (NULL)} does nothing, but
4094 some old systems don't support this (e.g., NextStep).
4096 @item @code{isinf}
4097 @itemx @code{isnan}
4098 @c @fuindex isinf
4099 @c @fuindex isnan
4100 @prindex @code{isinf}
4101 @prindex @code{isnan}
4102 The C99 standard says that @code{isinf} and @code{isnan} are
4103 macros.  On some systems just macros are available
4104 (e.g., @acronym{HP-UX} and Solaris 10), on
4105 some systems both macros and functions (e.g., glibc 2.3.2), and on some
4106 systems only functions (e.g., IRIX 6 and Solaris 9).  In some cases
4107 these functions are declared in nonstandard headers like
4108 @code{<sunmath.h>} and defined in non-default libraries like
4109 @option{-lm} or @option{-lsunmath}.
4111 The C99 @code{isinf} and @code{isnan} macros work correctly with
4112 @code{long double} arguments, but pre-C99 systems that use functions
4113 typically assume @code{double} arguments.  On such a system,
4114 @code{isinf} incorrectly returns true for a finite @code{long double}
4115 argument that is outside the range of @code{double}.
4117 To work around this porting mess, you can use code like the following.
4119 @smallexample
4120 #include <math.h>
4122 #ifndef isnan
4123 # define isnan(x) \
4124     (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
4125      : sizeof (x) == sizeof (double) ? isnan_d (x) \
4126      : isnan_f (x))
4127 static inline int isnan_f  (float       x) @{ return x != x; @}
4128 static inline int isnan_d  (double      x) @{ return x != x; @}
4129 static inline int isnan_ld (long double x) @{ return x != x; @}
4130 #endif
4132 #ifndef isinf
4133 # define isinf(x) \
4134     (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
4135      : sizeof (x) == sizeof (double) ? isinf_d (x) \
4136      : isinf_f (x))
4137 static inline int isinf_f  (float       x) @{ return isnan (x - x); @}
4138 static inline int isinf_d  (double      x) @{ return isnan (x - x); @}
4139 static inline int isinf_ld (long double x) @{ return isnan (x - x); @}
4140 #endif
4141 @end smallexample
4143 Use @code{AC_C_INLINE} (@pxref{C Compiler}) so that this code works on
4144 compilers that lack the @code{inline} keyword.  Some optimizing
4145 compilers mishandle these definitions, but systems with that bug
4146 typically have missing or broken @code{isnan} functions anyway, so it's
4147 probably not worth worrying about.
4149 @item @code{malloc}
4150 @c @fuindex malloc
4151 @prindex @code{malloc}
4152 The C standard says a call @code{malloc (0)} is implementation
4153 dependent.  It can return either @code{NULL} or a new non-null pointer.
4154 The latter is more common (e.g., the @acronym{GNU} C Library) but is by
4155 no means universal.  @code{AC_FUNC_MALLOC}
4156 can be used to insist on non-@code{NULL} (@pxref{Particular Functions}).
4158 @item @code{putenv}
4159 @c @fuindex putenv
4160 @prindex @code{putenv}
4161 Posix prefers @code{setenv} to @code{putenv}; among other things,
4162 @code{putenv} is not required of all Posix implementations, but
4163 @code{setenv} is.
4165 Posix specifies that @code{putenv} puts the given string directly in
4166 @code{environ}, but some systems make a copy of it instead (e.g.,
4167 glibc 2.0, or @acronym{BSD}).  And when a copy is made, @code{unsetenv} might
4168 not free it, causing a memory leak (e.g., Free@acronym{BSD} 4).
4170 On some systems @code{putenv ("FOO")} removes @samp{FOO} from the
4171 environment, but this is not standard usage and it dumps core
4172 on some systems (e.g., AIX).
4174 On MinGW, a call @code{putenv ("FOO=")} removes @samp{FOO} from the
4175 environment, rather than inserting it with an empty value.
4177 @item @code{realloc}
4178 @c @fuindex realloc
4179 @prindex @code{realloc}
4180 The C standard says a call @code{realloc (NULL, size)} is equivalent
4181 to @code{malloc (size)}, but some old systems don't support this (e.g.,
4182 NextStep).
4184 @item @code{signal} handler
4185 @c @fuindex signal
4186 @prindex @code{signal}
4187 Normally @code{signal} takes a handler function with a return type of
4188 @code{void}, but some old systems required @code{int} instead.  Any
4189 actual @code{int} value returned is not used; this is only a
4190 difference in the function prototype demanded.
4192 All systems we know of in current use return @code{void}.  The
4193 @code{int} was to support K&R C, where of course @code{void} is not
4194 available.  @code{AC_TYPE_SIGNAL} (@pxref{Particular Types}) can be
4195 used to establish the correct type in all cases.
4197 @item @code{snprintf}
4198 @c @fuindex snprintf
4199 @prindex @code{snprintf}
4200 @c @fuindex vsnprintf
4201 @prindex @code{vsnprintf}
4202 The C99 standard says that if the output array isn't big enough
4203 and if no other errors occur, @code{snprintf} and @code{vsnprintf}
4204 truncate the output and return the number of bytes that ought to have
4205 been produced.  Some older systems return the truncated length (e.g.,
4206 @acronym{GNU} C Library 2.0.x or @sc{irix} 6.5), some a negative value
4207 (e.g., earlier @acronym{GNU} C Library versions), and some the buffer
4208 length without truncation (e.g., 32-bit Solaris 7).  Also, some buggy
4209 older systems ignore the length and overrun the buffer (e.g., 64-bit
4210 Solaris 7).
4212 @item @code{sprintf}
4213 @c @fuindex sprintf
4214 @prindex @code{sprintf}
4215 @c @fuindex vsprintf
4216 @prindex @code{vsprintf}
4217 The C standard says @code{sprintf} and @code{vsprintf} return the
4218 number of bytes written.  On some ancient systems (SunOS 4 for
4219 instance) they return the buffer pointer instead, but these no
4220 longer need to be worried about.
4222 @item @code{sscanf}
4223 @c @fuindex sscanf
4224 @prindex @code{sscanf}
4225 On various old systems, e.g., @acronym{HP-UX} 9, @code{sscanf} requires that its
4226 input string be writable (though it doesn't actually change it).  This
4227 can be a problem when using @command{gcc} since it normally puts
4228 constant strings in read-only memory (@pxref{Incompatibilities,
4229 Incompatibilities of @acronym{GCC}, , gcc, Using and
4230 Porting the @acronym{GNU} Compiler Collection}).  Apparently in some cases even
4231 having format strings read-only can be a problem.
4233 @item @code{strerror_r}
4234 @c @fuindex strerror_r
4235 @prindex @code{strerror_r}
4236 Posix specifies that @code{strerror_r} returns an @code{int}, but many
4237 systems (e.g., @acronym{GNU} C Library version 2.2.4) provide a
4238 different version returning a @code{char *}.  @code{AC_FUNC_STRERROR_R}
4239 can detect which is in use (@pxref{Particular Functions}).
4241 @item @code{strnlen}
4242 @c @fuindex strnlen
4243 @prindex @code{strnlen}
4244 @acronym{AIX} 4.3 provides a broken version which produces the
4245 following results:
4247 @example
4248 strnlen ("foobar", 0) = 0
4249 strnlen ("foobar", 1) = 3
4250 strnlen ("foobar", 2) = 2
4251 strnlen ("foobar", 3) = 1
4252 strnlen ("foobar", 4) = 0
4253 strnlen ("foobar", 5) = 6
4254 strnlen ("foobar", 6) = 6
4255 strnlen ("foobar", 7) = 6
4256 strnlen ("foobar", 8) = 6
4257 strnlen ("foobar", 9) = 6
4258 @end example
4260 @item @code{sysconf}
4261 @c @fuindex sysconf
4262 @prindex @code{sysconf}
4263 @code{_SC_PAGESIZE} is standard, but some older systems (e.g., @acronym{HP-UX}
4264 9) have @code{_SC_PAGE_SIZE} instead.  This can be tested with
4265 @code{#ifdef}.
4267 @item @code{unlink}
4268 @c @fuindex unlink
4269 @prindex @code{unlink}
4270 The Posix spec says that @code{unlink} causes the given file to be
4271 removed only after there are no more open file handles for it.  Some
4272 non-Posix hosts have trouble with this requirement, though,
4273 and some @acronym{DOS} variants even corrupt the file system.
4275 @item @code{unsetenv}
4276 @c @fuindex unsetenv
4277 @prindex @code{unsetenv}
4278 On MinGW, @code{unsetenv} is not available, but a variable @samp{FOO}
4279 can be removed with a call @code{putenv ("FOO=")}, as described under
4280 @code{putenv} above.
4282 @item @code{va_copy}
4283 @c @fuindex va_copy
4284 @prindex @code{va_copy}
4285 The C99 standard provides @code{va_copy} for copying
4286 @code{va_list} variables.  It may be available in older environments
4287 too, though possibly as @code{__va_copy} (e.g., @command{gcc} in strict
4288 pre-C99 mode).  These can be tested with @code{#ifdef}.  A fallback to
4289 @code{memcpy (&dst, &src, sizeof (va_list))} gives maximum
4290 portability.
4292 @item @code{va_list}
4293 @c @fuindex va_list
4294 @prindex @code{va_list}
4295 @code{va_list} is not necessarily just a pointer.  It can be a
4296 @code{struct} (e.g., @command{gcc} on Alpha), which means @code{NULL} is
4297 not portable.  Or it can be an array (e.g., @command{gcc} in some
4298 PowerPC configurations), which means as a function parameter it can be
4299 effectively call-by-reference and library routines might modify the
4300 value back in the caller (e.g., @code{vsnprintf} in the @acronym{GNU} C Library
4301 2.1).
4303 @item Signed @code{>>}
4304 Normally the C @code{>>} right shift of a signed type replicates the
4305 high bit, giving a so-called ``arithmetic'' shift.  But care should be
4306 taken since Standard C doesn't require that behavior.  On those
4307 few processors without a native arithmetic shift (for instance Cray
4308 vector systems) zero bits may be shifted in, the same as a shift of an
4309 unsigned type.
4311 @item Integer @code{/}
4312 C divides signed integers by truncating their quotient toward zero,
4313 yielding the same result as Fortran.  However, before C99 the standard
4314 allowed C implementations to take the floor or ceiling of the quotient
4315 in some cases.  Hardly any implementations took advantage of this
4316 freedom, though, and it's probably not worth worrying about this issue
4317 nowadays.
4318 @end table
4321 @node Particular Functions
4322 @subsection Particular Function Checks
4323 @cindex Function, checking
4325 These macros check for particular C functions---whether they exist, and
4326 in some cases how they respond when given certain arguments.
4328 @defmac AC_FUNC_ALLOCA
4329 @acindex{FUNC_ALLOCA}
4330 @cvindex C_ALLOCA
4331 @cvindex HAVE_ALLOCA_H
4332 @ovindex ALLOCA
4333 @c @fuindex alloca
4334 @prindex @code{alloca}
4335 @hdrindex{alloca.h}
4336 Check how to get @code{alloca}.  Tries to get a builtin version by
4337 checking for @file{alloca.h} or the predefined C preprocessor macros
4338 @code{__GNUC__} and @code{_AIX}.  If this macro finds @file{alloca.h},
4339 it defines @code{HAVE_ALLOCA_H}.
4341 If those attempts fail, it looks for the function in the standard C
4342 library.  If any of those methods succeed, it defines
4343 @code{HAVE_ALLOCA}.  Otherwise, it sets the output variable
4344 @code{ALLOCA} to @samp{$@{LIBOBJDIR@}alloca.o} and defines
4345 @code{C_ALLOCA} (so programs can periodically call @samp{alloca (0)} to
4346 garbage collect).  This variable is separate from @code{LIBOBJS} so
4347 multiple programs can share the value of @code{ALLOCA} without needing
4348 to create an actual library, in case only some of them use the code in
4349 @code{LIBOBJS}.  The @samp{$@{LIBOBJDIR@}} prefix serves the same
4350 purpose as in @code{LIBOBJS} (@pxref{AC_LIBOBJ vs LIBOBJS}).
4352 This macro does not try to get @code{alloca} from the System V R3
4353 @file{libPW} or the System V R4 @file{libucb} because those libraries
4354 contain some incompatible functions that cause trouble.  Some versions
4355 do not even contain @code{alloca} or contain a buggy version.  If you
4356 still want to use their @code{alloca}, use @code{ar} to extract
4357 @file{alloca.o} from them instead of compiling @file{alloca.c}.
4359 Source files that use @code{alloca} should start with a piece of code
4360 like the following, to declare it properly.
4362 @example
4363 @group
4364 #ifdef HAVE_ALLOCA_H
4365 # include <alloca.h>
4366 #elif defined __GNUC__
4367 # define alloca __builtin_alloca
4368 #elif defined _AIX
4369 # define alloca __alloca
4370 #elif defined _MSC_VER
4371 # include <malloc.h>
4372 # define alloca _alloca
4373 #else
4374 # include <stddef.h>
4375 # ifdef  __cplusplus
4376 extern "C"
4377 # endif
4378 void *alloca (size_t);
4379 #endif
4380 @end group
4381 @end example
4382 @end defmac
4384 @defmac AC_FUNC_CHOWN
4385 @acindex{FUNC_CHOWN}
4386 @c @fuindex chown
4387 @prindex @code{chown}
4388 If the @code{chown} function is available and works (in particular, it
4389 should accept @option{-1} for @code{uid} and @code{gid}), define
4390 @code{HAVE_CHOWN}.
4391 @end defmac
4394 @defmac AC_FUNC_CLOSEDIR_VOID
4395 @acindex{FUNC_CLOSEDIR_VOID}
4396 @cvindex CLOSEDIR_VOID
4397 @c @fuindex closedir
4398 @prindex @code{closedir}
4399 If the @code{closedir} function does not return a meaningful value,
4400 define @code{CLOSEDIR_VOID}.  Otherwise, callers ought to check its
4401 return value for an error indicator.
4403 Currently this test is implemented by running a test program.  When
4404 cross compiling the pessimistic assumption that @code{closedir} does not
4405 return a meaningful value is made.
4407 This macro is obsolescent, as @code{closedir} returns a meaningful value
4408 on current systems.  New programs need not use this macro.
4409 @end defmac
4411 @defmac AC_FUNC_ERROR_AT_LINE
4412 @acindex{FUNC_ERROR_AT_LINE}
4413 @c @fuindex error_at_line
4414 @prindex @code{error_at_line}
4415 If the @code{error_at_line} function is not found, require an
4416 @code{AC_LIBOBJ} replacement of @samp{error}.
4417 @end defmac
4419 @defmac AC_FUNC_FNMATCH
4420 @acindex{FUNC_FNMATCH}
4421 @c @fuindex fnmatch
4422 @prindex @code{fnmatch}
4423 If the @code{fnmatch} function conforms to Posix, define
4424 @code{HAVE_FNMATCH}.  Detect common implementation bugs, for example,
4425 the bugs in Solaris 2.4.
4427 Unlike the other specific
4428 @code{AC_FUNC} macros, @code{AC_FUNC_FNMATCH} does not replace a
4429 broken/missing @code{fnmatch}.  This is for historical reasons.
4430 See @code{AC_REPLACE_FNMATCH} below.
4432 This macro is obsolescent.  New programs should use Gnulib's
4433 @code{fnmatch-posix} module.  @xref{Gnulib}.
4434 @end defmac
4436 @defmac AC_FUNC_FNMATCH_GNU
4437 @acindex{FUNC_FNMATCH_GNU}
4438 @c @fuindex fnmatch
4439 @prindex @code{fnmatch}
4440 Behave like @code{AC_REPLACE_FNMATCH} (@emph{replace}) but also test
4441 whether @code{fnmatch} supports @acronym{GNU} extensions.  Detect common
4442 implementation bugs, for example, the bugs in the @acronym{GNU} C
4443 Library 2.1.
4445 This macro is obsolescent.  New programs should use Gnulib's
4446 @code{fnmatch-gnu} module.  @xref{Gnulib}.
4447 @end defmac
4449 @defmac AC_FUNC_FORK
4450 @acindex{FUNC_FORK}
4451 @cvindex HAVE_VFORK_H
4452 @cvindex HAVE_WORKING_FORK
4453 @cvindex HAVE_WORKING_VFORK
4454 @cvindex vfork
4455 @c @fuindex fork
4456 @prindex @code{fork}
4457 @c @fuindex vfork
4458 @prindex @code{vfork}
4459 @hdrindex{vfork.h}
4460 This macro checks for the @code{fork} and @code{vfork} functions.  If a
4461 working @code{fork} is found, define @code{HAVE_WORKING_FORK}.  This macro
4462 checks whether @code{fork} is just a stub by trying to run it.
4464 If @file{vfork.h} is found, define @code{HAVE_VFORK_H}.  If a working
4465 @code{vfork} is found, define @code{HAVE_WORKING_VFORK}.  Otherwise,
4466 define @code{vfork} to be @code{fork} for backward compatibility with
4467 previous versions of @command{autoconf}.  This macro checks for several known
4468 errors in implementations of @code{vfork} and considers the system to not
4469 have a working @code{vfork} if it detects any of them.  It is not considered
4470 to be an implementation error if a child's invocation of @code{signal}
4471 modifies the parent's signal handler, since child processes rarely change
4472 their signal handlers.
4474 Since this macro defines @code{vfork} only for backward compatibility with
4475 previous versions of @command{autoconf} you're encouraged to define it
4476 yourself in new code:
4477 @example
4478 @group
4479 #ifndef HAVE_WORKING_VFORK
4480 # define vfork fork
4481 #endif
4482 @end group
4483 @end example
4484 @end defmac
4486 @defmac AC_FUNC_FSEEKO
4487 @acindex{FUNC_FSEEKO}
4488 @cvindex _LARGEFILE_SOURCE
4489 @c @fuindex fseeko
4490 @prindex @code{fseeko}
4491 If the @code{fseeko} function is available, define @code{HAVE_FSEEKO}.
4492 Define @code{_LARGEFILE_SOURCE} if necessary to make the prototype
4493 visible on some systems (e.g., glibc 2.2).  Otherwise linkage problems
4494 may occur when compiling with @code{AC_SYS_LARGEFILE} on
4495 largefile-sensitive systems where @code{off_t} does not default to a
4496 64bit entity.
4497 @end defmac
4499 @defmac AC_FUNC_GETGROUPS
4500 @acindex{FUNC_GETGROUPS}
4501 @ovindex GETGROUPS_LIBS
4502 @c @fuindex getgroups
4503 @prindex @code{getgroups}
4504 If the @code{getgroups} function is available and works (unlike on
4505 Ultrix 4.3, where @samp{getgroups (0, 0)} always fails), define
4506 @code{HAVE_GETGROUPS}.  Set @code{GETGROUPS_LIBS} to any libraries
4507 needed to get that function.  This macro runs @code{AC_TYPE_GETGROUPS}.
4508 @end defmac
4510 @defmac AC_FUNC_GETLOADAVG
4511 @acindex{FUNC_GETLOADAVG}
4512 @cvindex SVR4
4513 @cvindex DGUX
4514 @cvindex UMAX
4515 @cvindex UMAX4_3
4516 @cvindex HAVE_NLIST_H
4517 @cvindex NLIST_NAME_UNION
4518 @cvindex GETLOADAVG_PRIVILEGED
4519 @cvindex NEED_SETGID
4520 @cvindex C_GETLOADAVG
4521 @ovindex LIBOBJS
4522 @ovindex NEED_SETGID
4523 @ovindex KMEM_GROUP
4524 @ovindex GETLOADAVG_LIBS
4525 @c @fuindex getloadavg
4526 @prindex @code{getloadavg}
4527 Check how to get the system load averages.  To perform its tests
4528 properly, this macro needs the file @file{getloadavg.c}; therefore, be
4529 sure to set the @code{AC_LIBOBJ} replacement directory properly (see
4530 @ref{Generic Functions}, @code{AC_CONFIG_LIBOBJ_DIR}).
4532 If the system has the @code{getloadavg} function, define
4533 @code{HAVE_GETLOADAVG}, and set @code{GETLOADAVG_LIBS} to any libraries
4534 necessary to get that function.  Also add @code{GETLOADAVG_LIBS} to
4535 @code{LIBS}.  Otherwise, require an @code{AC_LIBOBJ} replacement for
4536 @samp{getloadavg} with source code in @file{@var{dir}/getloadavg.c}, and
4537 possibly define several other C preprocessor macros and output
4538 variables:
4540 @enumerate
4541 @item
4542 Define @code{C_GETLOADAVG}.
4544 @item
4545 Define @code{SVR4}, @code{DGUX}, @code{UMAX}, or @code{UMAX4_3} if on
4546 those systems.
4548 @item
4549 @hdrindex{nlist.h}
4550 If @file{nlist.h} is found, define @code{HAVE_NLIST_H}.
4552 @item
4553 If @samp{struct nlist} has an @samp{n_un.n_name} member, define
4554 @code{HAVE_STRUCT_NLIST_N_UN_N_NAME}.  The obsolete symbol
4555 @code{NLIST_NAME_UNION} is still defined, but do not depend upon it.
4557 @item
4558 Programs may need to be installed set-group-ID (or set-user-ID) for
4559 @code{getloadavg} to work.  In this case, define
4560 @code{GETLOADAVG_PRIVILEGED}, set the output variable @code{NEED_SETGID}
4561 to @samp{true} (and otherwise to @samp{false}), and set
4562 @code{KMEM_GROUP} to the name of the group that should own the installed
4563 program.
4564 @end enumerate
4566 The @code{AC_FUNC_GETLOADAVG} macro is obsolescent.  New programs should
4567 use Gnulib's @code{getloadavg} module.  @xref{Gnulib}.
4568 @end defmac
4570 @defmac AC_FUNC_GETMNTENT
4571 @acindex{FUNC_GETMNTENT}
4572 @cvindex HAVE_GETMNTENT
4573 @c @fuindex getmntent
4574 @prindex @code{getmntent}
4575 Check for @code{getmntent} in the standard C library, and then in the
4576 @file{sun}, @file{seq}, and @file{gen} libraries, for @sc{unicos},
4577 @sc{irix} 4, @sc{ptx}, and UnixWare, respectively.  Then, if
4578 @code{getmntent} is available, define @code{HAVE_GETMNTENT}.
4579 @end defmac
4581 @defmac AC_FUNC_GETPGRP
4582 @acindex{FUNC_GETPGRP}
4583 @cvindex GETPGRP_VOID
4584 @c @fuindex getpgid
4585 @c @fuindex getpgrp
4586 @prindex @code{getpgid}
4587 @prindex @code{getpgrp}
4588 Define @code{GETPGRP_VOID} if it is an error to pass 0 to
4589 @code{getpgrp}; this is the Posix behavior.  On older @acronym{BSD}
4590 systems, you must pass 0 to @code{getpgrp}, as it takes an argument and
4591 behaves like Posix's @code{getpgid}.
4593 @example
4594 #ifdef GETPGRP_VOID
4595   pid = getpgrp ();
4596 #else
4597   pid = getpgrp (0);
4598 #endif
4599 @end example
4601 This macro does not check whether
4602 @code{getpgrp} exists at all; if you need to work in that situation,
4603 first call @code{AC_CHECK_FUNC} for @code{getpgrp}.
4605 This macro is obsolescent, as current systems have a @code{getpgrp}
4606 whose signature conforms to Posix.  New programs need not use this macro.
4607 @end defmac
4609 @defmac AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
4610 @acindex{FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK}
4611 @cvindex LSTAT_FOLLOWS_SLASHED_SYMLINK
4612 @c @fuindex lstat
4613 @prindex @code{lstat}
4614 If @file{link} is a symbolic link, then @code{lstat} should treat
4615 @file{link/} the same as @file{link/.}.  However, many older
4616 @code{lstat} implementations incorrectly ignore trailing slashes.
4618 It is safe to assume that if @code{lstat} incorrectly ignores
4619 trailing slashes, then other symbolic-link-aware functions like
4620 @code{unlink} also incorrectly ignore trailing slashes.
4622 If @code{lstat} behaves properly, define
4623 @code{LSTAT_FOLLOWS_SLASHED_SYMLINK}, otherwise require an
4624 @code{AC_LIBOBJ} replacement of @code{lstat}.
4625 @end defmac
4627 @defmac AC_FUNC_MALLOC
4628 @acindex{FUNC_MALLOC}
4629 @cvindex HAVE_MALLOC
4630 @cvindex malloc
4631 @c @fuindex malloc
4632 @prindex @code{malloc}
4633 If the @code{malloc} function is compatible with the @acronym{GNU} C
4634 library @code{malloc} (i.e., @samp{malloc (0)} returns a valid
4635 pointer), define @code{HAVE_MALLOC} to 1.  Otherwise define
4636 @code{HAVE_MALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
4637 @samp{malloc}, and define @code{malloc} to @code{rpl_malloc} so that the
4638 native @code{malloc} is not used in the main project.
4640 Typically, the replacement file @file{malloc.c} should look like (note
4641 the @samp{#undef malloc}):
4643 @verbatim
4644 #ifdef HAVE_CONFIG_H
4645 # include <config.h>
4646 #endif
4647 #undef malloc
4649 #include <sys/types.h>
4651 void *malloc ();
4653 /* Allocate an N-byte block of memory from the heap.
4654    If N is zero, allocate a 1-byte block.  */
4656 void *
4657 rpl_malloc (size_t n)
4659   if (n == 0)
4660     n = 1;
4661   return malloc (n);
4663 @end verbatim
4664 @end defmac
4666 @defmac AC_FUNC_MEMCMP
4667 @acindex{FUNC_MEMCMP}
4668 @ovindex LIBOBJS
4669 @c @fuindex memcmp
4670 @prindex @code{memcmp}
4671 If the @code{memcmp} function is not available, or does not work on
4672 8-bit data (like the one on SunOS 4.1.3), or fails when comparing 16
4673 bytes or more and with at least one buffer not starting on a 4-byte
4674 boundary (such as the one on NeXT x86 OpenStep), require an
4675 @code{AC_LIBOBJ} replacement for @samp{memcmp}.
4677 This macro is obsolescent, as current systems have a working
4678 @code{memcmp}.  New programs need not use this macro.
4679 @end defmac
4681 @defmac AC_FUNC_MBRTOWC
4682 @acindex{FUNC_MBRTOWC}
4683 @cvindex HAVE_MBRTOWC
4684 @c @fuindex mbrtowc
4685 @prindex @code{mbrtowc}
4686 Define @code{HAVE_MBRTOWC} to 1 if the function @code{mbrtowc} and the
4687 type @code{mbstate_t} are properly declared.
4688 @end defmac
4690 @defmac AC_FUNC_MKTIME
4691 @acindex{FUNC_MKTIME}
4692 @ovindex LIBOBJS
4693 @c @fuindex mktime
4694 @prindex @code{mktime}
4695 If the @code{mktime} function is not available, or does not work
4696 correctly, require an @code{AC_LIBOBJ} replacement for @samp{mktime}.
4697 For the purposes of this test, @code{mktime} should conform to the
4698 Posix standard and should be the inverse of
4699 @code{localtime}.
4700 @end defmac
4702 @defmac AC_FUNC_MMAP
4703 @acindex{FUNC_MMAP}
4704 @cvindex HAVE_MMAP
4705 @c @fuindex mmap
4706 @prindex @code{mmap}
4707 If the @code{mmap} function exists and works correctly, define
4708 @code{HAVE_MMAP}.  This checks only private fixed mapping of already-mapped
4709 memory.
4710 @end defmac
4712 @defmac AC_FUNC_OBSTACK
4713 @acindex{FUNC_OBSTACK}
4714 @cvindex HAVE_OBSTACK
4715 @cindex obstack
4716 If the obstacks are found, define @code{HAVE_OBSTACK}, else require an
4717 @code{AC_LIBOBJ} replacement for @samp{obstack}.
4718 @end defmac
4720 @defmac AC_FUNC_REALLOC
4721 @acindex{FUNC_REALLOC}
4722 @cvindex HAVE_REALLOC
4723 @cvindex realloc
4724 @c @fuindex realloc
4725 @prindex @code{realloc}
4726 If the @code{realloc} function is compatible with the @acronym{GNU} C
4727 library @code{realloc} (i.e., @samp{realloc (NULL, 0)} returns a
4728 valid pointer), define @code{HAVE_REALLOC} to 1.  Otherwise define
4729 @code{HAVE_REALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
4730 @samp{realloc}, and define @code{realloc} to @code{rpl_realloc} so that
4731 the native @code{realloc} is not used in the main project.  See
4732 @code{AC_FUNC_MALLOC} for details.
4733 @end defmac
4735 @defmac AC_FUNC_SELECT_ARGTYPES
4736 @acindex{FUNC_SELECT_ARGTYPES}
4737 @cvindex SELECT_TYPE_ARG1
4738 @cvindex SELECT_TYPE_ARG234
4739 @cvindex SELECT_TYPE_ARG5
4740 @c @fuindex select
4741 @prindex @code{select}
4742 Determines the correct type to be passed for each of the
4743 @code{select} function's arguments, and defines those types
4744 in @code{SELECT_TYPE_ARG1}, @code{SELECT_TYPE_ARG234}, and
4745 @code{SELECT_TYPE_ARG5} respectively.  @code{SELECT_TYPE_ARG1} defaults
4746 to @samp{int}, @code{SELECT_TYPE_ARG234} defaults to @samp{int *},
4747 and @code{SELECT_TYPE_ARG5} defaults to @samp{struct timeval *}.
4749 This macro is obsolescent, as current systems have a @code{select} whose
4750 signature conforms to Posix.  New programs need not use this macro.
4751 @end defmac
4753 @defmac AC_FUNC_SETPGRP
4754 @acindex{FUNC_SETPGRP}
4755 @cvindex SETPGRP_VOID
4756 @c @fuindex setpgrp
4757 @prindex @code{setpgrp}
4758 If @code{setpgrp} takes no argument (the Posix version), define
4759 @code{SETPGRP_VOID}.  Otherwise, it is the @acronym{BSD} version, which takes
4760 two process IDs as arguments.  This macro does not check whether
4761 @code{setpgrp} exists at all; if you need to work in that situation,
4762 first call @code{AC_CHECK_FUNC} for @code{setpgrp}.
4764 This macro is obsolescent, as current systems have a @code{setpgrp}
4765 whose signature conforms to Posix.  New programs need not use this macro.
4766 @end defmac
4768 @defmac AC_FUNC_STAT
4769 @defmacx AC_FUNC_LSTAT
4770 @acindex{FUNC_STAT}
4771 @acindex{FUNC_LSTAT}
4772 @cvindex HAVE_STAT_EMPTY_STRING_BUG
4773 @cvindex HAVE_LSTAT_EMPTY_STRING_BUG
4774 @c @fuindex stat
4775 @prindex @code{stat}
4776 @c @fuindex lstat
4777 @prindex @code{lstat}
4778 Determine whether @code{stat} or @code{lstat} have the bug that it
4779 succeeds when given the zero-length file name as argument.  The @code{stat}
4780 and @code{lstat} from SunOS 4.1.4 and the Hurd (as of 1998-11-01) do
4781 this.
4783 If it does, then define @code{HAVE_STAT_EMPTY_STRING_BUG} (or
4784 @code{HAVE_LSTAT_EMPTY_STRING_BUG}) and ask for an @code{AC_LIBOBJ}
4785 replacement of it.
4787 These macros are obsolescent, as no current systems have the bug.
4788 New programs need not use these macros.
4789 @end defmac
4791 @defmac AC_FUNC_STRCOLL
4792 @acindex{FUNC_STRCOLL}
4793 @cvindex HAVE_STRCOLL
4794 @c @fuindex strcoll
4795 @prindex @code{strcoll}
4796 If the @code{strcoll} function exists and works correctly, define
4797 @code{HAVE_STRCOLL}.  This does a bit more than
4798 @samp{AC_CHECK_FUNCS(strcoll)}, because some systems have incorrect
4799 definitions of @code{strcoll} that should not be used.
4800 @end defmac
4802 @defmac AC_FUNC_STRERROR_R
4803 @acindex{FUNC_STRERROR_R}
4804 @cvindex HAVE_STRERROR_R
4805 @cvindex HAVE_DECL_STRERROR_R
4806 @cvindex STRERROR_R_CHAR_P
4807 @c @fuindex strerror_r
4808 @prindex @code{strerror_r}
4809 If @code{strerror_r} is available, define @code{HAVE_STRERROR_R}, and if
4810 it is declared, define @code{HAVE_DECL_STRERROR_R}.  If it returns a
4811 @code{char *} message, define @code{STRERROR_R_CHAR_P}; otherwise it
4812 returns an @code{int} error number.  The Thread-Safe Functions option of
4813 Posix requires @code{strerror_r} to return @code{int}, but
4814 many systems (including, for example, version 2.2.4 of the @acronym{GNU} C
4815 Library) return a @code{char *} value that is not necessarily equal to
4816 the buffer argument.
4817 @end defmac
4819 @defmac AC_FUNC_STRFTIME
4820 @acindex{FUNC_STRFTIME}
4821 @cvindex HAVE_STRFTIME
4822 @c @fuindex strftime
4823 @prindex @code{strftime}
4824 Check for @code{strftime} in the @file{intl} library, for SCO Unix.
4825 Then, if @code{strftime} is available, define @code{HAVE_STRFTIME}.
4827 This macro is obsolescent, as no current systems require the @file{intl}
4828 library for @code{strftime}.  New programs need not use this macro.
4829 @end defmac
4831 @defmac AC_FUNC_STRTOD
4832 @acindex{FUNC_STRTOD}
4833 @ovindex POW_LIB
4834 @c @fuindex strtod
4835 @prindex @code{strtod}
4836 If the @code{strtod} function does not exist or doesn't work correctly,
4837 ask for an @code{AC_LIBOBJ} replacement of @samp{strtod}.  In this case,
4838 because @file{strtod.c} is likely to need @samp{pow}, set the output
4839 variable @code{POW_LIB} to the extra library needed.
4840 @end defmac
4842 @defmac AC_FUNC_STRTOLD
4843 @acindex{FUNC_STRTOLD}
4844 @prindex @code{strtold}
4845 If the @code{strtold} function exists and conforms to C99, define
4846 @code{HAVE_STRTOLD}.
4847 @end defmac
4849 @defmac AC_FUNC_STRNLEN
4850 @acindex{FUNC_STRNLEN}
4851 @cvindex HAVE_STRNLEN
4852 @c @fuindex strnlen
4853 @prindex @code{strnlen}
4854 If the @code{strnlen} function is not available, or is buggy (like the one
4855 from @acronym{AIX} 4.3), require an @code{AC_LIBOBJ} replacement for it.
4856 @end defmac
4858 @defmac AC_FUNC_UTIME_NULL
4859 @acindex{FUNC_UTIME_NULL}
4860 @cvindex HAVE_UTIME_NULL
4861 @c @fuindex utime
4862 @prindex @code{utime}
4863 If @samp{utime (@var{file}, NULL)} sets @var{file}'s timestamp to
4864 the present, define @code{HAVE_UTIME_NULL}.
4866 This macro is obsolescent, as all current systems have a @code{utime}
4867 that behaves this way.  New programs need not use this macro.
4868 @end defmac
4870 @defmac AC_FUNC_VPRINTF
4871 @acindex{FUNC_VPRINTF}
4872 @cvindex HAVE_VPRINTF
4873 @cvindex HAVE_DOPRNT
4874 @c @fuindex vprintf
4875 @prindex @code{vprintf}
4876 If @code{vprintf} is found, define @code{HAVE_VPRINTF}.  Otherwise, if
4877 @code{_doprnt} is found, define @code{HAVE_DOPRNT}.  (If @code{vprintf}
4878 is available, you may assume that @code{vfprintf} and @code{vsprintf}
4879 are also available.)
4881 This macro is obsolescent, as all current systems have @code{vprintf}.
4882 New programs need not use this macro.
4883 @end defmac
4885 @defmac AC_REPLACE_FNMATCH
4886 @acindex{REPLACE_FNMATCH}
4887 @c @fuindex fnmatch
4888 @prindex @code{fnmatch}
4889 @hdrindex{fnmatch.h}
4890 If the @code{fnmatch} function does not conform to Posix (see
4891 @code{AC_FUNC_FNMATCH}), ask for its @code{AC_LIBOBJ} replacement.
4893 The files @file{fnmatch.c}, @file{fnmatch_loop.c}, and @file{fnmatch_.h}
4894 in the @code{AC_LIBOBJ} replacement directory are assumed to contain a
4895 copy of the source code of @acronym{GNU} @code{fnmatch}.  If necessary,
4896 this source code is compiled as an @code{AC_LIBOBJ} replacement, and the
4897 @file{fnmatch_.h} file is linked to @file{fnmatch.h} so that it can be
4898 included in place of the system @code{<fnmatch.h>}.
4900 This macro is obsolescent, as it assumes the use of particular source
4901 files.  New programs should use Gnulib's @code{fnmatch-posix} module,
4902 which provides this macro along with the source files.  @xref{Gnulib}.
4903 @end defmac
4907 @node Generic Functions
4908 @subsection Generic Function Checks
4910 These macros are used to find functions not covered by the ``particular''
4911 test macros.  If the functions might be in libraries other than the
4912 default C library, first call @code{AC_CHECK_LIB} for those libraries.
4913 If you need to check the behavior of a function as well as find out
4914 whether it is present, you have to write your own test for
4915 it (@pxref{Writing Tests}).
4917 @defmac AC_CHECK_FUNC (@var{function}, @ovar{action-if-found}, @ovar{action-if-not-found})
4918 @acindex{CHECK_FUNC}
4919 If C function @var{function} is available, run shell commands
4920 @var{action-if-found}, otherwise @var{action-if-not-found}.  If you just
4921 want to define a symbol if the function is available, consider using
4922 @code{AC_CHECK_FUNCS} instead.  This macro checks for functions with C
4923 linkage even when @code{AC_LANG(C++)} has been called, since C is more
4924 standardized than C++.  (@pxref{Language Choice}, for more information
4925 about selecting the language for checks.)
4926 @end defmac
4928 @defmac AC_CHECK_FUNCS (@var{function}@dots{}, @ovar{action-if-found}, @ovar{action-if-not-found})
4929 @acindex{CHECK_FUNCS}
4930 @cvindex HAVE_@var{function}
4931 For each @var{function} enumerated in the blank-or-newline-separated argument
4932 list, define @code{HAVE_@var{function}} (in all capitals) if it is available.
4933 If @var{action-if-found} is given, it is additional shell code to
4934 execute when one of the functions is found.  You can give it a value of
4935 @samp{break} to break out of the loop on the first match.  If
4936 @var{action-if-not-found} is given, it is executed when one of the
4937 functions is not found.
4938 @end defmac
4940 @defmac AC_CHECK_FUNCS_ONCE (@var{function}@dots{})
4941 @acindex{CHECK_FUNCS_ONCE}
4942 @cvindex HAVE_@var{function}
4943 For each @var{function} enumerated in the blank-or-newline-separated argument
4944 list, define @code{HAVE_@var{function}} (in all capitals) if it is available.
4945 This is a once-only variant of @code{AC_CHECK_FUNCS}.  It generates the
4946 checking code at most once, so that @command{configure} is smaller and
4947 faster; but the checks cannot be conditionalized and are always done once,
4948 early during the @command{configure} run.
4949 @end defmac
4951 @sp 1
4953 Autoconf follows a philosophy that was formed over the years by those
4954 who have struggled for portability: isolate the portability issues in
4955 specific files, and then program as if you were in a Posix
4956 environment.  Some functions may be missing or unfixable, and your
4957 package must be ready to replace them.
4959 Suitable replacements for many such problem functions are available from
4960 Gnulib (@pxref{Gnulib}).
4962 @defmac AC_LIBOBJ (@var{function})
4963 @acindex{LIBOBJ}
4964 @ovindex LIBOBJS
4965 Specify that @samp{@var{function}.c} must be included in the executables
4966 to replace a missing or broken implementation of @var{function}.
4968 Technically, it adds @samp{@var{function}.$ac_objext} to the output
4969 variable @code{LIBOBJS} if it is not already in, and calls
4970 @code{AC_LIBSOURCE} for @samp{@var{function}.c}.  You should not
4971 directly change @code{LIBOBJS}, since this is not traceable.
4972 @end defmac
4974 @defmac AC_LIBSOURCE (@var{file})
4975 @acindex{LIBSOURCE}
4976 Specify that @var{file} might be needed to compile the project.  If you
4977 need to know what files might be needed by a @file{configure.ac}, you
4978 should trace @code{AC_LIBSOURCE}.  @var{file} must be a literal.
4980 This macro is called automatically from @code{AC_LIBOBJ}, but you must
4981 call it explicitly if you pass a shell variable to @code{AC_LIBOBJ}.  In
4982 that case, since shell variables cannot be traced statically, you must
4983 pass to @code{AC_LIBSOURCE} any possible files that the shell variable
4984 might cause @code{AC_LIBOBJ} to need.  For example, if you want to pass
4985 a variable @code{$foo_or_bar} to @code{AC_LIBOBJ} that holds either
4986 @code{"foo"} or @code{"bar"}, you should do:
4988 @example
4989 AC_LIBSOURCE([foo.c])
4990 AC_LIBSOURCE([bar.c])
4991 AC_LIBOBJ([$foo_or_bar])
4992 @end example
4994 @noindent
4995 There is usually a way to avoid this, however, and you are encouraged to
4996 simply call @code{AC_LIBOBJ} with literal arguments.
4998 Note that this macro replaces the obsolete @code{AC_LIBOBJ_DECL}, with
4999 slightly different semantics: the old macro took the function name,
5000 e.g., @code{foo}, as its argument rather than the file name.
5001 @end defmac
5003 @defmac AC_LIBSOURCES (@var{files})
5004 @acindex{LIBSOURCES}
5005 Like @code{AC_LIBSOURCE}, but accepts one or more @var{files} in a
5006 comma-separated M4 list.  Thus, the above example might be rewritten:
5008 @example
5009 AC_LIBSOURCES([foo.c, bar.c])
5010 AC_LIBOBJ([$foo_or_bar])
5011 @end example
5012 @end defmac
5014 @defmac AC_CONFIG_LIBOBJ_DIR (@var{directory})
5015 @acindex{CONFIG_LIBOBJ_DIR}
5016 Specify that @code{AC_LIBOBJ} replacement files are to be found in
5017 @var{directory}, a name relative to the top level of the
5018 source tree.  The replacement directory defaults to @file{.}, the top
5019 level directory, and the most typical value is @file{lib}, corresponding
5020 to @samp{AC_CONFIG_LIBOBJ_DIR([lib])}.
5022 @command{configure} might need to know the replacement directory for the
5023 following reasons: (i) some checks use the replacement files, (ii) some
5024 macros bypass broken system headers by installing links to the
5025 replacement headers (iii) when used in conjunction with Automake,
5026 within each makefile, @var{directory} is used as a relative path
5027 from @code{$(top_srcdir)} to each object named in @code{LIBOBJS} and
5028 @code{LTLIBOBJS}, etc.
5029 @end defmac
5031 @sp 1
5033 It is common to merely check for the existence of a function, and ask
5034 for its @code{AC_LIBOBJ} replacement if missing.  The following macro is
5035 a convenient shorthand.
5037 @defmac AC_REPLACE_FUNCS (@var{function}@dots{})
5038 @acindex{REPLACE_FUNCS}
5039 @ovindex LIBOBJS
5040 Like @code{AC_CHECK_FUNCS}, but uses @samp{AC_LIBOBJ(@var{function})} as
5041 @var{action-if-not-found}.  You can declare your replacement function by
5042 enclosing the prototype in @samp{#ifndef HAVE_@var{function}}.  If the
5043 system has the function, it probably declares it in a header file you
5044 should be including, so you shouldn't redeclare it lest your declaration
5045 conflict.
5046 @end defmac
5048 @node Header Files
5049 @section Header Files
5050 @cindex Header, checking
5052 The following macros check for the presence of certain C header files.
5053 If there is no macro specifically defined to check for a header file you need,
5054 and you don't need to check for any special properties of
5055 it, then you can use one of the general header-file check macros.
5057 @menu
5058 * Header Portability::          Collected knowledge on common headers
5059 * Particular Headers::          Special handling to find certain headers
5060 * Generic Headers::             How to find other headers
5061 @end menu
5063 @node Header Portability
5064 @subsection Portability of Headers
5065 @cindex Portability of headers
5066 @cindex Header portability
5068 This section tries to collect knowledge about common headers, and the
5069 problems they cause.  By definition, this list always requires
5070 additions.  Please help us keeping it as complete as possible.
5072 @table @asis
5074 @item @file{limits.h}
5075 C99 says that @file{limits.h} defines @code{LLONG_MIN},
5076 @code{LLONG_MAX}, and @code{ULLONG_MAX}, but many almost-C99
5077 environments (e.g., default @acronym{GCC} 4.0.2 + glibc 2.4) do not
5078 define them.
5080 @item @file{inttypes.h} vs.@: @file{stdint.h}
5081 @hdrindex{inttypes.h}
5082 @hdrindex{stdint.h}
5083 The C99 standard says that @file{inttypes.h} includes
5084 @file{stdint.h}, so there's no need to include @file{stdint.h}
5085 separately in a standard environment.  Some implementations have
5086 @file{inttypes.h} but not @file{stdint.h} (e.g., Solaris 7), but we don't
5087 know of any implementation that has @file{stdint.h} but not
5088 @file{inttypes.h}.
5090 @item @file{linux/irda.h}
5091 @hdrindex{linux/irda.h}
5092 It requires @file{linux/types.h} and @file{sys/socket.h}.
5094 @item @file{linux/random.h}
5095 @hdrindex{linux/random.h}
5096 It requires @file{linux/types.h}.
5098 @item @file{net/if.h}
5099 @hdrindex{net/if.h}
5100 On Darwin, this file requires that @file{sys/socket.h} be included
5101 beforehand.  One should run:
5103 @example
5104 AC_CHECK_HEADERS([sys/socket.h])
5105 AC_CHECK_HEADERS([net/if.h], [], [],
5106 [#include <stdio.h>
5107 #ifdef STDC_HEADERS
5108 # include <stdlib.h>
5109 # include <stddef.h>
5110 #else
5111 # ifdef HAVE_STDLIB_H
5112 #  include <stdlib.h>
5113 # endif
5114 #endif
5115 #ifdef HAVE_SYS_SOCKET_H
5116 # include <sys/socket.h>
5117 #endif
5119 @end example
5121 @item @file{netinet/if_ether.h}
5122 @hdrindex{netinet/if_ether.h}
5123 On Darwin, this file requires that @file{stdio.h} and
5124 @file{sys/socket.h} be included beforehand.  One should run:
5126 @example
5127 AC_CHECK_HEADERS([sys/socket.h])
5128 AC_CHECK_HEADERS([netinet/if_ether.h], [], [],
5129 [#include <stdio.h>
5130 #ifdef STDC_HEADERS
5131 # include <stdlib.h>
5132 # include <stddef.h>
5133 #else
5134 # ifdef HAVE_STDLIB_H
5135 #  include <stdlib.h>
5136 # endif
5137 #endif
5138 #ifdef HAVE_SYS_SOCKET_H
5139 # include <sys/socket.h>
5140 #endif
5142 @end example
5144 @item @file{stdint.h}
5145 See above, item @file{inttypes.h} vs.@: @file{stdint.h}.
5147 @item @file{stdlib.h}
5148 @hdrindex{stdlib.h}
5149 On many systems (e.g., Darwin), @file{stdio.h} is a prerequisite.
5151 @item @file{sys/mount.h}
5152 @hdrindex{sys/mount.h}
5153 On Free@acronym{BSD} 4.8 on ia32 and using gcc version 2.95.4,
5154 @file{sys/params.h} is a prerequisite.
5156 @item @file{sys/ptem.h}
5157 @hdrindex{sys/ptem.h}
5158 On Solaris 8, @file{sys/stream.h} is a prerequisite.
5160 @item @file{sys/socket.h}
5161 @hdrindex{sys/socket.h}
5162 On Darwin, @file{stdlib.h} is a prerequisite.
5164 @item @file{sys/ucred.h}
5165 @hdrindex{sys/ucred.h}
5166 On Tru64 5.1, @file{sys/types.h} is a prerequisite.
5168 @item @file{X11/extensions/scrnsaver.h}
5169 @hdrindex{X11/extensions/scrnsaver.h}
5170 Using XFree86, this header requires @file{X11/Xlib.h}, which is probably
5171 so required that you might not even consider looking for it.
5173 @example
5174 AC_CHECK_HEADERS([X11/extensions/scrnsaver.h], [], [],
5175 [[#include <X11/Xlib.h>
5177 @end example
5178 @end table
5181 @node Particular Headers
5182 @subsection Particular Header Checks
5184 These macros check for particular system header files---whether they
5185 exist, and in some cases whether they declare certain symbols.
5187 @defmac AC_HEADER_ASSERT
5188 @acindex{HEADER_ASSERT}
5189 @cvindex NDEBUG
5190 @hdrindex{assert.h}
5191 Check whether to enable assertions in the style of @file{assert.h}.
5192 Assertions are enabled by default, but the user can override this by
5193 invoking @command{configure} with the @option{--disable-assert} option.
5194 @end defmac
5196 @defmac AC_HEADER_DIRENT
5197 @acindex{HEADER_DIRENT}
5198 @cvindex HAVE_DIRENT_H
5199 @cvindex HAVE_NDIR_H
5200 @cvindex HAVE_SYS_DIR_H
5201 @cvindex HAVE_SYS_NDIR_H
5202 @hdrindex{dirent.h}
5203 @hdrindex{sys/ndir.h}
5204 @hdrindex{sys/dir.h}
5205 @hdrindex{ndir.h}
5206 Check for the following header files.  For the first one that is
5207 found and defines @samp{DIR}, define the listed C preprocessor macro:
5209 @multitable {@file{sys/ndir.h}} {@code{HAVE_SYS_NDIR_H}}
5210 @item @file{dirent.h}   @tab @code{HAVE_DIRENT_H}
5211 @item @file{sys/ndir.h} @tab @code{HAVE_SYS_NDIR_H}
5212 @item @file{sys/dir.h}  @tab @code{HAVE_SYS_DIR_H}
5213 @item @file{ndir.h}     @tab @code{HAVE_NDIR_H}
5214 @end multitable
5216 The directory-library declarations in your source code should look
5217 something like the following:
5219 @example
5220 @group
5221 #include <sys/types.h>
5222 #ifdef HAVE_DIRENT_H
5223 # include <dirent.h>
5224 # define NAMLEN(dirent) strlen ((dirent)->d_name)
5225 #else
5226 # define dirent direct
5227 # define NAMLEN(dirent) ((dirent)->d_namlen)
5228 # ifdef HAVE_SYS_NDIR_H
5229 #  include <sys/ndir.h>
5230 # endif
5231 # ifdef HAVE_SYS_DIR_H
5232 #  include <sys/dir.h>
5233 # endif
5234 # ifdef HAVE_NDIR_H
5235 #  include <ndir.h>
5236 # endif
5237 #endif
5238 @end group
5239 @end example
5241 Using the above declarations, the program would declare variables to be
5242 of type @code{struct dirent}, not @code{struct direct}, and would access
5243 the length of a directory entry name by passing a pointer to a
5244 @code{struct dirent} to the @code{NAMLEN} macro.
5246 This macro also checks for the SCO Xenix @file{dir} and @file{x} libraries.
5248 This macro is obsolescent, as all current systems with directory
5249 libraries have @code{<dirent.h>}.  New programs need not use this macro.
5251 Also see @code{AC_STRUCT_DIRENT_D_INO} and
5252 @code{AC_STRUCT_DIRENT_D_TYPE} (@pxref{Particular Structures}).
5253 @end defmac
5255 @defmac AC_HEADER_MAJOR
5256 @acindex{HEADER_MAJOR}
5257 @cvindex MAJOR_IN_MKDEV
5258 @cvindex MAJOR_IN_SYSMACROS
5259 @hdrindex{sys/mkdev.h}
5260 @hdrindex{sys/sysmacros.h}
5261 If @file{sys/types.h} does not define @code{major}, @code{minor}, and
5262 @code{makedev}, but @file{sys/mkdev.h} does, define
5263 @code{MAJOR_IN_MKDEV}; otherwise, if @file{sys/sysmacros.h} does, define
5264 @code{MAJOR_IN_SYSMACROS}.
5265 @end defmac
5267 @defmac AC_HEADER_RESOLV
5268 @acindex{HEADER_RESOLV}
5269 @cvindex HAVE_RESOLV_H
5270 @hdrindex{resolv.h}
5271 Checks for header @file{resolv.h}, checking for prerequisites first.
5272 To properly use @file{resolv.h}, your code should contain something like
5273 the following:
5275 @verbatim
5276 #ifdef HAVE_SYS_TYPES_H
5277 #  include <sys/types.h>
5278 #endif
5279 #ifdef HAVE_NETINET_IN_H
5280 #  include <netinet/in.h>   /* inet_ functions / structs */
5281 #endif
5282 #ifdef HAVE_ARPA_NAMESER_H
5283 #  include <arpa/nameser.h> /* DNS HEADER struct */
5284 #endif
5285 #ifdef HAVE_NETDB_H
5286 #  include <netdb.h>
5287 #endif
5288 #include <resolv.h>
5289 @end verbatim
5290 @end defmac
5292 @defmac AC_HEADER_STAT
5293 @acindex{HEADER_STAT}
5294 @cvindex STAT_MACROS_BROKEN
5295 @hdrindex{sys/stat.h}
5296 If the macros @code{S_ISDIR}, @code{S_ISREG}, etc.@: defined in
5297 @file{sys/stat.h} do not work properly (returning false positives),
5298 define @code{STAT_MACROS_BROKEN}.  This is the case on Tektronix UTekV,
5299 Amdahl UTS and Motorola System V/88.
5301 This macro is obsolescent, as no current systems have the bug.
5302 New programs need not use this macro.
5303 @end defmac
5305 @defmac AC_HEADER_STDBOOL
5306 @acindex{HEADER_STDBOOL}
5307 @cvindex HAVE_STDBOOL_H
5308 @cvindex HAVE__BOOL
5309 @hdrindex{stdbool.h}
5310 @hdrindex{system.h}
5311 If @file{stdbool.h} exists and conforms to C99, define
5312 @code{HAVE_STDBOOL_H} to 1; if the type @code{_Bool} is defined, define
5313 @code{HAVE__BOOL} to 1.  To fulfill the C99 requirements, your
5314 @file{system.h} could contain the following code:
5316 @verbatim
5317 #ifdef HAVE_STDBOOL_H
5318 # include <stdbool.h>
5319 #else
5320 # ifndef HAVE__BOOL
5321 #  ifdef __cplusplus
5322 typedef bool _Bool;
5323 #  else
5324 #   define _Bool signed char
5325 #  endif
5326 # endif
5327 # define bool _Bool
5328 # define false 0
5329 # define true 1
5330 # define __bool_true_false_are_defined 1
5331 #endif
5332 @end verbatim
5334 Alternatively you can use the @samp{stdbool} package of Gnulib
5335 (@pxref{Gnulib}); it packages the above code into a replacement header
5336 and contains a few other bells and whistles.
5338 @end defmac
5341 @defmac AC_HEADER_STDC
5342 @acindex{HEADER_STDC}
5343 @cvindex STDC_HEADERS
5344 @hdrindex{stdlib.h}
5345 @hdrindex{stdarg.h}
5346 @hdrindex{string.h}
5347 @hdrindex{float.h}
5348 @hdrindex{ctype.h}
5349 Define @code{STDC_HEADERS} if the system has C header files
5350 conforming to @acronym{ANSI} C89 (@acronym{ISO} C90).
5351 Specifically, this macro checks for @file{stdlib.h}, @file{stdarg.h},
5352 @file{string.h}, and @file{float.h}; if the system has those, it
5353 probably has the rest of the C89 header files.  This macro also
5354 checks whether @file{string.h} declares @code{memchr} (and thus
5355 presumably the other @code{mem} functions), whether @file{stdlib.h}
5356 declare @code{free} (and thus presumably @code{malloc} and other related
5357 functions), and whether the @file{ctype.h} macros work on characters
5358 with the high bit set, as the C standard requires.
5360 If you use this macro, your code can refer to @code{STDC_HEADERS} to
5361 determine whether the system has conforming header files (and probably C
5362 library functions).
5364 This macro is obsolescent, as current systems have conforming header
5365 files.  New programs need not use this macro.
5367 @hdrindex{string.h}
5368 @hdrindex{strings.h}
5369 Nowadays @file{string.h} is part of the C standard and declares functions like
5370 @code{strcpy}, and @file{strings.h} is standardized by Posix and declares
5371 @acronym{BSD} functions like @code{bcopy}; but
5372 historically, string functions were a major sticking point in this area.
5373 If you still want to worry about portability to ancient systems without
5374 standard headers, there is so much variation
5375 that it is probably easier to declare the functions you use than to
5376 figure out exactly what the system header files declare.  Some ancient systems
5377 contained a mix of functions from the C standard and from @acronym{BSD};
5378 some were mostly standard but lacked @samp{memmove}; some defined the
5379 @acronym{BSD} functions as macros in @file{string.h} or
5380 @file{strings.h}; some had only the @acronym{BSD} functions but
5381 @file{string.h}; some declared the memory functions in @file{memory.h},
5382 some in @file{string.h}; etc.  It is probably sufficient to check for
5383 one string function and one memory function; if the library had the
5384 standard versions of those then it probably had most of the others.
5385 If you put the following in @file{configure.ac}:
5387 @example
5388 # This example is obsolescent.
5389 # Nowadays you can omit these macro calls.
5390 AC_HEADER_STDC
5391 AC_CHECK_FUNCS([strchr memcpy])
5392 @end example
5394 @noindent
5395 then, in your code, you can use declarations like this:
5397 @example
5398 @group
5399 /* This example is obsolescent.
5400    Nowadays you can just #include <string.h>.  */
5401 #ifdef STDC_HEADERS
5402 # include <string.h>
5403 #else
5404 # ifndef HAVE_STRCHR
5405 #  define strchr index
5406 #  define strrchr rindex
5407 # endif
5408 char *strchr (), *strrchr ();
5409 # ifndef HAVE_MEMCPY
5410 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
5411 #  define memmove(d, s, n) bcopy ((s), (d), (n))
5412 # endif
5413 #endif
5414 @end group
5415 @end example
5417 @noindent
5418 If you use a function like @code{memchr}, @code{memset}, @code{strtok},
5419 or @code{strspn}, which have no @acronym{BSD} equivalent, then macros don't
5420 suffice to port to ancient hosts; you must provide an implementation of
5421 each function.  An easy
5422 way to incorporate your implementations only when needed (since the ones
5423 in system C libraries may be hand optimized) is to, taking @code{memchr}
5424 for example, put it in @file{memchr.c} and use
5425 @samp{AC_REPLACE_FUNCS([memchr])}.
5426 @end defmac
5428 @defmac AC_HEADER_SYS_WAIT
5429 @acindex{HEADER_SYS_WAIT}
5430 @cvindex HAVE_SYS_WAIT_H
5431 @hdrindex{sys/wait.h}
5432 If @file{sys/wait.h} exists and is compatible with Posix, define
5433 @code{HAVE_SYS_WAIT_H}.  Incompatibility can occur if @file{sys/wait.h}
5434 does not exist, or if it uses the old @acronym{BSD} @code{union wait} instead
5435 of @code{int} to store a status value.  If @file{sys/wait.h} is not
5436 Posix compatible, then instead of including it, define the
5437 Posix macros with their usual interpretations.  Here is an
5438 example:
5440 @example
5441 @group
5442 #include <sys/types.h>
5443 #ifdef HAVE_SYS_WAIT_H
5444 # include <sys/wait.h>
5445 #endif
5446 #ifndef WEXITSTATUS
5447 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
5448 #endif
5449 #ifndef WIFEXITED
5450 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
5451 #endif
5452 @end group
5453 @end example
5455 @noindent
5456 This macro is obsolescent, as current systems are compatible with Posix.
5457 New programs need not use this macro.
5458 @end defmac
5460 @cvindex _POSIX_VERSION
5461 @hdrindex{unistd.h}
5462 @code{_POSIX_VERSION} is defined when @file{unistd.h} is included on
5463 Posix systems.  If there is no @file{unistd.h}, it is definitely
5464 not a Posix system.  However, some non-Posix systems do
5465 have @file{unistd.h}.
5467 The way to check whether the system supports Posix is:
5469 @example
5470 @group
5471 #ifdef HAVE_UNISTD_H
5472 # include <sys/types.h>
5473 # include <unistd.h>
5474 #endif
5476 #ifdef _POSIX_VERSION
5477 /* Code for Posix systems.  */
5478 #endif
5479 @end group
5480 @end example
5482 @defmac AC_HEADER_TIME
5483 @acindex{HEADER_TIME}
5484 @cvindex TIME_WITH_SYS_TIME
5485 @hdrindex{time.h}
5486 @hdrindex{sys/time.h}
5487 If a program may include both @file{time.h} and @file{sys/time.h},
5488 define @code{TIME_WITH_SYS_TIME}.  On some ancient systems,
5489 @file{sys/time.h} included @file{time.h}, but @file{time.h} was not
5490 protected against multiple inclusion, so programs could not explicitly
5491 include both files.  This macro is useful in programs that use, for
5492 example, @code{struct timeval} as well as
5493 @code{struct tm}.  It is best used in conjunction with
5494 @code{HAVE_SYS_TIME_H}, which can be checked for using
5495 @code{AC_CHECK_HEADERS([sys/time.h])}.
5497 @example
5498 @group
5499 #ifdef TIME_WITH_SYS_TIME
5500 # include <sys/time.h>
5501 # include <time.h>
5502 #else
5503 # ifdef HAVE_SYS_TIME_H
5504 #  include <sys/time.h>
5505 # else
5506 #  include <time.h>
5507 # endif
5508 #endif
5509 @end group
5510 @end example
5512 @noindent
5513 This macro is obsolescent, as current systems can include both files
5514 when they exist.  New programs need not use this macro.
5515 @end defmac
5518 @defmac AC_HEADER_TIOCGWINSZ
5519 @acindex{HEADER_TIOCGWINSZ}
5520 @cvindex GWINSZ_IN_SYS_IOCTL
5521 @hdrindex{sys/ioctl.h}
5522 @hdrindex{termios.h}
5523 @c FIXME: I need clarifications from Jim.
5524 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
5525 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
5526 found in @file{<termios.h>}.
5528 Use:
5530 @example
5531 @group
5532 #ifdef HAVE_TERMIOS_H
5533 # include <termios.h>
5534 #endif
5536 #ifdef GWINSZ_IN_SYS_IOCTL
5537 # include <sys/ioctl.h>
5538 #endif
5539 @end group
5540 @end example
5541 @end defmac
5543 @node Generic Headers
5544 @subsection Generic Header Checks
5546 These macros are used to find system header files not covered by the
5547 ``particular'' test macros.  If you need to check the contents of a header
5548 as well as find out whether it is present, you have to write your own
5549 test for it (@pxref{Writing Tests}).
5551 @defmac AC_CHECK_HEADER (@var{header-file}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5552 @acindex{CHECK_HEADER}
5553 If the system header file @var{header-file} is compilable, execute shell
5554 commands @var{action-if-found}, otherwise execute
5555 @var{action-if-not-found}.  If you just want to define a symbol if the
5556 header file is available, consider using @code{AC_CHECK_HEADERS}
5557 instead.
5559 For compatibility issues with older versions of Autoconf, please read
5560 below.
5561 @end defmac
5563 @defmac AC_CHECK_HEADERS (@var{header-file}@dots{}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5564 @acindex{CHECK_HEADERS}
5565 @cvindex HAVE_@var{header}
5566 For each given system header file @var{header-file} in the
5567 blank-separated argument list that exists, define
5568 @code{HAVE_@var{header-file}} (in all capitals).  If @var{action-if-found}
5569 is given, it is additional shell code to execute when one of the header
5570 files is found.  You can give it a value of @samp{break} to break out of
5571 the loop on the first match.  If @var{action-if-not-found} is given, it
5572 is executed when one of the header files is not found.
5574 For compatibility issues with older versions of Autoconf, please read
5575 below.
5576 @end defmac
5578 Previous versions of Autoconf merely checked whether the header was
5579 accepted by the preprocessor.  This was changed because the old test was
5580 inappropriate for typical uses.  Headers are typically used to compile,
5581 not merely to preprocess, and the old behavior sometimes accepted
5582 headers that clashed at compile-time.  If you need to check whether a
5583 header is preprocessable, you can use @code{AC_PREPROC_IFELSE}
5584 (@pxref{Running the Preprocessor}).
5586 This scheme, which improves the robustness of the test, also requires
5587 that you make sure that headers that must be included before the
5588 @var{header-file} be part of the @var{includes}, (@pxref{Default
5589 Includes}).  If looking for @file{bar.h}, which requires that
5590 @file{foo.h} be included before if it exists, we suggest the following
5591 scheme:
5593 @verbatim
5594 AC_CHECK_HEADERS([foo.h])
5595 AC_CHECK_HEADERS([bar.h], [], [],
5596 [#ifdef HAVE_FOO_H
5597 # include <foo.h>
5598 # endif
5600 @end verbatim
5602 The following variant generates smaller, faster @command{configure}
5603 files if you do not need the full power of @code{AC_CHECK_HEADERS}.
5605 @defmac AC_CHECK_HEADERS_ONCE (@var{header-file}@dots{})
5606 @acindex{CHECK_HEADERS_ONCE}
5607 @cvindex HAVE_@var{header}
5608 For each given system header file @var{header-file} in the
5609 blank-separated argument list that exists, define
5610 @code{HAVE_@var{header-file}} (in all capitals).
5611 This is a once-only variant of @code{AC_CHECK_HEADERS}.  It generates the
5612 checking code at most once, so that @command{configure} is smaller and
5613 faster; but the checks cannot be conditionalized and are always done once,
5614 early during the @command{configure} run.
5615 @end defmac
5617 @node Declarations
5618 @section Declarations
5619 @cindex Declaration, checking
5621 The following macros check for the declaration of variables and
5622 functions.  If there is no macro specifically defined to check for a
5623 symbol you need, then you can use the general macros (@pxref{Generic
5624 Declarations}) or, for more complex tests, you may use
5625 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
5627 @menu
5628 * Particular Declarations::     Macros to check for certain declarations
5629 * Generic Declarations::        How to find other declarations
5630 @end menu
5632 @node Particular Declarations
5633 @subsection Particular Declaration Checks
5635 There are no specific macros for declarations.
5637 @node Generic Declarations
5638 @subsection Generic Declaration Checks
5640 These macros are used to find declarations not covered by the ``particular''
5641 test macros.
5643 @defmac AC_CHECK_DECL (@var{symbol}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5644 @acindex{CHECK_DECL}
5645 If @var{symbol} (a function, variable, or constant) is not declared in
5646 @var{includes} and a declaration is needed, run the shell commands
5647 @var{action-if-not-found}, otherwise @var{action-if-found}.  If no
5648 @var{includes} are specified, the default includes are used
5649 (@pxref{Default Includes}).
5651 This macro actually tests whether @var{symbol} is defined as a macro or
5652 can be used as an r-value, not whether it is really declared, because it
5653 is much safer to avoid
5654 introducing extra declarations when they are not needed.
5655 @end defmac
5657 @defmac AC_CHECK_DECLS (@var{symbols}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5658 @acindex{CHECK_DECLS}
5659 @cvindex HAVE_DECL_@var{symbol}
5660 For each of the @var{symbols} (@emph{comma}-separated list), define
5661 @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
5662 @var{symbol} is declared, otherwise to @samp{0}.  If
5663 @var{action-if-not-found} is given, it is additional shell code to
5664 execute when one of the function declarations is needed, otherwise
5665 @var{action-if-found} is executed.
5667 This macro uses an M4 list as first argument:
5668 @example
5669 AC_CHECK_DECLS([strdup])
5670 AC_CHECK_DECLS([strlen])
5671 AC_CHECK_DECLS([malloc, realloc, calloc, free])
5672 @end example
5674 Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not
5675 declared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} instead
5676 of leaving @code{HAVE_DECL_@var{symbol}} undeclared.  When you are
5677 @emph{sure} that the check was performed, use
5678 @code{HAVE_DECL_@var{symbol}} in @code{#if}:
5680 @example
5681 #if !HAVE_DECL_SYMBOL
5682 extern char *symbol;
5683 #endif
5684 @end example
5686 @noindent
5687 If the test may have not been performed, however, because it is safer
5688 @emph{not} to declare a symbol than to use a declaration that conflicts
5689 with the system's one, you should use:
5691 @example
5692 #if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
5693 void *malloc (size_t *s);
5694 #endif
5695 @end example
5697 @noindent
5698 You fall into the second category only in extreme situations: either
5699 your files may be used without being configured, or they are used during
5700 the configuration.  In most cases the traditional approach is enough.
5701 @end defmac
5703 @defmac AC_CHECK_DECLS_ONCE (@var{symbols})
5704 @acindex{CHECK_DECLS_ONCE}
5705 @cvindex HAVE_DECL_@var{symbol}
5706 For each of the @var{symbols} (@emph{comma}-separated list), define
5707 @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
5708 @var{symbol} is declared in the default include files, otherwise to
5709 @samp{0}.  This is a once-only variant of @code{AC_CHECK_DECLS}.  It
5710 generates the checking code at most once, so that @command{configure} is
5711 smaller and faster; but the checks cannot be conditionalized and are
5712 always done once, early during the @command{configure} run.
5713 @end defmac
5716 @node Structures
5717 @section Structures
5718 @cindex Structure, checking
5720 The following macros check for the presence of certain members in C
5721 structures.  If there is no macro specifically defined to check for a
5722 member you need, then you can use the general structure-member macros
5723 (@pxref{Generic Structures}) or, for more complex tests, you may use
5724 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
5726 @menu
5727 * Particular Structures::       Macros to check for certain structure members
5728 * Generic Structures::          How to find other structure members
5729 @end menu
5731 @node Particular Structures
5732 @subsection Particular Structure Checks
5734 The following macros check for certain structures or structure members.
5736 @defmac AC_STRUCT_DIRENT_D_INO
5737 @acindex{STRUCT_DIRENT_D_INO}
5738 @cvindex HAVE_STRUCT_DIRENT_D_INO
5739 Perform all the actions of @code{AC_HEADER_DIRENT} (@pxref{Particular
5740 Headers}).  Then, if @code{struct dirent} contains a @code{d_ino}
5741 member, define @code{HAVE_STRUCT_DIRENT_D_INO}.
5743 @code{HAVE_STRUCT_DIRENT_D_INO} indicates only the presence of
5744 @code{d_ino}, not whether its contents are always reliable.
5745 Traditionally, a zero @code{d_ino} indicated a deleted directory entry,
5746 though current systems hide this detail from the user and never return
5747 zero @code{d_ino} values.
5748 Many current systems report an incorrect @code{d_ino} for a directory
5749 entry that is a mount point.
5750 @end defmac
5752 @defmac AC_STRUCT_DIRENT_D_TYPE
5753 @acindex{STRUCT_DIRENT_D_TYPE}
5754 @cvindex HAVE_STRUCT_DIRENT_D_TYPE
5755 Perform all the actions of @code{AC_HEADER_DIRENT} (@pxref{Particular
5756 Headers}).  Then, if @code{struct dirent} contains a @code{d_type}
5757 member, define @code{HAVE_STRUCT_DIRENT_D_TYPE}.
5758 @end defmac
5760 @defmac AC_STRUCT_ST_BLKSIZE
5761 @acindex{STRUCT_ST_BLKSIZE}
5762 @cvindex HAVE_STRUCT_STAT_ST_BLKSIZE
5763 @cvindex HAVE_ST_BLKSIZE
5764 If @code{struct stat} contains an @code{st_blksize} member, define
5765 @code{HAVE_STRUCT_STAT_ST_BLKSIZE}.  The former name,
5766 @code{HAVE_ST_BLKSIZE} is to be avoided, as its support will cease in
5767 the future.  This macro is obsoleted, and should be replaced by
5769 @example
5770 AC_CHECK_MEMBERS([struct stat.st_blksize])
5771 @end example
5772 @end defmac
5774 @defmac AC_STRUCT_ST_BLOCKS
5775 @acindex{STRUCT_ST_BLOCKS}
5776 @cvindex HAVE_STRUCT_STAT_ST_BLOCKS
5777 @cvindex HAVE_ST_BLOCKS
5778 @ovindex LIBOBJS
5779 If @code{struct stat} contains an @code{st_blocks} member, define
5780 @code{HAVE_STRUCT_STAT_ST_BLOCKS}.  Otherwise, require an
5781 @code{AC_LIBOBJ} replacement of @samp{fileblocks}.  The former name,
5782 @code{HAVE_ST_BLOCKS} is to be avoided, as its support will cease in the
5783 future.
5784 @end defmac
5786 @defmac AC_STRUCT_ST_RDEV
5787 @acindex{STRUCT_ST_RDEV}
5788 @cvindex HAVE_ST_RDEV
5789 @cvindex HAVE_STRUCT_STAT_ST_RDEV
5790 If @code{struct stat} contains an @code{st_rdev} member, define
5791 @code{HAVE_STRUCT_STAT_ST_RDEV}.  The former name for this macro,
5792 @code{HAVE_ST_RDEV}, is to be avoided as it will cease to be supported
5793 in the future.  Actually, even the new macro is obsolete and should be
5794 replaced by:
5795 @example
5796 AC_CHECK_MEMBERS([struct stat.st_rdev])
5797 @end example
5798 @end defmac
5800 @defmac AC_STRUCT_TM
5801 @acindex{STRUCT_TM}
5802 @cvindex TM_IN_SYS_TIME
5803 @hdrindex{time.h}
5804 @hdrindex{sys/time.h}
5805 If @file{time.h} does not define @code{struct tm}, define
5806 @code{TM_IN_SYS_TIME}, which means that including @file{sys/time.h}
5807 had better define @code{struct tm}.
5809 This macro is obsolescent, as @file{time.h} defines @code{struct tm} in
5810 current systems.  New programs need not use this macro.
5811 @end defmac
5813 @defmac AC_STRUCT_TIMEZONE
5814 @acindex{STRUCT_TIMEZONE}
5815 @cvindex HAVE_TM_ZONE
5816 @cvindex HAVE_TZNAME
5817 Figure out how to get the current timezone.  If @code{struct tm} has a
5818 @code{tm_zone} member, define @code{HAVE_STRUCT_TM_TM_ZONE} (and the
5819 obsoleted @code{HAVE_TM_ZONE}).  Otherwise, if the external array
5820 @code{tzname} is found, define @code{HAVE_TZNAME}; if it is declared,
5821 define @code{HAVE_DECL_TZNAME}.
5822 @end defmac
5824 @node Generic Structures
5825 @subsection Generic Structure Checks
5827 These macros are used to find structure members not covered by the
5828 ``particular'' test macros.
5830 @defmac AC_CHECK_MEMBER (@var{aggregate}.@var{member}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5831 @acindex{CHECK_MEMBER}
5832 Check whether @var{member} is a member of the aggregate @var{aggregate}.
5833 If no @var{includes} are specified, the default includes are used
5834 (@pxref{Default Includes}).
5836 @example
5837 AC_CHECK_MEMBER([struct passwd.pw_gecos], [],
5838                 [AC_MSG_ERROR([We need `passwd.pw_gecos'!])],
5839                 [#include <pwd.h>])
5840 @end example
5842 You can use this macro for submembers:
5844 @example
5845 AC_CHECK_MEMBER(struct top.middle.bot)
5846 @end example
5847 @end defmac
5849 @defmac AC_CHECK_MEMBERS (@var{members}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5850 @acindex{CHECK_MEMBERS}
5851 Check for the existence of each @samp{@var{aggregate}.@var{member}} of
5852 @var{members} using the previous macro.  When @var{member} belongs to
5853 @var{aggregate}, define @code{HAVE_@var{aggregate}_@var{member}} (in all
5854 capitals, with spaces and dots replaced by underscores).  If
5855 @var{action-if-found} is given, it is executed for each of the found
5856 members.  If @var{action-if-not-found} is given, it is executed for each
5857 of the members that could not be found.
5859 This macro uses M4 lists:
5860 @example
5861 AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize])
5862 @end example
5863 @end defmac
5866 @node Types
5867 @section Types
5868 @cindex Types
5869 @cindex C types
5871 The following macros check for C types, either builtin or typedefs.  If
5872 there is no macro specifically defined to check for a type you need, and
5873 you don't need to check for any special properties of it, then you can
5874 use a general type-check macro.
5876 @menu
5877 * Particular Types::            Special handling to find certain types
5878 * Generic Types::               How to find other types
5879 @end menu
5881 @node Particular Types
5882 @subsection Particular Type Checks
5884 @hdrindex{sys/types.h}
5885 @hdrindex{stdlib.h}
5886 @hdrindex{stdint.h}
5887 @hdrindex{inttypes.h}
5888 These macros check for particular C types in @file{sys/types.h},
5889 @file{stdlib.h}, @file{stdint.h}, @file{inttypes.h} and others, if they
5890 exist.
5892 The Gnulib @code{stdint} module is an alternate way to define many of
5893 these symbols; it is useful if you prefer your code to assume a
5894 C99-or-better environment.  @xref{Gnulib}.
5896 @defmac AC_TYPE_GETGROUPS
5897 @acindex{TYPE_GETGROUPS}
5898 @cvindex GETGROUPS_T
5899 Define @code{GETGROUPS_T} to be whichever of @code{gid_t} or @code{int}
5900 is the base type of the array argument to @code{getgroups}.
5901 @end defmac
5903 @defmac AC_TYPE_INT8_T
5904 @acindex{TYPE_INT8_T}
5905 @cvindex HAVE_INT8_T
5906 @cvindex int8_t
5907 If @file{stdint.h} or @file{inttypes.h} defines the type @code{int8_t},
5908 define @code{HAVE_INT8_T}.  Otherwise, define @code{int8_t} to a signed
5909 integer type that is exactly 8 bits wide and that uses two's complement
5910 representation, if such a type exists.
5911 @end defmac
5913 @defmac AC_TYPE_INT16_T
5914 @acindex{TYPE_INT16_T}
5915 @cvindex HAVE_INT16_T
5916 @cvindex int16_t
5917 This is like @code{AC_TYPE_INT8_T}, except for 16-bit integers.
5918 @end defmac
5920 @defmac AC_TYPE_INT32_T
5921 @acindex{TYPE_INT32_T}
5922 @cvindex HAVE_INT32_T
5923 @cvindex int32_t
5924 This is like @code{AC_TYPE_INT8_T}, except for 32-bit integers.
5925 @end defmac
5927 @defmac AC_TYPE_INT64_T
5928 @acindex{TYPE_INT64_T}
5929 @cvindex HAVE_INT64_T
5930 @cvindex int64_t
5931 This is like @code{AC_TYPE_INT8_T}, except for 64-bit integers.
5932 @end defmac
5934 @defmac AC_TYPE_INTMAX_T
5935 @acindex{TYPE_INTMAX_T}
5936 @cvindex HAVE_INTMAX_T
5937 @cvindex intmax_t
5938 If @file{stdint.h} or @file{inttypes.h} defines the type @code{intmax_t},
5939 define @code{HAVE_INTMAX_T}.  Otherwise, define @code{intmax_t} to the
5940 widest signed integer type.
5941 @end defmac
5943 @defmac AC_TYPE_INTPTR_T
5944 @acindex{TYPE_INTPTR_T}
5945 @cvindex HAVE_INTPTR_T
5946 @cvindex intptr_t
5947 If @file{stdint.h} or @file{inttypes.h} defines the type @code{intptr_t},
5948 define @code{HAVE_INTPTR_T}.  Otherwise, define @code{intptr_t} to a
5949 signed integer type wide enough to hold a pointer, if such a type
5950 exists.
5951 @end defmac
5953 @defmac AC_TYPE_LONG_DOUBLE
5954 @acindex{TYPE_LONG_DOUBLE}
5955 @cvindex HAVE_LONG_DOUBLE
5956 If the C compiler supports a working @code{long double} type, define
5957 @code{HAVE_LONG_DOUBLE}.  The @code{long double} type might have the
5958 same range and precision as @code{double}.
5959 @end defmac
5961 @defmac AC_TYPE_LONG_DOUBLE_WIDER
5962 @acindex{TYPE_LONG_DOUBLE_WIDER}
5963 @cvindex HAVE_LONG_DOUBLE_WIDER
5964 If the C compiler supports a working @code{long double} type with more
5965 range or precision than the @code{double} type, define
5966 @code{HAVE_LONG_DOUBLE_WIDER}.
5967 @end defmac
5969 @defmac AC_TYPE_LONG_LONG_INT
5970 @acindex{TYPE_LONG_LONG_INT}
5971 @cvindex HAVE_LONG_LONG_INT
5972 If the C compiler supports a working @code{long long int} type, define
5973 @code{HAVE_LONG_LONG_INT}.
5974 @end defmac
5976 @defmac AC_TYPE_MBSTATE_T
5977 @acindex{TYPE_MBSTATE_T}
5978 @cvindex mbstate_t
5979 @hdrindex{wchar.h}
5980 Define @code{HAVE_MBSTATE_T} if @code{<wchar.h>} declares the
5981 @code{mbstate_t} type.  Also, define @code{mbstate_t} to be a type if
5982 @code{<wchar.h>} does not declare it.
5983 @end defmac
5985 @defmac AC_TYPE_MODE_T
5986 @acindex{TYPE_MODE_T}
5987 @cvindex mode_t
5988 Define @code{mode_t} to a suitable type, if standard headers do not
5989 define it.
5990 @end defmac
5992 @defmac AC_TYPE_OFF_T
5993 @acindex{TYPE_OFF_T}
5994 @cvindex off_t
5995 Define @code{off_t} to a suitable type, if standard headers do not
5996 define it.
5997 @end defmac
5999 @defmac AC_TYPE_PID_T
6000 @acindex{TYPE_PID_T}
6001 @cvindex pid_t
6002 Define @code{pid_t} to a suitable type, if standard headers do not
6003 define it.
6004 @end defmac
6006 @defmac AC_TYPE_SIGNAL
6007 @acindex{TYPE_SIGNAL}
6008 @cvindex RETSIGTYPE
6009 @hdrindex{signal.h}
6010 If @file{signal.h} declares @code{signal} as returning a pointer to a
6011 function returning @code{void}, define @code{RETSIGTYPE} to be
6012 @code{void}; otherwise, define it to be @code{int}.
6014 Define signal handlers as returning type @code{RETSIGTYPE}:
6016 @example
6017 @group
6018 RETSIGTYPE
6019 hup_handler ()
6021 @dots{}
6023 @end group
6024 @end example
6025 @end defmac
6027 @defmac AC_TYPE_SIZE_T
6028 @acindex{TYPE_SIZE_T}
6029 @cvindex size_t
6030 Define @code{size_t} to a suitable type, if standard headers do not
6031 define it.
6032 @end defmac
6034 @defmac AC_TYPE_SSIZE_T
6035 @acindex{TYPE_SSIZE_T}
6036 @cvindex ssize_t
6037 Define @code{ssize_t} to a suitable type, if standard headers do not
6038 define it.
6039 @end defmac
6041 @defmac AC_TYPE_UID_T
6042 @acindex{TYPE_UID_T}
6043 @cvindex uid_t
6044 @cvindex gid_t
6045 Define @code{uid_t} and @code{gid_t} to suitable types, if standard
6046 headers do not define them.
6047 @end defmac
6049 @defmac AC_TYPE_UINT8_T
6050 @acindex{TYPE_UINT8_T}
6051 @cvindex HAVE_UINT8_T
6052 @cvindex uint8_t
6053 If @file{stdint.h} or @file{inttypes.h} defines the type @code{uint8_t},
6054 define @code{HAVE_UINT8_T}.  Otherwise, define @code{uint8_t} to an
6055 unsigned integer type that is exactly 8 bits wide, if such a type
6056 exists.
6057 @end defmac
6059 @defmac AC_TYPE_UINT16_T
6060 @acindex{TYPE_UINT16_T}
6061 @cvindex HAVE_UINT16_T
6062 @cvindex uint16_t
6063 This is like @code{AC_TYPE_UINT8_T}, except for 16-bit unsigned integers.
6064 @end defmac
6066 @defmac AC_TYPE_UINT32_T
6067 @acindex{TYPE_UINT32_T}
6068 @cvindex HAVE_UINT32_T
6069 @cvindex uint32_t
6070 This is like @code{AC_TYPE_UINT8_T}, except for 32-bit unsigned integers.
6071 @end defmac
6073 @defmac AC_TYPE_UINT64_T
6074 @acindex{TYPE_UINT64_T}
6075 @cvindex HAVE_UINT64_T
6076 @cvindex uint64_t
6077 This is like @code{AC_TYPE_UINT8_T}, except for 64-bit unsigned integers.
6078 @end defmac
6080 @defmac AC_TYPE_UINTMAX_T
6081 @acindex{TYPE_UINTMAX_T}
6082 @cvindex HAVE_UINTMAX_T
6083 @cvindex uintmax_t
6084 If @file{stdint.h} or @file{inttypes.h} defines the type @code{uintmax_t},
6085 define @code{HAVE_UINTMAX_T}.  Otherwise, define @code{uintmax_t} to the
6086 widest unsigned integer type.
6087 @end defmac
6089 @defmac AC_TYPE_UINTPTR_T
6090 @acindex{TYPE_UINTPTR_T}
6091 @cvindex HAVE_UINTPTR_T
6092 @cvindex uintptr_t
6093 If @file{stdint.h} or @file{inttypes.h} defines the type @code{uintptr_t},
6094 define @code{HAVE_UINTPTR_T}.  Otherwise, define @code{uintptr_t} to an
6095 unsigned integer type wide enough to hold a pointer, if such a type
6096 exists.
6097 @end defmac
6099 @defmac AC_TYPE_UNSIGNED_LONG_LONG_INT
6100 @acindex{TYPE_UNSIGNED_LONG_LONG_INT}
6101 @cvindex HAVE_UNSIGNED_LONG_LONG_INT
6102 If the C compiler supports a working @code{unsigned long long int} type,
6103 define @code{HAVE_UNSIGNED_LONG_LONG_INT}.
6104 @end defmac
6106 @node Generic Types
6107 @subsection Generic Type Checks
6109 These macros are used to check for types not covered by the ``particular''
6110 test macros.
6112 @defmac AC_CHECK_TYPE (@var{type}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
6113 @acindex{CHECK_TYPE}
6114 Check whether @var{type} is defined.  It may be a compiler builtin type
6115 or defined by the @var{includes} (@pxref{Default Includes}).
6116 @end defmac
6119 @defmac AC_CHECK_TYPES (@var{types}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
6120 @acindex{CHECK_TYPES}
6121 For each @var{type} of the @var{types} that is defined, define
6122 @code{HAVE_@var{type}} (in all capitals).  If no @var{includes} are
6123 specified, the default includes are used (@pxref{Default Includes}).  If
6124 @var{action-if-found} is given, it is additional shell code to execute
6125 when one of the types is found.  If @var{action-if-not-found} is given,
6126 it is executed when one of the types is not found.
6128 This macro uses M4 lists:
6129 @example
6130 AC_CHECK_TYPES([ptrdiff_t])
6131 AC_CHECK_TYPES([unsigned long long int, uintmax_t])
6132 @end example
6134 @end defmac
6136 Autoconf, up to 2.13, used to provide to another version of
6137 @code{AC_CHECK_TYPE}, broken by design.  In order to keep backward
6138 compatibility, a simple heuristics, quite safe but not totally, is
6139 implemented.  In case of doubt, read the documentation of the former
6140 @code{AC_CHECK_TYPE}, see @ref{Obsolete Macros}.
6143 @node Compilers and Preprocessors
6144 @section Compilers and Preprocessors
6145 @cindex Compilers
6146 @cindex Preprocessors
6148 @ovindex EXEEXT
6149 All the tests for compilers (@code{AC_PROG_CC}, @code{AC_PROG_CXX},
6150 @code{AC_PROG_F77}) define the output variable @code{EXEEXT} based on
6151 the output of the compiler, typically to the empty string if
6152 Posix and @samp{.exe} if a @acronym{DOS} variant.
6154 @ovindex OBJEXT
6155 They also define the output variable @code{OBJEXT} based on the
6156 output of the compiler, after @file{.c} files have been excluded, typically
6157 to @samp{o} if Posix, @samp{obj} if a @acronym{DOS} variant.
6159 If the compiler being used does not produce executables, the tests fail.  If
6160 the executables can't be run, and cross-compilation is not enabled, they
6161 fail too.  @xref{Manual Configuration}, for more on support for cross
6162 compiling.
6164 @menu
6165 * Specific Compiler Characteristics::  Some portability issues
6166 * Generic Compiler Characteristics::  Language independent tests and features
6167 * C Compiler::                  Checking its characteristics
6168 * C++ Compiler::                Likewise
6169 * Objective C Compiler::        Likewise
6170 * Erlang Compiler and Interpreter::  Likewise
6171 * Fortran Compiler::            Likewise
6172 @end menu
6174 @node Specific Compiler Characteristics
6175 @subsection Specific Compiler Characteristics
6177 Some compilers exhibit different behaviors.
6179 @table @asis
6180 @item Static/Dynamic Expressions
6181 Autoconf relies on a trick to extract one bit of information from the C
6182 compiler: using negative array sizes.  For instance the following
6183 excerpt of a C source demonstrates how to test whether @samp{int} objects are 4
6184 bytes wide:
6186 @example
6187 static int test_array[sizeof (int) == 4 ? 1 : -1];
6188 @end example
6190 @noindent
6191 To our knowledge, there is a single compiler that does not support this
6192 trick: the @acronym{HP} C compilers (the real ones, not only the ``bundled'') on
6193 @acronym{HP-UX} 11.00.
6194 They incorrectly reject the above program with the diagnostic
6195 ``Variable-length arrays cannot have static storage.''
6196 This bug comes from @acronym{HP} compilers' mishandling of @code{sizeof (int)},
6197 not from the @code{? 1 : -1}, and
6198 Autoconf works around this problem by casting @code{sizeof (int)} to
6199 @code{long int} before comparing it.
6200 @end table
6202 @node Generic Compiler Characteristics
6203 @subsection Generic Compiler Characteristics
6205 @defmac AC_CHECK_SIZEOF (@var{type}, @ovar{unused}, @dvar{includes, default-includes})
6206 @acindex{CHECK_SIZEOF}
6207 Define @code{SIZEOF_@var{type}} (@pxref{Standard Symbols}) to be the
6208 size in bytes of @var{type}.  If @samp{type} is unknown, it gets a size
6209 of 0.  If no @var{includes} are specified, the default includes are used
6210 (@pxref{Default Includes}).
6212 This macro now works even when cross-compiling.  The @var{unused}
6213 argument was used when cross-compiling.
6215 For example, the call
6217 @example
6218 AC_CHECK_SIZEOF([int *])
6219 @end example
6221 @noindent
6222 defines @code{SIZEOF_INT_P} to be 8 on DEC Alpha AXP systems.
6223 @end defmac
6225 @defmac AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, default-includes})
6226 @acindex{CHECK_ALIGNOF}
6227 Define @code{ALIGNOF_@var{type}} (@pxref{Standard Symbols}) to be the
6228 alignment in bytes of @var{type}.  If @samp{type} is unknown, it gets a size
6229 of 0.  If no @var{includes} are specified, the default includes are used
6230 (@pxref{Default Includes}).
6231 @end defmac
6233 @defmac AC_COMPUTE_INT (@var{var}, @var{expression}, @dvar{includes, default-includes}, @ovar{action-if-fails})
6234 @acindex{COMPUTE_INT}
6235 Store into the shell variable @var{var} the value of the integer
6236 @var{expression}.  The
6237 value should fit in an initializer in a C variable of type @code{signed
6238 long}.  To support cross compilation (in which case, the macro only works on
6239 hosts that use twos-complement arithmetic), it should be possible to evaluate
6240 the expression at compile-time.  If no @var{includes} are specified, the default
6241 includes are used (@pxref{Default Includes}).
6243 Execute @var{action-if-fails} if the value cannot be determined correctly.
6244 @end defmac
6246 @defmac AC_LANG_WERROR
6247 @acindex{LANG_WERROR}
6248 Normally Autoconf ignores warnings generated by the compiler, linker, and
6249 preprocessor.  If this macro is used, warnings count as fatal
6250 errors for the current language.  This macro is useful when the
6251 results of configuration are used where warnings are unacceptable; for
6252 instance, if parts of a program are built with the @acronym{GCC}
6253 @option{-Werror}
6254 option.  If the whole program is built using @option{-Werror} it is
6255 often simpler to put @option{-Werror} in the compiler flags (@code{CFLAGS},
6256 etc.).
6257 @end defmac
6259 @node C Compiler
6260 @subsection C Compiler Characteristics
6262 The following macros provide ways to find and exercise a C Compiler.
6263 There are a few constructs that ought to be avoided, but do not deserve
6264 being checked for, since they can easily be worked around.
6266 @table @asis
6267 @item Don't use lines containing solitary backslashes
6268 They tickle a bug in the @acronym{HP-UX} C compiler (checked on
6269 @acronym{HP-UX} 10.20,
6270 11.00, and 11i).  When given the following source:
6272 @example
6273 #ifdef __STDC__
6275 * A comment with backslash-newlines in it.  %@{ %@} *\
6278 char str[] = "\\
6279 " A string with backslash-newlines in it %@{ %@} \\
6281 char apostrophe = '\\
6285 #endif
6286 @end example
6288 @noindent
6289 the compiler incorrectly fails with the diagnostics ``Non-terminating
6290 comment at end of file'' and ``Missing @samp{#endif} at end of file.''
6291 Removing the lines with solitary backslashes solves the problem.
6293 @item Don't compile several files at once if output matters to you
6294 Some compilers, such as @acronym{HP}'s, report names of files being
6295 compiled when given more than one file operand.  For instance:
6297 @example
6298 $ @kbd{cc a.c b.c}
6299 a.c:
6300 b.c:
6301 @end example
6303 @noindent
6304 This can cause problems if you observe the output of the compiler to
6305 detect failures.  Invoking @samp{cc -c a.c && cc -c b.c && cc -o c a.o
6306 b.o} solves the issue.
6308 @item Don't rely on @code{#error} failing
6309 The @sc{irix} C compiler does not fail when #error is preprocessed; it
6310 simply emits a diagnostic and continues, exiting successfully.  So,
6311 instead of an error directive like @code{#error "Unsupported word size"}
6312 it is more portable to use an invalid directive like @code{#Unsupported
6313 word size} in Autoconf tests.  In ordinary source code, @code{#error} is
6314 OK, since installers with inadequate compilers like @sc{irix} can simply
6315 examine these compilers' diagnostic output.
6317 @item Don't rely on correct @code{#line} support
6318 On Solaris, @command{c89} (at least Sun C 5.3 through 5.8)
6319 diagnoses @code{#line} directives whose line
6320 numbers are greater than 32767.  Nothing in Posix
6321 makes this invalid.  That is why Autoconf stopped issuing
6322 @code{#line} directives.
6323 @end table
6325 @defmac AC_PROG_CC (@ovar{compiler-search-list})
6326 @acindex{PROG_CC}
6327 @ovindex CC
6328 @ovindex CFLAGS
6329 Determine a C compiler to use.  If @code{CC} is not already set in the
6330 environment, check for @code{gcc} and @code{cc}, then for other C
6331 compilers.  Set output variable @code{CC} to the name of the compiler
6332 found.
6334 This macro may, however, be invoked with an optional first argument
6335 which, if specified, must be a blank-separated list of C compilers to
6336 search for.  This just gives the user an opportunity to specify an
6337 alternative search list for the C compiler.  For example, if you didn't
6338 like the default order, then you could invoke @code{AC_PROG_CC} like
6339 this:
6341 @example
6342 AC_PROG_CC([gcc cl cc])
6343 @end example
6345 If the C compiler does not handle function prototypes correctly by
6346 default, try to add an option to output variable @code{CC} to make it
6347 so.  This macro tries various options that select standard-conformance
6348 modes on various systems.
6350 After calling this macro you can check whether the C compiler has been
6351 set to accept @acronym{ANSI} C89 (@acronym{ISO} C90); if not, the shell
6352 variable
6353 @code{ac_cv_prog_cc_c89} is set to @samp{no}.  See also
6354 @code{AC_C_PROTOTYPES} below.
6356 If using the @acronym{GNU} C compiler, set shell variable @code{GCC} to
6357 @samp{yes}.  If output variable @code{CFLAGS} was not already set, set
6358 it to @option{-g -O2} for the @acronym{GNU} C compiler (@option{-O2} on systems
6359 where @acronym{GCC} does not accept @option{-g}), or @option{-g} for
6360 other compilers.
6361 @end defmac
6363 @defmac AC_PROG_CC_C_O
6364 @acindex{PROG_CC_C_O}
6365 @cvindex NO_MINUS_C_MINUS_O
6366 If the C compiler does not accept the @option{-c} and @option{-o} options
6367 simultaneously, define @code{NO_MINUS_C_MINUS_O}.  This macro actually
6368 tests both the compiler found by @code{AC_PROG_CC}, and, if different,
6369 the first @code{cc} in the path.  The test fails if one fails.  This
6370 macro was created for @acronym{GNU} Make to choose the default C compilation
6371 rule.
6372 @end defmac
6375 @defmac AC_PROG_CPP
6376 @acindex{PROG_CPP}
6377 @ovindex CPP
6378 Set output variable @code{CPP} to a command that runs the
6379 C preprocessor.  If @samp{$CC -E} doesn't work, @file{/lib/cpp} is used.
6380 It is only portable to run @code{CPP} on files with a @file{.c}
6381 extension.
6383 Some preprocessors don't indicate missing include files by the error
6384 status.  For such preprocessors an internal variable is set that causes
6385 other macros to check the standard error from the preprocessor and
6386 consider the test failed if any warnings have been reported.
6387 For most preprocessors, though, warnings do not cause include-file
6388 tests to fail unless @code{AC_PROG_CPP_WERROR} is also specified.
6389 @end defmac
6391 @defmac AC_PROG_CPP_WERROR
6392 @acindex{PROG_CPP_WERROR}
6393 @ovindex CPP
6394 This acts like @code{AC_PROG_CPP}, except it treats warnings from the
6395 preprocessor as errors even if the preprocessor exit status indicates
6396 success.  This is useful for avoiding headers that generate mandatory
6397 warnings, such as deprecation notices.
6398 @end defmac
6401 The following macros check for C compiler or machine architecture
6402 features.  To check for characteristics not listed here, use
6403 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
6404 @code{AC_RUN_IFELSE} (@pxref{Runtime}).
6406 @defmac AC_PROG_CC_STDC
6407 @acindex{PROG_CC_STDC}
6408 If the C compiler cannot compile @acronym{ISO} Standard C (currently
6409 C99), try to add an option to output variable @code{CC} to make it work.
6410 If the compiler does not support C99, fall back to supporting
6411 @acronym{ANSI} C89 (@acronym{ISO} C90).
6413 After calling this macro you can check whether the C compiler has been
6414 set to accept Standard C; if not, the shell variable
6415 @code{ac_cv_prog_cc_stdc} is set to @samp{no}.
6416 @end defmac
6418 @defmac AC_PROG_CC_C89
6419 @acindex{PROG_CC_C89}
6420 If the C compiler is not in @acronym{ANSI} C89 (@acronym{ISO} C90) mode by
6421 default, try to add an option to output variable @code{CC} to make it
6422 so.  This macro tries various options that select @acronym{ANSI} C89 on
6423 some system or another.  It considers the compiler to be in
6424 @acronym{ANSI} C89 mode if it handles function prototypes correctly.
6426 After calling this macro you can check whether the C compiler has been
6427 set to accept @acronym{ANSI} C89; if not, the shell variable
6428 @code{ac_cv_prog_cc_c89} is set to @samp{no}.
6430 This macro is called automatically by @code{AC_PROG_CC}.
6431 @end defmac
6433 @defmac AC_PROG_CC_C99
6434 @acindex{PROG_CC_C99}
6435 If the C compiler is not in C99 mode by default, try to add an
6436 option to output variable @code{CC} to make it so.  This macro tries
6437 various options that select C99 on some system or another.  It
6438 considers the compiler to be in C99 mode if it handles @code{_Bool},
6439 @code{//} comments, flexible array members, @code{inline}, @code{long
6440 long int}, mixed code and declarations, named initialization of structs,
6441 @code{restrict}, @code{va_copy}, varargs macros, variable declarations
6442 in @code{for} loops, and variable length arrays.
6444 After calling this macro you can check whether the C compiler has been
6445 set to accept C99; if not, the shell variable
6446 @code{ac_cv_prog_cc_c99} is set to @samp{no}.
6447 @end defmac
6449 @defmac AC_C_BACKSLASH_A
6450 @acindex{HAVE_C_BACKSLASH_A}
6451 Define @samp{HAVE_C_BACKSLASH_A} to 1 if the C compiler understands
6452 @samp{\a}.
6454 This macro is obsolescent, as current C compilers understand @samp{\a}.
6455 New programs need not use this macro.
6456 @end defmac
6458 @defmac AC_C_BIGENDIAN (@ovar{action-if-true}, @ovar{action-if-false}, @ovar{action-if-unknown})
6459 @acindex{C_BIGENDIAN}
6460 @cvindex WORDS_BIGENDIAN
6461 @cindex Endianness
6462 If words are stored with the most significant byte first (like Motorola
6463 and SPARC CPUs), execute @var{action-if-true}.  If words are stored with
6464 the least significant byte first (like Intel and VAX CPUs), execute
6465 @var{action-if-false}.
6467 This macro runs a test-case if endianness cannot be determined from the
6468 system header files.  When cross-compiling, the test-case is not run but
6469 grep'ed for some magic values.  @var{action-if-unknown} is executed if
6470 the latter case fails to determine the byte sex of the host system.
6472 The default for @var{action-if-true} is to define
6473 @samp{WORDS_BIGENDIAN}.  The default for @var{action-if-false} is to do
6474 nothing.  And finally, the default for @var{action-if-unknown} is to
6475 abort configure and tell the installer which variable he should preset
6476 to bypass this test.
6477 @end defmac
6479 @defmac AC_C_CONST
6480 @acindex{C_CONST}
6481 @cvindex const
6482 If the C compiler does not fully support the @code{const} keyword,
6483 define @code{const} to be empty.  Some C compilers that do
6484 not define @code{__STDC__} do support @code{const}; some compilers that
6485 define @code{__STDC__} do not completely support @code{const}.  Programs
6486 can simply use @code{const} as if every C compiler supported it; for
6487 those that don't, the makefile or configuration header file
6488 defines it as empty.
6490 Occasionally installers use a C++ compiler to compile C code, typically
6491 because they lack a C compiler.  This causes problems with @code{const},
6492 because C and C++ treat @code{const} differently.  For example:
6494 @example
6495 const int foo;
6496 @end example
6498 @noindent
6499 is valid in C but not in C++.  These differences unfortunately cannot be
6500 papered over by defining @code{const} to be empty.
6502 If @command{autoconf} detects this situation, it leaves @code{const} alone,
6503 as this generally yields better results in practice.  However, using a
6504 C++ compiler to compile C code is not recommended or supported, and
6505 installers who run into trouble in this area should get a C compiler
6506 like @acronym{GCC} to compile their C code.
6508 This macro is obsolescent, as current C compilers support @code{const}.
6509 New programs need not use this macro.
6510 @end defmac
6512 @defmac AC_C_RESTRICT
6513 @acindex{C_RESTRICT}
6514 @cvindex restrict
6515 If the C compiler recognizes the @code{restrict} keyword, don't do anything.
6516 If it recognizes only a variant spelling (@code{__restrict},
6517 @code{__restrict__}, or @code{_Restrict}), then define
6518 @code{restrict} to that.
6519 Otherwise, define @code{restrict} to be empty.
6520 Thus, programs may simply use @code{restrict} as if every C compiler
6521 supported it; for those that do not, the makefile
6522 or configuration header defines it away.
6524 Although support in C++ for the @code{restrict} keyword is not
6525 required, several C++ compilers do accept the keyword.
6526 This macro works for them, too.
6527 @end defmac
6529 @defmac AC_C_VOLATILE
6530 @acindex{C_VOLATILE}
6531 @cvindex volatile
6532 If the C compiler does not understand the keyword @code{volatile},
6533 define @code{volatile} to be empty.  Programs can simply use
6534 @code{volatile} as if every C compiler supported it; for those that do
6535 not, the makefile or configuration header defines it as
6536 empty.
6538 If the correctness of your program depends on the semantics of
6539 @code{volatile}, simply defining it to be empty does, in a sense, break
6540 your code.  However, given that the compiler does not support
6541 @code{volatile}, you are at its mercy anyway.  At least your
6542 program compiles, when it wouldn't before.
6543 @xref{Volatile Objects}, for more about @code{volatile}.
6545 In general, the @code{volatile} keyword is a standard C feature, so
6546 you might expect that @code{volatile} is available only when
6547 @code{__STDC__} is defined.  However, Ultrix 4.3's native compiler does
6548 support volatile, but does not define @code{__STDC__}.
6550 This macro is obsolescent, as current C compilers support @code{volatile}.
6551 New programs need not use this macro.
6552 @end defmac
6554 @defmac AC_C_INLINE
6555 @acindex{C_INLINE}
6556 @cvindex inline
6557 If the C compiler supports the keyword @code{inline}, do nothing.
6558 Otherwise define @code{inline} to @code{__inline__} or @code{__inline}
6559 if it accepts one of those, otherwise define @code{inline} to be empty.
6560 @end defmac
6562 @defmac AC_C_CHAR_UNSIGNED
6563 @acindex{C_CHAR_UNSIGNED}
6564 @cvindex __CHAR_UNSIGNED__
6565 If the C type @code{char} is unsigned, define @code{__CHAR_UNSIGNED__},
6566 unless the C compiler predefines it.
6567 @end defmac
6569 @defmac AC_C_STRINGIZE
6570 @acindex{C_STRINGIZE}
6571 @cvindex HAVE_STRINGIZE
6572 If the C preprocessor supports the stringizing operator, define
6573 @code{HAVE_STRINGIZE}.  The stringizing operator is @samp{#} and is
6574 found in macros such as this:
6576 @example
6577 #define x(y) #y
6578 @end example
6580 This macro is obsolescent, as current C compilers support the
6581 stringizing operator.  New programs need not use this macro.
6582 @end defmac
6584 @defmac AC_C_FLEXIBLE_ARRAY_MEMBER
6585 @acindex{C_FLEXIBLE_ARRAY_MEMBER}
6586 @cvindex FLEXIBLE_ARRAY_MEMBER
6587 If the C compiler supports flexible array members, define
6588 @code{FLEXIBLE_ARRAY_MEMBER} to nothing; otherwise define it to 1.
6589 That way, a declaration like this:
6591 @example
6592 struct s
6593   @{
6594     size_t n_vals;
6595     double val[FLEXIBLE_ARRAY_MEMBER];
6596   @};
6597 @end example
6599 @noindent
6600 will let applications use the ``struct hack'' even with compilers that
6601 do not support flexible array members.  To allocate and use such an
6602 object, you can use code like this:
6604 @example
6605 size_t i;
6606 size_t n = compute_value_count ();
6607 struct s *p =
6608    malloc (offsetof (struct s, val)
6609            + n * sizeof (double));
6610 p->n_vals = n;
6611 for (i = 0; i < n; i++)
6612   p->val[i] = compute_value (i);
6613 @end example
6614 @end defmac
6616 @defmac AC_C_VARARRAYS
6617 @acindex{C_VARARRAYS}
6618 @cvindex HAVE_C_VARARRAYS
6619 If the C compiler supports variable-length arrays, define
6620 @code{HAVE_C_VARARRAYS}.  A variable-length array is an array of automatic
6621 storage duration whose length is determined at run time, when the array
6622 is declared.
6623 @end defmac
6625 @defmac AC_C_TYPEOF
6626 @acindex{C_TYPEOF}
6627 @cvindex HAVE_TYPEOF
6628 @cvindex typeof
6629 If the C compiler supports @acronym{GCC}'s @code{typeof} syntax either
6630 directly or
6631 through a different spelling of the keyword (e.g., @code{__typeof__}),
6632 define @code{HAVE_TYPEOF}.  If the support is available only through a
6633 different spelling, define @code{typeof} to that spelling.
6634 @end defmac
6636 @defmac AC_C_PROTOTYPES
6637 @acindex{C_PROTOTYPES}
6638 @cvindex PROTOTYPES
6639 @cvindex __PROTOTYPES
6640 @cvindex PARAMS
6641 If function prototypes are understood by the compiler (as determined by
6642 @code{AC_PROG_CC}), define @code{PROTOTYPES} and @code{__PROTOTYPES}.
6643 Defining @code{__PROTOTYPES} is for the benefit of
6644 header files that cannot use macros that infringe on user name space.
6646 This macro is obsolescent, as current C compilers support prototypes.
6647 New programs need not use this macro.
6648 @end defmac
6650 @defmac AC_PROG_GCC_TRADITIONAL
6651 @acindex{PROG_GCC_TRADITIONAL}
6652 @ovindex CC
6653 Add @option{-traditional} to output variable @code{CC} if using the
6654 @acronym{GNU} C compiler and @code{ioctl} does not work properly without
6655 @option{-traditional}.  That usually happens when the fixed header files
6656 have not been installed on an old system.
6658 This macro is obsolescent, since current versions of the @acronym{GNU} C
6659 compiler fix the header files automatically when installed.
6660 @end defmac
6663 @node C++ Compiler
6664 @subsection C++ Compiler Characteristics
6667 @defmac AC_PROG_CXX (@ovar{compiler-search-list})
6668 @acindex{PROG_CXX}
6669 @ovindex CXX
6670 @ovindex CXXFLAGS
6671 Determine a C++ compiler to use.  Check whether the environment variable
6672 @code{CXX} or @code{CCC} (in that order) is set; if so, then set output
6673 variable @code{CXX} to its value.
6675 Otherwise, if the macro is invoked without an argument, then search for
6676 a C++ compiler under the likely names (first @code{g++} and @code{c++}
6677 then other names).  If none of those checks succeed, then as a last
6678 resort set @code{CXX} to @code{g++}.
6680 This macro may, however, be invoked with an optional first argument
6681 which, if specified, must be a blank-separated list of C++ compilers to
6682 search for.  This just gives the user an opportunity to specify an
6683 alternative search list for the C++ compiler.  For example, if you
6684 didn't like the default order, then you could invoke @code{AC_PROG_CXX}
6685 like this:
6687 @example
6688 AC_PROG_CXX([gcc cl KCC CC cxx cc++ xlC aCC c++ g++])
6689 @end example
6691 If using the @acronym{GNU} C++ compiler, set shell variable @code{GXX} to
6692 @samp{yes}.  If output variable @code{CXXFLAGS} was not already set, set
6693 it to @option{-g -O2} for the @acronym{GNU} C++ compiler (@option{-O2} on
6694 systems where G++ does not accept @option{-g}), or @option{-g} for other
6695 compilers.
6696 @end defmac
6698 @defmac AC_PROG_CXXCPP
6699 @acindex{PROG_CXXCPP}
6700 @ovindex CXXCPP
6701 Set output variable @code{CXXCPP} to a command that runs the C++
6702 preprocessor.  If @samp{$CXX -E} doesn't work, @file{/lib/cpp} is used.
6703 It is portable to run @code{CXXCPP} only on files with a @file{.c},
6704 @file{.C}, @file{.cc}, or @file{.cpp} extension.
6706 Some preprocessors don't indicate missing include files by the error
6707 status.  For such preprocessors an internal variable is set that causes
6708 other macros to check the standard error from the preprocessor and
6709 consider the test failed if any warnings have been reported.  However,
6710 it is not known whether such broken preprocessors exist for C++.
6711 @end defmac
6713 @defmac AC_PROG_CXX_C_O
6714 @acindex{PROG_CXX_C_O}
6715 @cvindex CXX_NO_MINUS_C_MINUS_O
6716 Test whether the C++ compiler accepts the options @option{-c} and
6717 @option{-o} simultaneously, and define @code{CXX_NO_MINUS_C_MINUS_O},
6718 if it does not.
6719 @end defmac
6722 @node Objective C Compiler
6723 @subsection Objective C Compiler Characteristics
6726 @defmac AC_PROG_OBJC (@ovar{compiler-search-list})
6727 @acindex{PROG_OBJC}
6728 @ovindex OBJC
6729 @ovindex OBJCFLAGS
6730 Determine an Objective C compiler to use.  If @code{OBJC} is not already
6731 set in the environment, check for Objective C compilers.  Set output
6732 variable @code{OBJC} to the name of the compiler found.
6734 This macro may, however, be invoked with an optional first argument
6735 which, if specified, must be a blank-separated list of Objective C compilers to
6736 search for.  This just gives the user an opportunity to specify an
6737 alternative search list for the Objective C compiler.  For example, if you
6738 didn't like the default order, then you could invoke @code{AC_PROG_OBJC}
6739 like this:
6741 @example
6742 AC_PROG_OBJC([gcc objcc objc])
6743 @end example
6745 If using the @acronym{GNU} Objective C compiler, set shell variable
6746 @code{GOBJC} to @samp{yes}.  If output variable @code{OBJCFLAGS} was not
6747 already set, set it to @option{-g -O2} for the @acronym{GNU} Objective C
6748 compiler (@option{-O2} on systems where @command{gcc} does not accept
6749 @option{-g}), or @option{-g} for other compilers.
6750 @end defmac
6752 @defmac AC_PROG_OBJCPP
6753 @acindex{PROG_OBJCPP}
6754 @ovindex OBJCPP
6755 Set output variable @code{OBJCPP} to a command that runs the Objective C
6756 preprocessor.  If @samp{$OBJC -E} doesn't work, @file{/lib/cpp} is used.
6757 @end defmac
6760 @node Erlang Compiler and Interpreter
6761 @subsection Erlang Compiler and Interpreter Characteristics
6762 @cindex Erlang
6764 Autoconf defines the following macros for determining paths to the essential
6765 Erlang/OTP programs:
6767 @defmac AC_ERLANG_PATH_ERLC (@ovar{value-if-not-found}, @ovar{path})
6768 @acindex{ERLANG_PATH_ERLC}
6769 @ovindex ERLC
6770 @ovindex ERLCFLAGS
6771 Determine an Erlang compiler to use.  If @code{ERLC} is not already set in the
6772 environment, check for @command{erlc}.  Set output variable @code{ERLC} to the
6773 complete path of the compiler command found.  In addition, if @code{ERLCFLAGS}
6774 is not set in the environment, set it to an empty value.
6776 The two optional arguments have the same meaning as the two last arguments of
6777 macro @code{AC_PROG_PATH} for looking for the @command{erlc} program.  For
6778 example, to look for @command{erlc} only in the @file{/usr/lib/erlang/bin}
6779 directory:
6781 @example
6782 AC_ERLANG_PATH_ERLC([not found], [/usr/lib/erlang/bin])
6783 @end example
6784 @end defmac
6786 @defmac AC_ERLANG_NEED_ERLC (@ovar{path})
6787 @acindex{ERLANG_NEED_ERLC}
6788 A simplified variant of the @code{AC_ERLANG_PATH_ERLC} macro, that prints an
6789 error message and exits the @command{configure} script if the @command{erlc}
6790 program is not found.
6791 @end defmac
6793 @defmac AC_ERLANG_PATH_ERL (@ovar{value-if-not-found}, @ovar{path})
6794 @acindex{ERLANG_PATH_ERL}
6795 @ovindex ERL
6796 Determine an Erlang interpreter to use.  If @code{ERL} is not already set in the
6797 environment, check for @command{erl}.  Set output variable @code{ERL} to the
6798 complete path of the interpreter command found.
6800 The two optional arguments have the same meaning as the two last arguments of
6801 macro @code{AC_PROG_PATH} for looking for the @command{erl} program.  For
6802 example, to look for @command{erl} only in the @file{/usr/lib/erlang/bin}
6803 directory:
6805 @example
6806 AC_ERLANG_PATH_ERL([not found], [/usr/lib/erlang/bin])
6807 @end example
6808 @end defmac
6810 @defmac AC_ERLANG_NEED_ERL (@ovar{path})
6811 @acindex{ERLANG_NEED_ERL}
6812 A simplified variant of the @code{AC_ERLANG_PATH_ERL} macro, that prints an
6813 error message and exits the @command{configure} script if the @command{erl}
6814 program is not found.
6815 @end defmac
6818 @node Fortran Compiler
6819 @subsection Fortran Compiler Characteristics
6820 @cindex Fortran
6821 @cindex F77
6823 The Autoconf Fortran support is divided into two categories: legacy
6824 Fortran 77 macros (@code{F77}), and modern Fortran macros (@code{FC}).
6825 The former are intended for traditional Fortran 77 code, and have output
6826 variables like @code{F77}, @code{FFLAGS}, and @code{FLIBS}.  The latter
6827 are for newer programs that can (or must) compile under the newer
6828 Fortran standards, and have output variables like @code{FC},
6829 @code{FCFLAGS}, and @code{FCLIBS}.
6831 Except for two new macros @code{AC_FC_SRCEXT} and
6832 @code{AC_FC_FREEFORM} (see below), the @code{FC} and @code{F77} macros
6833 behave almost identically, and so they are documented together in this
6834 section.
6837 @defmac AC_PROG_F77 (@ovar{compiler-search-list})
6838 @acindex{PROG_F77}
6839 @ovindex F77
6840 @ovindex FFLAGS
6841 Determine a Fortran 77 compiler to use.  If @code{F77} is not already
6842 set in the environment, then check for @code{g77} and @code{f77}, and
6843 then some other names.  Set the output variable @code{F77} to the name
6844 of the compiler found.
6846 This macro may, however, be invoked with an optional first argument
6847 which, if specified, must be a blank-separated list of Fortran 77
6848 compilers to search for.  This just gives the user an opportunity to
6849 specify an alternative search list for the Fortran 77 compiler.  For
6850 example, if you didn't like the default order, then you could invoke
6851 @code{AC_PROG_F77} like this:
6853 @example
6854 AC_PROG_F77([fl32 f77 fort77 xlf g77 f90 xlf90])
6855 @end example
6857 If using @code{g77} (the @acronym{GNU} Fortran 77 compiler), then
6858 set the shell variable @code{G77} to @samp{yes}.
6859 If the output variable @code{FFLAGS} was not already set in the
6860 environment, then set it to @option{-g -02} for @code{g77} (or @option{-O2}
6861 where @code{g77} does not accept @option{-g}).  Otherwise, set
6862 @code{FFLAGS} to @option{-g} for all other Fortran 77 compilers.
6863 @end defmac
6865 @defmac AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect})
6866 @acindex{PROG_FC}
6867 @ovindex FC
6868 @ovindex FCFLAGS
6869 Determine a Fortran compiler to use.  If @code{FC} is not already set in
6870 the environment, then @code{dialect} is a hint to indicate what Fortran
6871 dialect to search for; the default is to search for the newest available
6872 dialect.  Set the output variable @code{FC} to the name of the compiler
6873 found.
6875 By default, newer dialects are preferred over older dialects, but if
6876 @code{dialect} is specified then older dialects are preferred starting
6877 with the specified dialect.  @code{dialect} can currently be one of
6878 Fortran 77, Fortran 90, or Fortran 95.  However, this is only a hint of
6879 which compiler @emph{name} to prefer (e.g., @code{f90} or @code{f95}),
6880 and no attempt is made to guarantee that a particular language standard
6881 is actually supported.  Thus, it is preferable that you avoid the
6882 @code{dialect} option, and use AC_PROG_FC only for code compatible with
6883 the latest Fortran standard.
6885 This macro may, alternatively, be invoked with an optional first argument
6886 which, if specified, must be a blank-separated list of Fortran
6887 compilers to search for, just as in @code{AC_PROG_F77}.
6889 If the output variable @code{FCFLAGS} was not already set in the
6890 environment, then set it to @option{-g -02} for @acronym{GNU} @code{g77} (or
6891 @option{-O2} where @code{g77} does not accept @option{-g}).  Otherwise,
6892 set @code{FCFLAGS} to @option{-g} for all other Fortran compilers.
6893 @end defmac
6895 @defmac AC_PROG_F77_C_O
6896 @defmacx AC_PROG_FC_C_O
6897 @acindex{PROG_F77_C_O}
6898 @acindex{PROG_FC_C_O}
6899 @cvindex F77_NO_MINUS_C_MINUS_O
6900 @cvindex FC_NO_MINUS_C_MINUS_O
6901 Test whether the Fortran compiler accepts the options @option{-c} and
6902 @option{-o} simultaneously, and define @code{F77_NO_MINUS_C_MINUS_O} or
6903 @code{FC_NO_MINUS_C_MINUS_O}, respectively, if it does not.
6904 @end defmac
6906 The following macros check for Fortran compiler characteristics.
6907 To check for characteristics not listed here, use
6908 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
6909 @code{AC_RUN_IFELSE} (@pxref{Runtime}), making sure to first set the
6910 current language to Fortran 77 or Fortran via @code{AC_LANG([Fortran 77])}
6911 or @code{AC_LANG(Fortran)} (@pxref{Language Choice}).
6914 @defmac AC_F77_LIBRARY_LDFLAGS
6915 @defmacx AC_FC_LIBRARY_LDFLAGS
6916 @acindex{F77_LIBRARY_LDFLAGS}
6917 @ovindex FLIBS
6918 @acindex{FC_LIBRARY_LDFLAGS}
6919 @ovindex FCLIBS
6920 Determine the linker flags (e.g., @option{-L} and @option{-l}) for the
6921 @dfn{Fortran intrinsic and runtime libraries} that are required to
6922 successfully link a Fortran program or shared library.  The output
6923 variable @code{FLIBS} or @code{FCLIBS} is set to these flags (which
6924 should be included after @code{LIBS} when linking).
6926 This macro is intended to be used in those situations when it is
6927 necessary to mix, e.g., C++ and Fortran source code in a single
6928 program or shared library (@pxref{Mixing Fortran 77 With C and C++, , ,
6929 automake, @acronym{GNU} Automake}).
6931 For example, if object files from a C++ and Fortran compiler must be
6932 linked together, then the C++ compiler/linker must be used for linking
6933 (since special C++-ish things need to happen at link time like calling
6934 global constructors, instantiating templates, enabling exception
6935 support, etc.).
6937 However, the Fortran intrinsic and runtime libraries must be linked in
6938 as well, but the C++ compiler/linker doesn't know by default how to add
6939 these Fortran 77 libraries.  Hence, this macro was created to determine
6940 these Fortran libraries.
6942 The macros @code{AC_F77_DUMMY_MAIN} and @code{AC_FC_DUMMY_MAIN} or
6943 @code{AC_F77_MAIN} and @code{AC_FC_MAIN} are probably also necessary to
6944 link C/C++ with Fortran; see below.
6945 @end defmac
6947 @defmac AC_F77_DUMMY_MAIN (@ovar{action-if-found}, @ovar{action-if-not-found})
6948 @defmacx AC_FC_DUMMY_MAIN (@ovar{action-if-found}, @ovar{action-if-not-found})
6949 @acindex{F77_DUMMY_MAIN}
6950 @cvindex F77_DUMMY_MAIN
6951 With many compilers, the Fortran libraries detected by
6952 @code{AC_F77_LIBRARY_LDFLAGS} or @code{AC_FC_LIBRARY_LDFLAGS} provide
6953 their own @code{main} entry function that initializes things like
6954 Fortran I/O, and which then calls a user-provided entry function named
6955 (say) @code{MAIN__} to run the user's program.  The
6956 @code{AC_F77_DUMMY_MAIN} and @code{AC_FC_DUMMY_MAIN} or
6957 @code{AC_F77_MAIN} and @code{AC_FC_MAIN} macros figure out how to deal with
6958 this interaction.
6960 When using Fortran for purely numerical functions (no I/O, etc.)@: often
6961 one prefers to provide one's own @code{main} and skip the Fortran
6962 library initializations.  In this case, however, one may still need to
6963 provide a dummy @code{MAIN__} routine in order to prevent linking errors
6964 on some systems.  @code{AC_F77_DUMMY_MAIN} or @code{AC_FC_DUMMY_MAIN}
6965 detects whether any such routine is @emph{required} for linking, and
6966 what its name is; the shell variable @code{F77_DUMMY_MAIN} or
6967 @code{FC_DUMMY_MAIN} holds this name, @code{unknown} when no solution
6968 was found, and @code{none} when no such dummy main is needed.
6970 By default, @var{action-if-found} defines @code{F77_DUMMY_MAIN} or
6971 @code{FC_DUMMY_MAIN} to the name of this routine (e.g., @code{MAIN__})
6972 @emph{if} it is required.  @var{action-if-not-found} defaults to
6973 exiting with an error.
6975 In order to link with Fortran routines, the user's C/C++ program should
6976 then include the following code to define the dummy main if it is
6977 needed:
6979 @example
6980 #ifdef F77_DUMMY_MAIN
6981 #  ifdef __cplusplus
6982      extern "C"
6983 #  endif
6984    int F77_DUMMY_MAIN() @{ return 1; @}
6985 #endif
6986 @end example
6988 (Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
6990 Note that this macro is called automatically from @code{AC_F77_WRAPPERS}
6991 or @code{AC_FC_WRAPPERS}; there is generally no need to call it
6992 explicitly unless one wants to change the default actions.
6993 @end defmac
6995 @defmac AC_F77_MAIN
6996 @defmacx AC_FC_MAIN
6997 @acindex{F77_MAIN}
6998 @cvindex F77_MAIN
6999 @acindex{FC_MAIN}
7000 @cvindex FC_MAIN
7001 As discussed above, many Fortran libraries allow you to provide an entry
7002 point called (say) @code{MAIN__} instead of the usual @code{main}, which
7003 is then called by a @code{main} function in the Fortran libraries that
7004 initializes things like Fortran I/O@.  The
7005 @code{AC_F77_MAIN} and @code{AC_FC_MAIN} macros detect whether it is
7006 @emph{possible} to utilize such an alternate main function, and defines
7007 @code{F77_MAIN} and @code{FC_MAIN} to the name of the function.  (If no
7008 alternate main function name is found, @code{F77_MAIN} and @code{FC_MAIN} are
7009 simply defined to @code{main}.)
7011 Thus, when calling Fortran routines from C that perform things like I/O,
7012 one should use this macro and name the "main" function
7013 @code{F77_MAIN} or @code{FC_MAIN} instead of @code{main}.
7014 @end defmac
7016 @defmac AC_F77_WRAPPERS
7017 @defmacx AC_FC_WRAPPERS
7018 @acindex{F77_WRAPPERS}
7019 @cvindex F77_FUNC
7020 @cvindex F77_FUNC_
7021 @acindex{FC_WRAPPERS}
7022 @cvindex FC_FUNC
7023 @cvindex FC_FUNC_
7024 Defines C macros @code{F77_FUNC (name, NAME)}, @code{FC_FUNC (name, NAME)},
7025 @code{F77_FUNC_(name, NAME)}, and @code{FC_FUNC_(name, NAME)} to properly
7026 mangle the names of C/C++ identifiers, and identifiers with underscores,
7027 respectively, so that they match the name-mangling scheme used by the
7028 Fortran compiler.
7030 Fortran is case-insensitive, and in order to achieve this the Fortran
7031 compiler converts all identifiers into a canonical case and format.  To
7032 call a Fortran subroutine from C or to write a C function that is
7033 callable from Fortran, the C program must explicitly use identifiers in
7034 the format expected by the Fortran compiler.  In order to do this, one
7035 simply wraps all C identifiers in one of the macros provided by
7036 @code{AC_F77_WRAPPERS} or @code{AC_FC_WRAPPERS}.  For example, suppose
7037 you have the following Fortran 77 subroutine:
7039 @example
7040       subroutine foobar (x, y)
7041       double precision x, y
7042       y = 3.14159 * x
7043       return
7044       end
7045 @end example
7047 You would then declare its prototype in C or C++ as:
7049 @example
7050 #define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)
7051 #ifdef __cplusplus
7052 extern "C"  /* prevent C++ name mangling */
7053 #endif
7054 void FOOBAR_F77(double *x, double *y);
7055 @end example
7057 Note that we pass both the lowercase and uppercase versions of the
7058 function name to @code{F77_FUNC} so that it can select the right one.
7059 Note also that all parameters to Fortran 77 routines are passed as
7060 pointers (@pxref{Mixing Fortran 77 With C and C++, , , automake, @acronym{GNU}
7061 Automake}).
7063 (Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
7065 Although Autoconf tries to be intelligent about detecting the
7066 name-mangling scheme of the Fortran compiler, there may be Fortran
7067 compilers that it doesn't support yet.  In this case, the above code
7068 generates a compile-time error, but some other behavior
7069 (e.g., disabling Fortran-related features) can be induced by checking
7070 whether @code{F77_FUNC} or @code{FC_FUNC} is defined.
7072 Now, to call that routine from a C program, we would do something like:
7074 @example
7076     double x = 2.7183, y;
7077     FOOBAR_F77 (&x, &y);
7079 @end example
7081 If the Fortran identifier contains an underscore (e.g., @code{foo_bar}),
7082 you should use @code{F77_FUNC_} or @code{FC_FUNC_} instead of
7083 @code{F77_FUNC} or @code{FC_FUNC} (with the same arguments).  This is
7084 because some Fortran compilers mangle names differently if they contain
7085 an underscore.
7086 @end defmac
7088 @defmac AC_F77_FUNC (@var{name}, @ovar{shellvar})
7089 @defmacx AC_FC_FUNC (@var{name}, @ovar{shellvar})
7090 @acindex{F77_FUNC}
7091 @acindex{FC_FUNC}
7092 Given an identifier @var{name}, set the shell variable @var{shellvar} to
7093 hold the mangled version @var{name} according to the rules of the
7094 Fortran linker (see also @code{AC_F77_WRAPPERS} or
7095 @code{AC_FC_WRAPPERS}).  @var{shellvar} is optional; if it is not
7096 supplied, the shell variable is simply @var{name}.  The purpose of
7097 this macro is to give the caller a way to access the name-mangling
7098 information other than through the C preprocessor as above, for example,
7099 to call Fortran routines from some language other than C/C++.
7100 @end defmac
7102 @defmac AC_FC_SRCEXT (@var{ext}, @ovar{action-if-success}, @ovar{action-if-failure})
7103 @acindex{FC_SRCEXT}
7104 By default, the @code{FC} macros perform their tests using a @file{.f}
7105 extension for source-code files.  Some compilers, however, only enable
7106 newer language features for appropriately named files, e.g., Fortran 90
7107 features only for @file{.f90} files.  On the other hand, some other
7108 compilers expect all source files to end in @file{.f} and require
7109 special flags to support other file name extensions.  The
7110 @code{AC_FC_SRCEXT} macro deals with both of these issues.
7112 The @code{AC_FC_SRCEXT} tries to get the @code{FC} compiler to accept files
7113 ending with the extension .@var{ext} (i.e., @var{ext} does @emph{not}
7114 contain the dot).  If any special compiler flags are needed for this, it
7115 stores them in the output variable @code{FCFLAGS_}@var{ext}.  This
7116 extension and these flags are then used for all subsequent @code{FC} tests
7117 (until @code{AC_FC_SRCEXT} is called again).
7119 For example, you would use @code{AC_FC_SRCEXT(f90)} to employ the
7120 @file{.f90} extension in future tests, and it would set a
7121 @code{FCFLAGS_f90} output variable with any extra flags that are needed
7122 to compile such files.
7124 The @code{FCFLAGS_}@var{ext} can @emph{not} be simply absorbed into
7125 @code{FCFLAGS}, for two reasons based on the limitations of some
7126 compilers.  First, only one @code{FCFLAGS_}@var{ext} can be used at a
7127 time, so files with different extensions must be compiled separately.
7128 Second, @code{FCFLAGS_}@var{ext} must appear @emph{immediately} before
7129 the source-code file name when compiling.  So, continuing the example
7130 above, you might compile a @file{foo.f90} file in your makefile with the
7131 command:
7133 @example
7134 foo.o: foo.f90
7135      $(FC) -c $(FCFLAGS) $(FCFLAGS_f90) '$(srcdir)/foo.f90'
7136 @end example
7138 If @code{AC_FC_SRCEXT} succeeds in compiling files with the @var{ext}
7139 extension, it calls @var{action-if-success} (defaults to nothing).  If
7140 it fails, and cannot find a way to make the @code{FC} compiler accept such
7141 files, it calls @var{action-if-failure} (defaults to exiting with an
7142 error message).
7144 @end defmac
7146 @defmac AC_FC_FREEFORM (@ovar{action-if-success}, @ovar{action-if-failure})
7147 @acindex{FC_FREEFORM}
7149 The @code{AC_FC_FREEFORM} tries to ensure that the Fortran compiler
7150 (@code{$FC}) allows free-format source code (as opposed to the older
7151 fixed-format style from Fortran 77).  If necessary, it may add some
7152 additional flags to @code{FCFLAGS}.
7154 This macro is most important if you are using the default @file{.f}
7155 extension, since many compilers interpret this extension as indicating
7156 fixed-format source unless an additional flag is supplied.  If you
7157 specify a different extension with @code{AC_FC_SRCEXT}, such as
7158 @file{.f90} or @file{.f95}, then @code{AC_FC_FREEFORM} ordinarily
7159 succeeds without modifying @code{FCFLAGS}.
7161 If @code{AC_FC_FREEFORM} succeeds in compiling free-form source, it
7162 calls @var{action-if-success} (defaults to nothing).  If it fails, it
7163 calls @var{action-if-failure} (defaults to exiting with an error
7164 message).
7165 @end defmac
7167 @node System Services
7168 @section System Services
7170 The following macros check for operating system services or capabilities.
7172 @defmac AC_PATH_X
7173 @acindex{PATH_X}
7174 @evindex XMKMF
7175 @cindex X Window System
7176 Try to locate the X Window System include files and libraries.  If the
7177 user gave the command line options @option{--x-includes=@var{dir}} and
7178 @option{--x-libraries=@var{dir}}, use those directories.
7180 If either or both were not given, get the missing values by running
7181 @code{xmkmf} (or an executable pointed to by the @code{XMKMF}
7182 environment variable) on a trivial @file{Imakefile} and examining the
7183 makefile that it produces.  Setting @code{XMKMF} to @samp{false}
7184 disables this method.
7186 If this method fails to find the X Window System, @command{configure}
7187 looks for the files in several directories where they often reside.
7188 If either method is successful, set the shell variables
7189 @code{x_includes} and @code{x_libraries} to their locations, unless they
7190 are in directories the compiler searches by default.
7192 If both methods fail, or the user gave the command line option
7193 @option{--without-x}, set the shell variable @code{no_x} to @samp{yes};
7194 otherwise set it to the empty string.
7195 @end defmac
7197 @defmac AC_PATH_XTRA
7198 @acindex{PATH_XTRA}
7199 @ovindex X_CFLAGS
7200 @ovindex X_LIBS
7201 @ovindex X_EXTRA_LIBS
7202 @ovindex X_PRE_LIBS
7203 @cvindex X_DISPLAY_MISSING
7204 An enhanced version of @code{AC_PATH_X}.  It adds the C compiler flags
7205 that X needs to output variable @code{X_CFLAGS}, and the X linker flags
7206 to @code{X_LIBS}.  Define @code{X_DISPLAY_MISSING} if X is not
7207 available.
7209 This macro also checks for special libraries that some systems need in
7210 order to compile X programs.  It adds any that the system needs to
7211 output variable @code{X_EXTRA_LIBS}.  And it checks for special X11R6
7212 libraries that need to be linked with before @option{-lX11}, and adds
7213 any found to the output variable @code{X_PRE_LIBS}.
7215 @c This is an incomplete kludge.  Make a real way to do it.
7216 @c If you need to check for other X functions or libraries yourself, then
7217 @c after calling this macro, add the contents of @code{X_EXTRA_LIBS} to
7218 @c @code{LIBS} temporarily, like this: (FIXME - add example)
7219 @end defmac
7221 @defmac AC_SYS_INTERPRETER
7222 @acindex{SYS_INTERPRETER}
7223 Check whether the system supports starting scripts with a line of the
7224 form @samp{#!/bin/sh} to select the interpreter to use for the script.
7225 After running this macro, shell code in @file{configure.ac} can check
7226 the shell variable @code{interpval}; it is set to @samp{yes}
7227 if the system supports @samp{#!}, @samp{no} if not.
7228 @end defmac
7230 @defmac AC_SYS_LARGEFILE
7231 @acindex{SYS_LARGEFILE}
7232 @cvindex _FILE_OFFSET_BITS
7233 @cvindex _LARGE_FILES
7234 @ovindex CC
7235 @cindex Large file support
7236 @cindex LFS
7237 Arrange for
7238 @uref{http://www.unix-systems.org/@/version2/@/whatsnew/@/lfs20mar.html,
7239 large-file support}.  On some hosts, one must use special compiler
7240 options to build programs that can access large files.  Append any such
7241 options to the output variable @code{CC}.  Define
7242 @code{_FILE_OFFSET_BITS} and @code{_LARGE_FILES} if necessary.
7244 Large-file support can be disabled by configuring with the
7245 @option{--disable-largefile} option.
7247 If you use this macro, check that your program works even when
7248 @code{off_t} is wider than @code{long int}, since this is common when
7249 large-file support is enabled.  For example, it is not correct to print
7250 an arbitrary @code{off_t} value @code{X} with @code{printf ("%ld",
7251 (long int) X)}.
7253 The LFS introduced the @code{fseeko} and @code{ftello} functions to
7254 replace their C counterparts @code{fseek} and @code{ftell} that do not
7255 use @code{off_t}.  Take care to use @code{AC_FUNC_FSEEKO} to make their
7256 prototypes available when using them and large-file support is
7257 enabled.
7258 @end defmac
7260 @defmac AC_SYS_LONG_FILE_NAMES
7261 @acindex{SYS_LONG_FILE_NAMES}
7262 @cvindex HAVE_LONG_FILE_NAMES
7263 If the system supports file names longer than 14 characters, define
7264 @code{HAVE_LONG_FILE_NAMES}.
7265 @end defmac
7267 @defmac AC_SYS_POSIX_TERMIOS
7268 @acindex{SYS_POSIX_TERMIOS}
7269 @cindex Posix termios headers
7270 @cindex termios Posix headers
7271 Check to see if the Posix termios headers and functions are available on the
7272 system.  If so, set the shell variable @code{ac_cv_sys_posix_termios} to
7273 @samp{yes}.  If not, set the variable to @samp{no}.
7274 @end defmac
7276 @node Posix Variants
7277 @section Posix Variants
7279 The following macros check for certain operating systems that need
7280 special treatment for some programs, due to exceptional oddities in
7281 their header files or libraries.  These macros are warts; they will be
7282 replaced by a more systematic approach, based on the functions they make
7283 available or the environments they provide.
7285 @defmac AC_AIX
7286 @acindex{AIX}
7287 @cvindex _ALL_SOURCE
7288 If on @acronym{AIX}, define @code{_ALL_SOURCE}.
7289 Allows the use of some @acronym{BSD}
7290 functions.  Should be called before any macros that run the C compiler.
7291 @end defmac
7293 @defmac AC_GNU_SOURCE
7294 @acindex{GNU_SOURCE}
7295 @cvindex _GNU_SOURCE
7296 If using the @acronym{GNU} C library, define @code{_GNU_SOURCE}.
7297 Allows the use of some @acronym{GNU} functions.  Should be called
7298 before any macros that run the C compiler.
7299 @end defmac
7301 @defmac AC_ISC_POSIX
7302 @acindex{ISC_POSIX}
7303 @ovindex LIBS
7304 For @sc{interactive} Systems Corporation Unix, add @option{-lcposix} to output
7305 variable @code{LIBS} if necessary for Posix facilities.  Call this
7306 after @code{AC_PROG_CC} and before any other macros that use Posix
7307 interfaces.
7309 This macro is obsolescent, as @sc{interactive} Unix is obsolete, and Sun
7310 dropped support for it on 2006-07-23.  New programs need not use this
7311 macro.
7312 @end defmac
7314 @defmac AC_MINIX
7315 @acindex{MINIX}
7316 @cvindex _MINIX
7317 @cvindex _POSIX_SOURCE
7318 @cvindex _POSIX_1_SOURCE
7319 If on Minix, define @code{_MINIX} and @code{_POSIX_SOURCE} and define
7320 @code{_POSIX_1_SOURCE} to be 2.  This allows the use of Posix
7321 facilities.  Should be called before any macros that run the C compiler.
7322 @end defmac
7324 @defmac AC_USE_SYSTEM_EXTENSIONS
7325 @acindex{USE_SYSTEM_EXTENSIONS}
7326 @cvindex _ALL_SOURCE
7327 @cvindex _GNU_SOURCE
7328 @cvindex _MINIX
7329 @cvindex _POSIX_1_SOURCE
7330 @cvindex _POSIX_PTHREAD_SEMANTICS
7331 @cvindex _POSIX_SOURCE
7332 @cvindex _TANDEM_SOURCE
7333 @cvindex __EXTENSIONS__
7334 If possible, enable extensions to Posix on hosts that normally disable
7335 the extensions, typically due to standards-conformance namespace issues.
7336 This may involve defining @code{__EXTENSIONS__} and
7337 @code{_POSIX_PTHREAD_SEMANTICS}, which are macros used by Solaris.
7338 It also defines @code{_TANDEM_SOURCE} for the @acronym{HP} NonStop platform.
7339 This macro also has the combined effects of @code{AC_GNU_SOURCE},
7340 @code{AC_AIX}, and @code{AC_MINIX}.
7341 @end defmac
7344 @node Erlang Libraries
7345 @section Erlang Libraries
7346 @cindex Erlang, Library, checking
7348 The following macros check for an installation of Erlang/OTP, and for the
7349 presence of certain Erlang libraries.  All those macros require the
7350 configuration of an Erlang interpreter and an Erlang compiler
7351 (@pxref{Erlang Compiler and Interpreter}).
7353 @defmac AC_ERLANG_SUBST_ROOT_DIR
7354 @acindex{ERLANG_SUBST_ROOT_DIR}
7355 @ovindex ERLANG_ROOT_DIR
7357 Set the output variable @code{ERLANG_ROOT_DIR} to the path to the base directory
7358 in which Erlang/OTP is installed (as returned by Erlang's @code{code:root_dir/0}
7359 function).  The result of this test is cached if caching is enabled when running
7360 @command{configure}.
7361 @end defmac
7363 @defmac AC_ERLANG_SUBST_LIB_DIR
7364 @acindex{ERLANG_SUBST_LIB_DIR}
7365 @ovindex ERLANG_LIB_DIR
7367 Set the output variable @code{ERLANG_LIB_DIR} to the path of the library
7368 directory of Erlang/OTP (as returned by Erlang's
7369 @code{code:lib_dir/0} function), which subdirectories each contain an installed
7370 Erlang/OTP library.  The result of this test is cached if caching is enabled
7371 when running @command{configure}.
7372 @end defmac
7374 @defmac AC_ERLANG_CHECK_LIB (@var{library}, @ovar{action-if-found}, @ovar{action-if-not-found})
7375 @acindex{ERLANG_CHECK_LIB}
7376 @ovindex ERLANG_LIB_DIR_@var{library}
7377 @ovindex ERLANG_LIB_VER_@var{library}
7379 Test whether the Erlang/OTP library @var{library} is installed by
7380 calling Erlang's @code{code:lib_dir/1} function.  The result of this
7381 test is cached if caching is enabled when running @command{configure}.
7382 @var{action-if-found} is a list of shell commands to run if the library
7383 is installed; @var{action-if-not-found} is a list of shell commands to
7384 run if it is not.  Additionally, if the library is installed, the output
7385 variable @samp{ERLANG_LIB_DIR_@var{library}} is set to the path to the
7386 library installation directory, and the output variable
7387 @samp{ERLANG_LIB_VER_@var{library}} is set to the version number that is
7388 part of the subdirectory name, if it is in the standard form
7389 (@code{@var{library}-@var{version}}).  If the directory name does not
7390 have a version part, @samp{ERLANG_LIB_VER_@var{library}} is set to the
7391 empty string.  If the library is not installed,
7392 @samp{ERLANG_LIB_DIR_@var{library}} and
7393 @samp{ERLANG_LIB_VER_@var{library}} are set to @code{"not found"}.  For
7394 example, to check if library @code{stdlib} is installed:
7396 @example
7397 AC_ERLANG_CHECK_LIB([stdlib],
7398   [echo "stdlib version \"$ERLANG_LIB_VER_stdlib\""
7399    echo "is installed in \"$ERLANG_LIB_DIR_stdlib\""],
7400   [AC_MSG_ERROR([stdlib was not found!])])
7401 @end example
7402 @end defmac
7404 In addition to the above macros, which test installed Erlang libraries, the
7405 following macros determine the paths to the directories into which newly built
7406 Erlang libraries are to be installed:
7408 @defmac AC_ERLANG_SUBST_INSTALL_LIB_DIR
7409 @acindex{ERLANG_SUBST_INSTALL_LIB_DIR}
7410 @ovindex ERLANG_INSTALL_LIB_DIR
7412 Set the @code{ERLANG_INSTALL_LIB_DIR} output variable to the directory into
7413 which every built Erlang library should be installed in a separate subdirectory.
7414 If this variable is not set in the environment when @command{configure} runs,
7415 its default value is @code{$ERLANG_LIB_DIR}, which value is set by the
7416 @code{AC_ERLANG_SUBST_LIB_DIR} macro.
7417 @end defmac
7419 @defmac AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR (@var{library}, @var{version})
7420 @acindex{ERLANG_SUBST_INSTALL_LIB_SUBDIR}
7421 @ovindex ERLANG_INSTALL_LIB_DIR_@var{library}
7423 Set the @samp{ERLANG_INSTALL_LIB_DIR_@var{library}} output variable to the
7424 directory into which the built Erlang library @var{library} version
7425 @var{version} should be installed.  If this variable is not set in the
7426 environment when @command{configure} runs, its default value is
7427 @samp{$ERLANG_INSTALL_LIB_DIR/@var{library}-@var{version}}, the value of the
7428 @code{ERLANG_INSTALL_LIB_DIR} variable being set by the
7429 @code{AC_ERLANG_SUBST_INSTALL_LIB_DIR} macro.
7430 @end defmac
7436 @c ========================================================= Writing Tests
7438 @node Writing Tests
7439 @chapter Writing Tests
7441 If the existing feature tests don't do something you need, you have to
7442 write new ones.  These macros are the building blocks.  They provide
7443 ways for other macros to check whether various kinds of features are
7444 available and report the results.
7446 This chapter contains some suggestions and some of the reasons why the
7447 existing tests are written the way they are.  You can also learn a lot
7448 about how to write Autoconf tests by looking at the existing ones.  If
7449 something goes wrong in one or more of the Autoconf tests, this
7450 information can help you understand the assumptions behind them, which
7451 might help you figure out how to best solve the problem.
7453 These macros check the output of the compiler system of the current
7454 language (@pxref{Language Choice}).  They do not cache the results of
7455 their tests for future use (@pxref{Caching Results}), because they don't
7456 know enough about the information they are checking for to generate a
7457 cache variable name.  They also do not print any messages, for the same
7458 reason.  The checks for particular kinds of features call these macros
7459 and do cache their results and print messages about what they're
7460 checking for.
7462 When you write a feature test that could be applicable to more than one
7463 software package, the best thing to do is encapsulate it in a new macro.
7464 @xref{Writing Autoconf Macros}, for how to do that.
7466 @menu
7467 * Language Choice::             Selecting which language to use for testing
7468 * Writing Test Programs::       Forging source files for compilers
7469 * Running the Preprocessor::    Detecting preprocessor symbols
7470 * Running the Compiler::        Detecting language or header features
7471 * Running the Linker::          Detecting library features
7472 * Runtime::                     Testing for runtime features
7473 * Systemology::                 A zoology of operating systems
7474 * Multiple Cases::              Tests for several possible values
7475 @end menu
7477 @node Language Choice
7478 @section Language Choice
7479 @cindex Language
7481 Autoconf-generated @command{configure} scripts check for the C compiler and
7482 its features by default.  Packages that use other programming languages
7483 (maybe more than one, e.g., C and C++) need to test features of the
7484 compilers for the respective languages.  The following macros determine
7485 which programming language is used in the subsequent tests in
7486 @file{configure.ac}.
7488 @defmac AC_LANG (@var{language})
7489 Do compilation tests using the compiler, preprocessor, and file
7490 extensions for the specified @var{language}.
7492 Supported languages are:
7494 @table @samp
7495 @item C
7496 Do compilation tests using @code{CC} and @code{CPP} and use extension
7497 @file{.c} for test programs.  Use compilation flags: @code{CPPFLAGS} with
7498 @code{CPP}, and both @code{CPPFLAGS} and @code{CFLAGS} with @code{CC}.
7500 @item C++
7501 Do compilation tests using @code{CXX} and @code{CXXCPP} and use
7502 extension @file{.C} for test programs.  Use compilation flags:
7503 @code{CPPFLAGS} with @code{CXXCPP}, and both @code{CPPFLAGS} and
7504 @code{CXXFLAGS} with @code{CXX}.
7506 @item Fortran 77
7507 Do compilation tests using @code{F77} and use extension @file{.f} for
7508 test programs.  Use compilation flags: @code{FFLAGS}.
7510 @item Fortran
7511 Do compilation tests using @code{FC} and use extension @file{.f} (or
7512 whatever has been set by @code{AC_FC_SRCEXT}) for test programs.  Use
7513 compilation flags: @code{FCFLAGS}.
7515 @item Erlang
7516 @ovindex ERLC
7517 @ovindex ERL
7518 @ovindex ERLCFLAGS
7519 Compile and execute tests using @code{ERLC} and @code{ERL} and use extension
7520 @file{.erl} for test Erlang modules.  Use compilation flags: @code{ERLCFLAGS}.
7522 @item Objective C
7523 Do compilation tests using @code{OBJC} and @code{OBJCPP} and use
7524 extension @file{.m} for test programs.  Use compilation flags:
7525 @code{CPPFLAGS} with @code{OBJCPP}, and both @code{CPPFLAGS} and
7526 @code{OBJCFLAGS} with @code{OBJC}.
7527 @end table
7528 @end defmac
7530 @defmac AC_LANG_PUSH (@var{language})
7531 @acindex{LANG_PUSH}
7532 Remember the current language (as set by @code{AC_LANG}) on a stack, and
7533 then select the @var{language}.  Use this macro and @code{AC_LANG_POP}
7534 in macros that need to temporarily switch to a particular language.
7535 @end defmac
7537 @defmac AC_LANG_POP (@ovar{language})
7538 @acindex{LANG_POP}
7539 Select the language that is saved on the top of the stack, as set by
7540 @code{AC_LANG_PUSH}, and remove it from the stack.
7542 If given, @var{language} specifies the language we just @emph{quit}.  It
7543 is a good idea to specify it when it's known (which should be the
7544 case@dots{}), since Autoconf detects inconsistencies.
7546 @example
7547 AC_LANG_PUSH([Fortran 77])
7548 # Perform some tests on Fortran 77.
7549 # @dots{}
7550 AC_LANG_POP([Fortran 77])
7551 @end example
7552 @end defmac
7554 @defmac AC_LANG_ASSERT (@var{language})
7555 @acindex{LANG_ASSERT} Check statically that the current language is
7556 @var{language}.  You should use this in your language specific macros
7557 to avoid that they be called with an inappropriate language.
7559 This macro runs only at @command{autoconf} time, and incurs no cost at
7560 @command{configure} time.  Sadly enough and because Autoconf is a two
7561 layer language @footnote{Because M4 is not aware of Sh code,
7562 especially conditionals, some optimizations that look nice statically
7563 may produce incorrect results at runtime.}, the macros
7564 @code{AC_LANG_PUSH} and @code{AC_LANG_POP} cannot be ``optimizing'',
7565 therefore as much as possible you ought to avoid using them to wrap
7566 your code, rather, require from the user to run the macro with a
7567 correct current language, and check it with @code{AC_LANG_ASSERT}.
7568 And anyway, that may help the user understand she is running a Fortran
7569 macro while expecting a result about her Fortran 77 compiler@dots{}
7570 @end defmac
7573 @defmac AC_REQUIRE_CPP
7574 @acindex{REQUIRE_CPP}
7575 Ensure that whichever preprocessor would currently be used for tests has
7576 been found.  Calls @code{AC_REQUIRE} (@pxref{Prerequisite Macros}) with an
7577 argument of either @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP},
7578 depending on which language is current.
7579 @end defmac
7582 @node Writing Test Programs
7583 @section Writing Test Programs
7585 Autoconf tests follow a common scheme: feed some program with some
7586 input, and most of the time, feed a compiler with some source file.
7587 This section is dedicated to these source samples.
7589 @menu
7590 * Guidelines::                  General rules for writing test programs
7591 * Test Functions::              Avoiding pitfalls in test programs
7592 * Generating Sources::          Source program boilerplate
7593 @end menu
7595 @node Guidelines
7596 @subsection Guidelines for Test Programs
7598 The most important rule to follow when writing testing samples is:
7600 @center @emph{Look for realism.}
7602 This motto means that testing samples must be written with the same
7603 strictness as real programs are written.  In particular, you should
7604 avoid ``shortcuts'' and simplifications.
7606 Don't just play with the preprocessor if you want to prepare a
7607 compilation.  For instance, using @command{cpp} to check whether a header is
7608 functional might let your @command{configure} accept a header which
7609 causes some @emph{compiler} error.  Do not hesitate to check a header with
7610 other headers included before, especially required headers.
7612 Make sure the symbols you use are properly defined, i.e., refrain for
7613 simply declaring a function yourself instead of including the proper
7614 header.
7616 Test programs should not write to standard output.  They
7617 should exit with status 0 if the test succeeds, and with status 1
7618 otherwise, so that success
7619 can be distinguished easily from a core dump or other failure;
7620 segmentation violations and other failures produce a nonzero exit
7621 status.  Unless you arrange for @code{exit} to be declared, test
7622 programs should @code{return}, not @code{exit}, from @code{main},
7623 because on many systems @code{exit} is not declared by default.
7625 Test programs can use @code{#if} or @code{#ifdef} to check the values of
7626 preprocessor macros defined by tests that have already run.  For
7627 example, if you call @code{AC_HEADER_STDBOOL}, then later on in
7628 @file{configure.ac} you can have a test program that includes
7629 @file{stdbool.h} conditionally:
7631 @example
7632 @group
7633 #ifdef HAVE_STDBOOL_H
7634 # include <stdbool.h>
7635 #endif
7636 @end group
7637 @end example
7639 Both @code{#if HAVE_STDBOOL_H} and @code{#ifdef HAVE_STDBOOL_H} will
7640 work with any standard C compiler.  Some developers prefer @code{#if}
7641 because it is easier to read, while others prefer @code{#ifdef} because
7642 it avoids diagnostics with picky compilers like @acronym{GCC} with the
7643 @option{-Wundef} option.
7645 If a test program needs to use or create a data file, give it a name
7646 that starts with @file{conftest}, such as @file{conftest.data}.  The
7647 @command{configure} script cleans up by running @samp{rm -f -r conftest*}
7648 after running test programs and if the script is interrupted.
7650 @node Test Functions
7651 @subsection Test Functions
7653 These days it's safe to assume support for function prototypes
7654 (introduced in C89).
7656 Functions that test programs declare should also be conditionalized for
7657 C++, which requires @samp{extern "C"} prototypes.  Make sure to not
7658 include any header files containing clashing prototypes.
7660 @example
7661 #ifdef __cplusplus
7662 extern "C"
7663 #endif
7664 void *valloc (size_t);
7665 @end example
7667 If a test program calls a function with invalid parameters (just to see
7668 whether it exists), organize the program to ensure that it never invokes
7669 that function.  You can do this by calling it in another function that is
7670 never invoked.  You can't do it by putting it after a call to
7671 @code{exit}, because @acronym{GCC} version 2 knows that @code{exit}
7672 never returns
7673 and optimizes out any code that follows it in the same block.
7675 If you include any header files, be sure to call the functions
7676 relevant to them with the correct number of arguments, even if they are
7677 just 0, to avoid compilation errors due to prototypes.  @acronym{GCC}
7678 version 2
7679 has internal prototypes for several functions that it automatically
7680 inlines; for example, @code{memcpy}.  To avoid errors when checking for
7681 them, either pass them the correct number of arguments or redeclare them
7682 with a different return type (such as @code{char}).
7685 @node Generating Sources
7686 @subsection Generating Sources
7688 Autoconf provides a set of macros that can be used to generate test
7689 source files.  They are written to be language generic, i.e., they
7690 actually depend on the current language (@pxref{Language Choice}) to
7691 ``format'' the output properly.
7694 @defmac AC_LANG_CONFTEST (@var{source})
7695 @acindex{LANG_CONFTEST}
7696 Save the @var{source} text in the current test source file:
7697 @file{conftest.@var{extension}} where the @var{extension} depends on the
7698 current language.
7700 Note that the @var{source} is evaluated exactly once, like regular
7701 Autoconf macro arguments, and therefore (i) you may pass a macro
7702 invocation, (ii) if not, be sure to double quote if needed.
7703 @end defmac
7705 @defmac AC_LANG_SOURCE (@var{source})
7706 @acindex{LANG_SOURCE}
7707 Expands into the @var{source}, with the definition of
7708 all the @code{AC_DEFINE} performed so far.
7709 @end defmac
7711 For instance executing (observe the double quotation!):
7713 @example
7714 AC_INIT([Hello], [1.0], [bug-hello@@example.org])
7715 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7716   [Greetings string.])
7717 AC_LANG(C)
7718 AC_LANG_CONFTEST(
7719    [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
7720 gcc -E -dD -o - conftest.c
7721 @end example
7723 @noindent
7724 results in:
7726 @example
7727 @dots{}
7728 # 1 "conftest.c"
7730 #define PACKAGE_NAME "Hello"
7731 #define PACKAGE_TARNAME "hello"
7732 #define PACKAGE_VERSION "1.0"
7733 #define PACKAGE_STRING "Hello 1.0"
7734 #define PACKAGE_BUGREPORT "bug-hello@@example.org"
7735 #define HELLO_WORLD "Hello, World\n"
7737 const char hw[] = "Hello, World\n";
7738 @end example
7740 When the test language is Fortran or Erlang, the @code{AC_DEFINE} definitions
7741 are not automatically translated into constants in the source code by this
7742 macro.
7744 @defmac AC_LANG_PROGRAM (@var{prologue}, @var{body})
7745 @acindex{LANG_PROGRAM}
7746 Expands into a source file which consists of the @var{prologue}, and
7747 then @var{body} as body of the main function (e.g., @code{main} in
7748 C).  Since it uses @code{AC_LANG_SOURCE}, the features of the latter are
7749 available.
7750 @end defmac
7752 For instance:
7754 @example
7755 AC_INIT([Hello], [1.0], [bug-hello@@example.org])
7756 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7757   [Greetings string.])
7758 AC_LANG_CONFTEST(
7759 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
7760                  [[fputs (hw, stdout);]])])
7761 gcc -E -dD -o - conftest.c
7762 @end example
7764 @noindent
7765 results in:
7767 @example
7768 @dots{}
7769 # 1 "conftest.c"
7771 #define PACKAGE_NAME "Hello"
7772 #define PACKAGE_TARNAME "hello"
7773 #define PACKAGE_VERSION "1.0"
7774 #define PACKAGE_STRING "Hello 1.0"
7775 #define PACKAGE_BUGREPORT "bug-hello@@example.org"
7776 #define HELLO_WORLD "Hello, World\n"
7778 const char hw[] = "Hello, World\n";
7780 main ()
7782 fputs (hw, stdout);
7783   ;
7784   return 0;
7786 @end example
7788 In Erlang tests, the created source file is that of an Erlang module called
7789 @code{conftest} (@file{conftest.erl}).  This module defines and exports at least
7790 one @code{start/0} function, which is called to perform the test.  The
7791 @var{prologue} is optional code that is inserted between the module header and
7792 the @code{start/0} function definition.  @var{body} is the body of the
7793 @code{start/0} function without the final period (@pxref{Runtime}, about
7794 constraints on this function's behavior).
7796 For instance:
7798 @example
7799 AC_INIT([Hello], [1.0], [bug-hello@@example.org])
7800 AC_LANG(Erlang)
7801 AC_LANG_CONFTEST(
7802 [AC_LANG_PROGRAM([[-define(HELLO_WORLD, "Hello, world!").]],
7803                  [[io:format("~s~n", [?HELLO_WORLD])]])])
7804 cat conftest.erl
7805 @end example
7807 @noindent
7808 results in:
7810 @example
7811 -module(conftest).
7812 -export([start/0]).
7813 -define(HELLO_WORLD, "Hello, world!").
7814 start() ->
7815 io:format("~s~n", [?HELLO_WORLD])
7817 @end example
7819 @defmac AC_LANG_CALL (@var{prologue}, @var{function})
7820 @acindex{LANG_CALL}
7821 Expands into a source file which consists of the @var{prologue}, and
7822 then a call to the @var{function} as body of the main function (e.g.,
7823 @code{main} in C).  Since it uses @code{AC_LANG_PROGRAM}, the feature
7824 of the latter are available.
7826 This function will probably be replaced in the future by a version
7827 which would enable specifying the arguments.  The use of this macro is
7828 not encouraged, as it violates strongly the typing system.
7830 This macro cannot be used for Erlang tests.
7831 @end defmac
7833 @defmac AC_LANG_FUNC_LINK_TRY (@var{function})
7834 @acindex{LANG_FUNC_LINK_TRY}
7835 Expands into a source file which uses the @var{function} in the body of
7836 the main function (e.g., @code{main} in C).  Since it uses
7837 @code{AC_LANG_PROGRAM}, the features of the latter are available.
7839 As @code{AC_LANG_CALL}, this macro is documented only for completeness.
7840 It is considered to be severely broken, and in the future will be
7841 removed in favor of actual function calls (with properly typed
7842 arguments).
7844 This macro cannot be used for Erlang tests.
7845 @end defmac
7847 @node Running the Preprocessor
7848 @section Running the Preprocessor
7850 Sometimes one might need to run the preprocessor on some source file.
7851 @emph{Usually it is a bad idea}, as you typically need to @emph{compile}
7852 your project, not merely run the preprocessor on it; therefore you
7853 certainly want to run the compiler, not the preprocessor.  Resist the
7854 temptation of following the easiest path.
7856 Nevertheless, if you need to run the preprocessor, then use
7857 @code{AC_PREPROC_IFELSE}.
7859 The macros described in this section cannot be used for tests in Erlang or
7860 Fortran, since those languages require no preprocessor.
7862 @defmac AC_PREPROC_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
7863 @acindex{PREPROC_IFELSE}
7864 Run the preprocessor of the current language (@pxref{Language Choice})
7865 on the @var{input}, run the shell commands @var{action-if-true} on
7866 success, @var{action-if-false} otherwise.  The @var{input} can be made
7867 by @code{AC_LANG_PROGRAM} and friends.
7869 This macro uses @code{CPPFLAGS}, but not @code{CFLAGS}, because
7870 @option{-g}, @option{-O}, etc.@: are not valid options to many C
7871 preprocessors.
7873 It is customary to report unexpected failures with
7874 @code{AC_MSG_FAILURE}.
7875 @end defmac
7877 For instance:
7879 @example
7880 AC_INIT([Hello], [1.0], [bug-hello@@example.org])
7881 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7882   [Greetings string.])
7883 AC_PREPROC_IFELSE(
7884    [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
7885                     [[fputs (hw, stdout);]])],
7886    [AC_MSG_RESULT([OK])],
7887    [AC_MSG_FAILURE([unexpected preprocessor failure])])
7888 @end example
7890 @noindent
7891 results in:
7893 @example
7894 checking for gcc... gcc
7895 checking for C compiler default output file name... a.out
7896 checking whether the C compiler works... yes
7897 checking whether we are cross compiling... no
7898 checking for suffix of executables...
7899 checking for suffix of object files... o
7900 checking whether we are using the GNU C compiler... yes
7901 checking whether gcc accepts -g... yes
7902 checking for gcc option to accept ISO C89... none needed
7903 checking how to run the C preprocessor... gcc -E
7905 @end example
7907 @sp 1
7909 The macro @code{AC_TRY_CPP} (@pxref{Obsolete Macros}) used to play the
7910 role of @code{AC_PREPROC_IFELSE}, but double quotes its argument, making
7911 it impossible to use it to elaborate sources.  You are encouraged to
7912 get rid of your old use of the macro @code{AC_TRY_CPP} in favor of
7913 @code{AC_PREPROC_IFELSE}, but, in the first place, are you sure you need
7914 to run the @emph{preprocessor} and not the compiler?
7916 @defmac AC_EGREP_HEADER (@var{pattern}, @var{header-file}, @var{action-if-found}, @ovar{action-if-not-found})
7917 @acindex{EGREP_HEADER}
7918 If the output of running the preprocessor on the system header file
7919 @var{header-file} matches the extended regular expression
7920 @var{pattern}, execute shell commands @var{action-if-found}, otherwise
7921 execute @var{action-if-not-found}.
7922 @end defmac
7924 @defmac AC_EGREP_CPP (@var{pattern}, @var{program}, @ovar{action-if-found}, @ovar{action-if-not-found})
7925 @acindex{EGREP_CPP}
7926 @var{program} is the text of a C or C++ program, on which shell
7927 variable, back quote, and backslash substitutions are performed.  If the
7928 output of running the preprocessor on @var{program} matches the
7929 extended regular expression @var{pattern}, execute shell commands
7930 @var{action-if-found}, otherwise execute @var{action-if-not-found}.
7931 @end defmac
7935 @node Running the Compiler
7936 @section Running the Compiler
7938 To check for a syntax feature of the current language's (@pxref{Language
7939 Choice}) compiler, such as whether it recognizes a certain keyword, or
7940 simply to try some library feature, use @code{AC_COMPILE_IFELSE} to try
7941 to compile a small program that uses that feature.
7943 @defmac AC_COMPILE_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
7944 @acindex{COMPILE_IFELSE}
7945 Run the compiler and compilation flags of the current language
7946 (@pxref{Language Choice}) on the @var{input}, run the shell commands
7947 @var{action-if-true} on success, @var{action-if-false} otherwise.  The
7948 @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.
7950 It is customary to report unexpected failures with
7951 @code{AC_MSG_FAILURE}.  This macro does not try to link; use
7952 @code{AC_LINK_IFELSE} if you need to do that (@pxref{Running the
7953 Linker}).
7954 @end defmac
7956 @ovindex ERL
7957 For tests in Erlang, the @var{input} must be the source code of a module named
7958 @code{conftest}.  @code{AC_COMPILE_IFELSE} generates a @file{conftest.beam}
7959 file that can be interpreted by the Erlang virtual machine (@code{ERL}).  It is
7960 recommended to use @code{AC_LANG_PROGRAM} to specify the test program, to ensure
7961 that the Erlang module has the right name.
7963 @node Running the Linker
7964 @section Running the Linker
7966 To check for a library, a function, or a global variable, Autoconf
7967 @command{configure} scripts try to compile and link a small program that
7968 uses it.  This is unlike Metaconfig, which by default uses @code{nm} or
7969 @code{ar} on the C library to try to figure out which functions are
7970 available.  Trying to link with the function is usually a more reliable
7971 approach because it avoids dealing with the variations in the options
7972 and output formats of @code{nm} and @code{ar} and in the location of the
7973 standard libraries.  It also allows configuring for cross-compilation or
7974 checking a function's runtime behavior if needed.  On the other hand,
7975 it can be slower than scanning the libraries once, but accuracy is more
7976 important than speed.
7978 @code{AC_LINK_IFELSE} is used to compile test programs to test for
7979 functions and global variables.  It is also used by @code{AC_CHECK_LIB}
7980 to check for libraries (@pxref{Libraries}), by adding the library being
7981 checked for to @code{LIBS} temporarily and trying to link a small
7982 program.
7985 @defmac AC_LINK_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
7986 @acindex{LINK_IFELSE}
7987 Run the compiler (and compilation flags) and the linker of the current
7988 language (@pxref{Language Choice}) on the @var{input}, run the shell
7989 commands @var{action-if-true} on success, @var{action-if-false}
7990 otherwise.  The @var{input} can be made by @code{AC_LANG_PROGRAM} and
7991 friends.
7993 @code{LDFLAGS} and @code{LIBS} are used for linking, in addition to the
7994 current compilation flags.
7996 It is customary to report unexpected failures with
7997 @code{AC_MSG_FAILURE}.  This macro does not try to execute the program;
7998 use @code{AC_RUN_IFELSE} if you need to do that (@pxref{Runtime}).
7999 @end defmac
8001 The @code{AC_LINK_IFELSE} macro cannot be used for Erlang tests, since Erlang
8002 programs are interpreted and do not require linking.
8006 @node Runtime
8007 @section Checking Runtime Behavior
8009 Sometimes you need to find out how a system performs at runtime, such
8010 as whether a given function has a certain capability or bug.  If you
8011 can, make such checks when your program runs instead of when it is
8012 configured.  You can check for things like the machine's endianness when
8013 your program initializes itself.
8015 If you really need to test for a runtime behavior while configuring,
8016 you can write a test program to determine the result, and compile and
8017 run it using @code{AC_RUN_IFELSE}.  Avoid running test programs if
8018 possible, because this prevents people from configuring your package for
8019 cross-compiling.
8021 @defmac AC_RUN_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false}, @ovar{action-if-cross-compiling})
8022 @acindex{RUN_IFELSE}
8023 If @var{program} compiles and links successfully and returns an exit
8024 status of 0 when executed, run shell commands @var{action-if-true}.
8025 Otherwise, run shell commands @var{action-if-false}.
8027 The @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.
8028 @code{LDFLAGS} and @code{LIBS} are used for linking, in addition to the
8029 compilation flags of the current language (@pxref{Language Choice}).
8031 If the compiler being used does not produce executables that run on the
8032 system where @command{configure} is being run, then the test program is
8033 not run.  If the optional shell commands @var{action-if-cross-compiling}
8034 are given, they are run instead.  Otherwise, @command{configure} prints
8035 an error message and exits.
8037 In the @var{action-if-false} section, the failing exit status is
8038 available in the shell variable @samp{$?}.  This exit status might be
8039 that of a failed compilation, or it might be that of a failed program
8040 execution.
8042 It is customary to report unexpected failures with
8043 @code{AC_MSG_FAILURE}.
8044 @end defmac
8046 Try to provide a pessimistic default value to use when cross-compiling
8047 makes runtime tests impossible.  You do this by passing the optional
8048 last argument to @code{AC_RUN_IFELSE}.  @command{autoconf} prints a
8049 warning message when creating @command{configure} each time it
8050 encounters a call to @code{AC_RUN_IFELSE} with no
8051 @var{action-if-cross-compiling} argument given.  You may ignore the
8052 warning, though users cannot configure your package for
8053 cross-compiling.  A few of the macros distributed with Autoconf produce
8054 this warning message.
8056 To configure for cross-compiling you can also choose a value for those
8057 parameters based on the canonical system name (@pxref{Manual
8058 Configuration}).  Alternatively, set up a test results cache file with
8059 the correct values for the host system (@pxref{Caching Results}).
8061 @ovindex cross_compiling
8062 To provide a default for calls of @code{AC_RUN_IFELSE} that are embedded
8063 in other macros, including a few of the ones that come with Autoconf,
8064 you can test whether the shell variable @code{cross_compiling} is set to
8065 @samp{yes}, and then use an alternate method to get the results instead
8066 of calling the macros.
8068 A C or C++ runtime test should be portable.
8069 @xref{Portable C and C++}.
8071 Erlang tests must exit themselves the Erlang VM by calling the @code{halt/1}
8072 function: the given status code is used to determine the success of the test
8073 (status is @code{0}) or its failure (status is different than @code{0}), as
8074 explained above.  It must be noted that data output through the standard output
8075 (e.g., using @code{io:format/2}) may be truncated when halting the VM.
8076 Therefore, if a test must output configuration information, it is recommended
8077 to create and to output data into the temporary file named @file{conftest.out},
8078 using the functions of module @code{file}.  The @code{conftest.out} file is
8079 automatically deleted by the @code{AC_RUN_IFELSE} macro.  For instance, a
8080 simplified implementation of Autoconf's @code{AC_ERLANG_SUBST_LIB_DIR} macro is:
8082 @example
8083 AC_INIT([LibdirTest], [1.0], [bug-libdirtest@@example.org])
8084 AC_ERLANG_NEED_ERL
8085 AC_LANG(Erlang)
8086 AC_RUN_IFELSE(
8087   [AC_LANG_PROGRAM([], [dnl
8088     file:write_file("conftest.out", code:lib_dir()),
8089     halt(0)])],
8090   [echo "code:lib_dir() returned: `cat conftest.out`"],
8091   [AC_MSG_FAILURE([test Erlang program execution failed])])
8092 @end example
8095 @node Systemology
8096 @section Systemology
8097 @cindex Systemology
8099 This section aims at presenting some systems and pointers to
8100 documentation.  It may help you addressing particular problems reported
8101 by users.
8103 @uref{http://www.opengroup.org/susv3, Posix-conforming systems} are
8104 derived from the @uref{http://www.bell-labs.com/history/unix/, Unix
8105 operating system}.
8107 The @uref{http://bhami.com/rosetta.html, Rosetta Stone for Unix}
8108 contains a table correlating the features of various Posix-conforming
8109 systems.  @uref{http://www.levenez.com/unix/, Unix History} is a
8110 simplified diagram of how many Unix systems were derived from each
8111 other.
8113 @uref{http://heirloom.sourceforge.net/, The Heirloom Project}
8114 provides some variants of traditional implementations of Unix utilities.
8116 @table @asis
8117 @item Darwin
8118 @cindex Darwin
8119 Darwin is also known as Mac OS X@.  Beware that the file system @emph{can} be
8120 case-preserving, but case insensitive.  This can cause nasty problems,
8121 since for instance the installation attempt for a package having an
8122 @file{INSTALL} file can result in @samp{make install} report that
8123 nothing was to be done!
8125 That's all dependent on whether the file system is a UFS (case
8126 sensitive) or HFS+ (case preserving).  By default Apple wants you to
8127 install the OS on HFS+.  Unfortunately, there are some pieces of
8128 software which really need to be built on UFS@.  We may want to rebuild
8129 Darwin to have both UFS and HFS+ available (and put the /local/build
8130 tree on the UFS).
8132 @item @acronym{QNX} 4.25
8133 @cindex @acronym{QNX} 4.25
8134 @c FIXME: Please, if you feel like writing something more precise,
8135 @c it'd be great.  In particular, I can't understand the difference with
8136 @c QNX Neutrino.
8137 @acronym{QNX} is a realtime operating system running on Intel architecture
8138 meant to be scalable from the small embedded systems to the hundred
8139 processor super-computer.  It claims to be Posix certified.  More
8140 information is available on the
8141 @uref{http://www.qnx.com/, @acronym{QNX} home page}.
8143 @item Tru64
8144 @cindex Tru64
8145 @uref{http://h30097.www3.hp.com/@/docs/,
8146 Documentation of several versions of Tru64} is available in different
8147 formats.
8149 @item Unix version 7
8150 @cindex Unix version 7
8151 @cindex V7
8152 Officially this was called the ``Seventh Edition'' of ``the @sc{unix}
8153 time-sharing system'' but we use the more-common name ``Unix version 7''.
8154 Documentation is available in the
8155 @uref{http://plan9.bell-labs.com/@/7thEdMan/, Unix Seventh Edition Manual}.
8156 Previous versions of Unix are called ``Unix version 6'', etc., but
8157 they were not as widely used.
8158 @end table
8161 @node Multiple Cases
8162 @section Multiple Cases
8164 Some operations are accomplished in several possible ways, depending on
8165 the OS variant.  Checking for them essentially requires a ``case
8166 statement''.  Autoconf does not directly provide one; however, it is
8167 easy to simulate by using a shell variable to keep track of whether a
8168 way to perform the operation has been found yet.
8170 Here is an example that uses the shell variable @code{fstype} to keep
8171 track of whether the remaining cases need to be checked.
8173 @example
8174 @group
8175 AC_MSG_CHECKING([how to get file system type])
8176 fstype=no
8177 # The order of these tests is important.
8178 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statvfs.h>
8179 #include <sys/fstyp.h>]])],
8180                   [AC_DEFINE([FSTYPE_STATVFS], [1],
8181                      [Define if statvfs exists.])
8182                    fstype=SVR4])
8183 if test $fstype = no; then
8184   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
8185 #include <sys/fstyp.h>]])],
8186                   [AC_DEFINE([FSTYPE_USG_STATFS], [1],
8187                      [Define if USG statfs.])
8188                    fstype=SVR3])
8190 if test $fstype = no; then
8191   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
8192 #include <sys/vmount.h>]])]),
8193                   [AC_DEFINE([FSTYPE_AIX_STATFS], [1],
8194                      [Define if AIX statfs.])
8195                    fstype=AIX])
8197 # (more cases omitted here)
8198 AC_MSG_RESULT([$fstype])
8199 @end group
8200 @end example
8202 @c ====================================================== Results of Tests.
8204 @node Results
8205 @chapter Results of Tests
8207 Once @command{configure} has determined whether a feature exists, what can
8208 it do to record that information?  There are four sorts of things it can
8209 do: define a C preprocessor symbol, set a variable in the output files,
8210 save the result in a cache file for future @command{configure} runs, and
8211 print a message letting the user know the result of the test.
8213 @menu
8214 * Defining Symbols::            Defining C preprocessor symbols
8215 * Setting Output Variables::    Replacing variables in output files
8216 * Special Chars in Variables::  Characters to beware of in variables
8217 * Caching Results::             Speeding up subsequent @command{configure} runs
8218 * Printing Messages::           Notifying @command{configure} users
8219 @end menu
8221 @node Defining Symbols
8222 @section Defining C Preprocessor Symbols
8224 A common action to take in response to a feature test is to define a C
8225 preprocessor symbol indicating the results of the test.  That is done by
8226 calling @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}.
8228 By default, @code{AC_OUTPUT} places the symbols defined by these macros
8229 into the output variable @code{DEFS}, which contains an option
8230 @option{-D@var{symbol}=@var{value}} for each symbol defined.  Unlike in
8231 Autoconf version 1, there is no variable @code{DEFS} defined while
8232 @command{configure} is running.  To check whether Autoconf macros have
8233 already defined a certain C preprocessor symbol, test the value of the
8234 appropriate cache variable, as in this example:
8236 @example
8237 AC_CHECK_FUNC([vprintf], [AC_DEFINE([HAVE_VPRINTF], [1],
8238                           [Define if vprintf exists.])])
8239 if test "$ac_cv_func_vprintf" != yes; then
8240   AC_CHECK_FUNC([_doprnt], [AC_DEFINE([HAVE_DOPRNT], [1],
8241                             [Define if _doprnt exists.])])
8243 @end example
8245 If @code{AC_CONFIG_HEADERS} has been called, then instead of creating
8246 @code{DEFS}, @code{AC_OUTPUT} creates a header file by substituting the
8247 correct values into @code{#define} statements in a template file.
8248 @xref{Configuration Headers}, for more information about this kind of
8249 output.
8251 @defmac AC_DEFINE (@var{variable}, @var{value}, @ovar{description})
8252 @defmacx AC_DEFINE (@var{variable})
8253 @acindex{DEFINE}
8254 Define @var{variable} to @var{value} (verbatim), by defining a C
8255 preprocessor macro for @var{variable}.  @var{variable} should be a C
8256 identifier, optionally suffixed by a parenthesized argument list to
8257 define a C preprocessor macro with arguments.  The macro argument list,
8258 if present, should be a comma-separated list of C identifiers, possibly
8259 terminated by an ellipsis @samp{...} if C99 syntax is employed.
8260 @var{variable} should not contain comments, white space, trigraphs,
8261 backslash-newlines, universal character names, or non-@acronym{ASCII}
8262 characters.
8264 @var{value} should not contain literal newlines, and if you are not
8265 using @code{AC_CONFIG_HEADERS} it should not contain any @samp{#}
8266 characters, as @command{make} tends to eat them.  To use a shell variable,
8267 use @code{AC_DEFINE_UNQUOTED} instead.
8268 @var{description} is only useful if you are using
8269 @code{AC_CONFIG_HEADERS}.  In this case, @var{description} is put into
8270 the generated @file{config.h.in} as the comment before the macro define.
8271 The following example defines the C preprocessor variable
8272 @code{EQUATION} to be the string constant @samp{"$a > $b"}:
8274 @example
8275 AC_DEFINE([EQUATION], ["$a > $b"],
8276   [Equation string.])
8277 @end example
8279 If neither @var{value} nor @var{description} are given, then
8280 @var{value} defaults to 1 instead of to the empty string.  This is for
8281 backwards compatibility with older versions of Autoconf, but this usage
8282 is obsolescent and may be withdrawn in future versions of Autoconf.
8284 If the @var{variable} is a literal string, it is passed to
8285 @code{m4_pattern_allow} (@pxref{Forbidden Patterns}).
8287 If multiple @code{AC_DEFINE} statements are executed for the same
8288 @var{variable} name (not counting any parenthesized argument list),
8289 the last one wins.
8290 @end defmac
8292 @defmac AC_DEFINE_UNQUOTED (@var{variable}, @var{value}, @ovar{description})
8293 @defmacx AC_DEFINE_UNQUOTED (@var{variable})
8294 @acindex{DEFINE_UNQUOTED}
8295 Like @code{AC_DEFINE}, but three shell expansions are
8296 performed---once---on @var{variable} and @var{value}: variable expansion
8297 (@samp{$}), command substitution (@samp{`}), and backslash escaping
8298 (@samp{\}).  Single and double quote characters in the value have no
8299 special meaning.  Use this macro instead of @code{AC_DEFINE} when
8300 @var{variable} or @var{value} is a shell variable.  Examples:
8302 @example
8303 AC_DEFINE_UNQUOTED([config_machfile], ["$machfile"],
8304   [Configuration machine file.])
8305 AC_DEFINE_UNQUOTED([GETGROUPS_T], [$ac_cv_type_getgroups],
8306   [getgroups return type.])
8307 AC_DEFINE_UNQUOTED([$ac_tr_hdr], [1],
8308   [Translated header name.])
8309 @end example
8310 @end defmac
8312 Due to a syntactical bizarreness of the Bourne shell, do not use
8313 semicolons to separate @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}
8314 calls from other macro calls or shell code; that can cause syntax errors
8315 in the resulting @command{configure} script.  Use either blanks or
8316 newlines.  That is, do this:
8318 @example
8319 AC_CHECK_HEADER([elf.h],
8320   [AC_DEFINE([SVR4], [1], [System V Release 4]) LIBS="-lelf $LIBS"])
8321 @end example
8323 @noindent
8324 or this:
8326 @example
8327 AC_CHECK_HEADER([elf.h],
8328   [AC_DEFINE([SVR4], [1], [System V Release 4])
8329    LIBS="-lelf $LIBS"])
8330 @end example
8332 @noindent
8333 instead of this:
8335 @example
8336 AC_CHECK_HEADER([elf.h],
8337   [AC_DEFINE([SVR4], [1], [System V Release 4]); LIBS="-lelf $LIBS"])
8338 @end example
8340 @node Setting Output Variables
8341 @section Setting Output Variables
8342 @cindex Output variables
8344 Another way to record the results of tests is to set @dfn{output
8345 variables}, which are shell variables whose values are substituted into
8346 files that @command{configure} outputs.  The two macros below create new
8347 output variables.  @xref{Preset Output Variables}, for a list of output
8348 variables that are always available.
8350 @defmac AC_SUBST (@var{variable}, @ovar{value})
8351 @acindex{SUBST}
8352 Create an output variable from a shell variable.  Make @code{AC_OUTPUT}
8353 substitute the variable @var{variable} into output files (typically one
8354 or more makefiles).  This means that @code{AC_OUTPUT}
8355 replaces instances of @samp{@@@var{variable}@@} in input files with the
8356 value that the shell variable @var{variable} has when @code{AC_OUTPUT}
8357 is called.  The value can contain any non-@code{NUL} character, including
8358 newline.
8359 Variable occurrences should not overlap: e.g., an input file should
8360 not contain @samp{@@@var{var1}@@@var{var2}@@} if @var{var1} and @var{var2}
8361 are variable names.
8362 The substituted value is not rescanned for more output variables;
8363 occurrences of @samp{@@@var{variable}@@} in the value are inserted
8364 literally into the output file.  (The algorithm uses the special marker
8365 @code{|#_!!_#|} internally, so neither the substituted value nor the
8366 output file may contain @code{|#_!!_#|}.)
8368 If @var{value} is given, in addition assign it to @var{variable}.
8370 The string @var{variable} is passed to @code{m4_pattern_allow}
8371 (@pxref{Forbidden Patterns}).
8372 @end defmac
8374 @defmac AC_SUBST_FILE (@var{variable})
8375 @acindex{SUBST_FILE}
8376 Another way to create an output variable from a shell variable.  Make
8377 @code{AC_OUTPUT} insert (without substitutions) the contents of the file
8378 named by shell variable @var{variable} into output files.  This means
8379 that @code{AC_OUTPUT} replaces instances of
8380 @samp{@@@var{variable}@@} in output files (such as @file{Makefile.in})
8381 with the contents of the file that the shell variable @var{variable}
8382 names when @code{AC_OUTPUT} is called.  Set the variable to
8383 @file{/dev/null} for cases that do not have a file to insert.
8384 This substitution occurs only when the @samp{@@@var{variable}@@} is on a
8385 line by itself, optionally surrounded by spaces and tabs.  The
8386 substitution replaces the whole line, including the spaces, tabs, and
8387 the terminating newline.
8389 This macro is useful for inserting makefile fragments containing
8390 special dependencies or other @code{make} directives for particular host
8391 or target types into makefiles.  For example, @file{configure.ac}
8392 could contain:
8394 @example
8395 AC_SUBST_FILE([host_frag])
8396 host_frag=$srcdir/conf/sun4.mh
8397 @end example
8399 @noindent
8400 and then a @file{Makefile.in} could contain:
8402 @example
8403 @@host_frag@@
8404 @end example
8406 The string @var{variable} is passed to @code{m4_pattern_allow}
8407 (@pxref{Forbidden Patterns}).
8408 @end defmac
8410 @cindex Precious Variable
8411 @cindex Variable, Precious
8412 Running @command{configure} in varying environments can be extremely
8413 dangerous.  If for instance the user runs @samp{CC=bizarre-cc
8414 ./configure}, then the cache, @file{config.h}, and many other output
8415 files depend upon @command{bizarre-cc} being the C compiler.  If
8416 for some reason the user runs @command{./configure} again, or if it is
8417 run via @samp{./config.status --recheck}, (@xref{Automatic Remaking},
8418 and @pxref{config.status Invocation}), then the configuration can be
8419 inconsistent, composed of results depending upon two different
8420 compilers.
8422 Environment variables that affect this situation, such as @samp{CC}
8423 above, are called @dfn{precious variables}, and can be declared as such
8424 by @code{AC_ARG_VAR}.
8426 @defmac AC_ARG_VAR (@var{variable}, @var{description})
8427 @acindex{ARG_VAR}
8428 Declare @var{variable} is a precious variable, and include its
8429 @var{description} in the variable section of @samp{./configure --help}.
8431 Being precious means that
8432 @itemize @minus
8433 @item
8434 @var{variable} is substituted via @code{AC_SUBST}.
8436 @item
8437 The value of @var{variable} when @command{configure} was launched is
8438 saved in the cache, including if it was not specified on the command
8439 line but via the environment.  Indeed, while @command{configure} can
8440 notice the definition of @code{CC} in @samp{./configure CC=bizarre-cc},
8441 it is impossible to notice it in @samp{CC=bizarre-cc ./configure},
8442 which, unfortunately, is what most users do.
8444 We emphasize that it is the @emph{initial} value of @var{variable} which
8445 is saved, not that found during the execution of @command{configure}.
8446 Indeed, specifying @samp{./configure FOO=foo} and letting
8447 @samp{./configure} guess that @code{FOO} is @code{foo} can be two
8448 different things.
8450 @item
8451 @var{variable} is checked for consistency between two
8452 @command{configure} runs.  For instance:
8454 @example
8455 $ @kbd{./configure --silent --config-cache}
8456 $ @kbd{CC=cc ./configure --silent --config-cache}
8457 configure: error: `CC' was not set in the previous run
8458 configure: error: changes in the environment can compromise \
8459 the build
8460 configure: error: run `make distclean' and/or \
8461 `rm config.cache' and start over
8462 @end example
8464 @noindent
8465 and similarly if the variable is unset, or if its content is changed.
8468 @item
8469 @var{variable} is kept during automatic reconfiguration
8470 (@pxref{config.status Invocation}) as if it had been passed as a command
8471 line argument, including when no cache is used:
8473 @example
8474 $ @kbd{CC=/usr/bin/cc ./configure undeclared_var=raboof --silent}
8475 $ @kbd{./config.status --recheck}
8476 running CONFIG_SHELL=/bin/sh /bin/sh ./configure undeclared_var=raboof \
8477   CC=/usr/bin/cc  --no-create --no-recursion
8478 @end example
8479 @end itemize
8480 @end defmac
8482 @node Special Chars in Variables
8483 @section Special Characters in Output Variables
8484 @cindex Output variables, special characters in
8486 Many output variables are intended to be evaluated both by
8487 @command{make} and by the shell.  Some characters are expanded
8488 differently in these two contexts, so to avoid confusion these
8489 variables' values should not contain any of the following characters:
8491 @example
8492 " # $ & ' ( ) * ; < > ? [ \ ^ ` |
8493 @end example
8495 Also, these variables' values should neither contain newlines, nor start
8496 with @samp{~}, nor contain white space or @samp{:} immediately followed
8497 by @samp{~}.  The values can contain nonempty sequences of white space
8498 characters like tabs and spaces, but each such sequence might
8499 arbitrarily be replaced by a single space during substitution.
8501 These restrictions apply both to the values that @command{configure}
8502 computes, and to the values set directly by the user.  For example, the
8503 following invocations of @command{configure} are problematic, since they
8504 attempt to use special characters within @code{CPPFLAGS} and white space
8505 within @code{$(srcdir)}:
8507 @example
8508 CPPFLAGS='-DOUCH="&\"#$*?"' '../My Source/ouch-1.0/configure'
8510 '../My Source/ouch-1.0/configure' CPPFLAGS='-DOUCH="&\"#$*?"'
8511 @end example
8513 @node Caching Results
8514 @section Caching Results
8515 @cindex Cache
8517 To avoid checking for the same features repeatedly in various
8518 @command{configure} scripts (or in repeated runs of one script),
8519 @command{configure} can optionally save the results of many checks in a
8520 @dfn{cache file} (@pxref{Cache Files}).  If a @command{configure} script
8521 runs with caching enabled and finds a cache file, it reads the results
8522 of previous runs from the cache and avoids rerunning those checks.  As a
8523 result, @command{configure} can then run much faster than if it had to
8524 perform all of the checks every time.
8526 @defmac AC_CACHE_VAL (@var{cache-id}, @var{commands-to-set-it})
8527 @acindex{CACHE_VAL}
8528 Ensure that the results of the check identified by @var{cache-id} are
8529 available.  If the results of the check were in the cache file that was
8530 read, and @command{configure} was not given the @option{--quiet} or
8531 @option{--silent} option, print a message saying that the result was
8532 cached; otherwise, run the shell commands @var{commands-to-set-it}.  If
8533 the shell commands are run to determine the value, the value is
8534 saved in the cache file just before @command{configure} creates its output
8535 files.  @xref{Cache Variable Names}, for how to choose the name of the
8536 @var{cache-id} variable.
8538 The @var{commands-to-set-it} @emph{must have no side effects} except for
8539 setting the variable @var{cache-id}, see below.
8540 @end defmac
8542 @defmac AC_CACHE_CHECK (@var{message}, @var{cache-id}, @var{commands-to-set-it})
8543 @acindex{CACHE_CHECK}
8544 A wrapper for @code{AC_CACHE_VAL} that takes care of printing the
8545 messages.  This macro provides a convenient shorthand for the most
8546 common way to use these macros.  It calls @code{AC_MSG_CHECKING} for
8547 @var{message}, then @code{AC_CACHE_VAL} with the @var{cache-id} and
8548 @var{commands} arguments, and @code{AC_MSG_RESULT} with @var{cache-id}.
8550 The @var{commands-to-set-it} @emph{must have no side effects} except for
8551 setting the variable @var{cache-id}, see below.
8552 @end defmac
8554 It is common to find buggy macros using @code{AC_CACHE_VAL} or
8555 @code{AC_CACHE_CHECK}, because people are tempted to call
8556 @code{AC_DEFINE} in the @var{commands-to-set-it}.  Instead, the code that
8557 @emph{follows} the call to @code{AC_CACHE_VAL} should call
8558 @code{AC_DEFINE}, by examining the value of the cache variable.  For
8559 instance, the following macro is broken:
8561 @example
8562 @group
8563 AC_DEFUN([AC_SHELL_TRUE],
8564 [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
8565                 [ac_cv_shell_true_works=no
8566                  (true) 2>/dev/null && ac_cv_shell_true_works=yes
8567                  if test "$ac_cv_shell_true_works" = yes; then
8568                    AC_DEFINE([TRUE_WORKS], [1],
8569                              [Define if `true(1)' works properly.])
8570                  fi])
8572 @end group
8573 @end example
8575 @noindent
8576 This fails if the cache is enabled: the second time this macro is run,
8577 @code{TRUE_WORKS} @emph{will not be defined}.  The proper implementation
8580 @example
8581 @group
8582 AC_DEFUN([AC_SHELL_TRUE],
8583 [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
8584                 [ac_cv_shell_true_works=no
8585                  (true) 2>/dev/null && ac_cv_shell_true_works=yes])
8586  if test "$ac_cv_shell_true_works" = yes; then
8587    AC_DEFINE([TRUE_WORKS], [1],
8588              [Define if `true(1)' works properly.])
8589  fi
8591 @end group
8592 @end example
8594 Also, @var{commands-to-set-it} should not print any messages, for
8595 example with @code{AC_MSG_CHECKING}; do that before calling
8596 @code{AC_CACHE_VAL}, so the messages are printed regardless of whether
8597 the results of the check are retrieved from the cache or determined by
8598 running the shell commands.
8600 @menu
8601 * Cache Variable Names::        Shell variables used in caches
8602 * Cache Files::                 Files @command{configure} uses for caching
8603 * Cache Checkpointing::         Loading and saving the cache file
8604 @end menu
8606 @node Cache Variable Names
8607 @subsection Cache Variable Names
8608 @cindex Cache variable
8610 The names of cache variables should have the following format:
8612 @example
8613 @var{package-prefix}_cv_@var{value-type}_@var{specific-value}_@ovar{additional-options}
8614 @end example
8616 @noindent
8617 for example, @samp{ac_cv_header_stat_broken} or
8618 @samp{ac_cv_prog_gcc_traditional}.  The parts of the variable name are:
8620 @table @asis
8621 @item @var{package-prefix}
8622 An abbreviation for your package or organization; the same prefix you
8623 begin local Autoconf macros with, except lowercase by convention.
8624 For cache values used by the distributed Autoconf macros, this value is
8625 @samp{ac}.
8627 @item @code{_cv_}
8628 Indicates that this shell variable is a cache value.  This string
8629 @emph{must} be present in the variable name, including the leading
8630 underscore.
8632 @item @var{value-type}
8633 A convention for classifying cache values, to produce a rational naming
8634 system.  The values used in Autoconf are listed in @ref{Macro Names}.
8636 @item @var{specific-value}
8637 Which member of the class of cache values this test applies to.
8638 For example, which function (@samp{alloca}), program (@samp{gcc}), or
8639 output variable (@samp{INSTALL}).
8641 @item @var{additional-options}
8642 Any particular behavior of the specific member that this test applies to.
8643 For example, @samp{broken} or @samp{set}.  This part of the name may
8644 be omitted if it does not apply.
8645 @end table
8647 The values assigned to cache variables may not contain newlines.
8648 Usually, their values are Boolean (@samp{yes} or @samp{no}) or the
8649 names of files or functions; so this is not an important restriction.
8651 @node Cache Files
8652 @subsection Cache Files
8654 A cache file is a shell script that caches the results of configure
8655 tests run on one system so they can be shared between configure scripts
8656 and configure runs.  It is not useful on other systems.  If its contents
8657 are invalid for some reason, the user may delete or edit it.
8659 By default, @command{configure} uses no cache file,
8660 to avoid problems caused by accidental
8661 use of stale cache files.
8663 To enable caching, @command{configure} accepts @option{--config-cache} (or
8664 @option{-C}) to cache results in the file @file{config.cache}.
8665 Alternatively, @option{--cache-file=@var{file}} specifies that
8666 @var{file} be the cache file.  The cache file is created if it does not
8667 exist already.  When @command{configure} calls @command{configure} scripts in
8668 subdirectories, it uses the @option{--cache-file} argument so that they
8669 share the same cache.  @xref{Subdirectories}, for information on
8670 configuring subdirectories with the @code{AC_CONFIG_SUBDIRS} macro.
8672 @file{config.status} only pays attention to the cache file if it is
8673 given the @option{--recheck} option, which makes it rerun
8674 @command{configure}.
8676 It is wrong to try to distribute cache files for particular system types.
8677 There is too much room for error in doing that, and too much
8678 administrative overhead in maintaining them.  For any features that
8679 can't be guessed automatically, use the standard method of the canonical
8680 system type and linking files (@pxref{Manual Configuration}).
8682 The site initialization script can specify a site-wide cache file to
8683 use, instead of the usual per-program cache.  In this case, the cache
8684 file gradually accumulates information whenever someone runs a new
8685 @command{configure} script.  (Running @command{configure} merges the new cache
8686 results with the existing cache file.)  This may cause problems,
8687 however, if the system configuration (e.g., the installed libraries or
8688 compilers) changes and the stale cache file is not deleted.
8690 @node Cache Checkpointing
8691 @subsection Cache Checkpointing
8693 If your configure script, or a macro called from @file{configure.ac}, happens
8694 to abort the configure process, it may be useful to checkpoint the cache
8695 a few times at key points using @code{AC_CACHE_SAVE}.  Doing so
8696 reduces the amount of time it takes to rerun the configure script with
8697 (hopefully) the error that caused the previous abort corrected.
8699 @c FIXME: Do we really want to document this guy?
8700 @defmac AC_CACHE_LOAD
8701 @acindex{CACHE_LOAD}
8702 Loads values from existing cache file, or creates a new cache file if a
8703 cache file is not found.  Called automatically from @code{AC_INIT}.
8704 @end defmac
8706 @defmac AC_CACHE_SAVE
8707 @acindex{CACHE_SAVE}
8708 Flushes all cached values to the cache file.  Called automatically from
8709 @code{AC_OUTPUT}, but it can be quite useful to call
8710 @code{AC_CACHE_SAVE} at key points in @file{configure.ac}.
8711 @end defmac
8713 For instance:
8715 @example
8716 @r{ @dots{} AC_INIT, etc. @dots{}}
8717 @group
8718 # Checks for programs.
8719 AC_PROG_CC
8720 AC_PROG_AWK
8721 @r{ @dots{} more program checks @dots{}}
8722 AC_CACHE_SAVE
8723 @end group
8725 @group
8726 # Checks for libraries.
8727 AC_CHECK_LIB([nsl], [gethostbyname])
8728 AC_CHECK_LIB([socket], [connect])
8729 @r{ @dots{} more lib checks @dots{}}
8730 AC_CACHE_SAVE
8731 @end group
8733 @group
8734 # Might abort@dots{}
8735 AM_PATH_GTK([1.0.2], [], [AC_MSG_ERROR([GTK not in path])])
8736 AM_PATH_GTKMM([0.9.5], [], [AC_MSG_ERROR([GTK not in path])])
8737 @end group
8738 @r{ @dots{} AC_OUTPUT, etc. @dots{}}
8739 @end example
8741 @node Printing Messages
8742 @section Printing Messages
8743 @cindex Messages, from @command{configure}
8745 @command{configure} scripts need to give users running them several kinds
8746 of information.  The following macros print messages in ways appropriate
8747 for each kind.  The arguments to all of them get enclosed in shell
8748 double quotes, so the shell performs variable and back-quote
8749 substitution on them.
8751 These macros are all wrappers around the @command{echo} shell command.
8752 They direct output to the appropriate file descriptor (@pxref{File
8753 Descriptor Macros}).
8754 @command{configure} scripts should rarely need to run @command{echo} directly
8755 to print messages for the user.  Using these macros makes it easy to
8756 change how and when each kind of message is printed; such changes need
8757 only be made to the macro definitions and all the callers change
8758 automatically.
8760 To diagnose static issues, i.e., when @command{autoconf} is run, see
8761 @ref{Reporting Messages}.
8763 @defmac AC_MSG_CHECKING (@var{feature-description})
8764 @acindex{MSG_CHECKING}
8765 Notify the user that @command{configure} is checking for a particular
8766 feature.  This macro prints a message that starts with @samp{checking }
8767 and ends with @samp{...} and no newline.  It must be followed by a call
8768 to @code{AC_MSG_RESULT} to print the result of the check and the
8769 newline.  The @var{feature-description} should be something like
8770 @samp{whether the Fortran compiler accepts C++ comments} or @samp{for
8771 c89}.
8773 This macro prints nothing if @command{configure} is run with the
8774 @option{--quiet} or @option{--silent} option.
8775 @end defmac
8777 @defmac AC_MSG_RESULT (@var{result-description})
8778 @acindex{MSG_RESULT}
8779 Notify the user of the results of a check.  @var{result-description} is
8780 almost always the value of the cache variable for the check, typically
8781 @samp{yes}, @samp{no}, or a file name.  This macro should follow a call
8782 to @code{AC_MSG_CHECKING}, and the @var{result-description} should be
8783 the completion of the message printed by the call to
8784 @code{AC_MSG_CHECKING}.
8786 This macro prints nothing if @command{configure} is run with the
8787 @option{--quiet} or @option{--silent} option.
8788 @end defmac
8790 @defmac AC_MSG_NOTICE (@var{message})
8791 @acindex{MSG_NOTICE}
8792 Deliver the @var{message} to the user.  It is useful mainly to print a
8793 general description of the overall purpose of a group of feature checks,
8794 e.g.,
8796 @example
8797 AC_MSG_NOTICE([checking if stack overflow is detectable])
8798 @end example
8800 This macro prints nothing if @command{configure} is run with the
8801 @option{--quiet} or @option{--silent} option.
8802 @end defmac
8804 @defmac AC_MSG_ERROR (@var{error-description}, @ovar{exit-status})
8805 @acindex{MSG_ERROR}
8806 Notify the user of an error that prevents @command{configure} from
8807 completing.  This macro prints an error message to the standard error
8808 output and exits @command{configure} with @var{exit-status} (1 by default).
8809 @var{error-description} should be something like @samp{invalid value
8810 $HOME for \$HOME}.
8812 The @var{error-description} should start with a lower-case letter, and
8813 ``cannot'' is preferred to ``can't''.
8814 @end defmac
8816 @defmac AC_MSG_FAILURE (@var{error-description}, @ovar{exit-status})
8817 @acindex{MSG_FAILURE}
8818 This @code{AC_MSG_ERROR} wrapper notifies the user of an error that
8819 prevents @command{configure} from completing @emph{and} that additional
8820 details are provided in @file{config.log}.  This is typically used when
8821 abnormal results are found during a compilation.
8822 @end defmac
8824 @defmac AC_MSG_WARN (@var{problem-description})
8825 @acindex{MSG_WARN}
8826 Notify the @command{configure} user of a possible problem.  This macro
8827 prints the message to the standard error output; @command{configure}
8828 continues running afterward, so macros that call @code{AC_MSG_WARN} should
8829 provide a default (back-up) behavior for the situations they warn about.
8830 @var{problem-description} should be something like @samp{ln -s seems to
8831 make hard links}.
8832 @end defmac
8836 @c ====================================================== Programming in M4.
8838 @node Programming in M4
8839 @chapter Programming in M4
8840 @cindex M4
8842 Autoconf is written on top of two layers: @dfn{M4sugar}, which provides
8843 convenient macros for pure M4 programming, and @dfn{M4sh}, which
8844 provides macros dedicated to shell script generation.
8846 As of this version of Autoconf, these two layers are still experimental,
8847 and their interface might change in the future.  As a matter of fact,
8848 @emph{anything that is not documented must not be used}.
8850 @menu
8851 * M4 Quotation::                Protecting macros from unwanted expansion
8852 * Using autom4te::              The Autoconf executables backbone
8853 * Programming in M4sugar::      Convenient pure M4 macros
8854 * Programming in M4sh::         Common shell Constructs
8855 * File Descriptor Macros::      File descriptor macros for input and output
8856 @end menu
8858 @node M4 Quotation
8859 @section M4 Quotation
8860 @cindex M4 quotation
8861 @cindex quotation
8863 @c FIXME: Grmph, yet another quoting myth: quotation has *never*
8864 @c prevented `expansion' of $1.  Unless it refers to the expansion
8865 @c of the value of $1?  Anyway, we need a rewrite here@enddots{}
8867 The most common problem with existing macros is an improper quotation.
8868 This section, which users of Autoconf can skip, but which macro writers
8869 @emph{must} read, first justifies the quotation scheme that was chosen
8870 for Autoconf and then ends with a rule of thumb.  Understanding the
8871 former helps one to follow the latter.
8873 @menu
8874 * Active Characters::           Characters that change the behavior of M4
8875 * One Macro Call::              Quotation and one macro call
8876 * Quotation and Nested Macros::  Macros calling macros
8877 * Changequote is Evil::         Worse than INTERCAL: M4 + changequote
8878 * Quadrigraphs::                Another way to escape special characters
8879 * Quotation Rule Of Thumb::     One parenthesis, one quote
8880 @end menu
8882 @node Active Characters
8883 @subsection Active Characters
8885 To fully understand where proper quotation is important, you first need
8886 to know what the special characters are in Autoconf: @samp{#} introduces
8887 a comment inside which no macro expansion is performed, @samp{,}
8888 separates arguments, @samp{[} and @samp{]} are the quotes themselves,
8889 and finally @samp{(} and @samp{)} (which M4 tries to match by
8890 pairs).
8892 In order to understand the delicate case of macro calls, we first have
8893 to present some obvious failures.  Below they are ``obvious-ified'',
8894 but when you find them in real life, they are usually in disguise.
8896 Comments, introduced by a hash and running up to the newline, are opaque
8897 tokens to the top level: active characters are turned off, and there is
8898 no macro expansion:
8900 @example
8901 # define([def], ine)
8902 @result{}# define([def], ine)
8903 @end example
8905 Each time there can be a macro expansion, there is a quotation
8906 expansion, i.e., one level of quotes is stripped:
8908 @example
8909 int tab[10];
8910 @result{}int tab10;
8911 [int tab[10];]
8912 @result{}int tab[10];
8913 @end example
8915 Without this in mind, the reader might try hopelessly to use her macro
8916 @code{array}:
8918 @example
8919 define([array], [int tab[10];])
8920 array
8921 @result{}int tab10;
8922 [array]
8923 @result{}array
8924 @end example
8926 @noindent
8927 How can you correctly output the intended results@footnote{Using
8928 @code{defn}.}?
8931 @node One Macro Call
8932 @subsection One Macro Call
8934 Let's proceed on the interaction between active characters and macros
8935 with this small macro, which just returns its first argument:
8937 @example
8938 define([car], [$1])
8939 @end example
8941 @noindent
8942 The two pairs of quotes above are not part of the arguments of
8943 @code{define}; rather, they are understood by the top level when it
8944 tries to find the arguments of @code{define}.  Therefore, assuming
8945 @code{car} is not already defined, it is equivalent to write:
8947 @example
8948 define(car, $1)
8949 @end example
8951 @noindent
8952 But, while it is acceptable for a @file{configure.ac} to avoid unnecessary
8953 quotes, it is bad practice for Autoconf macros which must both be more
8954 robust and also advocate perfect style.
8956 At the top level, there are only two possibilities: either you
8957 quote or you don't:
8959 @example
8960 car(foo, bar, baz)
8961 @result{}foo
8962 [car(foo, bar, baz)]
8963 @result{}car(foo, bar, baz)
8964 @end example
8966 Let's pay attention to the special characters:
8968 @example
8969 car(#)
8970 @error{}EOF in argument list
8971 @end example
8973 The closing parenthesis is hidden in the comment; with a hypothetical
8974 quoting, the top level understood it this way:
8976 @example
8977 car([#)]
8978 @end example
8980 @noindent
8981 Proper quotation, of course, fixes the problem:
8983 @example
8984 car([#])
8985 @result{}#
8986 @end example
8988 Here are more examples:
8990 @example
8991 car(foo, bar)
8992 @result{}foo
8993 car([foo, bar])
8994 @result{}foo, bar
8995 car((foo, bar))
8996 @result{}(foo, bar)
8997 car([(foo], [bar)])
8998 @result{}(foo
8999 define([a], [b])
9000 @result{}
9001 car(a)
9002 @result{}b
9003 car([a])
9004 @result{}b
9005 car([[a]])
9006 @result{}a
9007 car([[[a]]])
9008 @result{}[a]
9009 @end example
9011 With this in mind, we can explore the cases where macros invoke
9012 macros@enddots{}
9015 @node Quotation and Nested Macros
9016 @subsection Quotation and Nested Macros
9018 The examples below use the following macros:
9020 @example
9021 define([car], [$1])
9022 define([active], [ACT, IVE])
9023 define([array], [int tab[10]])
9024 @end example
9026 Each additional embedded macro call introduces other possible
9027 interesting quotations:
9029 @example
9030 car(active)
9031 @result{}ACT
9032 car([active])
9033 @result{}ACT, IVE
9034 car([[active]])
9035 @result{}active
9036 @end example
9038 In the first case, the top level looks for the arguments of @code{car},
9039 and finds @samp{active}.  Because M4 evaluates its arguments
9040 before applying the macro, @samp{active} is expanded, which results in:
9042 @example
9043 car(ACT, IVE)
9044 @result{}ACT
9045 @end example
9047 @noindent
9048 In the second case, the top level gives @samp{active} as first and only
9049 argument of @code{car}, which results in:
9051 @example
9052 active
9053 @result{}ACT, IVE
9054 @end example
9056 @noindent
9057 i.e., the argument is evaluated @emph{after} the macro that invokes it.
9058 In the third case, @code{car} receives @samp{[active]}, which results in:
9060 @example
9061 [active]
9062 @result{}active
9063 @end example
9065 @noindent
9066 exactly as we already saw above.
9068 The example above, applied to a more realistic example, gives:
9070 @example
9071 car(int tab[10];)
9072 @result{}int tab10;
9073 car([int tab[10];])
9074 @result{}int tab10;
9075 car([[int tab[10];]])
9076 @result{}int tab[10];
9077 @end example
9079 @noindent
9080 Huh?  The first case is easily understood, but why is the second wrong,
9081 and the third right?  To understand that, you must know that after
9082 M4 expands a macro, the resulting text is immediately subjected
9083 to macro expansion and quote removal.  This means that the quote removal
9084 occurs twice---first before the argument is passed to the @code{car}
9085 macro, and second after the @code{car} macro expands to the first
9086 argument.
9088 As the author of the Autoconf macro @code{car}, you then consider it to
9089 be incorrect that your users have to double-quote the arguments of
9090 @code{car}, so you ``fix'' your macro.  Let's call it @code{qar} for
9091 quoted car:
9093 @example
9094 define([qar], [[$1]])
9095 @end example
9097 @noindent
9098 and check that @code{qar} is properly fixed:
9100 @example
9101 qar([int tab[10];])
9102 @result{}int tab[10];
9103 @end example
9105 @noindent
9106 Ahhh!  That's much better.
9108 But note what you've done: now that the arguments are literal strings,
9109 if the user wants to use the results of expansions as arguments, she has
9110 to use an @emph{unquoted} macro call:
9112 @example
9113 qar(active)
9114 @result{}ACT
9115 @end example
9117 @noindent
9118 where she wanted to reproduce what she used to do with @code{car}:
9120 @example
9121 car([active])
9122 @result{}ACT, IVE
9123 @end example
9125 @noindent
9126 Worse yet: she wants to use a macro that produces a set of @code{cpp}
9127 macros:
9129 @example
9130 define([my_includes], [#include <stdio.h>])
9131 car([my_includes])
9132 @result{}#include <stdio.h>
9133 qar(my_includes)
9134 @error{}EOF in argument list
9135 @end example
9137 This macro, @code{qar}, because it double quotes its arguments, forces
9138 its users to leave their macro calls unquoted, which is dangerous.
9139 Commas and other active symbols are interpreted by M4 before
9140 they are given to the macro, often not in the way the users expect.
9141 Also, because @code{qar} behaves differently from the other macros,
9142 it's an exception that should be avoided in Autoconf.
9144 @node Changequote is Evil
9145 @subsection @code{changequote} is Evil
9146 @cindex @code{changequote}
9148 The temptation is often high to bypass proper quotation, in particular
9149 when it's late at night.  Then, many experienced Autoconf hackers
9150 finally surrender to the dark side of the force and use the ultimate
9151 weapon: @code{changequote}.
9153 The M4 builtin @code{changequote} belongs to a set of primitives that
9154 allow one to adjust the syntax of the language to adjust it to one's
9155 needs.  For instance, by default M4 uses @samp{`} and @samp{'} as
9156 quotes, but in the context of shell programming (and actually of most
9157 programming languages), that's about the worst choice one can make:
9158 because of strings and back-quoted expressions in shell code (such as
9159 @samp{'this'} and @samp{`that`}), because of literal characters in usual
9160 programming languages (as in @samp{'0'}), there are many unbalanced
9161 @samp{`} and @samp{'}.  Proper M4 quotation then becomes a nightmare, if
9162 not impossible.  In order to make M4 useful in such a context, its
9163 designers have equipped it with @code{changequote}, which makes it
9164 possible to choose another pair of quotes.  M4sugar, M4sh, Autoconf, and
9165 Autotest all have chosen to use @samp{[} and @samp{]}.  Not especially
9166 because they are unlikely characters, but @emph{because they are
9167 characters unlikely to be unbalanced}.
9169 There are other magic primitives, such as @code{changecom} to specify
9170 what syntactic forms are comments (it is common to see
9171 @samp{changecom(<!--, -->)} when M4 is used to produce HTML pages),
9172 @code{changeword} and @code{changesyntax} to change other syntactic
9173 details (such as the character to denote the @var{n}th argument, @samp{$} by
9174 default, the parenthesis around arguments, etc.).
9176 These primitives are really meant to make M4 more useful for specific
9177 domains: they should be considered like command line options:
9178 @option{--quotes}, @option{--comments}, @option{--words}, and
9179 @option{--syntax}.  Nevertheless, they are implemented as M4 builtins, as
9180 it makes M4 libraries self contained (no need for additional options).
9182 There lies the problem@enddots{}
9184 @sp 1
9186 The problem is that it is then tempting to use them in the middle of an
9187 M4 script, as opposed to its initialization.  This, if not carefully
9188 thought out, can lead to disastrous effects: @emph{you are changing the
9189 language in the middle of the execution}.  Changing and restoring the
9190 syntax is often not enough: if you happened to invoke macros in between,
9191 these macros are lost, as the current syntax is probably not
9192 the one they were implemented with.
9194 @c FIXME: I've been looking for a short, real case example, but I
9195 @c lost them all :(
9198 @node Quadrigraphs
9199 @subsection Quadrigraphs
9200 @cindex quadrigraphs
9201 @cindex @samp{@@S|@@}
9202 @cindex @samp{@@&t@@}
9203 @c Info cannot handle `:' in index entries.
9204 @c @cindex @samp{@@<:@@}
9205 @c @cindex @samp{@@:>@@}
9206 @c @cindex @samp{@@%:@@}
9208 When writing an Autoconf macro you may occasionally need to generate
9209 special characters that are difficult to express with the standard
9210 Autoconf quoting rules.  For example, you may need to output the regular
9211 expression @samp{[^[]}, which matches any character other than @samp{[}.
9212 This expression contains unbalanced brackets so it cannot be put easily
9213 into an M4 macro.
9215 You can work around this problem by using one of the following
9216 @dfn{quadrigraphs}:
9218 @table @samp
9219 @item @@<:@@
9220 @samp{[}
9221 @item @@:>@@
9222 @samp{]}
9223 @item @@S|@@
9224 @samp{$}
9225 @item @@%:@@
9226 @samp{#}
9227 @item @@&t@@
9228 Expands to nothing.
9229 @end table
9231 Quadrigraphs are replaced at a late stage of the translation process,
9232 after @command{m4} is run, so they do not get in the way of M4 quoting.
9233 For example, the string @samp{^@@<:@@}, independently of its quotation,
9234 appears as @samp{^[} in the output.
9236 The empty quadrigraph can be used:
9238 @itemize @minus
9239 @item to mark trailing spaces explicitly
9241 Trailing spaces are smashed by @command{autom4te}.  This is a feature.
9243 @item to produce other quadrigraphs
9245 For instance @samp{@@<@@&t@@:@@} produces @samp{@@<:@@}.
9247 @item to escape @emph{occurrences} of forbidden patterns
9249 For instance you might want to mention @code{AC_FOO} in a comment, while
9250 still being sure that @command{autom4te} still catches unexpanded
9251 @samp{AC_*}.  Then write @samp{AC@@&t@@_FOO}.
9252 @end itemize
9254 The name @samp{@@&t@@} was suggested by Paul Eggert:
9256 @quotation
9257 I should give some credit to the @samp{@@&t@@} pun.  The @samp{&} is my
9258 own invention, but the @samp{t} came from the source code of the
9259 @sc{algol68c} compiler, written by Steve Bourne (of Bourne shell fame),
9260 and which used @samp{mt} to denote the empty string.  In C, it would
9261 have looked like something like:
9263 @example
9264 char const mt[] = "";
9265 @end example
9267 @noindent
9268 but of course the source code was written in Algol 68.
9270 I don't know where he got @samp{mt} from: it could have been his own
9271 invention, and I suppose it could have been a common pun around the
9272 Cambridge University computer lab at the time.
9273 @end quotation
9275 @node Quotation Rule Of Thumb
9276 @subsection Quotation Rule Of Thumb
9278 To conclude, the quotation rule of thumb is:
9280 @center @emph{One pair of quotes per pair of parentheses.}
9282 Never over-quote, never under-quote, in particular in the definition of
9283 macros.  In the few places where the macros need to use brackets
9284 (usually in C program text or regular expressions), properly quote
9285 @emph{the arguments}!
9287 It is common to read Autoconf programs with snippets like:
9289 @example
9290 AC_TRY_LINK(
9291 changequote(<<, >>)dnl
9292 <<#include <time.h>
9293 #ifndef tzname /* For SGI.  */
9294 extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
9295 #endif>>,
9296 changequote([, ])dnl
9297 [atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)
9298 @end example
9300 @noindent
9301 which is incredibly useless since @code{AC_TRY_LINK} is @emph{already}
9302 double quoting, so you just need:
9304 @example
9305 AC_TRY_LINK(
9306 [#include <time.h>
9307 #ifndef tzname /* For SGI.  */
9308 extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
9309 #endif],
9310             [atoi (*tzname);],
9311             [ac_cv_var_tzname=yes],
9312             [ac_cv_var_tzname=no])
9313 @end example
9315 @noindent
9316 The M4-fluent reader might note that these two examples are rigorously
9317 equivalent, since M4 swallows both the @samp{changequote(<<, >>)}
9318 and @samp{<<} @samp{>>} when it @dfn{collects} the arguments: these
9319 quotes are not part of the arguments!
9321 Simplified, the example above is just doing this:
9323 @example
9324 changequote(<<, >>)dnl
9325 <<[]>>
9326 changequote([, ])dnl
9327 @end example
9329 @noindent
9330 instead of simply:
9332 @example
9333 [[]]
9334 @end example
9336 With macros that do not double quote their arguments (which is the
9337 rule), double-quote the (risky) literals:
9339 @example
9340 AC_LINK_IFELSE([AC_LANG_PROGRAM(
9341 [[#include <time.h>
9342 #ifndef tzname /* For SGI.  */
9343 extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
9344 #endif]],
9345                                 [atoi (*tzname);])],
9346                [ac_cv_var_tzname=yes],
9347                [ac_cv_var_tzname=no])
9348 @end example
9350 Please note that the macro @code{AC_TRY_LINK} is obsolete, so you really
9351 should be using @code{AC_LINK_IFELSE} instead.
9353 @xref{Quadrigraphs}, for what to do if you run into a hopeless case
9354 where quoting does not suffice.
9356 When you create a @command{configure} script using newly written macros,
9357 examine it carefully to check whether you need to add more quotes in
9358 your macros.  If one or more words have disappeared in the M4
9359 output, you need more quotes.  When in doubt, quote.
9361 However, it's also possible to put on too many layers of quotes.  If
9362 this happens, the resulting @command{configure} script may contain
9363 unexpanded macros.  The @command{autoconf} program checks for this problem
9364 by looking for the string @samp{AC_} in @file{configure}.  However, this
9365 heuristic does not work in general: for example, it does not catch
9366 overquoting in @code{AC_DEFINE} descriptions.
9369 @c ---------------------------------------- Using autom4te
9371 @node Using autom4te
9372 @section Using @command{autom4te}
9374 The Autoconf suite, including M4sugar, M4sh, and Autotest, in addition
9375 to Autoconf per se, heavily rely on M4.  All these different uses
9376 revealed common needs factored into a layer over M4:
9377 @command{autom4te}@footnote{
9379 Yet another great name from Lars J. Aas.
9383 @command{autom4te} is a preprocessor that is like @command{m4}.
9384 It supports M4 extensions designed for use in tools like Autoconf.
9386 @menu
9387 * autom4te Invocation::         A @acronym{GNU} M4 wrapper
9388 * Customizing autom4te::        Customizing the Autoconf package
9389 @end menu
9391 @node autom4te Invocation
9392 @subsection Invoking @command{autom4te}
9394 The command line arguments are modeled after M4's:
9396 @example
9397 autom4te @var{options} @var{files}
9398 @end example
9400 @noindent
9401 @evindex M4
9402 where the @var{files} are directly passed to @command{m4}.  By default,
9403 @acronym{GNU} M4 is found during configuration, but the environment
9404 variable
9405 @env{M4} can be set to tell @command{autom4te} where to look.  In addition
9406 to the regular expansion, it handles the replacement of the quadrigraphs
9407 (@pxref{Quadrigraphs}), and of @samp{__oline__}, the current line in the
9408 output.  It supports an extended syntax for the @var{files}:
9410 @table @file
9411 @item @var{file}.m4f
9412 This file is an M4 frozen file.  Note that @emph{all the previous files
9413 are ignored}.  See the option @option{--melt} for the rationale.
9415 @item @var{file}?
9416 If found in the library path, the @var{file} is included for expansion,
9417 otherwise it is ignored instead of triggering a failure.
9418 @end table
9420 @sp 1
9422 Of course, it supports the Autoconf common subset of options:
9424 @table @option
9425 @item --help
9426 @itemx -h
9427 Print a summary of the command line options and exit.
9429 @item --version
9430 @itemx -V
9431 Print the version number of Autoconf and exit.
9433 @item --verbose
9434 @itemx -v
9435 Report processing steps.
9437 @item --debug
9438 @itemx -d
9439 Don't remove the temporary files and be even more verbose.
9441 @item --include=@var{dir}
9442 @itemx -I @var{dir}
9443 Also look for input files in @var{dir}.  Multiple invocations
9444 accumulate.
9446 @item --output=@var{file}
9447 @itemx -o @var{file}
9448 Save output (script or trace) to @var{file}.  The file @option{-} stands
9449 for the standard output.
9450 @end table
9452 @sp 1
9454 As an extension of @command{m4}, it includes the following options:
9456 @table @option
9457 @item --warnings=@var{category}
9458 @itemx -W @var{category}
9459 @evindex WARNINGS
9460 @c FIXME: Point to the M4sugar macros, not Autoconf's.
9461 Report the warnings related to @var{category} (which can actually be a
9462 comma separated list).  @xref{Reporting Messages}, macro
9463 @code{AC_DIAGNOSE}, for a comprehensive list of categories.  Special
9464 values include:
9466 @table @samp
9467 @item all
9468 report all the warnings
9470 @item none
9471 report none
9473 @item error
9474 treats warnings as errors
9476 @item no-@var{category}
9477 disable warnings falling into @var{category}
9478 @end table
9480 Warnings about @samp{syntax} are enabled by default, and the environment
9481 variable @env{WARNINGS}, a comma separated list of categories, is
9482 honored.  @samp{autom4te -W @var{category}} actually
9483 behaves as if you had run:
9485 @example
9486 autom4te --warnings=syntax,$WARNINGS,@var{category}
9487 @end example
9489 @noindent
9490 For example, if you want to disable defaults and @env{WARNINGS}
9491 of @command{autom4te}, but enable the warnings about obsolete
9492 constructs, you would use @option{-W none,obsolete}.
9494 @cindex Back trace
9495 @cindex Macro invocation stack
9496 @command{autom4te} displays a back trace for errors, but not for
9497 warnings; if you want them, just pass @option{-W error}.
9499 @item --melt
9500 @itemx -M
9501 Do not use frozen files.  Any argument @code{@var{file}.m4f} is
9502 replaced by @code{@var{file}.m4}.  This helps tracing the macros which
9503 are executed only when the files are frozen, typically
9504 @code{m4_define}.  For instance, running:
9506 @example
9507 autom4te --melt 1.m4 2.m4f 3.m4 4.m4f input.m4
9508 @end example
9510 @noindent
9511 is roughly equivalent to running:
9513 @example
9514 m4 1.m4 2.m4 3.m4 4.m4 input.m4
9515 @end example
9517 @noindent
9518 while
9520 @example
9521 autom4te 1.m4 2.m4f 3.m4 4.m4f input.m4
9522 @end example
9524 @noindent
9525 is equivalent to:
9527 @example
9528 m4 --reload-state=4.m4f input.m4
9529 @end example
9531 @item --freeze
9532 @itemx -f
9533 Produce a frozen state file.  @command{autom4te} freezing is stricter
9534 than M4's: it must produce no warnings, and no output other than empty
9535 lines (a line with white space is @emph{not} empty) and comments
9536 (starting with @samp{#}).  Unlike @command{m4}'s similarly-named option,
9537 this option takes no argument:
9539 @example
9540 autom4te 1.m4 2.m4 3.m4 --freeze --output=3.m4f
9541 @end example
9543 @noindent
9544 corresponds to
9546 @example
9547 m4 1.m4 2.m4 3.m4 --freeze-state=3.m4f
9548 @end example
9550 @item --mode=@var{octal-mode}
9551 @itemx -m @var{octal-mode}
9552 Set the mode of the non-traces output to @var{octal-mode}; by default
9553 @samp{0666}.
9554 @end table
9556 @sp 1
9558 @cindex @file{autom4te.cache}
9559 As another additional feature over @command{m4}, @command{autom4te}
9560 caches its results.  @acronym{GNU} M4 is able to produce a regular
9561 output and traces at the same time.  Traces are heavily used in the
9562 @acronym{GNU} Build System: @command{autoheader} uses them to build
9563 @file{config.h.in}, @command{autoreconf} to determine what
9564 @acronym{GNU} Build System components are used, @command{automake} to
9565 ``parse'' @file{configure.ac} etc.  To avoid recomputation,
9566 traces are cached while performing regular expansion,
9567 and conversely.  This cache is (actually, the caches are) stored in
9568 the directory @file{autom4te.cache}.  @emph{It can safely be removed}
9569 at any moment (especially if for some reason @command{autom4te}
9570 considers it is trashed).
9572 @table @option
9573 @item --cache=@var{directory}
9574 @itemx -C @var{directory}
9575 Specify the name of the directory where the result should be cached.
9576 Passing an empty value disables caching.  Be sure to pass a relative
9577 file name, as for the time being, global caches are not supported.
9579 @item --no-cache
9580 Don't cache the results.
9582 @item --force
9583 @itemx -f
9584 If a cache is used, consider it obsolete (but update it anyway).
9585 @end table
9587 @sp 1
9589 Because traces are so important to the @acronym{GNU} Build System,
9590 @command{autom4te} provides high level tracing features as compared to
9591 M4, and helps exploiting the cache:
9593 @table @option
9594 @item --trace=@var{macro}[:@var{format}]
9595 @itemx -t @var{macro}[:@var{format}]
9596 Trace the invocations of @var{macro} according to the @var{format}.
9597 Multiple @option{--trace} arguments can be used to list several macros.
9598 Multiple @option{--trace} arguments for a single macro are not
9599 cumulative; instead, you should just make @var{format} as long as
9600 needed.
9602 The @var{format} is a regular string, with newlines if desired, and
9603 several special escape codes.  It defaults to @samp{$f:$l:$n:$%}.  It can
9604 use the following special escapes:
9606 @table @samp
9607 @item $$
9608 The character @samp{$}.
9610 @item $f
9611 The file name from which @var{macro} is called.
9613 @item $l
9614 The line number from which @var{macro} is called.
9616 @item $d
9617 The depth of the @var{macro} call.  This is an M4 technical detail that
9618 you probably don't want to know about.
9620 @item $n
9621 The name of the @var{macro}.
9623 @item $@var{num}
9624 The @var{num}th argument of the call to @var{macro}.
9626 @item $@@
9627 @itemx $@var{sep}@@
9628 @itemx $@{@var{separator}@}@@
9629 All the arguments passed to @var{macro}, separated by the character
9630 @var{sep} or the string @var{separator} (@samp{,} by default).  Each
9631 argument is quoted, i.e., enclosed in a pair of square brackets.
9633 @item $*
9634 @itemx $@var{sep}*
9635 @itemx $@{@var{separator}@}*
9636 As above, but the arguments are not quoted.
9638 @item $%
9639 @itemx $@var{sep}%
9640 @itemx $@{@var{separator}@}%
9641 As above, but the arguments are not quoted, all new line characters in
9642 the arguments are smashed, and the default separator is @samp{:}.
9644 The escape @samp{$%} produces single-line trace outputs (unless you put
9645 newlines in the @samp{separator}), while @samp{$@@} and @samp{$*} do
9646 not.
9647 @end table
9649 @xref{autoconf Invocation}, for examples of trace uses.
9651 @item --preselect=@var{macro}
9652 @itemx -p @var{macro}
9653 Cache the traces of @var{macro}, but do not enable traces.  This is
9654 especially important to save CPU cycles in the future.  For instance,
9655 when invoked, @command{autoconf} preselects all the macros that
9656 @command{autoheader}, @command{automake}, @command{autoreconf}, etc.,
9657 trace, so that running @command{m4} is not needed to trace them: the
9658 cache suffices.  This results in a huge speed-up.
9659 @end table
9661 @sp 1
9663 @cindex Autom4te Library
9664 Finally, @command{autom4te} introduces the concept of @dfn{Autom4te
9665 libraries}.  They consists in a powerful yet extremely simple feature:
9666 sets of combined command line arguments:
9668 @table @option
9669 @item --language=@var{language}
9670 @itemx -l @var{language}
9671 Use the @var{language} Autom4te library.  Current languages include:
9673 @table @code
9674 @item M4sugar
9675 create M4sugar output.
9677 @item M4sh
9678 create M4sh executable shell scripts.
9680 @item Autotest
9681 create Autotest executable test suites.
9683 @item Autoconf-without-aclocal-m4
9684 create Autoconf executable configure scripts without
9685 reading @file{aclocal.m4}.
9687 @item Autoconf
9688 create Autoconf executable configure scripts.  This language inherits
9689 all the characteristics of @code{Autoconf-without-aclocal-m4} and
9690 additionally reads @file{aclocal.m4}.
9691 @end table
9693 @item --prepend-include=@var{dir}
9694 @item -B @var{dir}
9695 Prepend directory @var{dir} to the search path.  This is used to include
9696 the language-specific files before any third-party macros.
9698 @end table
9700 @cindex @file{autom4te.cfg}
9701 As an example, if Autoconf is installed in its default location,
9702 @file{/usr/local}, the command @samp{autom4te -l m4sugar foo.m4} is
9703 strictly equivalent to the command:
9705 @example
9706 autom4te --prepend-include /usr/local/share/autoconf \
9707   m4sugar/m4sugar.m4f --warnings syntax foo.m4
9708 @end example
9710 @noindent
9711 Recursive expansion applies here: the command @samp{autom4te -l m4sh foo.m4}
9712 is the same as @samp{autom4te --language M4sugar m4sugar/m4sh.m4f
9713 foo.m4}, i.e.:
9715 @example
9716 autom4te --prepend-include /usr/local/share/autoconf \
9717   m4sugar/m4sugar.m4f m4sugar/m4sh.m4f --mode 777 foo.m4
9718 @end example
9720 @noindent
9721 The definition of the languages is stored in @file{autom4te.cfg}.
9723 @node Customizing autom4te
9724 @subsection Customizing @command{autom4te}
9726 One can customize @command{autom4te} via @file{~/.autom4te.cfg} (i.e.,
9727 as found in the user home directory), and @file{./.autom4te.cfg} (i.e.,
9728 as found in the directory from which @command{autom4te} is run).  The
9729 order is first reading @file{autom4te.cfg}, then @file{~/.autom4te.cfg},
9730 then @file{./.autom4te.cfg}, and finally the command line arguments.
9732 In these text files, comments are introduced with @code{#}, and empty
9733 lines are ignored.  Customization is performed on a per-language basis,
9734 wrapped in between a @samp{begin-language: "@var{language}"},
9735 @samp{end-language: "@var{language}"} pair.
9737 Customizing a language stands for appending options (@pxref{autom4te
9738 Invocation}) to the current definition of the language.  Options, and
9739 more generally arguments, are introduced by @samp{args:
9740 @var{arguments}}.  You may use the traditional shell syntax to quote the
9741 @var{arguments}.
9743 As an example, to disable Autoconf caches (@file{autom4te.cache})
9744 globally, include the following lines in @file{~/.autom4te.cfg}:
9746 @verbatim
9747 ## ------------------ ##
9748 ## User Preferences.  ##
9749 ## ------------------ ##
9751 begin-language: "Autoconf-without-aclocal-m4"
9752 args: --no-cache
9753 end-language: "Autoconf-without-aclocal-m4"
9754 @end verbatim
9757 @node Programming in M4sugar
9758 @section Programming in M4sugar
9760 @cindex M4sugar
9761 M4 by itself provides only a small, but sufficient, set of all-purpose
9762 macros.  M4sugar introduces additional generic macros.  Its name was
9763 coined by Lars J. Aas: ``Readability And Greater Understanding Stands 4
9764 M4sugar''.
9766 @menu
9767 * Redefined M4 Macros::         M4 builtins changed in M4sugar
9768 * Looping constructs::          Iteration in M4
9769 * Evaluation Macros::           More quotation and evaluation control
9770 * Text processing Macros::      String manipulation in M4
9771 * Forbidden Patterns::          Catching unexpanded macros
9772 @end menu
9774 @node Redefined M4 Macros
9775 @subsection Redefined M4 Macros
9777 @msindex{builtin}
9778 @msindex{decr}
9779 @msindex{define}
9780 @msindex{dumpdef}
9781 @msindex{errprint}
9782 @msindex{esyscmd}
9783 @msindex{eval}
9784 @msindex{format}
9785 @msindex{ifdef}
9786 @msindex{incr}
9787 @msindex{index}
9788 @msindex{indir}
9789 @msindex{len}
9790 @msindex{pushdef}
9791 @msindex{shift}
9792 @msindex{substr}
9793 @msindex{syscmd}
9794 @msindex{sysval}
9795 @msindex{translit}
9796 @msindex{undefine}
9797 With a few exceptions, all the M4 native macros are moved in the
9798 @samp{m4_} pseudo-namespace, e.g., M4sugar renames @code{define} as
9799 @code{m4_define} etc.
9801 Some M4 macros are redefined, and are slightly incompatible with their
9802 native equivalent.
9804 @defmac dnl
9805 @msindex{dnl}
9806 This macro kept its original name: no @code{m4_dnl} is defined.
9807 @end defmac
9809 @defmac m4_defn (@var{macro})
9810 @msindex{defn}
9811 Unlike the M4 builtin, this macro fails if @var{macro} is not
9812 defined.  See @code{m4_undefine}.
9813 @end defmac
9815 @defmac m4_exit (@var{exit-status})
9816 @msindex{exit}
9817 This macro corresponds to @code{m4exit}.
9818 @end defmac
9820 @defmac m4_if (@var{comment})
9821 @defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal}, @ovar{not-equal})
9822 @defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal}, @dots{})
9823 @msindex{if}
9824 This macro corresponds to @code{ifelse}.
9825 @end defmac
9827 @defmac m4_include (@var{file})
9828 @defmacx m4_sinclude (@var{file})
9829 @msindex{include}
9830 @msindex{sinclude}
9831 Like the M4 builtins, but warn against multiple inclusions of @var{file}.
9832 @end defmac
9834 @defmac m4_bpatsubst (@var{string}, @var{regexp}, @ovar{replacement})
9835 @msindex{bpatsubst}
9836 This macro corresponds to @code{patsubst}.  The name @code{m4_patsubst}
9837 is kept for future versions of M4sh, on top of @acronym{GNU} M4 which will
9838 provide extended regular expression syntax via @code{epatsubst}.
9839 @end defmac
9841 @defmac m4_popdef (@var{macro})
9842 @msindex{popdef}
9843 Unlike the M4 builtin, this macro fails if @var{macro} is not
9844 defined.  See @code{m4_undefine}.
9845 @end defmac
9847 @defmac m4_bregexp (@var{string}, @var{regexp}, @ovar{replacement})
9848 @msindex{bregexp}
9849 This macro corresponds to @code{regexp}.  The name @code{m4_regexp}
9850 is kept for future versions of M4sh, on top of @acronym{GNU} M4 which will
9851 provide extended regular expression syntax via @code{eregexp}.
9852 @end defmac
9854 @defmac m4_wrap (@var{text})
9855 @msindex{wrap}
9856 This macro corresponds to @code{m4wrap}.
9858 Posix requires arguments of multiple @code{m4wrap} calls to be
9859 reprocessed at @acronym{EOF} in the same order as the original calls.
9860 @acronym{GNU} M4 versions through 1.4.x, however, reprocess them in
9861 reverse order.  Your code should not depend on the order.
9863 Also, Posix requires @code{m4wrap} to ignore its second and succeeding
9864 arguments, but @acronym{GNU} M4 versions through 1.4.x concatenate the
9865 arguments with intervening spaces.  Your code should not pass more than
9866 one argument.
9868 You are encouraged to end @var{text} with @samp{[]}, to avoid unexpected
9869 token pasting between consecutive invocations of @code{m4_wrap}, as in:
9871 @example
9872 m4_define([foo], [bar])
9873 m4_define([foofoo], [OUCH])
9874 m4_wrap([foo])
9875 m4_wrap([foo])
9876 @result{}OUCH
9877 @end example
9878 @end defmac
9880 @defmac m4_undefine (@var{macro})
9881 @msindex{undefine}
9882 Unlike the M4 builtin, this macro fails if @var{macro} is not
9883 defined.  Use
9885 @example
9886 m4_ifdef([@var{macro}], [m4_undefine([@var{macro}])])
9887 @end example
9889 @noindent
9890 to recover the behavior of the builtin.
9891 @end defmac
9893 @defmac m4_maketemp (@var{template})
9894 @defmacx m4_mkstemp (@var{template})
9895 @msindex{maketemp}
9896 @msindex{mkstemp}
9897 Posix requires @code{maketemp} to replace the trailing @samp{X}
9898 characters in @var{template} with the process id, without regards to the
9899 existence of a file by that name, but this a security hole.  When this
9900 was pointed out to the Posix folks, they agreed to invent a new macro
9901 @code{mkstemp} that always creates a uniquely named file, but not all
9902 versions of @acronym{GNU} M4 support the new macro.  In M4sugar,
9903 @code{m4_maketemp} and @code{m4_mkstemp} are synonyms for each other,
9904 and both have the secure semantics regardless of which macro the
9905 underlying M4 provides.
9906 @end defmac
9909 @node Looping constructs
9910 @subsection Looping constructs
9912 The following macros implement loops in M4.
9914 @defmac m4_for (@var{var}, @var{first}, @var{last}, @ovar{step}, @var{expression})
9915 @msindex{for}
9916 Loop over the numeric values between @var{first} and @var{last}
9917 including bounds by increments of @var{step}.  For each iteration,
9918 expand @var{expression} with the numeric value assigned to @var{var}.
9919 If @var{step} is omitted, it defaults to @samp{1} or @samp{-1} depending
9920 on the order of the limits.  If given, @var{step} has to match this
9921 order.
9922 @end defmac
9924 @defmac m4_foreach (@var{var}, @var{list}, @var{expression})
9925 @msindex{foreach}
9926 Loop over the comma-separated M4 list @var{list}, assigning each value
9927 to @var{var}, and expand @var{expression}.  The following example
9928 outputs two lines:
9930 @example
9931 m4_foreach([myvar], [[foo], [bar, baz]],
9932            [echo myvar
9935 @end example
9936 @end defmac
9938 @defmac m4_foreach_w (@var{var}, @var{list}, @var{expression})
9939 @msindex{foreach_w}
9940 Loop over the white-space-separated list @var{list}, assigning each value
9941 to @var{var}, and expand @var{expression}.
9943 The deprecated macro @code{AC_FOREACH} is an alias of
9944 @code{m4_foreach_w}.
9945 @end defmac
9949 @node Evaluation Macros
9950 @subsection Evaluation Macros
9952 The following macros give some control over the order of the evaluation
9953 by adding or removing levels of quotes.  They are meant for hard-core M4
9954 programmers.
9956 @defmac m4_dquote (@var{arg1}, @dots{})
9957 @msindex{dquote}
9958 Return the arguments as a quoted list of quoted arguments.
9959 @end defmac
9961 @defmac m4_quote (@var{arg1}, @dots{})
9962 @msindex{quote}
9963 Return the arguments as a single entity, i.e., wrap them into a pair of
9964 quotes.
9965 @end defmac
9967 The following example aims at emphasizing the difference between (i), not
9968 using these macros, (ii), using @code{m4_quote}, and (iii), using
9969 @code{m4_dquote}.
9971 @example
9972 $ @kbd{cat example.m4}
9973 # Overquote, so that quotes are visible.
9974 m4_define([show], [$[]1 = [$1], $[]@@ = [$@@]])
9975 m4_define([mkargs], [1, 2, 3])
9976 m4_define([arg1], [[$1]])
9977 m4_divert(0)dnl
9978 show(a, b)
9979 show(m4_quote(a, b))
9980 show(m4_dquote(a, b))
9981 arg1(mkargs)
9982 arg1([mkargs])
9983 arg1(m4_defn([mkargs]))
9984 arg1(m4_quote(mkargs))
9985 arg1(m4_dquote(mkargs))
9986 $ @kbd{autom4te -l m4sugar example.m4}
9987 $1 = a, $@@ = [a],[b]
9988 $1 = a,b, $@@ = [a,b]
9989 $1 = [a],[b], $@@ = [[a],[b]]
9991 mkargs
9992 1, 2, 3
9993 1,2,3
9994 [1],[2],[3]
9995 @end example
9999 @node Text processing Macros
10000 @subsection Text processing Macros
10002 The following macros may be used to manipulate strings in M4.
10003 They are not intended for casual use.
10005 @defmac m4_re_escape (@var{string})
10006 @msindex{re_escape}
10007 Backslash-escape all characters in @var{string} that are active in
10008 regexps.
10009 @end defmac
10011 @defmac m4_tolower (@var{string})
10012 @defmacx m4_toupper (@var{string})
10013 @msindex{tolower}
10014 @msindex{toupper}
10015 Return @var{string} with letters converted to upper or lower case,
10016 respectively.
10017 @end defmac
10019 @defmac m4_split (@var{string}, @ovar{regexp})
10020 @msindex{split}
10021 Split @var{string} into an M4 list of elements quoted by @samp{[} and
10022 @samp{]}, while keeping white space at the beginning and at the end.
10023 If @var{regexp} is given, use it instead of @samp{[\t ]+} for splitting.
10024 If @var{string} is empty, the result is an empty list.
10025 @end defmac
10027 @defmac m4_normalize (@var{string})
10028 @msindex{normalize}
10029 Remove leading and trailing spaces and tabs, sequences of
10030 backslash-then-newline, and replace multiple spaces and tabs with a
10031 single space.
10032 @end defmac
10034 @defmac m4_append (@var{macro-name}, @var{string}, @ovar{separator})
10035 @defmacx m4_append_uniq (@var{macro-name}, @var{string}, @ovar{separator})
10036 @msindex{append}
10037 @msindex{append_uniq}
10038 Redefine @var{macro-name} to its former contents with @var{separator}
10039 and @var{string} added at the end.  If @var{macro-name} was undefined
10040 before (but not if it was defined but empty), then no @var{separator} is
10041 added.  @code{m4_append} can be used to grow strings, and
10042 @code{m4_append_uniq} to grow strings without duplicating substrings.
10043 @end defmac
10047 @node Forbidden Patterns
10048 @subsection Forbidden Patterns
10049 @cindex Forbidden patterns
10050 @cindex Patterns, forbidden
10052 M4sugar provides a means to define suspicious patterns, patterns
10053 describing tokens which should not be found in the output.  For
10054 instance, if an Autoconf @file{configure} script includes tokens such as
10055 @samp{AC_DEFINE}, or @samp{dnl}, then most probably something went
10056 wrong (typically a macro was not evaluated because of overquotation).
10058 M4sugar forbids all the tokens matching @samp{^m4_} and @samp{^dnl$}.
10060 @defmac m4_pattern_forbid (@var{pattern})
10061 @msindex{pattern_forbid}
10062 Declare that no token matching @var{pattern} must be found in the output.
10063 Comments are not checked; this can be a problem if, for instance, you
10064 have some macro left unexpanded after an @samp{#include}.  No consensus
10065 is currently found in the Autoconf community, as some people consider it
10066 should be valid to name macros in comments (which doesn't make sense to
10067 the author of this documentation, as @samp{#}-comments should document
10068 the output, not the input, documented by @samp{dnl} comments).
10069 @end defmac
10071 Of course, you might encounter exceptions to these generic rules, for
10072 instance you might have to refer to @samp{$m4_flags}.
10074 @defmac m4_pattern_allow (@var{pattern})
10075 @msindex{pattern_allow}
10076 Any token matching @var{pattern} is allowed, including if it matches an
10077 @code{m4_pattern_forbid} pattern.
10078 @end defmac
10080 @node Programming in M4sh
10081 @section Programming in M4sh
10083 @c FIXME: Eventually will become a chapter, as it is not related to
10084 @c programming in M4 per se.
10086 M4sh, pronounced ``mash'', is aiming at producing portable Bourne shell
10087 scripts.  This name was coined by Lars J. Aas, who notes that,
10088 according to the Webster's Revised Unabridged Dictionary (1913):
10090 @quotation
10091 Mash \Mash\, n.  [Akin to G. meisch, maisch, meische, maische, mash,
10092 wash, and prob.@: to AS. miscian to mix.  See ``Mix''.]
10094 @enumerate 1
10095 @item
10096 A mass of mixed ingredients reduced to a soft pulpy state by beating or
10097 pressure@enddots{}
10099 @item
10100 A mixture of meal or bran and water fed to animals.
10102 @item
10103 A mess; trouble.  [Obs.] --Beau.@: & Fl.
10104 @end enumerate
10105 @end quotation
10108 For the time being, it is not mature enough to be widely used.
10110 M4sh provides portable alternatives for some common shell constructs
10111 that unfortunately are not portable in practice.
10113 @c Deprecated, to be replaced by a better API
10114 @ignore
10115 @defmac AS_BASENAME (@var{file-name})
10116 @asindex{BASENAME}
10117 Output the non-directory portion of @var{file-name}.  For example,
10118 if @code{$file} is @samp{/one/two/three}, the command
10119 @code{base=`AS_BASENAME(["$file"])`} sets @code{base} to @samp{three}.
10120 @end defmac
10121 @end ignore
10123 @defmac AS_BOURNE_COMPATIBLE
10124 @asindex{BOURNE_COMPATIBLE}
10125 Set up the shell to be more compatible with the Bourne shell as
10126 standardized by Posix, if possible.  This may involve setting
10127 environment variables, or setting options, or similar
10128 implementation-specific actions.
10129 @end defmac
10131 @defmac AS_CASE (@var{word}, @ovar{pattern1}, @ovar{if-matched1}, @dots{}, @ovar{default})
10132 @asindex{CASE}
10133 Expand into a shell @samp{case} statement, where @var{word} is matched
10134 against one or more patterns.  @var{if-matched} is run if the
10135 corresponding pattern matched @var{word}, else @var{default} is run.
10136 @end defmac
10138 @defmac AS_DIRNAME (@var{file-name})
10139 @asindex{DIRNAME}
10140 Output the directory portion of @var{file-name}.  For example,
10141 if @code{$file} is @samp{/one/two/three}, the command
10142 @code{dir=`AS_DIRNAME(["$file"])`} sets @code{dir} to @samp{/one/two}.
10143 @end defmac
10145 @defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false})
10146 @asindex{IF}
10147 Run shell code @var{test1}.  If @var{test1} exits with a zero status then
10148 run shell code @var{run-if-true1}, else examine further tests.  If no test
10149 exits with a zero status, run shell code @var{run-if-false}, with
10150 simplifications if either @var{run-if-true1} or @var{run-if-false1}
10151 is empty.  For example,
10153 @example
10154 AS_IF([test "$foo" = yes], [HANDLE_FOO([yes])],
10155       [test "$foo" != no], [HANDLE_FOO([maybe])],
10156       [echo foo not specified])
10157 @end example
10159 @noindent
10160 ensures any required macros of @code{HANDLE_FOO}
10161 are expanded before the first test.
10162 @end defmac
10164 @defmac AS_MKDIR_P (@var{file-name})
10165 @asindex{MKDIR_P}
10166 Make the directory @var{file-name}, including intervening directories
10167 as necessary.  This is equivalent to @samp{mkdir -p @var{file-name}},
10168 except that it is portable to older versions of @command{mkdir} that
10169 lack support for the @option{-p} option.  Also, @code{AS_MKDIR_P}
10170 succeeds if @var{file-name} is a symbolic link to an existing directory,
10171 even though Posix is unclear whether @samp{mkdir -p} should
10172 succeed in that case.  If creation of @var{file-name} fails, exit the
10173 script.
10175 Also see the @code{AC_PROG_MKDIR_P} macro (@pxref{Particular Programs}).
10176 @end defmac
10178 @defmac AS_SHELL_SANITIZE
10179 @asindex{SHELL_SANITIZE}
10180 Initialize the shell suitably for @code{configure} scripts.  This has
10181 the effect of @code{AS_BOURNE_COMPATIBLE}, and sets some other
10182 environment variables for predictable results from configuration tests.
10183 For example, it sets @env{LC_ALL} to change to the default C locale.
10184 @xref{Special Shell Variables}.
10185 @end defmac
10187 @defmac AS_TR_CPP (@var{expression})
10188 @asindex{TR_CPP}
10189 Transform @var{expression} into a valid right-hand side for a C @code{#define}.
10190 For example:
10192 @example
10193 # This outputs "#define HAVE_CHAR_P 1".
10194 type="char *"
10195 echo "#define AS_TR_CPP([HAVE_$type]) 1"
10196 @end example
10197 @end defmac
10199 @defmac AS_TR_SH (@var{expression})
10200 @asindex{TR_SH}
10201 Transform @var{expression} into a valid shell variable name.  For example:
10203 @example
10204 # This outputs "Have it!".
10205 header="sys/some file.h"
10206 AS_TR_SH([HAVE_$header])=yes
10207 if test "$HAVE_sys_some_file_h" = yes; then echo "Have it!"; fi
10208 @end example
10209 @end defmac
10211 @defmac AS_SET_CATFILE (@var{var}, @var{dir}, @var{file})
10212 @asindex{SET_CATFILE}
10213 Set the shell variable @var{var} to @var{dir}/@var{file}, but
10214 optimizing the common cases (@var{dir} or @var{file} is @samp{.},
10215 @var{file} is absolute, etc.).
10216 @end defmac
10219 @node File Descriptor Macros
10220 @section File Descriptor Macros
10221 @cindex input
10222 @cindex standard input
10223 @cindex file descriptors
10224 @cindex descriptors
10225 @cindex low-level output
10226 @cindex output, low-level
10228 The following macros define file descriptors used to output messages
10229 (or input values) from @file{configure} scripts.
10230 For example:
10232 @example
10233 echo "$wombats found" >&AS_MESSAGE_LOG_FD
10234 echo 'Enter desired kangaroo count:' >&AS_MESSAGE_FD
10235 read kangaroos <&AS_ORIGINAL_STDIN_FD`
10236 @end example
10238 @noindent
10239 However doing so is seldom needed, because Autoconf provides higher
10240 level macros as described below.
10242 @defmac AS_MESSAGE_FD
10243 @asindex{MESSAGE_FD}
10244 The file descriptor for @samp{checking for...}  messages and results.
10245 Normally this directs messages to the standard output, however when
10246 @command{configure} is run with the @option{-q} option, messages sent to
10247 @code{AS_MESSAGE_FD} are discarded.
10249 If you want to display some messages, consider using one of the printing
10250 macros (@pxref{Printing Messages}) instead.  Copies of messages output
10251 via these macros are also recorded in @file{config.log}.
10252 @end defmac
10254 @defmac AS_MESSAGE_LOG_FD
10255 @asindex{MESSAGE_LOG_FD}
10257 The file descriptor for messages logged to @file{config.log}.  Macros
10258 that run tools, like @code{AC_COMPILE_IFELSE} (@pxref{Running the
10259 Compiler}), redirect all output to this descriptor.  You may want to do
10260 so if you develop such a low-level macro.
10261 @end defmac
10263 @defmac AS_ORIGINAL_STDIN_FD
10264 @asindex{ORIGINAL_STDIN_FD}
10265 The file descriptor for the original standard input.
10267 When @command{configure} runs, it may accidentally execute an
10268 interactive command that has the same name as the non-interactive meant
10269 to be used or checked.  If the standard input was the terminal, such
10270 interactive programs would cause @command{configure} to stop, pending
10271 some user input.  Therefore @command{configure} redirects its standard
10272 input from @file{/dev/null} during its initialization.  This is not
10273 normally a problem, since @command{configure} normally does not need
10274 user input.
10276 In the extreme case where your @file{configure} script really needs to
10277 obtain some values from the original standard input, you can read them
10278 explicitly from @code{AS_ORIGINAL_STDIN_FD}.
10279 @end defmac
10282 @c =================================================== Writing Autoconf Macros.
10284 @node Writing Autoconf Macros
10285 @chapter Writing Autoconf Macros
10287 When you write a feature test that could be applicable to more than one
10288 software package, the best thing to do is encapsulate it in a new macro.
10289 Here are some instructions and guidelines for writing Autoconf macros.
10291 @menu
10292 * Macro Definitions::           Basic format of an Autoconf macro
10293 * Macro Names::                 What to call your new macros
10294 * Reporting Messages::          Notifying @command{autoconf} users
10295 * Dependencies Between Macros::  What to do when macros depend on other macros
10296 * Obsoleting Macros::           Warning about old ways of doing things
10297 * Coding Style::                Writing Autoconf macros @`a la Autoconf
10298 @end menu
10300 @node Macro Definitions
10301 @section Macro Definitions
10303 @acindex{DEFUN}
10304 Autoconf macros are defined using the @code{AC_DEFUN} macro, which is
10305 similar to the M4 builtin @code{m4_define} macro.  In addition to
10306 defining a macro, @code{AC_DEFUN} adds to it some code that is used to
10307 constrain the order in which macros are called (@pxref{Prerequisite
10308 Macros}).
10310 An Autoconf macro definition looks like this:
10312 @example
10313 AC_DEFUN(@var{macro-name}, @var{macro-body})
10314 @end example
10316 You can refer to any arguments passed to the macro as @samp{$1},
10317 @samp{$2}, etc.  @xref{Definitions, , How to define new macros, m4.info,
10318 @acronym{GNU} M4}, for more complete information on writing M4 macros.
10320 Be sure to properly quote both the @var{macro-body} @emph{and} the
10321 @var{macro-name} to avoid any problems if the macro happens to have
10322 been previously defined.
10324 Each macro should have a header comment that gives its prototype, and a
10325 brief description.  When arguments have default values, display them in
10326 the prototype.  For example:
10328 @example
10329 # AC_MSG_ERROR(ERROR, [EXIT-STATUS = 1])
10330 # --------------------------------------
10331 m4_define([AC_MSG_ERROR],
10332   [@{ AS_MESSAGE([error: $1], [2])
10333      exit m4_default([$2], [1]); @}])
10334 @end example
10336 Comments about the macro should be left in the header comment.  Most
10337 other comments make their way into @file{configure}, so just keep
10338 using @samp{#} to introduce comments.
10340 @cindex @code{dnl}
10341 If you have some special comments about pure M4 code, comments
10342 that make no sense in @file{configure} and in the header comment, then
10343 use the builtin @code{dnl}: it causes M4 to discard the text
10344 through the next newline.
10346 Keep in mind that @code{dnl} is rarely needed to introduce comments;
10347 @code{dnl} is more useful to get rid of the newlines following macros
10348 that produce no output, such as @code{AC_REQUIRE}.
10351 @node Macro Names
10352 @section Macro Names
10354 All of the Autoconf macros have all-uppercase names starting with
10355 @samp{AC_} to prevent them from accidentally conflicting with other
10356 text.  All shell variables that they use for internal purposes have
10357 mostly-lowercase names starting with @samp{ac_}.  To ensure that your
10358 macros don't conflict with present or future Autoconf macros, you should
10359 prefix your own macro names and any shell variables they use with some
10360 other sequence.  Possibilities include your initials, or an abbreviation
10361 for the name of your organization or software package.
10363 Most of the Autoconf macros' names follow a structured naming convention
10364 that indicates the kind of feature check by the name.  The macro names
10365 consist of several words, separated by underscores, going from most
10366 general to most specific.  The names of their cache variables use the
10367 same convention (@pxref{Cache Variable Names}, for more information on
10368 them).
10370 The first word of the name after @samp{AC_} usually tells the category
10371 of the feature being tested.  Here are the categories used in Autoconf for
10372 specific test macros, the kind of macro that you are more likely to
10373 write.  They are also used for cache variables, in all-lowercase.  Use
10374 them where applicable; where they're not, invent your own categories.
10376 @table @code
10377 @item C
10378 C language builtin features.
10379 @item DECL
10380 Declarations of C variables in header files.
10381 @item FUNC
10382 Functions in libraries.
10383 @item GROUP
10384 Posix group owners of files.
10385 @item HEADER
10386 Header files.
10387 @item LIB
10388 C libraries.
10389 @item PATH
10390 Absolute names of files, including programs.
10391 @item PROG
10392 The base names of programs.
10393 @item MEMBER
10394 Members of aggregates.
10395 @item SYS
10396 Operating system features.
10397 @item TYPE
10398 C builtin or declared types.
10399 @item VAR
10400 C variables in libraries.
10401 @end table
10403 After the category comes the name of the particular feature being
10404 tested.  Any further words in the macro name indicate particular aspects
10405 of the feature.  For example, @code{AC_PROG_CC_STDC} checks whether the
10406 C compiler supports @acronym{ISO} Standard C.
10408 An internal macro should have a name that starts with an underscore;
10409 Autoconf internals should therefore start with @samp{_AC_}.
10410 Additionally, a macro that is an internal subroutine of another macro
10411 should have a name that starts with an underscore and the name of that
10412 other macro, followed by one or more words saying what the internal
10413 macro does.  For example, @code{AC_PATH_X} has internal macros
10414 @code{_AC_PATH_X_XMKMF} and @code{_AC_PATH_X_DIRECT}.
10416 @node Reporting Messages
10417 @section Reporting Messages
10418 @cindex Messages, from @command{autoconf}
10420 When macros statically diagnose abnormal situations, benign or fatal,
10421 they should report them using these macros.  For dynamic issues, i.e.,
10422 when @command{configure} is run, see @ref{Printing Messages}.
10424 @defmac AC_DIAGNOSE (@var{category}, @var{message})
10425 @acindex{DIAGNOSE}
10426 Report @var{message} as a warning (or as an error if requested by the
10427 user) if warnings of the @var{category} are turned on.  You are
10428 encouraged to use standard categories, which currently include:
10430 @table @samp
10431 @item all
10432 messages that don't fall into one of the following categories.  Use of an
10433 empty @var{category} is equivalent.
10435 @item cross
10436 related to cross compilation issues.
10438 @item obsolete
10439 use of an obsolete construct.
10441 @item syntax
10442 dubious syntactic constructs, incorrectly ordered macro calls.
10443 @end table
10444 @end defmac
10446 @defmac AC_WARNING (@var{message})
10447 @acindex{WARNING}
10448 Equivalent to @samp{AC_DIAGNOSE([syntax], @var{message})}, but you are
10449 strongly encouraged to use a finer grained category.
10450 @end defmac
10452 @defmac AC_FATAL (@var{message})
10453 @acindex{FATAL}
10454 Report a severe error @var{message}, and have @command{autoconf} die.
10455 @end defmac
10457 When the user runs @samp{autoconf -W error}, warnings from
10458 @code{AC_DIAGNOSE} and @code{AC_WARNING} are reported as error, see
10459 @ref{autoconf Invocation}.
10461 @node Dependencies Between Macros
10462 @section Dependencies Between Macros
10463 @cindex Dependencies between macros
10465 Some Autoconf macros depend on other macros having been called first in
10466 order to work correctly.  Autoconf provides a way to ensure that certain
10467 macros are called if needed and a way to warn the user if macros are
10468 called in an order that might cause incorrect operation.
10470 @menu
10471 * Prerequisite Macros::         Ensuring required information
10472 * Suggested Ordering::          Warning about possible ordering problems
10473 * One-Shot Macros::             Ensuring a macro is called only once
10474 @end menu
10476 @node Prerequisite Macros
10477 @subsection Prerequisite Macros
10478 @cindex Prerequisite macros
10479 @cindex Macros, prerequisites
10481 A macro that you write might need to use values that have previously
10482 been computed by other macros.  For example, @code{AC_DECL_YYTEXT}
10483 examines the output of @code{flex} or @code{lex}, so it depends on
10484 @code{AC_PROG_LEX} having been called first to set the shell variable
10485 @code{LEX}.
10487 Rather than forcing the user of the macros to keep track of the
10488 dependencies between them, you can use the @code{AC_REQUIRE} macro to do
10489 it automatically.  @code{AC_REQUIRE} can ensure that a macro is only
10490 called if it is needed, and only called once.
10492 @defmac AC_REQUIRE (@var{macro-name})
10493 @acindex{REQUIRE}
10494 If the M4 macro @var{macro-name} has not already been called, call it
10495 (without any arguments).  Make sure to quote @var{macro-name} with
10496 square brackets.  @var{macro-name} must have been defined using
10497 @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
10498 that it has been called.
10500 @code{AC_REQUIRE} must be used inside a macro defined by @code{AC_DEFUN}; it
10501 must not be called from the top level.
10502 @end defmac
10504 @code{AC_REQUIRE} is often misunderstood.  It really implements
10505 dependencies between macros in the sense that if one macro depends upon
10506 another, the latter is expanded @emph{before} the body of the
10507 former.  To be more precise, the required macro is expanded before
10508 the outermost defined macro in the current expansion stack.
10509 In particular, @samp{AC_REQUIRE([FOO])} is not replaced with the body of
10510 @code{FOO}.  For instance, this definition of macros:
10512 @example
10513 @group
10514 AC_DEFUN([TRAVOLTA],
10515 [test "$body_temperature_in_celsius" -gt "38" &&
10516   dance_floor=occupied])
10517 AC_DEFUN([NEWTON_JOHN],
10518 [test "$hair_style" = "curly" &&
10519   dance_floor=occupied])
10520 @end group
10522 @group
10523 AC_DEFUN([RESERVE_DANCE_FLOOR],
10524 [if date | grep '^Sat.*pm' >/dev/null 2>&1; then
10525   AC_REQUIRE([TRAVOLTA])
10526   AC_REQUIRE([NEWTON_JOHN])
10527 fi])
10528 @end group
10529 @end example
10531 @noindent
10532 with this @file{configure.ac}
10534 @example
10535 AC_INIT([Dance Manager], [1.0], [bug-dance@@example.org])
10536 RESERVE_DANCE_FLOOR
10537 if test "$dance_floor" = occupied; then
10538   AC_MSG_ERROR([cannot pick up here, let's move])
10540 @end example
10542 @noindent
10543 does not leave you with a better chance to meet a kindred soul at
10544 other times than Saturday night since it expands into:
10546 @example
10547 @group
10548 test "$body_temperature_in_Celsius" -gt "38" &&
10549   dance_floor=occupied
10550 test "$hair_style" = "curly" &&
10551   dance_floor=occupied
10553 if date | grep '^Sat.*pm' >/dev/null 2>&1; then
10557 @end group
10558 @end example
10560 This behavior was chosen on purpose: (i) it prevents messages in
10561 required macros from interrupting the messages in the requiring macros;
10562 (ii) it avoids bad surprises when shell conditionals are used, as in:
10564 @example
10565 @group
10566 if @dots{}; then
10567   AC_REQUIRE([SOME_CHECK])
10569 @dots{}
10570 SOME_CHECK
10571 @end group
10572 @end example
10574 The helper macros @code{AS_IF} and @code{AS_CASE} may be used to
10575 enforce expansion of required macros outside of shell conditional
10576 constructs.  You are furthermore encouraged to put all @code{AC_REQUIRE} calls
10577 at the beginning of a macro.  You can use @code{dnl} to avoid the empty
10578 lines they leave.
10580 @node Suggested Ordering
10581 @subsection Suggested Ordering
10582 @cindex Macros, ordering
10583 @cindex Ordering macros
10585 Some macros should be run before another macro if both are called, but
10586 neither @emph{requires} that the other be called.  For example, a macro
10587 that changes the behavior of the C compiler should be called before any
10588 macros that run the C compiler.  Many of these dependencies are noted in
10589 the documentation.
10591 Autoconf provides the @code{AC_BEFORE} macro to warn users when macros
10592 with this kind of dependency appear out of order in a
10593 @file{configure.ac} file.  The warning occurs when creating
10594 @command{configure} from @file{configure.ac}, not when running
10595 @command{configure}.
10597 For example, @code{AC_PROG_CPP} checks whether the C compiler
10598 can run the C preprocessor when given the @option{-E} option.  It should
10599 therefore be called after any macros that change which C compiler is
10600 being used, such as @code{AC_PROG_CC}.  So @code{AC_PROG_CC} contains:
10602 @example
10603 AC_BEFORE([$0], [AC_PROG_CPP])dnl
10604 @end example
10606 @noindent
10607 This warns the user if a call to @code{AC_PROG_CPP} has already occurred
10608 when @code{AC_PROG_CC} is called.
10610 @defmac AC_BEFORE (@var{this-macro-name}, @var{called-macro-name})
10611 @acindex{BEFORE}
10612 Make M4 print a warning message to the standard error output if
10613 @var{called-macro-name} has already been called.  @var{this-macro-name}
10614 should be the name of the macro that is calling @code{AC_BEFORE}.  The
10615 macro @var{called-macro-name} must have been defined using
10616 @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
10617 that it has been called.
10618 @end defmac
10620 @node One-Shot Macros
10621 @subsection One-Shot Macros
10622 @cindex One-shot macros
10623 @cindex Macros, called once
10625 Some macros should be called only once, either because calling them
10626 multiple time is unsafe, or because it is bad style.  For instance
10627 Autoconf ensures that @code{AC_CANONICAL_BUILD} and cousins
10628 (@pxref{Canonicalizing}) are evaluated only once, because it makes no
10629 sense to run these expensive checks more than once.  Such one-shot
10630 macros can be defined using @code{AC_DEFUN_ONCE}.
10632 @defmac AC_DEFUN_ONCE (@var{macro-name}, @var{macro-body})
10633 @acindex{DEFUN_ONCE}
10635 Declare macro @var{macro-name} like @code{AC_DEFUN} would (@pxref{Macro
10636 Definitions}), and emit a warning any time the macro is called more than
10637 once.
10638 @end defmac
10640 Obviously it is not sensible to evaluate a macro defined by
10641 @code{AC_DEFUN_ONCE} in a macro defined by @code{AC_DEFUN}.
10642 Most of the time you want to use @code{AC_REQUIRE} (@pxref{Prerequisite
10643 Macros}).
10645 @node Obsoleting Macros
10646 @section Obsoleting Macros
10647 @cindex Obsoleting macros
10648 @cindex Macros, obsoleting
10650 Configuration and portability technology has evolved over the years.
10651 Often better ways of solving a particular problem are developed, or
10652 ad-hoc approaches are systematized.  This process has occurred in many
10653 parts of Autoconf.  One result is that some of the macros are now
10654 considered @dfn{obsolete}; they still work, but are no longer considered
10655 the best thing to do, hence they should be replaced with more modern
10656 macros.  Ideally, @command{autoupdate} should replace the old macro calls
10657 with their modern implementation.
10659 Autoconf provides a simple means to obsolete a macro.
10661 @defmac AU_DEFUN (@var{old-macro}, @var{implementation}, @ovar{message})
10662 @auindex{DEFUN}
10663 Define @var{old-macro} as @var{implementation}.  The only difference
10664 with @code{AC_DEFUN} is that the user is warned that
10665 @var{old-macro} is now obsolete.
10667 If she then uses @command{autoupdate}, the call to @var{old-macro} is
10668 replaced by the modern @var{implementation}.  @var{message} should
10669 include information on what to do after running @command{autoupdate};
10670 @command{autoupdate} prints it as a warning, and includes it
10671 in the updated @file{configure.ac} file.
10673 The details of this macro are hairy: if @command{autoconf} encounters an
10674 @code{AU_DEFUN}ed macro, all macros inside its second argument are expanded
10675 as usual.  However, when @command{autoupdate} is run, only M4 and M4sugar
10676 macros are expanded here, while all other macros are disabled and
10677 appear literally in the updated @file{configure.ac}.
10678 @end defmac
10680 @defmac AU_ALIAS (@var{old-name}, @var{new-name})
10681 @auindex{ALIAS}
10682 Used if the @var{old-name} is to be replaced by a call to @var{new-macro}
10683 with the same parameters.  This happens for example if the macro was renamed.
10684 @end defmac
10686 @node Coding Style
10687 @section Coding Style
10688 @cindex Coding style
10690 The Autoconf macros follow a strict coding style.  You are encouraged to
10691 follow this style, especially if you intend to distribute your macro,
10692 either by contributing it to Autoconf itself, or via other means.
10694 The first requirement is to pay great attention to the quotation.  For
10695 more details, see @ref{Autoconf Language}, and @ref{M4 Quotation}.
10697 Do not try to invent new interfaces.  It is likely that there is a macro
10698 in Autoconf that resembles the macro you are defining: try to stick to
10699 this existing interface (order of arguments, default values, etc.).  We
10700 @emph{are} conscious that some of these interfaces are not perfect;
10701 nevertheless, when harmless, homogeneity should be preferred over
10702 creativity.
10704 Be careful about clashes both between M4 symbols and between shell
10705 variables.
10707 If you stick to the suggested M4 naming scheme (@pxref{Macro Names}),
10708 you are unlikely to generate conflicts.  Nevertheless, when you need to
10709 set a special value, @emph{avoid using a regular macro name}; rather,
10710 use an ``impossible'' name.  For instance, up to version 2.13, the macro
10711 @code{AC_SUBST} used to remember what @var{symbol} macros were already defined
10712 by setting @code{AC_SUBST_@var{symbol}}, which is a regular macro name.
10713 But since there is a macro named @code{AC_SUBST_FILE}, it was just
10714 impossible to @samp{AC_SUBST(FILE)}!  In this case,
10715 @code{AC_SUBST(@var{symbol})} or @code{_AC_SUBST(@var{symbol})} should
10716 have been used (yes, with the parentheses).
10717 @c or better yet, high-level macros such as @code{m4_expand_once}
10719 No Autoconf macro should ever enter the user-variable name space; i.e.,
10720 except for the variables that are the actual result of running the
10721 macro, all shell variables should start with @code{ac_}.  In
10722 addition, small macros or any macro that is likely to be embedded in
10723 other macros should be careful not to use obvious names.
10725 @cindex @code{dnl}
10726 Do not use @code{dnl} to introduce comments: most of the comments you
10727 are likely to write are either header comments which are not output
10728 anyway, or comments that should make their way into @file{configure}.
10729 There are exceptional cases where you do want to comment special M4
10730 constructs, in which case @code{dnl} is right, but keep in mind that it
10731 is unlikely.
10733 M4 ignores the leading blanks and newlines before each argument.
10734 Use this feature to
10735 indent in such a way that arguments are (more or less) aligned with the
10736 opening parenthesis of the macro being called.  For instance, instead of
10738 @example
10739 AC_CACHE_CHECK(for EMX OS/2 environment,
10740 ac_cv_emxos2,
10741 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __EMX__;])],
10742 [ac_cv_emxos2=yes], [ac_cv_emxos2=no])])
10743 @end example
10745 @noindent
10746 write
10748 @example
10749 AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
10750 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
10751                    [ac_cv_emxos2=yes],
10752                    [ac_cv_emxos2=no])])
10753 @end example
10755 @noindent
10756 or even
10758 @example
10759 AC_CACHE_CHECK([for EMX OS/2 environment],
10760                [ac_cv_emxos2],
10761                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
10762                                                    [return __EMX__;])],
10763                                   [ac_cv_emxos2=yes],
10764                                   [ac_cv_emxos2=no])])
10765 @end example
10767 When using @code{AC_RUN_IFELSE} or any macro that cannot work when
10768 cross-compiling, provide a pessimistic value (typically @samp{no}).
10770 Feel free to use various tricks to prevent auxiliary tools, such as
10771 syntax-highlighting editors, from behaving improperly.  For instance,
10772 instead of:
10774 @example
10775 m4_bpatsubst([$1], [$"])
10776 @end example
10778 @noindent
10781 @example
10782 m4_bpatsubst([$1], [$""])
10783 @end example
10785 @noindent
10786 so that Emacsen do not open an endless ``string'' at the first quote.
10787 For the same reasons, avoid:
10789 @example
10790 test $[#] != 0
10791 @end example
10793 @noindent
10794 and use:
10796 @example
10797 test $[@@%:@@] != 0
10798 @end example
10800 @noindent
10801 Otherwise, the closing bracket would be hidden inside a @samp{#}-comment,
10802 breaking the bracket-matching highlighting from Emacsen.  Note the
10803 preferred style to escape from M4: @samp{$[1]}, @samp{$[@@]}, etc.  Do
10804 not escape when it is unnecessary.  Common examples of useless quotation
10805 are @samp{[$]$1} (write @samp{$$1}), @samp{[$]var} (use @samp{$var}),
10806 etc.  If you add portability issues to the picture, you'll prefer
10807 @samp{$@{1+"$[@@]"@}} to @samp{"[$]@@"}, and you'll prefer do something
10808 better than hacking Autoconf @code{:-)}.
10810 When using @command{sed}, don't use @option{-e} except for indenting
10811 purposes.  With the @code{s} and @code{y} commands, the preferred
10812 separator is @samp{/} unless @samp{/} itself might appear in the pattern
10813 or replacement, in which case you should use @samp{|}, or optionally
10814 @samp{,} if you know the pattern and replacement cannot contain a file
10815 name.  If none of these characters will do, choose a printable character
10816 that cannot appear in the pattern or replacement.  Characters from the
10817 set @samp{"#$&'()*;<=>?`|~} are good choices if the pattern or
10818 replacement might contain a file name, since they have special meaning
10819 to the shell and are less likely to occur in file names.
10821 @xref{Macro Definitions}, for details on how to define a macro.  If a
10822 macro doesn't use @code{AC_REQUIRE}, is expected to never be the object
10823 of an @code{AC_REQUIRE} directive, and macros required by other macros
10824 inside arguments do not need to be expanded before this macro, then
10825 use @code{m4_define}.  In case of doubt, use @code{AC_DEFUN}.
10826 All the @code{AC_REQUIRE} statements should be at the beginning of the
10827 macro, and each statement should be followed by @code{dnl}.
10829 You should not rely on the number of arguments: instead of checking
10830 whether an argument is missing, test that it is not empty.  It provides
10831 both a simpler and a more predictable interface to the user, and saves
10832 room for further arguments.
10834 Unless the macro is short, try to leave the closing @samp{])} at the
10835 beginning of a line, followed by a comment that repeats the name of the
10836 macro being defined.  This introduces an additional newline in
10837 @command{configure}; normally, that is not a problem, but if you want to
10838 remove it you can use @samp{[]dnl} on the last line.  You can similarly
10839 use @samp{[]dnl} after a macro call to remove its newline.  @samp{[]dnl}
10840 is recommended instead of @samp{dnl} to ensure that M4 does not
10841 interpret the @samp{dnl} as being attached to the preceding text or
10842 macro output.  For example, instead of:
10844 @example
10845 AC_DEFUN([AC_PATH_X],
10846 [AC_MSG_CHECKING([for X])
10847 AC_REQUIRE_CPP()
10848 @r{# @dots{}omitted@dots{}}
10849   AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
10850 fi])
10851 @end example
10853 @noindent
10854 you would write:
10856 @example
10857 AC_DEFUN([AC_PATH_X],
10858 [AC_REQUIRE_CPP()[]dnl
10859 AC_MSG_CHECKING([for X])
10860 @r{# @dots{}omitted@dots{}}
10861   AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
10862 fi[]dnl
10863 ])# AC_PATH_X
10864 @end example
10866 If the macro is long, try to split it into logical chunks.  Typically,
10867 macros that check for a bug in a function and prepare its
10868 @code{AC_LIBOBJ} replacement should have an auxiliary macro to perform
10869 this setup.  Do not hesitate to introduce auxiliary macros to factor
10870 your code.
10872 In order to highlight the recommended coding style, here is a macro
10873 written the old way:
10875 @example
10876 dnl Check for EMX on OS/2.
10877 dnl _AC_EMXOS2
10878 AC_DEFUN(_AC_EMXOS2,
10879 [AC_CACHE_CHECK(for EMX OS/2 environment, ac_cv_emxos2,
10880 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return __EMX__;)],
10881 ac_cv_emxos2=yes, ac_cv_emxos2=no)])
10882 test "$ac_cv_emxos2" = yes && EMXOS2=yes])
10883 @end example
10885 @noindent
10886 and the new way:
10888 @example
10889 # _AC_EMXOS2
10890 # ----------
10891 # Check for EMX on OS/2.
10892 m4_define([_AC_EMXOS2],
10893 [AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
10894 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
10895                    [ac_cv_emxos2=yes],
10896                    [ac_cv_emxos2=no])])
10897 test "$ac_cv_emxos2" = yes && EMXOS2=yes[]dnl
10898 ])# _AC_EMXOS2
10899 @end example
10904 @c ============================================= Portable Shell Programming
10906 @node Portable Shell
10907 @chapter Portable Shell Programming
10908 @cindex Portable shell programming
10910 When writing your own checks, there are some shell-script programming
10911 techniques you should avoid in order to make your code portable.  The
10912 Bourne shell and upward-compatible shells like the Korn shell and Bash
10913 have evolved over the years, but to prevent trouble, do not take
10914 advantage of features that were added after Unix version 7, circa
10915 1977 (@pxref{Systemology}).
10917 You should not use shell functions, aliases, negated character
10918 classes, or other features that are not found in all Bourne-compatible
10919 shells; restrict yourself to the lowest common denominator.  Even
10920 @code{unset} is not supported by all shells!
10922 Some ancient systems have quite
10923 small limits on the length of the @samp{#!} line; for instance, 32
10924 bytes (not including the newline) on SunOS 4.
10925 A few ancient 4.2@acronym{BSD} based systems (such as Dynix circa 1984)
10926 required a single space between the @samp{#!} and the @samp{/}.
10927 However, these ancient systems are no longer of practical concern.
10929 The set of external programs you should run in a @command{configure} script
10930 is fairly small.  @xref{Utilities in Makefiles, , Utilities in
10931 Makefiles, standards, @acronym{GNU} Coding Standards}, for the list.  This
10932 restriction allows users to start out with a fairly small set of
10933 programs and build the rest, avoiding too many interdependencies between
10934 packages.
10936 Some of these external utilities have a portable subset of features; see
10937 @ref{Limitations of Usual Tools}.
10939 There are other sources of documentation about shells.  The
10940 specification for the Posix
10941 @uref{http://www.opengroup.org/@/susv3/@/utilities/@/xcu_chap02.html, Shell
10942 Command Language}, though more generous than the restrictive shell
10943 subset described above, is fairly portable nowadays.  Also please see
10944 @uref{http://www.faqs.org/@/faqs/@/unix-faq/@/shell/, the Shell FAQs}.
10946 @menu
10947 * Shellology::                  A zoology of shells
10948 * Here-Documents::              Quirks and tricks
10949 * File Descriptors::            FDs and redirections
10950 * File System Conventions::     File names
10951 * Shell Substitutions::         Variable and command expansions
10952 * Assignments::                 Varying side effects of assignments
10953 * Parentheses::                 Parentheses in shell scripts
10954 * Slashes::                     Slashes in shell scripts
10955 * Special Shell Variables::     Variables you should not change
10956 * Limitations of Builtins::     Portable use of not so portable /bin/sh
10957 * Limitations of Usual Tools::  Portable use of portable tools
10958 @end menu
10960 @node Shellology
10961 @section Shellology
10962 @cindex Shellology
10964 There are several families of shells, most prominently the Bourne family
10965 and the C shell family which are deeply incompatible.  If you want to
10966 write portable shell scripts, avoid members of the C shell family.  The
10967 @uref{http://www.faqs.org/@/faqs/@/unix-faq/@/shell/@/shell-differences/, the
10968 Shell difference FAQ} includes a small history of Posix shells, and a
10969 comparison between several of them.
10971 Below we describe some of the members of the Bourne shell family.
10973 @table @asis
10974 @item Ash
10975 @cindex Ash
10976 Ash is often used on @acronym{GNU}/Linux and @acronym{BSD}
10977 systems as a light-weight Bourne-compatible shell.  Ash 0.2 has some
10978 bugs that are fixed in the 0.3.x series, but portable shell scripts
10979 should work around them, since version 0.2 is still shipped with many
10980 @acronym{GNU}/Linux distributions.
10982 To be compatible with Ash 0.2:
10984 @itemize @minus
10985 @item
10986 don't use @samp{$?} after expanding empty or unset variables,
10987 or at the start of an @command{eval}:
10989 @example
10990 foo=
10991 false
10992 $foo
10993 echo "Do not use it: $?"
10994 false
10995 eval 'echo "Do not use it: $?"'
10996 @end example
10998 @item
10999 don't use command substitution within variable expansion:
11001 @example
11002 cat $@{FOO=`bar`@}
11003 @end example
11005 @item
11006 beware that single builtin substitutions are not performed by a
11007 subshell, hence their effect applies to the current shell!  @xref{Shell
11008 Substitutions}, item ``Command Substitution''.
11009 @end itemize
11011 @item Bash
11012 @cindex Bash
11013 To detect whether you are running Bash, test whether
11014 @code{BASH_VERSION} is set.  To require
11015 Posix compatibility, run @samp{set -o posix}.  @xref{Bash POSIX
11016 Mode, , Bash Posix Mode, bash, The @acronym{GNU} Bash Reference
11017 Manual}, for details.
11019 @item Bash 2.05 and later
11020 @cindex Bash 2.05 and later
11021 Versions 2.05 and later of Bash use a different format for the
11022 output of the @command{set} builtin, designed to make evaluating its
11023 output easier.  However, this output is not compatible with earlier
11024 versions of Bash (or with many other shells, probably).  So if
11025 you use Bash 2.05 or higher to execute @command{configure},
11026 you'll need to use Bash 2.05 for all other build tasks as well.
11028 @item Ksh
11029 @cindex Ksh
11030 @cindex Korn shell
11031 @prindex @samp{ksh}
11032 @prindex @samp{ksh88}
11033 @prindex @samp{ksh93}
11034 The Korn shell is compatible with the Bourne family and it mostly
11035 conforms to Posix.  It has two major variants commonly
11036 called @samp{ksh88} and @samp{ksh93}, named after the years of initial
11037 release.  It is usually called @command{ksh}, but is called @command{sh}
11038 on some hosts if you set your path appropriately.
11040 Solaris systems have three variants:
11041 @prindex @command{/usr/bin/ksh} on Solaris
11042 @command{/usr/bin/ksh} is @samp{ksh88}; it is
11043 standard on Solaris 2.0 and later.
11044 @prindex @command{/usr/xpg4/bin/sh} on Solaris
11045 @command{/usr/xpg4/bin/sh} is a Posix-compliant variant of
11046 @samp{ksh88}; it is standard on Solaris 9 and later.
11047 @prindex @command{/usr/dt/bin/dtksh} on Solaris
11048 @command{/usr/dt/bin/dtksh} is @samp{ksh93}.
11049 Variants that are not standard may be parts of optional
11050 packages.  There is no extra charge for these packages, but they are
11051 not part of a minimal OS install and therefore some installations may
11052 not have it.
11054 Starting with Tru64 Version 4.0, the Korn shell @command{/usr/bin/ksh}
11055 is also available as @command{/usr/bin/posix/sh}.  If the environment
11056 variable @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations of
11057 the standard shell conform to Posix.
11059 @item Pdksh
11060 @prindex @samp{pdksh}
11061 A public-domain clone of the Korn shell called @command{pdksh} is widely
11062 available: it has most of the @samp{ksh88} features along with a few of
11063 its own.  It usually sets @code{KSH_VERSION}, except if invoked as
11064 @command{/bin/sh} on Open@acronym{BSD}, and similarly to Bash you can require
11065 Posix compatibility by running @samp{set -o posix}.  Unfortunately, with
11066 @command{pdksh} 5.2.14 (the latest stable version as of January 2007)
11067 Posix mode is buggy and causes @command{pdksh} to depart from Posix in
11068 at least one respect:
11070 @example
11071 $ @kbd{echo "`echo \"hello\"`"}
11072 hello
11073 $ @kbd{set -o posix}
11074 $ @kbd{echo "`echo \"hello\"`"}
11075 "hello"
11076 @end example
11078 The last line of output contains spurious quotes.  This is yet another
11079 reason why portable shell code should not contain
11080 @code{"`@dots{}\"@dots{}\"@dots{}`"} constructs (@pxref{Shell
11081 Substitutions}).
11083 @item Zsh
11084 @cindex Zsh
11085 To detect whether you are running @command{zsh}, test whether
11086 @code{ZSH_VERSION} is set.  By default @command{zsh} is @emph{not}
11087 compatible with the Bourne shell: you must execute @samp{emulate sh},
11088 and for @command{zsh} versions before 3.1.6-dev-18 you must also
11089 set @code{NULLCMD} to @samp{:}.  @xref{Compatibility, , Compatibility,
11090 zsh, The Z Shell Manual}, for details.
11092 The default Mac OS X @command{sh} was originally Zsh; it was changed to
11093 Bash in Mac OS X 10.2.
11094 @end table
11096 The following discussion between Russ Allbery and Robert Lipe is worth
11097 reading:
11099 @noindent
11100 Russ Allbery:
11102 @quotation
11103 The @acronym{GNU} assumption that @command{/bin/sh} is the one and only shell
11104 leads to a permanent deadlock.  Vendors don't want to break users'
11105 existing shell scripts, and there are some corner cases in the Bourne
11106 shell that are not completely compatible with a Posix shell.  Thus,
11107 vendors who have taken this route will @emph{never} (OK@dots{}``never say
11108 never'') replace the Bourne shell (as @command{/bin/sh}) with a
11109 Posix shell.
11110 @end quotation
11112 @noindent
11113 Robert Lipe:
11115 @quotation
11116 This is exactly the problem.  While most (at least most System V's) do
11117 have a Bourne shell that accepts shell functions most vendor
11118 @command{/bin/sh} programs are not the Posix shell.
11120 So while most modern systems do have a shell @emph{somewhere} that meets the
11121 Posix standard, the challenge is to find it.
11122 @end quotation
11124 @node Here-Documents
11125 @section Here-Documents
11126 @cindex Here-documents
11127 @cindex Shell here-documents
11129 Don't rely on @samp{\} being preserved just because it has no special
11130 meaning together with the next symbol.  In the native @command{sh}
11131 on Open@acronym{BSD} 2.7 @samp{\"} expands to @samp{"} in here-documents with
11132 unquoted delimiter.  As a general rule, if @samp{\\} expands to @samp{\}
11133 use @samp{\\} to get @samp{\}.
11135 With Open@acronym{BSD} 2.7's @command{sh}
11137 @example
11138 @group
11139 $ @kbd{cat <<EOF
11140 > \" \\
11141 > EOF}
11142 " \
11143 @end group
11144 @end example
11146 @noindent
11147 and with Bash:
11149 @example
11150 @group
11151 bash-2.04$ @kbd{cat <<EOF
11152 > \" \\
11153 > EOF}
11154 \" \
11155 @end group
11156 @end example
11158 Some shells mishandle large here-documents: for example,
11159 Solaris 10 @command{dtksh} and the UnixWare 7.1.1 Posix shell, which are
11160 derived from Korn shell version M-12/28/93d, mishandle braced variable
11161 expansion that crosses a 1024- or 4096-byte buffer boundary
11162 within a here-document.  Only the part of the variable name after the boundary
11163 is used.  For example, @code{$@{variable@}} could be replaced by the expansion
11164 of @code{$@{ble@}}.  If the end of the variable name is aligned with the block
11165 boundary, the shell reports an error, as if you used @code{$@{@}}.
11166 Instead of @code{$@{variable-default@}}, the shell may expand
11167 @code{$@{riable-default@}}, or even @code{$@{fault@}}.  This bug can often
11168 be worked around by omitting the braces: @code{$variable}.  The bug was fixed in
11169 @samp{ksh93g} (1998-04-30) but as of 2006 many operating systems were
11170 still shipping older versions with the bug.
11172 Many older shells (including the Bourne shell) implement here-documents
11173 inefficiently.  In particular, some shells can be extremely inefficient when
11174 a single statement contains many here-documents.  For instance if your
11175 @file{configure.ac} includes something like:
11177 @example
11178 @group
11179 if <cross_compiling>; then
11180   assume this and that
11181 else
11182   check this
11183   check that
11184   check something else
11185   @dots{}
11186   on and on forever
11187   @dots{}
11189 @end group
11190 @end example
11192 A shell parses the whole @code{if}/@code{fi} construct, creating
11193 temporary files for each here-document in it.  Some shells create links
11194 for such here-documents on every @code{fork}, so that the clean-up code
11195 they had installed correctly removes them.  It is creating the links
11196 that can take the shell forever.
11198 Moving the tests out of the @code{if}/@code{fi}, or creating multiple
11199 @code{if}/@code{fi} constructs, would improve the performance
11200 significantly.  Anyway, this kind of construct is not exactly the
11201 typical use of Autoconf.  In fact, it's even not recommended, because M4
11202 macros can't look into shell conditionals, so we may fail to expand a
11203 macro when it was expanded before in a conditional path, and the
11204 condition turned out to be false at runtime, and we end up not
11205 executing the macro at all.
11207 @node File Descriptors
11208 @section File Descriptors
11209 @cindex Descriptors
11210 @cindex File descriptors
11211 @cindex Shell file descriptors
11213 Most shells, if not all (including Bash, Zsh, Ash), output traces on
11214 stderr, even for subshells.  This might result in undesirable content
11215 if you meant to capture the standard-error output of the inner command:
11217 @example
11218 $ @kbd{ash -x -c '(eval "echo foo >&2") 2>stderr'}
11219 $ @kbd{cat stderr}
11220 + eval echo foo >&2
11221 + echo foo
11223 $ @kbd{bash -x -c '(eval "echo foo >&2") 2>stderr'}
11224 $ @kbd{cat stderr}
11225 + eval 'echo foo >&2'
11226 ++ echo foo
11228 $ @kbd{zsh -x -c '(eval "echo foo >&2") 2>stderr'}
11229 @i{# Traces on startup files deleted here.}
11230 $ @kbd{cat stderr}
11231 +zsh:1> eval echo foo >&2
11232 +zsh:1> echo foo
11234 @end example
11236 @noindent
11237 One workaround is to grep out uninteresting lines, hoping not to remove
11238 good ones.
11240 If you intend to redirect both standard error and standard output,
11241 redirect standard output first.  This works better with @acronym{HP-UX},
11242 since its shell mishandles tracing if standard error is redirected
11243 first:
11245 @example
11246 $ @kbd{sh -x -c ': 2>err >out'}
11247 + :
11248 + 2> err $ @kbd{cat err}
11249 1> out
11250 @end example
11252 Don't try to redirect the standard error of a command substitution.  It
11253 must be done @emph{inside} the command substitution.  When running
11254 @samp{: `cd /zorglub` 2>/dev/null} expect the error message to
11255 escape, while @samp{: `cd /zorglub 2>/dev/null`} works properly.
11257 It is worth noting that Zsh (but not Ash nor Bash) makes it possible
11258 in assignments though: @samp{foo=`cd /zorglub` 2>/dev/null}.
11260 Don't redirect the same file descriptor several times, as you are doomed
11261 to failure under Ultrix.
11263 @example
11264 ULTRIX V4.4 (Rev. 69) System #31: Thu Aug 10 19:42:23 GMT 1995
11265 UWS V4.4 (Rev. 11)
11266 $ @kbd{eval 'echo matter >fullness' >void}
11267 illegal io
11268 $ @kbd{eval '(echo matter >fullness)' >void}
11269 illegal io
11270 $ @kbd{(eval '(echo matter >fullness)') >void}
11271 Ambiguous output redirect.
11272 @end example
11274 @noindent
11275 In each case the expected result is of course @file{fullness} containing
11276 @samp{matter} and @file{void} being empty.
11278 Don't rely on file descriptors 0, 1, and 2 remaining closed in a
11279 subsidiary program.  If any of these descriptors is closed, the
11280 operating system may open an unspecified file for the descriptor in the
11281 new process image.  Posix says this may be done only if the subsidiary
11282 program is set-user-ID or set-group-ID, but @acronym{HP-UX} 11.23 does it even for
11283 ordinary programs.
11285 Don't rely on open file descriptors being open in child processes.  In
11286 @command{ksh}, file descriptors above 2 which are opened using
11287 @samp{exec @var{n}>file} are closed by a subsequent @samp{exec} (such as
11288 that involved in the fork-and-exec which runs a program or script).
11289 Thus, using @command{sh}, we have:
11291 @example
11292 $ @kbd{cat ./descrips}
11293 #!/bin/sh -
11294 echo hello >&5
11295 $ @kbd{exec 5>t}
11296 $ @kbd{./descrips}
11297 $ @kbd{cat t}
11299 hello
11300 @end example
11302 @noindent
11303 But using ksh:
11305 @example
11306 $ @kbd{exec 5>t}
11307 $ @kbd{./descrips}
11308 hello
11309 $ @kbd{cat t}
11311 @end example
11313 @noindent
11314 Within the process which runs the @samp{descrips} script, file
11315 descriptor 5 is closed.
11317 @acronym{DOS} variants cannot rename or remove open files, such as in
11318 @samp{mv foo bar >foo} or @samp{rm foo >foo}, even though this is
11319 perfectly portable among Posix hosts.
11321 A few ancient systems reserved some file descriptors.  By convention,
11322 file descriptor 3 was opened to @file{/dev/tty} when you logged into
11323 Eighth Edition (1985) through Tenth Edition Unix (1989).  File
11324 descriptor 4 had a special use on the Stardent/Kubota Titan (circa
11325 1990), though we don't now remember what it was.  Both these systems are
11326 obsolete, so it's now safe to treat file descriptors 3 and 4 like any
11327 other file descriptors.
11329 @node File System Conventions
11330 @section File System Conventions
11331 @cindex File system conventions
11333 Autoconf uses shell-script processing extensively, so the file names
11334 that it processes should not contain characters that are special to the
11335 shell.  Special characters include space, tab, newline, @sc{nul}, and
11336 the following:
11338 @example
11339 " # $ & ' ( ) * ; < = > ? [ \ ` |
11340 @end example
11342 Also, file names should not begin with @samp{~} or @samp{-}, and should
11343 contain neither @samp{-} immediately after @samp{/} nor @samp{~}
11344 immediately after @samp{:}.  On Posix-like platforms, directory names
11345 should not contain @samp{:}, as this runs afoul of @samp{:} used as the
11346 path separator.
11348 These restrictions apply not only to the files that you distribute, but
11349 also to the absolute file names of your source, build, and destination
11350 directories.
11352 On some Posix-like platforms, @samp{!} and @samp{^} are special too, so
11353 they should be avoided.
11355 Posix lets implementations treat leading @file{//} specially, but
11356 requires leading @file{///} and beyond to be equivalent to @file{/}.
11357 Most Unix variants treat @file{//} like @file{/}.  However, some treat
11358 @file{//} as a ``super-root'' that can provide access to files that are
11359 not otherwise reachable from @file{/}.  The super-root tradition began
11360 with Apollo Domain/OS, which died out long ago, but unfortunately Cygwin
11361 has revived it.
11363 While @command{autoconf} and friends are usually run on some Posix
11364 variety, they can be used on other systems, most notably @acronym{DOS}
11365 variants.  This impacts several assumptions regarding file names.
11367 @noindent
11368 For example, the following code:
11370 @example
11371 case $foo_dir in
11372   /*) # Absolute
11373      ;;
11374   *)
11375      foo_dir=$dots$foo_dir ;;
11376 esac
11377 @end example
11379 @noindent
11380 fails to properly detect absolute file names on those systems, because
11381 they can use a drivespec, and usually use a backslash as directory
11382 separator.  If you want to be portable to @acronym{DOS} variants (at the
11383 price of rejecting valid but oddball Posix file names like @file{a:\b}),
11384 you can check for absolute file names like this:
11386 @example
11387 case $foo_dir in
11388   [\\/]* | ?:[\\/]* ) # Absolute
11389      ;;
11390   *)
11391      foo_dir=$dots$foo_dir ;;
11392 esac
11393 @end example
11395 @noindent
11396 Make sure you quote the brackets if appropriate and keep the backslash as
11397 first character (@pxref{Limitations of Builtins}).
11399 Also, because the colon is used as part of a drivespec, these systems don't
11400 use it as path separator.  When creating or accessing paths, you can use the
11401 @code{PATH_SEPARATOR} output variable instead.  @command{configure} sets this
11402 to the appropriate value for the build system (@samp{:} or @samp{;}) when it
11403 starts up.
11405 File names need extra care as well.  While @acronym{DOS} variants
11406 that are Posixy enough to run @command{autoconf} (such as @acronym{DJGPP})
11407 are usually able to handle long file names properly, there are still
11408 limitations that can seriously break packages.  Several of these issues
11409 can be easily detected by the
11410 @uref{ftp://ftp.gnu.org/gnu/non-gnu/doschk/doschk-1.1.tar.gz, doschk}
11411 package.
11413 A short overview follows; problems are marked with @sc{sfn}/@sc{lfn} to
11414 indicate where they apply: @sc{sfn} means the issues are only relevant to
11415 plain @acronym{DOS}, not to @acronym{DOS} under Microsoft Windows
11416 variants, while @sc{lfn} identifies problems that exist even under
11417 Microsoft Windows variants.
11419 @table @asis
11420 @item No multiple dots (@sc{sfn})
11421 @acronym{DOS} cannot handle multiple dots in file names.  This is an especially
11422 important thing to remember when building a portable configure script,
11423 as @command{autoconf} uses a .in suffix for template files.
11425 This is perfectly OK on Posix variants:
11427 @example
11428 AC_CONFIG_HEADERS([config.h])
11429 AC_CONFIG_FILES([source.c foo.bar])
11430 AC_OUTPUT
11431 @end example
11433 @noindent
11434 but it causes problems on @acronym{DOS}, as it requires @samp{config.h.in},
11435 @samp{source.c.in} and @samp{foo.bar.in}.  To make your package more portable
11436 to @acronym{DOS}-based environments, you should use this instead:
11438 @example
11439 AC_CONFIG_HEADERS([config.h:config.hin])
11440 AC_CONFIG_FILES([source.c:source.cin foo.bar:foobar.in])
11441 AC_OUTPUT
11442 @end example
11444 @item No leading dot (@sc{sfn})
11445 @acronym{DOS} cannot handle file names that start with a dot.  This is usually
11446 not important for @command{autoconf}.
11448 @item Case insensitivity (@sc{lfn})
11449 @acronym{DOS} is case insensitive, so you cannot, for example, have both a
11450 file called @samp{INSTALL} and a directory called @samp{install}.  This
11451 also affects @command{make}; if there's a file called @samp{INSTALL} in
11452 the directory, @samp{make install} does nothing (unless the
11453 @samp{install} target is marked as PHONY).
11455 @item The 8+3 limit (@sc{sfn})
11456 Because the @acronym{DOS} file system only stores the first 8 characters of
11457 the file name and the first 3 of the extension, those must be unique.
11458 That means that @file{foobar-part1.c}, @file{foobar-part2.c} and
11459 @file{foobar-prettybird.c} all resolve to the same file name
11460 (@file{FOOBAR-P.C}).  The same goes for @file{foo.bar} and
11461 @file{foo.bartender}.
11463 The 8+3 limit is not usually a problem under Microsoft Windows, as it
11464 uses numeric
11465 tails in the short version of file names to make them unique.  However, a
11466 registry setting can turn this behavior off.  While this makes it
11467 possible to share file trees containing long file names between @sc{sfn}
11468 and @sc{lfn} environments, it also means the above problem applies there
11469 as well.
11471 @item Invalid characters (@sc{lfn})
11472 Some characters are invalid in @acronym{DOS} file names, and should therefore
11473 be avoided.  In a @sc{lfn} environment, these are @samp{/}, @samp{\},
11474 @samp{?}, @samp{*}, @samp{:}, @samp{<}, @samp{>}, @samp{|} and @samp{"}.
11475 In a @sc{sfn} environment, other characters are also invalid.  These
11476 include @samp{+}, @samp{,}, @samp{[} and @samp{]}.
11478 @item Invalid names (@sc{lfn})
11479 Some @acronym{DOS} file names are reserved, and cause problems if you
11480 try to use files with those names.  These names include @file{CON},
11481 @file{AUX}, @file{COM1}, @file{COM2}, @file{COM3}, @file{COM4},
11482 @file{LPT1}, @file{LPT2}, @file{LPT3}, @file{NUL}, and @file{PRN}.
11483 File names are case insensitive, so even names like
11484 @file{aux/config.guess} are disallowed.
11486 @end table
11488 @node Shell Substitutions
11489 @section Shell Substitutions
11490 @cindex Shell substitutions
11492 Contrary to a persistent urban legend, the Bourne shell does not
11493 systematically split variables and back-quoted expressions, in particular
11494 on the right-hand side of assignments and in the argument of @code{case}.
11495 For instance, the following code:
11497 @example
11498 case "$given_srcdir" in
11499 .)  top_srcdir="`echo "$dots" | sed 's,/$,,'`" ;;
11500 *)  top_srcdir="$dots$given_srcdir" ;;
11501 esac
11502 @end example
11504 @noindent
11505 is more readable when written as:
11507 @example
11508 case $given_srcdir in
11509 .)  top_srcdir=`echo "$dots" | sed 's,/$,,'` ;;
11510 *)  top_srcdir=$dots$given_srcdir ;;
11511 esac
11512 @end example
11514 @noindent
11515 and in fact it is even @emph{more} portable: in the first case of the
11516 first attempt, the computation of @code{top_srcdir} is not portable,
11517 since not all shells properly understand @code{"`@dots{}"@dots{}"@dots{}`"}.
11518 Worse yet, not all shells understand @code{"`@dots{}\"@dots{}\"@dots{}`"}
11519 the same way.  There is just no portable way to use double-quoted
11520 strings inside double-quoted back-quoted expressions (pfew!).
11522 @table @code
11523 @item $@@
11524 @cindex @samp{"$@@"}
11525 One of the most famous shell-portability issues is related to
11526 @samp{"$@@"}.  When there are no positional arguments, Posix says
11527 that @samp{"$@@"} is supposed to be equivalent to nothing, but the
11528 original Unix version 7 Bourne shell treated it as equivalent to
11529 @samp{""} instead, and this behavior survives in later implementations
11530 like Digital Unix 5.0.
11532 The traditional way to work around this portability problem is to use
11533 @samp{$@{1+"$@@"@}}.  Unfortunately this method does not work with
11534 Zsh (3.x and 4.x), which is used on Mac OS X@.  When emulating
11535 the Bourne shell, Zsh performs word splitting on @samp{$@{1+"$@@"@}}:
11537 @example
11538 zsh $ @kbd{emulate sh}
11539 zsh $ @kbd{for i in "$@@"; do echo $i; done}
11540 Hello World
11542 zsh $ @kbd{for i in $@{1+"$@@"@}; do echo $i; done}
11543 Hello
11544 World
11546 @end example
11548 @noindent
11549 Zsh handles plain @samp{"$@@"} properly, but we can't use plain
11550 @samp{"$@@"} because of the portability problems mentioned above.
11551 One workaround relies on Zsh's ``global aliases'' to convert
11552 @samp{$@{1+"$@@"@}} into @samp{"$@@"} by itself:
11554 @example
11555 test "$@{ZSH_VERSION+set@}" = set && alias -g '$@{1+"$@@"@}'='"$@@"'
11556 @end example
11558 A more conservative workaround is to avoid @samp{"$@@"} if it is
11559 possible that there may be no positional arguments.  For example,
11560 instead of:
11562 @example
11563 cat conftest.c "$@@"
11564 @end example
11566 you can use this instead:
11568 @example
11569 case $# in
11570 0) cat conftest.c;;
11571 *) cat conftest.c "$@@";;
11572 esac
11573 @end example
11575 Autoconf macros often use the @command{set} command to update
11576 @samp{$@@}, so if you are writing shell code intended for
11577 @command{configure} you should not assume that the value of @samp{$@@}
11578 persists for any length of time.
11581 @item $@{10@}
11582 @cindex positional parameters
11583 The 10th, 11th, @dots{} positional parameters can be accessed only after
11584 a @code{shift}.  The 7th Edition shell reported an error if given
11585 @code{$@{10@}}, and
11586 Solaris 10 @command{/bin/sh} still acts that way:
11588 @example
11589 $ @kbd{set 1 2 3 4 5 6 7 8 9 10}
11590 $ @kbd{echo $@{10@}}
11591 bad substitution
11592 @end example
11594 @item $@{@var{var}:-@var{value}@}
11595 @c Info cannot handle `:' in index entries.
11596 @c @cindex $@{@var{var}:-@var{value}@}
11597 Old @acronym{BSD} shells, including the Ultrix @code{sh}, don't accept the
11598 colon for any shell substitution, and complain and die.
11599 Similarly for $@{@var{var}:=@var{value}@}, $@{@var{var}:?@var{value}@}, etc.
11601 @item $@{@var{var}=@var{literal}@}
11602 @cindex $@{@var{var}=@var{literal}@}
11603 Be sure to quote:
11605 @example
11606 : $@{var='Some words'@}
11607 @end example
11609 @noindent
11610 otherwise some shells, such as on Digital Unix V 5.0, die because
11611 of a ``bad substitution''.
11613 @sp 1
11615 Solaris @command{/bin/sh} has a frightening bug in its interpretation
11616 of this.  Imagine you need set a variable to a string containing
11617 @samp{@}}.  This @samp{@}} character confuses Solaris @command{/bin/sh}
11618 when the affected variable was already set.  This bug can be exercised
11619 by running:
11621 @example
11622 $ @kbd{unset foo}
11623 $ @kbd{foo=$@{foo='@}'@}}
11624 $ @kbd{echo $foo}
11626 $ @kbd{foo=$@{foo='@}'   # no error; this hints to what the bug is}
11627 $ @kbd{echo $foo}
11629 $ @kbd{foo=$@{foo='@}'@}}
11630 $ @kbd{echo $foo}
11631 @}@}
11632  ^ ugh!
11633 @end example
11635 It seems that @samp{@}} is interpreted as matching @samp{$@{}, even
11636 though it is enclosed in single quotes.  The problem doesn't happen
11637 using double quotes.
11639 @item $@{@var{var}=@var{expanded-value}@}
11640 @cindex $@{@var{var}=@var{expanded-value}@}
11641 On Ultrix,
11642 running
11644 @example
11645 default="yu,yaa"
11646 : $@{var="$default"@}
11647 @end example
11649 @noindent
11650 sets @var{var} to @samp{M-yM-uM-,M-yM-aM-a}, i.e., the 8th bit of
11651 each char is set.  You don't observe the phenomenon using a simple
11652 @samp{echo $var} since apparently the shell resets the 8th bit when it
11653 expands $var.  Here are two means to make this shell confess its sins:
11655 @example
11656 $ @kbd{cat -v <<EOF
11657 $var
11658 EOF}
11659 @end example
11661 @noindent
11664 @example
11665 $ @kbd{set | grep '^var=' | cat -v}
11666 @end example
11668 One classic incarnation of this bug is:
11670 @example
11671 default="a b c"
11672 : $@{list="$default"@}
11673 for c in $list; do
11674   echo $c
11675 done
11676 @end example
11678 @noindent
11679 You'll get @samp{a b c} on a single line.  Why?  Because there are no
11680 spaces in @samp{$list}: there are @samp{M- }, i.e., spaces with the 8th
11681 bit set, hence no IFS splitting is performed!!!
11683 One piece of good news is that Ultrix works fine with @samp{:
11684 $@{list=$default@}}; i.e., if you @emph{don't} quote.  The bad news is
11685 then that @acronym{QNX} 4.25 then sets @var{list} to the @emph{last} item of
11686 @var{default}!
11688 The portable way out consists in using a double assignment, to switch
11689 the 8th bit twice on Ultrix:
11691 @example
11692 list=$@{list="$default"@}
11693 @end example
11695 @noindent
11696 @dots{}but beware of the @samp{@}} bug from Solaris (see above).  For safety,
11697 use:
11699 @example
11700 test "$@{var+set@}" = set || var=@var{@{value@}}
11701 @end example
11703 @item $@{#@var{var}@}
11704 @itemx $@{@var{var}%@var{word}@}
11705 @itemx $@{@var{var}%%@var{word}@}
11706 @itemx $@{@var{var}#@var{word}@}
11707 @itemx $@{@var{var}##@var{word}@}
11708 @cindex $@{#@var{var}@}
11709 @cindex $@{@var{var}%@var{word}@}
11710 @cindex $@{@var{var}%%@var{word}@}
11711 @cindex $@{@var{var}#@var{word}@}
11712 @cindex $@{@var{var}##@var{word}@}
11713 Posix requires support for these usages, but they do not work with many
11714 traditional shells, e.g., Solaris 10 @command{/bin/sh}.
11716 Also, @command{pdksh} 5.2.14 mishandles some @var{word} forms.  For
11717 example if @samp{$1} is @samp{a/b} and @samp{$2} is @samp{a}, then
11718 @samp{$@{1#$2@}} should yield @samp{/b}, but with @command{pdksh} it
11719 yields the empty string.
11722 @item `@var{commands}`
11723 @cindex `@var{commands}`
11724 @cindex Command Substitution
11725 Posix requires shells to trim all trailing newlines from command
11726 output before substituting it, so assignments like
11727 @samp{dir=`echo "$file" | tr a A`} do not work as expected if
11728 @samp{$file} ends in a newline.
11730 While in general it makes no sense, do not substitute a single builtin
11731 with side effects, because Ash 0.2, trying to optimize, does not fork a
11732 subshell to perform the command.
11734 For instance, if you wanted to check that @command{cd} is silent, do not
11735 use @samp{test -z "`cd /`"} because the following can happen:
11737 @example
11738 $ @kbd{pwd}
11739 /tmp
11740 $ @kbd{test -z "`cd /`" && pwd}
11742 @end example
11744 @noindent
11745 The result of @samp{foo=`exit 1`} is left as an exercise to the reader.
11747 The MSYS shell leaves a stray byte in the expansion of a double-quoted
11748 command substitution of a native program, if the end of the substitution
11749 is not aligned with the end of the double quote.  This may be worked
11750 around by inserting another pair of quotes:
11752 @example
11753 $ @kbd{echo "`printf 'foo\r\n'` bar" > broken}
11754 $ @kbd{echo "`printf 'foo\r\n'`"" bar" | cmp - broken}
11755 - broken differ: char 4, line 1
11756 @end example
11759 @item $(@var{commands})
11760 @cindex $(@var{commands})
11761 This construct is meant to replace @samp{`@var{commands}`},
11762 and it has most of the problems listed under @code{`@var{commands}`}.
11764 This construct can be
11765 nested while this is impossible to do portably with back quotes.
11766 Unfortunately it is not yet universally supported.  Most notably, even recent
11767 releases of Solaris don't support it:
11769 @example
11770 $ @kbd{showrev -c /bin/sh | grep version}
11771 Command version: SunOS 5.10 Generic 121005-03 Oct 2006
11772 $ @kbd{echo $(echo blah)}
11773 syntax error: `(' unexpected
11774 @end example
11776 @noindent
11777 nor does @sc{irix} 6.5's Bourne shell:
11778 @example
11779 $ @kbd{uname -a}
11780 IRIX firebird-image 6.5 07151432 IP22
11781 $ @kbd{echo $(echo blah)}
11782 $(echo blah)
11783 @end example
11785 If you do use @samp{$(@var{commands})}, make sure that the commands
11786 do not start with a parenthesis, as that would cause confusion with
11787 a different notation @samp{$((@var{expression}))} that in modern
11788 shells is an arithmetic expression not a command.  To avoid the
11789 confusion, insert a space between the two opening parentheses.
11791 Avoid @var{commands} that contain unbalanced parentheses in
11792 here-documents, comments, or case statement patterns, as many shells
11793 mishandle them.  For example, Bash 3.1, @samp{ksh88}, @command{pdksh}
11794 5.2.14, and Zsh 4.2.6 all mishandle the following valid command:
11796 @example
11797 echo $(case x in x) echo hello;; esac)
11798 @end example
11800 @item ^
11801 @cindex ^ quoting
11802 Always quote @samp{^}, otherwise traditional shells such as
11803 @command{/bin/sh} on Solaris 10 treat this like @samp{|}.
11805 @end table
11808 @node Assignments
11809 @section Assignments
11810 @cindex Shell assignments
11812 When setting several variables in a row, be aware that the order of the
11813 evaluation is undefined.  For instance @samp{foo=1 foo=2; echo $foo}
11814 gives @samp{1} with Solaris @command{/bin/sh}, but @samp{2} with Bash.
11815 You must use
11816 @samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}.
11818 Don't rely on the following to find @file{subdir/program}:
11820 @example
11821 PATH=subdir$PATH_SEPARATOR$PATH program
11822 @end example
11824 @noindent
11825 as this does not work with Zsh 3.0.6.  Use something like this
11826 instead:
11828 @example
11829 (PATH=subdir$PATH_SEPARATOR$PATH; export PATH; exec program)
11830 @end example
11832 Don't rely on the exit status of an assignment: Ash 0.2 does not change
11833 the status and propagates that of the last statement:
11835 @example
11836 $ @kbd{false || foo=bar; echo $?}
11838 $ @kbd{false || foo=`:`; echo $?}
11840 @end example
11842 @noindent
11843 and to make things even worse, @acronym{QNX} 4.25 just sets the exit status
11844 to 0 in any case:
11846 @example
11847 $ @kbd{foo=`exit 1`; echo $?}
11849 @end example
11851 To assign default values, follow this algorithm:
11853 @enumerate
11854 @item
11855 If the default value is a literal and does not contain any closing
11856 brace, use:
11858 @example
11859 : $@{var='my literal'@}
11860 @end example
11862 @item
11863 If the default value contains no closing brace, has to be expanded, and
11864 the variable being initialized is not intended to be IFS-split
11865 (i.e., it's not a list), then use:
11867 @example
11868 : $@{var="$default"@}
11869 @end example
11871 @item
11872 If the default value contains no closing brace, has to be expanded, and
11873 the variable being initialized is intended to be IFS-split (i.e., it's a list),
11874 then use:
11876 @example
11877 var=$@{var="$default"@}
11878 @end example
11880 @item
11881 If the default value contains a closing brace, then use:
11883 @example
11884 test "$@{var+set@}" = set || var="has a '@}'"
11885 @end example
11886 @end enumerate
11888 In most cases @samp{var=$@{var="$default"@}} is fine, but in case of
11889 doubt, just use the last form.  @xref{Shell Substitutions}, items
11890 @samp{$@{@var{var}:-@var{value}@}} and @samp{$@{@var{var}=@var{value}@}}
11891 for the rationale.
11893 @node Parentheses
11894 @section Parentheses in Shell Scripts
11895 @cindex Shell parentheses
11897 Beware of two opening parentheses in a row, as some shell
11898 implementations mishandle them.  For example, @samp{pdksh} 5.2.14
11899 misparses the following code:
11901 @example
11902 if ((true) || false); then
11903   echo ok
11905 @end example
11907 @noindent
11908 To work around this problem, insert a space between the two opening
11909 parentheses.  There is a similar problem and workaround with
11910 @samp{$((}; see @ref{Shell Substitutions}.
11912 Posix requires support for @code{case} patterns with opening
11913 parentheses like this:
11915 @example
11916 case $file_name in
11917 (*.c) echo "C source code";;
11918 esac
11919 @end example
11921 @noindent
11922 but the @code{(} in this example is not portable to many older Bourne
11923 shell implementations.  It can be omitted safely.
11925 @node Slashes
11926 @section Slashes in Shell Scripts
11927 @cindex Shell slashes
11929 Unpatched Tru64 5.1 @command{sh} omits the last slash of command-line
11930 arguments that contain two trailing slashes:
11932 @example
11933 $ @kbd{echo / // /// //// .// //.}
11934 / / // /// ./ //.
11935 $ @kbd{x=//}
11936 $ @kbd{eval "echo \$x"}
11938 $ @kbd{set -x}
11939 $ @kbd{echo abc | tr -t ab //}
11940 + echo abc
11941 + tr -t ab /
11943 @end example
11945 Unpatched Tru64 4.0 @command{sh} adds a slash after @samp{"$var"} if the
11946 variable is empty and the second double-quote is followed by a word that
11947 begins and ends with slash:
11949 @example
11950 $ @kbd{sh -xc 'p=; echo "$p"/ouch/'}
11952 + echo //ouch/
11953 //ouch/
11954 @end example
11956 However, our understanding is that patches are available, so perhaps
11957 it's not worth worrying about working around these horrendous bugs.
11959 @node Special Shell Variables
11960 @section Special Shell Variables
11961 @cindex Shell variables
11962 @cindex Special shell variables
11964 Some shell variables should not be used, since they can have a deep
11965 influence on the behavior of the shell.  In order to recover a sane
11966 behavior from the shell, some variables should be unset, but
11967 @command{unset} is not portable (@pxref{Limitations of Builtins}) and a
11968 fallback value is needed.
11970 As a general rule, shell variable names containing a lower-case letter
11971 are safe; you can define and use these variables without worrying about
11972 their effect on the underlying system, and without worrying about
11973 whether the shell changes them unexpectedly.  (The exception is the
11974 shell variable @code{status}, as described below.)
11976 Here is a list of names that are known to cause trouble.  This list is
11977 not exhaustive, but you should be safe if you avoid the name
11978 @code{status} and names containing only upper-case letters and
11979 underscores.
11981 @c Alphabetical order, case insensitive, `A' before `a'.
11982 @table @code
11983 @item _
11984 Many shells reserve @samp{$_} for various purposes, e.g., the name of
11985 the last command executed.
11987 @item BIN_SH
11988 @evindex BIN_SH
11989 In Tru64, if @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations of
11990 the standard shell conform to Posix.
11992 @item CDPATH
11993 @evindex CDPATH
11994 When this variable is set it specifies a list of directories to search
11995 when invoking @code{cd} with a relative file name that did not start
11996 with @samp{./} or @samp{../}.  Posix
11997 1003.1-2001 says that if a nonempty directory name from @env{CDPATH}
11998 is used successfully, @code{cd} prints the resulting absolute
11999 file name.  Unfortunately this output can break idioms like
12000 @samp{abs=`cd src && pwd`} because @code{abs} receives the name twice.
12001 Also, many shells do not conform to this part of Posix; for
12002 example, @command{zsh} prints the result only if a directory name
12003 other than @file{.} was chosen from @env{CDPATH}.
12005 In practice the shells that have this problem also support
12006 @command{unset}, so you can work around the problem as follows:
12008 @example
12009 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
12010 @end example
12012 You can also avoid output by ensuring that your directory name is
12013 absolute or anchored at @samp{./}, as in @samp{abs=`cd ./src && pwd`}.
12015 Autoconf-generated scripts automatically unset @env{CDPATH} if
12016 possible, so you need not worry about this problem in those scripts.
12018 @item DUALCASE
12019 @evindex DUALCASE
12020 In the MKS shell, case statements and file name generation are
12021 case-insensitive unless @env{DUALCASE} is nonzero.
12022 Autoconf-generated scripts export this variable when they start up.
12024 @item ENV
12025 @itemx MAIL
12026 @itemx MAILPATH
12027 @itemx PS1
12028 @itemx PS2
12029 @itemx PS4
12030 @evindex ENV
12031 @evindex MAIL
12032 @evindex MAILPATH
12033 @evindex PS1
12034 @evindex PS2
12035 @evindex PS4
12036 These variables should not matter for shell scripts, since they are
12037 supposed to affect only interactive shells.  However, at least one
12038 shell (the pre-3.0 @sc{uwin} Korn shell) gets confused about
12039 whether it is interactive, which means that (for example) a @env{PS1}
12040 with a side effect can unexpectedly modify @samp{$?}.  To work around
12041 this bug, Autoconf-generated scripts do something like this:
12043 @example
12044 (unset ENV) >/dev/null 2>&1 && unset ENV MAIL MAILPATH
12045 PS1='$ '
12046 PS2='> '
12047 PS4='+ '
12048 @end example
12050 @item IFS
12051 @evindex IFS
12052 Long ago, shell scripts inherited @env{IFS} from the environment,
12053 but this caused many problems so modern shells ignore any environment
12054 settings for @env{IFS}.
12056 Don't set the first character of @code{IFS} to backslash.  Indeed,
12057 Bourne shells use the first character (backslash) when joining the
12058 components in @samp{"$@@"} and some shells then reinterpret (!)@: the
12059 backslash escapes, so you can end up with backspace and other strange
12060 characters.
12062 The proper value for @code{IFS} (in regular code, not when performing
12063 splits) is @samp{@key{SPC}@key{TAB}@key{RET}}.  The first character is
12064 especially important, as it is used to join the arguments in @samp{$*};
12065 however, note that traditional shells, but also bash-2.04, fail to adhere
12066 to this and join with a space anyway.
12068 @item LANG
12069 @itemx LC_ALL
12070 @itemx LC_COLLATE
12071 @itemx LC_CTYPE
12072 @itemx LC_MESSAGES
12073 @itemx LC_MONETARY
12074 @itemx LC_NUMERIC
12075 @itemx LC_TIME
12076 @evindex LANG
12077 @evindex LC_ALL
12078 @evindex LC_COLLATE
12079 @evindex LC_CTYPE
12080 @evindex LC_MESSAGES
12081 @evindex LC_MONETARY
12082 @evindex LC_NUMERIC
12083 @evindex LC_TIME
12085 Autoconf-generated scripts normally set all these variables to
12086 @samp{C} because so much configuration code assumes the C locale and
12087 Posix requires that locale environment variables be set to
12088 @samp{C} if the C locale is desired.  However, some older, nonstandard
12089 systems (notably @acronym{SCO}) break if locale environment variables
12090 are set to @samp{C}, so when running on these systems
12091 Autoconf-generated scripts unset the variables instead.
12093 @item LANGUAGE
12094 @evindex LANGUAGE
12096 @env{LANGUAGE} is not specified by Posix, but it is a @acronym{GNU}
12097 extension that overrides @env{LC_ALL} in some cases, so
12098 Autoconf-generated scripts set it too.
12100 @item LC_ADDRESS
12101 @itemx LC_IDENTIFICATION
12102 @itemx LC_MEASUREMENT
12103 @itemx LC_NAME
12104 @itemx LC_PAPER
12105 @itemx LC_TELEPHONE
12106 @evindex LC_ADDRESS
12107 @evindex LC_IDENTIFICATION
12108 @evindex LC_MEASUREMENT
12109 @evindex LC_NAME
12110 @evindex LC_PAPER
12111 @evindex LC_TELEPHONE
12113 These locale environment variables are @acronym{GNU} extensions.  They
12114 are treated like their Posix brethren (@env{LC_COLLATE},
12115 etc.)@: as described above.
12117 @item LINENO
12118 Most modern shells provide the current line number in @code{LINENO}.
12119 Its value is the line number of the beginning of the current command.
12120 Autoconf attempts to execute @command{configure} with a shell that
12121 supports @code{LINENO}.
12122 If no such shell is available, it attempts to implement @code{LINENO}
12123 with a Sed prepass that replaces each instance of the string
12124 @code{$LINENO} (not followed by an alphanumeric character) with the
12125 line's number.
12127 You should not rely on @code{LINENO} within @command{eval}, as the
12128 behavior differs in practice.  Also, the possibility of the Sed
12129 prepass means that you should not rely on @code{$LINENO} when quoted,
12130 when in here-documents, or when in long commands that cross line
12131 boundaries.  Subshells should be OK, though.  In the following
12132 example, lines 1, 6, and 9 are portable, but the other instances of
12133 @code{LINENO} are not:
12135 @example
12136 @group
12137 $ @kbd{cat lineno}
12138 echo 1. $LINENO
12139 cat <<EOF
12140 3. $LINENO
12141 4. $LINENO
12143 ( echo 6. $LINENO )
12144 eval 'echo 7. $LINENO'
12145 echo 8. '$LINENO'
12146 echo 9. $LINENO '
12147 10.' $LINENO
12148 @end group
12149 @group
12150 $ @kbd{bash-2.05 lineno}
12151 1. 1
12152 3. 2
12153 4. 2
12154 6. 6
12155 7. 1
12156 8. $LINENO
12157 9. 9
12158 10. 9
12159 @end group
12160 @group
12161 $ @kbd{zsh-3.0.6 lineno}
12162 1. 1
12163 3. 2
12164 4. 2
12165 6. 6
12166 7. 7
12167 8. $LINENO
12168 9. 9
12169 10. 9
12170 @end group
12171 @group
12172 $ @kbd{pdksh-5.2.14 lineno}
12173 1. 1
12174 3. 2
12175 4. 2
12176 6. 6
12177 7. 0
12178 8. $LINENO
12179 9. 9
12180 10. 9
12181 @end group
12182 @group
12183 $ @kbd{sed '=' <lineno |}
12184 > @kbd{  sed '}
12185 > @kbd{    N}
12186 > @kbd{    s,$,-,}
12187 > @kbd{    t loop}
12188 > @kbd{    :loop}
12189 > @kbd{    s,^\([0-9]*\)\(.*\)[$]LINENO\([^a-zA-Z0-9_]\),\1\2\1\3,}
12190 > @kbd{    t loop}
12191 > @kbd{    s,-$,,}
12192 > @kbd{    s,^[0-9]*\n,,}
12193 > @kbd{  ' |}
12194 > @kbd{  sh}
12195 1. 1
12196 3. 3
12197 4. 4
12198 6. 6
12199 7. 7
12200 8. 8
12201 9. 9
12202 10. 10
12203 @end group
12204 @end example
12206 @item NULLCMD
12207 @evindex NULLCMD
12208 When executing the command @samp{>foo}, @command{zsh} executes
12209 @samp{$NULLCMD >foo} unless it is operating in Bourne shell
12210 compatibility mode and the @command{zsh} version is newer
12211 than 3.1.6-dev-18.  If you are using an older @command{zsh}
12212 and forget to set @env{NULLCMD},
12213 your script might be suspended waiting for data on its standard input.
12215 @item PATH_SEPARATOR
12216 @evindex PATH_SEPARATOR
12217 On @acronym{DJGPP} systems, the @env{PATH_SEPARATOR} environment
12218 variable can be set to either @samp{:} or @samp{;} to control the path
12219 separator Bash uses to set up certain environment variables (such as
12220 @env{PATH}).  You can set this variable to @samp{;} if you want
12221 @command{configure} to use @samp{;} as a separator; this might be useful
12222 if you plan to use non-Posix shells to execute files.  @xref{File System
12223 Conventions}, for more information about @code{PATH_SEPARATOR}.
12225 @item PWD
12226 @evindex PWD
12227 Posix 1003.1-2001 requires that @command{cd} and
12228 @command{pwd} must update the @env{PWD} environment variable to point
12229 to the logical name of the current directory, but traditional shells
12230 do not support this.  This can cause confusion if one shell instance
12231 maintains @env{PWD} but a subsidiary and different shell does not know
12232 about @env{PWD} and executes @command{cd}; in this case @env{PWD}
12233 points to the wrong directory.  Use @samp{`pwd`} rather than
12234 @samp{$PWD}.
12236 @item RANDOM
12237 Many shells provide @code{RANDOM}, a variable that returns a different
12238 integer each time it is used.  Most of the time, its value does not
12239 change when it is not used, but on @sc{irix} 6.5 the value changes all
12240 the time.  This can be observed by using @command{set}.  It is common
12241 practice to use @code{$RANDOM} as part of a file name, but code
12242 shouldn't rely on @code{$RANDOM} expanding to a nonempty string.
12244 @item status
12245 This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6),
12246 hence read-only.  Do not use it.
12247 @end table
12249 @node Limitations of Builtins
12250 @section Limitations of Shell Builtins
12251 @cindex Shell builtins
12252 @cindex Limitations of shell builtins
12254 No, no, we are serious: some shells do have limitations!  :)
12256 You should always keep in mind that any builtin or command may support
12257 options, and therefore differ in behavior with arguments
12258 starting with a dash.  For instance, the innocent @samp{echo "$word"}
12259 can give unexpected results when @code{word} starts with a dash.  It is
12260 often possible to avoid this problem using @samp{echo "x$word"}, taking
12261 the @samp{x} into account later in the pipe.
12263 @table @asis
12264 @item @command{.}
12265 @prindex @command{.}
12266 Use @command{.} only with regular files (use @samp{test -f}).  Bash
12267 2.03, for instance, chokes on @samp{. /dev/null}.  Also, remember that
12268 @command{.} uses @env{PATH} if its argument contains no slashes, so if
12269 you want to use @command{.} on a file @file{foo} in the current
12270 directory, you must use @samp{. ./foo}.
12272 @item @command{!}
12273 @prindex @command{!}
12274 The Unix version 7 shell did not support
12275 negating the exit status of commands with @command{!}, and this feature
12276 is still absent from some shells (e.g., Solaris @command{/bin/sh}).
12277 Shell code like this:
12279 @example
12280 if ! cmp file1 file2 >/dev/null 2>&1; then
12281   echo files differ or trouble
12283 @end example
12285 is therefore not portable in practice.  Typically it is easy to rewrite
12286 such code, e.g.:
12288 @example
12289 cmp file1 file2 >/dev/null 2>&1 ||
12290   echo files differ or trouble
12291 @end example
12293 More generally, one can always rewrite @samp{! @var{command}} as:
12295 @example
12296 if @var{command}; then (exit 1); else :; fi
12297 @end example
12299 @item @command{break}
12300 @c ------------------
12301 @prindex @command{break}
12302 The use of @samp{break 2} etc.@: is safe.
12305 @item @command{case}
12306 @c -----------------
12307 @prindex @command{case}
12308 You don't need to quote the argument; no splitting is performed.
12310 You don't need the final @samp{;;}, but you should use it.
12312 Because of a bug in its @code{fnmatch}, Bash fails to properly
12313 handle backslashes in character classes:
12315 @example
12316 bash-2.02$ @kbd{case /tmp in [/\\]*) echo OK;; esac}
12317 bash-2.02$
12318 @end example
12320 @noindent
12321 This is extremely unfortunate, since you are likely to use this code to
12322 handle Posix or @sc{ms-dos} absolute file names.  To work around this
12323 bug, always put the backslash first:
12325 @example
12326 bash-2.02$ @kbd{case '\TMP' in [\\/]*) echo OK;; esac}
12328 bash-2.02$ @kbd{case /tmp in [\\/]*) echo OK;; esac}
12330 @end example
12332 Many Bourne shells cannot handle closing brackets in character classes
12333 correctly.
12335 Some shells also have problems with backslash escaping in case you do not want
12336 to match the backslash: both a backslash and the escaped character match this
12337 pattern.  To work around this, specify the character class in a variable, so
12338 that quote removal does not apply afterwards, and the special characters don't
12339 have to be backslash-escaped:
12341 @example
12342 $ @kbd{case '\' in [\<]) echo OK;; esac}
12344 $ @kbd{scanset='[<]'; case '\' in $scanset) echo OK;; esac}
12346 @end example
12348 Even with this, Solaris @command{ksh} matches a backslash if the set
12349 contains any
12350 of the characters @samp{|}, @samp{&}, @samp{(}, or @samp{)}.
12352 Conversely, Tru64 @command{ksh} (circa 2003) erroneously always matches
12353 a closing parenthesis if not specified in a character class:
12355 @example
12356 $ @kbd{case foo in *\)*) echo fail ;; esac}
12357 fail
12358 $ @kbd{case foo in *')'*) echo fail ;; esac}
12359 fail
12360 @end example
12362 Some shells, such as Ash 0.3.8, are confused by an empty
12363 @code{case}/@code{esac}:
12365 @example
12366 ash-0.3.8 $ @kbd{case foo in esac;}
12367 @error{}Syntax error: ";" unexpected (expecting ")")
12368 @end example
12370 Many shells still do not support parenthesized cases, which is a pity
12371 for those of us using tools that rely on balanced parentheses.  For
12372 instance, Solaris @command{/bin/sh}:
12374 @example
12375 $ @kbd{case foo in (foo) echo foo;; esac}
12376 @error{}syntax error: `(' unexpected
12377 @end example
12380 @item @command{cd}
12381 @c ---------------
12382 @prindex @command{cd}
12383 Posix 1003.1-2001 requires that @command{cd} must support
12384 the @option{-L} (``logical'') and @option{-P} (``physical'') options,
12385 with @option{-L} being the default.  However, traditional shells do
12386 not support these options, and their @command{cd} command has the
12387 @option{-P} behavior.
12389 Portable scripts should assume neither option is supported, and should
12390 assume neither behavior is the default.  This can be a bit tricky,
12391 since the Posix default behavior means that, for example,
12392 @samp{ls ..} and @samp{cd ..} may refer to different directories if
12393 the current logical directory is a symbolic link.  It is safe to use
12394 @command{cd @var{dir}} if @var{dir} contains no @file{..} components.
12395 Also, Autoconf-generated scripts check for this problem when computing
12396 variables like @code{ac_top_srcdir} (@pxref{Configuration Actions}),
12397 so it is safe to @command{cd} to these variables.
12399 See @xref{Special Shell Variables}, for portability problems involving
12400 @command{cd} and the @env{CDPATH} environment variable.
12401 Also please see the discussion of the @command{pwd} command.
12404 @item @command{echo}
12405 @c -----------------
12406 @prindex @command{echo}
12407 The simple @command{echo} is probably the most surprising source of
12408 portability troubles.  It is not possible to use @samp{echo} portably
12409 unless both options and escape sequences are omitted.  New applications
12410 which are not aiming at portability should use @samp{printf} instead of
12411 @samp{echo}.
12413 Don't expect any option.  @xref{Preset Output Variables}, @code{ECHO_N}
12414 etc.@: for a means to simulate @option{-n}.
12416 Do not use backslashes in the arguments, as there is no consensus on
12417 their handling.  For @samp{echo '\n' | wc -l}, the @command{sh} of
12418 Solaris outputs 2, but Bash and Zsh (in @command{sh} emulation mode) output 1.
12419 The problem is truly @command{echo}: all the shells
12420 understand @samp{'\n'} as the string composed of a backslash and an
12421 @samp{n}.
12423 Because of these problems, do not pass a string containing arbitrary
12424 characters to @command{echo}.  For example, @samp{echo "$foo"} is safe
12425 if you know that @var{foo}'s value cannot contain backslashes and cannot
12426 start with @samp{-}, but otherwise you should use a here-document like
12427 this:
12429 @example
12430 cat <<EOF
12431 $foo
12433 @end example
12436 @item @command{eval}
12437 @c -----------------
12438 @prindex @command{eval}
12439 The @command{eval} command is useful in limited circumstances, e.g.,
12440 using commands like @samp{eval table_$key=\$value} and @samp{eval
12441 value=table_$key} to simulate a hash table when the key is known to be
12442 alphanumeric.  However, @command{eval} is tricky to use on arbitrary
12443 arguments, even when it is implemented correctly.
12445 It is obviously unwise to use @samp{eval $cmd} if the string value of
12446 @samp{cmd} was derived from an untrustworthy source.  But even if the
12447 string value is valid, @samp{eval $cmd} might not work as intended,
12448 since it causes field splitting and file name expansion to occur twice,
12449 once for the @command{eval} and once for the command itself.  It is
12450 therefore safer to use @samp{eval "$cmd"}.  For example, if @var{cmd}
12451 has the value @samp{cat test?.c}, @samp{eval $cmd} might expand to the
12452 equivalent of @samp{cat test;.c} if there happens to be a file named
12453 @file{test;.c} in the current directory; and this in turn
12454 mistakenly attempts to invoke @command{cat} on the file @file{test} and
12455 then execute the command @command{.c}.  To avoid this problem, use
12456 @samp{eval "$cmd"} rather than @samp{eval $cmd}.
12458 However, suppose that you want to output the text of the evaluated
12459 command just before executing it.  Assuming the previous example,
12460 @samp{echo "Executing: $cmd"} outputs @samp{Executing: cat test?.c}, but
12461 this output doesn't show the user that @samp{test;.c} is the actual name
12462 of the copied file.  Conversely, @samp{eval "echo Executing: $cmd"}
12463 works on this example, but it fails with @samp{cmd='cat foo >bar'},
12464 since it mistakenly replaces the contents of @file{bar} by the
12465 string @samp{cat foo}.  No simple, general, and portable solution to
12466 this problem is known.
12468 You should also be wary of common bugs in @command{eval} implementations.
12469 In some shell implementations (e.g., older @command{ash}, Open@acronym{BSD} 3.8
12470 @command{sh}, @command{pdksh} v5.2.14 99/07/13.2, and @command{zsh}
12471 4.2.5), the arguments of @samp{eval} are evaluated in a context where
12472 @samp{$?} is 0, so they exhibit behavior like this:
12474 @example
12475 $ @kbd{false; eval 'echo $?'}
12477 @end example
12479 The correct behavior here is to output a nonzero value,
12480 but portable scripts should not rely on this.
12482 You should not rely on @code{LINENO} within @command{eval}.
12483 @xref{Special Shell Variables}.
12485 @item @command{exit}
12486 @c -----------------
12487 @prindex @command{exit}
12488 The default value of @command{exit} is supposed to be @code{$?};
12489 unfortunately, some shells, such as the @acronym{DJGPP} port of Bash 2.04, just
12490 perform @samp{exit 0}.
12492 @example
12493 bash-2.04$ @kbd{foo=`exit 1` || echo fail}
12494 fail
12495 bash-2.04$ @kbd{foo=`(exit 1)` || echo fail}
12496 fail
12497 bash-2.04$ @kbd{foo=`(exit 1); exit` || echo fail}
12498 bash-2.04$
12499 @end example
12501 Using @samp{exit $?} restores the expected behavior.
12503 Some shell scripts, such as those generated by @command{autoconf}, use a
12504 trap to clean up before exiting.  If the last shell command exited with
12505 nonzero status, the trap also exits with nonzero status so that the
12506 invoker can tell that an error occurred.
12508 Unfortunately, in some shells, such as Solaris @command{/bin/sh}, an exit
12509 trap ignores the @code{exit} command's argument.  In these shells, a trap
12510 cannot determine whether it was invoked by plain @code{exit} or by
12511 @code{exit 1}.  Instead of calling @code{exit} directly, use the
12512 @code{AC_MSG_ERROR} macro that has a workaround for this problem.
12515 @item @command{export}
12516 @c -------------------
12517 @prindex @command{export}
12518 The builtin @command{export} dubs a shell variable @dfn{environment
12519 variable}.  Each update of exported variables corresponds to an update
12520 of the environment variables.  Conversely, each environment variable
12521 received by the shell when it is launched should be imported as a shell
12522 variable marked as exported.
12524 Alas, many shells, such as Solaris @command{/bin/sh},
12525 @sc{irix} 6.3, @sc{irix} 5.2,
12526 @acronym{AIX} 4.1.5, and Digital Unix 4.0, forget to
12527 @command{export} the environment variables they receive.  As a result,
12528 two variables coexist: the environment variable and the shell
12529 variable.  The following code demonstrates this failure:
12531 @example
12532 #!/bin/sh
12533 echo $FOO
12534 FOO=bar
12535 echo $FOO
12536 exec /bin/sh $0
12537 @end example
12539 @noindent
12540 when run with @samp{FOO=foo} in the environment, these shells print
12541 alternately @samp{foo} and @samp{bar}, although they should print only
12542 @samp{foo} and then a sequence of @samp{bar}s.
12544 Therefore you should @command{export} again each environment variable
12545 that you update.
12548 @item @command{false}
12549 @c ------------------
12550 @prindex @command{false}
12551 Don't expect @command{false} to exit with status 1: in native
12552 Solaris @file{/bin/false} exits with status 255.
12555 @item @command{for}
12556 @c ----------------
12557 @prindex @command{for}
12558 To loop over positional arguments, use:
12560 @example
12561 for arg
12563   echo "$arg"
12564 done
12565 @end example
12567 @noindent
12568 You may @emph{not} leave the @code{do} on the same line as @code{for},
12569 since some shells improperly grok:
12571 @example
12572 for arg; do
12573   echo "$arg"
12574 done
12575 @end example
12577 If you want to explicitly refer to the positional arguments, given the
12578 @samp{$@@} bug (@pxref{Shell Substitutions}), use:
12580 @example
12581 for arg in $@{1+"$@@"@}; do
12582   echo "$arg"
12583 done
12584 @end example
12586 @noindent
12587 But keep in mind that Zsh, even in Bourne shell emulation mode, performs
12588 word splitting on @samp{$@{1+"$@@"@}}; see @ref{Shell Substitutions},
12589 item @samp{$@@}, for more.
12592 @item @command{if}
12593 @c ---------------
12594 @prindex @command{if}
12595 Using @samp{!} is not portable.  Instead of:
12597 @example
12598 if ! cmp -s file file.new; then
12599   mv file.new file
12601 @end example
12603 @noindent
12604 use:
12606 @example
12607 if cmp -s file file.new; then :; else
12608   mv file.new file
12610 @end example
12612 There are shells that do not reset the exit status from an @command{if}:
12614 @example
12615 $ @kbd{if (exit 42); then true; fi; echo $?}
12617 @end example
12619 @noindent
12620 whereas a proper shell should have printed @samp{0}.  This is especially
12621 bad in makefiles since it produces false failures.  This is why properly
12622 written makefiles, such as Automake's, have such hairy constructs:
12624 @example
12625 if test -f "$file"; then
12626   install "$file" "$dest"
12627 else
12628   :
12630 @end example
12633 @item @command{printf}
12634 @c ------------------
12635 @prindex @command{printf}
12636 A format string starting with a @samp{-} can cause problems.
12637 Bash (e.g., 2.05b) interprets it as an options argument and
12638 gives an error.  And @samp{--} to mark the end of options is not good
12639 in the Net@acronym{BSD} Almquist shell (e.g., 0.4.6) which takes that
12640 literally as the format string.  Putting the @samp{-} in a @samp{%c}
12641 or @samp{%s} is probably the easiest way to avoid doubt,
12643 @example
12644 printf %s -foo
12645 @end example
12648 @item @command{read}
12649 @c ------------------
12650 @prindex @command{read}
12651 Not all shells support @option{-r} (Solaris @command{/bin/sh} for example).
12654 @item @command{pwd}
12655 @c ----------------
12656 @prindex @command{pwd}
12657 With modern shells, plain @command{pwd} outputs a ``logical''
12658 directory name, some of whose components may be symbolic links.  These
12659 directory names are in contrast to ``physical'' directory names, whose
12660 components are all directories.
12662 Posix 1003.1-2001 requires that @command{pwd} must support
12663 the @option{-L} (``logical'') and @option{-P} (``physical'') options,
12664 with @option{-L} being the default.  However, traditional shells do
12665 not support these options, and their @command{pwd} command has the
12666 @option{-P} behavior.
12668 Portable scripts should assume neither option is supported, and should
12669 assume neither behavior is the default.  Also, on many hosts
12670 @samp{/bin/pwd} is equivalent to @samp{pwd -P}, but Posix
12671 does not require this behavior and portable scripts should not rely on
12674 Typically it's best to use plain @command{pwd}.  On modern hosts this
12675 outputs logical directory names, which have the following advantages:
12677 @itemize @bullet
12678 @item
12679 Logical names are what the user specified.
12680 @item
12681 Physical names may not be portable from one installation
12682 host to another due to network file system gymnastics.
12683 @item
12684 On modern hosts @samp{pwd -P} may fail due to lack of permissions to
12685 some parent directory, but plain @command{pwd} cannot fail for this
12686 reason.
12687 @end itemize
12689 Also please see the discussion of the @command{cd} command.
12692 @item @command{set}
12693 @c ----------------
12694 @prindex @command{set}
12695 With the Free@acronym{BSD} 6.0 shell, the @command{set} command (without
12696 any options) does not sort its output.
12698 The @command{set} builtin faces the usual problem with arguments starting with a
12699 dash.  Modern shells such as Bash or Zsh understand @option{--} to specify
12700 the end of the options (any argument after @option{--} is a parameter,
12701 even @samp{-x} for instance), but many traditional shells (e.g., Solaris
12702 10 @command{/bin/sh}) simply stop option
12703 processing as soon as a non-option argument is found.  Therefore, use
12704 @samp{dummy} or simply @samp{x} to end the option processing, and use
12705 @command{shift} to pop it out:
12707 @example
12708 set x $my_list; shift
12709 @end example
12711 Avoid @samp{set -}, e.g., @samp{set - $my_list}.  Posix no
12712 longer requires support for this command, and in traditional shells
12713 @samp{set - $my_list} resets the @option{-v} and @option{-x} options, which
12714 makes scripts harder to debug.
12716 Some nonstandard shells do not recognize more than one option
12717 (e.g., @samp{set -e -x} assigns @samp{-x} to the command line).  It is
12718 better to combine them:
12720 @example
12721 set -ex
12722 @end example
12724 The @acronym{BSD} shell has had several problems with the @option{-e}
12725 option, partly because @acronym{BSD} @command{make} traditionally used
12726 @option{-e} even though this was incompatible with Posix
12727 (@pxref{Failure in Make Rules}).  Older versions of the @acronym{BSD}
12728 shell (circa 1990) mishandled @samp{&&}, @samp{||}, @samp{if}, and
12729 @samp{case} when @option{-e} was in effect, causing the shell to exit
12730 unexpectedly in some cases.  This was particularly a problem with
12731 makefiles, and led to circumlocutions like @samp{sh -c 'test -f file ||
12732 touch file'}, where the seemingly-unnecessary @samp{sh -c '@dots{}'}
12733 wrapper works around the bug.
12735 Even relatively-recent versions of the @acronym{BSD} shell (e.g.,
12736 Open@acronym{BSD} 3.4) wrongly exit with @option{-e} if a command within
12737 @samp{&&} fails inside a compound statement.  For example:
12739 @example
12740 #! /bin/sh
12741 set -e
12742 foo=''
12743 test -n "$foo" && exit 1
12744 echo one
12745 if :; then
12746   test -n "$foo" && exit 1
12748 echo two
12749 @end example
12751 @noindent
12752 does not print @samp{two}.  One workaround is to use @samp{if test -n
12753 "$foo"; then exit 1; fi} rather than @samp{test -n "$foo" && exit 1}.
12754 Another possibility is to warn @acronym{BSD} users not to use @samp{sh -e}.
12757 @item @command{shift}
12758 @c ------------------
12759 @prindex @command{shift}
12760 Not only is @command{shift}ing a bad idea when there is nothing left to
12761 shift, but in addition it is not portable: the shell of @acronym{MIPS
12762 RISC/OS} 4.52 refuses to do it.
12764 Don't use @samp{shift 2} etc.; it was not in the 7th Edition Bourne shell,
12765 and it is also absent in many pre-Posix shells.
12768 @item @command{source}
12769 @c -------------------
12770 @prindex @command{source}
12771 This command is not portable, as Posix does not require it; use
12772 @command{.} instead.
12775 @item @command{test}
12776 @c -----------------
12777 @prindex @command{test}
12778 The @code{test} program is the way to perform many file and string
12779 tests.  It is often invoked by the alternate name @samp{[}, but using
12780 that name in Autoconf code is asking for trouble since it is an M4 quote
12781 character.
12783 If you need to make multiple checks using @code{test}, combine them with
12784 the shell operators @samp{&&} and @samp{||} instead of using the
12785 @code{test} operators @option{-a} and @option{-o}.  On System V, the
12786 precedence of @option{-a} and @option{-o} is wrong relative to the unary
12787 operators; consequently, Posix does not specify them, so using them
12788 is nonportable.  If you combine @samp{&&} and @samp{||} in the same
12789 statement, keep in mind that they have equal precedence.
12791 It is safe to use @samp{!} as a @command{test} operator.  For example,
12792 @samp{if test ! -d foo; @dots{}} is portable even though @samp{if ! test
12793 -d foo; @dots{}} is not.
12796 @item @command{test} (files)
12797 @c -------------------------
12798 To enable @command{configure} scripts to support cross-compilation, they
12799 shouldn't do anything that tests features of the build system instead of
12800 the host system.  But occasionally you may find it necessary to check
12801 whether some arbitrary file exists.  To do so, use @samp{test -f} or
12802 @samp{test -r}.  Do not use @samp{test -x}, because 4.3@acronym{BSD} does not
12803 have it.  Do not use @samp{test -e} either, because Solaris @command{/bin/sh}
12804 lacks it.  To test for symbolic links on systems that have them, use
12805 @samp{test -h} rather than @samp{test -L}; either form conforms to
12806 Posix 1003.1-2001, but older shells like Solaris 8
12807 @code{/bin/sh} support only @option{-h}.
12809 @item @command{test} (strings)
12810 @c ---------------------------
12811 Avoid @samp{test "@var{string}"}, in particular if @var{string} might
12812 start with a dash, since @code{test} might interpret its argument as an
12813 option (e.g., @samp{@var{string} = "-n"}).
12815 Contrary to a common belief, @samp{test -n @var{string}} and
12816 @samp{test -z @var{string}} @strong{are} portable.  Nevertheless many
12817 shells (such as Solaris, @acronym{AIX} 3.2, @sc{unicos} 10.0.0.6,
12818 Digital Unix 4, etc.)@: have bizarre precedence and may be confused if
12819 @var{string} looks like an operator:
12821 @example
12822 $ @kbd{test -n =}
12823 test: argument expected
12824 @end example
12826 If there are risks, use @samp{test "x@var{string}" = x} or @samp{test
12827 "x@var{string}" != x} instead.
12829 It is common to find variations of the following idiom:
12831 @example
12832 test -n "`echo $ac_feature | sed 's/[-a-zA-Z0-9_]//g'`" &&
12833   @var{action}
12834 @end example
12836 @noindent
12837 to take an action when a token matches a given pattern.  Such constructs
12838 should always be avoided by using:
12840 @example
12841 echo "$ac_feature" | grep '[^-a-zA-Z0-9_]' >/dev/null 2>&1 &&
12842   @var{action}
12843 @end example
12845 @noindent
12846 Use @code{case} where possible since it is faster, being a shell builtin:
12849 @example
12850 case $ac_feature in
12851   *[!-a-zA-Z0-9_]*) @var{action};;
12852 esac
12853 @end example
12855 Alas, negated character classes are probably not portable, although no
12856 shell is known to not support the Posix syntax @samp{[!@dots{}]}
12857 (when in interactive mode, @command{zsh} is confused by the
12858 @samp{[!@dots{}]} syntax and looks for an event in its history because of
12859 @samp{!}).  Many shells do not support the alternative syntax
12860 @samp{[^@dots{}]} (Solaris, Digital Unix, etc.).
12862 One solution can be:
12864 @example
12865 expr "$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null &&
12866   @var{action}
12867 @end example
12869 @noindent
12870 or better yet
12872 @example
12873 expr "X$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null &&
12874   @var{action}
12875 @end example
12877 @samp{expr "X@var{foo}" : "X@var{bar}"} is more robust than @samp{echo
12878 "X@var{foo}" | grep "^X@var{bar}"}, because it avoids problems when
12879 @samp{@var{foo}} contains backslashes.
12882 @item @command{trap}
12883 @c -----------------
12884 @prindex @command{trap}
12885 It is safe to trap at least the signals 1, 2, 13, and 15.  You can also
12886 trap 0, i.e., have the @command{trap} run when the script ends (either via an
12887 explicit @command{exit}, or the end of the script).  The trap for 0 should be
12888 installed outside of a shell function, or @acronym{AIX} 5.3 @command{/bin/sh}
12889 will invoke the trap at the end of this function.
12891 Posix says that @samp{trap - 1 2 13 15} resets the traps for the
12892 specified signals to their default values, but many common shells (e.g.,
12893 Solaris @command{/bin/sh}) misinterpret this and attempt to execute a
12894 ``command'' named @command{-} when the specified conditions arise.
12895 There is no portable workaround, except for @samp{trap - 0}, for which
12896 @samp{trap '' 0} is a portable substitute.
12898 Although Posix is not absolutely clear on this point, it is widely
12899 admitted that when entering the trap @samp{$?} should be set to the exit
12900 status of the last command run before the trap.  The ambiguity can be
12901 summarized as: ``when the trap is launched by an @command{exit}, what is
12902 the @emph{last} command run: that before @command{exit}, or
12903 @command{exit} itself?''
12905 Bash considers @command{exit} to be the last command, while Zsh and
12906 Solaris @command{/bin/sh} consider that when the trap is run it is
12907 @emph{still} in the @command{exit}, hence it is the previous exit status
12908 that the trap receives:
12910 @example
12911 $ @kbd{cat trap.sh}
12912 trap 'echo $?' 0
12913 (exit 42); exit 0
12914 $ @kbd{zsh trap.sh}
12916 $ @kbd{bash trap.sh}
12918 @end example
12920 The portable solution is then simple: when you want to @samp{exit 42},
12921 run @samp{(exit 42); exit 42}, the first @command{exit} being used to
12922 set the exit status to 42 for Zsh, and the second to trigger the trap
12923 and pass 42 as exit status for Bash.
12925 The shell in Free@acronym{BSD} 4.0 has the following bug: @samp{$?} is
12926 reset to 0 by empty lines if the code is inside @command{trap}.
12928 @example
12929 $ @kbd{trap 'false}
12931 echo $?' 0
12932 $ @kbd{exit}
12934 @end example
12936 @noindent
12937 Fortunately, this bug only affects @command{trap}.
12939 @item @command{true}
12940 @c -----------------
12941 @prindex @command{true}
12942 @c Info cannot handle `:' in index entries.
12943 @c @prindex @command{:}
12944 Don't worry: as far as we know @command{true} is portable.
12945 Nevertheless, it's not always a builtin (e.g., Bash 1.x), and the
12946 portable shell community tends to prefer using @command{:}.  This has a
12947 funny side effect: when asked whether @command{false} is more portable
12948 than @command{true} Alexandre Oliva answered:
12950 @quotation
12951 In a sense, yes, because if it doesn't exist, the shell will produce an
12952 exit status of failure, which is correct for @command{false}, but not
12953 for @command{true}.
12954 @end quotation
12957 @item @command{unset}
12958 @c ------------------
12959 @prindex @command{unset}
12960 In some nonconforming shells (e.g., Bash 2.05a), @code{unset FOO} fails
12961 when @code{FOO} is not set.  Also, Bash 2.01 mishandles @code{unset
12962 MAIL} in some cases and dumps core.
12964 A few ancient shells lack @command{unset} entirely.  Nevertheless, because
12965 it is extremely useful to disable embarrassing variables such as
12966 @code{PS1}, you can test for its existence and use
12967 it @emph{provided} you give a neutralizing value when @command{unset} is
12968 not supported:
12970 @smallexample
12971 # "|| exit" suppresses any "Segmentation fault" message.
12972 if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
12973   unset=unset
12974 else
12975   unset=false
12977 $unset PS1 || PS1='$ '
12978 @end smallexample
12980 @noindent
12981 @xref{Special Shell Variables}, for some neutralizing values.  Also, see
12982 @ref{Limitations of Builtins}, documentation of @command{export}, for
12983 the case of environment variables.
12984 @end table
12986 @node Limitations of Usual Tools
12987 @section Limitations of Usual Tools
12988 @cindex Limitations of usual tools
12990 The small set of tools you can expect to find on any machine can still
12991 include some limitations you should be aware of.
12993 @table @asis
12994 @item Awk
12995 @c ------
12996 @prindex Awk
12997 Don't leave white space before the opening parenthesis in a user function call.
12998 Posix does not allow this and @acronym{GNU} Awk rejects it:
13000 @example
13001 $ @kbd{gawk 'function die () @{ print "Aaaaarg!"  @}
13002         BEGIN @{ die () @}'}
13003 gawk: cmd. line:2:         BEGIN @{ die () @}
13004 gawk: cmd. line:2:                      ^ parse error
13005 $ @kbd{gawk 'function die () @{ print "Aaaaarg!"  @}
13006         BEGIN @{ die() @}'}
13007 Aaaaarg!
13008 @end example
13010 If you want your program to be deterministic, don't depend on @code{for}
13011 on arrays:
13013 @example
13014 $ @kbd{cat for.awk}
13015 END @{
13016   arr["foo"] = 1
13017   arr["bar"] = 1
13018   for (i in arr)
13019     print i
13021 $ @kbd{gawk -f for.awk </dev/null}
13024 $ @kbd{nawk -f for.awk </dev/null}
13027 @end example
13029 Some Awk implementations, such as @acronym{HP-UX} 11.0's native one, mishandle anchors:
13031 @example
13032 $ @kbd{echo xfoo | $AWK '/foo|^bar/ @{ print @}'}
13033 $ @kbd{echo bar | $AWK '/foo|^bar/ @{ print @}'}
13035 $ @kbd{echo xfoo | $AWK '/^bar|foo/ @{ print @}'}
13036 xfoo
13037 $ @kbd{echo bar | $AWK '/^bar|foo/ @{ print @}'}
13039 @end example
13041 @noindent
13042 Either do not depend on such patterns (i.e., use @samp{/^(.*foo|bar)/},
13043 or use a simple test to reject such implementations.
13045 @acronym{AIX} version 5.2 has an arbitrary limit of 399 on the
13046 length of regular expressions and literal strings in an Awk program.
13048 Traditional Awk implementations derived from Unix version 7, such as
13049 Solaris @command{/bin/awk}, have many limitations and do not
13050 conform to Posix.  Nowadays @code{AC_PROG_AWK} (@pxref{Particular
13051 Programs}) finds you an Awk that doesn't have these problems, but if
13052 for some reason you prefer not to use @code{AC_PROG_AWK} you may need to
13053 address them.
13055 Traditional Awk does not support multidimensional arrays or user-defined
13056 functions.
13058 Traditional Awk does not support the @option{-v} option.  You can use
13059 assignments after the program instead, e.g., @command{$AWK '@{print v
13060 $1@}' v=x}; however, don't forget that such assignments are not
13061 evaluated until they are encountered (e.g., after any @code{BEGIN}
13062 action).
13064 Traditional Awk does not support the keywords @code{delete} or @code{do}.
13066 Traditional Awk does not support the expressions
13067 @code{@var{a}?@var{b}:@var{c}}, @code{!@var{a}}, @code{@var{a}^@var{b}},
13068 or @code{@var{a}^=@var{b}}.
13070 Traditional Awk does not support the predefined @code{CONVFMT} variable.
13072 Traditional Awk supports only the predefined functions @code{exp},
13073 @code{int}, @code{length}, @code{log}, @code{split}, @code{sprintf},
13074 @code{sqrt}, and @code{substr}.
13076 Traditional Awk @code{getline} is not at all compatible with Posix;
13077 avoid it.
13079 Traditional Awk has @code{for (i in a) @dots{}} but no other uses of the
13080 @code{in} keyword.  For example, it lacks @code{if (i in a) @dots{}}.
13082 In code portable to both traditional and modern Awk, @code{FS} must be a
13083 string containing just one ordinary character, and similarly for the
13084 field-separator argument to @code{split}.
13086 Traditional Awk has a limit of 99
13087 fields in a record.  You may be able to circumvent this problem by using
13088 @code{split}.
13090 Traditional Awk has a limit of at most 99 bytes in a number formatted by
13091 @code{OFMT}; for example, @code{OFMT="%.300e"; print 0.1;} typically
13092 dumps core.
13094 The original version of Awk had a limit of at most 99 bytes per
13095 @code{split} field, 99 bytes per @code{substr} substring, and 99 bytes
13096 per run of non-special characters in a @code{printf} format, but these
13097 bugs have been fixed on all practical hosts that we know of.
13099 @item @command{basename}
13100 @c ---------------------
13101 @prindex @command{basename}
13102 Not all hosts have a working @command{basename}.
13103 You can use @command{expr} instead.
13105 @c AS_BASENAME is to be replaced by a better API.
13106 @ignore
13107 Not all hosts have a working @command{basename}, and you should instead
13108 use @code{AS_BASENAME} (@pxref{Programming in M4sh}), followed by
13109 @command{expr} if you need to strip a suffix.  For example:
13111 @example
13112 a=`basename "$aname"`       # This is not portable.
13113 a=`AS_BASENAME(["$aname"])` # This is more portable.
13115 # This is not portable.
13116 c=`basename "$cname" .c`
13118 # This is more portable.
13119 c=`AS_BASENAME(["$cname"])`
13120 case $c in
13121 ?*.c) c=`expr "X$c" : 'X\(.*\)\.c'`;;
13122 esac
13123 @end example
13124 @end ignore
13127 @item @command{cat}
13128 @c ----------------
13129 @prindex @command{cat}
13130 Don't rely on any option.
13133 @item @command{cc}
13134 @c ---------------
13135 @prindex @command{cc}
13136 The command @samp{cc -c foo.c} traditionally produces an object file
13137 named @file{foo.o}.  Most compilers allow @option{-c} to be combined
13138 with @option{-o} to specify a different object file name, but
13139 Posix does not require this combination and a few compilers
13140 lack support for it.  @xref{C Compiler}, for how @acronym{GNU} Make
13141 tests for this feature with @code{AC_PROG_CC_C_O}.
13143 When a compilation such as @samp{cc -o foo foo.c} fails, some compilers
13144 (such as @sc{cds} on Reliant Unix) leave a @file{foo.o}.
13146 @acronym{HP-UX} @command{cc} doesn't accept @file{.S} files to preprocess and
13147 assemble.  @samp{cc -c foo.S} appears to succeed, but in fact does
13148 nothing.
13150 The default executable, produced by @samp{cc foo.c}, can be
13152 @itemize
13153 @item @file{a.out} --- usual Posix convention.
13154 @item @file{b.out} --- i960 compilers (including @command{gcc}).
13155 @item @file{a.exe} --- @acronym{DJGPP} port of @command{gcc}.
13156 @item @file{a_out.exe} --- GNV @command{cc} wrapper for DEC C on OpenVMS.
13157 @item @file{foo.exe} --- various MS-DOS compilers.
13158 @end itemize
13160 The C compiler's traditional name is @command{cc}, but other names like
13161 @command{gcc} are common.  Posix 1003.1-2001 specifies the
13162 name @command{c99}, but older Posix editions specified
13163 @command{c89} and anyway these standard names are rarely used in
13164 practice.  Typically the C compiler is invoked from makefiles that use
13165 @samp{$(CC)}, so the value of the @samp{CC} make variable selects the
13166 compiler name.
13169 @item @command{chmod}
13170 @c ------------------
13171 @prindex @command{chmod}
13172 Avoid usages like @samp{chmod -w file}; use @samp{chmod a-w file}
13173 instead, for two reasons.  First, plain @option{-w} does not necessarily
13174 make the file unwritable, since it does not affect mode bits that
13175 correspond to bits in the file mode creation mask.  Second,
13176 Posix says that the @option{-w} might be interpreted as an
13177 implementation-specific option, not as a mode; Posix suggests
13178 using @samp{chmod -- -w file} to avoid this confusion, but unfortunately
13179 @samp{--} does not work on some older hosts.
13182 @item @command{cmp}
13183 @c ----------------
13184 @prindex @command{cmp}
13185 @command{cmp} performs a raw data comparison of two files, while
13186 @command{diff} compares two text files.  Therefore, if you might compare
13187 DOS files, even if only checking whether two files are different, use
13188 @command{diff} to avoid spurious differences due to differences of
13189 newline encoding.
13192 @item @command{cp}
13193 @c ---------------
13194 @prindex @command{cp}
13195 Avoid the @option{-r} option, since Posix 1003.1-2004 marks it as
13196 obsolescent and its behavior on special files is implementation-defined.
13197 Use @option{-R} instead.  On @acronym{GNU} hosts the two options
13198 are equivalent, but on Solaris hosts (for example) @command{cp -r}
13199 reads from pipes instead of replicating them.
13201 Some @command{cp} implementations (e.g., @acronym{BSD/OS} 4.2) do not allow
13202 trailing slashes at the end of nonexistent destination directories.  To
13203 avoid this problem, omit the trailing slashes.  For example, use
13204 @samp{cp -R source /tmp/newdir} rather than @samp{cp -R source
13205 /tmp/newdir/} if @file{/tmp/newdir} does not exist.
13207 @c This is thanks to Ian.
13208 The ancient SunOS 4 @command{cp} does not support @option{-f}, although
13209 its @command{mv} does.
13211 @cindex timestamp resolution
13212 Traditionally, file timestamps had 1-second resolution, and @samp{cp
13213 -p} copied the timestamps exactly.  However, many modern file systems
13214 have timestamps with 1-nanosecond resolution.  Unfortunately, @samp{cp
13215 -p} implementations truncate timestamps when copying files, so this
13216 can result in the destination file appearing to be older than the
13217 source.  The exact amount of truncation depends on the resolution of
13218 the system calls that @command{cp} uses; traditionally this was
13219 @code{utime}, which has 1-second resolution, but some newer
13220 @command{cp} implementations use @code{utimes}, which has
13221 1-microsecond resolution.  These newer implementations include @acronym{GNU}
13222 Core Utilities 5.0.91 or later, and Solaris 8 (sparc) patch 109933-02 or
13223 later.  Unfortunately as of January 2006 there is still no system
13224 call to set timestamps to the full nanosecond resolution.
13226 Bob Proulx notes that @samp{cp -p} always @emph{tries} to copy
13227 ownerships.  But whether it actually does copy ownerships or not is a
13228 system dependent policy decision implemented by the kernel.  If the
13229 kernel allows it then it happens.  If the kernel does not allow it then
13230 it does not happen.  It is not something @command{cp} itself has control
13231 over.
13233 In Unix System V any user can chown files to any other user, and System
13234 V also has a non-sticky @file{/tmp}.  That probably derives from the
13235 heritage of System V in a business environment without hostile users.
13236 @acronym{BSD} changed this
13237 to be a more secure model where only root can @command{chown} files and
13238 a sticky @file{/tmp} is used.  That undoubtedly derives from the heritage
13239 of @acronym{BSD} in a campus environment.
13241 @acronym{GNU}/Linux and Solaris by default follow @acronym{BSD}, but
13242 can be configured to allow a System V style @command{chown}.  On the
13243 other hand, @acronym{HP-UX} follows System V, but can
13244 be configured to use the modern security model and disallow
13245 @command{chown}.  Since it is an administrator-configurable parameter
13246 you can't use the name of the kernel as an indicator of the behavior.
13250 @item @command{date}
13251 @c -----------------
13252 @prindex @command{date}
13253 Some versions of @command{date} do not recognize special @samp{%} directives,
13254 and unfortunately, instead of complaining, they just pass them through,
13255 and exit with success:
13257 @example
13258 $ @kbd{uname -a}
13259 OSF1 medusa.sis.pasteur.fr V5.1 732 alpha
13260 $ @kbd{date "+%s"}
13262 @end example
13265 @item @command{diff}
13266 @c -----------------
13267 @prindex @command{diff}
13268 Option @option{-u} is nonportable.
13270 Some implementations, such as Tru64's, fail when comparing to
13271 @file{/dev/null}.  Use an empty file instead.
13274 @item @command{dirname}
13275 @c --------------------
13276 @prindex @command{dirname}
13277 Not all hosts have a working @command{dirname}, and you should instead
13278 use @code{AS_DIRNAME} (@pxref{Programming in M4sh}).  For example:
13280 @example
13281 dir=`dirname "$file"`       # This is not portable.
13282 dir=`AS_DIRNAME(["$file"])` # This is more portable.
13283 @end example
13286 @item @command{egrep}
13287 @c ------------------
13288 @prindex @command{egrep}
13289 Posix 1003.1-2001 no longer requires @command{egrep},
13290 but many older hosts do not yet support the Posix
13291 replacement @code{grep -E}.  Also, some traditional implementations do
13292 not work on long input lines.  To work around these problems, invoke
13293 @code{AC_PROG_EGREP} and then use @code{$EGREP}.
13295 Portable extended regular expressions should use @samp{\} only to escape
13296 characters in the string @samp{$()*+.?[\^@{|}.  For example, @samp{\@}}
13297 is not portable, even though it typically matches @samp{@}}.
13299 The empty alternative is not portable.  Use @samp{?} instead.  For
13300 instance with Digital Unix v5.0:
13302 @example
13303 > printf "foo\n|foo\n" | $EGREP '^(|foo|bar)$'
13304 |foo
13305 > printf "bar\nbar|\n" | $EGREP '^(foo|bar|)$'
13306 bar|
13307 > printf "foo\nfoo|\n|bar\nbar\n" | $EGREP '^(foo||bar)$'
13309 |bar
13310 @end example
13312 @command{$EGREP} also suffers the limitations of @command{grep}.
13314 @item @command{expr}
13315 @c -----------------
13316 @prindex @command{expr}
13317 No @command{expr} keyword starts with @samp{X}, so use @samp{expr
13318 X"@var{word}" : 'X@var{regex}'} to keep @command{expr} from
13319 misinterpreting @var{word}.
13321 Don't use @code{length}, @code{substr}, @code{match} and @code{index}.
13323 @item @command{expr} (@samp{|})
13324 @prindex @command{expr} (@samp{|})
13325 You can use @samp{|}.  Although Posix does require that @samp{expr
13326 ''} return the empty string, it does not specify the result when you
13327 @samp{|} together the empty string (or zero) with the empty string.  For
13328 example:
13330 @example
13331 expr '' \| ''
13332 @end example
13334 Posix 1003.2-1992 returns the empty string
13335 for this case, but traditional Unix returns @samp{0} (Solaris is
13336 one such example).  In Posix 1003.1-2001, the specification was
13337 changed to match traditional Unix's behavior (which is
13338 bizarre, but it's too late to fix this).  Please note that the same
13339 problem does arise when the empty string results from a computation,
13340 as in:
13342 @example
13343 expr bar : foo \| foo : bar
13344 @end example
13346 @noindent
13347 Avoid this portability problem by avoiding the empty string.
13350 @item @command{expr} (@samp{:})
13351 @c ----------------------------
13352 @prindex @command{expr}
13353 Portable @command{expr} regular expressions should use @samp{\} to
13354 escape only characters in the string @samp{$()*.0123456789[\^n@{@}}.
13355 For example, alternation, @samp{\|}, is common but Posix does not
13356 require its support, so it should be avoided in portable scripts.
13357 Similarly, @samp{\+} and @samp{\?} should be avoided.
13359 Portable @command{expr} regular expressions should not begin with
13360 @samp{^}.  Patterns are automatically anchored so leading @samp{^} is
13361 not needed anyway.
13363 The Posix standard is ambiguous as to whether
13364 @samp{expr 'a' : '\(b\)'} outputs @samp{0} or the empty string.
13365 In practice, it outputs the empty string on most platforms, but portable
13366 scripts should not assume this.  For instance, the @acronym{QNX} 4.25 native
13367 @command{expr} returns @samp{0}.
13369 One might think that a way to get a uniform behavior would be to use
13370 the empty string as a default value:
13372 @example
13373 expr a : '\(b\)' \| ''
13374 @end example
13376 @noindent
13377 Unfortunately this behaves exactly as the original expression; see the
13378 @command{expr} (@samp{|}) entry for more information.
13380 Ancient @command{expr} implementations (e.g., SunOS 4 @command{expr} and
13381 Solaris 8 @command{/usr/ucb/expr}) have a silly length limit that causes
13382 @command{expr} to fail if the matched substring is longer than 120
13383 bytes.  In this case, you might want to fall back on @samp{echo|sed} if
13384 @command{expr} fails.  Nowadays this is of practical importance only for
13385 the rare installer who mistakenly puts @file{/usr/ucb} before
13386 @file{/usr/bin} in @env{PATH}.
13388 On Mac OS X 10.4, @command{expr} mishandles the pattern @samp{[^-]} in
13389 some cases.  For example, the command
13390 @example
13391 expr Xpowerpc-apple-darwin8.1.0 : 'X[^-]*-[^-]*-\(.*\)'
13392 @end example
13394 @noindent
13395 outputs @samp{apple-darwin8.1.0} rather than the correct @samp{darwin8.1.0}.
13396 This particular case can be worked around by substituting @samp{[^--]}
13397 for @samp{[^-]}.
13399 Don't leave, there is some more!
13401 The @acronym{QNX} 4.25 @command{expr}, in addition of preferring @samp{0} to
13402 the empty string, has a funny behavior in its exit status: it's always 1
13403 when parentheses are used!
13405 @example
13406 $ @kbd{val=`expr 'a' : 'a'`; echo "$?: $val"}
13407 0: 1
13408 $ @kbd{val=`expr 'a' : 'b'`; echo "$?: $val"}
13409 1: 0
13411 $ @kbd{val=`expr 'a' : '\(a\)'`; echo "?: $val"}
13412 1: a
13413 $ @kbd{val=`expr 'a' : '\(b\)'`; echo "?: $val"}
13414 1: 0
13415 @end example
13417 @noindent
13418 In practice this can be a big problem if you are ready to catch failures
13419 of @command{expr} programs with some other method (such as using
13420 @command{sed}), since you may get twice the result.  For instance
13422 @example
13423 $ @kbd{expr 'a' : '\(a\)' || echo 'a' | sed 's/^\(a\)$/\1/'}
13424 @end example
13426 @noindent
13427 outputs @samp{a} on most hosts, but @samp{aa} on @acronym{QNX} 4.25.  A
13428 simple workaround consists of testing @command{expr} and using a variable
13429 set to @command{expr} or to @command{false} according to the result.
13431 Tru64 @command{expr} incorrectly treats the result as a number, if it
13432 can be interpreted that way:
13434 @example
13435 $ @kbd{expr 00001 : '.*\(...\)'}
13437 @end example
13440 @item @command{fgrep}
13441 @c ------------------
13442 @prindex @command{fgrep}
13443 Posix 1003.1-2001 no longer requires @command{fgrep},
13444 but many older hosts do not yet support the Posix
13445 replacement @code{grep -F}.  Also, some traditional implementations do
13446 not work on long input lines.  To work around these problems, invoke
13447 @code{AC_PROG_FGREP} and then use @code{$FGREP}.
13450 @item @command{find}
13451 @c -----------------
13452 @prindex @command{find}
13453 The option @option{-maxdepth} seems to be @acronym{GNU} specific.
13454 Tru64 v5.1, Net@acronym{BSD} 1.5 and Solaris @command{find}
13455 commands do not understand it.
13457 The replacement of @samp{@{@}} is guaranteed only if the argument is
13458 exactly @emph{@{@}}, not if it's only a part of an argument.  For
13459 instance on DU, and @acronym{HP-UX} 10.20 and @acronym{HP-UX} 11:
13461 @example
13462 $ @kbd{touch foo}
13463 $ @kbd{find . -name foo -exec echo "@{@}-@{@}" \;}
13464 @{@}-@{@}
13465 @end example
13467 @noindent
13468 while @acronym{GNU} @command{find} reports @samp{./foo-./foo}.
13471 @item @command{grep}
13472 @c -----------------
13473 @prindex @command{grep}
13474 Portable scripts can rely on the @command{grep} options @option{-c},
13475 @option{-l}, @option{-n}, and @option{-v}, but should avoid other
13476 options.  For example, don't use @option{-w}, as Posix does not require
13477 it and Irix 6.5.16m's @command{grep} does not support it.  Also,
13478 portable scripts should not combine @option{-c} with @option{-l},
13479 as Posix does not allow this.
13481 Some of the options required by Posix are not portable in practice.
13482 Don't use @samp{grep -q} to suppress output, because many @command{grep}
13483 implementations (e.g., Solaris) do not support @option{-q}.
13484 Don't use @samp{grep -s} to suppress output either, because Posix
13485 says @option{-s} does not suppress output, only some error messages;
13486 also, the @option{-s} option of traditional @command{grep} behaved
13487 like @option{-q} does in most modern implementations.  Instead,
13488 redirect the standard output and standard error (in case the file
13489 doesn't exist) of @code{grep} to @file{/dev/null}.  Check the exit
13490 status of @code{grep} to determine whether it found a match.
13492 Some traditional @command{grep} implementations do not work on long
13493 input lines.  On AIX the default @code{grep} silently truncates long
13494 lines on the input before matching.
13496 Also, many implementations do not support multiple regexps
13497 with @option{-e}: they either reject @option{-e} entirely (e.g., Solaris)
13498 or honor only the last pattern (e.g., @acronym{IRIX} 6.5 and NeXT).  To
13499 work around these problems, invoke @code{AC_PROG_GREP} and then use
13500 @code{$GREP}.
13502 Another possible workaround for the multiple @option{-e} problem is to
13503 separate the patterns by newlines, for example:
13505 @example
13506 grep 'foo
13507 bar' in.txt
13508 @end example
13510 @noindent
13511 except that this fails with traditional @command{grep}
13512 implementations and with Open@acronym{BSD} 3.8 @command{grep}.
13514 Traditional @command{grep} implementations (e.g., Solaris) do not
13515 support the @option{-E} or @option{-F} options.  To work around these
13516 problems, invoke @code{AC_PROG_EGREP} and then use @code{$EGREP}, and
13517 similarly for @code{AC_PROG_FGREP} and @code{$FGREP}.  Even if you are
13518 willing to require support for Posix @command{grep}, your script should
13519 not use both @option{-E} and @option{-F}, since Posix does not allow
13520 this combination.
13522 Portable @command{grep} regular expressions should use @samp{\} only to
13523 escape characters in the string @samp{$()*.0123456789[\^@{@}}.  For example,
13524 alternation, @samp{\|}, is common but Posix does not require its
13525 support in basic regular expressions, so it should be avoided in
13526 portable scripts.  Solaris @command{grep} does not support it.
13527 Similarly, @samp{\+} and @samp{\?} should be avoided.
13530 @item @command{join}
13531 @c -----------------
13532 @prindex @command{join}
13533 Solaris 8 @command{join} has bugs when the second operand is standard
13534 input, and when standard input is a pipe.  For example, the following
13535 shell script causes Solaris 8 @command{join} to loop forever:
13537 @example
13538 cat >file <<'EOF'
13539 1 x
13540 2 y
13542 cat file | join file -
13543 @end example
13545 Use @samp{join - file} instead.
13548 @item @command{ln}
13549 @c ---------------
13550 @prindex @command{ln}
13551 @cindex Symbolic links
13552 Don't rely on @command{ln} having a @option{-f} option.  Symbolic links
13553 are not available on old systems; use @samp{$(LN_S)} as a portable substitute.
13555 For versions of the @acronym{DJGPP} before 2.04,
13556 @command{ln} emulates symbolic links
13557 to executables by generating a stub that in turn calls the real
13558 program.  This feature also works with nonexistent files like in the
13559 Posix spec.  So @samp{ln -s file link} generates @file{link.exe},
13560 which attempts to call @file{file.exe} if run.  But this feature only
13561 works for executables, so @samp{cp -p} is used instead for these
13562 systems.  @acronym{DJGPP} versions 2.04 and later have full support
13563 for symbolic links.
13566 @item @command{ls}
13567 @c ---------------
13568 @prindex @command{ls}
13569 @cindex Listing directories
13570 The portable options are @option{-acdilrtu}.  Current practice is for
13571 @option{-l} to output both owner and group, even though ancient versions
13572 of @command{ls} omitted the group.
13574 On ancient hosts, @samp{ls foo} sent the diagnostic @samp{foo not found}
13575 to standard output if @file{foo} did not exist.  Hence a shell command
13576 like @samp{sources=`ls *.c 2>/dev/null`} did not always work, since it
13577 was equivalent to @samp{sources='*.c not found'} in the absence of
13578 @samp{.c} files.  This is no longer a practical problem, since current
13579 @command{ls} implementations send diagnostics to standard error.
13581 @item @command{mkdir}
13582 @c ------------------
13583 @prindex @command{mkdir}
13584 @cindex Making directories
13585 No @command{mkdir} option is portable to older systems.  Instead of
13586 @samp{mkdir -p @var{file-name}}, you should use
13587 @code{AS_MKDIR_P(@var{file-name})} (@pxref{Programming in M4sh})
13588 or @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs}).
13590 Combining the @option{-m} and @option{-p} options, as in @samp{mkdir -m
13591 go-w -p @var{dir}}, often leads to trouble.  Free@acronym{BSD}
13592 @command{mkdir} incorrectly attempts to change the permissions of
13593 @var{dir} even if it already exists.  @acronym{HP-UX} 11.23 and
13594 @acronym{IRIX} 6.5 @command{mkdir} often assign the wrong permissions to
13595 any newly-created parents of @var{dir}.
13597 Posix does not clearly specify whether @samp{mkdir -p foo}
13598 should succeed when @file{foo} is a symbolic link to an already-existing
13599 directory.  The @acronym{GNU} Core Utilities 5.1.0 @command{mkdir}
13600 succeeds, but Solaris @command{mkdir} fails.
13602 Traditional @code{mkdir -p} implementations suffer from race conditions.
13603 For example, if you invoke @code{mkdir -p a/b} and @code{mkdir -p a/c}
13604 at the same time, both processes might detect that @file{a} is missing,
13605 one might create @file{a}, then the other might try to create @file{a}
13606 and fail with a @code{File exists} diagnostic.  The @acronym{GNU} Core
13607 Utilities (@samp{fileutils} version 4.1), Free@acronym{BSD} 5.0,
13608 Net@acronym{BSD} 2.0.2, and Open@acronym{BSD} 2.4 are known to be
13609 race-free when two processes invoke @code{mkdir -p} simultaneously, but
13610 earlier versions are vulnerable.  Solaris @command{mkdir} is still
13611 vulnerable as of Solaris 10, and other traditional Unix systems are
13612 probably vulnerable too.  This possible race is harmful in parallel
13613 builds when several Make rules call @code{mkdir -p} to
13614 construct directories.  You may use
13615 @code{install-sh -d} as a safe replacement, provided this script is
13616 recent enough; the copy shipped with Autoconf 2.60 and Automake 1.10 is
13617 OK, but copies from older versions are vulnerable.
13620 @item @command{mktemp}
13621 @c -------------------
13622 @prindex @command{mktemp}
13623 @cindex Creating temporary files
13624 Shell scripts can use temporary files safely with @command{mktemp}, but
13625 it does not exist on all systems.  A portable way to create a safe
13626 temporary file name is to create a temporary directory with mode 700 and
13627 use a file inside this directory.  Both methods prevent attackers from
13628 gaining control, though @command{mktemp} is far less likely to fail
13629 gratuitously under attack.
13631 Here is sample code to create a new temporary directory safely:
13633 @example
13634 # Create a temporary directory $tmp in $TMPDIR (default /tmp).
13635 # Use mktemp if possible; otherwise fall back on mkdir,
13636 # with $RANDOM to make collisions less likely.
13637 : $@{TMPDIR=/tmp@}
13639   tmp=`
13640     (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
13641   ` &&
13642   test -n "$tmp" && test -d "$tmp"
13643 @} || @{
13644   tmp=$TMPDIR/foo$$-$RANDOM
13645   (umask 077 && mkdir "$tmp")
13646 @} || exit $?
13647 @end example
13650 @item @command{mv}
13651 @c ---------------
13652 @prindex @command{mv}
13653 @cindex Moving open files
13654 The only portable options are @option{-f} and @option{-i}.
13656 Moving individual files between file systems is portable (it was in Unix
13657 version 6),
13658 but it is not always atomic: when doing @samp{mv new existing}, there's
13659 a critical section where neither the old nor the new version of
13660 @file{existing} actually exists.
13662 On some systems moving files from @file{/tmp} can sometimes cause
13663 undesirable (but perfectly valid) warnings, even if you created these
13664 files.  This is because @file{/tmp} belongs to a group that ordinary
13665 users are not members of, and files created in @file{/tmp} inherit
13666 the group of @file{/tmp}.  When the file is copied, @command{mv} issues
13667 a diagnostic without failing:
13669 @smallexample
13670 $ @kbd{touch /tmp/foo}
13671 $ @kbd{mv /tmp/foo .}
13672 @error{}mv: ./foo: set owner/group (was: 100/0): Operation not permitted
13673 $ @kbd{echo $?}
13675 $ @kbd{ls foo}
13677 @end smallexample
13679 @noindent
13680 This annoying behavior conforms to Posix, unfortunately.
13682 Moving directories across mount points is not portable, use @command{cp}
13683 and @command{rm}.
13685 @acronym{DOS} variants cannot rename or remove open files, and do not
13686 support commands like @samp{mv foo bar >foo}, even though this is
13687 perfectly portable among Posix hosts.
13690 @item @command{od}
13691 @c ---------------
13692 @prindex @command{od}
13694 In Mac OS X 10.3, @command{od} does not support the
13695 standard Posix options @option{-A}, @option{-j}, @option{-N}, or
13696 @option{-t}, or the @acronym{XSI} option @option{-s}.  The only
13697 supported Posix option is @option{-v}, and the only supported
13698 @acronym{XSI} options are those in @option{-bcdox}.  The @acronym{BSD}
13699 @command{hexdump} program can be used instead.
13701 This problem no longer exists in Mac OS X 10.4.3.
13704 @item @command{rm}
13705 @c ---------------
13706 @prindex @command{rm}
13707 The @option{-f} and @option{-r} options are portable.
13709 It is not portable to invoke @command{rm} without operands.  For
13710 example, on many systems @samp{rm -f -r} (with no other arguments)
13711 silently succeeds without doing anything, but it fails with a diagnostic
13712 on Net@acronym{BSD} 2.0.2.
13714 A file might not be removed even if its parent directory is writable
13715 and searchable.  Many Posix hosts cannot remove a mount point, a named
13716 stream, a working directory, or a last link to a file that is being
13717 executed.
13719 @acronym{DOS} variants cannot rename or remove open files, and do not
13720 support commands like @samp{rm foo >foo}, even though this is
13721 perfectly portable among Posix hosts.
13724 @item @command{sed}
13725 @c ----------------
13726 @prindex @command{sed}
13727 Patterns should not include the separator (unless escaped), even as part
13728 of a character class.  In conformance with Posix, the Cray
13729 @command{sed} rejects @samp{s/[^/]*$//}: use @samp{s,[^/]*$,,}.
13731 Avoid empty patterns within parentheses (i.e., @samp{\(\)}).  Posix does
13732 not require support for empty patterns, and Unicos 9 @command{sed} rejects
13733 them.
13735 Unicos 9 @command{sed} loops endlessly on patterns like @samp{.*\n.*}.
13737 Sed scripts should not use branch labels longer than 7 characters and
13738 should not contain comments.  @acronym{HP-UX} sed has a limit of 99 commands
13739 (not counting @samp{:} commands) and
13740 48 labels, which can not be circumvented by using more than one script
13741 file.  It can execute up to 19 reads with the @samp{r} command per cycle.
13742 Solaris @command{/usr/ucb/sed} rejects usages that exceed an limit of
13743 about 6000 bytes for the internal representation of commands.
13745 Avoid redundant @samp{;}, as some @command{sed} implementations, such as
13746 Net@acronym{BSD} 1.4.2's, incorrectly try to interpret the second
13747 @samp{;} as a command:
13749 @example
13750 $ @kbd{echo a | sed 's/x/x/;;s/x/x/'}
13751 sed: 1: "s/x/x/;;s/x/x/": invalid command code ;
13752 @end example
13754 Input should not have unreasonably long lines, since some @command{sed}
13755 implementations have an input buffer limited to 4000 bytes.
13757 Portable @command{sed} regular expressions should use @samp{\} only to escape
13758 characters in the string @samp{$()*.0123456789[\^n@{@}}.  For example,
13759 alternation, @samp{\|}, is common but Posix does not require its
13760 support, so it should be avoided in portable scripts.  Solaris
13761 @command{sed} does not support alternation; e.g., @samp{sed '/a\|b/d'}
13762 deletes only lines that contain the literal string @samp{a|b}.
13763 Similarly, @samp{\+} and @samp{\?} should be avoided.
13765 Anchors (@samp{^} and @samp{$}) inside groups are not portable.
13767 Nested parentheses in patterns (e.g., @samp{\(\(a*\)b*)\)}) are
13768 quite portable to current hosts, but was not supported by some ancient
13769 @command{sed} implementations like SVR3.
13771 Some @command{sed} implementations, e.g., Solaris,
13772 restrict the special role of the asterisk to one-character regular expressions.
13773 This may lead to unexpected behavior:
13775 @example
13776 $ @kbd{echo '1*23*4' | /usr/bin/sed 's/\(.\)*/x/g'}
13777 x2x4
13778 $ @kbd{echo '1*23*4' | /usr/xpg4/bin/sed 's/\(.\)*/x/g'}
13780 @end example
13782 The @option{-e} option is portable, so long as its argument
13783 does not begin with @samp{a}, @samp{c}, or @samp{i}
13784 (as this runs afoul of a Tru64 5.1 bug).
13785 Some people prefer to use @samp{-e}:
13787 @example
13788 sed -e '@var{command-1}' \
13789     -e '@var{command-2}'
13790 @end example
13792 @noindent
13793 as opposed to the equivalent:
13795 @example
13796 sed '
13797   @var{command-1}
13798   @var{command-2}
13800 @end example
13802 @noindent
13803 The following usage is sometimes equivalent:
13805 @example
13806 sed '@var{command-1};@var{command-2}'
13807 @end example
13809 but Posix says that this use of a semicolon has undefined effect if
13810 @var{command-1}'s verb is @samp{@{}, @samp{a}, @samp{b}, @samp{c},
13811 @samp{i}, @samp{r}, @samp{t}, @samp{w}, @samp{:}, or @samp{#}, so you
13812 should use semicolon only with simple scripts that do not use these
13813 verbs.
13815 Commands inside @{ @} brackets are further restricted.  Posix says that
13816 they cannot be preceded by addresses, @samp{!}, or @samp{;}, and that
13817 each command must be followed immediately by a newline, without any
13818 intervening blanks or semicolons.  The closing bracket must be alone on
13819 a line, other than white space preceding or following it.
13821 Contrary to yet another urban legend, you may portably use @samp{&} in
13822 the replacement part of the @code{s} command to mean ``what was
13823 matched''.  All descendants of Unix version 7 @command{sed}
13824 (at least; we
13825 don't have first hand experience with older @command{sed} implementations) have
13826 supported it.
13828 Posix requires that you must not have any white space between
13829 @samp{!} and the following command.  It is OK to have blanks between
13830 the address and the @samp{!}.  For instance, on Solaris:
13832 @example
13833 $ @kbd{echo "foo" | sed -n '/bar/ ! p'}
13834 @error{}Unrecognized command: /bar/ ! p
13835 $ @kbd{echo "foo" | sed -n '/bar/! p'}
13836 @error{}Unrecognized command: /bar/! p
13837 $ @kbd{echo "foo" | sed -n '/bar/ !p'}
13839 @end example
13841 Posix also says that you should not combine @samp{!} and @samp{;}.  If
13842 you use @samp{!}, it is best to put it on a command that is delimited by
13843 newlines rather than @samp{;}.
13845 Also note that Posix requires that the @samp{b}, @samp{t}, @samp{r}, and
13846 @samp{w} commands be followed by exactly one space before their argument.
13847 On the other hand, no white space is allowed between @samp{:} and the
13848 subsequent label name.
13850 If a sed script is specified on the command line and ends in an
13851 @samp{a}, @samp{c}, or @samp{i} command, the last line of inserted text
13852 should be followed by a newline.  Otherwise some @command{sed}
13853 implementations (e.g., Open@acronym{BSD} 3.9) do not append a newline to the
13854 inserted text.
13856 Many @command{sed} implementations (e.g., MacOS X 10.4,
13857 Open@acronym{BSD} 3.9, Solaris 10
13858 @command{/usr/ucb/sed}) strip leading white space from the text of
13859 @samp{a}, @samp{c}, and @samp{i} commands.  Prepend a backslash to
13860 work around this incompatibility with Posix:
13862 @example
13863 $ @kbd{echo flushleft | sed 'a\}
13864 > @kbd{   indented}
13865 > @kbd{'}
13866 flushleft
13867 indented
13868 $ @kbd{echo foo | sed 'a\}
13869 > @kbd{\   indented}
13870 > @kbd{'}
13871 flushleft
13872    indented
13873 @end example
13876 @item @command{sed} (@samp{t})
13877 @c ---------------------------
13878 @prindex @command{sed} (@samp{t})
13879 Some old systems have @command{sed} that ``forget'' to reset their
13880 @samp{t} flag when starting a new cycle.  For instance on @acronym{MIPS
13881 RISC/OS}, and on @sc{irix} 5.3, if you run the following @command{sed}
13882 script (the line numbers are not actual part of the texts):
13884 @example
13885 s/keep me/kept/g  # a
13886 t end             # b
13887 s/.*/deleted/g    # c
13888 :end              # d
13889 @end example
13891 @noindent
13894 @example
13895 delete me         # 1
13896 delete me         # 2
13897 keep me           # 3
13898 delete me         # 4
13899 @end example
13901 @noindent
13902 you get
13904 @example
13905 deleted
13906 delete me
13907 kept
13908 deleted
13909 @end example
13911 @noindent
13912 instead of
13914 @example
13915 deleted
13916 deleted
13917 kept
13918 deleted
13919 @end example
13921 Why?  When processing line 1, (c) matches, therefore sets the @samp{t}
13922 flag, and the output is produced.  When processing
13923 line 2, the @samp{t} flag is still set (this is the bug).  Command (a)
13924 fails to match, but @command{sed} is not supposed to clear the @samp{t}
13925 flag when a substitution fails.  Command (b) sees that the flag is set,
13926 therefore it clears it, and jumps to (d), hence you get @samp{delete me}
13927 instead of @samp{deleted}.  When processing line (3), @samp{t} is clear,
13928 (a) matches, so the flag is set, hence (b) clears the flags and jumps.
13929 Finally, since the flag is clear, line 4 is processed properly.
13931 There are two things one should remember about @samp{t} in @command{sed}.
13932 Firstly, always remember that @samp{t} jumps if @emph{some} substitution
13933 succeeded, not only the immediately preceding substitution.  Therefore,
13934 always use a fake @samp{t clear} followed by a @samp{:clear} on the next
13935 line, to reset the @samp{t} flag where needed.
13937 Secondly, you cannot rely on @command{sed} to clear the flag at each new
13938 cycle.
13940 One portable implementation of the script above is:
13942 @example
13943 t clear
13944 :clear
13945 s/keep me/kept/g
13946 t end
13947 s/.*/deleted/g
13948 :end
13949 @end example
13951 @item @command{touch}
13952 @c ------------------
13953 @prindex @command{touch}
13954 @cindex timestamp resolution
13955 If you specify the desired timestamp (e.g., with the @option{-r}
13956 option), @command{touch} typically uses the @code{utime} or
13957 @code{utimes} system call, which can result in the same kind of
13958 timestamp truncation problems that @samp{cp -p} has.
13960 On ancient @acronym{BSD} systems, @command{touch} or any command that
13961 results in an empty file does not update the timestamps, so use a
13962 command like @command{echo} as a workaround.
13963 Also,
13964 @acronym{GNU} @command{touch} 3.16r (and presumably all before that)
13965 fails to work on SunOS 4.1.3 when the empty file is on an
13966 @acronym{NFS}-mounted 4.2 volume.
13967 However, these problems are no longer of practical concern.
13969 @end table
13972 @node Portable Make
13973 @chapter Portable Make Programming
13974 @prindex @command{make}
13975 @cindex Limitations of @command{make}
13977 Writing portable makefiles is an art.  Since a makefile's commands are
13978 executed by the shell, you must consider the shell portability issues
13979 already mentioned.  However, other issues are specific to @command{make}
13980 itself.
13982 @menu
13983 * $< in Ordinary Make Rules::   $< in ordinary rules
13984 * Failure in Make Rules::       Failing portably in rules
13985 * Special Chars in Names::      Special Characters in Macro Names
13986 * Backslash-Newline-Newline::   Empty last lines in macro definitions
13987 * Backslash-Newline Comments::  Spanning comments across line boundaries
13988 * Long Lines in Makefiles::     Line length limitations
13989 * Macros and Submakes::         @code{make macro=value} and submakes
13990 * The Make Macro MAKEFLAGS::    @code{$(MAKEFLAGS)} portability issues
13991 * The Make Macro SHELL::        @code{$(SHELL)} portability issues
13992 * Comments in Make Rules::      Other problems with Make comments
13993 * obj/ and Make::               Don't name a subdirectory @file{obj}
13994 * make -k Status::              Exit status of @samp{make -k}
13995 * VPATH and Make::              @code{VPATH} woes
13996 * Single Suffix Rules::         Single suffix rules and separated dependencies
13997 * Timestamps and Make::         Subsecond timestamp resolution
13998 @end menu
14000 @node $< in Ordinary Make Rules
14001 @section @code{$<} in Ordinary Make Rules
14003 Posix says that the @samp{$<} construct in makefiles can be
14004 used only in inference rules and in the @samp{.DEFAULT} rule; its
14005 meaning in ordinary rules is unspecified.  Solaris @command{make}
14006 for instance replaces it with the empty string.  Open@acronym{BSD} (3.0 and
14007 later) @command{make} diagnoses these uses and errors out.
14009 @node Failure in Make Rules
14010 @section Failure in Make Rules
14012 Since 1992 Posix has required that @command{make} must invoke
14013 each command with the equivalent of a @samp{sh -c} subshell.  However,
14014 many @command{make} implementations, including @acronym{BSD} make through 2004,
14015 use @samp{sh -e -c} instead, and the @option{-e} option causes the
14016 subshell to exit immediately if a subsidiary simple-command fails.  For
14017 example, the command @samp{touch T; rm -f U} always attempts to
14018 remove @file{U} with Posix make, but incompatible
14019 @command{make} implementations skip the @command{rm} if the
14020 @command{touch} fails.  One way to work around this is to reword the
14021 affected simple-commands so that they always succeed, e.g., @samp{touch
14022 T || :; rm -f U}.
14023 However, even this approach can run into common bugs in @acronym{BSD}
14024 implementations of the @option{-e} option of @command{sh} and
14025 @command{set} (@pxref{Limitations of Builtins}), so if you are worried
14026 about porting to buggy @acronym{BSD} shells it may be simpler to migrate
14027 complicated @command{make} actions into separate scripts.
14029 @node Special Chars in Names
14030 @section Special Characters in Make Macro Names
14032 Posix limits macro names to nonempty strings containing only
14033 @acronym{ASCII} letters and digits, @samp{.}, and @samp{_}.  Many
14034 @command{make} implementations allow a wider variety of characters, but
14035 portable makefiles should avoid them.  It is portable to start a name
14036 with a special character, e.g., @samp{$(.FOO)}.
14038 Some ancient @command{make} implementations don't support leading
14039 underscores in macro names.  An example is @acronym{NEWS-OS} 4.2R.
14041 @example
14042 $ @kbd{cat Makefile}
14043 _am_include = #
14044 _am_quote =
14045 all:; @@echo this is test
14046 $ @kbd{make}
14047 Make: Must be a separator on rules line 2.  Stop.
14048 $ @kbd{cat Makefile2}
14049 am_include = #
14050 am_quote =
14051 all:; @@echo this is test
14052 $ @kbd{make -f Makefile2}
14053 this is test
14054 @end example
14056 @noindent
14057 However, this problem is no longer of practical concern.
14059 @node Backslash-Newline-Newline
14060 @section Backslash-Newline-Newline in Make Macro Values
14062 @c  This has been seen on ia64 hpux 11.20, and on one hppa hpux 10.20,
14063 @c  but another hppa hpux 10.20 didn't have it.  Bob Proulx
14064 @c  <bob@proulx.com> thinks it was in hpux 8.0 too.
14065 On some versions of @acronym{HP-UX}, @command{make} reads multiple newlines
14066 following a backslash, continuing to the next non-empty line.  For
14067 example,
14069 @example
14070 FOO = one \
14072 BAR = two
14074 test:
14075         : FOO is "$(FOO)"
14076         : BAR is "$(BAR)"
14077 @end example
14079 @noindent
14080 shows @code{FOO} equal to @code{one BAR = two}.  Other implementations
14081 sensibly let a backslash continue only to the immediately following
14082 line.
14084 @node Backslash-Newline Comments
14085 @section Backslash-Newline in Make Comments
14087 According to Posix, Make comments start with @code{#}
14088 and continue until an unescaped newline is reached.
14090 @example
14091 $ @kbd{cat Makefile}
14092 # A = foo \
14093       bar \
14094       baz
14096 all:
14097         @@echo ok
14098 $ @kbd{make}   # GNU make
14100 @end example
14102 @noindent
14103 However this is not always the case.  Some implementations
14104 discard everything from @code{#} through the end of the line, ignoring any
14105 trailing backslash.
14107 @example
14108 $ @kbd{pmake}  # BSD make
14109 "Makefile", line 3: Need an operator
14110 Fatal errors encountered -- cannot continue
14111 @end example
14113 @noindent
14114 Therefore, if you want to comment out a multi-line definition, prefix each
14115 line with @code{#}, not only the first.
14117 @example
14118 # A = foo \
14119 #     bar \
14120 #     baz
14121 @end example
14123 @node Long Lines in Makefiles
14124 @section Long Lines in Makefiles
14126 Tru64 5.1's @command{make} has been reported to crash when given a
14127 makefile with lines longer than around 20 kB.  Earlier versions are
14128 reported to exit with @code{Line too long} diagnostics.
14130 @node Macros and Submakes
14131 @section @code{make macro=value} and Submakes
14133 A command-line variable definition such as @code{foo=bar} overrides any
14134 definition of @code{foo} in a makefile.  Some @command{make}
14135 implementations (such as @acronym{GNU} @command{make}) propagate this
14136 override to subsidiary invocations of @command{make}.  Some other
14137 implementations do not pass the substitution along to submakes.
14139 @example
14140 $ @kbd{cat Makefile}
14141 foo = foo
14142 one:
14143         @@echo $(foo)
14144         $(MAKE) two
14145 two:
14146         @@echo $(foo)
14147 $ @kbd{make foo=bar}            # GNU make 3.79.1
14149 make two
14150 make[1]: Entering directory `/home/adl'
14152 make[1]: Leaving directory `/home/adl'
14153 $ @kbd{pmake foo=bar}           # BSD make
14155 pmake two
14157 @end example
14159 You have a few possibilities if you do want the @code{foo=bar} override
14160 to propagate to submakes.  One is to use the @option{-e}
14161 option, which causes all environment variables to have precedence over
14162 the makefile macro definitions, and declare foo as an environment
14163 variable:
14165 @example
14166 $ @kbd{env foo=bar make -e}
14167 @end example
14169 The @option{-e} option is propagated to submakes automatically,
14170 and since the environment is inherited between @command{make}
14171 invocations, the @code{foo} macro is overridden in
14172 submakes as expected.
14174 This syntax (@code{foo=bar make -e}) is portable only when used
14175 outside of a makefile, for instance from a script or from the
14176 command line.  When run inside a @command{make} rule, @acronym{GNU}
14177 @command{make} 3.80 and prior versions forget to propagate the
14178 @option{-e} option to submakes.
14180 Moreover, using @option{-e} could have unexpected side effects if your
14181 environment contains some other macros usually defined by the
14182 makefile.  (See also the note about @code{make -e} and @code{SHELL}
14183 below.)
14185 Another way to propagate overrides to submakes is to do it
14186 manually, from your makefile:
14188 @example
14189 foo = foo
14190 one:
14191         @@echo $(foo)
14192         $(MAKE) foo=$(foo) two
14193 two:
14194         @@echo $(foo)
14195 @end example
14197 You need to foresee all macros that a user might want to override if
14198 you do that.
14200 @node The Make Macro MAKEFLAGS
14201 @section The Make Macro MAKEFLAGS
14202 @cindex @code{MAKEFLAGS} and @command{make}
14203 @cindex @command{make} and @code{MAKEFLAGS}
14205 Posix requires @command{make} to use @code{MAKEFLAGS} to affect the
14206 current and recursive invocations of make, but allows implementations
14207 several formats for the variable.  It is tricky to parse
14208 @code{$MAKEFLAGS} to determine whether @option{-s} for silent execution
14209 or @option{-k} for continued execution are in effect.  For example, you
14210 cannot assume that the first space-separated word in @code{$MAKEFLAGS}
14211 contains single-letter options, since in the Cygwin version of
14212 @acronym{GNU} @command{make} it is either @option{--unix} or
14213 @option{--win32} with the second word containing single-letter options.
14215 @example
14216 $ @kbd{cat Makefile}
14217 all:
14218         @@echo MAKEFLAGS = $(MAKEFLAGS)
14219 $ @kbd{make}
14220 MAKEFLAGS = --unix
14221 $ @kbd{make -k}
14222 MAKEFLAGS = --unix -k
14223 @end example
14225 @node The Make Macro SHELL
14226 @section The Make Macro @code{SHELL}
14227 @cindex @code{SHELL} and @command{make}
14228 @cindex @command{make} and @code{SHELL}
14230 Posix-compliant @command{make} internally uses the @code{$(SHELL)}
14231 macro to spawn shell processes and execute Make rules.  This
14232 is a builtin macro supplied by @command{make}, but it can be modified
14233 by a makefile or by a command-line argument.
14235 Not all @command{make} implementations define this @code{SHELL} macro.
14236 Tru64
14237 @command{make} is an example; this implementation always uses
14238 @code{/bin/sh}.  So it's a good idea to always define @code{SHELL} in
14239 your makefiles.  If you use Autoconf, do
14241 @example
14242 SHELL = @@SHELL@@
14243 @end example
14245 Do not force @code{SHELL = /bin/sh} because that is not correct
14246 everywhere.  For instance @acronym{DJGPP} lacks @code{/bin/sh}, and when
14247 its @acronym{GNU} @code{make} port sees such a setting it enters a special
14248 emulation mode where features like pipes and redirections are emulated
14249 on top of DOS's @command{command.com}.  Unfortunately this emulation is
14250 incomplete; for instance it does not handle command substitutions.
14251 On @acronym{DJGPP} @code{SHELL} should point to Bash.
14253 Posix-compliant @command{make} should never acquire the value of
14254 $(SHELL) from the environment, even when @code{make -e} is used
14255 (otherwise, think about what would happen to your rules if
14256 @code{SHELL=/bin/tcsh}).
14258 However not all @command{make} implementations have this exception.
14259 For instance it's not surprising that Tru64 @command{make} doesn't
14260 protect @code{SHELL}, since it doesn't use it.
14262 @example
14263 $ @kbd{cat Makefile}
14264 SHELL = /bin/sh
14265 FOO = foo
14266 all:
14267         @@echo $(SHELL)
14268         @@echo $(FOO)
14269 $ @kbd{env SHELL=/bin/tcsh FOO=bar make -e}   # Tru64 Make
14270 /bin/tcsh
14272 $ @kbd{env SHELL=/bin/tcsh FOO=bar gmake -e}  # GNU make
14273 /bin/sh
14275 @end example
14277 @node Comments in Make Rules
14278 @section Comments in Make Rules
14279 @cindex Comments in @file{Makefile} rules
14280 @cindex @file{Makefile} rules and comments
14282 Never put comments in a rule.
14284 Some @command{make} treat anything starting with a tab as a command for
14285 the current rule, even if the tab is immediately followed by a @code{#}.
14286 The @command{make} from Tru64 Unix V5.1 is one of them.  The following
14287 makefile runs @code{# foo} through the shell.
14289 @example
14290 all:
14291         # foo
14292 @end example
14294 @node obj/ and Make
14295 @section The @file{obj/} Subdirectory and Make
14296 @cindex @file{obj/}, subdirectory
14297 @cindex @acronym{BSD} @command{make} and @file{obj/}
14299 Never name one of your subdirectories @file{obj/} if you don't like
14300 surprises.
14302 If an @file{obj/} directory exists, @acronym{BSD} @command{make} enters it
14303 before reading the makefile.  Hence the makefile in the
14304 current directory is not read.
14306 @example
14307 $ @kbd{cat Makefile}
14308 all:
14309         echo Hello
14310 $ @kbd{cat obj/Makefile}
14311 all:
14312         echo World
14313 $ @kbd{make}      # GNU make
14314 echo Hello
14315 Hello
14316 $ @kbd{pmake}     # BSD make
14317 echo World
14318 World
14319 @end example
14321 @node make -k Status
14322 @section Exit Status of @code{make -k}
14323 @cindex @code{make -k}
14325 Do not rely on the exit status of @code{make -k}.  Some implementations
14326 reflect whether they encountered an error in their exit status; other
14327 implementations always succeed.
14329 @example
14330 $ @kbd{cat Makefile}
14331 all:
14332         false
14333 $ @kbd{make -k; echo exit status: $?}    # GNU make
14334 false
14335 make: *** [all] Error 1
14336 exit status: 2
14337 $ @kbd{pmake -k; echo exit status: $?}   # BSD make
14338 false
14339 *** Error code 1 (continuing)
14340 exit status: 0
14341 @end example
14343 @node VPATH and Make
14344 @section @code{VPATH} and Make
14345 @cindex @code{VPATH}
14347 Posix does not specify the semantics of @code{VPATH}.  Typically,
14348 @command{make} supports @code{VPATH}, but its implementation is not
14349 consistent.
14351 Autoconf and Automake support makefiles whose usages of @code{VPATH} are
14352 portable to recent-enough popular implementations of @command{make}, but
14353 to keep the resulting makefiles portable, a package's makefile
14354 prototypes must take the following issues into account.  These issues
14355 are complicated and are often poorly understood, and installers who use
14356 @code{VPATH} should expect to find many bugs in this area.  If you use
14357 @code{VPATH}, the simplest way to avoid these portability bugs is to
14358 stick with @acronym{GNU} @command{make}, since it is the most
14359 commonly-used @command{make} among Autoconf users.
14361 Here are some known issues with some @code{VPATH}
14362 implementations.
14364 @menu
14365 * VPATH and Double-colon::      Problems with @samp{::} on ancient hosts
14366 * $< in Explicit Rules::        @code{$<} does not work in ordinary rules
14367 * Automatic Rule Rewriting::    @code{VPATH} goes wild on Solaris
14368 * Tru64 Directory Magic::       @command{mkdir} goes wild on Tru64
14369 * Make Target Lookup::          More details about @code{VPATH} lookup
14370 @end menu
14372 @node VPATH and Double-colon
14373 @subsection @code{VPATH} and Double-colon Rules
14374 @cindex @code{VPATH} and double-colon rules
14375 @cindex double-colon rules and @code{VPATH}
14377 With ancient versions of Sun @command{make},
14378 any assignment to @code{VPATH} causes @command{make} to execute only
14379 the first set of double-colon rules.
14380 However, this problem is no longer of practical concern.
14382 @node $< in Explicit Rules
14383 @subsection @code{$<} Not Supported in Explicit Rules
14384 @cindex explicit rules, @code{$<}, and @code{VPATH}
14385 @cindex @code{$<}, explicit rules, and @code{VPATH}
14386 @cindex @code{VPATH}, explicit rules, and @code{$<}
14388 Using @code{$<} in explicit rules is not portable.
14389 The prerequisite file must be named explicitly in the rule.  If you want
14390 to find the prerequisite via a @code{VPATH} search, you have to code the
14391 whole thing manually.  @xref{Build Directories}.
14393 @node Automatic Rule Rewriting
14394 @subsection Automatic Rule Rewriting
14395 @cindex @code{VPATH} and automatic rule rewriting
14396 @cindex automatic rule rewriting and @code{VPATH}
14398 Some @command{make} implementations, such as Solaris and Tru64,
14399 search for prerequisites in @code{VPATH} and
14400 then rewrite each occurrence as a plain word in the rule.
14401 For instance:
14403 @example
14404 # This isn't portable to GNU make.
14405 VPATH = ../pkg/src
14406 f.c: if.c
14407         cp if.c f.c
14408 @end example
14410 @noindent
14411 executes @code{cp ../pkg/src/if.c f.c} if @file{if.c} is
14412 found in @file{../pkg/src}.
14414 However, this rule leads to real problems in practice.  For example, if
14415 the source directory contains an ordinary file named @file{test} that is
14416 used in a dependency, Solaris @command{make} rewrites commands like
14417 @samp{if test -r foo; @dots{}} to @samp{if ../pkg/src/test -r foo;
14418 @dots{}}, which is typically undesirable.  To avoid this problem,
14419 portable makefiles should never mention a source file whose name is that
14420 of a shell keyword like @file{until} or a shell command like
14421 @command{cat} or @command{gcc} or @command{test}.
14423 Because of these problems @acronym{GNU} @command{make} and many other
14424 @command{make} implementations do not rewrite commands, so portable
14425 makefiles should
14426 search @code{VPATH} manually.  It is tempting to write this:
14428 @smallexample
14429 # This isn't portable to Solaris make.
14430 VPATH = ../pkg/src
14431 f.c: if.c
14432         cp `test -f if.c || echo $(VPATH)/`if.c f.c
14433 @end smallexample
14435 @noindent
14436 However, the ``prerequisite rewriting'' still applies here.  So if
14437 @file{if.c} is in @file{../pkg/src}, Solaris and Tru64 @command{make}
14438 execute
14440 @smallexample
14441 cp `test -f ../pkg/src/if.c || echo ../pkg/src/`if.c f.c
14442 @end smallexample
14444 @noindent
14445 which reduces to
14447 @example
14448 cp if.c f.c
14449 @end example
14451 @noindent
14452 and thus fails.  Oops.
14454 A simple workaround, and good practice anyway, is to use @samp{$?} and
14455 @samp{$@@} when possible:
14457 @smallexample
14458 VPATH = ../pkg/src
14459 f.c: if.c
14460         cp $? $@@
14461 @end smallexample
14463 @noindent
14464 but this does not generalize well to commands with multiple
14465 prerequisites.  A more general workaround is to rewrite the rule so that
14466 the prerequisite @file{if.c} never appears as a plain word.  For
14467 example, these three rules would be safe, assuming @file{if.c} is in
14468 @file{../pkg/src} and the other files are in the working directory:
14470 @smallexample
14471 VPATH = ../pkg/src
14472 f.c: if.c f1.c
14473         cat `test -f ./if.c || echo $(VPATH)/`if.c f1.c >$@@
14474 g.c: if.c g1.c
14475         cat `test -f 'if.c' || echo $(VPATH)/`if.c g1.c >$@@
14476 h.c: if.c h1.c
14477         cat `test -f "if.c" || echo $(VPATH)/`if.c h1.c >$@@
14478 @end smallexample
14480 Things get worse when your prerequisites are in a macro.
14482 @example
14483 VPATH = ../pkg/src
14484 HEADERS = f.h g.h h.h
14485 install-HEADERS: $(HEADERS)
14486         for i in $(HEADERS); do \
14487           $(INSTALL) -m 644 \
14488             `test -f $$i || echo $(VPATH)/`$$i \
14489             $(DESTDIR)$(includedir)/$$i; \
14490         done
14491 @end example
14493 The above @code{install-HEADERS} rule is not Solaris-proof because @code{for
14494 i in $(HEADERS);} is expanded to @code{for i in f.h g.h h.h;}
14495 where @code{f.h} and @code{g.h} are plain words and are hence
14496 subject to @code{VPATH} adjustments.
14498 If the three files are in @file{../pkg/src}, the rule is run as:
14500 @example
14501 for i in ../pkg/src/f.h ../pkg/src/g.h h.h; do \
14502   install -m 644 \
14503      `test -f $i || echo ../pkg/src/`$i \
14504      /usr/local/include/$i; \
14505 done
14506 @end example
14508 where the two first @command{install} calls fail.  For instance,
14509 consider the @code{f.h} installation:
14511 @example
14512 install -m 644 \
14513   `test -f ../pkg/src/f.h || \
14514     echo ../pkg/src/ \
14515   `../pkg/src/f.h \
14516   /usr/local/include/../pkg/src/f.h;
14517 @end example
14519 @noindent
14520 It reduces to:
14522 @example
14523 install -m 644 \
14524   ../pkg/src/f.h \
14525   /usr/local/include/../pkg/src/f.h;
14526 @end example
14528 Note that the manual @code{VPATH} search did not cause any problems here;
14529 however this command installs @file{f.h} in an incorrect directory.
14531 Trying to quote @code{$(HEADERS)} in some way, as we did for
14532 @code{foo.c} a few makefiles ago, does not help:
14534 @example
14535 install-HEADERS: $(HEADERS)
14536         headers='$(HEADERS)'; \
14537         for i in $$headers; do \
14538           $(INSTALL) -m 644 \
14539             `test -f $$i || echo $(VPATH)/`$$i \
14540             $(DESTDIR)$(includedir)/$$i; \
14541         done
14542 @end example
14544 Now, @code{headers='$(HEADERS)'} macro-expands to:
14546 @example
14547 headers='f.h g.h h.h'
14548 @end example
14550 @noindent
14551 but @code{g.h} is still a plain word.  (As an aside, the idiom
14552 @code{headers='$(HEADERS)'; for i in $$headers;} is a good
14553 idea if @code{$(HEADERS)} can be empty, because some shells diagnose a
14554 syntax error on @code{for i in;}.)
14556 One workaround is to strip this unwanted @file{../pkg/src/} prefix manually:
14558 @example
14559 VPATH = ../pkg/src
14560 HEADERS = f.h g.h h.h
14561 install-HEADERS: $(HEADERS)
14562         headers='$(HEADERS)'; \
14563         for i in $$headers; do \
14564           i=`expr "$$i" : '$(VPATH)/\(.*\)'`;
14565           $(INSTALL) -m 644 \
14566             `test -f $$i || echo $(VPATH)/`$$i \
14567             $(DESTDIR)$(includedir)/$$i; \
14568         done
14569 @end example
14571 Automake does something similar.  However the above hack works only if
14572 the files listed in @code{HEADERS} are in the current directory or a
14573 subdirectory; they should not be in an enclosing directory.  If we had
14574 @code{HEADERS = ../f.h}, the above fragment would fail in a VPATH
14575 build with Tru64 @command{make}.  The reason is that not only does
14576 Tru64 @command{make} rewrite dependencies, but it also simplifies
14577 them.  Hence @code{../f.h} becomes @code{../pkg/f.h} instead of
14578 @code{../pkg/src/../f.h}.  This obviously defeats any attempt to strip
14579 a leading @file{../pkg/src/} component.
14581 The following example makes the behavior of Tru64 @command{make}
14582 more apparent.
14584 @example
14585 $ @kbd{cat Makefile}
14586 VPATH = sub
14587 all: ../foo
14588         echo ../foo
14589 $ @kbd{ls}
14590 Makefile foo
14591 $ @kbd{make}
14592 echo foo
14594 @end example
14596 @noindent
14597 Dependency @file{../foo} was found in @file{sub/../foo}, but Tru64
14598 @command{make} simplified it as @file{foo}.  (Note that the @file{sub/}
14599 directory does not even exist, this just means that the simplification
14600 occurred before the file was checked for.)
14602 For the record here is how SunOS 4 @command{make} behaves on this
14603 example.
14605 @smallexample
14606 $ @kbd{make}
14607 make: Fatal error: Don't know how to make target `../foo'
14608 $ @kbd{mkdir sub}
14609 $ @kbd{make}
14610 echo sub/../foo
14611 sub/../foo
14612 @end smallexample
14615 @node Tru64 Directory Magic
14616 @subsection Tru64 @command{make} Creates Prerequisite Directories Magically
14617 @cindex @code{VPATH} and prerequisite directories
14618 @cindex prerequisite directories and @code{VPATH}
14620 When a prerequisite is a subdirectory of @code{VPATH}, Tru64
14621 @command{make} creates it in the current directory.
14623 @example
14624 $ @kbd{mkdir -p foo/bar build}
14625 $ @kbd{cd build}
14626 $ @kbd{cat >Makefile <<END
14627 VPATH = ..
14628 all: foo/bar
14629 END}
14630 $ @kbd{make}
14631 mkdir foo
14632 mkdir foo/bar
14633 @end example
14635 This can yield unexpected results if a rule uses a manual @code{VPATH}
14636 search as presented before.
14638 @example
14639 VPATH = ..
14640 all : foo/bar
14641         command `test -d foo/bar || echo ../`foo/bar
14642 @end example
14644 The above @command{command} is run on the empty @file{foo/bar}
14645 directory that was created in the current directory.
14647 @node Make Target Lookup
14648 @subsection Make Target Lookup
14649 @cindex @code{VPATH}, resolving target pathnames
14651 @acronym{GNU} @command{make} uses a complex algorithm to decide when it
14652 should use files found via a @code{VPATH} search.  @xref{Search
14653 Algorithm, , How Directory Searches are Performed, make, The @acronym{GNU} Make
14654 Manual}.
14656 If a target needs to be rebuilt, @acronym{GNU} @command{make} discards the
14657 file name found during the @code{VPATH} search for this target, and
14658 builds the file locally using the file name given in the makefile.
14659 If a target does not need to be rebuilt, @acronym{GNU} @command{make} uses the
14660 file name found during the @code{VPATH} search.
14662 Other @command{make} implementations, like Net@acronym{BSD} @command{make}, are
14663 easier to describe: the file name found during the @code{VPATH} search
14664 is used whether the target needs to be rebuilt or not.  Therefore
14665 new files are created locally, but existing files are updated at their
14666 @code{VPATH} location.
14668 Open@acronym{BSD} and Free@acronym{BSD} @command{make}, however,
14669 never perform a
14670 @code{VPATH} search for a dependency that has an explicit rule.
14671 This is extremely annoying.
14673 When attempting a @code{VPATH} build for an autoconfiscated package
14674 (e.g., @code{mkdir build && cd build && ../configure}), this means
14675 @acronym{GNU}
14676 @command{make} builds everything locally in the @file{build}
14677 directory, while @acronym{BSD} @command{make} builds new files locally and
14678 updates existing files in the source directory.
14680 @example
14681 $ @kbd{cat Makefile}
14682 VPATH = ..
14683 all: foo.x bar.x
14684 foo.x bar.x: newer.x
14685         @@echo Building $@@
14686 $ @kbd{touch ../bar.x}
14687 $ @kbd{touch ../newer.x}
14688 $ @kbd{make}        # GNU make
14689 Building foo.x
14690 Building bar.x
14691 $ @kbd{pmake}       # NetBSD make
14692 Building foo.x
14693 Building ../bar.x
14694 $ @kbd{fmake}       # FreeBSD make, OpenBSD make
14695 Building foo.x
14696 Building bar.x
14697 $ @kbd{tmake}       # Tru64 make
14698 Building foo.x
14699 Building bar.x
14700 $ @kbd{touch ../bar.x}
14701 $ @kbd{make}        # GNU make
14702 Building foo.x
14703 $ @kbd{pmake}       # NetBSD make
14704 Building foo.x
14705 $ @kbd{fmake}       # FreeBSD make, OpenBSD make
14706 Building foo.x
14707 Building bar.x
14708 $ @kbd{tmake}       # Tru64 make
14709 Building foo.x
14710 Building bar.x
14711 @end example
14713 Note how Net@acronym{BSD} @command{make} updates @file{../bar.x} in its
14714 VPATH location, and how Free@acronym{BSD}, Open@acronym{BSD}, and Tru64
14715 @command{make} always
14716 update @file{bar.x}, even when @file{../bar.x} is up to date.
14718 Another point worth mentioning is that once @acronym{GNU} @command{make} has
14719 decided to ignore a @code{VPATH} file name (e.g., it ignored
14720 @file{../bar.x} in the above example) it continues to ignore it when
14721 the target occurs as a prerequisite of another rule.
14723 The following example shows that @acronym{GNU} @command{make} does not look up
14724 @file{bar.x} in @code{VPATH} before performing the @code{.x.y} rule,
14725 because it ignored the @code{VPATH} result of @file{bar.x} while running
14726 the @code{bar.x: newer.x} rule.
14728 @example
14729 $ @kbd{cat Makefile}
14730 VPATH = ..
14731 all: bar.y
14732 bar.x: newer.x
14733         @@echo Building $@@
14734 .SUFFIXES: .x .y
14735 .x.y:
14736         cp $< $@@
14737 $ @kbd{touch ../bar.x}
14738 $ @kbd{touch ../newer.x}
14739 $ @kbd{make}        # GNU make
14740 Building bar.x
14741 cp bar.x bar.y
14742 cp: cannot stat `bar.x': No such file or directory
14743 make: *** [bar.y] Error 1
14744 $ @kbd{pmake}       # NetBSD make
14745 Building ../bar.x
14746 cp ../bar.x bar.y
14747 $ @kbd{rm bar.y}
14748 $ @kbd{fmake}       # FreeBSD make, OpenBSD make
14749 echo Building bar.x
14750 cp bar.x bar.y
14751 cp: cannot stat `bar.x': No such file or directory
14752 *** Error code 1
14753 $ @kbd{tmake}       # Tru64 make
14754 Building bar.x
14755 cp: bar.x: No such file or directory
14756 *** Exit 1
14757 @end example
14759 Note that if you drop away the command from the @code{bar.x: newer.x}
14760 rule, @acronym{GNU} @command{make} magically starts to work: it
14761 knows that @code{bar.x} hasn't been updated, therefore it doesn't
14762 discard the result from @code{VPATH} (@file{../bar.x}) in succeeding
14763 uses.  Tru64 also works, but Free@acronym{BSD} and Open@acronym{BSD}
14764 still don't.
14766 @example
14767 $ @kbd{cat Makefile}
14768 VPATH = ..
14769 all: bar.y
14770 bar.x: newer.x
14771 .SUFFIXES: .x .y
14772 .x.y:
14773         cp $< $@@
14774 $ @kbd{touch ../bar.x}
14775 $ @kbd{touch ../newer.x}
14776 $ @kbd{make}        # GNU make
14777 cp ../bar.x bar.y
14778 $ @kbd{rm bar.y}
14779 $ @kbd{pmake}       # NetBSD make
14780 cp ../bar.x bar.y
14781 $ @kbd{rm bar.y}
14782 $ @kbd{fmake}       # FreeBSD make, OpenBSD make
14783 cp bar.x bar.y
14784 cp: cannot stat `bar.x': No such file or directory
14785 *** Error code 1
14786 $ @kbd{tmake}       # Tru64 make
14787 cp ../bar.x bar.y
14788 @end example
14790 It seems the sole solution that would please every @command{make}
14791 implementation is to never rely on @code{VPATH} searches for targets.
14792 In other words, @code{VPATH} should be reserved to unbuilt sources.
14795 @node Single Suffix Rules
14796 @section Single Suffix Rules and Separated Dependencies
14797 @cindex Single Suffix Inference Rule
14798 @cindex Rule, Single Suffix Inference
14799 A @dfn{Single Suffix Rule} is basically a usual suffix (inference) rule
14800 (@samp{.from.to:}), but which @emph{destination} suffix is empty
14801 (@samp{.from:}).
14803 @cindex Separated Dependencies
14804 @dfn{Separated dependencies} simply refers to listing the prerequisite
14805 of a target, without defining a rule.  Usually one can list on the one
14806 hand side, the rules, and on the other hand side, the dependencies.
14808 Solaris @command{make} does not support separated dependencies for
14809 targets defined by single suffix rules:
14811 @example
14812 $ @kbd{cat Makefile}
14813 .SUFFIXES: .in
14814 foo: foo.in
14815 .in:
14816         cp $< $@@
14817 $ @kbd{touch foo.in}
14818 $ @kbd{make}
14819 $ @kbd{ls}
14820 Makefile  foo.in
14821 @end example
14823 @noindent
14824 while @acronym{GNU} Make does:
14826 @example
14827 $ @kbd{gmake}
14828 cp foo.in foo
14829 $ @kbd{ls}
14830 Makefile  foo       foo.in
14831 @end example
14833 Note it works without the @samp{foo: foo.in} dependency.
14835 @example
14836 $ @kbd{cat Makefile}
14837 .SUFFIXES: .in
14838 .in:
14839         cp $< $@@
14840 $ @kbd{make foo}
14841 cp foo.in foo
14842 @end example
14844 @noindent
14845 and it works with double suffix inference rules:
14847 @example
14848 $ @kbd{cat Makefile}
14849 foo.out: foo.in
14850 .SUFFIXES: .in .out
14851 .in.out:
14852         cp $< $@@
14853 $ @kbd{make}
14854 cp foo.in foo.out
14855 @end example
14857 As a result, in such a case, you have to write target rules.
14859 @node Timestamps and Make
14860 @section Timestamp Resolution and Make
14861 @cindex timestamp resolution
14862 Traditionally, file timestamps had 1-second resolution, and
14863 @command{make} used those timestamps to determine whether one file was
14864 newer than the other.  However, many modern file systems have
14865 timestamps with 1-nanosecond resolution.  Some @command{make}
14866 implementations look at the entire timestamp; others ignore the
14867 fractional part, which can lead to incorrect results.  Normally this
14868 is not a problem, but in some extreme cases you may need to use tricks
14869 like @samp{sleep 1} to work around timestamp truncation bugs.
14871 Commands like @samp{cp -p} and @samp{touch -r} typically do not copy
14872 file timestamps to their full resolutions (@pxref{Limitations of Usual
14873 Tools}).  Hence you should be wary of rules like this:
14875 @example
14876 dest: src
14877         cp -p src dest
14878 @end example
14880 as @file{dest} often appears to be older than @file{src} after the
14881 timestamp is truncated, and this can cause @command{make} to do
14882 needless rework the next time it is invoked.  To work around this
14883 problem, you can use a timestamp file, e.g.:
14885 @example
14886 dest-stamp: src
14887         cp -p src dest
14888         date >dest-stamp
14889 @end example
14894 @c ======================================== Portable C and C++ Programming
14896 @node Portable C and C++
14897 @chapter Portable C and C++ Programming
14898 @cindex Portable C and C++ programming
14900 C and C++ programs often use low-level features of the underlying
14901 system, and therefore are often more difficult to make portable to other
14902 platforms.
14904 Several standards have been developed to help make your programs more
14905 portable.  If you write programs with these standards in mind, you can
14906 have greater confidence that your programs work on a wide variety
14907 of systems.  @xref{Standards, , Language Standards Supported by
14908 @acronym{GCC}, gcc, Using the @acronym{GNU} Compiler Collection
14909 (@acronym{GCC})}, for a list of C-related
14910 standards.  Many programs also assume the
14911 @uref{http://www.opengroup.org/susv3, Posix standard}.
14913 Some old code is written to be portable to K&R C, which predates any C
14914 standard.  K&R C compilers are no longer of practical interest, though,
14915 and the rest of section assumes at least C89, the first C standard.
14917 Program portability is a huge topic, and this section can only briefly
14918 introduce common pitfalls.  @xref{System Portability, , Portability
14919 between System Types, standards, @acronym{GNU} Coding Standards}, for
14920 more information.
14922 @menu
14923 * Varieties of Unportability::  How to make your programs unportable
14924 * Integer Overflow::            When integers get too large
14925 * Null Pointers::               Properties of null pointers
14926 * Buffer Overruns::             Subscript errors and the like
14927 * Volatile Objects::            @code{volatile} and signals
14928 * Floating Point Portability::  Portable floating-point arithmetic
14929 * Exiting Portably::            Exiting and the exit status
14930 @end menu
14932 @node Varieties of Unportability
14933 @section Varieties of Unportability
14934 @cindex portability
14936 Autoconf tests and ordinary programs often need to test what is allowed
14937 on a system, and therefore they may need to deliberately exceed the
14938 boundaries of what the standards allow, if only to see whether an
14939 optional feature is present.  When you write such a program, you should
14940 keep in mind the difference between constraints, unspecified behavior,
14941 and undefined behavior.
14943 In C, a @dfn{constraint} is a rule that the compiler must enforce.  An
14944 example constraint is that C programs must not declare a bit-field with
14945 negative width.  Tests can therefore reliably assume that programs with
14946 negative-width bit-fields are rejected by a compiler that conforms
14947 to the standard.
14949 @dfn{Unspecified behavior} is valid behavior, where the standard allows
14950 multiple possibilities.  For example, the order of evaluation of
14951 function arguments is unspecified.  Some unspecified behavior is
14952 @dfn{implementation-defined}, i.e., documented by the implementation,
14953 but since Autoconf tests cannot read the documentation they cannot
14954 distinguish between implementation-defined and other unspecified
14955 behavior.  It is common for Autoconf tests to probe implementations to
14956 determine otherwise-unspecified behavior.
14958 @dfn{Undefined behavior} is invalid behavior, where the standard allows
14959 the implementation to do anything it pleases.  For example,
14960 dereferencing a null pointer leads to undefined behavior.  If possible,
14961 test programs should avoid undefined behavior, since a program with
14962 undefined behavior might succeed on a test that should fail.
14964 The above rules apply to programs that are intended to conform to the
14965 standard.  However, strictly-conforming programs are quite rare, since
14966 the standards are so limiting.  A major goal of Autoconf is to support
14967 programs that use implementation features not described by the standard,
14968 and it is fairly common for test programs to violate the above rules, if
14969 the programs work well enough in practice.
14971 @node Integer Overflow
14972 @section Integer Overflow
14973 @cindex integer overflow
14974 @cindex overflow, signed integer
14975 @cindex signed integer overflow
14976 @cindex wraparound arithmetic
14978 In practice many portable C programs assume that signed integer overflow wraps
14979 around reliably using two's complement arithmetic.  Yet the C standard
14980 says that program behavior is undefined on overflow, and in a few cases
14981 C programs do not work on some modern implementations because their
14982 overflows do not wrap around as their authors expected.  Conversely, in
14983 signed integer remainder, the C standard requires overflow
14984 behavior that is commonly not implemented.
14986 @menu
14987 * Integer Overflow Basics::      Why integer overflow is a problem
14988 * Signed Overflow Examples::     Examples of code assuming wraparound
14989 * Optimization and Wraparound::  Optimizations that break uses of wraparound
14990 * Signed Overflow Advice::       Practical advice for signed overflow issues
14991 * Signed Integer Division::      @code{INT_MIN / -1} and @code{INT_MIN % -1}
14992 @end menu
14994 @node Integer Overflow Basics
14995 @subsection Basics of Integer Overflow
14996 @cindex integer overflow
14997 @cindex overflow, signed integer
14998 @cindex signed integer overflow
14999 @cindex wraparound arithmetic
15001 In languages like C, unsigned integer overflow reliably wraps around;
15002 e.g., @code{UINT_MAX + 1} yields zero.
15003 This is guaranteed by the C standard and is
15004 portable in practice, unless you specify aggressive,
15005 nonstandard optimization options
15006 suitable only for special applications.
15008 In contrast, the C standard says that signed integer overflow leads to
15009 undefined behavior where a program can do anything, including dumping
15010 core or overrunning a buffer.  The misbehavior can even precede the
15011 overflow.  Such an overflow can occur during addition, subtraction,
15012 multiplication, division, and left shift.
15014 Despite this requirement of the standard, many C programs and Autoconf
15015 tests assume that signed integer overflow silently wraps around modulo a
15016 power of two, using two's complement arithmetic, so long as you cast the
15017 resulting value to a signed integer type or store it into a signed
15018 integer variable.  If you use conservative optimization flags, such
15019 programs are generally portable to the vast majority of modern
15020 platforms, with a few exceptions discussed later.
15022 For historical reasons the C standard also allows implementations with
15023 ones' complement or signed magnitude arithmetic, but it is safe to
15024 assume two's complement nowadays.
15026 Also, overflow can occur when converting an out-of-range value to a
15027 signed integer type.  Here a standard implementation must define what
15028 happens, but this might include raising an exception.  In practice all
15029 known implementations support silent wraparound in this case, so you need
15030 not worry about other possibilities.
15032 @node Signed Overflow Examples
15033 @subsection Examples of Code Assuming Wraparound Overflow
15034 @cindex integer overflow
15035 @cindex overflow, signed integer
15036 @cindex signed integer overflow
15037 @cindex wraparound arithmetic
15039 There has long been a tension between what the C standard requires for
15040 signed integer overflow, and what C programs commonly assume.  The
15041 standard allows aggressive optimizations based on assumptions that
15042 overflow never occurs, but many practical C programs rely on overflow
15043 wrapping around.  These programs do not conform to the standard, but
15044 they commonly work in practice because compiler writers are
15045 understandably reluctant to implement optimizations that would break
15046 many programs, unless perhaps a user specifies aggressive optimization.
15048 The C Standard says that if a program has signed integer overflow its
15049 behavior is undefined, and the undefined behavior can even precede the
15050 overflow.  To take an extreme example:
15052 @c Inspired by Robert Dewar's example in
15053 @c <http://gcc.gnu.org/ml/gcc/2007-01/msg00038.html> (2007-01-01).
15054 @example
15055 if (password == expected_password)
15056   allow_superuser_privileges ();
15057 else if (counter++ == INT_MAX)
15058   abort ();
15059 else
15060   printf ("%d password mismatches\n", counter);
15061 @end example
15063 @noindent
15064 If the @code{int} variable @code{counter} equals @code{INT_MAX},
15065 @code{counter++} must overflow and the behavior is undefined, so the C
15066 standard allows the compiler to optimize away the test against
15067 @code{INT_MAX} and the @code{abort} call.
15068 Worse, if an earlier bug in the program lets the compiler deduce that
15069 @code{counter == INT_MAX} or that @code{counter} previously overflowed,
15070 the C standard allows the compiler to optimize away the password test
15071 and generate code that allows superuser privileges unconditionally.
15073 Despite this requirement by the standard, it has long been common for C
15074 code to assume wraparound arithmetic after signed overflow, and all
15075 known practical C implementations support some C idioms that assume
15076 wraparound signed arithmetic, even if the idioms do not conform
15077 strictly to the standard.  If your code looks like the following
15078 examples it will almost surely work with real-world compilers.
15080 Here is an example derived from the 7th Edition Unix implementation of
15081 @code{atoi} (1979-01-10):
15083 @example
15084 char *p;
15085 int f, n;
15086 @dots{}
15087 while (*p >= '0' && *p <= '9')
15088   n = n * 10 + *p++ - '0';
15089 return (f ? -n : n);
15090 @end example
15092 @noindent
15093 Even if the input string is in range, on most modern machines this has
15094 signed overflow when computing the most negative integer (the @code{-n}
15095 overflows) or a value near an extreme integer (the first @code{+}
15096 overflows).
15098 Here is another example, derived from the 7th Edition implementation of
15099 @code{rand} (1979-01-10).  Here the programmer expects both
15100 multiplication and addition to wrap on overflow:
15102 @example
15103 static long int randx = 1;
15104 @dots{}
15105 randx = randx * 1103515245 + 12345;
15106 return (randx >> 16) & 077777;
15107 @end example
15109 In the following example, derived from the @acronym{GNU} C Library 2.5
15110 implementation of @code{mktime} (2006-09-09), the code assumes
15111 wraparound arithmetic in @code{+} to detect signed overflow:
15113 @example
15114 time_t t, t1, t2;
15115 int sec_requested, sec_adjustment;
15116 @dots{}
15117 t1 = t + sec_requested;
15118 t2 = t1 + sec_adjustment;
15119 if (((t1 < t) != (sec_requested < 0))
15120     | ((t2 < t1) != (sec_adjustment < 0)))
15121   return -1;
15122 @end example
15124 If your code looks like these examples, it is probably safe even though
15125 it does not strictly conform to the C standard.  This might lead one to
15126 believe that one can generally assume wraparound on overflow, but that
15127 is not always true, as can be seen in the next section.
15129 @node Optimization and Wraparound
15130 @subsection Optimizations That Break Wraparound Arithmetic
15131 @cindex loop induction
15133 Compilers sometimes generate code that is incompatible with wraparound
15134 integer arithmetic.  A simple example is an algebraic simplification: a
15135 compiler might translate @code{(i * 2000) / 1000} to @code{i * 2}
15136 because it assumes that @code{i * 2000} does not overflow.  The
15137 translation is not equivalent to the original when overflow occurs:
15138 e.g., in the typical case of 32-bit signed two's complement wraparound
15139 @code{int}, if @code{i} has type @code{int} and value @code{1073742},
15140 the original expression returns @minus{}2147483 but the optimized
15141 version returns the mathematically correct value 2147484.
15143 More subtly, loop induction optimizations often exploit the undefined
15144 behavior of signed overflow.  Consider the following contrived function
15145 @code{sumc}:
15147 @example
15149 sumc (int lo, int hi)
15151   int sum = 0;
15152   int i;
15153   for (i = lo; i <= hi; i++)
15154     sum ^= i * 53;
15155   return sum;
15157 @end example
15159 @noindent
15160 To avoid multiplying by 53 each time through the loop, an optimizing
15161 compiler might internally transform @code{sumc} to the equivalent of the
15162 following:
15164 @example
15166 transformed_sumc (int lo, int hi)
15168   int sum = 0;
15169   int hic = hi * 53;
15170   int ic;
15171   for (ic = lo * 53; ic <= hic; ic += 53)
15172     sum ^= ic;
15173   return sum;
15175 @end example
15177 @noindent
15178 This transformation is allowed by the C standard, but it is invalid for
15179 wraparound arithmetic when @code{INT_MAX / 53 < hi}, because then the
15180 overflow in computing expressions like @code{hi * 53} can cause the
15181 expression @code{i <= hi} to yield a different value from the
15182 transformed expression @code{ic <= hic}.
15184 For this reason, compilers that use loop induction and similar
15185 techniques often do not support reliable wraparound arithmetic when a
15186 loop induction variable like @code{ic} is involved.  Since loop
15187 induction variables are generated by the compiler, and are not visible
15188 in the source code, it is not always trivial to say whether the problem
15189 affects your code.
15191 Hardly any code actually depends on wraparound arithmetic in cases like
15192 these, so in practice these loop induction optimizations are almost
15193 always useful.  However, edge cases in this area can cause problems.
15194 For example:
15196 @example
15197 int j;
15198 for (j = 1; 0 < j; j *= 2)
15199   test (j);
15200 @end example
15202 @noindent
15203 Here, the loop attempts to iterate through all powers of 2 that
15204 @code{int} can represent, but the C standard allows a compiler to
15205 optimize away the comparison and generate an infinite loop,
15206 under the argument that behavior is undefined on overflow.  As of this
15207 writing this optimization is not done by any production version of
15208 @acronym{GCC} with @option{-O2}, but it might be performed by other
15209 compilers, or by more aggressive @acronym{GCC} optimization options,
15210 and the @acronym{GCC} developers have not decided whether it will
15211 continue to work with @acronym{GCC} and @option{-O2}.
15213 @node Signed Overflow Advice
15214 @subsection Practical Advice for Signed Overflow Issues
15215 @cindex integer overflow
15216 @cindex overflow, signed integer
15217 @cindex signed integer overflow
15218 @cindex wraparound arithmetic
15220 Ideally the safest approach is to avoid signed integer overflow
15221 entirely.  For example, instead of multiplying two signed integers, you
15222 can convert them to unsigned integers, multiply the unsigned values,
15223 then test whether the result is in signed range.
15225 Rewriting code in this way will be inconvenient, though, particularly if
15226 the signed values might be negative.  Also, it may hurt
15227 performance.  Using unsigned arithmetic to check for overflow is
15228 particularly painful to do portably and efficiently when dealing with an
15229 integer type like @code{uid_t} whose width and signedness vary from
15230 platform to platform.
15232 Furthermore, many C applications pervasively assume wraparound behavior
15233 and typically it is not easy to find and remove all these assumptions.
15234 Hence it is often useful to maintain nonstandard code that assumes
15235 wraparound on overflow, instead of rewriting the code.  The rest of this
15236 section attempts to give practical advice for this situation.
15238 If your code wants to detect signed integer overflow in @code{sum = a +
15239 b}, it is generally safe to use an expression like @code{(sum < a) != (b
15240 < 0)}.
15242 If your code uses a signed loop index, make sure that the index cannot
15243 overflow, along with all signed expressions derived from the index.
15244 Here is a contrived example of problematic code with two instances of
15245 overflow.
15247 @example
15248 for (i = INT_MAX - 10; i <= INT_MAX; i++)
15249   if (i + 1 < 0)
15250     @{
15251       report_overflow ();
15252       break;
15253     @}
15254 @end example
15256 @noindent
15257 Because of the two overflows, a compiler might optimize away or
15258 transform the two comparisons in a way that is incompatible with the
15259 wraparound assumption.
15261 If your code uses an expression like @code{(i * 2000) / 1000} and you
15262 actually want the multiplication to wrap around on overflow, use
15263 unsigned arithmetic
15264 to do it, e.g., @code{((int) (i * 2000u)) / 1000}.
15266 If your code assumes wraparound behavior and you want to insulate it
15267 against any @acronym{GCC} optimizations that would fail to support that
15268 behavior, you should use @acronym{GCC}'s @option{-fwrapv} option, which
15269 causes signed overflow to wrap around reliably (except for division and
15270 remainder, as discussed in the next section).
15272 If you need to port to platforms where signed integer overflow does not
15273 reliably wrap around (e.g., due to hardware overflow checking, or to
15274 highly aggressive optimizations), you should consider debugging with
15275 @acronym{GCC}'s @option{-ftrapv} option, which causes signed overflow to
15276 raise an exception.
15278 @node Signed Integer Division
15279 @subsection Signed Integer Division and Integer Overflow
15280 @cindex division, integer
15282 Overflow in signed
15283 integer division is not always harmless: for example, on CPUs of the
15284 i386 family, dividing @code{INT_MIN} by @code{-1} yields a SIGFPE signal
15285 which by default terminates the program.  Worse, taking the remainder
15286 of these two values typically yields the same signal on these CPUs,
15287 even though the C standard requires @code{INT_MIN % -1} to yield zero
15288 because the expression does not overflow.
15290 @node Null Pointers
15291 @section Properties of Null Pointers
15292 @cindex null pointers
15294 Most modern hosts reliably fail when you attempt to dereference a null
15295 pointer.
15297 On almost all modern hosts, null pointers use an all-bits-zero internal
15298 representation, so you can reliably use @code{memset} with 0 to set all
15299 the pointers in an array to null values.
15301 If @code{p} is a null pointer to an object type, the C expression
15302 @code{p + 0} always evaluates to @code{p} on modern hosts, even though
15303 the standard says that it has undefined behavior.
15305 @node Buffer Overruns
15306 @section Buffer Overruns and Subscript Errors
15307 @cindex buffer overruns
15309 Buffer overruns and subscript errors are the most common dangerous
15310 errors in C programs.  They result in undefined behavior because storing
15311 outside an array typically modifies storage that is used by some other
15312 object, and most modern systems lack runtime checks to catch these
15313 errors.  Programs should not rely on buffer overruns being caught.
15315 There is one exception to the usual rule that a portable program cannot
15316 address outside an array.  In C, it is valid to compute the address just
15317 past an object, e.g., @code{&a[N]} where @code{a} has @code{N} elements,
15318 so long as you do not dereference the resulting pointer.  But it is not
15319 valid to compute the address just before an object, e.g., @code{&a[-1]};
15320 nor is it valid to compute two past the end, e.g., @code{&a[N+1]}.  On
15321 most platforms @code{&a[-1] < &a[0] && &a[N] < &a[N+1]}, but this is not
15322 reliable in general, and it is usually easy enough to avoid the
15323 potential portability problem, e.g., by allocating an extra unused array
15324 element at the start or end.
15326 @uref{http://valgrind.org/, Valgrind} can catch many overruns.
15327 @acronym{GCC}
15328 users might also consider using the @option{-fmudflap} option to catch
15329 overruns.
15331 Buffer overruns are usually caused by off-by-one errors, but there are
15332 more subtle ways to get them.
15334 Using @code{int} values to index into an array or compute array sizes
15335 causes problems on typical 64-bit hosts where an array index might
15336 be @math{2^31} or larger.  Index values of type @code{size_t} avoid this
15337 problem, but cannot be negative.  Index values of type @code{ptrdiff_t}
15338 are signed, and are wide enough in practice.
15340 If you add or multiply two numbers to calculate an array size, e.g.,
15341 @code{malloc (x * sizeof y + z)}, havoc ensues if the addition or
15342 multiplication overflows.
15344 Many implementations of the @code{alloca} function silently misbehave
15345 and can generate buffer overflows if given sizes that are too large.
15346 The size limits are implementation dependent, but are at least 4000
15347 bytes on all platforms that we know about.
15349 The standard functions @code{asctime}, @code{asctime_r}, @code{ctime},
15350 @code{ctime_r}, and @code{gets} are prone to buffer overflows, and
15351 portable code should not use them unless the inputs are known to be
15352 within certain limits.  The time-related functions can overflow their
15353 buffers if given timestamps out of range (e.g., a year less than -999
15354 or greater than 9999).  Time-related buffer overflows cannot happen with
15355 recent-enough versions of the @acronym{GNU} C library, but are possible
15356 with other
15357 implementations.  The @code{gets} function is the worst, since it almost
15358 invariably overflows its buffer when presented with an input line larger
15359 than the buffer.
15361 @node Volatile Objects
15362 @section Volatile Objects
15363 @cindex volatile objects
15365 The keyword @code{volatile} is often misunderstood in portable code.
15366 Its use inhibits some memory-access optimizations, but programmers often
15367 wish that it had a different meaning than it actually does.
15369 @code{volatile} was designed for code that accesses special objects like
15370 memory-mapped device registers whose contents spontaneously change.
15371 Such code is inherently low-level, and it is difficult to specify
15372 portably what @code{volatile} means in these cases.  The C standard
15373 says, ``What constitutes an access to an object that has
15374 volatile-qualified type is implementation-defined,'' so in theory each
15375 implementation is supposed to fill in the gap by documenting what
15376 @code{volatile} means for that implementation.  In practice, though,
15377 this documentation is usually absent or incomplete.
15379 One area of confusion is the distinction between objects defined with
15380 volatile types, and volatile lvalues.  From the C standard's point of
15381 view, an object defined with a volatile type has externally visible
15382 behavior.  You can think of such objects as having little oscilloscope
15383 probes attached to them, so that the user can observe some properties of
15384 accesses to them, just as the user can observe data written to output
15385 files.  However, the standard does not make it clear whether users can
15386 observe accesses by volatile lvalues to ordinary objects.  For example:
15388 @example
15389 /* Declare and access a volatile object.
15390    Accesses to X are "visible" to users.  */
15391 static int volatile x;
15392 x = 1;
15394 /* Access two ordinary objects via a volatile lvalue.
15395    It's not clear whether accesses to *P are "visible".  */
15396 int y;
15397 int *z = malloc (sizeof (int));
15398 int volatile *p;
15399 p = &y;
15400 *p = 1;
15401 p = z;
15402 *p = 1;
15403 @end example
15405 Programmers often wish that @code{volatile} meant ``Perform the memory
15406 access here and now, without merging several memory accesses, without
15407 changing the memory word size, and without reordering.''  But the C
15408 standard does not require this.  For objects defined with a volatile
15409 type, accesses must be done before the next sequence point; but
15410 otherwise merging, reordering, and word-size change is allowed.  Worse,
15411 it is not clear from the standard whether volatile lvalues provide more
15412 guarantees in general than nonvolatile lvalues, if the underlying
15413 objects are ordinary.
15415 Even when accessing objects defined with a volatile type,
15416 the C standard allows only
15417 extremely limited signal handlers: the behavior is undefined if a signal
15418 handler reads any nonlocal object, or writes to any nonlocal object
15419 whose type is not @code{sig_atomic_t volatile}, or calls any standard
15420 library function other than @code{abort}, @code{signal}, and (if C99)
15421 @code{_Exit}.  Hence C compilers need not worry about a signal handler
15422 disturbing ordinary computation, unless the computation accesses a
15423 @code{sig_atomic_t volatile} lvalue that is not a local variable.
15424 (There is an obscure exception for accesses via a pointer to a volatile
15425 character, since it may point into part of a @code{sig_atomic_t
15426 volatile} object.)  Posix
15427 adds to the list of library functions callable from a portable signal
15428 handler, but otherwise is like the C standard in this area.
15430 Some C implementations allow memory-access optimizations within each
15431 translation unit, such that actual behavior agrees with the behavior
15432 required by the standard only when calling a function in some other
15433 translation unit, and a signal handler acts like it was called from a
15434 different translation unit.  The C standard hints that in these
15435 implementations, objects referred to by signal handlers ``would require
15436 explicit specification of @code{volatile} storage, as well as other
15437 implementation-defined restrictions.''  But unfortunately even for this
15438 special case these other restrictions are often not documented well.
15439 @xref{Volatiles, , When is a Volatile Object Accessed?, gcc, Using the
15440 @acronym{GNU} Compiler Collection (@acronym{GCC})}, for some
15441 restrictions imposed by @acronym{GCC}.  @xref{Defining Handlers, ,
15442 Defining Signal Handlers, libc, The @acronym{GNU} C Library}, for some
15443 restrictions imposed by the @acronym{GNU} C library.  Restrictions
15444 differ on other platforms.
15446 If possible, it is best to use a signal handler that fits within the
15447 limits imposed by the C and Posix standards.
15449 If this is not practical, you can try the following rules of thumb.  A
15450 signal handler should access only volatile lvalues, preferably lvalues
15451 that refer to objects defined with a volatile type, and should not
15452 assume that the accessed objects have an internally consistent state
15453 if they are larger than a machine word.  Furthermore, installers
15454 should employ compilers and compiler options that are commonly used
15455 for building operating system kernels, because kernels often need more
15456 from @code{volatile} than the C Standard requires, and installers who
15457 compile an application in a similar environment can sometimes benefit
15458 from the extra constraints imposed by kernels on compilers.
15459 Admittedly we are handwaving somewhat here, as there are few
15460 guarantees in this area; the rules of thumb may help to fix some bugs
15461 but there is a good chance that they will not fix them all.
15463 For @code{volatile}, C++ has the same problems that C does.
15464 Multithreaded applications have even more problems with @code{volatile},
15465 but they are beyond the scope of this section.
15467 The bottom line is that using @code{volatile} typically hurts
15468 performance but should not hurt correctness.  In some cases its use
15469 does help correctness, but these cases are often so poorly understood
15470 that all too often adding @code{volatile} to a data structure merely
15471 alleviates some symptoms of a bug while not fixing the bug in general.
15473 @node Floating Point Portability
15474 @section Floating Point Portability
15475 @cindex floating point
15477 Almost all modern systems use IEEE-754 floating point, and it is safe to
15478 assume IEEE-754 in most portable code these days.  For more information,
15479 please see David Goldberg's classic paper
15480 @uref{http://www.validlab.com/goldberg/paper.pdf, What Every Computer
15481 Scientist Should Know About Floating-Point Arithmetic}.
15483 @node Exiting Portably
15484 @section Exiting Portably
15485 @cindex exiting portably
15487 A C or C++ program can exit with status @var{N} by returning
15488 @var{N} from the @code{main} function.  Portable programs are supposed
15489 to exit either with status 0 or @code{EXIT_SUCCESS} to succeed, or with
15490 status @code{EXIT_FAILURE} to fail, but in practice it is portable to
15491 fail by exiting with status 1, and test programs that assume Posix can
15492 fail by exiting with status values from 1 through 255.  Programs on
15493 SunOS 2.0 (1985) through 3.5.2 (1988) incorrectly exited with zero
15494 status when @code{main} returned nonzero, but ancient systems like these
15495 are no longer of practical concern.
15497 A program can also exit with status @var{N} by passing @var{N} to the
15498 @code{exit} function, and a program can fail by calling the @code{abort}
15499 function.  If a program is specialized to just some platforms, it can fail
15500 by calling functions specific to those platforms, e.g., @code{_exit}
15501 (Posix) and @code{_Exit} (C99).  However, like other functions, an exit
15502 function should be declared, typically by including a header.  For
15503 example, if a C program calls @code{exit}, it should include @file{stdlib.h}
15504 either directly or via the default includes (@pxref{Default Includes}).
15506 A program can fail due to undefined behavior such as dereferencing a null
15507 pointer, but this is not recommended as undefined behavior allows an
15508 implementation to do whatever it pleases and this includes exiting
15509 successfully.
15512 @c ================================================== Manual Configuration
15514 @node Manual Configuration
15515 @chapter Manual Configuration
15517 A few kinds of features can't be guessed automatically by running test
15518 programs.  For example, the details of the object-file format, or
15519 special options that need to be passed to the compiler or linker.  You
15520 can check for such features using ad-hoc means, such as having
15521 @command{configure} check the output of the @code{uname} program, or
15522 looking for libraries that are unique to particular systems.  However,
15523 Autoconf provides a uniform method for handling unguessable features.
15525 @menu
15526 * Specifying Names::            Specifying the system type
15527 * Canonicalizing::              Getting the canonical system type
15528 * Using System Type::           What to do with the system type
15529 @end menu
15531 @node Specifying Names
15532 @section Specifying the System Type
15533 @cindex System type
15535 Like other @acronym{GNU} @command{configure} scripts, Autoconf-generated
15536 @command{configure} scripts can make decisions based on a canonical name
15537 for the system type, which has the form:
15538 @samp{@var{cpu}-@var{vendor}-@var{os}}, where @var{os} can be
15539 @samp{@var{system}} or @samp{@var{kernel}-@var{system}}
15541 @command{configure} can usually guess the canonical name for the type of
15542 system it's running on.  To do so it runs a script called
15543 @command{config.guess}, which infers the name using the @code{uname}
15544 command or symbols predefined by the C preprocessor.
15546 Alternately, the user can specify the system type with command line
15547 arguments to @command{configure}.  Doing so is necessary when
15548 cross-compiling.  In the most complex case of cross-compiling, three
15549 system types are involved.  The options to specify them are:
15551 @table @option
15552 @item --build=@var{build-type}
15553 the type of system on which the package is being configured and
15554 compiled.  It defaults to the result of running @command{config.guess}.
15556 @item --host=@var{host-type}
15557 the type of system on which the package runs.  By default it is the
15558 same as the build machine.  Specifying it enables the cross-compilation
15559 mode.
15561 @item --target=@var{target-type}
15562 the type of system for which any compiler tools in the package
15563 produce code (rarely needed).  By default, it is the same as host.
15564 @end table
15566 If you mean to override the result of @command{config.guess}, use
15567 @option{--build}, not @option{--host}, since the latter enables
15568 cross-compilation.  For historical reasons, passing @option{--host} also
15569 changes the build type.  Therefore, whenever you specify @option{--host},
15570 be sure to specify @option{--build} too; this will be fixed in the
15571 future.  So, to enter cross-compilation mode, use a command like this
15573 @example
15574 ./configure --build=i686-pc-linux-gnu --host=m68k-coff
15575 @end example
15577 @noindent
15578 Note that if you do not specify @option{--host}, @command{configure}
15579 fails if it can't run the code generated by the specified compiler.  For
15580 example, configuring as follows fails:
15582 @example
15583 ./configure CC=m68k-coff-gcc
15584 @end example
15586 In the future, when cross-compiling Autoconf will @emph{not}
15587 accept tools (compilers, linkers, assemblers) whose name is not
15588 prefixed with the host type.  The only case when this may be
15589 useful is when you really are not cross-compiling, but only
15590 building for a least-common-denominator architecture: an example
15591 is building for @code{i386-pc-linux-gnu} while running on an
15592 @code{i686-pc-linux-gnu} architecture.  In this case, some particular
15593 pairs might be similar enough to let you get away with the system
15594 compilers, but in general the compiler might make bogus assumptions
15595 on the host: if you know what you are doing, please create symbolic
15596 links from the host compiler to the build compiler.
15598 @cindex @command{config.sub}
15599 @command{configure} recognizes short aliases for many system types; for
15600 example, @samp{decstation} can be used instead of
15601 @samp{mips-dec-ultrix4.2}.  @command{configure} runs a script called
15602 @command{config.sub} to canonicalize system type aliases.
15604 This section deliberately omits the description of the obsolete
15605 interface; see @ref{Hosts and Cross-Compilation}.
15608 @node Canonicalizing
15609 @section Getting the Canonical System Type
15610 @cindex System type
15611 @cindex Canonical system type
15613 The following macros make the system type available to @command{configure}
15614 scripts.
15616 @ovindex build_alias
15617 @ovindex host_alias
15618 @ovindex target_alias
15620 The variables @samp{build_alias}, @samp{host_alias}, and
15621 @samp{target_alias} are always exactly the arguments of @option{--build},
15622 @option{--host}, and @option{--target}; in particular, they are left empty
15623 if the user did not use them, even if the corresponding
15624 @code{AC_CANONICAL} macro was run.  Any configure script may use these
15625 variables anywhere.  These are the variables that should be used when in
15626 interaction with the user.
15628 If you need to recognize some special environments based on their system
15629 type, run the following macros to get canonical system names.  These
15630 variables are not set before the macro call.
15632 If you use these macros, you must distribute @command{config.guess} and
15633 @command{config.sub} along with your source code.  @xref{Output}, for
15634 information about the @code{AC_CONFIG_AUX_DIR} macro which you can use
15635 to control in which directory @command{configure} looks for those scripts.
15638 @defmac AC_CANONICAL_BUILD
15639 @acindex{CANONICAL_BUILD}
15640 @ovindex build
15641 @ovindex build_cpu
15642 @ovindex build_vendor
15643 @ovindex build_os
15644 Compute the canonical build-system type variable, @code{build}, and its
15645 three individual parts @code{build_cpu}, @code{build_vendor}, and
15646 @code{build_os}.
15648 If @option{--build} was specified, then @code{build} is the
15649 canonicalization of @code{build_alias} by @command{config.sub},
15650 otherwise it is determined by the shell script @command{config.guess}.
15651 @end defmac
15653 @defmac AC_CANONICAL_HOST
15654 @acindex{CANONICAL_HOST}
15655 @ovindex host
15656 @ovindex host_cpu
15657 @ovindex host_vendor
15658 @ovindex host_os
15659 Compute the canonical host-system type variable, @code{host}, and its
15660 three individual parts @code{host_cpu}, @code{host_vendor}, and
15661 @code{host_os}.
15663 If @option{--host} was specified, then @code{host} is the
15664 canonicalization of @code{host_alias} by @command{config.sub},
15665 otherwise it defaults to @code{build}.
15666 @end defmac
15668 @defmac AC_CANONICAL_TARGET
15669 @acindex{CANONICAL_TARGET}
15670 @ovindex target
15671 @ovindex target_cpu
15672 @ovindex target_vendor
15673 @ovindex target_os
15674 Compute the canonical target-system type variable, @code{target}, and its
15675 three individual parts @code{target_cpu}, @code{target_vendor}, and
15676 @code{target_os}.
15678 If @option{--target} was specified, then @code{target} is the
15679 canonicalization of @code{target_alias} by @command{config.sub},
15680 otherwise it defaults to @code{host}.
15681 @end defmac
15683 Note that there can be artifacts due to the backward compatibility
15684 code.  See @xref{Hosts and Cross-Compilation}, for more.
15686 @node Using System Type
15687 @section Using the System Type
15689 In @file{configure.ac} the system type is generally used by one or more
15690 @code{case} statements to select system-specifics.  Shell wildcards can
15691 be used to match a group of system types.
15693 For example, an extra assembler code object file could be chosen, giving
15694 access to a CPU cycle counter register.  @code{$(CYCLE_OBJ)} in the
15695 following would be used in a makefile to add the object to a
15696 program or library.
15698 @example
15699 case $host in
15700   alpha*-*-*) CYCLE_OBJ=rpcc.o ;;
15701   i?86-*-*)   CYCLE_OBJ=rdtsc.o ;;
15702   *)          CYCLE_OBJ= ;;
15703 esac
15704 AC_SUBST([CYCLE_OBJ])
15705 @end example
15707 @code{AC_CONFIG_LINKS} (@pxref{Configuration Links}) is another good way
15708 to select variant source files, for example optimized code for some
15709 CPUs.  The configured CPU type doesn't always indicate exact CPU types,
15710 so some runtime capability checks may be necessary too.
15712 @example
15713 case $host in
15714   alpha*-*-*)   AC_CONFIG_LINKS([dither.c:alpha/dither.c]) ;;
15715   powerpc*-*-*) AC_CONFIG_LINKS([dither.c:powerpc/dither.c]) ;;
15716   *-*-*)        AC_CONFIG_LINKS([dither.c:generic/dither.c]) ;;
15717 esac
15718 @end example
15720 The host system type can also be used to find cross-compilation tools
15721 with @code{AC_CHECK_TOOL} (@pxref{Generic Programs}).
15723 The above examples all show @samp{$host}, since this is where the code
15724 is going to run.  Only rarely is it necessary to test @samp{$build}
15725 (which is where the build is being done).
15727 Whenever you're tempted to use @samp{$host} it's worth considering
15728 whether some sort of probe would be better.  New system types come along
15729 periodically or previously missing features are added.  Well-written
15730 probes can adapt themselves to such things, but hard-coded lists of
15731 names can't.  Here are some guidelines,
15733 @itemize @bullet
15734 @item
15735 Availability of libraries and library functions should always be checked
15736 by probing.
15737 @item
15738 Variant behavior of system calls is best identified with runtime tests
15739 if possible, but bug workarounds or obscure difficulties might have to
15740 be driven from @samp{$host}.
15741 @item
15742 Assembler code is inevitably highly CPU-specific and is best selected
15743 according to @samp{$host_cpu}.
15744 @item
15745 Assembler variations like underscore prefix on globals or ELF versus
15746 COFF type directives are however best determined by probing, perhaps
15747 even examining the compiler output.
15748 @end itemize
15750 @samp{$target} is for use by a package creating a compiler or similar.
15751 For ordinary packages it's meaningless and should not be used.  It
15752 indicates what the created compiler should generate code for, if it can
15753 cross-compile.  @samp{$target} generally selects various hard-coded CPU
15754 and system conventions, since usually the compiler or tools under
15755 construction themselves determine how the target works.
15758 @c ===================================================== Site Configuration.
15760 @node Site Configuration
15761 @chapter Site Configuration
15763 @command{configure} scripts support several kinds of local configuration
15764 decisions.  There are ways for users to specify where external software
15765 packages are, include or exclude optional features, install programs
15766 under modified names, and set default values for @command{configure}
15767 options.
15769 @menu
15770 * Help Formatting::             Customizing @samp{configure --help}
15771 * External Software::           Working with other optional software
15772 * Package Options::             Selecting optional features
15773 * Pretty Help Strings::         Formatting help string
15774 * Option Checking::             Controlling checking of @command{configure} options
15775 * Site Details::                Configuring site details
15776 * Transforming Names::          Changing program names when installing
15777 * Site Defaults::               Giving @command{configure} local defaults
15778 @end menu
15780 @node Help Formatting
15781 @section Controlling Help Output
15783 Users consult @samp{configure --help} to learn of configuration
15784 decisions specific to your package.  By default, @command{configure}
15785 breaks this output into sections for each type of option; within each
15786 section, help strings appear in the order @file{configure.ac} defines
15787 them:
15789 @example
15790 Optional Features:
15791   @dots{}
15792   --enable-bar            include bar
15794 Optional Packages:
15795   @dots{}
15796   --with-foo              use foo
15797 @end example
15799 @defmac AC_PRESERVE_HELP_ORDER
15800 @acindex{PRESERVE_HELP_ORDER}
15802 Request an alternate @option{--help} format, in which options of all
15803 types appear together, in the order defined.  Call this macro before any
15804 @code{AC_ARG_ENABLE} or @code{AC_ARG_WITH}.
15806 @example
15807 Optional Features and Packages:
15808   @dots{}
15809   --enable-bar            include bar
15810   --with-foo              use foo
15811 @end example
15813 @end defmac
15815 @node External Software
15816 @section Working With External Software
15817 @cindex External software
15819 Some packages require, or can optionally use, other software packages
15820 that are already installed.  The user can give @command{configure}
15821 command line options to specify which such external software to use.
15822 The options have one of these forms:
15824 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
15825 @c awful.
15826 @example
15827 --with-@var{package}[=@var{arg}]
15828 --without-@var{package}
15829 @end example
15831 For example, @option{--with-gnu-ld} means work with the @acronym{GNU} linker
15832 instead of some other linker.  @option{--with-x} means work with The X
15833 Window System.
15835 The user can give an argument by following the package name with
15836 @samp{=} and the argument.  Giving an argument of @samp{no} is for
15837 packages that are used by default; it says to @emph{not} use the
15838 package.  An argument that is neither @samp{yes} nor @samp{no} could
15839 include a name or number of a version of the other package, to specify
15840 more precisely which other package this program is supposed to work
15841 with.  If no argument is given, it defaults to @samp{yes}.
15842 @option{--without-@var{package}} is equivalent to
15843 @option{--with-@var{package}=no}.
15845 Normally @command{configure} scripts complain about
15846 @option{--with-@var{package}} options that they do not support.
15847 @xref{Option Checking}, for details, and for how to override the
15848 defaults.
15850 For each external software package that may be used, @file{configure.ac}
15851 should call @code{AC_ARG_WITH} to detect whether the @command{configure}
15852 user asked to use it.  Whether each package is used or not by default,
15853 and which arguments are valid, is up to you.
15855 @defmac AC_ARG_WITH (@var{package}, @var{help-string}, @ovar{action-if-given}, @ovar{action-if-not-given})
15856 @acindex{ARG_WITH}
15857 If the user gave @command{configure} the option @option{--with-@var{package}}
15858 or @option{--without-@var{package}}, run shell commands
15859 @var{action-if-given}.  If neither option was given, run shell commands
15860 @var{action-if-not-given}.  The name @var{package} indicates another
15861 software package that this program should work with.  It should consist
15862 only of alphanumeric characters, dashes, and dots.
15864 The option's argument is available to the shell commands
15865 @var{action-if-given} in the shell variable @code{withval}, which is
15866 actually just the value of the shell variable @code{with_@var{package}},
15867 with any non-alphanumeric characters changed into @samp{_}.  You may use that
15868 variable instead, if you wish.
15870 The argument @var{help-string} is a description of the option that
15871 looks like this:
15872 @example
15873   --with-readline         support fancy command line editing
15874 @end example
15876 @noindent
15877 @var{help-string} may be more than one line long, if more detail is
15878 needed.  Just make sure the columns line up in @samp{configure
15879 --help}.  Avoid tabs in the help string.  You'll need to enclose the
15880 help string in @samp{[} and @samp{]} in order to produce the leading
15881 blanks.
15883 You should format your @var{help-string} with the macro
15884 @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
15886 The following example shows how to use the @code{AC_ARG_WITH} macro in
15887 a common situation.  You want to let the user decide whether to enable
15888 support for an external library (e.g., the readline library); if the user
15889 specified neither @option{--with-readline} nor @option{--without-readline},
15890 you want to enable support for readline only if the library is available
15891 on the system.
15893 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
15894 @example
15895 AC_ARG_WITH([readline],
15896   [AS_HELP_STRING([--with-readline],
15897     [support fancy command line editing @@<:@@default=check@@:>@@])],
15898   [],
15899   [with_readline=check])
15901 LIBREADLINE=
15902 AS_IF([test "x$with_readline" != xno],
15903   [AC_CHECK_LIB([readline], [main],
15904     [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
15905      AC_DEFINE([HAVE_LIBREADLINE], [1],
15906                [Define if you have libreadline])
15907     ],
15908     [if test "x$with_readline" != xcheck; then
15909        AC_MSG_FAILURE(
15910          [--with-readline was given, but test for readline failed])
15911      fi
15912     ], -lncurses)])
15913 @end example
15915 The next example shows how to use @code{AC_ARG_WITH} to give the user the
15916 possibility to enable support for the readline library, in case it is still
15917 experimental and not well tested, and is therefore disabled by default.
15919 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
15920 @example
15921 AC_ARG_WITH([readline],
15922   [AS_HELP_STRING([--with-readline],
15923     [enable experimental support for readline])],
15924   [],
15925   [with_readline=no])
15927 LIBREADLINE=
15928 AS_IF([test "x$with_readline" != xno],
15929   [AC_CHECK_LIB([readline], [main],
15930     [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
15931      AC_DEFINE([HAVE_LIBREADLINE], [1],
15932                [Define if you have libreadline])
15933     ],
15934     [AC_MSG_FAILURE(
15935        [--with-readline was given, but test for readline failed])],
15936     [-lncurses])])
15937 @end example
15939 The last example shows how to use @code{AC_ARG_WITH} to give the user the
15940 possibility to disable support for the readline library, given that it is
15941 an important feature and that it should be enabled by default.
15943 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
15944 @example
15945 AC_ARG_WITH([readline],
15946   [AS_HELP_STRING([--without-readline],
15947     [disable support for readline])],
15948   [],
15949   [with_readline=yes])
15951 LIBREADLINE=
15952 AS_IF([test "x$with_readline" != xno],
15953   [AC_CHECK_LIB([readline], [main],
15954     [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
15955      AC_DEFINE([HAVE_LIBREADLINE], [1],
15956                [Define if you have libreadline])
15957     ],
15958     [AC_MSG_FAILURE(
15959        [readline test failed (--without-readline to disable)])],
15960     [-lncurses])])
15961 @end example
15963 These three examples can be easily adapted to the case where
15964 @code{AC_ARG_ENABLE} should be preferred to @code{AC_ARG_WITH} (see
15965 @ref{Package Options}).
15966 @end defmac
15968 @defmac AC_WITH (@var{package}, @var{action-if-given}, @ovar{action-if-not-given})
15969 @acindex{WITH}
15970 This is an obsolete version of @code{AC_ARG_WITH} that does not
15971 support providing a help string.
15972 @end defmac
15974 @node Package Options
15975 @section Choosing Package Options
15976 @cindex Package options
15977 @cindex Options, package
15979 If a software package has optional compile-time features, the user can
15980 give @command{configure} command line options to specify whether to
15981 compile them.  The options have one of these forms:
15983 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
15984 @c awful.
15985 @example
15986 --enable-@var{feature}[=@var{arg}]
15987 --disable-@var{feature}
15988 @end example
15990 These options allow users to choose which optional features to build and
15991 install.  @option{--enable-@var{feature}} options should never make a
15992 feature behave differently or cause one feature to replace another.
15993 They should only cause parts of the program to be built rather than left
15994 out.
15996 The user can give an argument by following the feature name with
15997 @samp{=} and the argument.  Giving an argument of @samp{no} requests
15998 that the feature @emph{not} be made available.  A feature with an
15999 argument looks like @option{--enable-debug=stabs}.  If no argument is
16000 given, it defaults to @samp{yes}.  @option{--disable-@var{feature}} is
16001 equivalent to @option{--enable-@var{feature}=no}.
16003 Normally @command{configure} scripts complain about
16004 @option{--enable-@var{package}} options that they do not support.
16005 @xref{Option Checking}, for details, and for how to override the
16006 defaults.
16008 For each optional feature, @file{configure.ac} should call
16009 @code{AC_ARG_ENABLE} to detect whether the @command{configure} user asked
16010 to include it.  Whether each feature is included or not by default, and
16011 which arguments are valid, is up to you.
16013 @defmac AC_ARG_ENABLE (@var{feature}, @var{help-string}, @ovar{action-if-given}, @ovar{action-if-not-given})
16014 @acindex{ARG_ENABLE}
16015 If the user gave @command{configure} the option
16016 @option{--enable-@var{feature}} or @option{--disable-@var{feature}}, run
16017 shell commands @var{action-if-given}.  If neither option was given, run
16018 shell commands @var{action-if-not-given}.  The name @var{feature}
16019 indicates an optional user-level facility.  It should consist only of
16020 alphanumeric characters, dashes, and dots.
16022 The option's argument is available to the shell commands
16023 @var{action-if-given} in the shell variable @code{enableval}, which is
16024 actually just the value of the shell variable
16025 @code{enable_@var{feature}}, with any non-alphanumeric characters changed into
16026 @samp{_}.  You may use that variable instead, if you wish.  The
16027 @var{help-string} argument is like that of @code{AC_ARG_WITH}
16028 (@pxref{External Software}).
16030 You should format your @var{help-string} with the macro
16031 @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
16033 See the examples suggested with the definition of @code{AC_ARG_WITH}
16034 (@pxref{External Software}) to get an idea of possible applications of
16035 @code{AC_ARG_ENABLE}.
16036 @end defmac
16038 @defmac AC_ENABLE (@var{feature}, @var{action-if-given}, @ovar{action-if-not-given})
16039 @acindex{ENABLE}
16040 This is an obsolete version of @code{AC_ARG_ENABLE} that does not
16041 support providing a help string.
16042 @end defmac
16045 @node Pretty Help Strings
16046 @section Making Your Help Strings Look Pretty
16047 @cindex Help strings
16049 Properly formatting the @samp{help strings} which are used in
16050 @code{AC_ARG_WITH} (@pxref{External Software}) and @code{AC_ARG_ENABLE}
16051 (@pxref{Package Options}) can be challenging.  Specifically, you want
16052 your own @samp{help strings} to line up in the appropriate columns of
16053 @samp{configure --help} just like the standard Autoconf @samp{help
16054 strings} do.  This is the purpose of the @code{AS_HELP_STRING} macro.
16056 @defmac AS_HELP_STRING (@var{left-hand-side}, @var{right-hand-side})
16057 @acindex{HELP_STRING}
16059 Expands into an help string that looks pretty when the user executes
16060 @samp{configure --help}.  It is typically used in @code{AC_ARG_WITH}
16061 (@pxref{External Software}) or @code{AC_ARG_ENABLE} (@pxref{Package
16062 Options}).  The following example makes this clearer.
16064 @example
16065 AC_ARG_WITH([foo],
16066   [AS_HELP_STRING([--with-foo],
16067      [use foo (default is no)])],
16068   [use_foo=$withval],
16069   [use_foo=no])
16070 @end example
16072 The second argument of @code{AS_HELP_STRING} is
16073 not a literal, and should not be double quoted.
16074 @xref{Autoconf Language}, for a more detailed explanation.
16075 Then the last few lines of @samp{configure --help} appear like
16076 this:
16078 @example
16079 --enable and --with options recognized:
16080   --with-foo              use foo (default is no)
16081 @end example
16083 The @code{AS_HELP_STRING} macro is particularly helpful when the
16084 @var{left-hand-side} and/or @var{right-hand-side} are composed of macro
16085 arguments, as shown in the following example.
16087 @example
16088 AC_DEFUN([MY_ARG_WITH],
16089   [AC_ARG_WITH([$1],
16090      [AS_HELP_STRING([--with-$1], [use $1 (default is $2)])],
16091      [use_[]$1=$withval],
16092      [use_[]$1=$2])])
16093 @end example
16094 @end defmac
16097 @node Option Checking
16098 @section Controlling Checking of @command{configure} Options
16099 @cindex Options, Package
16101 The @command{configure} script checks its command-line options against a
16102 list of known options, like @option{--help} or @option{--config-cache}.
16103 An unknown option ordinarily indicates a mistake by the user and
16104 @command{configure} halts with an error.  However, by default unknown
16105 @option{--with-@var{package}} and @option{--enable-@var{feature}}
16106 options elicit only a warning, to support configuring entire source
16107 trees.
16109 Source trees often contain multiple packages with a top-level
16110 @command{configure} script that uses the @code{AC_CONFIG_SUBDIRS} macro
16111 (@pxref{Subdirectories}).  Because the packages generally support
16112 different @option{--with-@var{package}} and
16113 @option{--enable-@var{feature}} options, the @acronym{GNU} Coding
16114 Standards say they must accept unrecognized options without halting.
16115 Even a warning message is undesirable here, so @code{AC_CONFIG_SUBDIRS}
16116 automatically disables the warnings.
16118 This default behavior may be modified in two ways.  First, the installer
16119 can invoke @command{configure} with the
16120 @option{--disable-option-checking} or
16121 @option{--enable-option-checking=fatal} options to disable these
16122 warnings or turn them into fatal errors, respectively.  Second, the
16123 maintainer can use @code{AC_DISABLE_OPTION_CHECKING}.
16125 @defmac AC_DISABLE_OPTION_CHECKING
16126 @acindex{DISABLE_OPTION_CHECKING}
16128 By default, disable warnings for unrecognized
16129 @option{--with-@var{package}} or @option{--enable-@var{feature}}
16130 options.  This is implied by @code{AC_CONFIG_SUBDIRS}.
16132 The installer can override this behavior by passing
16133 @option{--enable-option-checking} (enable warnings) or
16134 @option{--enable-option-checking=fatal} (enable errors) to
16135 @command{configure}.
16136 @end defmac
16139 @node Site Details
16140 @section Configuring Site Details
16141 @cindex Site details
16143 Some software packages require complex site-specific information.  Some
16144 examples are host names to use for certain services, company names, and
16145 email addresses to contact.  Since some configuration scripts generated
16146 by Metaconfig ask for such information interactively, people sometimes
16147 wonder how to get that information in Autoconf-generated configuration
16148 scripts, which aren't interactive.
16150 Such site configuration information should be put in a file that is
16151 edited @emph{only by users}, not by programs.  The location of the file
16152 can either be based on the @code{prefix} variable, or be a standard
16153 location such as the user's home directory.  It could even be specified
16154 by an environment variable.  The programs should examine that file at
16155 runtime, rather than at compile time.  Runtime configuration is more
16156 convenient for users and makes the configuration process simpler than
16157 getting the information while configuring.  @xref{Directory Variables, ,
16158 Variables for Installation Directories, standards, @acronym{GNU} Coding
16159 Standards}, for more information on where to put data files.
16161 @node Transforming Names
16162 @section Transforming Program Names When Installing
16163 @cindex Transforming program names
16164 @cindex Program names, transforming
16166 Autoconf supports changing the names of programs when installing them.
16167 In order to use these transformations, @file{configure.ac} must call the
16168 macro @code{AC_ARG_PROGRAM}.
16170 @defmac AC_ARG_PROGRAM
16171 @acindex{ARG_PROGRAM}
16172 @ovindex program_transform_name
16173 Place in output variable @code{program_transform_name} a sequence of
16174 @code{sed} commands for changing the names of installed programs.
16176 If any of the options described below are given to @command{configure},
16177 program names are transformed accordingly.  Otherwise, if
16178 @code{AC_CANONICAL_TARGET} has been called and a @option{--target} value
16179 is given, the target type followed by a dash is used as a prefix.
16180 Otherwise, no program name transformation is done.
16181 @end defmac
16183 @menu
16184 * Transformation Options::      @command{configure} options to transform names
16185 * Transformation Examples::     Sample uses of transforming names
16186 * Transformation Rules::        Makefile uses of transforming names
16187 @end menu
16189 @node Transformation Options
16190 @subsection Transformation Options
16192 You can specify name transformations by giving @command{configure} these
16193 command line options:
16195 @table @option
16196 @item --program-prefix=@var{prefix}
16197 prepend @var{prefix} to the names;
16199 @item --program-suffix=@var{suffix}
16200 append @var{suffix} to the names;
16202 @item --program-transform-name=@var{expression}
16203 perform @code{sed} substitution @var{expression} on the names.
16204 @end table
16206 @node Transformation Examples
16207 @subsection Transformation Examples
16209 These transformations are useful with programs that can be part of a
16210 cross-compilation development environment.  For example, a
16211 cross-assembler running on a Sun 4 configured with
16212 @option{--target=i960-vxworks} is normally installed as
16213 @file{i960-vxworks-as}, rather than @file{as}, which could be confused
16214 with a native Sun 4 assembler.
16216 You can force a program name to begin with @file{g}, if you don't want
16217 @acronym{GNU} programs installed on your system to shadow other programs with
16218 the same name.  For example, if you configure @acronym{GNU} @code{diff} with
16219 @option{--program-prefix=g}, then when you run @samp{make install} it is
16220 installed as @file{/usr/local/bin/gdiff}.
16222 As a more sophisticated example, you could use
16224 @example
16225 --program-transform-name='s/^/g/; s/^gg/g/; s/^gless/less/'
16226 @end example
16227 @noindent
16229 to prepend @samp{g} to most of the program names in a source tree,
16230 excepting those like @code{gdb} that already have one and those like
16231 @code{less} and @code{lesskey} that aren't @acronym{GNU} programs.  (That is
16232 assuming that you have a source tree containing those programs that is
16233 set up to use this feature.)
16235 One way to install multiple versions of some programs simultaneously is
16236 to append a version number to the name of one or both.  For example, if
16237 you want to keep Autoconf version 1 around for awhile, you can configure
16238 Autoconf version 2 using @option{--program-suffix=2} to install the
16239 programs as @file{/usr/local/bin/autoconf2},
16240 @file{/usr/local/bin/autoheader2}, etc.  Nevertheless, pay attention
16241 that only the binaries are renamed, therefore you'd have problems with
16242 the library files which might overlap.
16244 @node Transformation Rules
16245 @subsection Transformation Rules
16247 Here is how to use the variable @code{program_transform_name} in a
16248 @file{Makefile.in}:
16250 @example
16251 PROGRAMS = cp ls rm
16252 transform = @@program_transform_name@@
16253 install:
16254         for p in $(PROGRAMS); do \
16255           $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p | \
16256                                               sed '$(transform)'`; \
16257         done
16259 uninstall:
16260         for p in $(PROGRAMS); do \
16261           rm -f $(DESTDIR)$(bindir)/`echo $$p | sed '$(transform)'`; \
16262         done
16263 @end example
16265 It is guaranteed that @code{program_transform_name} is never empty, and
16266 that there are no useless separators.  Therefore you may safely embed
16267 @code{program_transform_name} within a sed program using @samp{;}:
16269 @example
16270 transform = @@program_transform_name@@
16271 transform_exe = s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/
16272 @end example
16274 Whether to do the transformations on documentation files (Texinfo or
16275 @code{man}) is a tricky question; there seems to be no perfect answer,
16276 due to the several reasons for name transforming.  Documentation is not
16277 usually particular to a specific architecture, and Texinfo files do not
16278 conflict with system documentation.  But they might conflict with
16279 earlier versions of the same files, and @code{man} pages sometimes do
16280 conflict with system documentation.  As a compromise, it is probably
16281 best to do name transformations on @code{man} pages but not on Texinfo
16282 manuals.
16284 @node Site Defaults
16285 @section Setting Site Defaults
16286 @cindex Site defaults
16288 Autoconf-generated @command{configure} scripts allow your site to provide
16289 default values for some configuration values.  You do this by creating
16290 site- and system-wide initialization files.
16292 @evindex CONFIG_SITE
16293 If the environment variable @code{CONFIG_SITE} is set, @command{configure}
16294 uses its value as the name of a shell script to read.  Otherwise, it
16295 reads the shell script @file{@var{prefix}/share/config.site} if it exists,
16296 then @file{@var{prefix}/etc/config.site} if it exists.  Thus,
16297 settings in machine-specific files override those in machine-independent
16298 ones in case of conflict.
16300 Site files can be arbitrary shell scripts, but only certain kinds of
16301 code are really appropriate to be in them.  Because @command{configure}
16302 reads any cache file after it has read any site files, a site file can
16303 define a default cache file to be shared between all Autoconf-generated
16304 @command{configure} scripts run on that system (@pxref{Cache Files}).  If
16305 you set a default cache file in a site file, it is a good idea to also
16306 set the output variable @code{CC} in that site file, because the cache
16307 file is only valid for a particular compiler, but many systems have
16308 several available.
16310 You can examine or override the value set by a command line option to
16311 @command{configure} in a site file; options set shell variables that have
16312 the same names as the options, with any dashes turned into underscores.
16313 The exceptions are that @option{--without-} and @option{--disable-} options
16314 are like giving the corresponding @option{--with-} or @option{--enable-}
16315 option and the value @samp{no}.  Thus, @option{--cache-file=localcache}
16316 sets the variable @code{cache_file} to the value @samp{localcache};
16317 @option{--enable-warnings=no} or @option{--disable-warnings} sets the variable
16318 @code{enable_warnings} to the value @samp{no}; @option{--prefix=/usr} sets the
16319 variable @code{prefix} to the value @samp{/usr}; etc.
16321 Site files are also good places to set default values for other output
16322 variables, such as @code{CFLAGS}, if you need to give them non-default
16323 values: anything you would normally do, repetitively, on the command
16324 line.  If you use non-default values for @var{prefix} or
16325 @var{exec_prefix} (wherever you locate the site file), you can set them
16326 in the site file if you specify it with the @code{CONFIG_SITE}
16327 environment variable.
16329 You can set some cache values in the site file itself.  Doing this is
16330 useful if you are cross-compiling, where it is impossible to check features
16331 that require running a test program.  You could ``prime the cache'' by
16332 setting those values correctly for that system in
16333 @file{@var{prefix}/etc/config.site}.  To find out the names of the cache
16334 variables you need to set, look for shell variables with @samp{_cv_} in
16335 their names in the affected @command{configure} scripts, or in the Autoconf
16336 M4 source code for those macros.
16338 The cache file is careful to not override any variables set in the site
16339 files.  Similarly, you should not override command-line options in the
16340 site files.  Your code should check that variables such as @code{prefix}
16341 and @code{cache_file} have their default values (as set near the top of
16342 @command{configure}) before changing them.
16344 Here is a sample file @file{/usr/share/local/gnu/share/config.site}.  The
16345 command @samp{configure --prefix=/usr/share/local/gnu} would read this
16346 file (if @code{CONFIG_SITE} is not set to a different file).
16348 @example
16349 # config.site for configure
16351 # Change some defaults.
16352 test "$prefix" = NONE && prefix=/usr/share/local/gnu
16353 test "$exec_prefix" = NONE && exec_prefix=/usr/local/gnu
16354 test "$sharedstatedir" = '$prefix/com' && sharedstatedir=/var
16355 test "$localstatedir" = '$prefix/var' && localstatedir=/var
16357 # Give Autoconf 2.x generated configure scripts a shared default
16358 # cache file for feature test results, architecture-specific.
16359 if test "$cache_file" = /dev/null; then
16360   cache_file="$prefix/var/config.cache"
16361   # A cache file is only valid for one C compiler.
16362   CC=gcc
16364 @end example
16367 @c ============================================== Running configure Scripts.
16369 @node Running configure Scripts
16370 @chapter Running @command{configure} Scripts
16371 @cindex @command{configure}
16373 Below are instructions on how to configure a package that uses a
16374 @command{configure} script, suitable for inclusion as an @file{INSTALL}
16375 file in the package.  A plain-text version of @file{INSTALL} which you
16376 may use comes with Autoconf.
16378 @menu
16379 * Basic Installation::          Instructions for typical cases
16380 * Compilers and Options::       Selecting compilers and optimization
16381 * Multiple Architectures::      Compiling for multiple architectures at once
16382 * Installation Names::          Installing in different directories
16383 * Optional Features::           Selecting optional features
16384 * System Type::                 Specifying the system type
16385 * Sharing Defaults::            Setting site-wide defaults for @command{configure}
16386 * Defining Variables::          Specifying the compiler etc.
16387 * configure Invocation::        Changing how @command{configure} runs
16388 @end menu
16390 @set autoconf
16391 @include install.texi
16394 @c ============================================== config.status Invocation
16396 @node config.status Invocation
16397 @chapter config.status Invocation
16398 @cindex @command{config.status}
16400 The @command{configure} script creates a file named @file{config.status},
16401 which actually configures, @dfn{instantiates}, the template files.  It
16402 also records the configuration options that were specified when the
16403 package was last configured in case reconfiguring is needed.
16405 Synopsis:
16406 @example
16407 ./config.status @var{option}@dots{} [@var{file}@dots{}]
16408 @end example
16410 It configures the @var{files}; if none are specified, all the templates
16411 are instantiated.  The files must be specified without their
16412 dependencies, as in
16414 @example
16415 ./config.status foobar
16416 @end example
16418 @noindent
16421 @example
16422 ./config.status foobar:foo.in:bar.in
16423 @end example
16425 The supported options are:
16427 @table @option
16428 @item --help
16429 @itemx -h
16430 Print a summary of the command line options, the list of the template
16431 files, and exit.
16433 @item --version
16434 @itemx -V
16435 Print the version number of Autoconf and the configuration settings,
16436 and exit.
16438 @item --silent
16439 @itemx --quiet
16440 @itemx -q
16441 Do not print progress messages.
16443 @item --debug
16444 @itemx -d
16445 Don't remove the temporary files.
16447 @item --file=@var{file}[:@var{template}]
16448 Require that @var{file} be instantiated as if
16449 @samp{AC_CONFIG_FILES(@var{file}:@var{template})} was used.  Both
16450 @var{file} and @var{template} may be @samp{-} in which case the standard
16451 output and/or standard input, respectively, is used.  If a
16452 @var{template} file name is relative, it is first looked for in the build
16453 tree, and then in the source tree.  @xref{Configuration Actions}, for
16454 more details.
16456 This option and the following ones provide one way for separately
16457 distributed packages to share the values computed by @command{configure}.
16458 Doing so can be useful if some of the packages need a superset of the
16459 features that one of them, perhaps a common library, does.  These
16460 options allow a @file{config.status} file to create files other than the
16461 ones that its @file{configure.ac} specifies, so it can be used for a
16462 different package.
16464 @item --header=@var{file}[:@var{template}]
16465 Same as @option{--file} above, but with @samp{AC_CONFIG_HEADERS}.
16467 @item --recheck
16468 Ask @file{config.status} to update itself and exit (no instantiation).
16469 This option is useful if you change @command{configure}, so that the
16470 results of some tests might be different from the previous run.  The
16471 @option{--recheck} option reruns @command{configure} with the same arguments
16472 you used before, plus the @option{--no-create} option, which prevents
16473 @command{configure} from running @file{config.status} and creating
16474 @file{Makefile} and other files, and the @option{--no-recursion} option,
16475 which prevents @command{configure} from running other @command{configure}
16476 scripts in subdirectories.  (This is so other Make rules can
16477 run @file{config.status} when it changes; @pxref{Automatic Remaking},
16478 for an example).
16479 @end table
16481 @file{config.status} checks several optional environment variables that
16482 can alter its behavior:
16484 @defvar CONFIG_SHELL
16485 @evindex CONFIG_SHELL
16486 The shell with which to run @command{configure} for the @option{--recheck}
16487 option.  It must be Bourne-compatible.  The default is a shell that
16488 supports @code{LINENO} if available, and @file{/bin/sh} otherwise.
16489 Invoking @command{configure} by hand bypasses this setting, so you may
16490 need to use a command like @samp{CONFIG_SHELL=/bin/bash /bin/bash ./configure}
16491 to insure that the same shell is used everywhere.  The absolute name of the
16492 shell should be passed.
16493 @end defvar
16495 @defvar CONFIG_STATUS
16496 @evindex CONFIG_STATUS
16497 The file name to use for the shell script that records the
16498 configuration.  The default is @file{./config.status}.  This variable is
16499 useful when one package uses parts of another and the @command{configure}
16500 scripts shouldn't be merged because they are maintained separately.
16501 @end defvar
16503 You can use @file{./config.status} in your makefiles.  For example, in
16504 the dependencies given above (@pxref{Automatic Remaking}),
16505 @file{config.status} is run twice when @file{configure.ac} has changed.
16506 If that bothers you, you can make each run only regenerate the files for
16507 that rule:
16508 @example
16509 @group
16510 config.h: stamp-h
16511 stamp-h: config.h.in config.status
16512         ./config.status config.h
16513         echo > stamp-h
16515 Makefile: Makefile.in config.status
16516         ./config.status Makefile
16517 @end group
16518 @end example
16520 The calling convention of @file{config.status} has changed; see
16521 @ref{Obsolete config.status Use}, for details.
16524 @c =================================================== Obsolete Constructs
16526 @node Obsolete Constructs
16527 @chapter Obsolete Constructs
16528 @cindex Obsolete constructs
16530 Autoconf changes, and throughout the years some constructs have been
16531 obsoleted.  Most of the changes involve the macros, but in some cases
16532 the tools themselves, or even some concepts, are now considered
16533 obsolete.
16535 You may completely skip this chapter if you are new to Autoconf.  Its
16536 intention is mainly to help maintainers updating their packages by
16537 understanding how to move to more modern constructs.
16539 @menu
16540 * Obsolete config.status Use::  Obsolete convention for @command{config.status}
16541 * acconfig Header::             Additional entries in @file{config.h.in}
16542 * autoupdate Invocation::       Automatic update of @file{configure.ac}
16543 * Obsolete Macros::             Backward compatibility macros
16544 * Autoconf 1::                  Tips for upgrading your files
16545 * Autoconf 2.13::               Some fresher tips
16546 @end menu
16548 @node Obsolete config.status Use
16549 @section Obsolete @file{config.status} Invocation
16551 @file{config.status} now supports arguments to specify the files to
16552 instantiate; see @ref{config.status Invocation}, for more details.
16553 Before, environment variables had to be used.
16555 @defvar CONFIG_COMMANDS
16556 @evindex CONFIG_COMMANDS
16557 The tags of the commands to execute.  The default is the arguments given
16558 to @code{AC_OUTPUT} and @code{AC_CONFIG_COMMANDS} in
16559 @file{configure.ac}.
16560 @end defvar
16562 @defvar CONFIG_FILES
16563 @evindex CONFIG_FILES
16564 The files in which to perform @samp{@@@var{variable}@@} substitutions.
16565 The default is the arguments given to @code{AC_OUTPUT} and
16566 @code{AC_CONFIG_FILES} in @file{configure.ac}.
16567 @end defvar
16569 @defvar CONFIG_HEADERS
16570 @evindex CONFIG_HEADERS
16571 The files in which to substitute C @code{#define} statements.  The
16572 default is the arguments given to @code{AC_CONFIG_HEADERS}; if that
16573 macro was not called, @file{config.status} ignores this variable.
16574 @end defvar
16576 @defvar CONFIG_LINKS
16577 @evindex CONFIG_LINKS
16578 The symbolic links to establish.  The default is the arguments given to
16579 @code{AC_CONFIG_LINKS}; if that macro was not called,
16580 @file{config.status} ignores this variable.
16581 @end defvar
16583 In @ref{config.status Invocation}, using this old interface, the example
16584 would be:
16586 @example
16587 @group
16588 config.h: stamp-h
16589 stamp-h: config.h.in config.status
16590         CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_FILES= \
16591           CONFIG_HEADERS=config.h ./config.status
16592         echo > stamp-h
16594 Makefile: Makefile.in config.status
16595         CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_HEADERS= \
16596           CONFIG_FILES=Makefile ./config.status
16597 @end group
16598 @end example
16600 @noindent
16601 (If @file{configure.ac} does not call @code{AC_CONFIG_HEADERS}, there is
16602 no need to set @code{CONFIG_HEADERS} in the @code{make} rules.  Equally
16603 for @code{CONFIG_COMMANDS}, etc.)
16606 @node acconfig Header
16607 @section @file{acconfig.h}
16609 @cindex @file{acconfig.h}
16610 @cindex @file{config.h.top}
16611 @cindex @file{config.h.bot}
16613 In order to produce @file{config.h.in}, @command{autoheader} needs to
16614 build or to find templates for each symbol.  Modern releases of Autoconf
16615 use @code{AH_VERBATIM} and @code{AH_TEMPLATE} (@pxref{Autoheader
16616 Macros}), but in older releases a file, @file{acconfig.h}, contained the
16617 list of needed templates.  @command{autoheader} copied comments and
16618 @code{#define} and @code{#undef} statements from @file{acconfig.h} in
16619 the current directory, if present.  This file used to be mandatory if
16620 you @code{AC_DEFINE} any additional symbols.
16622 Modern releases of Autoconf also provide @code{AH_TOP} and
16623 @code{AH_BOTTOM} if you need to prepend/append some information to
16624 @file{config.h.in}.  Ancient versions of Autoconf had a similar feature:
16625 if @file{./acconfig.h} contains the string @samp{@@TOP@@},
16626 @command{autoheader} copies the lines before the line containing
16627 @samp{@@TOP@@} into the top of the file that it generates.  Similarly,
16628 if @file{./acconfig.h} contains the string @samp{@@BOTTOM@@},
16629 @command{autoheader} copies the lines after that line to the end of the
16630 file it generates.  Either or both of those strings may be omitted.  An
16631 even older alternate way to produce the same effect in ancient versions
16632 of Autoconf is to create the files @file{@var{file}.top} (typically
16633 @file{config.h.top}) and/or @file{@var{file}.bot} in the current
16634 directory.  If they exist, @command{autoheader} copies them to the
16635 beginning and end, respectively, of its output.
16637 In former versions of Autoconf, the files used in preparing a software
16638 package for distribution were:
16639 @example
16640 @group
16641 configure.ac --.   .------> autoconf* -----> configure
16642                +---+
16643 [aclocal.m4] --+   `---.
16644 [acsite.m4] ---'       |
16645                        +--> [autoheader*] -> [config.h.in]
16646 [acconfig.h] ----.     |
16647                  +-----'
16648 [config.h.top] --+
16649 [config.h.bot] --'
16650 @end group
16651 @end example
16653 Using only the @code{AH_} macros, @file{configure.ac} should be
16654 self-contained, and should not depend upon @file{acconfig.h} etc.
16657 @node autoupdate Invocation
16658 @section Using @command{autoupdate} to Modernize @file{configure.ac}
16659 @cindex @command{autoupdate}
16661 The @command{autoupdate} program updates a @file{configure.ac} file that
16662 calls Autoconf macros by their old names to use the current macro names.
16663 In version 2 of Autoconf, most of the macros were renamed to use a more
16664 uniform and descriptive naming scheme.  @xref{Macro Names}, for a
16665 description of the new scheme.  Although the old names still work
16666 (@pxref{Obsolete Macros}, for a list of the old macros and the corresponding
16667 new names), you can make your @file{configure.ac} files more readable
16668 and make it easier to use the current Autoconf documentation if you
16669 update them to use the new macro names.
16671 @evindex SIMPLE_BACKUP_SUFFIX
16672 If given no arguments, @command{autoupdate} updates @file{configure.ac},
16673 backing up the original version with the suffix @file{~} (or the value
16674 of the environment variable @code{SIMPLE_BACKUP_SUFFIX}, if that is
16675 set).  If you give @command{autoupdate} an argument, it reads that file
16676 instead of @file{configure.ac} and writes the updated file to the
16677 standard output.
16679 @noindent
16680 @command{autoupdate} accepts the following options:
16682 @table @option
16683 @item --help
16684 @itemx -h
16685 Print a summary of the command line options and exit.
16687 @item --version
16688 @itemx -V
16689 Print the version number of Autoconf and exit.
16691 @item --verbose
16692 @itemx -v
16693 Report processing steps.
16695 @item --debug
16696 @itemx -d
16697 Don't remove the temporary files.
16699 @item --force
16700 @itemx -f
16701 Force the update even if the file has not changed.  Disregard the cache.
16703 @item --include=@var{dir}
16704 @itemx -I @var{dir}
16705 Also look for input files in @var{dir}.  Multiple invocations accumulate.
16706 Directories are browsed from last to first.
16707 @end table
16709 @node Obsolete Macros
16710 @section Obsolete Macros
16712 Several macros are obsoleted in Autoconf, for various reasons (typically
16713 they failed to quote properly, couldn't be extended for more recent
16714 issues, etc.).  They are still supported, but deprecated: their use
16715 should be avoided.
16717 During the jump from Autoconf version 1 to version 2, most of the
16718 macros were renamed to use a more uniform and descriptive naming scheme,
16719 but their signature did not change.  @xref{Macro Names}, for a
16720 description of the new naming scheme.  Below, if there is just the mapping
16721 from old names to new names for these macros, the reader is invited to
16722 refer to the definition of the new macro for the signature and the
16723 description.
16725 @defmac AC_ALLOCA
16726 @acindex{ALLOCA}
16727 @code{AC_FUNC_ALLOCA}
16728 @end defmac
16730 @defmac AC_ARG_ARRAY
16731 @acindex{ARG_ARRAY}
16732 removed because of limited usefulness
16733 @end defmac
16735 @defmac AC_C_CROSS
16736 @acindex{C_CROSS}
16737 This macro is obsolete; it does nothing.
16738 @end defmac
16740 @defmac AC_C_LONG_DOUBLE
16741 @acindex{C_LONG_DOUBLE}
16742 @cvindex HAVE_LONG_DOUBLE
16743 If the C compiler supports a working @code{long double} type with more
16744 range or precision than the @code{double} type, define
16745 @code{HAVE_LONG_DOUBLE}.
16747 You should use @code{AC_TYPE_LONG_DOUBLE} or
16748 @code{AC_TYPE_LONG_DOUBLE_WIDER} instead.  @xref{Particular Types}.
16749 @end defmac
16751 @defmac AC_CANONICAL_SYSTEM
16752 @acindex{CANONICAL_SYSTEM}
16753 Determine the system type and set output variables to the names of the
16754 canonical system types.  @xref{Canonicalizing}, for details about the
16755 variables this macro sets.
16757 The user is encouraged to use either @code{AC_CANONICAL_BUILD}, or
16758 @code{AC_CANONICAL_HOST}, or @code{AC_CANONICAL_TARGET}, depending on
16759 the needs.  Using @code{AC_CANONICAL_TARGET} is enough to run the two
16760 other macros.
16761 @end defmac
16763 @defmac AC_CHAR_UNSIGNED
16764 @acindex{CHAR_UNSIGNED}
16765 @code{AC_C_CHAR_UNSIGNED}
16766 @end defmac
16768 @defmac AC_CHECK_TYPE (@var{type}, @var{default})
16769 @acindex{CHECK_TYPE}
16770 Autoconf, up to 2.13, used to provide this version of
16771 @code{AC_CHECK_TYPE}, deprecated because of its flaws.  First, although
16772 it is a member of the @code{CHECK} clan, it does
16773 more than just checking.  Secondly, missing types are defined
16774 using @code{#define}, not @code{typedef}, and this can lead to
16775 problems in the case of pointer types.
16777 This use of @code{AC_CHECK_TYPE} is obsolete and discouraged; see
16778 @ref{Generic Types}, for the description of the current macro.
16780 If the type @var{type} is not defined, define it to be the C (or C++)
16781 builtin type @var{default}, e.g., @samp{short int} or @samp{unsigned int}.
16783 This macro is equivalent to:
16785 @example
16786 AC_CHECK_TYPE([@var{type}], [],
16787   [AC_DEFINE_UNQUOTED([@var{type}], [@var{default}],
16788      [Define to `@var{default}'
16789       if <sys/types.h> does not define.])])
16790 @end example
16792 In order to keep backward compatibility, the two versions of
16793 @code{AC_CHECK_TYPE} are implemented, selected by a simple heuristics:
16795 @enumerate
16796 @item
16797 If there are three or four arguments, the modern version is used.
16799 @item
16800 If the second argument appears to be a C or C++ type, then the
16801 obsolete version is used.  This happens if the argument is a C or C++
16802 @emph{builtin} type or a C identifier ending in @samp{_t}, optionally
16803 followed by one of @samp{[(* } and then by a string of zero or more
16804 characters taken from the set @samp{[]()* _a-zA-Z0-9}.
16806 @item
16807 If the second argument is spelled with the alphabet of valid C and C++
16808 types, the user is warned and the modern version is used.
16810 @item
16811 Otherwise, the modern version is used.
16812 @end enumerate
16814 @noindent
16815 You are encouraged either to use a valid builtin type, or to use the
16816 equivalent modern code (see above), or better yet, to use
16817 @code{AC_CHECK_TYPES} together with
16819 @example
16820 #ifndef HAVE_LOFF_T
16821 typedef loff_t off_t;
16822 #endif
16823 @end example
16824 @end defmac
16825 @c end of AC_CHECK_TYPE
16827 @defmac AC_CHECKING (@var{feature-description})
16828 @acindex{CHECKING}
16829 Same as @samp{AC_MSG_NOTICE([checking @var{feature-description}@dots{}]}.
16830 @end defmac
16832 @defmac AC_COMPILE_CHECK (@var{echo-text}, @var{includes}, @var{function-body}, @var{action-if-true}, @ovar{action-if-false})
16833 @acindex{COMPILE_CHECK}
16834 This is an obsolete version of @code{AC_TRY_COMPILE} itself replaced by
16835 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}), with the
16836 addition that it prints @samp{checking for @var{echo-text}} to the
16837 standard output first, if @var{echo-text} is non-empty.  Use
16838 @code{AC_MSG_CHECKING} and @code{AC_MSG_RESULT} instead to print
16839 messages (@pxref{Printing Messages}).
16840 @end defmac
16842 @defmac AC_CONST
16843 @acindex{CONST}
16844 @code{AC_C_CONST}
16845 @end defmac
16847 @defmac AC_CROSS_CHECK
16848 @acindex{CROSS_CHECK}
16849 Same as @code{AC_C_CROSS}, which is obsolete too, and does nothing
16850 @code{:-)}.
16851 @end defmac
16853 @defmac AC_CYGWIN
16854 @acindex{CYGWIN}
16855 Check for the Cygwin environment in which case the shell variable
16856 @code{CYGWIN} is set to @samp{yes}.  Don't use this macro, the dignified
16857 means to check the nature of the host is using
16858 @code{AC_CANONICAL_HOST}.  As a matter of fact this macro is defined as:
16860 @example
16861 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
16862 case $host_os in
16863   *cygwin* ) CYGWIN=yes;;
16864          * ) CYGWIN=no;;
16865 esac
16866 @end example
16868 Beware that the variable @code{CYGWIN} has a special meaning when
16869 running Cygwin, and should not be changed.  That's yet another reason
16870 not to use this macro.
16871 @end defmac
16873 @defmac AC_DECL_SYS_SIGLIST
16874 @acindex{DECL_SYS_SIGLIST}
16875 @cvindex SYS_SIGLIST_DECLARED
16876 Same as:
16878 @example
16879 AC_CHECK_DECLS([sys_siglist], [], [],
16880 [#include <signal.h>
16881 /* NetBSD declares sys_siglist in unistd.h.  */
16882 #ifdef HAVE_UNISTD_H
16883 # include <unistd.h>
16884 #endif
16886 @end example
16887 @end defmac
16889 @defmac AC_DECL_YYTEXT
16890 @acindex{DECL_YYTEXT}
16891 Does nothing, now integrated in @code{AC_PROG_LEX}.
16892 @end defmac
16894 @defmac AC_DIR_HEADER
16895 @acindex{DIR_HEADER}
16896 @cvindex DIRENT
16897 @cvindex SYSNDIR
16898 @cvindex SYSDIR
16899 @cvindex NDIR
16900 Like calling @code{AC_FUNC_CLOSEDIR_VOID} and@code{AC_HEADER_DIRENT},
16901 but defines a different set of C preprocessor macros to indicate which
16902 header file is found:
16904 @multitable {@file{sys/ndir.h}} {Old Symbol} {@code{HAVE_SYS_NDIR_H}}
16905 @item Header            @tab Old Symbol     @tab New Symbol
16906 @item @file{dirent.h}   @tab @code{DIRENT}  @tab @code{HAVE_DIRENT_H}
16907 @item @file{sys/ndir.h} @tab @code{SYSNDIR} @tab @code{HAVE_SYS_NDIR_H}
16908 @item @file{sys/dir.h}  @tab @code{SYSDIR}  @tab @code{HAVE_SYS_DIR_H}
16909 @item @file{ndir.h}     @tab @code{NDIR}    @tab @code{HAVE_NDIR_H}
16910 @end multitable
16911 @end defmac
16913 @defmac AC_DYNIX_SEQ
16914 @acindex{DYNIX_SEQ}
16915 If on DYNIX/ptx, add @option{-lseq} to output variable
16916 @code{LIBS}.  This macro used to be defined as
16918 @example
16919 AC_CHECK_LIB([seq], [getmntent], [LIBS="-lseq $LIBS"])
16920 @end example
16922 @noindent
16923 now it is just @code{AC_FUNC_GETMNTENT}.
16924 @end defmac
16926 @defmac AC_EXEEXT
16927 @acindex{EXEEXT}
16928 @ovindex EXEEXT
16929 Defined the output variable @code{EXEEXT} based on the output of the
16930 compiler, which is now done automatically.  Typically set to empty
16931 string if Posix and @samp{.exe} if a @acronym{DOS} variant.
16932 @end defmac
16934 @defmac AC_EMXOS2
16935 @acindex{EMXOS2}
16936 Similar to @code{AC_CYGWIN} but checks for the EMX environment on OS/2
16937 and sets @code{EMXOS2}.
16938 @end defmac
16940 @defmac AC_ERROR
16941 @acindex{ERROR}
16942 @code{AC_MSG_ERROR}
16943 @end defmac
16945 @defmac AC_FIND_X
16946 @acindex{FIND_X}
16947 @code{AC_PATH_X}
16948 @end defmac
16950 @defmac AC_FIND_XTRA
16951 @acindex{FIND_XTRA}
16952 @code{AC_PATH_XTRA}
16953 @end defmac
16955 @defmac AC_FOREACH
16956 @acindex{FOREACH}
16957 @code{m4_foreach_w}
16958 @end defmac
16960 @defmac AC_FUNC_CHECK
16961 @acindex{FUNC_CHECK}
16962 @code{AC_CHECK_FUNC}
16963 @end defmac
16965 @defmac AC_FUNC_SETVBUF_REVERSED
16966 @acindex{FUNC_SETVBUF_REVERSED}
16967 @cvindex SETVBUF_REVERSED
16968 @c @fuindex setvbuf
16969 @prindex @code{setvbuf}
16970 Do nothing.  Formerly, this macro checked whether @code{setvbuf} takes
16971 the buffering type as its second argument and the buffer pointer as the
16972 third, instead of the other way around, and defined
16973 @code{SETVBUF_REVERSED}.  However, the last systems to have the problem
16974 were those based on SVR2, which became obsolete in 1987, and the macro
16975 is no longer needed.
16976 @end defmac
16978 @defmac AC_FUNC_WAIT3
16979 @acindex{FUNC_WAIT3}
16980 @cvindex HAVE_WAIT3
16981 If @code{wait3} is found and fills in the contents of its third argument
16982 (a @samp{struct rusage *}), which @acronym{HP-UX} does not do, define
16983 @code{HAVE_WAIT3}.
16985 These days portable programs should use @code{waitpid}, not
16986 @code{wait3}, as @code{wait3} has been removed from Posix.
16987 @end defmac
16989 @defmac AC_GCC_TRADITIONAL
16990 @acindex{GCC_TRADITIONAL}
16991 @code{AC_PROG_GCC_TRADITIONAL}
16992 @end defmac
16994 @defmac AC_GETGROUPS_T
16995 @acindex{GETGROUPS_T}
16996 @code{AC_TYPE_GETGROUPS}
16997 @end defmac
16999 @defmac AC_GETLOADAVG
17000 @acindex{GETLOADAVG}
17001 @code{AC_FUNC_GETLOADAVG}
17002 @end defmac
17004 @defmac AC_HAVE_FUNCS
17005 @acindex{HAVE_FUNCS}
17006 @code{AC_CHECK_FUNCS}
17007 @end defmac
17009 @defmac AC_HAVE_HEADERS
17010 @acindex{HAVE_HEADERS}
17011 @code{AC_CHECK_HEADERS}
17012 @end defmac
17014 @defmac AC_HAVE_LIBRARY (@var{library}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
17015 @acindex{HAVE_LIBRARY}
17016 This macro is equivalent to calling @code{AC_CHECK_LIB} with a
17017 @var{function} argument of @code{main}.  In addition, @var{library} can
17018 be written as any of @samp{foo}, @option{-lfoo}, or @samp{libfoo.a}.  In
17019 all of those cases, the compiler is passed @option{-lfoo}.  However,
17020 @var{library} cannot be a shell variable; it must be a literal name.
17021 @end defmac
17023 @defmac AC_HAVE_POUNDBANG
17024 @acindex{HAVE_POUNDBANG}
17025 @code{AC_SYS_INTERPRETER} (different calling convention)
17026 @end defmac
17028 @defmac AC_HEADER_CHECK
17029 @acindex{HEADER_CHECK}
17030 @code{AC_CHECK_HEADER}
17031 @end defmac
17033 @defmac AC_HEADER_EGREP
17034 @acindex{HEADER_EGREP}
17035 @code{AC_EGREP_HEADER}
17036 @end defmac
17038 @defmac AC_HELP_STRING
17039 @acindex{HELP_STRING}
17040 @code{AS_HELP_STRING}
17041 @end defmac
17043 @defmac AC_INIT (@var{unique-file-in-source-dir})
17044 @acindex{INIT}
17045 Formerly @code{AC_INIT} used to have a single argument, and was
17046 equivalent to:
17048 @example
17049 AC_INIT
17050 AC_CONFIG_SRCDIR(@var{unique-file-in-source-dir})
17051 @end example
17052 @end defmac
17054 @defmac AC_INLINE
17055 @acindex{INLINE}
17056 @code{AC_C_INLINE}
17057 @end defmac
17059 @defmac AC_INT_16_BITS
17060 @acindex{INT_16_BITS}
17061 @cvindex INT_16_BITS
17062 If the C type @code{int} is 16 bits wide, define @code{INT_16_BITS}.
17063 Use @samp{AC_CHECK_SIZEOF(int)} instead.
17064 @end defmac
17066 @defmac AC_IRIX_SUN
17067 @acindex{IRIX_SUN}
17068 If on @sc{irix} (Silicon Graphics Unix), add @option{-lsun} to output
17069 @code{LIBS}.  If you were using it to get @code{getmntent}, use
17070 @code{AC_FUNC_GETMNTENT} instead.  If you used it for the NIS versions
17071 of the password and group functions, use @samp{AC_CHECK_LIB(sun,
17072 getpwnam)}.  Up to Autoconf 2.13, it used to be
17074 @example
17075 AC_CHECK_LIB([sun], [getmntent], [LIBS="-lsun $LIBS"])
17076 @end example
17078 @noindent
17079 now it is defined as
17081 @example
17082 AC_FUNC_GETMNTENT
17083 AC_CHECK_LIB([sun], [getpwnam])
17084 @end example
17085 @end defmac
17087 @defmac AC_LANG_C
17088 @acindex{LANG_C}
17089 Same as @samp{AC_LANG([C])}.
17090 @end defmac
17092 @defmac AC_LANG_CPLUSPLUS
17093 @acindex{LANG_CPLUSPLUS}
17094 Same as @samp{AC_LANG([C++])}.
17095 @end defmac
17097 @defmac AC_LANG_FORTRAN77
17098 @acindex{LANG_FORTRAN77}
17099 Same as @samp{AC_LANG([Fortran 77])}.
17100 @end defmac
17102 @defmac AC_LANG_RESTORE
17103 @acindex{LANG_RESTORE}
17104 Select the @var{language} that is saved on the top of the stack, as set
17105 by @code{AC_LANG_SAVE}, remove it from the stack, and call
17106 @code{AC_LANG(@var{language})}.
17107 @end defmac
17109 @defmac AC_LANG_SAVE
17110 @acindex{LANG_SAVE}
17111 Remember the current language (as set by @code{AC_LANG}) on a stack.
17112 The current language does not change.  @code{AC_LANG_PUSH} is preferred.
17113 @end defmac
17115 @defmac AC_LINK_FILES (@var{source}@dots{}, @var{dest}@dots{})
17116 @acindex{LINK_FILES}
17117 This is an obsolete version of @code{AC_CONFIG_LINKS}.  An updated
17118 version of:
17120 @example
17121 AC_LINK_FILES(config/$machine.h config/$obj_format.h,
17122               host.h            object.h)
17123 @end example
17125 @noindent
17128 @example
17129 AC_CONFIG_LINKS([host.h:config/$machine.h
17130                 object.h:config/$obj_format.h])
17131 @end example
17132 @end defmac
17134 @defmac AC_LN_S
17135 @acindex{LN_S}
17136 @code{AC_PROG_LN_S}
17137 @end defmac
17139 @defmac AC_LONG_64_BITS
17140 @acindex{LONG_64_BITS}
17141 @cvindex LONG_64_BITS
17142 Define @code{LONG_64_BITS} if the C type @code{long int} is 64 bits wide.
17143 Use the generic macro @samp{AC_CHECK_SIZEOF([long int])} instead.
17144 @end defmac
17146 @defmac AC_LONG_DOUBLE
17147 @acindex{LONG_DOUBLE}
17148 If the C compiler supports a working @code{long double} type with more
17149 range or precision than the @code{double} type, define
17150 @code{HAVE_LONG_DOUBLE}.
17152 You should use @code{AC_TYPE_LONG_DOUBLE} or
17153 @code{AC_TYPE_LONG_DOUBLE_WIDER} instead.  @xref{Particular Types}.
17154 @end defmac
17156 @defmac AC_LONG_FILE_NAMES
17157 @acindex{LONG_FILE_NAMES}
17158 @code{AC_SYS_LONG_FILE_NAMES}
17159 @end defmac
17161 @defmac AC_MAJOR_HEADER
17162 @acindex{MAJOR_HEADER}
17163 @code{AC_HEADER_MAJOR}
17164 @end defmac
17166 @defmac AC_MEMORY_H
17167 @acindex{MEMORY_H}
17168 @cvindex NEED_MEMORY_H
17169 Used to define @code{NEED_MEMORY_H} if the @code{mem} functions were
17170 defined in @file{memory.h}.  Today it is equivalent to
17171 @samp{AC_CHECK_HEADERS([memory.h])}.  Adjust your code to depend upon
17172 @code{HAVE_MEMORY_H}, not @code{NEED_MEMORY_H}; see @ref{Standard
17173 Symbols}.
17174 @end defmac
17176 @defmac AC_MINGW32
17177 @acindex{MINGW32}
17178 Similar to @code{AC_CYGWIN} but checks for the MinGW compiler
17179 environment and sets @code{MINGW32}.
17180 @end defmac
17182 @defmac AC_MINUS_C_MINUS_O
17183 @acindex{MINUS_C_MINUS_O}
17184 @code{AC_PROG_CC_C_O}
17185 @end defmac
17187 @defmac AC_MMAP
17188 @acindex{MMAP}
17189 @code{AC_FUNC_MMAP}
17190 @end defmac
17192 @defmac AC_MODE_T
17193 @acindex{MODE_T}
17194 @code{AC_TYPE_MODE_T}
17195 @end defmac
17197 @defmac AC_OBJEXT
17198 @acindex{OBJEXT}
17199 @ovindex OBJEXT
17200 Defined the output variable @code{OBJEXT} based on the output of the
17201 compiler, after .c files have been excluded.  Typically set to @samp{o}
17202 if Posix, @samp{obj} if a @acronym{DOS} variant.
17203 Now the compiler checking macros handle
17204 this automatically.
17205 @end defmac
17207 @defmac AC_OBSOLETE (@var{this-macro-name}, @ovar{suggestion})
17208 @acindex{OBSOLETE}
17209 Make M4 print a message to the standard error output warning that
17210 @var{this-macro-name} is obsolete, and giving the file and line number
17211 where it was called.  @var{this-macro-name} should be the name of the
17212 macro that is calling @code{AC_OBSOLETE}.  If @var{suggestion} is given,
17213 it is printed at the end of the warning message; for example, it can be
17214 a suggestion for what to use instead of @var{this-macro-name}.
17216 For instance
17218 @example
17219 AC_OBSOLETE([$0], [; use AC_CHECK_HEADERS(unistd.h) instead])dnl
17220 @end example
17222 You are encouraged to use @code{AU_DEFUN} instead, since it gives better
17223 services to the user.
17224 @end defmac
17226 @defmac AC_OFF_T
17227 @acindex{OFF_T}
17228 @code{AC_TYPE_OFF_T}
17229 @end defmac
17231 @defmac AC_OUTPUT (@ovar{file}@dots{}, @ovar{extra-cmds}, @ovar{init-cmds})
17232 @acindex{OUTPUT}
17233 The use of @code{AC_OUTPUT} with argument is deprecated.  This obsoleted
17234 interface is equivalent to:
17236 @example
17237 @group
17238 AC_CONFIG_FILES(@var{file}@dots{})
17239 AC_CONFIG_COMMANDS([default],
17240                    @var{extra-cmds}, @var{init-cmds})
17241 AC_OUTPUT
17242 @end group
17243 @end example
17244 @end defmac
17246 @defmac AC_OUTPUT_COMMANDS (@var{extra-cmds}, @ovar{init-cmds})
17247 @acindex{OUTPUT_COMMANDS}
17248 Specify additional shell commands to run at the end of
17249 @file{config.status}, and shell commands to initialize any variables
17250 from @command{configure}.  This macro may be called multiple times.  It is
17251 obsolete, replaced by @code{AC_CONFIG_COMMANDS}.
17253 Here is an unrealistic example:
17255 @example
17256 fubar=27
17257 AC_OUTPUT_COMMANDS([echo this is extra $fubar, and so on.],
17258                    [fubar=$fubar])
17259 AC_OUTPUT_COMMANDS([echo this is another, extra, bit],
17260                    [echo init bit])
17261 @end example
17263 Aside from the fact that @code{AC_CONFIG_COMMANDS} requires an
17264 additional key, an important difference is that
17265 @code{AC_OUTPUT_COMMANDS} is quoting its arguments twice, unlike
17266 @code{AC_CONFIG_COMMANDS}.  This means that @code{AC_CONFIG_COMMANDS}
17267 can safely be given macro calls as arguments:
17269 @example
17270 AC_CONFIG_COMMANDS(foo, [my_FOO()])
17271 @end example
17273 @noindent
17274 Conversely, where one level of quoting was enough for literal strings
17275 with @code{AC_OUTPUT_COMMANDS}, you need two with
17276 @code{AC_CONFIG_COMMANDS}.  The following lines are equivalent:
17278 @example
17279 @group
17280 AC_OUTPUT_COMMANDS([echo "Square brackets: []"])
17281 AC_CONFIG_COMMANDS([default], [[echo "Square brackets: []"]])
17282 @end group
17283 @end example
17284 @end defmac
17286 @defmac AC_PID_T
17287 @acindex{PID_T}
17288 @code{AC_TYPE_PID_T}
17289 @end defmac
17291 @defmac AC_PREFIX
17292 @acindex{PREFIX}
17293 @code{AC_PREFIX_PROGRAM}
17294 @end defmac
17296 @defmac AC_PROGRAMS_CHECK
17297 @acindex{PROGRAMS_CHECK}
17298 @code{AC_CHECK_PROGS}
17299 @end defmac
17301 @defmac AC_PROGRAMS_PATH
17302 @acindex{PROGRAMS_PATH}
17303 @code{AC_PATH_PROGS}
17304 @end defmac
17306 @defmac AC_PROGRAM_CHECK
17307 @acindex{PROGRAM_CHECK}
17308 @code{AC_CHECK_PROG}
17309 @end defmac
17311 @defmac AC_PROGRAM_EGREP
17312 @acindex{PROGRAM_EGREP}
17313 @code{AC_EGREP_CPP}
17314 @end defmac
17316 @defmac AC_PROGRAM_PATH
17317 @acindex{PROGRAM_PATH}
17318 @code{AC_PATH_PROG}
17319 @end defmac
17321 @defmac AC_REMOTE_TAPE
17322 @acindex{REMOTE_TAPE}
17323 removed because of limited usefulness
17324 @end defmac
17326 @defmac AC_RESTARTABLE_SYSCALLS
17327 @acindex{RESTARTABLE_SYSCALLS}
17328 @code{AC_SYS_RESTARTABLE_SYSCALLS}
17329 @end defmac
17331 @defmac AC_RETSIGTYPE
17332 @acindex{RETSIGTYPE}
17333 @code{AC_TYPE_SIGNAL}
17334 @end defmac
17336 @defmac AC_RSH
17337 @acindex{RSH}
17338 removed because of limited usefulness
17339 @end defmac
17341 @defmac AC_SCO_INTL
17342 @acindex{SCO_INTL}
17343 @ovindex LIBS
17344 If on SCO Unix, add @option{-lintl} to output variable @code{LIBS}.  This
17345 macro used to do this:
17347 @example
17348 AC_CHECK_LIB([intl], [strftime], [LIBS="-lintl $LIBS"])
17349 @end example
17351 @noindent
17352 Now it just calls @code{AC_FUNC_STRFTIME} instead.
17353 @end defmac
17355 @defmac AC_SETVBUF_REVERSED
17356 @acindex{SETVBUF_REVERSED}
17357 @code{AC_FUNC_SETVBUF_REVERSED}
17358 @end defmac
17360 @defmac AC_SET_MAKE
17361 @acindex{SET_MAKE}
17362 @code{AC_PROG_MAKE_SET}
17363 @end defmac
17365 @defmac AC_SIZEOF_TYPE
17366 @acindex{SIZEOF_TYPE}
17367 @code{AC_CHECK_SIZEOF}
17368 @end defmac
17370 @defmac AC_SIZE_T
17371 @acindex{SIZE_T}
17372 @code{AC_TYPE_SIZE_T}
17373 @end defmac
17375 @defmac AC_STAT_MACROS_BROKEN
17376 @acindex{STAT_MACROS_BROKEN}
17377 @code{AC_HEADER_STAT}
17378 @end defmac
17380 @defmac AC_STDC_HEADERS
17381 @acindex{STDC_HEADERS}
17382 @code{AC_HEADER_STDC}
17383 @end defmac
17385 @defmac AC_STRCOLL
17386 @acindex{STRCOLL}
17387 @code{AC_FUNC_STRCOLL}
17388 @end defmac
17390 @defmac AC_ST_BLKSIZE
17391 @acindex{ST_BLKSIZE}
17392 @code{AC_CHECK_MEMBERS}
17393 @end defmac
17395 @defmac AC_ST_BLOCKS
17396 @acindex{ST_BLOCKS}
17397 @code{AC_STRUCT_ST_BLOCKS}
17398 @end defmac
17400 @defmac AC_ST_RDEV
17401 @acindex{ST_RDEV}
17402 @code{AC_CHECK_MEMBERS}
17403 @end defmac
17405 @defmac AC_SYS_RESTARTABLE_SYSCALLS
17406 @acindex{SYS_RESTARTABLE_SYSCALLS}
17407 @cvindex HAVE_RESTARTABLE_SYSCALLS
17408 If the system automatically restarts a system call that is interrupted
17409 by a signal, define @code{HAVE_RESTARTABLE_SYSCALLS}.  This macro does
17410 not check whether system calls are restarted in general---it checks whether a
17411 signal handler installed with @code{signal} (but not @code{sigaction})
17412 causes system calls to be restarted.  It does not check whether system calls
17413 can be restarted when interrupted by signals that have no handler.
17415 These days portable programs should use @code{sigaction} with
17416 @code{SA_RESTART} if they want restartable system calls.  They should
17417 not rely on @code{HAVE_RESTARTABLE_SYSCALLS}, since nowadays whether a
17418 system call is restartable is a dynamic issue, not a configuration-time
17419 issue.
17420 @end defmac
17422 @defmac AC_SYS_SIGLIST_DECLARED
17423 @acindex{SYS_SIGLIST_DECLARED}
17424 @code{AC_DECL_SYS_SIGLIST}
17425 @end defmac
17427 @defmac AC_TEST_CPP
17428 @acindex{TEST_CPP}
17429 @code{AC_TRY_CPP}, replaced by @code{AC_PREPROC_IFELSE}.
17430 @end defmac
17432 @defmac AC_TEST_PROGRAM
17433 @acindex{TEST_PROGRAM}
17434 @code{AC_TRY_RUN}, replaced by @code{AC_RUN_IFELSE}.
17435 @end defmac
17437 @defmac AC_TIMEZONE
17438 @acindex{TIMEZONE}
17439 @code{AC_STRUCT_TIMEZONE}
17440 @end defmac
17442 @defmac AC_TIME_WITH_SYS_TIME
17443 @acindex{TIME_WITH_SYS_TIME}
17444 @code{AC_HEADER_TIME}
17445 @end defmac
17447 @defmac AC_TRY_COMPILE (@var{includes}, @var{function-body}, @ovar{action-if-true}, @ovar{action-if-false})
17448 @acindex{TRY_COMPILE}
17449 Same as:
17451 @example
17452 AC_COMPILE_IFELSE(
17453   [AC_LANG_PROGRAM([[@var{includes}]],
17454      [[@var{function-body}]])],
17455   [@var{action-if-true}],
17456   [@var{action-if-false}])
17457 @end example
17459 @noindent
17460 @xref{Running the Compiler}.
17462 This macro double quotes both @var{includes} and @var{function-body}.
17464 For C and C++, @var{includes} is any @code{#include} statements needed
17465 by the code in @var{function-body} (@var{includes} is ignored if
17466 the currently selected language is Fortran or Fortran 77).  The compiler
17467 and compilation flags are determined by the current language
17468 (@pxref{Language Choice}).
17469 @end defmac
17471 @defmac AC_TRY_CPP (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
17472 @acindex{TRY_CPP}
17473 Same as:
17475 @example
17476 AC_PREPROC_IFELSE(
17477   [AC_LANG_SOURCE([[@var{input}]])],
17478   [@var{action-if-true}],
17479   [@var{action-if-false}])
17480 @end example
17482 @noindent
17483 @xref{Running the Preprocessor}.
17485 This macro double quotes the @var{input}.
17486 @end defmac
17488 @defmac AC_TRY_LINK (@var{includes}, @var{function-body}, @ovar{action-if-true}, @ovar{action-if-false})
17489 @acindex{TRY_LINK}
17490 Same as:
17492 @example
17493 AC_LINK_IFELSE(
17494   [AC_LANG_PROGRAM([[@var{includes}]],
17495      [[@var{function-body}]])],
17496   [@var{action-if-true}],
17497   [@var{action-if-false}])
17498 @end example
17500 @noindent
17501 @xref{Running the Compiler}.
17503 This macro double quotes both @var{includes} and @var{function-body}.
17505 Depending on the current language (@pxref{Language Choice}), create a
17506 test program to see whether a function whose body consists of
17507 @var{function-body} can be compiled and linked.  If the file compiles
17508 and links successfully, run shell commands @var{action-if-found},
17509 otherwise run @var{action-if-not-found}.
17511 This macro double quotes both @var{includes} and @var{function-body}.
17513 For C and C++, @var{includes} is any @code{#include} statements needed
17514 by the code in @var{function-body} (@var{includes} is ignored if
17515 the currently selected language is Fortran or Fortran 77).  The compiler
17516 and compilation flags are determined by the current language
17517 (@pxref{Language Choice}), and in addition @code{LDFLAGS} and
17518 @code{LIBS} are used for linking.
17519 @end defmac
17521 @defmac AC_TRY_LINK_FUNC (@var{function}, @ovar{action-if-found}, @ovar{action-if-not-found})
17522 @acindex{TRY_LINK_FUNC}
17523 This macro is equivalent to
17524 @samp{AC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])],
17525 [@var{action-if-found}], [@var{action-if-not-found}])}.
17526 @end defmac
17528 @defmac AC_TRY_RUN (@var{program}, @ovar{action-if-true}, @ovar{action-if-false}, @ovar{action-if-cross-compiling})
17529 @acindex{TRY_RUN}
17530 Same as:
17532 @example
17533 AC_RUN_IFELSE(
17534   [AC_LANG_SOURCE([[@var{program}]])],
17535   [@var{action-if-true}],
17536   [@var{action-if-false}],
17537   [@var{action-if-cross-compiling}])
17538 @end example
17540 @noindent
17541 @xref{Runtime}.
17542 @end defmac
17544 @defmac AC_UID_T
17545 @acindex{UID_T}
17546 @code{AC_TYPE_UID_T}
17547 @end defmac
17549 @defmac AC_UNISTD_H
17550 @acindex{UNISTD_H}
17551 Same as @samp{AC_CHECK_HEADERS([unistd.h])}.
17552 @end defmac
17554 @defmac AC_USG
17555 @acindex{USG}
17556 @cvindex USG
17557 Define @code{USG} if the @acronym{BSD} string functions are defined in
17558 @file{strings.h}.  You should no longer depend upon @code{USG}, but on
17559 @code{HAVE_STRING_H}; see @ref{Standard Symbols}.
17560 @end defmac
17562 @defmac AC_UTIME_NULL
17563 @acindex{UTIME_NULL}
17564 @code{AC_FUNC_UTIME_NULL}
17565 @end defmac
17567 @defmac AC_VALIDATE_CACHED_SYSTEM_TUPLE (@ovar{cmd})
17568 @acindex{VALIDATE_CACHED_SYSTEM_TUPLE}
17569 If the cache file is inconsistent with the current host, target and
17570 build system types, it used to execute @var{cmd} or print a default
17571 error message.  This is now handled by default.
17572 @end defmac
17574 @defmac AC_VERBOSE (@var{result-description})
17575 @acindex{VERBOSE}
17576 @code{AC_MSG_RESULT}.
17577 @end defmac
17579 @defmac AC_VFORK
17580 @acindex{VFORK}
17581 @code{AC_FUNC_VFORK}
17582 @end defmac
17584 @defmac AC_VPRINTF
17585 @acindex{VPRINTF}
17586 @code{AC_FUNC_VPRINTF}
17587 @end defmac
17589 @defmac AC_WAIT3
17590 @acindex{WAIT3}
17591 @code{AC_FUNC_WAIT3}
17592 @end defmac
17594 @defmac AC_WARN
17595 @acindex{WARN}
17596 @code{AC_MSG_WARN}
17597 @end defmac
17599 @defmac AC_WORDS_BIGENDIAN
17600 @acindex{WORDS_BIGENDIAN}
17601 @code{AC_C_BIGENDIAN}
17602 @end defmac
17604 @defmac AC_XENIX_DIR
17605 @acindex{XENIX_DIR}
17606 @ovindex LIBS
17607 This macro used to add @option{-lx} to output variable @code{LIBS} if on
17608 Xenix.  Also, if @file{dirent.h} is being checked for, added
17609 @option{-ldir} to @code{LIBS}.  Now it is merely an alias of
17610 @code{AC_HEADER_DIRENT} instead, plus some code to detect whether
17611 running @sc{xenix} on which you should not depend:
17613 @example
17614 AC_MSG_CHECKING([for Xenix])
17615 AC_EGREP_CPP([yes],
17616 [#if defined M_XENIX && !defined M_UNIX
17617   yes
17618 #endif],
17619              [AC_MSG_RESULT([yes]); XENIX=yes],
17620              [AC_MSG_RESULT([no]); XENIX=])
17621 @end example
17622 @end defmac
17624 @defmac AC_YYTEXT_POINTER
17625 @acindex{YYTEXT_POINTER}
17626 @code{AC_DECL_YYTEXT}
17627 @end defmac
17629 @node Autoconf 1
17630 @section Upgrading From Version 1
17631 @cindex Upgrading autoconf
17632 @cindex Autoconf upgrading
17634 Autoconf version 2 is mostly backward compatible with version 1.
17635 However, it introduces better ways to do some things, and doesn't
17636 support some of the ugly things in version 1.  So, depending on how
17637 sophisticated your @file{configure.ac} files are, you might have to do
17638 some manual work in order to upgrade to version 2.  This chapter points
17639 out some problems to watch for when upgrading.  Also, perhaps your
17640 @command{configure} scripts could benefit from some of the new features in
17641 version 2; the changes are summarized in the file @file{NEWS} in the
17642 Autoconf distribution.
17644 @menu
17645 * Changed File Names::          Files you might rename
17646 * Changed Makefiles::           New things to put in @file{Makefile.in}
17647 * Changed Macros::              Macro calls you might replace
17648 * Changed Results::             Changes in how to check test results
17649 * Changed Macro Writing::       Better ways to write your own macros
17650 @end menu
17652 @node Changed File Names
17653 @subsection Changed File Names
17655 If you have an @file{aclocal.m4} installed with Autoconf (as opposed to
17656 in a particular package's source directory), you must rename it to
17657 @file{acsite.m4}.  @xref{autoconf Invocation}.
17659 If you distribute @file{install.sh} with your package, rename it to
17660 @file{install-sh} so @code{make} builtin rules don't inadvertently
17661 create a file called @file{install} from it.  @code{AC_PROG_INSTALL}
17662 looks for the script under both names, but it is best to use the new name.
17664 If you were using @file{config.h.top}, @file{config.h.bot}, or
17665 @file{acconfig.h}, you still can, but you have less clutter if you
17666 use the @code{AH_} macros.  @xref{Autoheader Macros}.
17668 @node Changed Makefiles
17669 @subsection Changed Makefiles
17671 Add @samp{@@CFLAGS@@}, @samp{@@CPPFLAGS@@}, and @samp{@@LDFLAGS@@} in
17672 your @file{Makefile.in} files, so they can take advantage of the values
17673 of those variables in the environment when @command{configure} is run.
17674 Doing this isn't necessary, but it's a convenience for users.
17676 Also add @samp{@@configure_input@@} in a comment to each input file for
17677 @code{AC_OUTPUT}, so that the output files contain a comment saying
17678 they were produced by @command{configure}.  Automatically selecting the
17679 right comment syntax for all the kinds of files that people call
17680 @code{AC_OUTPUT} on became too much work.
17682 Add @file{config.log} and @file{config.cache} to the list of files you
17683 remove in @code{distclean} targets.
17685 If you have the following in @file{Makefile.in}:
17687 @example
17688 prefix = /usr/local
17689 exec_prefix = $(prefix)
17690 @end example
17692 @noindent
17693 you must change it to:
17695 @example
17696 prefix = @@prefix@@
17697 exec_prefix = @@exec_prefix@@
17698 @end example
17700 @noindent
17701 The old behavior of replacing those variables without @samp{@@}
17702 characters around them has been removed.
17704 @node Changed Macros
17705 @subsection Changed Macros
17707 Many of the macros were renamed in Autoconf version 2.  You can still
17708 use the old names, but the new ones are clearer, and it's easier to find
17709 the documentation for them.  @xref{Obsolete Macros}, for a table showing the
17710 new names for the old macros.  Use the @command{autoupdate} program to
17711 convert your @file{configure.ac} to using the new macro names.
17712 @xref{autoupdate Invocation}.
17714 Some macros have been superseded by similar ones that do the job better,
17715 but are not call-compatible.  If you get warnings about calling obsolete
17716 macros while running @command{autoconf}, you may safely ignore them, but
17717 your @command{configure} script generally works better if you follow
17718 the advice that is printed about what to replace the obsolete macros with.  In
17719 particular, the mechanism for reporting the results of tests has
17720 changed.  If you were using @command{echo} or @code{AC_VERBOSE} (perhaps
17721 via @code{AC_COMPILE_CHECK}), your @command{configure} script's output
17722 looks better if you switch to @code{AC_MSG_CHECKING} and
17723 @code{AC_MSG_RESULT}.  @xref{Printing Messages}.  Those macros work best
17724 in conjunction with cache variables.  @xref{Caching Results}.
17728 @node Changed Results
17729 @subsection Changed Results
17731 If you were checking the results of previous tests by examining the
17732 shell variable @code{DEFS}, you need to switch to checking the values of
17733 the cache variables for those tests.  @code{DEFS} no longer exists while
17734 @command{configure} is running; it is only created when generating output
17735 files.  This difference from version 1 is because properly quoting the
17736 contents of that variable turned out to be too cumbersome and
17737 inefficient to do every time @code{AC_DEFINE} is called.  @xref{Cache
17738 Variable Names}.
17740 For example, here is a @file{configure.ac} fragment written for Autoconf
17741 version 1:
17743 @example
17744 AC_HAVE_FUNCS(syslog)
17745 case "$DEFS" in
17746 *-DHAVE_SYSLOG*) ;;
17747 *) # syslog is not in the default libraries.  See if it's in some other.
17748   saved_LIBS="$LIBS"
17749   for lib in bsd socket inet; do
17750     AC_CHECKING(for syslog in -l$lib)
17751     LIBS="-l$lib $saved_LIBS"
17752     AC_HAVE_FUNCS(syslog)
17753     case "$DEFS" in
17754     *-DHAVE_SYSLOG*) break ;;
17755     *) ;;
17756     esac
17757     LIBS="$saved_LIBS"
17758   done ;;
17759 esac
17760 @end example
17762 Here is a way to write it for version 2:
17764 @example
17765 AC_CHECK_FUNCS([syslog])
17766 if test $ac_cv_func_syslog = no; then
17767   # syslog is not in the default libraries.  See if it's in some other.
17768   for lib in bsd socket inet; do
17769     AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG])
17770       LIBS="-l$lib $LIBS"; break])
17771   done
17773 @end example
17775 If you were working around bugs in @code{AC_DEFINE_UNQUOTED} by adding
17776 backslashes before quotes, you need to remove them.  It now works
17777 predictably, and does not treat quotes (except back quotes) specially.
17778 @xref{Setting Output Variables}.
17780 All of the Boolean shell variables set by Autoconf macros now use
17781 @samp{yes} for the true value.  Most of them use @samp{no} for false,
17782 though for backward compatibility some use the empty string instead.  If
17783 you were relying on a shell variable being set to something like 1 or
17784 @samp{t} for true, you need to change your tests.
17786 @node Changed Macro Writing
17787 @subsection Changed Macro Writing
17789 When defining your own macros, you should now use @code{AC_DEFUN}
17790 instead of @code{define}.  @code{AC_DEFUN} automatically calls
17791 @code{AC_PROVIDE} and ensures that macros called via @code{AC_REQUIRE}
17792 do not interrupt other macros, to prevent nested @samp{checking@dots{}}
17793 messages on the screen.  There's no actual harm in continuing to use the
17794 older way, but it's less convenient and attractive.  @xref{Macro
17795 Definitions}.
17797 You probably looked at the macros that came with Autoconf as a guide for
17798 how to do things.  It would be a good idea to take a look at the new
17799 versions of them, as the style is somewhat improved and they take
17800 advantage of some new features.
17802 If you were doing tricky things with undocumented Autoconf internals
17803 (macros, variables, diversions), check whether you need to change
17804 anything to account for changes that have been made.  Perhaps you can
17805 even use an officially supported technique in version 2 instead of
17806 kludging.  Or perhaps not.
17808 To speed up your locally written feature tests, add caching to them.
17809 See whether any of your tests are of general enough usefulness to
17810 encapsulate them into macros that you can share.
17813 @node Autoconf 2.13
17814 @section Upgrading From Version 2.13
17815 @cindex Upgrading autoconf
17816 @cindex Autoconf upgrading
17818 The introduction of the previous section (@pxref{Autoconf 1}) perfectly
17819 suits this section@enddots{}
17821 @quotation
17822 Autoconf version 2.50 is mostly backward compatible with version 2.13.
17823 However, it introduces better ways to do some things, and doesn't
17824 support some of the ugly things in version 2.13.  So, depending on how
17825 sophisticated your @file{configure.ac} files are, you might have to do
17826 some manual work in order to upgrade to version 2.50.  This chapter
17827 points out some problems to watch for when upgrading.  Also, perhaps
17828 your @command{configure} scripts could benefit from some of the new
17829 features in version 2.50; the changes are summarized in the file
17830 @file{NEWS} in the Autoconf distribution.
17831 @end quotation
17833 @menu
17834 * Changed Quotation::           Broken code which used to work
17835 * New Macros::                  Interaction with foreign macros
17836 * Hosts and Cross-Compilation::  Bugward compatibility kludges
17837 * AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token
17838 * AC_FOO_IFELSE vs AC_TRY_FOO::  A more generic scheme for testing sources
17839 @end menu
17841 @node Changed Quotation
17842 @subsection Changed Quotation
17844 The most important changes are invisible to you: the implementation of
17845 most macros have completely changed.  This allowed more factorization of
17846 the code, better error messages, a higher uniformity of the user's
17847 interface etc.  Unfortunately, as a side effect, some construct which
17848 used to (miraculously) work might break starting with Autoconf 2.50.
17849 The most common culprit is bad quotation.
17851 For instance, in the following example, the message is not properly
17852 quoted:
17854 @example
17855 AC_INIT
17856 AC_CHECK_HEADERS(foo.h, ,
17857   AC_MSG_ERROR(cannot find foo.h, bailing out))
17858 AC_OUTPUT
17859 @end example
17861 @noindent
17862 Autoconf 2.13 simply ignores it:
17864 @example
17865 $ @kbd{autoconf-2.13; ./configure --silent}
17866 creating cache ./config.cache
17867 configure: error: cannot find foo.h
17869 @end example
17871 @noindent
17872 while Autoconf 2.50 produces a broken @file{configure}:
17874 @example
17875 $ @kbd{autoconf-2.50; ./configure --silent}
17876 configure: error: cannot find foo.h
17877 ./configure: exit: bad non-numeric arg `bailing'
17878 ./configure: exit: bad non-numeric arg `bailing'
17880 @end example
17882 The message needs to be quoted, and the @code{AC_MSG_ERROR} invocation
17883 too!
17885 @example
17886 AC_INIT([Example], [1.0], [bug-example@@example.org])
17887 AC_CHECK_HEADERS([foo.h], [],
17888   [AC_MSG_ERROR([cannot find foo.h, bailing out])])
17889 AC_OUTPUT
17890 @end example
17892 Many many (and many more) Autoconf macros were lacking proper quotation,
17893 including no less than@dots{} @code{AC_DEFUN} itself!
17895 @example
17896 $ @kbd{cat configure.in}
17897 AC_DEFUN([AC_PROG_INSTALL],
17898 [# My own much better version
17900 AC_INIT
17901 AC_PROG_INSTALL
17902 AC_OUTPUT
17903 $ @kbd{autoconf-2.13}
17904 autoconf: Undefined macros:
17905 ***BUG in Autoconf--please report*** AC_FD_MSG
17906 ***BUG in Autoconf--please report*** AC_EPI
17907 configure.in:1:AC_DEFUN([AC_PROG_INSTALL],
17908 configure.in:5:AC_PROG_INSTALL
17909 $ @kbd{autoconf-2.50}
17911 @end example
17914 @node New Macros
17915 @subsection New Macros
17917 @cindex undefined macro
17918 @cindex @code{_m4_divert_diversion}
17920 While Autoconf was relatively dormant in the late 1990s, Automake
17921 provided Autoconf-like macros for a while.  Starting with Autoconf 2.50
17922 in 2001, Autoconf provided
17923 versions of these macros, integrated in the @code{AC_} namespace,
17924 instead of @code{AM_}.  But in order to ease the upgrading via
17925 @command{autoupdate}, bindings to such @code{AM_} macros are provided.
17927 Unfortunately older versions of Automake (e.g., Automake 1.4)
17928 did not quote the names of these macros.
17929 Therefore, when @command{m4} finds something like
17930 @samp{AC_DEFUN(AM_TYPE_PTRDIFF_T, @dots{})} in @file{aclocal.m4},
17931 @code{AM_TYPE_PTRDIFF_T} is
17932 expanded, replaced with its Autoconf definition.
17934 Fortunately Autoconf catches pre-@code{AC_INIT} expansions, and
17935 complains, in its own words:
17937 @example
17938 $ @kbd{cat configure.ac}
17939 AC_INIT([Example], [1.0], [bug-example@@example.org])
17940 AM_TYPE_PTRDIFF_T
17941 $ @kbd{aclocal-1.4}
17942 $ @kbd{autoconf}
17943 aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversion
17944 aclocal.m4:17: the top level
17945 autom4te: m4 failed with exit status: 1
17947 @end example
17949 Modern versions of Automake no longer define most of these
17950 macros, and properly quote the names of the remaining macros.
17951 If you must use an old Automake, do not depend upon macros from Automake
17952 as it is simply not its job
17953 to provide macros (but the one it requires itself):
17955 @example
17956 $ @kbd{cat configure.ac}
17957 AC_INIT([Example], [1.0], [bug-example@@example.org])
17958 AM_TYPE_PTRDIFF_T
17959 $ @kbd{rm aclocal.m4}
17960 $ @kbd{autoupdate}
17961 autoupdate: `configure.ac' is updated
17962 $ @kbd{cat configure.ac}
17963 AC_INIT([Example], [1.0], [bug-example@@example.org])
17964 AC_CHECK_TYPES([ptrdiff_t])
17965 $ @kbd{aclocal-1.4}
17966 $ @kbd{autoconf}
17968 @end example
17971 @node Hosts and Cross-Compilation
17972 @subsection Hosts and Cross-Compilation
17973 @cindex Cross compilation
17975 Based on the experience of compiler writers, and after long public
17976 debates, many aspects of the cross-compilation chain have changed:
17978 @itemize @minus
17979 @item
17980 the relationship between the build, host, and target architecture types,
17982 @item
17983 the command line interface for specifying them to @command{configure},
17985 @item
17986 the variables defined in @command{configure},
17988 @item
17989 the enabling of cross-compilation mode.
17990 @end itemize
17992 @sp 1
17994 The relationship between build, host, and target have been cleaned up:
17995 the chain of default is now simply: target defaults to host, host to
17996 build, and build to the result of @command{config.guess}.  Nevertheless,
17997 in order to ease the transition from 2.13 to 2.50, the following
17998 transition scheme is implemented.  @emph{Do not rely on it}, as it will
17999 be completely disabled in a couple of releases (we cannot keep it, as it
18000 proves to cause more problems than it cures).
18002 They all default to the result of running @command{config.guess}, unless
18003 you specify either @option{--build} or @option{--host}.  In this case,
18004 the default becomes the system type you specified.  If you specify both,
18005 and they're different, @command{configure} enters cross compilation
18006 mode, so it doesn't run any tests that require execution.
18008 Hint: if you mean to override the result of @command{config.guess},
18009 prefer @option{--build} over @option{--host}.  In the future,
18010 @option{--host} will not override the name of the build system type.
18011 Whenever you specify @option{--host}, be sure to specify @option{--build}
18012 too.
18014 @sp 1
18016 For backward compatibility, @command{configure} accepts a system
18017 type as an option by itself.  Such an option overrides the
18018 defaults for build, host, and target system types.  The following
18019 configure statement configures a cross toolchain that runs on
18020 Net@acronym{BSD}/alpha but generates code for @acronym{GNU} Hurd/sparc,
18021 which is also the build platform.
18023 @example
18024 ./configure --host=alpha-netbsd sparc-gnu
18025 @end example
18027 @sp 1
18029 In Autoconf 2.13 and before, the variables @code{build}, @code{host},
18030 and @code{target} had a different semantics before and after the
18031 invocation of @code{AC_CANONICAL_BUILD} etc.  Now, the argument of
18032 @option{--build} is strictly copied into @code{build_alias}, and is left
18033 empty otherwise.  After the @code{AC_CANONICAL_BUILD}, @code{build} is
18034 set to the canonicalized build type.  To ease the transition, before,
18035 its contents is the same as that of @code{build_alias}.  Do @emph{not}
18036 rely on this broken feature.
18038 For consistency with the backward compatibility scheme exposed above,
18039 when @option{--host} is specified but @option{--build} isn't, the build
18040 system is assumed to be the same as @option{--host}, and
18041 @samp{build_alias} is set to that value.  Eventually, this
18042 historically incorrect behavior will go away.
18044 @sp 1
18046 The former scheme to enable cross-compilation proved to cause more harm
18047 than good, in particular, it used to be triggered too easily, leaving
18048 regular end users puzzled in front of cryptic error messages.
18049 @command{configure} could even enter cross-compilation mode only
18050 because the compiler was not functional.  This is mainly because
18051 @command{configure} used to try to detect cross-compilation, instead of
18052 waiting for an explicit flag from the user.
18054 Now, @command{configure} enters cross-compilation mode if and only if
18055 @option{--host} is passed.
18057 That's the short documentation.  To ease the transition between 2.13 and
18058 its successors, a more complicated scheme is implemented.  @emph{Do not
18059 rely on the following}, as it will be removed in the near future.
18061 If you specify @option{--host}, but not @option{--build}, when
18062 @command{configure} performs the first compiler test it tries to run
18063 an executable produced by the compiler.  If the execution fails, it
18064 enters cross-compilation mode.  This is fragile.  Moreover, by the time
18065 the compiler test is performed, it may be too late to modify the
18066 build-system type: other tests may have already been performed.
18067 Therefore, whenever you specify @option{--host}, be sure to specify
18068 @option{--build} too.
18070 @example
18071 ./configure --build=i686-pc-linux-gnu --host=m68k-coff
18072 @end example
18074 @noindent
18075 enters cross-compilation mode.  The former interface, which
18076 consisted in setting the compiler to a cross-compiler without informing
18077 @command{configure} is obsolete.  For instance, @command{configure}
18078 fails if it can't run the code generated by the specified compiler if you
18079 configure as follows:
18081 @example
18082 ./configure CC=m68k-coff-gcc
18083 @end example
18086 @node AC_LIBOBJ vs LIBOBJS
18087 @subsection @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}
18089 Up to Autoconf 2.13, the replacement of functions was triggered via the
18090 variable @code{LIBOBJS}.  Since Autoconf 2.50, the macro
18091 @code{AC_LIBOBJ} should be used instead (@pxref{Generic Functions}).
18092 Starting at Autoconf 2.53, the use of @code{LIBOBJS} is an error.
18094 This change is mandated by the unification of the @acronym{GNU} Build System
18095 components.  In particular, the various fragile techniques used to parse
18096 a @file{configure.ac} are all replaced with the use of traces.  As a
18097 consequence, any action must be traceable, which obsoletes critical
18098 variable assignments.  Fortunately, @code{LIBOBJS} was the only problem,
18099 and it can even be handled gracefully (read, ``without your having to
18100 change something'').
18102 There were two typical uses of @code{LIBOBJS}: asking for a replacement
18103 function, and adjusting @code{LIBOBJS} for Automake and/or Libtool.
18105 @sp 1
18107 As for function replacement, the fix is immediate: use
18108 @code{AC_LIBOBJ}.  For instance:
18110 @example
18111 LIBOBJS="$LIBOBJS fnmatch.o"
18112 LIBOBJS="$LIBOBJS malloc.$ac_objext"
18113 @end example
18115 @noindent
18116 should be replaced with:
18118 @example
18119 AC_LIBOBJ([fnmatch])
18120 AC_LIBOBJ([malloc])
18121 @end example
18123 @sp 1
18125 @ovindex LIBOBJDIR
18126 When used with Automake 1.10 or newer, a suitable value for
18127 @code{LIBOBJDIR} is set so that the @code{LIBOBJS} and @code{LTLIBOBJS}
18128 can be referenced from any @file{Makefile.am}.  Even without Automake,
18129 arranging for @code{LIBOBJDIR} to be set correctly enables
18130 referencing @code{LIBOBJS} and @code{LTLIBOBJS} in another directory.
18131 The @code{LIBOBJDIR} feature is experimental.
18134 @node AC_FOO_IFELSE vs AC_TRY_FOO
18135 @subsection @code{AC_FOO_IFELSE} vs.@: @code{AC_TRY_FOO}
18137 Since Autoconf 2.50, internal codes uses @code{AC_PREPROC_IFELSE},
18138 @code{AC_COMPILE_IFELSE}, @code{AC_LINK_IFELSE}, and
18139 @code{AC_RUN_IFELSE} on one hand and @code{AC_LANG_SOURCES},
18140 and @code{AC_LANG_PROGRAM} on the other hand instead of the deprecated
18141 @code{AC_TRY_CPP}, @code{AC_TRY_COMPILE}, @code{AC_TRY_LINK}, and
18142 @code{AC_TRY_RUN}.  The motivations where:
18143 @itemize @minus
18144 @item
18145 a more consistent interface: @code{AC_TRY_COMPILE} etc.@: were double
18146 quoting their arguments;
18148 @item
18149 the combinatoric explosion is solved by decomposing on the one hand the
18150 generation of sources, and on the other hand executing the program;
18152 @item
18153 this scheme helps supporting more languages than plain C and C++.
18154 @end itemize
18156 In addition to the change of syntax, the philosophy has changed too:
18157 while emphasis was put on speed at the expense of accuracy, today's
18158 Autoconf promotes accuracy of the testing framework at, ahem@dots{}, the
18159 expense of speed.
18162 As a perfect example of what is @emph{not} to be done, here is how to
18163 find out whether a header file contains a particular declaration, such
18164 as a typedef, a structure, a structure member, or a function.  Use
18165 @code{AC_EGREP_HEADER} instead of running @code{grep} directly on the
18166 header file; on some systems the symbol might be defined in another
18167 header file that the file you are checking includes.
18169 As a (bad) example, here is how you should not check for C preprocessor
18170 symbols, either defined by header files or predefined by the C
18171 preprocessor: using @code{AC_EGREP_CPP}:
18173 @example
18174 @group
18175 AC_EGREP_CPP(yes,
18176 [#ifdef _AIX
18177   yes
18178 #endif
18179 ], is_aix=yes, is_aix=no)
18180 @end group
18181 @end example
18183 The above example, properly written would (i) use
18184 @code{AC_LANG_PROGRAM}, and (ii) run the compiler:
18186 @example
18187 @group
18188 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
18189 [[#ifndef _AIX
18190  error: This isn't AIX!
18191 #endif
18192 ]])],
18193                    [is_aix=yes],
18194                    [is_aix=no])
18195 @end group
18196 @end example
18199 @c ============================= Generating Test Suites with Autotest
18201 @node Using Autotest
18202 @chapter Generating Test Suites with Autotest
18204 @cindex Autotest
18206 @display
18207 @strong{N.B.: This section describes an experimental feature which will
18208 be part of Autoconf in a forthcoming release.  Although we believe
18209 Autotest is stabilizing, this documentation describes an interface which
18210 might change in the future: do not depend upon Autotest without
18211 subscribing to the Autoconf mailing lists.}
18212 @end display
18214 It is paradoxical that portable projects depend on nonportable tools
18215 to run their test suite.  Autoconf by itself is the paragon of this
18216 problem: although it aims at perfectly portability, up to 2.13 its
18217 test suite was using Deja@acronym{GNU}, a rich and complex testing
18218 framework, but which is far from being standard on Posix systems.
18219 Worse yet, it was likely to be missing on the most fragile platforms,
18220 the very platforms that are most likely to torture Autoconf and
18221 exhibit deficiencies.
18223 To circumvent this problem, many package maintainers have developed their
18224 own testing framework, based on simple shell scripts whose sole outputs
18225 are exit status values describing whether the test succeeded.  Most of
18226 these tests share common patterns, and this can result in lots of
18227 duplicated code and tedious maintenance.
18229 Following exactly the same reasoning that yielded to the inception of
18230 Autoconf, Autotest provides a test suite generation framework, based on
18231 M4 macros building a portable shell script.  The suite itself is
18232 equipped with automatic logging and tracing facilities which greatly
18233 diminish the interaction with bug reporters, and simple timing reports.
18235 Autoconf itself has been using Autotest for years, and we do attest that
18236 it has considerably improved the strength of the test suite and the
18237 quality of bug reports.  Other projects are known to use some generation
18238 of Autotest, such as Bison, Free Recode, Free Wdiff, @acronym{GNU} Tar, each of
18239 them with different needs, and this usage has validated Autotest as a general
18240 testing framework.
18242 Nonetheless, compared to Deja@acronym{GNU}, Autotest is inadequate for
18243 interactive tool testing, which is probably its main limitation.
18245 @menu
18246 * Using an Autotest Test Suite::  Autotest and the user
18247 * Writing Testsuites::          Autotest macros
18248 * testsuite Invocation::        Running @command{testsuite} scripts
18249 * Making testsuite Scripts::    Using autom4te to create @command{testsuite}
18250 @end menu
18252 @node Using an Autotest Test Suite
18253 @section Using an Autotest Test Suite
18255 @menu
18256 * testsuite Scripts::           The concepts of Autotest
18257 * Autotest Logs::               Their contents
18258 @end menu
18260 @node testsuite Scripts
18261 @subsection @command{testsuite} Scripts
18263 @cindex @command{testsuite}
18265 Generating testing or validation suites using Autotest is rather easy.
18266 The whole validation suite is held in a file to be processed through
18267 @command{autom4te}, itself using @acronym{GNU} M4 under the scene, to
18268 produce a stand-alone Bourne shell script which then gets distributed.
18269 Neither @command{autom4te} nor @acronym{GNU} M4 are needed at
18270 the installer's end.
18272 @cindex test group
18273 Each test of the validation suite should be part of some test group.  A
18274 @dfn{test group} is a sequence of interwoven tests that ought to be
18275 executed together, usually because one test in the group creates data
18276 files than a later test in the same group needs to read.  Complex test
18277 groups make later debugging more tedious.  It is much better to
18278 keep only a few tests per test group.  Ideally there is only one test
18279 per test group.
18281 For all but the simplest packages, some file such as @file{testsuite.at}
18282 does not fully hold all test sources, as these are often easier to
18283 maintain in separate files.  Each of these separate files holds a single
18284 test group, or a sequence of test groups all addressing some common
18285 functionality in the package.  In such cases, @file{testsuite.at}
18286 merely initializes the validation suite, and sometimes does elementary
18287 health checking, before listing include statements for all other test
18288 files.  The special file @file{package.m4}, containing the
18289 identification of the package, is automatically included if found.
18291 A convenient alternative consists in moving all the global issues
18292 (local Autotest macros, elementary health checking, and @code{AT_INIT}
18293 invocation) into the file @code{local.at}, and making
18294 @file{testsuite.at} be a simple list of @code{m4_include} of sub test
18295 suites.  In such case, generating the whole test suite or pieces of it
18296 is only a matter of choosing the @command{autom4te} command line
18297 arguments.
18299 The validation scripts that Autotest produces are by convention called
18300 @command{testsuite}.  When run, @command{testsuite} executes each test
18301 group in turn, producing only one summary line per test to say if that
18302 particular test succeeded or failed.  At end of all tests, summarizing
18303 counters get printed.  One debugging directory is left for each test
18304 group which failed, if any: such directories are named
18305 @file{testsuite.dir/@var{nn}}, where @var{nn} is the sequence number of
18306 the test group, and they include:
18308 @itemize @bullet
18309 @item a debugging script named @file{run} which reruns the test in
18310 @dfn{debug mode} (@pxref{testsuite Invocation}).  The automatic generation
18311 of debugging scripts has the purpose of easing the chase for bugs.
18313 @item all the files created with @code{AT_DATA}
18315 @item a log of the run, named @file{testsuite.log}
18316 @end itemize
18318 In the ideal situation, none of the tests fail, and consequently no
18319 debugging directory is left behind for validation.
18321 It often happens in practice that individual tests in the validation
18322 suite need to get information coming out of the configuration process.
18323 Some of this information, common for all validation suites, is provided
18324 through the file @file{atconfig}, automatically created by
18325 @code{AC_CONFIG_TESTDIR}.  For configuration informations which your
18326 testing environment specifically needs, you might prepare an optional
18327 file named @file{atlocal.in}, instantiated by @code{AC_CONFIG_FILES}.
18328 The configuration process produces @file{atconfig} and @file{atlocal}
18329 out of these two input files, and these two produced files are
18330 automatically read by the @file{testsuite} script.
18332 Here is a diagram showing the relationship between files.
18334 @noindent
18335 Files used in preparing a software package for distribution:
18337 @example
18338                 [package.m4] -->.
18339                                  \
18340 subfile-1.at ->.  [local.at] ---->+
18341     ...         \                  \
18342 subfile-i.at ---->-- testsuite.at -->-- autom4te* -->testsuite
18343     ...         /
18344 subfile-n.at ->'
18345 @end example
18347 @noindent
18348 Files used in configuring a software package:
18350 @example
18351                                      .--> atconfig
18352                                     /
18353 [atlocal.in] -->  config.status* --<
18354                                     \
18355                                      `--> [atlocal]
18356 @end example
18358 @noindent
18359 Files created during the test suite execution:
18361 @example
18362 atconfig -->.                    .--> testsuite.log
18363              \                  /
18364               >-- testsuite* --<
18365              /                  \
18366 [atlocal] ->'                    `--> [testsuite.dir]
18367 @end example
18370 @node Autotest Logs
18371 @subsection Autotest Logs
18373 When run, the test suite creates a log file named after itself, e.g., a
18374 test suite named @command{testsuite} creates @file{testsuite.log}.  It
18375 contains a lot of information, usually more than maintainers actually
18376 need, but therefore most of the time it contains all that is needed:
18378 @table @asis
18379 @item command line arguments
18380 @c akim s/to consist in/to consist of/
18381 A bad but unfortunately widespread habit consists of
18382 setting environment variables before the command, such as in
18383 @samp{CC=my-home-grown-cc ./testsuite}.  The test suite does not
18384 know this change, hence (i) it cannot report it to you, and (ii)
18385 it cannot preserve the value of @code{CC} for subsequent runs.
18386 Autoconf faced exactly the same problem, and solved it by asking
18387 users to pass the variable definitions as command line arguments.
18388 Autotest requires this rule, too, but has no means to enforce it; the log
18389 then contains a trace of the variables that were changed by the user.
18391 @item @file{ChangeLog} excerpts
18392 The topmost lines of all the @file{ChangeLog} files found in the source
18393 hierarchy.  This is especially useful when bugs are reported against
18394 development versions of the package, since the version string does not
18395 provide sufficient information to know the exact state of the sources
18396 the user compiled.  Of course, this relies on the use of a
18397 @file{ChangeLog}.
18399 @item build machine
18400 Running a test suite in a cross-compile environment is not an easy task,
18401 since it would mean having the test suite run on a machine @var{build},
18402 while running programs on a machine @var{host}.  It is much simpler to
18403 run both the test suite and the programs on @var{host}, but then, from
18404 the point of view of the test suite, there remains a single environment,
18405 @var{host} = @var{build}.  The log contains relevant information on the
18406 state of the build machine, including some important environment
18407 variables.
18408 @c FIXME: How about having an M4sh macro to say `hey, log the value
18409 @c of `@dots{}'?  This would help both Autoconf and Autotest.
18411 @item tested programs
18412 The absolute file name and answers to @option{--version} of the tested
18413 programs (see @ref{Writing Testsuites}, @code{AT_TESTED}).
18415 @item configuration log
18416 The contents of @file{config.log}, as created by @command{configure},
18417 are appended.  It contains the configuration flags and a detailed report
18418 on the configuration itself.
18419 @end table
18422 @node Writing Testsuites
18423 @section Writing @file{testsuite.at}
18425 The @file{testsuite.at} is a Bourne shell script making use of special
18426 Autotest M4 macros.  It often contains a call to @code{AT_INIT} near
18427 its beginning followed by one call to @code{m4_include} per source file
18428 for tests.  Each such included file, or the remainder of
18429 @file{testsuite.at} if include files are not used, contain a sequence of
18430 test groups.  Each test group begins with a call to @code{AT_SETUP},
18431 then an arbitrary number of shell commands or calls to @code{AT_CHECK},
18432 and then completes with a call to @code{AT_CLEANUP}.
18434 @defmac AT_INIT (@ovar{name})
18435 @atindex{INIT}
18436 @c FIXME: Not clear, plus duplication of the information.
18437 Initialize Autotest.  Giving a @var{name} to the test suite is
18438 encouraged if your package includes several test suites.  In any case,
18439 the test suite always displays the package name and version.  It also
18440 inherits the package bug report address.
18441 @end defmac
18443 @defmac AT_COPYRIGHT (@var{copyright-notice})
18444 @atindex{COPYRIGHT}
18445 @cindex Copyright Notice
18446 State that, in addition to the Free Software Foundation's copyright on
18447 the Autotest macros, parts of your test suite are covered by
18448 @var{copyright-notice}.
18450 The @var{copyright-notice} shows up in both the head of
18451 @command{testsuite} and in @samp{testsuite --version}.
18452 @end defmac
18454 @defmac AT_TESTED (@var{executables})
18455 @atindex{TESTED}
18456 Log the file name and answer to @option{--version} of each program in
18457 space-separated list @var{executables}.  Several invocations register
18458 new executables, in other words, don't fear registering one program
18459 several times.
18460 @end defmac
18462 Autotest test suites rely on @env{PATH} to find the tested program.
18463 This avoids the need to generate absolute names of the various tools, and
18464 makes it possible to test installed programs.  Therefore, knowing which
18465 programs are being exercised is crucial to understanding problems in
18466 the test suite itself, or its occasional misuses.  It is a good idea to
18467 also subscribe foreign programs you depend upon, to avoid incompatible
18468 diagnostics.
18470 @sp 1
18472 @defmac AT_SETUP (@var{test-group-name})
18473 @atindex{SETUP}
18474 This macro starts a group of related tests, all to be executed in the
18475 same subshell.  It accepts a single argument, which holds a few words
18476 (no more than about 30 or 40 characters) quickly describing the purpose
18477 of the test group being started.
18478 @end defmac
18480 @defmac AT_KEYWORDS (@var{keywords})
18481 @atindex{KEYWORDS}
18482 Associate the space-separated list of @var{keywords} to the enclosing
18483 test group.  This makes it possible to run ``slices'' of the test suite.
18484 For instance, if some of your test groups exercise some @samp{foo}
18485 feature, then using @samp{AT_KEYWORDS(foo)} lets you run
18486 @samp{./testsuite -k foo} to run exclusively these test groups.  The
18487 @var{title} of the test group is automatically recorded to
18488 @code{AT_KEYWORDS}.
18490 Several invocations within a test group accumulate new keywords.  In
18491 other words, don't fear registering the same keyword several times in a
18492 test group.
18493 @end defmac
18495 @defmac AT_CAPTURE_FILE (@var{file})
18496 @atindex{CAPTURE_FILE}
18497 If the current test group fails, log the contents of @var{file}.
18498 Several identical calls within one test group have no additional effect.
18499 @end defmac
18501 @defmac AT_XFAIL_IF (@var{shell-condition})
18502 @atindex{XFAIL_IF}
18503 Determine whether the test is expected to fail because it is a known
18504 bug (for unsupported features, you should skip the test).
18505 @var{shell-condition} is a shell expression such as a @code{test}
18506 command; you can instantiate this macro many times from within the
18507 same test group, and one of the conditions is enough to turn
18508 the test into an expected failure.
18509 @end defmac
18511 @defmac AT_CLEANUP
18512 @atindex{CLEANUP}
18513 End the current test group.
18514 @end defmac
18516 @sp 1
18518 @defmac AT_DATA (@var{file}, @var{contents})
18519 @atindex{DATA}
18520 Initialize an input data @var{file} with given @var{contents}.  Of
18521 course, the @var{contents} have to be properly quoted between square
18522 brackets to protect against included commas or spurious M4
18523 expansion.  The contents ought to end with an end of line.
18524 @end defmac
18526 @defmac AT_CHECK (@var{commands}, @dvar{status, 0}, @dvar{stdout, }, @dvar{stderr, }, @ovar{run-if-fail}, @ovar{run-if-pass})
18527 @atindex{CHECK}
18528 Execute a test by performing given shell @var{commands}.  These commands
18529 should normally exit with @var{status}, while producing expected
18530 @var{stdout} and @var{stderr} contents.  If @var{commands} exit with
18531 status 77, then the whole test group is skipped.  Otherwise, if this test
18532 fails, run shell commands @var{run-if-fail} or, if this test passes, run shell
18533 commands @var{run-if-pass}.
18535 The @var{commands} @emph{must not} redirect the standard output, nor the
18536 standard error.
18538 If @var{status}, or @var{stdout}, or @var{stderr} is @samp{ignore}, then
18539 the corresponding value is not checked.
18541 The special value @samp{expout} for @var{stdout} means the expected
18542 output of the @var{commands} is the content of the file @file{expout}.
18543 If @var{stdout} is @samp{stdout}, then the standard output of the
18544 @var{commands} is available for further tests in the file @file{stdout}.
18545 Similarly for @var{stderr} with @samp{experr} and @samp{stderr}.
18546 @end defmac
18549 @node testsuite Invocation
18550 @section Running @command{testsuite} Scripts
18551 @cindex @command{testsuite}
18553 Autotest test suites support the following arguments:
18555 @table @option
18556 @item --help
18557 @itemx -h
18558 Display the list of options and exit successfully.
18560 @item --version
18561 @itemx -V
18562 Display the version of the test suite and exit successfully.
18564 @item --clean
18565 @itemx -c
18566 Remove all the files the test suite might have created and exit.  Meant
18567 for @code{clean} Make targets.
18569 @item --list
18570 @itemx -l
18571 List all the tests (or only the selection), including their possible
18572 keywords.
18573 @end table
18575 @sp 1
18577 By default all tests are performed (or described with
18578 @option{--list}) in the default environment first silently, then
18579 verbosely, but the environment, set of tests, and verbosity level can be
18580 tuned:
18582 @table @samp
18583 @item @var{variable}=@var{value}
18584 Set the environment @var{variable} to @var{value}.  Use this rather
18585 than @samp{FOO=foo ./testsuite} as debugging scripts would then run in a
18586 different environment.
18588 @cindex @code{AUTOTEST_PATH}
18589 The variable @code{AUTOTEST_PATH} specifies the testing path to prepend
18590 to @env{PATH}.  Relative directory names (not starting with
18591 @samp{/}) are considered to be relative to the top level of the
18592 package being built.  All directories are made absolute, first
18593 starting from the top level @emph{build} tree, then from the
18594 @emph{source} tree.  For instance @samp{./testsuite
18595 AUTOTEST_PATH=tests:bin} for a @file{/src/foo-1.0} source package built
18596 in @file{/tmp/foo} results in @samp{/tmp/foo/tests:/tmp/foo/bin} and
18597 then @samp{/src/foo-1.0/tests:/src/foo-1.0/bin} being prepended to
18598 @env{PATH}.
18600 @item @var{number}
18601 @itemx @var{number}-@var{number}
18602 @itemx @var{number}-
18603 @itemx -@var{number}
18604 Add the corresponding test groups, with obvious semantics, to the
18605 selection.
18607 @item --keywords=@var{keywords}
18608 @itemx -k @var{keywords}
18609 Add to the selection the test groups with title or keywords (arguments
18610 to @code{AT_SETUP} or @code{AT_KEYWORDS}) that match @emph{all} keywords
18611 of the comma separated list @var{keywords}, case-insensitively.  Use
18612 @samp{!} immediately before the keyword to invert the selection for this
18613 keyword.  By default, the keywords match whole words; enclose them in
18614 @samp{.*} to also match parts of words.
18616 For example, running
18618 @example
18619 @kbd{./testsuite -k 'autoupdate,.*FUNC.*'}
18620 @end example
18622 @noindent
18623 selects all tests tagged @samp{autoupdate} @emph{and} with tags
18624 containing @samp{FUNC} (as in @samp{AC_CHECK_FUNC}, @samp{AC_FUNC_ALLOCA},
18625 etc.), while
18627 @example
18628 @kbd{./testsuite -k '!autoupdate' -k '.*FUNC.*'}
18629 @end example
18631 @noindent
18632 selects all tests not tagged @samp{autoupdate} @emph{or} with tags
18633 containing @samp{FUNC}.
18635 @item --errexit
18636 @itemx -e
18637 If any test fails, immediately abort testing.  It implies
18638 @option{--debug}: post test group clean up, and top-level logging
18639 are inhibited.  This option is meant for the full test
18640 suite, it is not really useful for generated debugging scripts.
18642 @item --verbose
18643 @itemx -v
18644 Force more verbosity in the detailed output of what is being done.  This
18645 is the default for debugging scripts.
18647 @item --debug
18648 @itemx -d
18649 Do not remove the files after a test group was performed ---but they are
18650 still removed @emph{before}, therefore using this option is sane when
18651 running several test groups.  Create debugging scripts.  Do not
18652 overwrite the top-level
18653 log (in order to preserve supposedly existing full log file).  This is
18654 the default for debugging scripts, but it can also be useful to debug
18655 the testsuite itself.
18657 @item --trace
18658 @itemx -x
18659 Trigger shell tracing of the test groups.
18660 @end table
18663 @node Making testsuite Scripts
18664 @section Making @command{testsuite} Scripts
18666 For putting Autotest into movement, you need some configuration and
18667 makefile machinery.  We recommend, at least if your package uses deep or
18668 shallow hierarchies, that you use @file{tests/} as the name of the
18669 directory holding all your tests and their makefile.  Here is a
18670 check list of things to do.
18672 @itemize @minus
18674 @item
18675 @cindex @file{package.m4}
18676 Make sure to create the file @file{package.m4}, which defines the
18677 identity of the package.  It must define @code{AT_PACKAGE_STRING}, the
18678 full signature of the package, and @code{AT_PACKAGE_BUGREPORT}, the
18679 address to which bug reports should be sent.  For sake of completeness,
18680 we suggest that you also define @code{AT_PACKAGE_NAME},
18681 @code{AT_PACKAGE_TARNAME}, and @code{AT_PACKAGE_VERSION}.
18682 @xref{Initializing configure}, for a description of these variables.  We
18683 suggest the following makefile excerpt:
18685 @smallexample
18686 $(srcdir)/package.m4: $(top_srcdir)/configure.ac
18687         @{                                      \
18688           echo '# Signature of the current package.'; \
18689           echo 'm4_define([AT_PACKAGE_NAME],      [@@PACKAGE_NAME@@])'; \
18690           echo 'm4_define([AT_PACKAGE_TARNAME],   [@@PACKAGE_TARNAME@@])'; \
18691           echo 'm4_define([AT_PACKAGE_VERSION],   [@@PACKAGE_VERSION@@])'; \
18692           echo 'm4_define([AT_PACKAGE_STRING],    [@@PACKAGE_STRING@@])'; \
18693           echo 'm4_define([AT_PACKAGE_BUGREPORT], [@@PACKAGE_BUGREPORT@@])'; \
18694         @} >'$(srcdir)/package.m4'
18695 @end smallexample
18697 @noindent
18698 Be sure to distribute @file{package.m4} and to put it into the source
18699 hierarchy: the test suite ought to be shipped!
18701 @item
18702 Invoke @code{AC_CONFIG_TESTDIR}.
18704 @defmac AC_CONFIG_TESTDIR (@var{directory}, @dvar{test-path, directory})
18705 @acindex{CONFIG_TESTDIR}
18706 An Autotest test suite is to be configured in @var{directory}.  This
18707 macro requires the instantiation of @file{@var{directory}/atconfig} from
18708 @file{@var{directory}/atconfig.in}, and sets the default
18709 @code{AUTOTEST_PATH} to @var{test-path} (@pxref{testsuite Invocation}).
18710 @end defmac
18712 @item
18713 Still within @file{configure.ac}, as appropriate, ensure that some
18714 @code{AC_CONFIG_FILES} command includes substitution for
18715 @file{tests/atlocal}.
18717 @item
18718 The @file{tests/Makefile.in} should be modified so the validation in
18719 your package is triggered by @samp{make check}.  An example is provided
18720 below.
18721 @end itemize
18723 With Automake, here is a minimal example about how to link @samp{make
18724 check} with a validation suite.
18726 @example
18727 EXTRA_DIST = testsuite.at $(TESTSUITE) atlocal.in
18728 TESTSUITE = $(srcdir)/testsuite
18730 check-local: atconfig atlocal $(TESTSUITE)
18731         $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
18733 installcheck-local: atconfig atlocal $(TESTSUITE)
18734         $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \
18735           $(TESTSUITEFLAGS)
18737 clean-local:
18738         test ! -f '$(TESTSUITE)' || \
18739          $(SHELL) '$(TESTSUITE)' --clean
18741 AUTOTEST = $(AUTOM4TE) --language=autotest
18742 $(TESTSUITE): $(srcdir)/testsuite.at
18743         $(AUTOTEST) -I '$(srcdir)' -o $@@.tmp $@@.at
18744         mv $@@.tmp $@@
18745 @end example
18747 You might want to list explicitly the dependencies, i.e., the list of
18748 the files @file{testsuite.at} includes.
18750 With strict Autoconf, you might need to add lines inspired from the
18751 following:
18753 @example
18754 subdir = tests
18756 atconfig: $(top_builddir)/config.status
18757         cd $(top_builddir) && \
18758            $(SHELL) ./config.status $(subdir)/$@@
18760 atlocal: $(srcdir)/atlocal.in $(top_builddir)/config.status
18761         cd $(top_builddir) && \
18762            $(SHELL) ./config.status $(subdir)/$@@
18763 @end example
18765 @noindent
18766 and manage to have @file{atconfig.in} and @code{$(EXTRA_DIST)}
18767 distributed.
18769 With all this in place, and if you have not initialized @samp{TESTSUITEFLAGS}
18770 within your makefile, you can fine-tune test suite execution with this variable,
18771 for example:
18773 @example
18774 make check TESTSUITEFLAGS='-v -d -x 75 -k AC_PROG_CC CFLAGS=-g'
18775 @end example
18779 @c =============================== Frequent Autoconf Questions, with answers
18781 @node FAQ
18782 @chapter Frequent Autoconf Questions, with answers
18784 Several questions about Autoconf come up occasionally.  Here some of them
18785 are addressed.
18787 @menu
18788 * Distributing::                Distributing @command{configure} scripts
18789 * Why GNU M4::                  Why not use the standard M4?
18790 * Bootstrapping::               Autoconf and @acronym{GNU} M4 require each other?
18791 * Why Not Imake::               Why @acronym{GNU} uses @command{configure} instead of Imake
18792 * Defining Directories::        Passing @code{datadir} to program
18793 * Autom4te Cache::              What is it?  Can I remove it?
18794 * Present But Cannot Be Compiled::  Compiler and Preprocessor Disagree
18795 @end menu
18797 @node Distributing
18798 @section Distributing @command{configure} Scripts
18799 @cindex License
18801 @display
18802 What are the restrictions on distributing @command{configure}
18803 scripts that Autoconf generates?  How does that affect my
18804 programs that use them?
18805 @end display
18807 There are no restrictions on how the configuration scripts that Autoconf
18808 produces may be distributed or used.  In Autoconf version 1, they were
18809 covered by the @acronym{GNU} General Public License.  We still encourage
18810 software authors to distribute their work under terms like those of the
18811 @acronym{GPL}, but doing so is not required to use Autoconf.
18813 Of the other files that might be used with @command{configure},
18814 @file{config.h.in} is under whatever copyright you use for your
18815 @file{configure.ac}.  @file{config.sub} and @file{config.guess} have an
18816 exception to the @acronym{GPL} when they are used with an Autoconf-generated
18817 @command{configure} script, which permits you to distribute them under the
18818 same terms as the rest of your package.  @file{install-sh} is from the X
18819 Consortium and is not copyrighted.
18821 @node Why GNU M4
18822 @section Why Require @acronym{GNU} M4?
18824 @display
18825 Why does Autoconf require @acronym{GNU} M4?
18826 @end display
18828 Many M4 implementations have hard-coded limitations on the size and
18829 number of macros that Autoconf exceeds.  They also lack several
18830 builtin macros that it would be difficult to get along without in a
18831 sophisticated application like Autoconf, including:
18833 @example
18834 m4_builtin
18835 m4_indir
18836 m4_bpatsubst
18837 __file__
18838 __line__
18839 @end example
18841 Autoconf requires version 1.4.7 or later of @acronym{GNU} M4.
18843 Since only software maintainers need to use Autoconf, and since @acronym{GNU}
18844 M4 is simple to configure and install, it seems reasonable to require
18845 @acronym{GNU} M4 to be installed also.  Many maintainers of @acronym{GNU} and
18846 other free software already have most of the @acronym{GNU} utilities
18847 installed, since they prefer them.
18849 @node Bootstrapping
18850 @section How Can I Bootstrap?
18851 @cindex Bootstrap
18853 @display
18854 If Autoconf requires @acronym{GNU} M4 and @acronym{GNU} M4 has an Autoconf
18855 @command{configure} script, how do I bootstrap?  It seems like a chicken
18856 and egg problem!
18857 @end display
18859 This is a misunderstanding.  Although @acronym{GNU} M4 does come with a
18860 @command{configure} script produced by Autoconf, Autoconf is not required
18861 in order to run the script and install @acronym{GNU} M4.  Autoconf is only
18862 required if you want to change the M4 @command{configure} script, which few
18863 people have to do (mainly its maintainer).
18865 @node Why Not Imake
18866 @section Why Not Imake?
18867 @cindex Imake
18869 @display
18870 Why not use Imake instead of @command{configure} scripts?
18871 @end display
18873 Several people have written addressing this question, so I include
18874 adaptations of their explanations here.
18876 The following answer is based on one written by Richard Pixley:
18878 @quotation
18879 Autoconf generated scripts frequently work on machines that it has
18880 never been set up to handle before.  That is, it does a good job of
18881 inferring a configuration for a new system.  Imake cannot do this.
18883 Imake uses a common database of host specific data.  For X11, this makes
18884 sense because the distribution is made as a collection of tools, by one
18885 central authority who has control over the database.
18887 @acronym{GNU} tools are not released this way.  Each @acronym{GNU} tool has a
18888 maintainer; these maintainers are scattered across the world.  Using a
18889 common database would be a maintenance nightmare.  Autoconf may appear
18890 to be this kind of database, but in fact it is not.  Instead of listing
18891 host dependencies, it lists program requirements.
18893 If you view the @acronym{GNU} suite as a collection of native tools, then the
18894 problems are similar.  But the @acronym{GNU} development tools can be
18895 configured as cross tools in almost any host+target permutation.  All of
18896 these configurations can be installed concurrently.  They can even be
18897 configured to share host independent files across hosts.  Imake doesn't
18898 address these issues.
18900 Imake templates are a form of standardization.  The @acronym{GNU} coding
18901 standards address the same issues without necessarily imposing the same
18902 restrictions.
18903 @end quotation
18906 Here is some further explanation, written by Per Bothner:
18908 @quotation
18909 One of the advantages of Imake is that it easy to generate large
18910 makefiles using the @samp{#include} and macro mechanisms of @command{cpp}.
18911 However, @code{cpp} is not programmable: it has limited conditional
18912 facilities, and no looping.  And @code{cpp} cannot inspect its
18913 environment.
18915 All of these problems are solved by using @code{sh} instead of
18916 @code{cpp}.  The shell is fully programmable, has macro substitution,
18917 can execute (or source) other shell scripts, and can inspect its
18918 environment.
18919 @end quotation
18922 Paul Eggert elaborates more:
18924 @quotation
18925 With Autoconf, installers need not assume that Imake itself is already
18926 installed and working well.  This may not seem like much of an advantage
18927 to people who are accustomed to Imake.  But on many hosts Imake is not
18928 installed or the default installation is not working well, and requiring
18929 Imake to install a package hinders the acceptance of that package on
18930 those hosts.  For example, the Imake template and configuration files
18931 might not be installed properly on a host, or the Imake build procedure
18932 might wrongly assume that all source files are in one big directory
18933 tree, or the Imake configuration might assume one compiler whereas the
18934 package or the installer needs to use another, or there might be a
18935 version mismatch between the Imake expected by the package and the Imake
18936 supported by the host.  These problems are much rarer with Autoconf,
18937 where each package comes with its own independent configuration
18938 processor.
18940 Also, Imake often suffers from unexpected interactions between
18941 @command{make} and the installer's C preprocessor.  The fundamental problem
18942 here is that the C preprocessor was designed to preprocess C programs,
18943 not makefiles.  This is much less of a problem with Autoconf,
18944 which uses the general-purpose preprocessor M4, and where the
18945 package's author (rather than the installer) does the preprocessing in a
18946 standard way.
18947 @end quotation
18950 Finally, Mark Eichin notes:
18952 @quotation
18953 Imake isn't all that extensible, either.  In order to add new features to
18954 Imake, you need to provide your own project template, and duplicate most
18955 of the features of the existing one.  This means that for a sophisticated
18956 project, using the vendor-provided Imake templates fails to provide any
18957 leverage---since they don't cover anything that your own project needs
18958 (unless it is an X11 program).
18960 On the other side, though:
18962 The one advantage that Imake has over @command{configure}:
18963 @file{Imakefile} files tend to be much shorter (likewise, less redundant)
18964 than @file{Makefile.in} files.  There is a fix to this, however---at least
18965 for the Kerberos V5 tree, we've modified things to call in common
18966 @file{post.in} and @file{pre.in} makefile fragments for the
18967 entire tree.  This means that a lot of common things don't have to be
18968 duplicated, even though they normally are in @command{configure} setups.
18969 @end quotation
18972 @node Defining Directories
18973 @section How Do I @code{#define} Installation Directories?
18975 @display
18976 My program needs library files, installed in @code{datadir} and
18977 similar.  If I use
18979 @example
18980 AC_DEFINE_UNQUOTED([DATADIR], [$datadir],
18981   [Define to the read-only architecture-independent
18982    data directory.])
18983 @end example
18985 @noindent
18986 I get
18988 @example
18989 #define DATADIR "$@{prefix@}/share"
18990 @end example
18991 @end display
18993 As already explained, this behavior is on purpose, mandated by the
18994 @acronym{GNU} Coding Standards, see @ref{Installation Directory
18995 Variables}.  There are several means to achieve a similar goal:
18997 @itemize @minus
18998 @item
18999 Do not use @code{AC_DEFINE} but use your makefile to pass the
19000 actual value of @code{datadir} via compilation flags.
19001 @xref{Installation Directory Variables}, for the details.
19003 @item
19004 This solution can be simplified when compiling a program: you may either
19005 extend the @code{CPPFLAGS}:
19007 @example
19008 CPPFLAGS = -DDATADIR='"$(datadir)"' @@CPPFLAGS@@
19009 @end example
19011 @noindent
19012 or create a dedicated header file:
19014 @example
19015 DISTCLEANFILES = datadir.h
19016 datadir.h: Makefile
19017         echo '#define DATADIR "$(datadir)"' >$@@
19018 @end example
19020 @item
19021 Use @code{AC_DEFINE} but have @command{configure} compute the literal
19022 value of @code{datadir} and others.  Many people have wrapped macros to
19023 automate this task.  For instance, the macro @code{AC_DEFINE_DIR} from
19024 the @uref{http://autoconf-archive.cryp.to/, Autoconf Macro
19025 Archive}.
19027 This solution does not conform to the @acronym{GNU} Coding Standards.
19029 @item
19030 Note that all the previous solutions hard wire the absolute name of
19031 these directories in the executables, which is not a good property.  You
19032 may try to compute the names relative to @code{prefix}, and try to
19033 find @code{prefix} at runtime, this way your package is relocatable.
19034 Some macros are already available to address this issue: see
19035 @code{adl_COMPUTE_RELATIVE_PATHS} and
19036 @code{adl_COMPUTE_STANDARD_RELATIVE_PATHS} on the
19037 @uref{http://autoconf-archive.cryp.to/,
19038 Autoconf Macro Archive}.
19039 @end itemize
19042 @node Autom4te Cache
19043 @section What is @file{autom4te.cache}?
19045 @display
19046 What is this directory @file{autom4te.cache}?  Can I safely remove it?
19047 @end display
19049 In the @acronym{GNU} Build System, @file{configure.ac} plays a central
19050 role and is read by many tools: @command{autoconf} to create
19051 @file{configure}, @command{autoheader} to create @file{config.h.in},
19052 @command{automake} to create @file{Makefile.in}, @command{autoscan} to
19053 check the completeness of @file{configure.ac}, @command{autoreconf} to
19054 check the @acronym{GNU} Build System components that are used.  To
19055 ``read @file{configure.ac}'' actually means to compile it with M4,
19056 which can be a long process for complex @file{configure.ac}.
19058 This is why all these tools, instead of running directly M4, invoke
19059 @command{autom4te} (@pxref{autom4te Invocation}) which, while answering to
19060 a specific demand, stores additional information in
19061 @file{autom4te.cache} for future runs.  For instance, if you run
19062 @command{autoconf}, behind the scenes, @command{autom4te} also
19063 stores information for the other tools, so that when you invoke
19064 @command{autoheader} or @command{automake} etc., reprocessing
19065 @file{configure.ac} is not needed.  The speed up is frequently of 30%,
19066 and is increasing with the size of @file{configure.ac}.
19068 But it is and remains being simply a cache: you can safely remove it.
19070 @sp 1
19072 @display
19073 Can I permanently get rid of it?
19074 @end display
19076 The creation of this cache can be disabled from
19077 @file{~/.autom4te.cfg}, see @ref{Customizing autom4te}, for more
19078 details.  You should be aware that disabling the cache slows down the
19079 Autoconf test suite by 40%.  The more @acronym{GNU} Build System
19080 components are used, the more the cache is useful; for instance
19081 running @samp{autoreconf -f} on the Core Utilities is twice slower without
19082 the cache @emph{although @option{--force} implies that the cache is
19083 not fully exploited}, and eight times slower than without
19084 @option{--force}.
19087 @node Present But Cannot Be Compiled
19088 @section Header Present But Cannot Be Compiled
19090 The most important guideline to bear in mind when checking for
19091 features is to mimic as much as possible the intended use.
19092 Unfortunately, old versions of @code{AC_CHECK_HEADER} and
19093 @code{AC_CHECK_HEADERS} failed to follow this idea, and called
19094 the preprocessor, instead of the compiler, to check for headers.  As a
19095 result, incompatibilities between headers went unnoticed during
19096 configuration, and maintainers finally had to deal with this issue
19097 elsewhere.
19099 As of Autoconf 2.56 both checks are performed, and @code{configure}
19100 complains loudly if the compiler and the preprocessor do not agree.
19101 For the time being the result used is that of the preprocessor, to give
19102 maintainers time to adjust their @file{configure.ac}, but in the
19103 future, only the compiler will be considered.
19105 Consider the following example:
19107 @smallexample
19108 $ @kbd{cat number.h}
19109 typedef int number;
19110 $ @kbd{cat pi.h}
19111 const number pi = 3;
19112 $ @kbd{cat configure.ac}
19113 AC_INIT([Example], [1.0], [bug-example@@example.org])
19114 AC_CHECK_HEADERS([pi.h])
19115 $ @kbd{autoconf -Wall}
19116 $ @kbd{./configure}
19117 checking for gcc... gcc
19118 checking for C compiler default output file name... a.out
19119 checking whether the C compiler works... yes
19120 checking whether we are cross compiling... no
19121 checking for suffix of executables...
19122 checking for suffix of object files... o
19123 checking whether we are using the GNU C compiler... yes
19124 checking whether gcc accepts -g... yes
19125 checking for gcc option to accept ISO C89... none needed
19126 checking how to run the C preprocessor... gcc -E
19127 checking for grep that handles long lines and -e... grep
19128 checking for egrep... grep -E
19129 checking for ANSI C header files... yes
19130 checking for sys/types.h... yes
19131 checking for sys/stat.h... yes
19132 checking for stdlib.h... yes
19133 checking for string.h... yes
19134 checking for memory.h... yes
19135 checking for strings.h... yes
19136 checking for inttypes.h... yes
19137 checking for stdint.h... yes
19138 checking for unistd.h... yes
19139 checking pi.h usability... no
19140 checking pi.h presence... yes
19141 configure: WARNING: pi.h: present but cannot be compiled
19142 configure: WARNING: pi.h:     check for missing prerequisite headers?
19143 configure: WARNING: pi.h: see the Autoconf documentation
19144 configure: WARNING: pi.h:     section "Present But Cannot Be Compiled"
19145 configure: WARNING: pi.h: proceeding with the preprocessor's result
19146 configure: WARNING: pi.h: in the future, the compiler will take precedence
19147 configure: WARNING:     ## -------------------------------------- ##
19148 configure: WARNING:     ## Report this to bug-example@@example.org ##
19149 configure: WARNING:     ## -------------------------------------- ##
19150 checking for pi.h... yes
19151 @end smallexample
19153 @noindent
19154 The proper way the handle this case is using the fourth argument
19155 (@pxref{Generic Headers}):
19157 @example
19158 $ @kbd{cat configure.ac}
19159 AC_INIT([Example], [1.0], [bug-example@@example.org])
19160 AC_CHECK_HEADERS([number.h pi.h], [], [],
19161 [[#ifdef HAVE_NUMBER_H
19162 # include <number.h>
19163 #endif
19165 $ @kbd{autoconf -Wall}
19166 $ @kbd{./configure}
19167 checking for gcc... gcc
19168 checking for C compiler default output... a.out
19169 checking whether the C compiler works... yes
19170 checking whether we are cross compiling... no
19171 checking for suffix of executables...
19172 checking for suffix of object files... o
19173 checking whether we are using the GNU C compiler... yes
19174 checking whether gcc accepts -g... yes
19175 checking for gcc option to accept ANSI C... none needed
19176 checking for number.h... yes
19177 checking for pi.h... yes
19178 @end example
19180 See @ref{Particular Headers}, for a list of headers with their
19181 prerequisite.
19183 @c ===================================================== History of Autoconf.
19185 @node History
19186 @chapter History of Autoconf
19187 @cindex History of autoconf
19189 You may be wondering, Why was Autoconf originally written?  How did it
19190 get into its present form?  (Why does it look like gorilla spit?)  If
19191 you're not wondering, then this chapter contains no information useful
19192 to you, and you might as well skip it.  If you @emph{are} wondering,
19193 then let there be light@enddots{}
19195 @menu
19196 * Genesis::                     Prehistory and naming of @command{configure}
19197 * Exodus::                      The plagues of M4 and Perl
19198 * Leviticus::                   The priestly code of portability arrives
19199 * Numbers::                     Growth and contributors
19200 * Deuteronomy::                 Approaching the promises of easy configuration
19201 @end menu
19203 @node Genesis
19204 @section Genesis
19206 In June 1991 I was maintaining many of the @acronym{GNU} utilities for the
19207 Free Software Foundation.  As they were ported to more platforms and
19208 more programs were added, the number of @option{-D} options that users
19209 had to select in the makefile (around 20) became burdensome.
19210 Especially for me---I had to test each new release on a bunch of
19211 different systems.  So I wrote a little shell script to guess some of
19212 the correct settings for the fileutils package, and released it as part
19213 of fileutils 2.0.  That @command{configure} script worked well enough that
19214 the next month I adapted it (by hand) to create similar @command{configure}
19215 scripts for several other @acronym{GNU} utilities packages.  Brian Berliner
19216 also adapted one of my scripts for his @acronym{CVS} revision control system.
19218 Later that summer, I learned that Richard Stallman and Richard Pixley
19219 were developing similar scripts to use in the @acronym{GNU} compiler tools;
19220 so I adapted my @command{configure} scripts to support their evolving
19221 interface: using the file name @file{Makefile.in} as the templates;
19222 adding @samp{+srcdir}, the first option (of many); and creating
19223 @file{config.status} files.
19225 @node Exodus
19226 @section Exodus
19228 As I got feedback from users, I incorporated many improvements, using
19229 Emacs to search and replace, cut and paste, similar changes in each of
19230 the scripts.  As I adapted more @acronym{GNU} utilities packages to use
19231 @command{configure} scripts, updating them all by hand became impractical.
19232 Rich Murphey, the maintainer of the @acronym{GNU} graphics utilities, sent me
19233 mail saying that the @command{configure} scripts were great, and asking if
19234 I had a tool for generating them that I could send him.  No, I thought,
19235 but I should!  So I started to work out how to generate them.  And the
19236 journey from the slavery of hand-written @command{configure} scripts to the
19237 abundance and ease of Autoconf began.
19239 Cygnus @command{configure}, which was being developed at around that time,
19240 is table driven; it is meant to deal mainly with a discrete number of
19241 system types with a small number of mainly unguessable features (such as
19242 details of the object file format).  The automatic configuration system
19243 that Brian Fox had developed for Bash takes a similar approach.  For
19244 general use, it seems to me a hopeless cause to try to maintain an
19245 up-to-date database of which features each variant of each operating
19246 system has.  It's easier and more reliable to check for most features on
19247 the fly---especially on hybrid systems that people have hacked on
19248 locally or that have patches from vendors installed.
19250 I considered using an architecture similar to that of Cygnus
19251 @command{configure}, where there is a single @command{configure} script that
19252 reads pieces of @file{configure.in} when run.  But I didn't want to have
19253 to distribute all of the feature tests with every package, so I settled
19254 on having a different @command{configure} made from each
19255 @file{configure.in} by a preprocessor.  That approach also offered more
19256 control and flexibility.
19258 I looked briefly into using the Metaconfig package, by Larry Wall,
19259 Harlan Stenn, and Raphael Manfredi, but I decided not to for several
19260 reasons.  The @command{Configure} scripts it produces are interactive,
19261 which I find quite inconvenient; I didn't like the ways it checked for
19262 some features (such as library functions); I didn't know that it was
19263 still being maintained, and the @command{Configure} scripts I had
19264 seen didn't work on many modern systems (such as System V R4 and NeXT);
19265 it wasn't flexible in what it could do in response to a feature's
19266 presence or absence; I found it confusing to learn; and it was too big
19267 and complex for my needs (I didn't realize then how much Autoconf would
19268 eventually have to grow).
19270 I considered using Perl to generate my style of @command{configure}
19271 scripts, but decided that M4 was better suited to the job of simple
19272 textual substitutions: it gets in the way less, because output is
19273 implicit.  Plus, everyone already has it.  (Initially I didn't rely on
19274 the @acronym{GNU} extensions to M4.)  Also, some of my friends at the
19275 University of Maryland had recently been putting M4 front ends on
19276 several programs, including @code{tvtwm}, and I was interested in trying
19277 out a new language.
19279 @node Leviticus
19280 @section Leviticus
19282 Since my @command{configure} scripts determine the system's capabilities
19283 automatically, with no interactive user intervention, I decided to call
19284 the program that generates them Autoconfig.  But with a version number
19285 tacked on, that name would be too long for old Unix file systems,
19286 so I shortened it to Autoconf.
19288 In the fall of 1991 I called together a group of fellow questers after
19289 the Holy Grail of portability (er, that is, alpha testers) to give me
19290 feedback as I encapsulated pieces of my handwritten scripts in M4 macros
19291 and continued to add features and improve the techniques used in the
19292 checks.  Prominent among the testers were Fran@,{c}ois Pinard, who came up
19293 with the idea of making an Autoconf shell script to run M4
19294 and check for unresolved macro calls; Richard Pixley, who suggested
19295 running the compiler instead of searching the file system to find
19296 include files and symbols, for more accurate results; Karl Berry, who
19297 got Autoconf to configure @TeX{} and added the macro index to the
19298 documentation; and Ian Lance Taylor, who added support for creating a C
19299 header file as an alternative to putting @option{-D} options in a
19300 makefile, so he could use Autoconf for his @acronym{UUCP} package.
19301 The alpha testers cheerfully adjusted their files again and again as the
19302 names and calling conventions of the Autoconf macros changed from
19303 release to release.  They all contributed many specific checks, great
19304 ideas, and bug fixes.
19306 @node Numbers
19307 @section Numbers
19309 In July 1992, after months of alpha testing, I released Autoconf 1.0,
19310 and converted many @acronym{GNU} packages to use it.  I was surprised by how
19311 positive the reaction to it was.  More people started using it than I
19312 could keep track of, including people working on software that wasn't
19313 part of the @acronym{GNU} Project (such as TCL, FSP, and Kerberos V5).
19314 Autoconf continued to improve rapidly, as many people using the
19315 @command{configure} scripts reported problems they encountered.
19317 Autoconf turned out to be a good torture test for M4 implementations.
19318 Unix M4 started to dump core because of the length of the
19319 macros that Autoconf defined, and several bugs showed up in @acronym{GNU}
19320 M4 as well.  Eventually, we realized that we needed to use some
19321 features that only @acronym{GNU} M4 has.  4.3@acronym{BSD} M4, in
19322 particular, has an impoverished set of builtin macros; the System V
19323 version is better, but still doesn't provide everything we need.
19325 More development occurred as people put Autoconf under more stresses
19326 (and to uses I hadn't anticipated).  Karl Berry added checks for X11.
19327 david zuhn contributed C++ support.  Fran@,{c}ois Pinard made it diagnose
19328 invalid arguments.  Jim Blandy bravely coerced it into configuring
19329 @acronym{GNU} Emacs, laying the groundwork for several later improvements.
19330 Roland McGrath got it to configure the @acronym{GNU} C Library, wrote the
19331 @command{autoheader} script to automate the creation of C header file
19332 templates, and added a @option{--verbose} option to @command{configure}.
19333 Noah Friedman added the @option{--autoconf-dir} option and
19334 @code{AC_MACRODIR} environment variable.  (He also coined the term
19335 @dfn{autoconfiscate} to mean ``adapt a software package to use
19336 Autoconf''.)  Roland and Noah improved the quoting protection in
19337 @code{AC_DEFINE} and fixed many bugs, especially when I got sick of
19338 dealing with portability problems from February through June, 1993.
19340 @node Deuteronomy
19341 @section Deuteronomy
19343 A long wish list for major features had accumulated, and the effect of
19344 several years of patching by various people had left some residual
19345 cruft.  In April 1994, while working for Cygnus Support, I began a major
19346 revision of Autoconf.  I added most of the features of the Cygnus
19347 @command{configure} that Autoconf had lacked, largely by adapting the
19348 relevant parts of Cygnus @command{configure} with the help of david zuhn
19349 and Ken Raeburn.  These features include support for using
19350 @file{config.sub}, @file{config.guess}, @option{--host}, and
19351 @option{--target}; making links to files; and running @command{configure}
19352 scripts in subdirectories.  Adding these features enabled Ken to convert
19353 @acronym{GNU} @code{as}, and Rob Savoye to convert Deja@acronym{GNU}, to using
19354 Autoconf.
19356 I added more features in response to other peoples' requests.  Many
19357 people had asked for @command{configure} scripts to share the results of
19358 the checks between runs, because (particularly when configuring a large
19359 source tree, like Cygnus does) they were frustratingly slow.  Mike
19360 Haertel suggested adding site-specific initialization scripts.  People
19361 distributing software that had to unpack on MS-DOS asked for a way to
19362 override the @file{.in} extension on the file names, which produced file
19363 names like @file{config.h.in} containing two dots.  Jim Avera did an
19364 extensive examination of the problems with quoting in @code{AC_DEFINE}
19365 and @code{AC_SUBST}; his insights led to significant improvements.
19366 Richard Stallman asked that compiler output be sent to @file{config.log}
19367 instead of @file{/dev/null}, to help people debug the Emacs
19368 @command{configure} script.
19370 I made some other changes because of my dissatisfaction with the quality
19371 of the program.  I made the messages showing results of the checks less
19372 ambiguous, always printing a result.  I regularized the names of the
19373 macros and cleaned up coding style inconsistencies.  I added some
19374 auxiliary utilities that I had developed to help convert source code
19375 packages to use Autoconf.  With the help of Fran@,{c}ois Pinard, I made
19376 the macros not interrupt each others' messages.  (That feature revealed
19377 some performance bottlenecks in @acronym{GNU} M4, which he hastily
19378 corrected!)  I reorganized the documentation around problems people want
19379 to solve.  And I began a test suite, because experience had shown that
19380 Autoconf has a pronounced tendency to regress when we change it.
19382 Again, several alpha testers gave invaluable feedback, especially
19383 Fran@,{c}ois Pinard, Jim Meyering, Karl Berry, Rob Savoye, Ken Raeburn,
19384 and Mark Eichin.
19386 Finally, version 2.0 was ready.  And there was much rejoicing.  (And I
19387 have free time again.  I think.  Yeah, right.)
19390 @c ========================================================== Appendices
19392 @node Copying This Manual
19393 @appendix Copying This Manual
19394 @cindex License
19396 @menu
19397 * GNU Free Documentation License::  License for copying this manual
19398 @end menu
19400 @include fdl.texi
19402 @node Indices
19403 @appendix Indices
19405 @menu
19406 * Environment Variable Index::  Index of environment variables used
19407 * Output Variable Index::       Index of variables set in output files
19408 * Preprocessor Symbol Index::   Index of C preprocessor symbols defined
19409 * Autoconf Macro Index::        Index of Autoconf macros
19410 * M4 Macro Index::              Index of M4, M4sugar, and M4sh macros
19411 * Autotest Macro Index::        Index of Autotest macros
19412 * Program & Function Index::    Index of those with portability problems
19413 * Concept Index::               General index
19414 @end menu
19416 @node Environment Variable Index
19417 @appendixsec Environment Variable Index
19419 This is an alphabetical list of the environment variables that Autoconf
19420 checks.
19422 @printindex ev
19424 @node Output Variable Index
19425 @appendixsec Output Variable Index
19427 This is an alphabetical list of the variables that Autoconf can
19428 substitute into files that it creates, typically one or more
19429 makefiles.  @xref{Setting Output Variables}, for more information
19430 on how this is done.
19432 @printindex ov
19434 @node Preprocessor Symbol Index
19435 @appendixsec Preprocessor Symbol Index
19437 This is an alphabetical list of the C preprocessor symbols that the
19438 Autoconf macros define.  To work with Autoconf, C source code needs to
19439 use these names in @code{#if} or @code{#ifdef} directives.
19441 @printindex cv
19443 @node Autoconf Macro Index
19444 @appendixsec Autoconf Macro Index
19446 This is an alphabetical list of the Autoconf macros.
19447 @ifset shortindexflag
19448 To make the list easier to use, the macros are listed without their
19449 preceding @samp{AC_}.
19450 @end ifset
19452 @printindex AC
19454 @node M4 Macro Index
19455 @appendixsec M4 Macro Index
19457 This is an alphabetical list of the M4, M4sugar, and M4sh macros.
19458 @ifset shortindexflag
19459 To make the list easier to use, the macros are listed without their
19460 preceding @samp{m4_} or @samp{AS_}.
19461 @end ifset
19463 @printindex MS
19465 @node Autotest Macro Index
19466 @appendixsec Autotest Macro Index
19468 This is an alphabetical list of the Autotest macros.
19469 @ifset shortindexflag
19470 To make the list easier to use, the macros are listed without their
19471 preceding @samp{AT_}.
19472 @end ifset
19474 @printindex AT
19476 @node Program & Function Index
19477 @appendixsec Program and Function Index
19479 This is an alphabetical list of the programs and functions which
19480 portability is discussed in this document.
19482 @printindex pr
19484 @node Concept Index
19485 @appendixsec Concept Index
19487 This is an alphabetical list of the files, tools, and concepts
19488 introduced in this document.
19490 @printindex cp
19492 @bye
19494 @c  LocalWords:  texinfo setfilename autoconf texi settitle setchapternewpage
19495 @c  LocalWords:  setcontentsaftertitlepage finalout ARG ovar varname dvar acx
19496 @c  LocalWords:  makeinfo dvi defcodeindex ev ov CPP cv Autotest mv defindex fn
19497 @c  LocalWords:  shortindexflag iftex ifset acindex ACindex ifclear ahindex fu
19498 @c  LocalWords:  asindex MSindex atindex ATindex auindex hdrindex prindex FIXME
19499 @c  LocalWords:  msindex alloca fnindex Aaarg indices FSF's dircategory ifnames
19500 @c  LocalWords:  direntry autoscan autoreconf autoheader autoupdate config FDs
19501 @c  LocalWords:  testsuite titlepage Elliston Demaille vskip filll ifnottex hmm
19502 @c  LocalWords:  insertcopying Autoconf's detailmenu Automake Libtool Posix ois
19503 @c  LocalWords:  Systemology Checkpointing Changequote INTERCAL changequote dfn
19504 @c  LocalWords:  Quadrigraphs builtins Shellology acconfig Bugward LIBOBJ Imake
19505 @c  LocalWords:  LIBOBJS IFELSE cindex flushright Pinard Metaconfig uref Simons
19506 @c  LocalWords:  distclean uninstall noindent versioning Tromey dir
19507 @c  LocalWords:  SAMS samp aclocal acsite underquoted emph itemx prepend SUBST
19508 @c  LocalWords:  evindex automake Gettext autopoint gettext symlink libtoolize
19509 @c  LocalWords:  defmac INIT tarname ovindex cvindex BUGREPORT PREREQ asis PROG
19510 @c  LocalWords:  SRCDIR srcdir globbing afterwards cmds foos fooo foooo init cd
19511 @c  LocalWords:  builddir timestamp src Imakefile chmod defvar CFLAGS CPPFLAGS
19512 @c  LocalWords:  CXXFLAGS DEFS DHAVE defvarx FCFLAGS FFLAGS LDFLAGS bindir GCC
19513 @c  LocalWords:  datadir datarootdir docdir dvidir htmldir libdir ifnothtml kbd
19514 @c  LocalWords:  includedir infodir libexecdir localedir localstatedir mandir
19515 @c  LocalWords:  oldincludedir pdfdir PDF psdir PostScript sbindir sysconfdir
19516 @c  LocalWords:  sharedstatedir DDATADIR sed tmp pkgdatadir VPATH conf unistd
19517 @c  LocalWords:  undef endif builtin FUNCS ifndef STACKSEG getb GETB YMP fubar
19518 @c  LocalWords:  PRE dest SUBDIRS subdirs fi struct STDC stdlib stddef INTTYPES
19519 @c  LocalWords:  inttypes STDINT stdint AWK AIX Solaris NeXT env EGREP FGREP yy
19520 @c  LocalWords:  LEXLIB YYTEXT lfl nonportable Automake's LN RANLIB byacc INETD
19521 @c  LocalWords:  inetd prog PROGS progs ranlib lmp lXt lX nsl gethostbyname UX
19522 @c  LocalWords:  NextStep isinf isnan glibc IRIX sunmath lm lsunmath pre sizeof
19523 @c  LocalWords:  ld inline malloc putenv setenv FreeBSD realloc SunOS MinGW
19524 @c  LocalWords:  snprintf vsnprintf sprintf vsprintf sscanf gcc strerror ifdef
19525 @c  LocalWords:  strnlen sysconf PAGESIZE unsetenv va fallback memcpy dst FUNC
19526 @c  LocalWords:  PowerPC GNUC libPW pragma Olibcalls CHOWN chown CLOSEDIR VFORK
19527 @c  LocalWords:  closedir FNMATCH fnmatch vfork FSEEKO LARGEFILE fseeko SVR sc
19528 @c  LocalWords:  largefile GETGROUPS getgroups GETLOADAVG DGUX UMAX NLIST KMEM
19529 @c  LocalWords:  SETGID getloadavg nlist GETMNTENT irix
19530 @c  LocalWords:  getmntent UnixWare GETPGRP getpgid getpgrp Posix's pid LSTAT
19531 @c  LocalWords:  lstat rpl MEMCMP memcmp OpenStep MBRTOWC mbrtowc MKTIME mktime
19532 @c  LocalWords:  localtime MMAP mmap OBSTACK obstack obstacks ARGTYPES timeval
19533 @c  LocalWords:  SETPGRP setpgrp defmacx Hurd SETVBUF setvbuf STRCOLL strcoll
19534 @c  LocalWords:  STRTOD strtod DECL STRFTIME strftime SCO UTIME utime VPRINTF
19535 @c  LocalWords:  DOPRNT vprintf doprnt sp unfixable LIBSOURCE LIBSOURCES Eggert
19536 @c  LocalWords:  linux netinet ia Tru XFree DIRENT NDIR dirent ndir multitable
19537 @c  LocalWords:  NAMLEN strlen namlen MKDEV SYSMACROS makedev RESOLV resolv DNS
19538 @c  LocalWords:  inet structs NAMESER arpa NETDB netdb UTekV UTS GCC's kB
19539 @c  LocalWords:  STDBOOL BOOL stdbool conformant cplusplus bool Bool stdarg tm
19540 @c  LocalWords:  ctype strchr strrchr rindex bcopy memmove memchr WEXITSTATUS
19541 @c  LocalWords:  WIFEXITED TIOCGWINSZ GWINSZ termios preprocess preprocessable
19542 @c  LocalWords:  DECLS strdup calloc BLKSIZE blksize RDEV rdev TZNAME tzname pw
19543 @c  LocalWords:  passwd gecos pwd MBSTATE mbstate wchar RETSIGTYPE hup UID uid
19544 @c  LocalWords:  gid ptrdiff uintmax EXEEXT OBJEXT Ae conftest AXP str
19545 @c  LocalWords:  ALIGNOF WERROR Werror cpp HP's WorkShop egcs un fied stdc CXX
19546 @c  LocalWords:  varargs BIGENDIAN Endianness SPARC endianness grep'ed CONST FC
19547 @c  LocalWords:  const STRINGIZE stringizing PARAMS unprotoize protos KCC cxx
19548 @c  LocalWords:  xlC aCC CXXCPP FREEFORM xlf FLIBS FCLIBS ish SRCEXT XTRA LFS
19549 @c  LocalWords:  ISC lcposix MINIX Minix conditionalized inlines hw dD confdefs
19550 @c  LocalWords:  fputs stdout PREPROC ar UFS HFS QNX realtime fstype STATVFS se
19551 @c  LocalWords:  statvfs STATFS statfs func machfile hdr lelf raboof DEFUN GTK
19552 @c  LocalWords:  GTKMM Grmph ified ine defn baz EOF qar Ahhh changecom algol io
19553 @c  LocalWords:  changeword quadrigraphs quadrigraph dnl SGI atoi overquoting
19554 @c  LocalWords:  Aas Wcross sep args namespace undefine bpatsubst popdef dquote
19555 @c  LocalWords:  bregexp Overquote overquotation meisch maisch meische maische
19556 @c  LocalWords:  miscian DIRNAME dirname MKDIR CATFILE XMKMF TRAVOLTA celsius
19557 @c  LocalWords:  EMX emxos Emacsen Korn DYNIX subshell posix Ksh ksh Pdksh Zsh
19558 @c  LocalWords:  pdksh zsh Allbery Lipe Kubota UWS zorglub stderr eval esac lfn
19559 @c  LocalWords:  drivespec Posixy DJGPP doschk prettybird LPT pfew Zsh's yu yaa
19560 @c  LocalWords:  yM uM aM firebird IP subdir misparses ok Unpatched abc bc zA
19561 @c  LocalWords:  CDPATH DUALCASE LINENO prepass Subshells lineno NULLCMD cmp wc
19562 @c  LocalWords:  MAILPATH scanset arg NetBSD Almquist printf expr cp
19563 @c  LocalWords:  Oliva awk Aaaaarg cmd regex xfoo GNV OpenVMS VM
19564 @c  LocalWords:  sparc Proulx nbar nfoo maxdepth acdilrtu TWG mc
19565 @c  LocalWords:  mkdir exe uname OpenBSD Fileutils mktemp umask TMPDIR guid os
19566 @c  LocalWords:  fooXXXXXX Unicos utimes hpux hppa unescaped
19567 @c  LocalWords:  pmake DOS's gmake ifoo DESTDIR autoconfiscated pc coff mips gg
19568 @c  LocalWords:  dec ultrix cpu wildcards rpcc rdtsc powerpc readline
19569 @c  LocalWords:  withval vxworks gless localcache usr LOFF loff CYGWIN Cygwin
19570 @c  LocalWords:  cygwin SIGLIST siglist SYSNDIR SYSDIR ptx lseq rusage elif MSC
19571 @c  LocalWords:  lfoo POUNDBANG lsun NIS getpwnam SYSCALLS RSH INTL lintl aix
19572 @c  LocalWords:  intl lx ldir syslog bsd EPI toolchain netbsd objext de KNR nn
19573 @c  LocalWords:  fication LTLIBOBJS Wdiff TESTDIR atconfig atlocal akim XFAIL
19574 @c  LocalWords:  ChangeLog prepended errexit smallexample TESTSUITEFLAGS GPL er
19575 @c  LocalWords:  installcheck autotest indir Pixley Bothner Eichin Kerberos adl
19576 @c  LocalWords:  DISTCLEANFILES preprocessor's fileutils Stallman Murphey Stenn
19577 @c  LocalWords:  Manfredi Autoconfig TCL FSP david zuhn Blandy MACRODIR Raeburn
19578 @c  LocalWords:  autoconfiscate Savoye Haertel Avera Meyering fdl appendixsec
19579 @c  LocalWords:  printindex american LIBOBJDIR LibdirTest ERLCFLAGS OBJCFLAGS
19580 @c  LocalWords:  VER Gnulib online xyes strcpy TYPEOF typeof OBJC objcc objc ln
19581 @c  LocalWords:  GOBJC OTP ERLC erl valloc decr dumpdef errprint incr
19582 @c  LocalWords:  esyscmd len maketemp pushdef substr syscmd sysval translit txt
19583 @c  LocalWords:  sinclude foreach myvar tolower toupper uniq BASENAME STDIN
19584 @c  LocalWords:  Dynix descrips basename aname cname macroexpands xno xcheck
19585 @c  LocalWords:  LIBREADLINE lreadline lncurses libreadline
19587 @c Local Variables:
19588 @c fill-column: 72
19589 @c ispell-local-dictionary: "american"
19590 @c indent-tabs-mode: nil
19591 @c whitespace-check-buffer-indent: nil
19592 @c End: