1 \input texinfo @c -*-texinfo-*-
2 @comment ========================================================
3 @comment %**start of header
4 @setfilename autoconf.info
9 @setcontentsaftertitlepage
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).
18 @r{[}@var{\varname\}@r{]}
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{]}
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.
51 @c Define an output variable index.
53 @c Define a CPP variable index.
55 @c Define an Autoconf macro index that @defmac doesn't write to.
57 @c Define an Autotest macro index that @defmac doesn't write to.
59 @c Define an M4sugar macro index that @defmac doesn't write to.
61 @c Define an index for *foreign* programs: `mv' etc. Used for the
62 @c portability sections and so on.
67 @c Shall we factor AC_ out of the Autoconf macro index etc.?
74 @c Registering an AC_\MACRO\.
81 @ifclear shortindexflag
89 @c Registering an AH_\MACRO\.
97 @c Registering an AS_\MACRO\.
104 @ifclear shortindexflag
105 @macro asindex{macro}
112 @c Registering an AT_\MACRO\.
113 @ifset shortindexflag
114 @macro atindex{macro}
119 @ifclear shortindexflag
120 @macro atindex{macro}
127 @c Registering an AU_\MACRO\.
128 @macro auindex{macro}
135 @c Indexing a header.
136 @macro hdrindex{macro}
137 @prindex @file{\macro\}
143 @c Registering an m4_\MACRO\.
144 @ifset shortindexflag
145 @macro msindex{macro}
150 @ifclear shortindexflag
151 @macro msindex{macro}
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.
172 @c @c Put the programs and functions into their own index.
173 @c @syncodeindex fu pr
175 @comment %**end of header
176 @comment ========================================================
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 Free Software Foundation, Inc.
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.''
206 @dircategory Software development
208 * Autoconf: (autoconf). Create source code configuration scripts.
211 @dircategory Individual utilities
213 * autoscan: (autoconf)autoscan Invocation.
214 Semi-automatic @file{configure.ac} writing
215 * ifnames: (autoconf)ifnames Invocation. Listing conditionals in source.
216 * autoconf: (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.
233 @subtitle Creating Automatic Configuration Scripts
234 @subtitle for version @value{VERSION}, @value{UPDATED}
235 @author David MacKenzie
237 @author Akim Demaille
239 @vskip 0pt plus 1filll
252 @c The master menu, created with texinfo-master-menu, goes here.
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 C and C++:: C and C++ portability pitfalls
266 * Manual Configuration:: Selecting features that can't be guessed
267 * Site Configuration:: Local defaults for @command{configure}
268 * Running configure Scripts:: How to use the Autoconf output
269 * config.status Invocation:: Recreating a configuration
270 * Obsolete Constructs:: Kept for backward compatibility
271 * Using Autotest:: Creating portable test suites
272 * FAQ:: Frequent Autoconf Questions, with answers
273 * History:: History of Autoconf
274 * Copying This Manual:: How to make copies of this manual
275 * Indices:: Indices of symbols, concepts, etc.
278 --- The Detailed Node Listing ---
280 The @acronym{GNU} Build System
282 * Automake:: Escaping Makefile hell
283 * Gnulib:: The @acronym{GNU} portability library
284 * Libtool:: Building libraries portably
285 * Pointers:: More info on the @acronym{GNU} build system
287 Making @command{configure} Scripts
289 * Writing configure.ac:: What to put in an Autoconf input file
290 * autoscan Invocation:: Semi-automatic @file{configure.ac} writing
291 * ifnames Invocation:: Listing the conditionals in source code
292 * autoconf Invocation:: How to create configuration scripts
293 * autoreconf Invocation:: Remaking multiple @command{configure} scripts
295 Writing @file{configure.ac}
297 * Shell Script Compiler:: Autoconf as solution of a problem
298 * Autoconf Language:: Programming in Autoconf
299 * configure.ac Layout:: Standard organization of @file{configure.ac}
301 Initialization and Output Files
303 * Initializing configure:: Option processing etc.
304 * Notices:: Copyright, version numbers in @command{configure}
305 * Input:: Where Autoconf should find files
306 * Output:: Outputting results from the configuration
307 * Configuration Actions:: Preparing the output based on results
308 * Configuration Files:: Creating output files
309 * Makefile Substitutions:: Using output variables in @file{Makefile}s
310 * Configuration Headers:: Creating a configuration header file
311 * Configuration Commands:: Running arbitrary instantiation commands
312 * Configuration Links:: Links depending on the configuration
313 * Subdirectories:: Configuring independent packages together
314 * Default Prefix:: Changing the default installation prefix
316 Substitutions in Makefiles
318 * Preset Output Variables:: Output variables that are always set
319 * Installation Directory Variables:: Other preset output variables
320 * Build Directories:: Supporting multiple concurrent compiles
321 * Automatic Remaking:: Makefile rules for configuring
323 Configuration Header Files
325 * Header Templates:: Input for the configuration headers
326 * autoheader Invocation:: How to create configuration templates
327 * Autoheader Macros:: How to specify CPP templates
331 * Common Behavior:: Macros' standard schemes
332 * Alternative Programs:: Selecting between alternative programs
333 * Files:: Checking for the existence of files
334 * Libraries:: Library archives that might be missing
335 * Library Functions:: C library functions that might be missing
336 * Header Files:: Header files that might be missing
337 * Declarations:: Declarations that may be missing
338 * Structures:: Structures or members that might be missing
339 * Types:: Types that might be missing
340 * Compilers and Preprocessors:: Checking for compiling programs
341 * System Services:: Operating system services
342 * Posix Variants:: Special kludges for specific Posix variants
343 * Erlang Libraries:: Checking for the existence of Erlang libraries
347 * Standard Symbols:: Symbols defined by the macros
348 * Default Includes:: Includes used by the generic macros
352 * Particular Programs:: Special handling to find certain programs
353 * Generic Programs:: How to find other programs
357 * Function Portability:: Pitfalls with usual functions
358 * Particular Functions:: Special handling to find certain functions
359 * Generic Functions:: How to find other functions
363 * Header Portability:: Collected knowledge on common headers
364 * Particular Headers:: Special handling to find certain headers
365 * Generic Headers:: How to find other headers
369 * Particular Declarations:: Macros to check for certain declarations
370 * Generic Declarations:: How to find other declarations
374 * Particular Structures:: Macros to check for certain structure members
375 * Generic Structures:: How to find other structure members
379 * Particular Types:: Special handling to find certain types
380 * Generic Types:: How to find other types
382 Compilers and Preprocessors
384 * Specific Compiler Characteristics:: Some portability issues
385 * Generic Compiler Characteristics:: Language independent tests and features
386 * C Compiler:: Checking its characteristics
387 * C++ Compiler:: Likewise
388 * Objective C Compiler:: Likewise
389 * Erlang Compiler and Interpreter:: Likewise
390 * Fortran Compiler:: Likewise
394 * Language Choice:: Selecting which language to use for testing
395 * Writing Test Programs:: Forging source files for compilers
396 * Running the Preprocessor:: Detecting preprocessor symbols
397 * Running the Compiler:: Detecting language or header features
398 * Running the Linker:: Detecting library features
399 * Runtime:: Testing for runtime features
400 * Systemology:: A zoology of operating systems
401 * Multiple Cases:: Tests for several possible values
403 Writing Test Programs
405 * Guidelines:: General rules for writing test programs
406 * Test Functions:: Avoiding pitfalls in test programs
407 * Generating Sources:: Source program boilerplate
411 * Defining Symbols:: Defining C preprocessor symbols
412 * Setting Output Variables:: Replacing variables in output files
413 * Caching Results:: Speeding up subsequent @command{configure} runs
414 * Printing Messages:: Notifying @command{configure} users
418 * Cache Variable Names:: Shell variables used in caches
419 * Cache Files:: Files @command{configure} uses for caching
420 * Cache Checkpointing:: Loading and saving the cache file
424 * M4 Quotation:: Protecting macros from unwanted expansion
425 * Using autom4te:: The Autoconf executables backbone
426 * Programming in M4sugar:: Convenient pure M4 macros
427 * Programming in M4sh:: Common shell Constructs
428 * File Descriptor Macros:: File descriptor macros for input and output
432 * Active Characters:: Characters that change the behavior of M4
433 * One Macro Call:: Quotation and one macro call
434 * Quotation and Nested Macros:: Macros calling macros
435 * Changequote is Evil:: Worse than INTERCAL: M4 + changequote
436 * Quadrigraphs:: Another way to escape special characters
437 * Quotation Rule Of Thumb:: One parenthesis, one quote
439 Using @command{autom4te}
441 * autom4te Invocation:: A @acronym{GNU} M4 wrapper
442 * Customizing autom4te:: Customizing the Autoconf package
444 Programming in M4sugar
446 * Redefined M4 Macros:: M4 builtins changed in M4sugar
447 * Looping constructs:: Iteration in M4
448 * Evaluation Macros:: More quotation and evaluation control
449 * Text processing Macros:: String manipulation in M4
450 * Forbidden Patterns:: Catching unexpanded macros
452 Writing Autoconf Macros
454 * Macro Definitions:: Basic format of an Autoconf macro
455 * Macro Names:: What to call your new macros
456 * Reporting Messages:: Notifying @command{autoconf} users
457 * Dependencies Between Macros:: What to do when macros depend on other macros
458 * Obsoleting Macros:: Warning about old ways of doing things
459 * Coding Style:: Writing Autoconf macros @`a la Autoconf
461 Dependencies Between Macros
463 * Prerequisite Macros:: Ensuring required information
464 * Suggested Ordering:: Warning about possible ordering problems
465 * One-Shot Macros:: Ensuring a macro is called only once
467 Portable Shell Programming
469 * Shellology:: A zoology of shells
470 * Here-Documents:: Quirks and tricks
471 * File Descriptors:: FDs and redirections
472 * File System Conventions:: File names
473 * Shell Substitutions:: Variable and command expansions
474 * Assignments:: Varying side effects of assignments
475 * Parentheses:: Parentheses in shell scripts
476 * Slashes:: Slashes in shell scripts
477 * Special Shell Variables:: Variables you should not change
478 * Limitations of Builtins:: Portable use of not so portable /bin/sh
479 * Limitations of Usual Tools:: Portable use of portable tools
480 * Limitations of Make:: Portable Makefiles
482 Portable C and C++ Programming
484 * Varieties of Unportability:: How to make your programs unportable
485 * Integer Overflow:: When integers get too large
486 * Null Pointers:: Properties of null pointers
487 * Buffer Overruns:: Subscript errors and the like
488 * Floating Point Portability:: Portable floating-point arithmetic
489 * Exiting Portably:: Exiting and the exit status
493 * Specifying Names:: Specifying the system type
494 * Canonicalizing:: Getting the canonical system type
495 * Using System Type:: What to do with the system type
499 * Help Formatting:: Customizing @samp{configure --help}
500 * External Software:: Working with other optional software
501 * Package Options:: Selecting optional features
502 * Pretty Help Strings:: Formatting help string
503 * Site Details:: Configuring site details
504 * Transforming Names:: Changing program names when installing
505 * Site Defaults:: Giving @command{configure} local defaults
507 Transforming Program Names When Installing
509 * Transformation Options:: @command{configure} options to transform names
510 * Transformation Examples:: Sample uses of transforming names
511 * Transformation Rules:: @file{Makefile} uses of transforming names
513 Running @command{configure} Scripts
515 * Basic Installation:: Instructions for typical cases
516 * Compilers and Options:: Selecting compilers and optimization
517 * Multiple Architectures:: Compiling for multiple architectures at once
518 * Installation Names:: Installing in different directories
519 * Optional Features:: Selecting optional features
520 * System Type:: Specifying the system type
521 * Sharing Defaults:: Setting site-wide defaults for @command{configure}
522 * Defining Variables:: Specifying the compiler etc.
523 * configure Invocation:: Changing how @command{configure} runs
527 * Obsolete config.status Use:: Different calling convention
528 * acconfig.h:: Additional entries in @file{config.h.in}
529 * autoupdate Invocation:: Automatic update of @file{configure.ac}
530 * Obsolete Macros:: Backward compatibility macros
531 * Autoconf 1:: Tips for upgrading your files
532 * Autoconf 2.13:: Some fresher tips
534 Upgrading From Version 1
536 * Changed File Names:: Files you might rename
537 * Changed Makefiles:: New things to put in @file{Makefile.in}
538 * Changed Macros:: Macro calls you might replace
539 * Changed Results:: Changes in how to check test results
540 * Changed Macro Writing:: Better ways to write your own macros
542 Upgrading From Version 2.13
544 * Changed Quotation:: Broken code which used to work
545 * New Macros:: Interaction with foreign macros
546 * Hosts and Cross-Compilation:: Bugward compatibility kludges
547 * AC_LIBOBJ vs LIBOBJS:: LIBOBJS is a forbidden token
548 * AC_FOO_IFELSE vs AC_TRY_FOO:: A more generic scheme for testing sources
550 Generating Test Suites with Autotest
552 * Using an Autotest Test Suite:: Autotest and the user
553 * Writing testsuite.at:: Autotest macros
554 * testsuite Invocation:: Running @command{testsuite} scripts
555 * Making testsuite Scripts:: Using autom4te to create @command{testsuite}
557 Using an Autotest Test Suite
559 * testsuite Scripts:: The concepts of Autotest
560 * Autotest Logs:: Their contents
562 Frequent Autoconf Questions, with answers
564 * Distributing:: Distributing @command{configure} scripts
565 * Why GNU m4:: Why not use the standard M4?
566 * Bootstrapping:: Autoconf and @acronym{GNU} M4 require each other?
567 * Why Not Imake:: Why @acronym{GNU} uses @command{configure} instead of Imake
568 * Defining Directories:: Passing @code{datadir} to program
569 * autom4te.cache:: What is it? Can I remove it?
570 * Present But Cannot Be Compiled:: Compiler and Preprocessor Disagree
574 * Genesis:: Prehistory and naming of @command{configure}
575 * Exodus:: The plagues of M4 and Perl
576 * Leviticus:: The priestly code of portability arrives
577 * Numbers:: Growth and contributors
578 * Deuteronomy:: Approaching the promises of easy configuration
582 * GNU Free Documentation License:: License for copying this manual
586 * Environment Variable Index:: Index of environment variables used
587 * Output Variable Index:: Index of variables set in output files
588 * Preprocessor Symbol Index:: Index of C preprocessor symbols defined
589 * Autoconf Macro Index:: Index of Autoconf macros
590 * M4 Macro Index:: Index of M4, M4sugar, and M4sh macros
591 * Autotest Macro Index:: Index of Autotest macros
592 * Program & Function Index:: Index of those with portability problems
593 * Concept Index:: General index
598 @c ============================================================= Introduction.
601 @chapter Introduction
605 A physicist, an engineer, and a computer scientist were discussing the
606 nature of God. ``Surely a Physicist,'' said the physicist, ``because
607 early in the Creation, God made Light; and you know, Maxwell's
608 equations, the dual nature of electromagnetic waves, the relativistic
609 consequences@dots{}'' ``An Engineer!,'' said the engineer, ``because
610 before making Light, God split the Chaos into Land and Water; it takes a
611 hell of an engineer to handle that big amount of mud, and orderly
612 separation of solids from liquids@dots{}'' The computer scientist
613 shouted: ``And the Chaos, where do you think it was coming from, hmm?''
617 @c (via Franc,ois Pinard)
619 Autoconf is a tool for producing shell scripts that automatically
620 configure software source code packages to adapt to many kinds of
621 Posix-like systems. The configuration scripts produced by Autoconf
622 are independent of Autoconf when they are run, so their users do not
623 need to have Autoconf.
625 The configuration scripts produced by Autoconf require no manual user
626 intervention when run; they do not normally even need an argument
627 specifying the system type. Instead, they individually test for the
628 presence of each feature that the software package they are for might need.
629 (Before each check, they print a one-line message stating what they are
630 checking for, so the user doesn't get too bored while waiting for the
631 script to finish.) As a result, they deal well with systems that are
632 hybrids or customized from the more common Posix variants. There is
633 no need to maintain files that list the features supported by each
634 release of each variant of Posix.
636 For each software package that Autoconf is used with, it creates a
637 configuration script from a template file that lists the system features
638 that the package needs or can use. After the shell code to recognize
639 and respond to a system feature has been written, Autoconf allows it to
640 be shared by many software packages that can use (or need) that feature.
641 If it later turns out that the shell code needs adjustment for some
642 reason, it needs to be changed in only one place; all of the
643 configuration scripts can be regenerated automatically to take advantage
646 The Metaconfig package is similar in purpose to Autoconf, but the
647 scripts it produces require manual user intervention, which is quite
648 inconvenient when configuring large source trees. Unlike Metaconfig
649 scripts, Autoconf scripts can support cross-compiling, if some care is
650 taken in writing them.
652 Autoconf does not solve all problems related to making portable
653 software packages---for a more complete solution, it should be used in
654 concert with other @acronym{GNU} build tools like Automake and
655 Libtool. These other tools take on jobs like the creation of a
656 portable, recursive @file{Makefile} with all of the standard targets,
657 linking of shared libraries, and so on. @xref{The GNU Build System},
658 for more information.
660 Autoconf imposes some restrictions on the names of macros used with
661 @code{#if} in C programs (@pxref{Preprocessor Symbol Index}).
663 Autoconf requires @acronym{GNU} M4 in order to generate the scripts. It uses
664 features that some versions of M4, including @acronym{GNU} M4 1.3,
665 do not have. You should use version 1.4.3 or later of @acronym{GNU} M4.
667 @xref{Autoconf 1}, for information about upgrading from version 1.
668 @xref{History}, for the story of Autoconf's development. @xref{FAQ},
669 for answers to some common questions about Autoconf.
671 See the @uref{http://www.gnu.org/software/autoconf/,
672 Autoconf web page} for up-to-date information, details on the mailing
673 lists, pointers to a list of known bugs, etc.
675 Mail suggestions to @email{autoconf@@gnu.org, the Autoconf mailing
676 list}. Past suggestions are
677 @uref{http://lists.gnu.org/archive/html/autoconf/, archived}.
679 Mail bug reports to @email{bug-autoconf@@gnu.org, the
680 Autoconf Bugs mailing list}. Past bug reports are
681 @uref{http://lists.gnu.org/archive/html/bug-autoconf/, archived}.
683 If possible, first check that your bug is
684 not already solved in current development versions, and that it has not
685 been reported yet. Be sure to include all the needed information and a
686 short @file{configure.ac} that demonstrates the problem.
688 Autoconf's development tree is accessible via anonymous @acronym{CVS}; see the
689 @uref{http://savannah.gnu.org/projects/autoconf/, Autoconf
690 Summary} for details. Patches relative to the
691 current @acronym{CVS} version can be sent for review to the
692 @email{autoconf-patches@@gnu.org, Autoconf Patches mailing list}.
694 @uref{http://lists.gnu.org/archive/html/autoconf-patches/, archived}.
696 Because of its mission, the Autoconf package itself
697 includes only a set of often-used
698 macros that have already demonstrated their usefulness. Nevertheless,
699 if you wish to share your macros, or find existing ones, see the
700 @uref{http://autoconf-archive.cryp.to/, Autoconf Macro
701 Archive}, which is kindly run by @email{simons@@cryp.to,
705 @c ================================================= The GNU Build System
707 @node The GNU Build System
708 @chapter The @acronym{GNU} Build System
709 @cindex GNU build system
711 Autoconf solves an important problem---reliable discovery of
712 system-specific build and runtime information---but this is only one
713 piece of the puzzle for the development of portable software. To this
714 end, the @acronym{GNU} project has developed a suite of integrated
715 utilities to finish the job Autoconf started: the @acronym{GNU} build
716 system, whose most important components are Autoconf, Automake, and
717 Libtool. In this chapter, we introduce you to those tools, point you
718 to sources of more information, and try to convince you to use the
719 entire @acronym{GNU} build system for your software.
722 * Automake:: Escaping Makefile hell
723 * Gnulib:: The @acronym{GNU} portability library
724 * Libtool:: Building libraries portably
725 * Pointers:: More info on the @acronym{GNU} build system
731 The ubiquity of @command{make} means that a @file{Makefile} is almost the
732 only viable way to distribute automatic build rules for software, but
733 one quickly runs into @command{make}'s numerous limitations. Its lack of
734 support for automatic dependency tracking, recursive builds in
735 subdirectories, reliable timestamps (e.g., for network file systems), and
736 so on, mean that developers must painfully (and often incorrectly)
737 reinvent the wheel for each project. Portability is non-trivial, thanks
738 to the quirks of @command{make} on many systems. On top of all this is the
739 manual labor required to implement the many standard targets that users
740 have come to expect (@code{make install}, @code{make distclean},
741 @code{make uninstall}, etc.). Since you are, of course, using Autoconf,
742 you also have to insert repetitive code in your @code{Makefile.in} to
743 recognize @code{@@CC@@}, @code{@@CFLAGS@@}, and other substitutions
744 provided by @command{configure}. Into this mess steps @dfn{Automake}.
747 Automake allows you to specify your build needs in a @code{Makefile.am}
748 file with a vastly simpler and more powerful syntax than that of a plain
749 @code{Makefile}, and then generates a portable @code{Makefile.in} for
750 use with Autoconf. For example, the @code{Makefile.am} to build and
751 install a simple ``Hello world'' program might look like:
755 hello_SOURCES = hello.c
759 The resulting @code{Makefile.in} (~400 lines) automatically supports all
760 the standard targets, the substitutions provided by Autoconf, automatic
761 dependency tracking, @code{VPATH} building, and so on. @command{make} will
762 build the @code{hello} program, and @code{make install} will install it
763 in @file{/usr/local/bin} (or whatever prefix was given to
764 @command{configure}, if not @file{/usr/local}).
766 The benefits of Automake increase for larger packages (especially ones
767 with subdirectories), but even for small programs the added convenience
768 and portability can be substantial. And that's not all@enddots{}
773 @acronym{GNU} software has a well-deserved reputation for running on
774 many different types of systems. While our primary goal is to write
775 software for the @acronym{GNU} system, many users and developers have
776 been introduced to us through the systems that they were already using.
779 Gnulib is a central location for common @acronym{GNU} code, intended to
780 be shared among free software packages. Its components are typically
781 shared at the source level, rather than being a library that gets built,
782 installed, and linked against. The idea is to copy files from Gnulib
783 into your own source tree. There is no distribution tarball; developers
784 should just grab source modules from the repository. The source files
785 are available online, under various licenses, mostly @acronym{GNU}
786 @acronym{GPL} or @acronym{GNU} @acronym{LGPL}.
788 Gnulib modules typically contain C source code along with Autoconf
789 macros used to configure the source code. For example, the Gnulib
790 @code{stdbool} module implements a @file{stdbool.h} header that nearly
791 conforms to C99, even on old-fashioned hosts that lack @file{stdbool.h}.
792 This module contains a source file for the replacement header, along
793 with an Autoconf macro that arranges to use the replacement header on
794 old-fashioned systems.
799 Very often, one wants to build not only programs, but libraries, so that
800 other programs can benefit from the fruits of your labor. Ideally, one
801 would like to produce @emph{shared} (dynamically linked) libraries,
802 which can be used by multiple programs without duplication on disk or in
803 memory and can be updated independently of the linked programs.
804 Producing shared libraries portably, however, is the stuff of
805 nightmares---each system has its own incompatible tools, compiler flags,
806 and magic incantations. Fortunately, @acronym{GNU} provides a solution:
810 Libtool handles all the requirements of building shared libraries for
811 you, and at this time seems to be the @emph{only} way to do so with any
812 portability. It also handles many other headaches, such as: the
813 interaction of @code{Makefile} rules with the variable suffixes of
814 shared libraries, linking reliably with shared libraries before they are
815 installed by the superuser, and supplying a consistent versioning system
816 (so that different versions of a library can be installed or upgraded
817 without breaking binary compatibility). Although Libtool, like
818 Autoconf, can be used without Automake, it is most simply utilized in
819 conjunction with Automake---there, Libtool is used automatically
820 whenever shared libraries are needed, and you need not know its syntax.
825 Developers who are used to the simplicity of @command{make} for small
826 projects on a single system might be daunted at the prospect of
827 learning to use Automake and Autoconf. As your software is
828 distributed to more and more users, however, you will otherwise
829 quickly find yourself putting lots of effort into reinventing the
830 services that the @acronym{GNU} build tools provide, and making the
831 same mistakes that they once made and overcame. (Besides, since
832 you're already learning Autoconf, Automake will be a piece of cake.)
834 There are a number of places that you can go to for more information on
835 the @acronym{GNU} build tools.
842 @uref{http://www.gnu.org/software/autoconf/, Autoconf},
843 @uref{http://www.gnu.org/software/automake/, Automake},
844 @uref{http://www.gnu.org/software/gnulib/, Gnulib}, and
845 @uref{http://www.gnu.org/software/libtool/, Libtool}.
847 @item Automake Manual
849 @xref{Top, , Automake, automake, @acronym{GNU} Automake}, for more
850 information on Automake.
854 The book @cite{@acronym{GNU} Autoconf, Automake and
855 Libtool}@footnote{@cite{@acronym{GNU} Autoconf, Automake and Libtool},
856 by G. V. Vaughan, B. Elliston, T. Tromey, and I. L. Taylor. SAMS (originally
857 New Riders), 2000, ISBN 1578701902.} describes the complete @acronym{GNU}
858 build environment. You can also find
859 @uref{http://sources.redhat.com/autobook/, the entire book on-line}.
863 @c ================================================= Making configure Scripts.
865 @node Making configure Scripts
866 @chapter Making @command{configure} Scripts
867 @cindex @file{aclocal.m4}
868 @cindex @command{configure}
870 The configuration scripts that Autoconf produces are by convention
871 called @command{configure}. When run, @command{configure} creates several
872 files, replacing configuration parameters in them with appropriate
873 values. The files that @command{configure} creates are:
877 one or more @file{Makefile} files, usually one in each subdirectory of the
878 package (@pxref{Makefile Substitutions});
881 optionally, a C header file, the name of which is configurable,
882 containing @code{#define} directives (@pxref{Configuration Headers});
885 a shell script called @file{config.status} that, when run, will recreate
886 the files listed above (@pxref{config.status Invocation});
889 an optional shell script normally called @file{config.cache}
890 (created when using @samp{configure --config-cache}) that
891 saves the results of running many of the tests (@pxref{Cache Files});
894 a file called @file{config.log} containing any messages produced by
895 compilers, to help debugging if @command{configure} makes a mistake.
898 @cindex @file{configure.in}
899 @cindex @file{configure.ac}
900 To create a @command{configure} script with Autoconf, you need to write an
901 Autoconf input file @file{configure.ac} (or @file{configure.in}) and run
902 @command{autoconf} on it. If you write your own feature tests to
903 supplement those that come with Autoconf, you might also write files
904 called @file{aclocal.m4} and @file{acsite.m4}. If you use a C header
905 file to contain @code{#define} directives, you might also run
906 @command{autoheader}, and you will distribute the generated file
907 @file{config.h.in} with the package.
909 Here is a diagram showing how the files that can be used in
910 configuration are produced. Programs that are executed are suffixed by
911 @samp{*}. Optional files are enclosed in square brackets (@samp{[]}).
912 @command{autoconf} and @command{autoheader} also read the installed Autoconf
913 macro files (by reading @file{autoconf.m4}).
916 Files used in preparing a software package for distribution:
918 your source files --> [autoscan*] --> [configure.scan] --> configure.ac
922 | .------> autoconf* -----> configure
924 | `-----> [autoheader*] --> [config.h.in]
928 Makefile.in -------------------------------> Makefile.in
932 Files used in configuring a software package:
935 .-------------> [config.cache]
936 configure* ------------+-------------> config.log
938 [config.h.in] -. v .-> [config.h] -.
939 +--> config.status* -+ +--> make*
940 Makefile.in ---' `-> Makefile ---'
945 * Writing configure.ac:: What to put in an Autoconf input file
946 * autoscan Invocation:: Semi-automatic @file{configure.ac} writing
947 * ifnames Invocation:: Listing the conditionals in source code
948 * autoconf Invocation:: How to create configuration scripts
949 * autoreconf Invocation:: Remaking multiple @command{configure} scripts
952 @node Writing configure.ac
953 @section Writing @file{configure.ac}
955 To produce a @command{configure} script for a software package, create a
956 file called @file{configure.ac} that contains invocations of the
957 Autoconf macros that test the system features your package needs or can
958 use. Autoconf macros already exist to check for many features; see
959 @ref{Existing Tests}, for their descriptions. For most other features,
960 you can use Autoconf template macros to produce custom checks; see
961 @ref{Writing Tests}, for information about them. For especially tricky
962 or specialized features, @file{configure.ac} might need to contain some
963 hand-crafted shell commands; see @ref{Portable Shell}. The
964 @command{autoscan} program can give you a good start in writing
965 @file{configure.ac} (@pxref{autoscan Invocation}, for more information).
967 Previous versions of Autoconf promoted the name @file{configure.in},
968 which is somewhat ambiguous (the tool needed to process this file is not
969 described by its extension), and introduces a slight confusion with
970 @file{config.h.in} and so on (for which @samp{.in} means ``to be
971 processed by @command{configure}''). Using @file{configure.ac} is now
975 * Shell Script Compiler:: Autoconf as solution of a problem
976 * Autoconf Language:: Programming in Autoconf
977 * configure.ac Layout:: Standard organization of @file{configure.ac}
980 @node Shell Script Compiler
981 @subsection A Shell Script Compiler
983 Just as for any other computer language, in order to properly program
984 @file{configure.ac} in Autoconf you must understand @emph{what} problem
985 the language tries to address and @emph{how} it does so.
987 The problem Autoconf addresses is that the world is a mess. After all,
988 you are using Autoconf in order to have your package compile easily on
989 all sorts of different systems, some of them being extremely hostile.
990 Autoconf itself bears the price for these differences: @command{configure}
991 must run on all those systems, and thus @command{configure} must limit itself
992 to their lowest common denominator of features.
994 Naturally, you might then think of shell scripts; who needs
995 @command{autoconf}? A set of properly written shell functions is enough to
996 make it easy to write @command{configure} scripts by hand. Sigh!
997 Unfortunately, shell functions do not belong to the least common
998 denominator; therefore, where you would like to define a function and
999 use it ten times, you would instead need to copy its body ten times.
1001 So, what is really needed is some kind of compiler, @command{autoconf},
1002 that takes an Autoconf program, @file{configure.ac}, and transforms it
1003 into a portable shell script, @command{configure}.
1005 How does @command{autoconf} perform this task?
1007 There are two obvious possibilities: creating a brand new language or
1008 extending an existing one. The former option is very attractive: all
1009 sorts of optimizations could easily be implemented in the compiler and
1010 many rigorous checks could be performed on the Autoconf program
1011 (e.g., rejecting any non-portable construct). Alternatively, you can
1012 extend an existing language, such as the @code{sh} (Bourne shell)
1015 Autoconf does the latter: it is a layer on top of @code{sh}. It was
1016 therefore most convenient to implement @command{autoconf} as a macro
1017 expander: a program that repeatedly performs @dfn{macro expansions} on
1018 text input, replacing macro calls with macro bodies and producing a pure
1019 @code{sh} script in the end. Instead of implementing a dedicated
1020 Autoconf macro expander, it is natural to use an existing
1021 general-purpose macro language, such as M4, and implement the extensions
1022 as a set of M4 macros.
1025 @node Autoconf Language
1026 @subsection The Autoconf Language
1029 The Autoconf language is very different from many other computer
1030 languages because it treats actual code the same as plain text. Whereas
1031 in C, for instance, data and instructions have very different syntactic
1032 status, in Autoconf their status is rigorously the same. Therefore, we
1033 need a means to distinguish literal strings from text to be expanded:
1036 When calling macros that take arguments, there must not be any white
1037 space between the macro name and the open parenthesis. Arguments should
1038 be enclosed within the M4 quote characters @samp{[} and @samp{]}, and be
1039 separated by commas. Any leading blanks or newlines in arguments are ignored,
1040 unless they are quoted. You should always quote an argument that
1041 might contain a macro name, comma, parenthesis, or a leading blank or
1042 newline. This rule applies recursively for every macro
1043 call, including macros called from other macros.
1048 AC_CHECK_HEADER([stdio.h],
1049 [AC_DEFINE([HAVE_STDIO_H], [1],
1050 [Define to 1 if you have <stdio.h>.])],
1051 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1055 is quoted properly. You may safely simplify its quotation to:
1058 AC_CHECK_HEADER([stdio.h],
1059 [AC_DEFINE([HAVE_STDIO_H], 1,
1060 [Define to 1 if you have <stdio.h>.])],
1061 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1065 because @samp{1} cannot contain a macro call. Here, the argument of
1066 @code{AC_MSG_ERROR} must be quoted; otherwise, its comma would be
1067 interpreted as an argument separator. Also, @samp{AC_CHECK_HEADER}'s
1068 second and third arguments must be quoted, since those arguments contain
1069 macro calls. The three arguments @samp{HAVE_STDIO_H}, @samp{stdio.h},
1070 and @samp{Define to 1 if you have <stdio.h>.} do not need quoting, but
1071 if you unwisely defined a macro with a name like @samp{Define} or
1072 @samp{stdio} then they would need quoting. Cautious Autoconf users
1073 would keep the quotes, but many Autoconf users find such precautions
1074 annoying, and would rewrite the example as follows:
1077 AC_CHECK_HEADER(stdio.h,
1078 [AC_DEFINE(HAVE_STDIO_H, 1,
1079 [Define to 1 if you have <stdio.h>.])],
1080 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1084 This is safe, so long as you adopt good naming conventions and do not
1085 define macros with names like @samp{HAVE_STDIO_H}, @samp{stdio}, or
1086 @samp{h}. Though it is also safe here to omit the quotes around
1087 @samp{Define to 1 if you have <stdio.h>.} this is not recommended, as
1088 message strings are more likely to inadvertently contain commas.
1090 The following example is wrong and dangerous, as it is underquoted:
1093 AC_CHECK_HEADER(stdio.h,
1094 AC_DEFINE(HAVE_STDIO_H, 1,
1095 Define to 1 if you have <stdio.h>.),
1096 AC_MSG_ERROR([Sorry, can't do anything for you]))
1099 In other cases, you may have to use text that also resembles a macro
1100 call. You must quote that text even when it is not passed as a macro
1104 echo "Hard rock was here! --[AC_DC]"
1108 which will result in
1111 echo "Hard rock was here! --AC_DC"
1115 When you use the same text in a macro argument, you must therefore have
1116 an extra quotation level (since one is stripped away by the macro
1117 substitution). In general, then, it is a good idea to @emph{use double
1118 quoting for all literal string arguments}:
1121 AC_MSG_WARN([[AC_DC stinks --Iron Maiden]])
1124 You are now able to understand one of the constructs of Autoconf that
1125 has been continually misunderstood@dots{} The rule of thumb is that
1126 @emph{whenever you expect macro expansion, expect quote expansion};
1127 i.e., expect one level of quotes to be lost. For instance:
1130 AC_COMPILE_IFELSE([char b[10];], [], [AC_MSG_ERROR([you lose])])
1134 is incorrect: here, the first argument of @code{AC_COMPILE_IFELSE} is
1135 @samp{char b[10];} and will be expanded once, which results in
1136 @samp{char b10;}. (There was an idiom common in Autoconf's past to
1137 address this issue via the M4 @code{changequote} primitive, but do not
1138 use it!) Let's take a closer look: the author meant the first argument
1139 to be understood as a literal, and therefore it must be quoted twice:
1142 AC_COMPILE_IFELSE([[char b[10];]], [], [AC_MSG_ERROR([you lose])])
1146 Voil@`a, you actually produce @samp{char b[10];} this time!
1148 On the other hand, descriptions (e.g., the last parameter of
1149 @code{AC_DEFINE} or @code{AS_HELP_STRING}) are not literals---they
1150 are subject to line breaking, for example---and should not be double quoted.
1151 Even if these descriptions are short and are not actually broken, double
1152 quoting them yields weird results.
1154 Some macros take optional arguments, which this documentation represents
1155 as @ovar{arg} (not to be confused with the quote characters). You may
1156 just leave them empty, or use @samp{[]} to make the emptiness of the
1157 argument explicit, or you may simply omit the trailing commas. The
1158 three lines below are equivalent:
1161 AC_CHECK_HEADERS([stdio.h], [], [], [])
1162 AC_CHECK_HEADERS([stdio.h],,,)
1163 AC_CHECK_HEADERS([stdio.h])
1166 It is best to put each macro call on its own line in
1167 @file{configure.ac}. Most of the macros don't add extra newlines; they
1168 rely on the newline after the macro call to terminate the commands.
1169 This approach makes the generated @command{configure} script a little
1170 easier to read by not inserting lots of blank lines. It is generally
1171 safe to set shell variables on the same line as a macro call, because
1172 the shell allows assignments without intervening newlines.
1174 You can include comments in @file{configure.ac} files by starting them
1175 with the @samp{#}. For example, it is helpful to begin
1176 @file{configure.ac} files with a line like this:
1179 # Process this file with autoconf to produce a configure script.
1182 @node configure.ac Layout
1183 @subsection Standard @file{configure.ac} Layout
1185 The order in which @file{configure.ac} calls the Autoconf macros is not
1186 important, with a few exceptions. Every @file{configure.ac} must
1187 contain a call to @code{AC_INIT} before the checks, and a call to
1188 @code{AC_OUTPUT} at the end (@pxref{Output}). Additionally, some macros
1189 rely on other macros having been called first, because they check
1190 previously set values of some variables to decide what to do. These
1191 macros are noted in the individual descriptions (@pxref{Existing
1192 Tests}), and they also warn you when @command{configure} is created if they
1193 are called out of order.
1195 To encourage consistency, here is a suggested order for calling the
1196 Autoconf macros. Generally speaking, the things near the end of this
1197 list are those that could depend on things earlier in it. For example,
1198 library functions could be affected by types and libraries.
1202 Autoconf requirements
1203 @code{AC_INIT(@var{package}, @var{version}, @var{bug-report-address})}
1204 information on the package
1206 checks for libraries
1207 checks for header files
1209 checks for structures
1210 checks for compiler characteristics
1211 checks for library functions
1212 checks for system services
1213 @code{AC_CONFIG_FILES(@r{[}@var{file@dots{}}@r{]})}
1219 @node autoscan Invocation
1220 @section Using @command{autoscan} to Create @file{configure.ac}
1221 @cindex @command{autoscan}
1223 The @command{autoscan} program can help you create and/or maintain a
1224 @file{configure.ac} file for a software package. @command{autoscan}
1225 examines source files in the directory tree rooted at a directory given
1226 as a command line argument, or the current directory if none is given.
1227 It searches the source files for common portability problems and creates
1228 a file @file{configure.scan} which is a preliminary @file{configure.ac}
1229 for that package, and checks a possibly existing @file{configure.ac} for
1232 When using @command{autoscan} to create a @file{configure.ac}, you
1233 should manually examine @file{configure.scan} before renaming it to
1234 @file{configure.ac}; it will probably need some adjustments.
1235 Occasionally, @command{autoscan} outputs a macro in the wrong order
1236 relative to another macro, so that @command{autoconf} produces a warning;
1237 you need to move such macros manually. Also, if you want the package to
1238 use a configuration header file, you must add a call to
1239 @code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers}). You might
1240 also have to change or add some @code{#if} directives to your program in
1241 order to make it work with Autoconf (@pxref{ifnames Invocation}, for
1242 information about a program that can help with that job).
1244 When using @command{autoscan} to maintain a @file{configure.ac}, simply
1245 consider adding its suggestions. The file @file{autoscan.log} will
1246 contain detailed information on why a macro is requested.
1248 @command{autoscan} uses several data files (installed along with Autoconf)
1249 to determine which macros to output when it finds particular symbols in
1250 a package's source files. These data files all have the same format:
1251 each line consists of a symbol, one or more blanks, and the Autoconf macro to
1252 output if that symbol is encountered. Lines starting with @samp{#} are
1255 @command{autoscan} accepts the following options:
1260 Print a summary of the command line options and exit.
1264 Print the version number of Autoconf and exit.
1268 Print the names of the files it examines and the potentially interesting
1269 symbols it finds in them. This output can be voluminous.
1271 @item --include=@var{dir}
1273 Append @var{dir} to the include path. Multiple invocations accumulate.
1275 @item --prepend-include=@var{dir}
1277 Prepend @var{dir} to the include path. Multiple invocations accumulate.
1280 @node ifnames Invocation
1281 @section Using @command{ifnames} to List Conditionals
1282 @cindex @command{ifnames}
1284 @command{ifnames} can help you write @file{configure.ac} for a software
1285 package. It prints the identifiers that the package already uses in C
1286 preprocessor conditionals. If a package has already been set up to have
1287 some portability, @command{ifnames} can thus help you figure out what its
1288 @command{configure} needs to check for. It may help fill in some gaps in a
1289 @file{configure.ac} generated by @command{autoscan} (@pxref{autoscan
1292 @command{ifnames} scans all of the C source files named on the command line
1293 (or the standard input, if none are given) and writes to the standard
1294 output a sorted list of all the identifiers that appear in those files
1295 in @code{#if}, @code{#elif}, @code{#ifdef}, or @code{#ifndef}
1296 directives. It prints each identifier on a line, followed by a
1297 space-separated list of the files in which that identifier occurs.
1300 @command{ifnames} accepts the following options:
1305 Print a summary of the command line options and exit.
1309 Print the version number of Autoconf and exit.
1312 @node autoconf Invocation
1313 @section Using @command{autoconf} to Create @command{configure}
1314 @cindex @command{autoconf}
1316 To create @command{configure} from @file{configure.ac}, run the
1317 @command{autoconf} program with no arguments. @command{autoconf} processes
1318 @file{configure.ac} with the M4 macro processor, using the
1319 Autoconf macros. If you give @command{autoconf} an argument, it reads that
1320 file instead of @file{configure.ac} and writes the configuration script
1321 to the standard output instead of to @command{configure}. If you give
1322 @command{autoconf} the argument @option{-}, it reads from the standard
1323 input instead of @file{configure.ac} and writes the configuration script
1324 to the standard output.
1326 The Autoconf macros are defined in several files. Some of the files are
1327 distributed with Autoconf; @command{autoconf} reads them first. Then it
1328 looks for the optional file @file{acsite.m4} in the directory that
1329 contains the distributed Autoconf macro files, and for the optional file
1330 @file{aclocal.m4} in the current directory. Those files can contain
1331 your site's or the package's own Autoconf macro definitions
1332 (@pxref{Writing Autoconf Macros}, for more information). If a macro is
1333 defined in more than one of the files that @command{autoconf} reads, the
1334 last definition it reads overrides the earlier ones.
1336 @command{autoconf} accepts the following options:
1341 Print a summary of the command line options and exit.
1345 Print the version number of Autoconf and exit.
1349 Report processing steps.
1353 Don't remove the temporary files.
1357 Remake @file{configure} even if newer than its input files.
1359 @item --include=@var{dir}
1361 Append @var{dir} to the include path. Multiple invocations accumulate.
1363 @item --prepend-include=@var{dir}
1365 Prepend @var{dir} to the include path. Multiple invocations accumulate.
1367 @item --output=@var{file}
1368 @itemx -o @var{file}
1369 Save output (script or trace) to @var{file}. The file @option{-} stands
1370 for the standard output.
1372 @item --warnings=@var{category}
1373 @itemx -W @var{category}
1375 Report the warnings related to @var{category} (which can actually be a
1376 comma separated list). @xref{Reporting Messages}, macro
1377 @code{AC_DIAGNOSE}, for a comprehensive list of categories. Special
1382 report all the warnings
1388 treats warnings as errors
1390 @item no-@var{category}
1391 disable warnings falling into @var{category}
1394 Warnings about @samp{syntax} are enabled by default, and the environment
1395 variable @env{WARNINGS}, a comma separated list of categories, is
1396 honored as well. Passing @samp{-W @var{category}} will actually behave as if
1397 you had passed @samp{--warnings=syntax,$WARNINGS,@var{category}}. If
1398 you want to disable the defaults and @env{WARNINGS}, but (for example)
1399 enable the warnings about obsolete constructs, you would use @option{-W
1403 @cindex Macro invocation stack
1404 Because @command{autoconf} uses @command{autom4te} behind the scenes, it
1405 displays a back trace for errors, but not for warnings; if you want
1406 them, just pass @option{-W error}. @xref{autom4te Invocation}, for some
1409 @item --trace=@var{macro}[:@var{format}]
1410 @itemx -t @var{macro}[:@var{format}]
1411 Do not create the @command{configure} script, but list the calls to
1412 @var{macro} according to the @var{format}. Multiple @option{--trace}
1413 arguments can be used to list several macros. Multiple @option{--trace}
1414 arguments for a single macro are not cumulative; instead, you should
1415 just make @var{format} as long as needed.
1417 The @var{format} is a regular string, with newlines if desired, and
1418 several special escape codes. It defaults to @samp{$f:$l:$n:$%}; see
1419 @ref{autom4te Invocation}, for details on the @var{format}.
1421 @item --initialization
1423 By default, @option{--trace} does not trace the initialization of the
1424 Autoconf macros (typically the @code{AC_DEFUN} definitions). This
1425 results in a noticeable speedup, but can be disabled by this option.
1429 It is often necessary to check the content of a @file{configure.ac}
1430 file, but parsing it yourself is extremely fragile and error-prone. It
1431 is suggested that you rely upon @option{--trace} to scan
1432 @file{configure.ac}. For instance, to find the list of variables that
1433 are substituted, use:
1437 $ @kbd{autoconf -t AC_SUBST}
1438 configure.ac:2:AC_SUBST:ECHO_C
1439 configure.ac:2:AC_SUBST:ECHO_N
1440 configure.ac:2:AC_SUBST:ECHO_T
1441 @i{More traces deleted}
1446 The example below highlights the difference between @samp{$@@},
1447 @samp{$*}, and @samp{$%}.
1451 $ @kbd{cat configure.ac}
1452 AC_DEFINE(This, is, [an
1454 $ @kbd{autoconf -t 'AC_DEFINE:@@: $@@}
1461 %: This:is:an [example]
1466 The @var{format} gives you a lot of freedom:
1470 $ @kbd{autoconf -t 'AC_SUBST:$$ac_subst@{"$1"@} = "$f:$l";'}
1471 $ac_subst@{"ECHO_C"@} = "configure.ac:2";
1472 $ac_subst@{"ECHO_N"@} = "configure.ac:2";
1473 $ac_subst@{"ECHO_T"@} = "configure.ac:2";
1474 @i{More traces deleted}
1479 A long @var{separator} can be used to improve the readability of complex
1480 structures, and to ease their parsing (for instance when no single
1481 character is suitable as a separator):
1485 $ @kbd{autoconf -t 'AM_MISSING_PROG:$@{|:::::|@}*'}
1486 ACLOCAL|:::::|aclocal|:::::|$missing_dir
1487 AUTOCONF|:::::|autoconf|:::::|$missing_dir
1488 AUTOMAKE|:::::|automake|:::::|$missing_dir
1489 @i{More traces deleted}
1493 @node autoreconf Invocation
1494 @section Using @command{autoreconf} to Update @command{configure} Scripts
1495 @cindex @command{autoreconf}
1497 Installing the various components of the @acronym{GNU} Build System can be
1498 tedious: running @command{autopoint} for Gettext, @command{automake} for
1499 @file{Makefile.in} etc.@: in each directory. It may be needed either
1500 because some tools such as @command{automake} have been updated on your
1501 system, or because some of the sources such as @file{configure.ac} have
1502 been updated, or finally, simply in order to install the @acronym{GNU} Build
1503 System in a fresh tree.
1505 @command{autoreconf} runs @command{autoconf}, @command{autoheader},
1506 @command{aclocal}, @command{automake}, @command{libtoolize}, and
1507 @command{autopoint} (when appropriate) repeatedly to update the
1508 @acronym{GNU} Build System in the specified directories and their
1509 subdirectories (@pxref{Subdirectories}). By default, it only remakes
1510 those files that are older than their sources.
1512 If you install a new version of some tool, you can make
1513 @command{autoreconf} remake @emph{all} of the files by giving it the
1514 @option{--force} option.
1516 @xref{Automatic Remaking}, for @file{Makefile} rules to automatically
1517 remake @command{configure} scripts when their source files change. That
1518 method handles the timestamps of configuration header templates
1519 properly, but does not pass @option{--autoconf-dir=@var{dir}} or
1520 @option{--localdir=@var{dir}}.
1523 @cindex @command{autopoint}
1524 Gettext supplies the @command{autopoint} command to add translation
1525 infrastructure to a source package. If you use @command{autopoint},
1526 your @file{configure.ac} should invoke both @code{AM_GNU_GETTEXT} and
1527 @code{AM_GNU_GETTEXT_VERSION(@var{gettext-version})}. @xref{autopoint
1528 Invocation, , Invoking the @code{autopoint} Program, gettext, GNU
1529 @code{gettext} utilities}, for further details.
1532 @command{autoreconf} accepts the following options:
1537 Print a summary of the command line options and exit.
1541 Print the version number of Autoconf and exit.
1544 Print the name of each directory @command{autoreconf} examines and the
1545 commands it runs. If given two or more times, pass @option{--verbose}
1546 to subordinate tools that support it.
1550 Don't remove the temporary files.
1554 Remake even @file{configure} scripts and configuration headers that are
1555 newer than their input files (@file{configure.ac} and, if present,
1560 Install the missing auxiliary files in the package. By default, files
1561 are copied; this can be changed with @option{--symlink}.
1563 If deemed appropriate, this option triggers calls to
1564 @samp{automake --add-missing},
1565 @samp{libtoolize}, @samp{autopoint}, etc.
1567 @item --no-recursive
1568 Do not rebuild files in subdirectories to configure (see @ref{Subdirectories},
1569 macro @code{AC_CONFIG_SUBDIRS}).
1573 When used with @option{--install}, install symbolic links to the missing
1574 auxiliary files instead of copying them.
1578 When the directories were configured, update the configuration by
1579 running @samp{./config.status --recheck && ./config.status}, and then
1582 @item --include=@var{dir}
1584 Append @var{dir} to the include path. Multiple invocations accumulate.
1585 Passed on to @command{autoconf} and @command{autoheader} internally.
1587 @item --prepend-include=@var{dir}
1589 Prepend @var{dir} to the include path. Multiple invocations accumulate.
1590 Passed on to @command{autoconf} and @command{autoheader} internally.
1592 @item --warnings=@var{category}
1593 @itemx -W @var{category}
1595 Report the warnings related to @var{category} (which can actually be a
1596 comma separated list).
1600 related to cross compilation issues.
1603 report the uses of obsolete constructs.
1609 dubious syntactic constructs.
1612 report all the warnings
1618 treats warnings as errors
1620 @item no-@var{category}
1621 disable warnings falling into @var{category}
1624 Warnings about @samp{syntax} are enabled by default, and the environment
1625 variable @env{WARNINGS}, a comma separated list of categories, is
1626 honored as well. Passing @samp{-W @var{category}} will actually behave as if
1627 you had passed @samp{--warnings=syntax,$WARNINGS,@var{category}}. If
1628 you want to disable the defaults and @env{WARNINGS}, but (for example)
1629 enable the warnings about obsolete constructs, you would use @option{-W
1633 If you want @command{autoreconf} to pass flags that are not listed here
1634 on to @command{aclocal}, set @code{ACLOCAL_AMFLAGS} in your Makefile.am.
1636 @c ========================================= Initialization and Output Files.
1639 @chapter Initialization and Output Files
1641 Autoconf-generated @command{configure} scripts need some information about
1642 how to initialize, such as how to find the package's source files and
1643 about the output files to produce. The following sections describe the
1644 initialization and the creation of output files.
1647 * Initializing configure:: Option processing etc.
1648 * Notices:: Copyright, version numbers in @command{configure}
1649 * Input:: Where Autoconf should find files
1650 * Output:: Outputting results from the configuration
1651 * Configuration Actions:: Preparing the output based on results
1652 * Configuration Files:: Creating output files
1653 * Makefile Substitutions:: Using output variables in @file{Makefile}s
1654 * Configuration Headers:: Creating a configuration header file
1655 * Configuration Commands:: Running arbitrary instantiation commands
1656 * Configuration Links:: Links depending on the configuration
1657 * Subdirectories:: Configuring independent packages together
1658 * Default Prefix:: Changing the default installation prefix
1661 @node Initializing configure
1662 @section Initializing @command{configure}
1664 Every @command{configure} script must call @code{AC_INIT} before doing
1665 anything else. The only other required macro is @code{AC_OUTPUT}
1668 @defmac AC_INIT (@var{package}, @var{version}, @ovar{bug-report}, @ovar{tarname})
1670 Process any command-line arguments and perform various initializations
1673 Set the name of the @var{package} and its @var{version}. These are
1674 typically used in @option{--version} support, including that of
1675 @command{configure}. The optional argument @var{bug-report} should be
1676 the email to which users should send bug reports. The package
1677 @var{tarname} differs from @var{package}: the latter designates the full
1678 package name (e.g., @samp{GNU Autoconf}), while the former is meant for
1679 distribution tar ball names (e.g., @samp{autoconf}). It defaults to
1680 @var{package} with @samp{GNU } stripped, lower-cased, and all characters
1681 other than alphanumerics and underscores are changed to @samp{-}.
1683 It is preferable that the arguments of @code{AC_INIT} be static, i.e.,
1684 there should not be any shell computation, but they can be computed by
1687 The following M4 macros (e.g., @code{AC_PACKAGE_NAME}), output variables
1688 (e.g., @code{PACKAGE_NAME}), and preprocessor symbols (e.g.,
1689 @code{PACKAGE_NAME}) are defined by @code{AC_INIT}:
1692 @item @code{AC_PACKAGE_NAME}, @code{PACKAGE_NAME}
1693 @acindex{PACKAGE_NAME}
1694 @ovindex PACKAGE_NAME
1695 @cvindex PACKAGE_NAME
1696 Exactly @var{package}.
1698 @item @code{AC_PACKAGE_TARNAME}, @code{PACKAGE_TARNAME}
1699 @acindex{PACKAGE_TARNAME}
1700 @ovindex PACKAGE_TARNAME
1701 @cvindex PACKAGE_TARNAME
1702 Exactly @var{tarname}.
1704 @item @code{AC_PACKAGE_VERSION}, @code{PACKAGE_VERSION}
1705 @acindex{PACKAGE_VERSION}
1706 @ovindex PACKAGE_VERSION
1707 @cvindex PACKAGE_VERSION
1708 Exactly @var{version}.
1710 @item @code{AC_PACKAGE_STRING}, @code{PACKAGE_STRING}
1711 @acindex{PACKAGE_STRING}
1712 @ovindex PACKAGE_STRING
1713 @cvindex PACKAGE_STRING
1714 Exactly @samp{@var{package} @var{version}}.
1716 @item @code{AC_PACKAGE_BUGREPORT}, @code{PACKAGE_BUGREPORT}
1717 @acindex{PACKAGE_BUGREPORT}
1718 @ovindex PACKAGE_BUGREPORT
1719 @cvindex PACKAGE_BUGREPORT
1720 Exactly @var{bug-report}.
1726 @section Notices in @command{configure}
1727 @cindex Notices in @command{configure}
1729 The following macros manage version numbers for @command{configure}
1730 scripts. Using them is optional.
1732 @c FIXME: AC_PREREQ should not be here
1733 @defmac AC_PREREQ (@var{version})
1736 Ensure that a recent enough version of Autoconf is being used. If the
1737 version of Autoconf being used to create @command{configure} is
1738 earlier than @var{version}, print an error message to the standard
1739 error output and exit with failure (exit status is 63). For example:
1742 AC_PREREQ([@value{VERSION}])
1745 This macro is the only macro that may be used before @code{AC_INIT}, but
1746 for consistency, you are invited not to do so.
1749 @defmac AC_COPYRIGHT (@var{copyright-notice})
1751 @cindex Copyright Notice
1752 State that, in addition to the Free Software Foundation's copyright on
1753 the Autoconf macros, parts of your @command{configure} are covered by the
1754 @var{copyright-notice}.
1756 The @var{copyright-notice} will show up in both the head of
1757 @command{configure} and in @samp{configure --version}.
1761 @defmac AC_REVISION (@var{revision-info})
1764 Copy revision stamp @var{revision-info} into the @command{configure}
1765 script, with any dollar signs or double-quotes removed. This macro lets
1766 you put a revision stamp from @file{configure.ac} into @command{configure}
1767 without @acronym{RCS} or @acronym{CVS} changing it when you check in
1768 @command{configure}. That way, you can determine easily which revision of
1769 @file{configure.ac} a particular @command{configure} corresponds to.
1771 For example, this line in @file{configure.ac}:
1773 @c The asis prevents RCS from changing the example in the manual.
1775 AC_REVISION([$@asis{Revision: 1.30 }$])
1779 produces this in @command{configure}:
1783 # From configure.ac Revision: 1.30
1789 @section Finding @command{configure} Input
1792 @defmac AC_CONFIG_SRCDIR (@var{unique-file-in-source-dir})
1793 @acindex{CONFIG_SRCDIR}
1794 @var{unique-file-in-source-dir} is some file that is in the package's
1795 source directory; @command{configure} checks for this file's existence to
1796 make sure that the directory that it is told contains the source code in
1797 fact does. Occasionally people accidentally specify the wrong directory
1798 with @option{--srcdir}; this is a safety check. @xref{configure
1799 Invocation}, for more information.
1803 @c FIXME: Remove definitively once --install explained.
1805 @c Small packages may store all their macros in @code{aclocal.m4}. As the
1806 @c set of macros grows, or for maintenance reasons, a maintainer may prefer
1807 @c to split the macros in several files. In this case, Autoconf must be
1808 @c told which files to load, and in which order.
1810 @c @defmac AC_INCLUDE (@var{file}@dots{})
1811 @c @acindex{INCLUDE}
1812 @c @c FIXME: There is no longer shell globbing.
1813 @c Read the macro definitions that appear in the listed files. A list of
1814 @c space-separated file names or shell globbing patterns is expected. The
1815 @c files will be read in the order they're listed.
1817 @c Because the order of definition of macros is important (only the last
1818 @c definition of a macro is used), beware that it is @code{AC_INIT} that
1819 @c loads @file{acsite.m4} and @file{aclocal.m4}. Note that
1820 @c @code{AC_INCLUDE}ing a file before @code{AC_INIT} or within
1821 @c @file{aclocal.m4} is different from doing so after @code{AC_INIT}: in
1822 @c the latter case, non-macro lines from included files may end up in the
1823 @c @file{configure} script, whereas in the former case, they'd be discarded
1824 @c just like any text that appear before @code{AC_INIT}.
1827 Packages that do manual configuration or use the @code{install} program
1828 might need to tell @command{configure} where to find some other shell
1829 scripts by calling @code{AC_CONFIG_AUX_DIR}, though the default places
1830 it looks are correct for most cases.
1832 @defmac AC_CONFIG_AUX_DIR (@var{dir})
1833 @acindex{CONFIG_AUX_DIR}
1834 Use the auxiliary build tools (e.g., @file{install-sh},
1835 @file{config.sub}, @file{config.guess}, Cygnus @command{configure},
1836 Automake and Libtool scripts, etc.)@: that are in directory @var{dir}.
1837 These are auxiliary files used in configuration. @var{dir} can be
1838 either absolute or relative to @file{@var{srcdir}}. The default is
1839 @file{@var{srcdir}} or @file{@var{srcdir}/..} or
1840 @file{@var{srcdir}/../..}, whichever is the first that contains
1841 @file{install-sh}. The other files are not checked for, so that using
1842 @code{AC_PROG_INSTALL} does not automatically require distributing the
1843 other auxiliary files. It checks for @file{install.sh} also, but that
1844 name is obsolete because some @code{make} have a rule that creates
1845 @file{install} from it if there is no @file{Makefile}.
1847 The auxiliary directory is commonly named @file{build-aux}.
1848 If you need portability to @acronym{DOS} variants, do not name the
1849 auxiliary directory @file{aux}. @xref{File System Conventions}.
1852 @defmac AC_REQUIRE_AUX_FILE (@var{file})
1853 @acindex{REQUIRE_AUX_FILE}
1854 Declares that @var{file} is expected in the directory defined above. In
1855 Autoconf proper, this macro does nothing: its sole purpose is to be
1856 traced by third-party tools to produce a list of expected auxiliary
1857 files. For instance it is called by macros like @code{AC_PROG_INSTALL}
1858 (@pxref{Particular Programs}) or @code{AC_CANONICAL_BUILD}
1859 (@pxref{Canonicalizing}) to register the auxiliary files they need.
1862 Similarly, packages that use @command{aclocal} should declare where
1863 local macros can be found using @code{AC_CONFIG_MACRO_DIR}.
1865 @defmac AC_CONFIG_MACRO_DIR (@var{dir})
1866 @acindex{CONFIG_MACRO_DIR}
1867 Future versions of @command{autopoint}, @command{libtoolize},
1868 @command{aclocal} and @command{autoreconf} will use directory
1869 @var{dir} as the location of additional local Autoconf macros. Be
1870 sure to call this macro directly from @file{configure.ac} so that
1871 tools that install macros for @command{aclocal} can find the
1872 declaration before @option{--trace} can be called safely.
1877 @section Outputting Files
1878 @cindex Outputting files
1880 Every Autoconf script, e.g., @file{configure.ac}, should finish by
1881 calling @code{AC_OUTPUT}. That is the macro that generates and runs
1882 @file{config.status}, which will create the @file{Makefile}s and any
1883 other files resulting from configuration. This is the only required
1884 macro besides @code{AC_INIT} (@pxref{Input}).
1888 @cindex Instantiation
1889 Generate @file{config.status} and launch it. Call this macro once, at
1890 the end of @file{configure.ac}.
1892 @file{config.status} will perform all the configuration actions: all the
1893 output files (see @ref{Configuration Files}, macro
1894 @code{AC_CONFIG_FILES}), header files (see @ref{Configuration Headers},
1895 macro @code{AC_CONFIG_HEADERS}), commands (see @ref{Configuration
1896 Commands}, macro @code{AC_CONFIG_COMMANDS}), links (see
1897 @ref{Configuration Links}, macro @code{AC_CONFIG_LINKS}), subdirectories
1898 to configure (see @ref{Subdirectories}, macro @code{AC_CONFIG_SUBDIRS})
1901 The location of your @code{AC_OUTPUT} invocation is the exact point
1902 where configuration actions are taken: any code afterwards will be
1903 executed by @code{configure} once @command{config.status} was run. If
1904 you want to bind actions to @command{config.status} itself
1905 (independently of whether @command{configure} is being run), see
1906 @ref{Configuration Commands, , Running Arbitrary Configuration
1910 Historically, the usage of @code{AC_OUTPUT} was somewhat different.
1911 @xref{Obsolete Macros}, for a description of the arguments that
1912 @code{AC_OUTPUT} used to support.
1915 If you run @command{make} in subdirectories, you should run it using the
1916 @code{make} variable @code{MAKE}. Most versions of @command{make} set
1917 @code{MAKE} to the name of the @command{make} program plus any options it
1918 was given. (But many do not include in it the values of any variables
1919 set on the command line, so those are not passed on automatically.)
1920 Some old versions of @command{make} do not set this variable. The
1921 following macro allows you to use it even with those versions.
1923 @defmac AC_PROG_MAKE_SET
1924 @acindex{PROG_MAKE_SET}
1926 If the Make command, @code{$MAKE} if set or else @samp{make}, predefines
1927 @code{$(MAKE)}, define output variable @code{SET_MAKE} to be empty.
1928 Otherwise, define @code{SET_MAKE} to a macro definition that sets
1929 @code{$(MAKE)}, such as @samp{MAKE=make}. Calls @code{AC_SUBST} for
1933 If you use this macro, place a line like this in each @file{Makefile.in}
1934 that runs @code{MAKE} on other directories:
1942 @node Configuration Actions
1943 @section Performing Configuration Actions
1944 @cindex Configuration actions
1946 @file{configure} is designed so that it appears to do everything itself,
1947 but there is actually a hidden slave: @file{config.status}.
1948 @file{configure} is in charge of examining your system, but it is
1949 @file{config.status} that actually takes the proper actions based on the
1950 results of @file{configure}. The most typical task of
1951 @file{config.status} is to @emph{instantiate} files.
1953 This section describes the common behavior of the four standard
1954 instantiating macros: @code{AC_CONFIG_FILES}, @code{AC_CONFIG_HEADERS},
1955 @code{AC_CONFIG_COMMANDS} and @code{AC_CONFIG_LINKS}. They all
1956 have this prototype:
1958 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
1961 AC_CONFIG_FOOS(@var{tag}@dots{}, [@var{commands}], [@var{init-cmds}])
1965 where the arguments are:
1968 @item @var{tag}@dots{}
1969 A blank-or-newline-separated list of tags, which are typically the names of
1970 the files to instantiate.
1972 You are encouraged to use literals as @var{tags}. In particular, you
1976 @dots{} && my_foos="$my_foos fooo"
1977 @dots{} && my_foos="$my_foos foooo"
1978 AC_CONFIG_FOOS([$my_foos])
1982 and use this instead:
1985 @dots{} && AC_CONFIG_FOOS([fooo])
1986 @dots{} && AC_CONFIG_FOOS([foooo])
1989 The macros @code{AC_CONFIG_FILES} and @code{AC_CONFIG_HEADERS} use
1990 special @var{tag}s: they may have the form @samp{@var{output}} or
1991 @samp{@var{output}:@var{inputs}}. The file @var{output} is instantiated
1992 from its templates, @var{inputs} (defaulting to @samp{@var{output}.in}).
1994 @samp{AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk)]},
1995 for example, asks for
1996 the creation of @file{Makefile} that will be the expansion of the
1997 output variables in the concatenation of @file{boiler/top.mk} and
1998 @file{boiler/bot.mk}.
2000 The special value @samp{-} might be used to denote the standard output
2001 when used in @var{output}, or the standard input when used in the
2002 @var{inputs}. You most probably don't need to use this in
2003 @file{configure.ac}, but it is convenient when using the command line
2004 interface of @file{./config.status}, see @ref{config.status Invocation},
2007 The @var{inputs} may be absolute or relative file names. In the latter
2008 case they are first looked for in the build tree, and then in the source
2012 Shell commands output literally into @file{config.status}, and
2013 associated with a tag that the user can use to tell @file{config.status}
2014 which the commands to run. The commands are run each time a @var{tag}
2015 request is given to @file{config.status}, typically each time the file
2016 @file{@var{tag}} is created.
2018 The variables set during the execution of @command{configure} are
2019 @emph{not} available here: you first need to set them via the
2020 @var{init-cmds}. Nonetheless the following variables are precomputed:
2024 The name of the top source directory, assuming that the working
2025 directory is the top build directory. This
2026 is what @command{configure}'s option @option{--srcdir} sets.
2029 The name of the top source directory, assuming that the working
2030 directory is the current build directory.
2033 @item ac_top_build_prefix
2034 The name of the top build directory, assuming that the working
2035 directory is the current build directory.
2036 It can be empty, or else ends with a slash, so that you may concatenate
2040 The name of the corresponding source directory, assuming that the
2041 working directory is the current build directory.
2045 The @dfn{current} directory refers to the directory (or
2046 pseudo-directory) containing the input part of @var{tags}. For
2050 AC_CONFIG_COMMANDS([deep/dir/out:in/in.in], [@dots{}], [@dots{}])
2054 with @option{--srcdir=../package} produces the following values:
2057 # Argument of --srcdir
2059 # Reversing deep/dir
2060 ac_top_build_prefix='../../'
2061 # Concatenation of $ac_top_build_prefix and srcdir
2062 ac_top_srcdir='../../../package'
2063 # Concatenation of $ac_top_srcdir and deep/dir
2064 ac_srcdir='../../../package/deep/dir'
2068 independently of @samp{in/in.in}.
2071 Shell commands output @emph{unquoted} near the beginning of
2072 @file{config.status}, and executed each time @file{config.status} runs
2073 (regardless of the tag). Because they are unquoted, for example,
2074 @samp{$var} will be output as the value of @code{var}. @var{init-cmds}
2075 is typically used by @file{configure} to give @file{config.status} some
2076 variables it needs to run the @var{commands}.
2078 You should be extremely cautious in your variable names: all the
2079 @var{init-cmds} share the same name space and may overwrite each other
2080 in unpredictable ways. Sorry@enddots{}
2083 All these macros can be called multiple times, with different
2084 @var{tag}s, of course!
2087 @node Configuration Files
2088 @section Creating Configuration Files
2089 @cindex Creating configuration files
2090 @cindex Configuration file creation
2092 Be sure to read the previous section, @ref{Configuration Actions}.
2094 @defmac AC_CONFIG_FILES (@var{file}@dots{}, @ovar{cmds}, @ovar{init-cmds})
2095 @acindex{CONFIG_FILES}
2096 Make @code{AC_OUTPUT} create each @file{@var{file}} by copying an input
2097 file (by default @file{@var{file}.in}), substituting the output variable
2099 @c Before we used to have this feature, which was later rejected
2100 @c because it complicates the write of Makefiles:
2101 @c If the file would be unchanged, it is left untouched, to preserve
2103 This macro is one of the instantiating macros; see @ref{Configuration
2104 Actions}. @xref{Makefile Substitutions}, for more information on using
2105 output variables. @xref{Setting Output Variables}, for more information
2106 on creating them. This macro creates the directory that the file is in
2107 if it doesn't exist. Usually, @file{Makefile}s are created this way,
2108 but other files, such as @file{.gdbinit}, can be specified as well.
2110 Typical calls to @code{AC_CONFIG_FILES} look like this:
2113 AC_CONFIG_FILES([Makefile src/Makefile man/Makefile X/Imakefile])
2114 AC_CONFIG_FILES([autoconf], [chmod +x autoconf])
2117 You can override an input file name by appending to @var{file} a
2118 colon-separated list of input files. Examples:
2121 AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk]
2122 [lib/Makefile:boiler/lib.mk])
2126 Doing this allows you to keep your file names acceptable to
2127 @acronym{DOS} variants, or
2128 to prepend and/or append boilerplate to the file.
2133 @node Makefile Substitutions
2134 @section Substitutions in Makefiles
2135 @cindex Substitutions in makefiles
2136 @cindex Makefile substitutions
2138 Each subdirectory in a distribution that contains something to be
2139 compiled or installed should come with a file @file{Makefile.in}, from
2140 which @command{configure} will create a @file{Makefile} in that directory.
2141 To create a @file{Makefile}, @command{configure} performs a simple variable
2142 substitution, replacing occurrences of @samp{@@@var{variable}@@} in
2143 @file{Makefile.in} with the value that @command{configure} has determined
2144 for that variable. Variables that are substituted into output files in
2145 this way are called @dfn{output variables}. They are ordinary shell
2146 variables that are set in @command{configure}. To make @command{configure}
2147 substitute a particular variable into the output files, the macro
2148 @code{AC_SUBST} must be called with that variable name as an argument.
2149 Any occurrences of @samp{@@@var{variable}@@} for other variables are
2150 left unchanged. @xref{Setting Output Variables}, for more information
2151 on creating output variables with @code{AC_SUBST}.
2153 A software package that uses a @command{configure} script should be
2154 distributed with a file @file{Makefile.in}, but no @file{Makefile}; that
2155 way, the user has to properly configure the package for the local system
2156 before compiling it.
2158 @xref{Makefile Conventions, , Makefile Conventions, standards, The
2159 @acronym{GNU} Coding Standards}, for more information on what to put in
2163 * Preset Output Variables:: Output variables that are always set
2164 * Installation Directory Variables:: Other preset output variables
2165 * Build Directories:: Supporting multiple concurrent compiles
2166 * Automatic Remaking:: Makefile rules for configuring
2169 @node Preset Output Variables
2170 @subsection Preset Output Variables
2171 @cindex Output variables
2173 Some output variables are preset by the Autoconf macros. Some of the
2174 Autoconf macros set additional output variables, which are mentioned in
2175 the descriptions for those macros. @xref{Output Variable Index}, for a
2176 complete list of output variables. @xref{Installation Directory
2177 Variables}, for the list of the preset ones related to installation
2178 directories. Below are listed the other preset ones. They all are
2179 precious variables (@pxref{Setting Output Variables},
2182 @c Just say no to ASCII sorting! We're humans, not computers.
2183 @c These variables are listed as they would be in a dictionary:
2190 Debugging and optimization options for the C compiler. If it is not set
2191 in the environment when @command{configure} runs, the default value is set
2192 when you call @code{AC_PROG_CC} (or empty if you don't). @command{configure}
2193 uses this variable when compiling programs to test for C features.
2196 @defvar configure_input
2197 @ovindex configure_input
2198 A comment saying that the file was generated automatically by
2199 @command{configure} and giving the name of the input file.
2200 @code{AC_OUTPUT} adds a comment line containing this variable to the top
2201 of every @file{Makefile} it creates. For other files, you should
2202 reference this variable in a comment at the top of each input file. For
2203 example, an input shell script should begin like this:
2207 # @@configure_input@@
2211 The presence of that line also reminds people editing the file that it
2212 needs to be processed by @command{configure} in order to be used.
2217 Header file search directory (@option{-I@var{dir}}) and any other
2218 miscellaneous options for the C and C++ preprocessors and compilers. If
2219 it is not set in the environment when @command{configure} runs, the default
2220 value is empty. @command{configure} uses this variable when compiling or
2221 preprocessing programs to test for C and C++ features.
2226 Debugging and optimization options for the C++ compiler. If it is not
2227 set in the environment when @command{configure} runs, the default value is
2228 set when you call @code{AC_PROG_CXX} (or empty if you don't).
2229 @command{configure} uses this variable when compiling programs to test for
2235 @option{-D} options to pass to the C compiler. If @code{AC_CONFIG_HEADERS}
2236 is called, @command{configure} replaces @samp{@@DEFS@@} with
2237 @option{-DHAVE_CONFIG_H} instead (@pxref{Configuration Headers}). This
2238 variable is not defined while @command{configure} is performing its tests,
2239 only when creating the output files. @xref{Setting Output Variables}, for
2240 how to check the results of previous tests.
2249 How does one suppress the trailing newline from @command{echo} for
2250 question-answer message pairs? These variables provide a way:
2253 echo $ECHO_N "And the winner is... $ECHO_C"
2255 echo "$@{ECHO_T@}dead."
2259 Some old and uncommon @command{echo} implementations offer no means to
2260 achieve this, in which case @code{ECHO_T} is set to tab. You might not
2266 Debugging and optimization options for the Erlang compiler. If it is not set
2267 in the environment when @command{configure} runs, the default value is empty.
2268 @command{configure} uses this variable when compiling programs to test for
2274 Debugging and optimization options for the Fortran compiler. If it
2275 is not set in the environment when @command{configure} runs, the default
2276 value is set when you call @code{AC_PROG_FC} (or empty if you don't).
2277 @command{configure} uses this variable when compiling programs to test for
2283 Debugging and optimization options for the Fortran 77 compiler. If it
2284 is not set in the environment when @command{configure} runs, the default
2285 value is set when you call @code{AC_PROG_F77} (or empty if you don't).
2286 @command{configure} uses this variable when compiling programs to test for
2287 Fortran 77 features.
2292 Stripping (@option{-s}), path (@option{-L}), and any other miscellaneous
2293 options for the linker. Don't use this variable to pass library names
2294 (@option{-l}) to the linker, use @code{LIBS} instead. If it is not set
2295 in the environment when @command{configure} runs, the default value is empty.
2296 @command{configure} uses this variable when linking programs to test for
2297 C, C++, and Fortran features.
2302 @option{-l} options to pass to the linker. The default value is empty,
2303 but some Autoconf macros may prepend extra libraries to this variable if
2304 those libraries are found and provide necessary functions, see
2305 @ref{Libraries}. @command{configure} uses this variable when linking
2306 programs to test for C, C++, and Fortran features.
2311 Debugging and optimization options for the Objective C compiler. If it is
2312 not set in the environment when @command{configure} runs, the default value
2313 is set when you call @code{AC_PROG_OBJC} (or empty if you don't).
2314 @command{configure} uses this variable when compiling programs to test for
2315 Objective C features.
2320 Rigorously equal to @samp{.}. Added for symmetry only.
2323 @defvar abs_builddir
2324 @ovindex abs_builddir
2325 Absolute name of @code{builddir}.
2328 @defvar top_builddir
2329 @ovindex top_builddir
2330 The relative name of the top level of the current build tree. In the
2331 top-level directory, this is the same as @code{builddir}.
2334 @defvar abs_top_builddir
2335 @ovindex abs_top_builddir
2336 Absolute name of @code{top_builddir}.
2341 The relative name of the directory that contains the source code for
2342 that @file{Makefile}.
2347 Absolute name of @code{srcdir}.
2352 The relative name of the top-level source code directory for the
2353 package. In the top-level directory, this is the same as @code{srcdir}.
2356 @defvar abs_top_srcdir
2357 @ovindex abs_top_srcdir
2358 Absolute name of @code{top_srcdir}.
2361 @node Installation Directory Variables
2362 @subsection Installation Directory Variables
2363 @cindex Installation directories
2364 @cindex Directories, installation
2366 The following variables specify the directories where the package will
2367 be installed, see @ref{Directory Variables, , Variables for
2368 Installation Directories, standards, The @acronym{GNU} Coding
2369 Standards}, for more information. See the end of this section for
2370 details on when and how to use these variables.
2374 The directory for installing executables that users run.
2379 The directory for installing idiosyncratic read-only
2380 architecture-independent data.
2384 @ovindex datarootdir
2385 The root of the directory tree for read-only architecture-independent
2391 The directory for installing documentation files (other than Info and
2397 The directory for installing documentation files in DVI format.
2401 @ovindex exec_prefix
2402 The installation prefix for architecture-dependent files. By default
2403 it's the same as @var{prefix}. You should avoid installing anything
2404 directly to @var{exec_prefix}. However, the default value for
2405 directories containing architecture-dependent files should be relative
2406 to @var{exec_prefix}.
2411 The directory for installing HTML documentation.
2416 The directory for installing C header files.
2421 The directory for installing documentation in Info format.
2426 The directory for installing object code libraries.
2431 The directory for installing executables that other programs run.
2436 The directory for installing locale-dependent but
2437 architecture-independent data, such as message catalogs. This directory
2438 usually has a subdirectory per locale.
2441 @defvar localstatedir
2442 @ovindex localstatedir
2443 The directory for installing modifiable single-machine data.
2448 The top-level directory for installing documentation in man format.
2451 @defvar oldincludedir
2452 @ovindex oldincludedir
2453 The directory for installing C header files for non-GCC compilers.
2458 The directory for installing PDF documentation.
2463 The common installation prefix for all files. If @var{exec_prefix}
2464 is defined to a different value, @var{prefix} is used only for
2465 architecture-independent files.
2470 The directory for installing PostScript documentation.
2475 The directory for installing executables that system
2479 @defvar sharedstatedir
2480 @ovindex sharedstatedir
2481 The directory for installing modifiable architecture-independent data.
2486 The directory for installing read-only single-machine data.
2490 Most of these variables have values that rely on @code{prefix} or
2491 @code{exec_prefix}. It is deliberate that the directory output
2492 variables keep them unexpanded: typically @samp{@@datarootdir@@} will be
2493 replaced by @samp{$@{prefix@}/share}, not @samp{/usr/local/share}, and
2494 @samp{@@datadir@@} will be replaced by @samp{$@{datarootdir@}}.
2496 This behavior is mandated by the @acronym{GNU} coding standards, so that when
2501 she can still specify a different prefix from the one specified to
2502 @command{configure}, in which case, if needed, the package shall hard
2503 code dependencies corresponding to the make-specified prefix.
2506 she can specify a different installation location, in which case the
2507 package @emph{must} still depend on the location which was compiled in
2508 (i.e., never recompile when @samp{make install} is run). This is an
2509 extremely important feature, as many people may decide to install all
2510 the files of a package grouped together, and then install links from
2511 the final locations to there.
2514 In order to support these features, it is essential that
2515 @code{datarootdir} remains being defined as @samp{$@{prefix@}/share} to
2516 depend upon the current value of @code{prefix}.
2518 A corollary is that you should not use these variables except in
2519 Makefiles. For instance, instead of trying to evaluate @code{datadir}
2520 in @file{configure} and hard-coding it in Makefiles using
2521 e.g., @samp{AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])},
2523 @samp{-DDATADIR="$(datadir)"} to your @code{CPPFLAGS}.
2525 Similarly, you should not rely on @code{AC_CONFIG_FILES} to replace
2526 @code{datadir} and friends in your shell scripts and other files, rather
2527 let @command{make} manage their replacement. For instance Autoconf
2528 ships templates of its shell scripts ending with @samp{.in}, and uses a
2529 Makefile snippet similar to:
2534 -e 's|@@datadir[@@]|$(pkgdatadir)|g' \
2535 -e 's|@@prefix[@@]|$(prefix)|g'
2539 autoconf: Makefile $(srcdir)/autoconf.in
2540 rm -f autoconf autoconf.tmp
2541 $(edit) $(srcdir)/autoconf.in >autoconf.tmp
2542 chmod +x autoconf.tmp
2543 mv autoconf.tmp autoconf
2547 autoheader: Makefile $(srcdir)/autoheader.in
2548 rm -f autoheader autoheader.tmp
2549 $(edit) $(srcdir)/autoconf.in >autoheader.tmp
2550 chmod +x autoheader.tmp
2551 mv autoheader.tmp autoheader
2555 Some details are noteworthy:
2559 The brackets prevent @command{configure} from replacing
2560 @samp{@@datadir@@} in the Sed expression itself.
2561 Brackets are preferable to a backslash here, since
2562 Posix says @samp{\@@} is not portable.
2565 Don't use @samp{@@pkgdatadir@@}! Use the matching makefile variable
2569 Don't use @samp{/} in the Sed expression(s) since most likely the
2570 variables you use, such as @samp{$(pkgdatadir)}, will contain
2573 @item Dependency on @file{Makefile}
2574 Since @code{edit} uses values that depend on the configuration specific
2575 values (@code{prefix}, etc.)@: and not only on @code{VERSION} and so forth,
2576 the output depends on @file{Makefile}, not @file{configure.ac}.
2578 @item Separated dependencies and Single Suffix Rules
2579 You can't use them! The above snippet cannot be (portably) rewritten
2583 autoconf autoheader: Makefile
2593 @xref{Limitations of Make}, for details.
2595 @item @samp{$(srcdir)}
2596 Be sure to specify the name of the source directory,
2597 otherwise the package won't support separated builds.
2600 For the more specific installation of Erlang libraries, the following variables
2603 @defvar ERLANG_INSTALL_LIB_DIR
2604 @ovindex ERLANG_INSTALL_LIB_DIR
2605 @acindex{ERLANG_SUBST_INSTALL_LIB_DIR}
2606 The common parent directory of Erlang library installation directories.
2607 This variable is set by calling the @code{AC_ERLANG_SUBST_INSTALL_LIB_DIR}
2608 macro in @file{configure.ac}.
2611 @defvar ERLANG_INSTALL_LIB_DIR_@var{library}
2612 @ovindex ERLANG_INSTALL_LIB_DIR_@var{library}
2613 @acindex{ERLANG_SUBST_INSTALL_LIB_SUBDIR}
2614 The installation directory for Erlang library @var{library}.
2615 This variable is set by calling the
2616 @samp{AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(@var{library}, @var{version}}
2617 macro in @file{configure.ac}.
2620 @xref{Erlang Libraries}, for details.
2623 @node Build Directories
2624 @subsection Build Directories
2625 @cindex Build directories
2626 @cindex Directories, build
2628 You can support compiling a software package for several architectures
2629 simultaneously from the same copy of the source code. The object files
2630 for each architecture are kept in their own directory.
2632 To support doing this, @command{make} uses the @code{VPATH} variable to
2633 find the files that are in the source directory. @acronym{GNU} Make
2634 and most other recent @command{make} programs can do this. Older
2635 @command{make} programs do not support @code{VPATH}; when using them, the
2636 source code must be in the same directory as the object files.
2638 To support @code{VPATH}, each @file{Makefile.in} should contain two
2639 lines that look like:
2646 Do not set @code{VPATH} to the value of another variable, for example
2647 @samp{VPATH = $(srcdir)}, because some versions of @command{make} do not do
2648 variable substitutions on the value of @code{VPATH}.
2650 @command{configure} substitutes the correct value for @code{srcdir} when
2651 it produces @file{Makefile}.
2653 Do not use the @code{make} variable @code{$<}, which expands to the
2654 file name of the file in the source directory (found with @code{VPATH}),
2655 except in implicit rules. (An implicit rule is one such as @samp{.c.o},
2656 which tells how to create a @file{.o} file from a @file{.c} file.) Some
2657 versions of @command{make} do not set @code{$<} in explicit rules; they
2658 expand it to an empty value.
2660 Instead, @file{Makefile} command lines should always refer to source
2661 files by prefixing them with @samp{$(srcdir)/}. For example:
2664 time.info: time.texinfo
2665 $(MAKEINFO) $(srcdir)/time.texinfo
2668 @node Automatic Remaking
2669 @subsection Automatic Remaking
2670 @cindex Automatic remaking
2671 @cindex Remaking automatically
2673 You can put rules like the following in the top-level @file{Makefile.in}
2674 for a package to automatically update the configuration information when
2675 you change the configuration files. This example includes all of the
2676 optional files, such as @file{aclocal.m4} and those related to
2677 configuration header files. Omit from the @file{Makefile.in} rules for
2678 any of these files that your package does not use.
2680 The @samp{$(srcdir)/} prefix is included because of limitations in the
2681 @code{VPATH} mechanism.
2683 The @file{stamp-} files are necessary because the timestamps of
2684 @file{config.h.in} and @file{config.h} will not be changed if remaking
2685 them does not change their contents. This feature avoids unnecessary
2686 recompilation. You should include the file @file{stamp-h.in} your
2687 package's distribution, so @command{make} will consider
2688 @file{config.h.in} up to date. Don't use @command{touch}
2689 (@pxref{Limitations of Usual Tools}), rather use @command{echo} (using
2690 @command{date} would cause needless differences, hence @acronym{CVS}
2695 $(srcdir)/configure: configure.ac aclocal.m4
2696 cd $(srcdir) && autoconf
2698 # autoheader might not change config.h.in, so touch a stamp file.
2699 $(srcdir)/config.h.in: stamp-h.in
2700 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
2701 cd $(srcdir) && autoheader
2702 echo timestamp > $(srcdir)/stamp-h.in
2705 stamp-h: config.h.in config.status
2708 Makefile: Makefile.in config.status
2711 config.status: configure
2712 ./config.status --recheck
2717 (Be careful if you copy these lines directly into your Makefile, as you
2718 will need to convert the indented lines to start with the tab character.)
2720 In addition, you should use
2723 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
2727 so @file{config.status} will ensure that @file{config.h} is considered up to
2728 date. @xref{Output}, for more information about @code{AC_OUTPUT}.
2730 @xref{config.status Invocation}, for more examples of handling
2731 configuration-related dependencies.
2733 @node Configuration Headers
2734 @section Configuration Header Files
2735 @cindex Configuration Header
2736 @cindex @file{config.h}
2738 When a package contains more than a few tests that define C preprocessor
2739 symbols, the command lines to pass @option{-D} options to the compiler
2740 can get quite long. This causes two problems. One is that the
2741 @command{make} output is hard to visually scan for errors. More
2742 seriously, the command lines can exceed the length limits of some
2743 operating systems. As an alternative to passing @option{-D} options to
2744 the compiler, @command{configure} scripts can create a C header file
2745 containing @samp{#define} directives. The @code{AC_CONFIG_HEADERS}
2746 macro selects this kind of output. Though it can be called anywhere
2747 between @code{AC_INIT} and @code{AC_OUTPUT}, it is customary to call
2748 it right after @code{AC_INIT}.
2750 The package should @samp{#include} the configuration header file before
2751 any other header files, to prevent inconsistencies in declarations (for
2752 example, if it redefines @code{const}).
2754 To provide for VPATH builds, remember to pass the C compiler a @option{-I.}
2755 option (or @option{-I..}; whichever directory contains @file{config.h}).
2756 Even if you use @samp{#include "config.h"}, the preprocessor searches only
2757 the directory of the currently read file, i.e., the source directory, not
2758 the build directory.
2760 With the appropriate @option{-I} option, you can use
2761 @samp{#include <config.h>}. Actually, it's a good habit to use it,
2762 because in the rare case when the source directory contains another
2763 @file{config.h}, the build directory should be searched first.
2766 @defmac AC_CONFIG_HEADERS (@var{header} @dots{}, @ovar{cmds}, @ovar{init-cmds})
2767 @acindex{CONFIG_HEADERS}
2768 @cvindex HAVE_CONFIG_H
2769 This macro is one of the instantiating macros; see @ref{Configuration
2770 Actions}. Make @code{AC_OUTPUT} create the file(s) in the
2771 blank-or-newline-separated list @var{header} containing C preprocessor
2772 @code{#define} statements, and replace @samp{@@DEFS@@} in generated
2773 files with @option{-DHAVE_CONFIG_H} instead of the value of @code{DEFS}.
2774 The usual name for @var{header} is @file{config.h}.
2776 If @var{header} already exists and its contents are identical to what
2777 @code{AC_OUTPUT} would put in it, it is left alone. Doing this allows
2778 making some changes in the configuration without needlessly causing
2779 object files that depend on the header file to be recompiled.
2781 Usually the input file is named @file{@var{header}.in}; however, you can
2782 override the input file name by appending to @var{header} a
2783 colon-separated list of input files. Examples:
2786 AC_CONFIG_HEADERS([config.h:config.hin])
2787 AC_CONFIG_HEADERS([defines.h:defs.pre:defines.h.in:defs.post])
2791 Doing this allows you to keep your file names acceptable to
2792 @acronym{DOS} variants, or
2793 to prepend and/or append boilerplate to the file.
2798 This macro is defined as the name of the first declared config header
2799 and undefined if no config headers have been declared up to this point.
2800 A third-party macro may, for example, require use of a config header
2801 without invoking AC_CONFIG_HEADERS twice, like this:
2804 AC_CONFIG_COMMANDS_PRE(
2805 [m4_ifndef([AH_HEADER], [AC_CONFIG_HEADERS([config.h])])])
2810 @xref{Configuration Actions}, for more details on @var{header}.
2813 * Header Templates:: Input for the configuration headers
2814 * autoheader Invocation:: How to create configuration templates
2815 * Autoheader Macros:: How to specify CPP templates
2818 @node Header Templates
2819 @subsection Configuration Header Templates
2820 @cindex Configuration Header Template
2821 @cindex Header templates
2822 @cindex @file{config.h.in}
2824 Your distribution should contain a template file that looks as you want
2825 the final header file to look, including comments, with @code{#undef}
2826 statements which are used as hooks. For example, suppose your
2827 @file{configure.ac} makes these calls:
2830 AC_CONFIG_HEADERS([conf.h])
2831 AC_CHECK_HEADERS([unistd.h])
2835 Then you could have code like the following in @file{conf.h.in}. On
2836 systems that have @file{unistd.h}, @command{configure} will @samp{#define}
2837 @samp{HAVE_UNISTD_H} to 1. On other systems, the whole line will be
2838 commented out (in case the system predefines that symbol).
2842 /* Define as 1 if you have unistd.h. */
2843 #undef HAVE_UNISTD_H
2847 Pay attention that @samp{#undef} is in the first column, and there is
2848 nothing after @samp{HAVE_UNISTD_H}, not even white space. You can
2849 then decode the configuration header using the preprocessor directives:
2856 # include <unistd.h>
2858 /* We are in trouble. */
2863 The use of old form templates, with @samp{#define} instead of
2864 @samp{#undef} is strongly discouraged. Similarly with old templates
2865 with comments on the same line as the @samp{#undef}. Anyway, putting
2866 comments in preprocessor macros has never been a good idea.
2868 Since it is a tedious task to keep a template header up to date, you may
2869 use @command{autoheader} to generate it, see @ref{autoheader Invocation}.
2872 @node autoheader Invocation
2873 @subsection Using @command{autoheader} to Create @file{config.h.in}
2874 @cindex @command{autoheader}
2876 The @command{autoheader} program can create a template file of C
2877 @samp{#define} statements for @command{configure} to use. If
2878 @file{configure.ac} invokes @code{AC_CONFIG_HEADERS(@var{file})},
2879 @command{autoheader} creates @file{@var{file}.in}; if multiple file
2880 arguments are given, the first one is used. Otherwise,
2881 @command{autoheader} creates @file{config.h.in}.
2883 In order to do its job, @command{autoheader} needs you to document all
2884 of the symbols that you might use; i.e., there must be at least one
2885 @code{AC_DEFINE} or one @code{AC_DEFINE_UNQUOTED} call with a third
2886 argument for each symbol (@pxref{Defining Symbols}). An additional
2887 constraint is that the first argument of @code{AC_DEFINE} must be a
2888 literal. Note that all symbols defined by Autoconf's builtin tests are
2889 already documented properly; you only need to document those that you
2892 You might wonder why @command{autoheader} is needed: after all, why
2893 would @command{configure} need to ``patch'' a @file{config.h.in} to
2894 produce a @file{config.h} instead of just creating @file{config.h} from
2895 scratch? Well, when everything rocks, the answer is just that we are
2896 wasting our time maintaining @command{autoheader}: generating
2897 @file{config.h} directly is all that is needed. When things go wrong,
2898 however, you'll be thankful for the existence of @command{autoheader}.
2900 The fact that the symbols are documented is important in order to
2901 @emph{check} that @file{config.h} makes sense. The fact that there is a
2902 well-defined list of symbols that should be @code{#define}'d (or not) is
2903 also important for people who are porting packages to environments where
2904 @command{configure} cannot be run: they just have to @emph{fill in the
2907 But let's come back to the point: @command{autoheader}'s invocation@dots{}
2909 If you give @command{autoheader} an argument, it uses that file instead
2910 of @file{configure.ac} and writes the header file to the standard output
2911 instead of to @file{config.h.in}. If you give @command{autoheader} an
2912 argument of @option{-}, it reads the standard input instead of
2913 @file{configure.ac} and writes the header file to the standard output.
2915 @command{autoheader} accepts the following options:
2920 Print a summary of the command line options and exit.
2924 Print the version number of Autoconf and exit.
2928 Report processing steps.
2932 Don't remove the temporary files.
2936 Remake the template file even if newer than its input files.
2938 @item --include=@var{dir}
2940 Append @var{dir} to the include path. Multiple invocations accumulate.
2942 @item --prepend-include=@var{dir}
2944 Prepend @var{dir} to the include path. Multiple invocations accumulate.
2946 @item --warnings=@var{category}
2947 @itemx -W @var{category}
2949 Report the warnings related to @var{category} (which can actually be a
2950 comma separated list). Current categories include:
2954 report the uses of obsolete constructs
2957 report all the warnings
2963 treats warnings as errors
2965 @item no-@var{category}
2966 disable warnings falling into @var{category}
2973 @node Autoheader Macros
2974 @subsection Autoheader Macros
2975 @cindex Autoheader macros
2977 @command{autoheader} scans @file{configure.ac} and figures out which C
2978 preprocessor symbols it might define. It knows how to generate
2979 templates for symbols defined by @code{AC_CHECK_HEADERS},
2980 @code{AC_CHECK_FUNCS} etc., but if you @code{AC_DEFINE} any additional
2981 symbol, you must define a template for it. If there are missing
2982 templates, @command{autoheader} fails with an error message.
2984 The simplest way to create a template for a @var{symbol} is to supply
2985 the @var{description} argument to an @samp{AC_DEFINE(@var{symbol})}; see
2986 @ref{Defining Symbols}. You may also use one of the following macros.
2988 @defmac AH_VERBATIM (@var{key}, @var{template})
2990 Tell @command{autoheader} to include the @var{template} as-is in the header
2991 template file. This @var{template} is associated with the @var{key},
2992 which is used to sort all the different templates and guarantee their
2993 uniqueness. It should be a symbol that can be @code{AC_DEFINE}'d.
2998 AH_VERBATIM([_GNU_SOURCE],
2999 [/* Enable GNU extensions on systems that have them. */
3001 # define _GNU_SOURCE
3007 @defmac AH_TEMPLATE (@var{key}, @var{description})
3009 Tell @command{autoheader} to generate a template for @var{key}. This macro
3010 generates standard templates just like @code{AC_DEFINE} when a
3011 @var{description} is given.
3016 AH_TEMPLATE([CRAY_STACKSEG_END],
3017 [Define to one of _getb67, GETB67, getb67
3018 for Cray-2 and Cray-YMP systems. This
3019 function is required for alloca.c support
3024 will generate the following template, with the description properly
3028 /* Define to one of _getb67, GETB67, getb67 for Cray-2 and
3029 Cray-YMP systems. This function is required for alloca.c
3030 support on those systems. */
3031 #undef CRAY_STACKSEG_END
3036 @defmac AH_TOP (@var{text})
3038 Include @var{text} at the top of the header template file.
3042 @defmac AH_BOTTOM (@var{text})
3044 Include @var{text} at the bottom of the header template file.
3048 @node Configuration Commands
3049 @section Running Arbitrary Configuration Commands
3050 @cindex Configuration commands
3051 @cindex Commands for configuration
3053 You can execute arbitrary commands before, during, and after
3054 @file{config.status} is run. The three following macros accumulate the
3055 commands to run when they are called multiple times.
3056 @code{AC_CONFIG_COMMANDS} replaces the obsolete macro
3057 @code{AC_OUTPUT_COMMANDS}; see @ref{Obsolete Macros}, for details.
3059 @defmac AC_CONFIG_COMMANDS (@var{tag}@dots{}, @ovar{cmds}, @ovar{init-cmds})
3060 @acindex{CONFIG_COMMANDS}
3061 Specify additional shell commands to run at the end of
3062 @file{config.status}, and shell commands to initialize any variables
3063 from @command{configure}. Associate the commands with @var{tag}.
3064 Since typically the @var{cmds} create a file, @var{tag} should
3065 naturally be the name of that file. If needed, the directory hosting
3066 @var{tag} is created. This macro is one of the instantiating macros;
3067 see @ref{Configuration Actions}.
3069 Here is an unrealistic example:
3072 AC_CONFIG_COMMANDS([fubar],
3073 [echo this is extra $fubar, and so on.],
3077 Here is a better one:
3079 AC_CONFIG_COMMANDS([time-stamp], [date >time-stamp])
3083 The following two macros look similar, but in fact they are not of the same
3084 breed: they are executed directly by @file{configure}, so you cannot use
3085 @file{config.status} to re-run them.
3087 @c Yet it is good to leave them here. The user sees them together and
3088 @c decides which best fits their needs.
3090 @defmac AC_CONFIG_COMMANDS_PRE (@var{cmds})
3091 @acindex{CONFIG_COMMANDS_PRE}
3092 Execute the @var{cmds} right before creating @file{config.status}.
3094 This macro presents the last opportunity to call @code{AC_SUBST},
3095 @code{AC_DEFINE}, or @code{AC_CONFIG_FOOS} macros.
3098 @defmac AC_CONFIG_COMMANDS_POST (@var{cmds})
3099 @acindex{CONFIG_COMMANDS_POST}
3100 Execute the @var{cmds} right after creating @file{config.status}.
3106 @node Configuration Links
3107 @section Creating Configuration Links
3108 @cindex Configuration links
3109 @cindex Links for configuration
3111 You may find it convenient to create links whose destinations depend upon
3112 results of tests. One can use @code{AC_CONFIG_COMMANDS} but the
3113 creation of relative symbolic links can be delicate when the package is
3114 built in a directory different from the source directory.
3116 @defmac AC_CONFIG_LINKS (@var{dest}:@var{source}@dots{}, @ovar{cmds}, @ovar{init-cmds})
3117 @acindex{CONFIG_LINKS}
3119 Make @code{AC_OUTPUT} link each of the existing files @var{source} to
3120 the corresponding link name @var{dest}. Makes a symbolic link if
3121 possible, otherwise a hard link if possible, otherwise a copy. The
3122 @var{dest} and @var{source} names should be relative to the top level
3123 source or build directory. This macro is one of the instantiating
3124 macros; see @ref{Configuration Actions}.
3126 For example, this call:
3129 AC_CONFIG_LINKS([host.h:config/$machine.h
3130 object.h:config/$obj_format.h])
3134 creates in the current directory @file{host.h} as a link to
3135 @file{@var{srcdir}/config/$machine.h}, and @file{object.h} as a
3136 link to @file{@var{srcdir}/config/$obj_format.h}.
3138 The tempting value @samp{.} for @var{dest} is invalid: it makes it
3139 impossible for @samp{config.status} to guess the links to establish.
3143 ./config.status host.h object.h
3146 to create the links.
3151 @node Subdirectories
3152 @section Configuring Other Packages in Subdirectories
3153 @cindex Configure subdirectories
3154 @cindex Subdirectory configure
3156 In most situations, calling @code{AC_OUTPUT} is sufficient to produce
3157 @file{Makefile}s in subdirectories. However, @command{configure} scripts
3158 that control more than one independent package can use
3159 @code{AC_CONFIG_SUBDIRS} to run @command{configure} scripts for other
3160 packages in subdirectories.
3162 @defmac AC_CONFIG_SUBDIRS (@var{dir} @dots{})
3163 @acindex{CONFIG_SUBDIRS}
3165 Make @code{AC_OUTPUT} run @command{configure} in each subdirectory
3166 @var{dir} in the given blank-or-newline-separated list. Each @var{dir} should
3167 be a literal, i.e., please do not use:
3170 if test "$package_foo_enabled" = yes; then
3171 $my_subdirs="$my_subdirs foo"
3173 AC_CONFIG_SUBDIRS([$my_subdirs])
3177 because this prevents @samp{./configure --help=recursive} from
3178 displaying the options of the package @code{foo}. Rather, you should
3182 if test "$package_foo_enabled" = yes; then
3183 AC_CONFIG_SUBDIRS([foo])
3187 If a given @var{dir} is not found, an error is reported: if the
3188 subdirectory is optional, write:
3191 if test -d $srcdir/foo; then
3192 AC_CONFIG_SUBDIRS([foo])
3196 @c NB: Yes, below we mean configure.in, not configure.ac.
3197 If a given @var{dir} contains @command{configure.gnu}, it is run instead
3198 of @command{configure}. This is for packages that might use a
3199 non-Autoconf script @command{Configure}, which can't be called through a
3200 wrapper @command{configure} since it would be the same file on
3201 case-insensitive file systems. Likewise, if a @var{dir} contains
3202 @file{configure.in} but no @command{configure}, the Cygnus
3203 @command{configure} script found by @code{AC_CONFIG_AUX_DIR} is used.
3205 The subdirectory @command{configure} scripts are given the same command
3206 line options that were given to this @command{configure} script, with minor
3207 changes if needed, which include:
3211 adjusting a relative name for the cache file;
3214 adjusting a relative name for the source directory;
3217 propagating the current value of @code{$prefix}, including if it was
3218 defaulted, and if the default values of the top level and of the subdirectory
3219 @file{configure} differ.
3222 This macro also sets the output variable @code{subdirs} to the list of
3223 directories @samp{@var{dir} @dots{}}. @file{Makefile} rules can use
3224 this variable to determine which subdirectories to recurse into.
3226 This macro may be called multiple times.
3229 @node Default Prefix
3230 @section Default Prefix
3231 @cindex Install prefix
3232 @cindex Prefix for install
3234 By default, @command{configure} sets the prefix for files it installs to
3235 @file{/usr/local}. The user of @command{configure} can select a different
3236 prefix using the @option{--prefix} and @option{--exec-prefix} options.
3237 There are two ways to change the default: when creating
3238 @command{configure}, and when running it.
3240 Some software packages might want to install in a directory other than
3241 @file{/usr/local} by default. To accomplish that, use the
3242 @code{AC_PREFIX_DEFAULT} macro.
3244 @defmac AC_PREFIX_DEFAULT (@var{prefix})
3245 @acindex{PREFIX_DEFAULT}
3246 Set the default installation prefix to @var{prefix} instead of
3250 It may be convenient for users to have @command{configure} guess the
3251 installation prefix from the location of a related program that they
3252 have already installed. If you wish to do that, you can call
3253 @code{AC_PREFIX_PROGRAM}.
3255 @defmac AC_PREFIX_PROGRAM (@var{program})
3256 @acindex{PREFIX_PROGRAM}
3257 If the user did not specify an installation prefix (using the
3258 @option{--prefix} option), guess a value for it by looking for
3259 @var{program} in @env{PATH}, the way the shell does. If @var{program}
3260 is found, set the prefix to the parent of the directory containing
3261 @var{program}, else default the prefix as described above
3262 (@file{/usr/local} or @code{AC_PREFIX_DEFAULT}). For example, if
3263 @var{program} is @code{gcc} and the @env{PATH} contains
3264 @file{/usr/local/gnu/bin/gcc}, set the prefix to @file{/usr/local/gnu}.
3269 @c ======================================================== Existing tests
3271 @node Existing Tests
3272 @chapter Existing Tests
3274 These macros test for particular system features that packages might
3275 need or want to use. If you need to test for a kind of feature that
3276 none of these macros check for, you can probably do it by calling
3277 primitive test macros with appropriate arguments (@pxref{Writing
3280 These tests print messages telling the user which feature they're
3281 checking for, and what they find. They cache their results for future
3282 @command{configure} runs (@pxref{Caching Results}).
3284 Some of these macros set output variables. @xref{Makefile
3285 Substitutions}, for how to get their values. The phrase ``define
3286 @var{name}'' is used below as a shorthand to mean ``define C
3287 preprocessor symbol @var{name} to the value 1''. @xref{Defining
3288 Symbols}, for how to get those symbol definitions into your program.
3291 * Common Behavior:: Macros' standard schemes
3292 * Alternative Programs:: Selecting between alternative programs
3293 * Files:: Checking for the existence of files
3294 * Libraries:: Library archives that might be missing
3295 * Library Functions:: C library functions that might be missing
3296 * Header Files:: Header files that might be missing
3297 * Declarations:: Declarations that may be missing
3298 * Structures:: Structures or members that might be missing
3299 * Types:: Types that might be missing
3300 * Compilers and Preprocessors:: Checking for compiling programs
3301 * System Services:: Operating system services
3302 * Posix Variants:: Special kludges for specific Posix variants
3303 * Erlang Libraries:: Checking for the existence of Erlang libraries
3306 @node Common Behavior
3307 @section Common Behavior
3308 @cindex Common autoconf behavior
3310 Much effort has been expended to make Autoconf easy to learn. The most
3311 obvious way to reach this goal is simply to enforce standard interfaces
3312 and behaviors, avoiding exceptions as much as possible. Because of
3313 history and inertia, unfortunately, there are still too many exceptions
3314 in Autoconf; nevertheless, this section describes some of the common
3318 * Standard Symbols:: Symbols defined by the macros
3319 * Default Includes:: Includes used by the generic macros
3322 @node Standard Symbols
3323 @subsection Standard Symbols
3324 @cindex Standard symbols
3326 All the generic macros that @code{AC_DEFINE} a symbol as a result of
3327 their test transform their @var{argument}s to a standard alphabet.
3328 First, @var{argument} is converted to upper case and any asterisks
3329 (@samp{*}) are each converted to @samp{P}. Any remaining characters
3330 that are not alphanumeric are converted to underscores.
3335 AC_CHECK_TYPES([struct $Expensive*])
3339 will define the symbol @samp{HAVE_STRUCT__EXPENSIVEP} if the check
3343 @node Default Includes
3344 @subsection Default Includes
3345 @cindex Default includes
3346 @cindex Includes, default
3348 Several tests depend upon a set of header files. Since these headers
3349 are not universally available, tests actually have to provide a set of
3350 protected includes, such as:
3354 #if TIME_WITH_SYS_TIME
3355 # include <sys/time.h>
3358 # if HAVE_SYS_TIME_H
3359 # include <sys/time.h>
3368 Unless you know exactly what you are doing, you should avoid using
3369 unconditional includes, and check the existence of the headers you
3370 include beforehand (@pxref{Header Files}).
3372 Most generic macros use the following macro to provide the default set
3375 @defmac AC_INCLUDES_DEFAULT (@ovar{include-directives})
3376 @acindex{INCLUDES_DEFAULT}
3377 Expand to @var{include-directives} if defined, otherwise to:
3382 #if HAVE_SYS_TYPES_H
3383 # include <sys/types.h>
3386 # include <sys/stat.h>
3389 # include <stdlib.h>
3390 # include <stddef.h>
3393 # include <stdlib.h>
3397 # if !STDC_HEADERS && HAVE_MEMORY_H
3398 # include <memory.h>
3400 # include <string.h>
3403 # include <strings.h>
3406 # include <inttypes.h>
3409 # include <stdint.h>
3412 # include <unistd.h>
3417 If the default includes are used, then check for the presence of these
3418 headers and their compatibility, i.e., you don't need to run
3419 @code{AC_HEADER_STDC}, nor check for @file{stdlib.h} etc.
3421 These headers are checked for in the same order as they are included.
3422 For instance, on some systems @file{string.h} and @file{strings.h} both
3423 exist, but conflict. Then @code{HAVE_STRING_H} will be defined, but
3424 @code{HAVE_STRINGS_H} won't.
3427 @node Alternative Programs
3428 @section Alternative Programs
3429 @cindex Programs, checking
3431 These macros check for the presence or behavior of particular programs.
3432 They are used to choose between several alternative programs and to
3433 decide what to do once one has been chosen. If there is no macro
3434 specifically defined to check for a program you need, and you don't need
3435 to check for any special properties of it, then you can use one of the
3436 general program-check macros.
3439 * Particular Programs:: Special handling to find certain programs
3440 * Generic Programs:: How to find other programs
3443 @node Particular Programs
3444 @subsection Particular Program Checks
3446 These macros check for particular programs---whether they exist, and
3447 in some cases whether they support certain features.
3452 Check for @code{gawk}, @code{mawk}, @code{nawk}, and @code{awk}, in that
3453 order, and set output variable @code{AWK} to the first one that is found.
3454 It tries @code{gawk} first because that is reported to be the
3455 best implementation.
3458 @defmac AC_PROG_GREP
3461 On AIX the default @code{grep} silently truncates long lines on the
3462 input before matching. On Solaris, @code{/usr/bin/grep} does not
3463 understand the @option{-e} option. On NeXT, @code{grep} understands only a
3464 single @option{-e} option. This macro looks for @sc{gnu} Grep or
3465 else the best available @code{grep} or @code{ggrep} in the user's
3466 @env{PATH} which accepts the longest input lines possible, and which
3467 accepts and respects multiple @option{-e} options. Set the
3468 output variable @code{GREP} to whatever is chosen.
3471 @defmac AC_PROG_EGREP
3472 @acindex{PROG_EGREP}
3474 Check whether @code{$GREP -E} works, or else search the user's
3475 @env{PATH} for @code{egrep}, and @code{gegrep}, in that order, and set
3476 output variable @code{EGREP} to the one that accepts the longest input
3480 @defmac AC_PROG_FGREP
3481 @acindex{PROG_FGREP}
3483 Check whether @code{$GREP -F} works, or else search the user's
3484 @env{PATH} for @code{fgrep}, and @code{gfgrep}, in that order, and set
3485 output variable @code{FGREP} to the one that accepts the longest input
3489 @defmac AC_PROG_INSTALL
3490 @acindex{PROG_INSTALL}
3492 @ovindex INSTALL_PROGRAM
3493 @ovindex INSTALL_DATA
3494 @ovindex INSTALL_SCRIPT
3495 Set output variable @code{INSTALL} to the name of a @acronym{BSD}-compatible
3496 @code{install} program, if one is found in the current @env{PATH}.
3497 Otherwise, set @code{INSTALL} to @samp{@var{dir}/install-sh -c},
3498 checking the directories specified to @code{AC_CONFIG_AUX_DIR} (or its
3499 default directories) to determine @var{dir} (@pxref{Output}). Also set
3500 the variables @code{INSTALL_PROGRAM} and @code{INSTALL_SCRIPT} to
3501 @samp{$@{INSTALL@}} and @code{INSTALL_DATA} to @samp{$@{INSTALL@} -m 644}.
3503 This macro screens out various instances of @code{install} known not to
3504 work. It prefers to find a C program rather than a shell script, for
3505 speed. Instead of @file{install-sh}, it can also use @file{install.sh},
3506 but that name is obsolete because some @command{make} programs have a rule
3507 that creates @file{install} from it if there is no @file{Makefile}.
3509 Autoconf comes with a copy of @file{install-sh} that you can use. If
3510 you use @code{AC_PROG_INSTALL}, you must include either
3511 @file{install-sh} or @file{install.sh} in your distribution, or
3512 @command{configure} will produce an error message saying it can't find
3513 them---even if the system you're on has a good @code{install} program.
3514 This check is a safety measure to prevent you from accidentally leaving
3515 that file out, which would prevent your package from installing on
3516 systems that don't have a @acronym{BSD}-compatible @code{install} program.
3518 If you need to use your own installation program because it has features
3519 not found in standard @code{install} programs, there is no reason to use
3520 @code{AC_PROG_INSTALL}; just put the file name of your program into your
3521 @file{Makefile.in} files.
3528 @cvindex YYTEXT_POINTER
3529 @ovindex LEX_OUTPUT_ROOT
3530 If @code{flex} is found, set output variable @code{LEX} to @samp{flex}
3531 and @code{LEXLIB} to @option{-lfl}, if that library is in a standard
3532 place. Otherwise set @code{LEX} to @samp{lex} and @code{LEXLIB} to
3535 Define @code{YYTEXT_POINTER} if @code{yytext} is a @samp{char *} instead
3536 of a @samp{char []}. Also set output variable @code{LEX_OUTPUT_ROOT} to
3537 the base of the file name that the lexer generates; usually
3538 @file{lex.yy}, but sometimes something else. These results vary
3539 according to whether @code{lex} or @code{flex} is being used.
3541 You are encouraged to use Flex in your sources, since it is both more
3542 pleasant to use than plain Lex and the C source it produces is portable.
3543 In order to ensure portability, however, you must either provide a
3544 function @code{yywrap} or, if you don't use it (e.g., your scanner has
3545 no @samp{#include}-like feature), simply include a @samp{%noyywrap}
3546 statement in the scanner's source. Once this done, the scanner is
3547 portable (unless @emph{you} felt free to use nonportable constructs) and
3548 does not depend on any library. In this case, and in this case only, it
3549 is suggested that you use this Autoconf snippet:
3553 if test "$LEX" != flex; then
3554 LEX="$SHELL $missing_dir/missing flex"
3555 AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
3556 AC_SUBST([LEXLIB], [''])
3560 The shell script @command{missing} can be found in the Automake
3563 To ensure backward compatibility, Automake's @code{AM_PROG_LEX} invokes
3564 (indirectly) this macro twice, which will cause an annoying but benign
3565 ``@code{AC_PROG_LEX} invoked multiple times'' warning. Future versions
3566 of Automake will fix this issue; meanwhile, just ignore this message.
3568 As part of running the test, this macro may delete any file in the
3569 configuration directory named @file{lex.yy.c} or @file{lexyy.c}.
3572 @defmac AC_PROG_LN_S
3575 If @samp{ln -s} works on the current file system (the operating system
3576 and file system support symbolic links), set the output variable
3577 @code{LN_S} to @samp{ln -s}; otherwise, if @samp{ln} works, set
3578 @code{LN_S} to @samp{ln}, and otherwise set it to @samp{cp -p}.
3580 If you make a link in a directory other than the current directory, its
3581 meaning depends on whether @samp{ln} or @samp{ln -s} is used. To safely
3582 create links using @samp{$(LN_S)}, either find out which form is used
3583 and adjust the arguments, or always invoke @code{ln} in the directory
3584 where the link is to be created.
3586 In other words, it does not work to do:
3594 (cd /x && $(LN_S) foo bar)
3598 @defmac AC_PROG_RANLIB
3599 @acindex{PROG_RANLIB}
3601 Set output variable @code{RANLIB} to @samp{ranlib} if @code{ranlib}
3602 is found, and otherwise to @samp{:} (do nothing).
3608 Set output variable @code{SED} to a Sed implementation on @env{PATH} that
3609 truncates as few characters as possible. If @sc{gnu} Sed is found,
3613 @defmac AC_PROG_YACC
3616 If @code{bison} is found, set output variable @code{YACC} to @samp{bison
3617 -y}. Otherwise, if @code{byacc} is found, set @code{YACC} to
3618 @samp{byacc}. Otherwise set @code{YACC} to @samp{yacc}.
3621 @node Generic Programs
3622 @subsection Generic Program and File Checks
3624 These macros are used to find programs not covered by the ``particular''
3625 test macros. If you need to check the behavior of a program as well as
3626 find out whether it is present, you have to write your own test for it
3627 (@pxref{Writing Tests}). By default, these macros use the environment
3628 variable @env{PATH}. If you need to check for a program that might not
3629 be in the user's @env{PATH}, you can pass a modified path to use
3633 AC_PATH_PROG([INETD], [inetd], [/usr/libexec/inetd],
3634 [$PATH:/usr/libexec:/usr/sbin:/usr/etc:/etc])
3637 You are strongly encouraged to declare the @var{variable} passed to
3638 @code{AC_CHECK_PROG} etc.@: as precious, @xref{Setting Output Variables},
3639 @code{AC_ARG_VAR}, for more details.
3641 @defmac AC_CHECK_PROG (@var{variable}, @var{prog-to-check-for}, @var{value-if-found}, @ovar{value-if-not-found}, @ovar{path}, @ovar{reject})
3642 @acindex{CHECK_PROG}
3643 Check whether program @var{prog-to-check-for} exists in @env{PATH}. If
3644 it is found, set @var{variable} to @var{value-if-found}, otherwise to
3645 @var{value-if-not-found}, if given. Always pass over @var{reject} (an
3646 absolute file name) even if it is the first found in the search path; in
3647 that case, set @var{variable} using the absolute file name of the
3648 @var{prog-to-check-for} found that is not @var{reject}. If
3649 @var{variable} was already set, do nothing. Calls @code{AC_SUBST} for
3653 @defmac AC_CHECK_PROGS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3654 @acindex{CHECK_PROGS}
3655 Check for each program in the blank-separated list
3656 @var{progs-to-check-for} existing in the @env{PATH}. If one is found, set
3657 @var{variable} to the name of that program. Otherwise, continue
3658 checking the next program in the list. If none of the programs in the
3659 list are found, set @var{variable} to @var{value-if-not-found}; if
3660 @var{value-if-not-found} is not specified, the value of @var{variable}
3661 is not changed. Calls @code{AC_SUBST} for @var{variable}.
3664 @defmac AC_CHECK_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3665 @acindex{CHECK_TARGET_TOOL}
3666 Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
3667 with a prefix of the target type as determined by
3668 @code{AC_CANONICAL_TARGET}, followed by a dash (@pxref{Canonicalizing}).
3669 If the tool cannot be found with a prefix, and if the build and target
3670 types are equal, then it is also searched for without a prefix.
3672 As noted in @ref{Specifying Names, , Specifying the system type}, the
3673 target is rarely specified, because most of the time it is the same
3674 as the host: it is the type of system for which any compiler tools in
3675 the package will produce code. What this macro will look for is,
3676 for example, @emph{a tool @r{(assembler, linker, etc.)}@: that the
3677 compiler driver @r{(@command{gcc} for the @acronym{GNU} C Compiler)}
3678 will use to produce objects, archives or executables}.
3681 @defmac AC_CHECK_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3682 @acindex{CHECK_TOOL}
3683 Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
3684 with a prefix of the host type as determined by
3685 @code{AC_CANONICAL_HOST}, followed by a dash (@pxref{Canonicalizing}).
3686 For example, if the user runs @samp{configure --host=i386-gnu}, then
3689 AC_CHECK_TOOL([RANLIB], [ranlib], [:])
3692 sets @code{RANLIB} to @file{i386-gnu-ranlib} if that program exists in
3693 @env{PATH}, or otherwise to @samp{ranlib} if that program exists in
3694 @env{PATH}, or to @samp{:} if neither program exists.
3696 In the future, when cross-compiling this macro will @emph{only}
3697 accept program names that are prefixed with the host type.
3698 For more information, see @ref{Specifying Names, , Specifying the
3702 @defmac AC_CHECK_TARGET_TOOLS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3703 @acindex{CHECK_TARGET_TOOLS}
3704 Like @code{AC_CHECK_TARGET_TOOL}, each of the tools in the list
3705 @var{progs-to-check-for} are checked with a prefix of the target type as
3706 determined by @code{AC_CANONICAL_TARGET}, followed by a dash
3707 (@pxref{Canonicalizing}). If none of the tools can be found with a
3708 prefix, and if the build and target types are equal, then the first one
3709 without a prefix is used. If a tool is found, set @var{variable} to
3710 the name of that program. If none of the tools in the list are found,
3711 set @var{variable} to @var{value-if-not-found}; if @var{value-if-not-found}
3712 is not specified, the value of @var{variable} is not changed. Calls
3713 @code{AC_SUBST} for @var{variable}.
3716 @defmac AC_CHECK_TOOLS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3717 @acindex{CHECK_TOOLS}
3718 Like @code{AC_CHECK_TOOL}, each of the tools in the list
3719 @var{progs-to-check-for} are checked with a prefix of the host type as
3720 determined by @code{AC_CANONICAL_HOST}, followed by a dash
3721 (@pxref{Canonicalizing}). If none of the tools can be found with a
3722 prefix, then the first one without a prefix is used. If a tool is found,
3723 set @var{variable} to the name of that program. If none of the tools in
3724 the list are found, set @var{variable} to @var{value-if-not-found}; if
3725 @var{value-if-not-found} is not specified, the value of @var{variable}
3726 is not changed. Calls @code{AC_SUBST} for @var{variable}.
3728 In the future, when cross-compiling this macro will @emph{not}
3729 accept program names that are not prefixed with the host type.
3732 @defmac AC_PATH_PROG (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3734 Like @code{AC_CHECK_PROG}, but set @var{variable} to the absolute
3735 name of @var{prog-to-check-for} if found.
3738 @defmac AC_PATH_PROGS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3739 @acindex{PATH_PROGS}
3740 Like @code{AC_CHECK_PROGS}, but if any of @var{progs-to-check-for}
3741 are found, set @var{variable} to the absolute name of the program
3745 @defmac AC_PATH_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3746 @acindex{PATH_TARGET_TOOL}
3747 Like @code{AC_CHECK_TARGET_TOOL}, but set @var{variable} to the absolute
3748 name of the program if it is found.
3751 @defmac AC_PATH_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3753 Like @code{AC_CHECK_TOOL}, but set @var{variable} to the absolute
3754 name of the program if it is found.
3756 In the future, when cross-compiling this macro will @emph{not}
3757 accept program names that are not prefixed with the host type.
3763 @cindex File, checking
3765 You might also need to check for the existence of files. Before using
3766 these macros, ask yourself whether a runtime test might not be a better
3767 solution. Be aware that, like most Autoconf macros, they test a feature
3768 of the host machine, and therefore, they die when cross-compiling.
3770 @defmac AC_CHECK_FILE (@var{file}, @ovar{action-if-found}, @ovar{action-if-not-found})
3771 @acindex{CHECK_FILE}
3772 Check whether file @var{file} exists on the native system. If it is
3773 found, execute @var{action-if-found}, otherwise do
3774 @var{action-if-not-found}, if given.
3777 @defmac AC_CHECK_FILES (@var{files}, @ovar{action-if-found}, @ovar{action-if-not-found})
3778 @acindex{CHECK_FILES}
3779 Executes @code{AC_CHECK_FILE} once for each file listed in @var{files}.
3780 Additionally, defines @samp{HAVE_@var{file}} (@pxref{Standard Symbols})
3781 for each file found.
3786 @section Library Files
3787 @cindex Library, checking
3789 The following macros check for the presence of certain C, C++, or Fortran
3790 library archive files.
3792 @defmac AC_CHECK_LIB (@var{library}, @var{function}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
3794 Test whether the library @var{library} is available by trying to link
3795 a test program that calls function @var{function} with the library.
3796 @var{function} should be a function provided by the library.
3798 name of the library; e.g., to check for @option{-lmp}, use @samp{mp} as
3799 the @var{library} argument.
3801 @var{action-if-found} is a list of shell commands to run if the link
3802 with the library succeeds; @var{action-if-not-found} is a list of shell
3803 commands to run if the link fails. If @var{action-if-found} is not
3804 specified, the default action will prepend @option{-l@var{library}} to
3805 @code{LIBS} and define @samp{HAVE_LIB@var{library}} (in all
3806 capitals). This macro is intended to support building @code{LIBS} in
3807 a right-to-left (least-dependent to most-dependent) fashion such that
3808 library dependencies are satisfied as a natural side-effect of
3809 consecutive tests. Some linkers are very sensitive to library ordering
3810 so the order in which @code{LIBS} is generated is important to reliable
3811 detection of libraries.
3813 If linking with @var{library} results in unresolved symbols that would
3814 be resolved by linking with additional libraries, give those libraries
3815 as the @var{other-libraries} argument, separated by spaces:
3816 e.g., @option{-lXt -lX11}. Otherwise, this macro will fail to detect
3817 that @var{library} is present, because linking the test program will
3818 always fail with unresolved symbols. The @var{other-libraries} argument
3819 should be limited to cases where it is desirable to test for one library
3820 in the presence of another that is not already in @code{LIBS}.
3822 @code{AC_CHECK_LIB} requires some care in usage, and should be avoided
3823 in some common cases. Many standard functions like @code{gethostbyname}
3824 appear the standard C library on some hosts, and in special libraries
3825 like @code{nsl} on other hosts. On some hosts the special libraries
3826 contain variant implementations that you may not want to use. These
3827 days it is normally better to use @code{AC_SEARCH_LIBS([gethostbyname],
3828 [nsl])} instead of @code{AC_CHECK_LIB([nsl], [gethostbyname])}.
3832 @defmac AC_SEARCH_LIBS (@var{function}, @var{search-libs}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
3833 @acindex{SEARCH_LIBS}
3834 Search for a library defining @var{function} if it's not already
3835 available. This equates to calling
3836 @samp{AC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])])} first with
3837 no libraries, then for each library listed in @var{search-libs}.
3839 Add @option{-l@var{library}} to @code{LIBS} for the first library found
3840 to contain @var{function}, and run @var{action-if-found}. If the
3841 function is not found, run @var{action-if-not-found}.
3843 If linking with @var{library} results in unresolved symbols that would
3844 be resolved by linking with additional libraries, give those libraries
3845 as the @var{other-libraries} argument, separated by spaces:
3846 e.g., @option{-lXt -lX11}. Otherwise, this macro will fail to detect
3847 that @var{function} is present, because linking the test program will
3848 always fail with unresolved symbols.
3853 @node Library Functions
3854 @section Library Functions
3856 The following macros check for particular C library functions.
3857 If there is no macro specifically defined to check for a function you need,
3858 and you don't need to check for any special properties of
3859 it, then you can use one of the general function-check macros.
3862 * Function Portability:: Pitfalls with usual functions
3863 * Particular Functions:: Special handling to find certain functions
3864 * Generic Functions:: How to find other functions
3867 @node Function Portability
3868 @subsection Portability of C Functions
3869 @cindex Portability of C functions
3870 @cindex C function portability
3872 Most usual functions can either be missing, or be buggy, or be limited
3873 on some architectures. This section tries to make an inventory of these
3874 portability issues. By definition, this list will always require
3875 additions. Please help us keeping it as complete as possible.
3880 @prindex @code{exit}
3881 On ancient hosts, @code{exit} returned @code{int}.
3882 This is because @code{exit} predates @code{void}, and there was a long
3883 tradition of it returning @code{int}.
3885 On more-modern hosts, the problem more likely is that @code{exit} is not
3886 declared, due to C++ problems of some sort or another. For this reason
3887 we suggest that test programs not invoke @code{exit}, but return from
3888 @code{main} instead.
3892 @prindex @code{free}
3893 The C standard says a call @code{free (NULL)} does nothing, but
3894 some old systems don't support this (e.g., NextStep).
3900 @prindex @code{isinf}
3901 @prindex @code{isnan}
3902 The C99 standard says that @code{isinf} and @code{isnan} are
3903 macros. On some systems just macros are available (e.g., HP-UX), on
3904 some systems both macros and functions (e.g., glibc 2.3.2), and on some
3905 systems only functions (e.g., IRIX 6 and Solaris 9). In some cases
3906 these functions are declared in nonstandard headers like
3907 @code{<sunmath.h>} and defined in non-default libraries like
3908 @option{-lm} or @option{-lsunmath}.
3910 The C99 @code{isinf} and @code{isnan} macros work correctly with
3911 @code{long double} arguments, but pre-C99 systems that use functions
3912 typically assume @code{double} arguments. On such a system,
3913 @code{isinf} incorrectly returns true for a finite @code{long double}
3914 argument that is outside the range of @code{double}.
3916 To work around this porting mess, you can use code like the following.
3923 (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
3924 : sizeof (x) == sizeof (double) ? isnan_d (x) \
3926 static inline int isnan_f (float x) @{ return x != x; @}
3927 static inline int isnan_d (double x) @{ return x != x; @}
3928 static inline int isnan_ld (long double x) @{ return x != x; @}
3933 (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
3934 : sizeof (x) == sizeof (double) ? isinf_d (x) \
3936 static inline int isinf_f (float x) @{ return isnan (x - x); @}
3937 static inline int isinf_d (double x) @{ return isnan (x - x); @}
3938 static inline int isinf_ld (long double x) @{ return isnan (x - x); @}
3942 Use @code{AC_C_INLINE} (@pxref{C Compiler}) so that this code works on
3943 compilers that lack the @code{inline} keyword. Some optimizing
3944 compilers mishandle these definitions, but systems with that bug
3945 typically have missing or broken @code{isnan} functions anyway, so it's
3946 probably not worth worrying about.
3950 @prindex @code{malloc}
3951 The C standard says a call @code{malloc (0)} is implementation
3952 dependent. It may either return @code{NULL} (e.g., OSF 4) or
3953 non-@code{NULL} (e.g., @acronym{GNU} C Library). @code{AC_FUNC_MALLOC}
3954 can be used to insist on non-@code{NULL} (@pxref{Particular Functions}).
3958 @prindex @code{putenv}
3959 Posix prefers @code{setenv} to @code{putenv}; among other things,
3960 @code{putenv} is not required of all Posix implementations, but
3963 Posix specifies that @code{putenv} puts the given string directly in
3964 @code{environ}, but some systems make a copy of it instead (e.g.,
3965 glibc 2.0, or @acronym{BSD}). And when a copy is made, @code{unsetenv} might
3966 not free it, causing a memory leak (e.g., Free@acronym{BSD} 4).
3968 On some systems @code{putenv ("FOO")} removes @samp{FOO} from the
3969 environment, but this is not standard usage and it dumps core
3970 on some systems (e.g., AIX).
3972 On MinGW, a call @code{putenv ("FOO=")} removes @samp{FOO} from the
3973 environment, rather than inserting it with an empty value.
3975 @item @code{realloc}
3977 @prindex @code{realloc}
3978 The C standard says a call @code{realloc (NULL, size)} is equivalent
3979 to @code{malloc (size)}, but some old systems don't support this (e.g.,
3982 @item @code{signal} handler
3984 @prindex @code{signal}
3985 Normally @code{signal} takes a handler function with a return type of
3986 @code{void}, but some old systems required @code{int} instead. Any
3987 actual @code{int} value returned is not used; this is only a
3988 difference in the function prototype demanded.
3990 All systems we know of in current use return @code{void}. The
3991 @code{int} was to support K&R C, where of course @code{void} is not
3992 available. @code{AC_TYPE_SIGNAL} (@pxref{Particular Types}) can be
3993 used to establish the correct type in all cases.
3995 @item @code{snprintf}
3996 @c @fuindex snprintf
3997 @prindex @code{snprintf}
3998 @c @fuindex vsnprintf
3999 @prindex @code{vsnprintf}
4000 The C99 standard says that if the output array isn't big enough
4001 and if no other errors occur, @code{snprintf} and @code{vsnprintf}
4002 truncate the output and return the number of bytes that ought to have
4003 been produced. Some older systems return the truncated length (e.g.,
4004 @acronym{GNU} C Library 2.0.x or @sc{irix} 6.5), some a negative value
4005 (e.g., earlier @acronym{GNU} C Library versions), and some the buffer
4006 length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
4007 older systems ignore the length and overrun the buffer (e.g., 64-bit
4010 @item @code{sprintf}
4012 @prindex @code{sprintf}
4013 @c @fuindex vsprintf
4014 @prindex @code{vsprintf}
4015 The C standard says @code{sprintf} and @code{vsprintf} return the
4016 number of bytes written, but on some ancient systems (SunOS 4 for
4017 instance) they return the buffer pointer instead.
4021 @prindex @code{sscanf}
4022 On various old systems, e.g., HP-UX 9, @code{sscanf} requires that its
4023 input string be writable (though it doesn't actually change it). This
4024 can be a problem when using @command{gcc} since it normally puts
4025 constant strings in read-only memory
4026 (@pxref{Incompatibilities, Incompatibilities of GCC, , gcc, Using and
4027 Porting the @acronym{GNU} Compiler Collection}). Apparently in some cases even
4028 having format strings read-only can be a problem.
4030 @item @code{strerror_r}
4031 @c @fuindex strerror_r
4032 @prindex @code{strerror_r}
4033 Posix specifies that @code{strerror_r} returns an @code{int}, but many
4034 systems (e.g., @acronym{GNU} C Library version 2.2.4) provide a
4035 different version returning a @code{char *}. @code{AC_FUNC_STRERROR_R}
4036 can detect which is in use (@pxref{Particular Functions}).
4038 @item @code{strnlen}
4040 @prindex @code{strnlen}
4041 @acronym{AIX} 4.3 provides a broken version which produces the
4045 strnlen ("foobar", 0) = 0
4046 strnlen ("foobar", 1) = 3
4047 strnlen ("foobar", 2) = 2
4048 strnlen ("foobar", 3) = 1
4049 strnlen ("foobar", 4) = 0
4050 strnlen ("foobar", 5) = 6
4051 strnlen ("foobar", 6) = 6
4052 strnlen ("foobar", 7) = 6
4053 strnlen ("foobar", 8) = 6
4054 strnlen ("foobar", 9) = 6
4057 @item @code{sysconf}
4059 @prindex @code{sysconf}
4060 @code{_SC_PAGESIZE} is standard, but some older systems (e.g., HP-UX
4061 9) have @code{_SC_PAGE_SIZE} instead. This can be tested with
4066 @prindex @code{unlink}
4067 The Posix spec says that @code{unlink} causes the given file to be
4068 removed only after there are no more open file handles for it. Some
4069 non-Posix hosts have trouble with this requirement, though,
4070 and some @acronym{DOS} variants even corrupt the file system.
4072 @item @code{unsetenv}
4073 @c @fuindex unsetenv
4074 @prindex @code{unsetenv}
4075 On MinGW, @code{unsetenv} is not available, but a variable @samp{FOO}
4076 can be removed with a call @code{putenv ("FOO=")}, as described under
4077 @code{putenv} above.
4079 @item @code{va_copy}
4081 @prindex @code{va_copy}
4082 The C99 standard provides @code{va_copy} for copying
4083 @code{va_list} variables. It may be available in older environments
4084 too, though possibly as @code{__va_copy} (e.g., @command{gcc} in strict
4085 pre-C99 mode). These can be tested with @code{#ifdef}. A fallback to
4086 @code{memcpy (&dst, &src, sizeof (va_list))} will give maximum
4089 @item @code{va_list}
4091 @prindex @code{va_list}
4092 @code{va_list} is not necessarily just a pointer. It can be a
4093 @code{struct} (e.g., @command{gcc} on Alpha), which means @code{NULL} is
4094 not portable. Or it can be an array (e.g., @command{gcc} in some
4095 PowerPC configurations), which means as a function parameter it can be
4096 effectively call-by-reference and library routines might modify the
4097 value back in the caller (e.g., @code{vsnprintf} in the @acronym{GNU} C Library
4100 @item Signed @code{>>}
4101 Normally the C @code{>>} right shift of a signed type replicates the
4102 high bit, giving a so-called ``arithmetic'' shift. But care should be
4103 taken since Standard C doesn't require that behavior. On those
4104 few processors without a native arithmetic shift (for instance Cray
4105 vector systems) zero bits may be shifted in, the same as a shift of an
4108 @item Integer @code{/}
4109 C divides signed integers by truncating their quotient toward zero,
4110 yielding the same result as Fortran. However, before C99 the standard
4111 allowed C implementations to take the floor or ceiling of the quotient
4112 in some cases. Hardly any implementations took advantage of this
4113 freedom, though, and it's probably not worth worrying about this issue
4118 @node Particular Functions
4119 @subsection Particular Function Checks
4120 @cindex Function, checking
4122 These macros check for particular C functions---whether they exist, and
4123 in some cases how they respond when given certain arguments.
4125 @defmac AC_FUNC_ALLOCA
4126 @acindex{FUNC_ALLOCA}
4128 @cvindex HAVE_ALLOCA_H
4131 @prindex @code{alloca}
4133 Check how to get @code{alloca}. Tries to get a builtin version by
4134 checking for @file{alloca.h} or the predefined C preprocessor macros
4135 @code{__GNUC__} and @code{_AIX}. If this macro finds @file{alloca.h},
4136 it defines @code{HAVE_ALLOCA_H}.
4138 If those attempts fail, it looks for the function in the standard C
4139 library. If any of those methods succeed, it defines
4140 @code{HAVE_ALLOCA}. Otherwise, it sets the output variable
4141 @code{ALLOCA} to @samp{$@{LIBOBJDIR@}alloca.o} and defines
4142 @code{C_ALLOCA} (so programs can periodically call @samp{alloca (0)} to
4143 garbage collect). This variable is separate from @code{LIBOBJS} so
4144 multiple programs can share the value of @code{ALLOCA} without needing
4145 to create an actual library, in case only some of them use the code in
4146 @code{LIBOBJS}. The @samp{$@{LIBOBJDIR@}} prefix serves the same
4147 purpose as in @code{LIBOBJS} (@pxref{AC_LIBOBJ vs LIBOBJS}).
4149 This macro does not try to get @code{alloca} from the System V R3
4150 @file{libPW} or the System V R4 @file{libucb} because those libraries
4151 contain some incompatible functions that cause trouble. Some versions
4152 do not even contain @code{alloca} or contain a buggy version. If you
4153 still want to use their @code{alloca}, use @code{ar} to extract
4154 @file{alloca.o} from them instead of compiling @file{alloca.c}.
4156 Source files that use @code{alloca} should start with a piece of code
4157 like the following, to declare it properly.
4162 # include <alloca.h>
4163 #elif defined __GNUC__
4164 # define alloca __builtin_alloca
4166 # define alloca __alloca
4167 #elif defined _MSC_VER
4168 # include <malloc.h>
4169 # define alloca _alloca
4171 # include <stddef.h>
4175 void *alloca (size_t);
4181 @defmac AC_FUNC_CHOWN
4182 @acindex{FUNC_CHOWN}
4184 @prindex @code{chown}
4185 If the @code{chown} function is available and works (in particular, it
4186 should accept @option{-1} for @code{uid} and @code{gid}), define
4191 @defmac AC_FUNC_CLOSEDIR_VOID
4192 @acindex{FUNC_CLOSEDIR_VOID}
4193 @cvindex CLOSEDIR_VOID
4194 @c @fuindex closedir
4195 @prindex @code{closedir}
4196 If the @code{closedir} function does not return a meaningful value,
4197 define @code{CLOSEDIR_VOID}. Otherwise, callers ought to check its
4198 return value for an error indicator.
4200 Currently this test is implemented by running a test program. When
4201 cross compiling the pessimistic assumption that @code{closedir} does not
4202 return a meaningful value is made.
4205 @defmac AC_FUNC_ERROR_AT_LINE
4206 @acindex{FUNC_ERROR_AT_LINE}
4207 @c @fuindex error_at_line
4208 @prindex @code{error_at_line}
4209 If the @code{error_at_line} function is not found, require an
4210 @code{AC_LIBOBJ} replacement of @samp{error}.
4213 @defmac AC_FUNC_FNMATCH
4214 @acindex{FUNC_FNMATCH}
4216 @prindex @code{fnmatch}
4217 If the @code{fnmatch} function conforms to Posix, define
4218 @code{HAVE_FNMATCH}. Detect common implementation bugs, for example,
4219 the bugs in Solaris 2.4.
4221 Note that for historical reasons, contrary to the other specific
4222 @code{AC_FUNC} macros, @code{AC_FUNC_FNMATCH} does not replace a
4223 broken/missing @code{fnmatch}. See @code{AC_REPLACE_FNMATCH} below.
4226 @defmac AC_FUNC_FNMATCH_GNU
4227 @acindex{FUNC_FNMATCH_GNU}
4229 @prindex @code{fnmatch}
4230 Behave like @code{AC_REPLACE_FNMATCH} (@emph{replace}) but also test
4231 whether @code{fnmatch} supports @acronym{GNU} extensions. Detect common
4232 implementation bugs, for example, the bugs in the @acronym{GNU} C
4236 @defmac AC_FUNC_FORK
4238 @cvindex HAVE_VFORK_H
4239 @cvindex HAVE_WORKING_FORK
4240 @cvindex HAVE_WORKING_VFORK
4243 @prindex @code{fork}
4245 @prindex @code{vfork}
4247 This macro checks for the @code{fork} and @code{vfork} functions. If a
4248 working @code{fork} is found, define @code{HAVE_WORKING_FORK}. This macro
4249 checks whether @code{fork} is just a stub by trying to run it.
4251 If @file{vfork.h} is found, define @code{HAVE_VFORK_H}. If a working
4252 @code{vfork} is found, define @code{HAVE_WORKING_VFORK}. Otherwise,
4253 define @code{vfork} to be @code{fork} for backward compatibility with
4254 previous versions of @command{autoconf}. This macro checks for several known
4255 errors in implementations of @code{vfork} and considers the system to not
4256 have a working @code{vfork} if it detects any of them. It is not considered
4257 to be an implementation error if a child's invocation of @code{signal}
4258 modifies the parent's signal handler, since child processes rarely change
4259 their signal handlers.
4261 Since this macro defines @code{vfork} only for backward compatibility with
4262 previous versions of @command{autoconf} you're encouraged to define it
4263 yourself in new code:
4266 #if !HAVE_WORKING_VFORK
4273 @defmac AC_FUNC_FSEEKO
4274 @acindex{FUNC_FSEEKO}
4275 @cvindex _LARGEFILE_SOURCE
4277 @prindex @code{fseeko}
4278 If the @code{fseeko} function is available, define @code{HAVE_FSEEKO}.
4279 Define @code{_LARGEFILE_SOURCE} if necessary to make the prototype
4280 visible on some systems (e.g., glibc 2.2). Otherwise linkage problems
4281 may occur when compiling with @code{AC_SYS_LARGEFILE} on
4282 largefile-sensitive systems where @code{off_t} does not default to a
4286 @defmac AC_FUNC_GETGROUPS
4287 @acindex{FUNC_GETGROUPS}
4288 @ovindex GETGROUPS_LIBS
4289 @c @fuindex getgroups
4290 @prindex @code{getgroups}
4291 If the @code{getgroups} function is available and works (unlike on
4292 Ultrix 4.3, where @samp{getgroups (0, 0)} always fails), define
4293 @code{HAVE_GETGROUPS}. Set @code{GETGROUPS_LIBS} to any libraries
4294 needed to get that function. This macro runs @code{AC_TYPE_GETGROUPS}.
4297 @defmac AC_FUNC_GETLOADAVG
4298 @acindex{FUNC_GETLOADAVG}
4303 @cvindex HAVE_NLIST_H
4304 @cvindex NLIST_NAME_UNION
4305 @cvindex GETLODAVG_PRIVILEGED
4306 @cvindex NEED_SETGID
4307 @cvindex C_GETLOADAVG
4309 @ovindex NEED_SETGID
4311 @ovindex GETLOADAVG_LIBS
4312 @c @fuindex getloadavg
4313 @prindex @code{getloadavg}
4314 Check how to get the system load averages. To perform its tests
4315 properly, this macro needs the file @file{getloadavg.c}; therefore, be
4316 sure to set the @code{AC_LIBOBJ} replacement directory properly (see
4317 @ref{Generic Functions}, @code{AC_CONFIG_LIBOBJ_DIR}).
4319 If the system has the @code{getloadavg} function, define
4320 @code{HAVE_GETLOADAVG}, and set @code{GETLOADAVG_LIBS} to any libraries
4321 necessary to get that function. Also add @code{GETLOADAVG_LIBS} to
4322 @code{LIBS}. Otherwise, require an @code{AC_LIBOBJ} replacement for
4323 @samp{getloadavg} with source code in @file{@var{dir}/getloadavg.c}, and
4324 possibly define several other C preprocessor macros and output
4329 Define @code{C_GETLOADAVG}.
4332 Define @code{SVR4}, @code{DGUX}, @code{UMAX}, or @code{UMAX4_3} if on
4337 If @file{nlist.h} is found, define @code{HAVE_NLIST_H}.
4340 If @samp{struct nlist} has an @samp{n_un.n_name} member, define
4341 @code{HAVE_STRUCT_NLIST_N_UN_N_NAME}. The obsolete symbol
4342 @code{NLIST_NAME_UNION} is still defined, but do not depend upon it.
4345 Programs may need to be installed setgid (or setuid) for
4346 @code{getloadavg} to work. In this case, define
4347 @code{GETLOADAVG_PRIVILEGED}, set the output variable @code{NEED_SETGID}
4348 to @samp{true} (and otherwise to @samp{false}), and set
4349 @code{KMEM_GROUP} to the name of the group that should own the installed
4354 @defmac AC_FUNC_GETMNTENT
4355 @acindex{FUNC_GETMNTENT}
4356 @cvindex HAVE_GETMNTENT
4357 @c @fuindex getmntent
4358 @prindex @code{getmntent}
4359 Check for @code{getmntent} in the standard C library, and then in the
4360 @file{sun}, @file{seq}, and @file{gen} libraries, for @sc{unicos},
4361 @sc{irix} 4, @sc{ptx}, and UnixWare, respectively. Then, if
4362 @code{getmntent} is available, define @code{HAVE_GETMNTENT}.
4365 @defmac AC_FUNC_GETPGRP
4366 @acindex{FUNC_GETPGRP}
4367 @cvindex GETPGRP_VOID
4370 @prindex @code{getpgid}
4371 @prindex @code{getpgrp}
4372 Define @code{GETPGRP_VOID} if it is an error to pass 0 to
4373 @code{getpgrp}; this is the Posix behavior. On older @acronym{BSD}
4374 systems, you must pass 0 to @code{getpgrp}, as it takes an argument and
4375 behaves like Posix's @code{getpgid}.
4385 This macro does not check whether
4386 @code{getpgrp} exists at all; if you need to work in that situation,
4387 first call @code{AC_CHECK_FUNC} for @code{getpgrp}.
4390 @defmac AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
4391 @acindex{FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK}
4392 @cvindex LSTAT_FOLLOWS_SLASHED_SYMLINK
4394 @prindex @code{lstat}
4395 If @file{link} is a symbolic link, then @code{lstat} should treat
4396 @file{link/} the same as @file{link/.}. However, many older
4397 @code{lstat} implementations incorrectly ignore trailing slashes.
4399 It is safe to assume that if @code{lstat} incorrectly ignores
4400 trailing slashes, then other symbolic-link-aware functions like
4401 @code{unlink} also incorrectly ignore trailing slashes.
4403 If @code{lstat} behaves properly, define
4404 @code{LSTAT_FOLLOWS_SLASHED_SYMLINK}, otherwise require an
4405 @code{AC_LIBOBJ} replacement of @code{lstat}.
4408 @defmac AC_FUNC_MALLOC
4409 @acindex{FUNC_MALLOC}
4410 @cvindex HAVE_MALLOC
4413 @prindex @code{malloc}
4414 If the @code{malloc} function is compatible with the @acronym{GNU} C
4415 library @code{malloc} (i.e., @samp{malloc (0)} returns a valid
4416 pointer), define @code{HAVE_MALLOC} to 1. Otherwise define
4417 @code{HAVE_MALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
4418 @samp{malloc}, and define @code{malloc} to @code{rpl_malloc} so that the
4419 native @code{malloc} is not used in the main project.
4421 Typically, the replacement file @file{malloc.c} should look like (note
4422 the @samp{#undef malloc}):
4426 # include <config.h>
4430 #include <sys/types.h>
4434 /* Allocate an N-byte block of memory from the heap.
4435 If N is zero, allocate a 1-byte block. */
4438 rpl_malloc (size_t n)
4447 @defmac AC_FUNC_MEMCMP
4448 @acindex{FUNC_MEMCMP}
4451 @prindex @code{memcmp}
4452 If the @code{memcmp} function is not available, or does not work on
4453 8-bit data (like the one on SunOS 4.1.3), or fails when comparing 16
4454 bytes or more and with at least one buffer not starting on a 4-byte
4455 boundary (such as the one on NeXT x86 OpenStep), require an
4456 @code{AC_LIBOBJ} replacement for @samp{memcmp}.
4459 @defmac AC_FUNC_MBRTOWC
4460 @acindex{FUNC_MBRTOWC}
4461 @cvindex HAVE_MBRTOWC
4463 @prindex @code{mbrtowc}
4464 Define @code{HAVE_MBRTOWC} to 1 if the function @code{mbrtowc} and the
4465 type @code{mbstate_t} are properly declared.
4468 @defmac AC_FUNC_MKTIME
4469 @acindex{FUNC_MKTIME}
4472 @prindex @code{mktime}
4473 If the @code{mktime} function is not available, or does not work
4474 correctly, require an @code{AC_LIBOBJ} replacement for @samp{mktime}.
4475 For the purposes of this test, @code{mktime} should conform to the
4476 Posix standard and should be the inverse of
4480 @defmac AC_FUNC_MMAP
4484 @prindex @code{mmap}
4485 If the @code{mmap} function exists and works correctly, define
4486 @code{HAVE_MMAP}. Only checks private fixed mapping of already-mapped
4490 @defmac AC_FUNC_OBSTACK
4491 @acindex{FUNC_OBSTACK}
4492 @cvindex HAVE_OBSTACK
4494 If the obstacks are found, define @code{HAVE_OBSTACK}, else require an
4495 @code{AC_LIBOBJ} replacement for @samp{obstack}.
4498 @defmac AC_FUNC_REALLOC
4499 @acindex{FUNC_REALLOC}
4500 @cvindex HAVE_REALLOC
4503 @prindex @code{realloc}
4504 If the @code{realloc} function is compatible with the @acronym{GNU} C
4505 library @code{realloc} (i.e., @samp{realloc (NULL, 0)} returns a
4506 valid pointer), define @code{HAVE_REALLOC} to 1. Otherwise define
4507 @code{HAVE_REALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
4508 @samp{realloc}, and define @code{realloc} to @code{rpl_realloc} so that
4509 the native @code{realloc} is not used in the main project. See
4510 @code{AC_FUNC_MALLOC} for details.
4513 @defmac AC_FUNC_SELECT_ARGTYPES
4514 @acindex{FUNC_SELECT_ARGTYPES}
4515 @cvindex SELECT_TYPE_ARG1
4516 @cvindex SELECT_TYPE_ARG234
4517 @cvindex SELECT_TYPE_ARG5
4519 @prindex @code{select}
4520 Determines the correct type to be passed for each of the
4521 @code{select} function's arguments, and defines those types
4522 in @code{SELECT_TYPE_ARG1}, @code{SELECT_TYPE_ARG234}, and
4523 @code{SELECT_TYPE_ARG5} respectively. @code{SELECT_TYPE_ARG1} defaults
4524 to @samp{int}, @code{SELECT_TYPE_ARG234} defaults to @samp{int *},
4525 and @code{SELECT_TYPE_ARG5} defaults to @samp{struct timeval *}.
4528 @defmac AC_FUNC_SETPGRP
4529 @acindex{FUNC_SETPGRP}
4530 @cvindex SETPGRP_VOID
4532 @prindex @code{setpgrp}
4533 If @code{setpgrp} takes no argument (the Posix version), define
4534 @code{SETPGRP_VOID}. Otherwise, it is the @acronym{BSD} version, which takes
4535 two process IDs as arguments. This macro does not check whether
4536 @code{setpgrp} exists at all; if you need to work in that situation,
4537 first call @code{AC_CHECK_FUNC} for @code{setpgrp}.
4540 @defmac AC_FUNC_STAT
4541 @defmacx AC_FUNC_LSTAT
4543 @acindex{FUNC_LSTAT}
4544 @cvindex HAVE_STAT_EMPTY_STRING_BUG
4545 @cvindex HAVE_LSTAT_EMPTY_STRING_BUG
4547 @prindex @code{stat}
4549 @prindex @code{lstat}
4550 Determine whether @code{stat} or @code{lstat} have the bug that it
4551 succeeds when given the zero-length file name as argument. The @code{stat}
4552 and @code{lstat} from SunOS 4.1.4 and the Hurd (as of 1998-11-01) do
4555 If it does, then define @code{HAVE_STAT_EMPTY_STRING_BUG} (or
4556 @code{HAVE_LSTAT_EMPTY_STRING_BUG}) and ask for an @code{AC_LIBOBJ}
4560 @defmac AC_FUNC_SETVBUF_REVERSED
4561 @acindex{FUNC_SETVBUF_REVERSED}
4562 @cvindex SETVBUF_REVERSED
4564 @prindex @code{setvbuf}
4565 If @code{setvbuf} takes the buffering type as its second argument and
4566 the buffer pointer as the third, instead of the other way around, define
4567 @code{SETVBUF_REVERSED}.
4570 @defmac AC_FUNC_STRCOLL
4571 @acindex{FUNC_STRCOLL}
4572 @cvindex HAVE_STRCOLL
4574 @prindex @code{strcoll}
4575 If the @code{strcoll} function exists and works correctly, define
4576 @code{HAVE_STRCOLL}. This does a bit more than
4577 @samp{AC_CHECK_FUNCS(strcoll)}, because some systems have incorrect
4578 definitions of @code{strcoll} that should not be used.
4581 @defmac AC_FUNC_STRERROR_R
4582 @acindex{FUNC_STRERROR_R}
4583 @cvindex HAVE_STRERROR_R
4584 @cvindex HAVE_DECL_STRERROR_R
4585 @cvindex STRERROR_R_CHAR_P
4586 @c @fuindex strerror_r
4587 @prindex @code{strerror_r}
4588 If @code{strerror_r} is available, define @code{HAVE_STRERROR_R}, and if
4589 it is declared, define @code{HAVE_DECL_STRERROR_R}. If it returns a
4590 @code{char *} message, define @code{STRERROR_R_CHAR_P}; otherwise it
4591 returns an @code{int} error number. The Thread-Safe Functions option of
4592 Posix requires @code{strerror_r} to return @code{int}, but
4593 many systems (including, for example, version 2.2.4 of the @acronym{GNU} C
4594 Library) return a @code{char *} value that is not necessarily equal to
4595 the buffer argument.
4598 @defmac AC_FUNC_STRFTIME
4599 @acindex{FUNC_STRFTIME}
4600 @cvindex HAVE_STRFTIME
4601 @c @fuindex strftime
4602 @prindex @code{strftime}
4603 Check for @code{strftime} in the @file{intl} library, for SCO Unix.
4604 Then, if @code{strftime} is available, define @code{HAVE_STRFTIME}.
4607 @defmac AC_FUNC_STRTOD
4608 @acindex{FUNC_STRTOD}
4611 @prindex @code{strtod}
4612 If the @code{strtod} function does not exist or doesn't work correctly,
4613 ask for an @code{AC_LIBOBJ} replacement of @samp{strtod}. In this case,
4614 because @file{strtod.c} is likely to need @samp{pow}, set the output
4615 variable @code{POW_LIB} to the extra library needed.
4618 @defmac AC_FUNC_STRTOLD
4619 @acindex{FUNC_STRTOLD}
4620 @prindex @code{strtold}
4621 If the @code{strtold} function exists and conforms to C99, define
4622 @code{HAVE_STRTOLD}.
4625 @defmac AC_FUNC_STRNLEN
4626 @acindex{FUNC_STRNLEN}
4627 @cvindex HAVE_STRNLEN
4629 @prindex @code{strnlen}
4630 If the @code{strnlen} function is not available, or is buggy (like the one
4631 from @acronym{AIX} 4.3), require an @code{AC_LIBOBJ} replacement for it.
4634 @defmac AC_FUNC_UTIME_NULL
4635 @acindex{FUNC_UTIME_NULL}
4636 @cvindex HAVE_UTIME_NULL
4638 @prindex @code{utime}
4639 If @samp{utime (@var{file}, NULL)} sets @var{file}'s timestamp to
4640 the present, define @code{HAVE_UTIME_NULL}.
4643 @defmac AC_FUNC_VPRINTF
4644 @acindex{FUNC_VPRINTF}
4645 @cvindex HAVE_VPRINTF
4646 @cvindex HAVE_DOPRNT
4648 @prindex @code{vprintf}
4649 If @code{vprintf} is found, define @code{HAVE_VPRINTF}. Otherwise, if
4650 @code{_doprnt} is found, define @code{HAVE_DOPRNT}. (If @code{vprintf}
4651 is available, you may assume that @code{vfprintf} and @code{vsprintf}
4652 are also available.)
4655 @defmac AC_REPLACE_FNMATCH
4656 @acindex{REPLACE_FNMATCH}
4658 @prindex @code{fnmatch}
4659 @hdrindex{fnmatch.h}
4660 If the @code{fnmatch} function does not conform to Posix (see
4661 @code{AC_FUNC_FNMATCH}), ask for its @code{AC_LIBOBJ} replacement.
4663 The files @file{fnmatch.c}, @file{fnmatch_loop.c}, and @file{fnmatch_.h}
4664 in the @code{AC_LIBOBJ} replacement directory are assumed to contain a
4665 copy of the source code of @acronym{GNU} @code{fnmatch}. If necessary,
4666 this source code is compiled as an @code{AC_LIBOBJ} replacement, and the
4667 @file{fnmatch_.h} file is linked to @file{fnmatch.h} so that it can be
4668 included in place of the system @code{<fnmatch.h>}.
4673 @node Generic Functions
4674 @subsection Generic Function Checks
4676 These macros are used to find functions not covered by the ``particular''
4677 test macros. If the functions might be in libraries other than the
4678 default C library, first call @code{AC_CHECK_LIB} for those libraries.
4679 If you need to check the behavior of a function as well as find out
4680 whether it is present, you have to write your own test for
4681 it (@pxref{Writing Tests}).
4683 @defmac AC_CHECK_FUNC (@var{function}, @ovar{action-if-found}, @ovar{action-if-not-found})
4684 @acindex{CHECK_FUNC}
4685 If C function @var{function} is available, run shell commands
4686 @var{action-if-found}, otherwise @var{action-if-not-found}. If you just
4687 want to define a symbol if the function is available, consider using
4688 @code{AC_CHECK_FUNCS} instead. This macro checks for functions with C
4689 linkage even when @code{AC_LANG(C++)} has been called, since C is more
4690 standardized than C++. (@pxref{Language Choice}, for more information
4691 about selecting the language for checks.)
4694 @defmac AC_CHECK_FUNCS (@var{function}@dots{}, @ovar{action-if-found}, @ovar{action-if-not-found})
4695 @acindex{CHECK_FUNCS}
4696 @cvindex HAVE_@var{function}
4697 For each @var{function} enumerated in the blank-or-newline-separated argument
4698 list, define @code{HAVE_@var{function}} (in all capitals) if it is available.
4699 If @var{action-if-found} is given, it is additional shell code to
4700 execute when one of the functions is found. You can give it a value of
4701 @samp{break} to break out of the loop on the first match. If
4702 @var{action-if-not-found} is given, it is executed when one of the
4703 functions is not found.
4706 @defmac AC_CHECK_FUNCS_ONCE (@var{function}@dots{})
4707 @acindex{CHECK_FUNCS_ONCE}
4708 @cvindex HAVE_@var{function}
4709 For each @var{function} enumerated in the blank-or-newline-separated argument
4710 list, define @code{HAVE_@var{function}} (in all capitals) if it is available.
4711 This is a once-only variant of @code{AC_CHECK_FUNCS}. It generates the
4712 checking code at most once, so that @command{configure} is smaller and
4713 faster; but the checks cannot be conditionalized and are always done once,
4714 early during the @command{configure} run.
4719 Autoconf follows a philosophy that was formed over the years by those
4720 who have struggled for portability: isolate the portability issues in
4721 specific files, and then program as if you were in a Posix
4722 environment. Some functions may be missing or unfixable, and your
4723 package must be ready to replace them.
4725 Suitable replacements for many such problem functions are available from
4726 Gnulib (@pxref{Gnulib}).
4728 @defmac AC_LIBOBJ (@var{function})
4731 Specify that @samp{@var{function}.c} must be included in the executables
4732 to replace a missing or broken implementation of @var{function}.
4734 Technically, it adds @samp{@var{function}.$ac_objext} to the output
4735 variable @code{LIBOBJS} if it is not already in, and calls
4736 @code{AC_LIBSOURCE} for @samp{@var{function}.c}. You should not
4737 directly change @code{LIBOBJS}, since this is not traceable.
4740 @defmac AC_LIBSOURCE (@var{file})
4742 Specify that @var{file} might be needed to compile the project. If you
4743 need to know what files might be needed by a @file{configure.ac}, you
4744 should trace @code{AC_LIBSOURCE}. @var{file} must be a literal.
4746 This macro is called automatically from @code{AC_LIBOBJ}, but you must
4747 call it explicitly if you pass a shell variable to @code{AC_LIBOBJ}. In
4748 that case, since shell variables cannot be traced statically, you must
4749 pass to @code{AC_LIBSOURCE} any possible files that the shell variable
4750 might cause @code{AC_LIBOBJ} to need. For example, if you want to pass
4751 a variable @code{$foo_or_bar} to @code{AC_LIBOBJ} that holds either
4752 @code{"foo"} or @code{"bar"}, you should do:
4755 AC_LIBSOURCE([foo.c])
4756 AC_LIBSOURCE([bar.c])
4757 AC_LIBOBJ([$foo_or_bar])
4761 There is usually a way to avoid this, however, and you are encouraged to
4762 simply call @code{AC_LIBOBJ} with literal arguments.
4764 Note that this macro replaces the obsolete @code{AC_LIBOBJ_DECL}, with
4765 slightly different semantics: the old macro took the function name,
4766 e.g., @code{foo}, as its argument rather than the file name.
4769 @defmac AC_LIBSOURCES (@var{files})
4770 @acindex{LIBSOURCES}
4771 Like @code{AC_LIBSOURCE}, but accepts one or more @var{files} in a
4772 comma-separated M4 list. Thus, the above example might be rewritten:
4775 AC_LIBSOURCES([foo.c, bar.c])
4776 AC_LIBOBJ([$foo_or_bar])
4780 @defmac AC_CONFIG_LIBOBJ_DIR (@var{directory})
4781 @acindex{CONFIG_LIBOBJ_DIR}
4782 Specify that @code{AC_LIBOBJ} replacement files are to be found in
4783 @var{directory}, a name relative to the top level of the
4784 source tree. The replacement directory defaults to @file{.}, the top
4785 level directory, and the most typical value is @file{lib}, corresponding
4786 to @samp{AC_CONFIG_LIBOBJ_DIR([lib])}.
4788 @command{configure} might need to know the replacement directory for the
4789 following reasons: (i) some checks use the replacement files, (ii) some
4790 macros bypass broken system headers by installing links to the
4791 replacement headers (iii) when used in conjunction with Automake,
4792 within each @file{Makefile}, @var{directory} is used as a relative path
4793 from @code{$(top_srcdir)} to each object named in @code{LIBOBJS} and
4794 @code{LTLIBOBJS}, etc.
4799 It is common to merely check for the existence of a function, and ask
4800 for its @code{AC_LIBOBJ} replacement if missing. The following macro is
4801 a convenient shorthand.
4803 @defmac AC_REPLACE_FUNCS (@var{function}@dots{})
4804 @acindex{REPLACE_FUNCS}
4806 Like @code{AC_CHECK_FUNCS}, but uses @samp{AC_LIBOBJ(@var{function})} as
4807 @var{action-if-not-found}. You can declare your replacement function by
4808 enclosing the prototype in @samp{#if !HAVE_@var{function}}. If the
4809 system has the function, it probably declares it in a header file you
4810 should be including, so you shouldn't redeclare it lest your declaration
4815 @section Header Files
4816 @cindex Header, checking
4818 The following macros check for the presence of certain C header files.
4819 If there is no macro specifically defined to check for a header file you need,
4820 and you don't need to check for any special properties of
4821 it, then you can use one of the general header-file check macros.
4824 * Header Portability:: Collected knowledge on common headers
4825 * Particular Headers:: Special handling to find certain headers
4826 * Generic Headers:: How to find other headers
4829 @node Header Portability
4830 @subsection Portability of Headers
4831 @cindex Portability of headers
4832 @cindex Header portability
4834 This section tries to collect knowledge about common headers, and the
4835 problems they cause. By definition, this list will always require
4836 additions. Please help us keeping it as complete as possible.
4840 @item @file{limits.h}
4841 C99 says that @file{limits.h} defines @code{LLONG_MIN},
4842 @code{LLONG_MAX}, and @code{ULLONG_MAX}, but many almost-C99
4843 environments (e.g., default GCC 4.0.2 + glibc 2.4) do not define them.
4845 @item @file{inttypes.h} vs.@: @file{stdint.h}
4846 @hdrindex{inttypes.h}
4848 The C99 standard says that @file{inttypes.h} includes
4849 @file{stdint.h}, so there's no need to include @file{stdint.h}
4850 separately in a standard environment. Some implementations have
4851 @file{inttypes.h} but not @file{stdint.h} (e.g., Solaris 7), but we don't
4852 know of any implementation that has @file{stdint.h} but not
4855 @item @file{linux/irda.h}
4856 @hdrindex{linux/irda.h}
4857 It requires @file{linux/types.h} and @file{sys/socket.h}.
4859 @item @file{linux/random.h}
4860 @hdrindex{linux/random.h}
4861 It requires @file{linux/types.h}.
4863 @item @file{net/if.h}
4865 On Darwin, this file requires that @file{sys/socket.h} be included
4866 beforehand. One should run:
4869 AC_CHECK_HEADERS([sys/socket.h])
4870 AC_CHECK_HEADERS([net/if.h], [], [],
4873 # include <stdlib.h>
4874 # include <stddef.h>
4877 # include <stdlib.h>
4880 #if HAVE_SYS_SOCKET_H
4881 # include <sys/socket.h>
4886 @item @file{netinet/if_ether.h}
4887 @hdrindex{netinet/if_ether.h}
4888 On Darwin, this file requires that @file{stdio.h} and
4889 @file{sys/socket.h} be included beforehand. One should run:
4892 AC_CHECK_HEADERS([sys/socket.h])
4893 AC_CHECK_HEADERS([netinet/if_ether.h], [], [],
4896 # include <stdlib.h>
4897 # include <stddef.h>
4900 # include <stdlib.h>
4903 #if HAVE_SYS_SOCKET_H
4904 # include <sys/socket.h>
4909 @item @file{stdint.h}
4910 See above, item @file{inttypes.h} vs.@: @file{stdint.h}.
4912 @item @file{stdlib.h}
4914 On many systems (e.g., Darwin), @file{stdio.h} is a prerequisite.
4916 @item @file{sys/mount.h}
4917 @hdrindex{sys/mount.h}
4918 On Free@acronym{BSD} 4.8 on ia32 and using gcc version 2.95.4,
4919 @file{sys/params.h} is a prerequisite.
4921 @item @file{sys/ptem.h}
4922 @hdrindex{sys/ptem.h}
4923 On Solaris 8, @file{sys/stream.h} is a prerequisite.
4925 @item @file{sys/socket.h}
4926 @hdrindex{sys/socket.h}
4927 On Darwin, @file{stdlib.h} is a prerequisite.
4929 @item @file{sys/ucred.h}
4930 @hdrindex{sys/ucred.h}
4931 On HP Tru64 5.1, @file{sys/types.h} is a prerequisite.
4933 @item @file{X11/extensions/scrnsaver.h}
4934 @hdrindex{X11/extensions/scrnsaver.h}
4935 Using XFree86, this header requires @file{X11/Xlib.h}, which is probably
4936 so required that you might not even consider looking for it.
4939 AC_CHECK_HEADERS([X11/extensions/scrnsaver.h], [], [],
4940 [[#include <X11/Xlib.h>
4946 @node Particular Headers
4947 @subsection Particular Header Checks
4949 These macros check for particular system header files---whether they
4950 exist, and in some cases whether they declare certain symbols.
4952 @defmac AC_HEADER_ASSERT
4953 @acindex{HEADER_ASSERT}
4956 Check whether to enable assertions in the style of @file{assert.h}.
4957 Assertions are enabled by default, but the user can override this by
4958 invoking @command{configure} with the @option{--disable-assert} option.
4961 @defmac AC_HEADER_DIRENT
4962 @acindex{HEADER_DIRENT}
4963 @cvindex HAVE_DIRENT_H
4964 @cvindex HAVE_NDIR_H
4965 @cvindex HAVE_SYS_DIR_H
4966 @cvindex HAVE_SYS_NDIR_H
4968 @hdrindex{sys/ndir.h}
4969 @hdrindex{sys/dir.h}
4971 Check for the following header files. For the first one that is
4972 found and defines @samp{DIR}, define the listed C preprocessor macro:
4974 @multitable {@file{sys/ndir.h}} {@code{HAVE_SYS_NDIR_H}}
4975 @item @file{dirent.h} @tab @code{HAVE_DIRENT_H}
4976 @item @file{sys/ndir.h} @tab @code{HAVE_SYS_NDIR_H}
4977 @item @file{sys/dir.h} @tab @code{HAVE_SYS_DIR_H}
4978 @item @file{ndir.h} @tab @code{HAVE_NDIR_H}
4981 The directory-library declarations in your source code should look
4982 something like the following:
4986 #include <sys/types.h>
4987 #ifdef HAVE_DIRENT_H
4988 # include <dirent.h>
4989 # define NAMLEN(dirent) strlen ((dirent)->d_name)
4991 # define dirent direct
4992 # define NAMLEN(dirent) ((dirent)->d_namlen)
4993 # if HAVE_SYS_NDIR_H
4994 # include <sys/ndir.h>
4997 # include <sys/dir.h>
5006 Using the above declarations, the program would declare variables to be
5007 of type @code{struct dirent}, not @code{struct direct}, and would access
5008 the length of a directory entry name by passing a pointer to a
5009 @code{struct dirent} to the @code{NAMLEN} macro.
5011 This macro also checks for the SCO Xenix @file{dir} and @file{x} libraries.
5013 Also see @code{AC_STRUCT_DIRENT_D_INO} and
5014 @code{AC_STRUCT_DIRENT_D_TYPE} (@pxref{Particular Structures}).
5017 @defmac AC_HEADER_MAJOR
5018 @acindex{HEADER_MAJOR}
5019 @cvindex MAJOR_IN_MKDEV
5020 @cvindex MAJOR_IN_SYSMACROS
5021 @hdrindex{sys/mkdev.h}
5022 @hdrindex{sys/sysmacros.h}
5023 If @file{sys/types.h} does not define @code{major}, @code{minor}, and
5024 @code{makedev}, but @file{sys/mkdev.h} does, define
5025 @code{MAJOR_IN_MKDEV}; otherwise, if @file{sys/sysmacros.h} does, define
5026 @code{MAJOR_IN_SYSMACROS}.
5029 @defmac AC_HEADER_RESOLV
5030 @acindex{HEADER_RESOLV}
5031 @cvindex HAVE_RESOLV_H
5033 Checks for header @file{resolv.h}, checking for prerequisites first.
5034 To properly use @file{resolv.h}, your code should contain something like
5038 #if HAVE_SYS_TYPES_H
5039 # include <sys/types.h>
5041 #ifdef HAVE_NETINET_IN_H
5042 # include <netinet/in.h> /* inet_ functions / structs */
5044 #ifdef HAVE_ARPA_NAMESER_H
5045 # include <arpa/nameser.h> /* DNS HEADER struct */
5054 @defmac AC_HEADER_STAT
5055 @acindex{HEADER_STAT}
5056 @cvindex STAT_MACROS_BROKEN
5057 @hdrindex{sys/stat.h}
5058 If the macros @code{S_ISDIR}, @code{S_ISREG}, etc.@: defined in
5059 @file{sys/stat.h} do not work properly (returning false positives),
5060 define @code{STAT_MACROS_BROKEN}. This is the case on Tektronix UTekV,
5061 Amdahl UTS and Motorola System V/88.
5064 @defmac AC_HEADER_STDBOOL
5065 @acindex{HEADER_STDBOOL}
5066 @cvindex HAVE_STDBOOL_H
5068 @hdrindex{stdbool.h}
5070 If @file{stdbool.h} exists and conforms to C99, define
5071 @code{HAVE_STDBOOL_H} to 1; if the type @code{_Bool} is defined, define
5072 @code{HAVE__BOOL} to 1. To fulfill the C99 requirements, your
5073 @file{system.h} could contain the following code:
5077 # include <stdbool.h>
5083 # define _Bool signed char
5089 # define __bool_true_false_are_defined 1
5093 Alternatively you can use the @samp{stdbool} package of Gnulib
5094 (@pxref{Gnulib}); it packages the above code into a replacement header
5095 and contains a few other bells and whistles.
5100 @defmac AC_HEADER_STDC
5101 @acindex{HEADER_STDC}
5102 @cvindex STDC_HEADERS
5108 Define @code{STDC_HEADERS} if the system has C header files
5109 conforming to @acronym{ANSI} C89 (@acronym{ISO} C90).
5110 Specifically, this macro checks for @file{stdlib.h}, @file{stdarg.h},
5111 @file{string.h}, and @file{float.h}; if the system has those, it
5112 probably has the rest of the C89 header files. This macro also
5113 checks whether @file{string.h} declares @code{memchr} (and thus
5114 presumably the other @code{mem} functions), whether @file{stdlib.h}
5115 declare @code{free} (and thus presumably @code{malloc} and other related
5116 functions), and whether the @file{ctype.h} macros work on characters
5117 with the high bit set, as the C standard requires.
5119 Nowadays this macro is becoming obsolete. However, if you use it, your
5120 code can refer to @code{STDC_HEADERS} instead of @code{__STDC__} to
5121 determine whether the system has conforming header files (and probably C
5122 library functions). This is useful if you worry about portability
5123 to ancient systems that lack C89 header files.
5126 @hdrindex{strings.h}
5127 Nowadays @file{string.h} is part of the C standard and declares functions like
5128 @code{strcpy}, and @file{strings.h} is standardized by Posix and declares
5129 @acronym{BSD} functions like @code{bcopy}; but
5130 historically, string functions were a major sticking point in this area.
5131 If you worry about portability to ancient systems without standard
5132 headers, there is so much variation
5133 that it is probably easier to declare the functions you use than to
5134 figure out exactly what the system header files declare. Some ancient systems
5135 contain a mix of functions from the C standard and from @acronym{BSD}; some are
5136 mostly standard but lack @samp{memmove}; some define the
5137 @acronym{BSD} functions as macros in @file{string.h} or
5138 @file{strings.h}; some have only the @acronym{BSD} functions but
5139 @file{string.h}; some declare the memory functions in @file{memory.h},
5140 some in @file{string.h}; etc. It is probably sufficient to check for
5141 one string function and one memory function; if the library has the
5142 standard versions of those then it probably has most of the others.
5143 If you put the following in @file{configure.ac}:
5147 AC_CHECK_FUNCS([strchr memcpy])
5151 then, in your code, you can use declarations like this:
5156 # include <string.h>
5159 # define strchr index
5160 # define strrchr rindex
5162 char *strchr (), *strrchr ();
5164 # define memcpy(d, s, n) bcopy ((s), (d), (n))
5165 # define memmove(d, s, n) bcopy ((s), (d), (n))
5172 If you use a function like @code{memchr}, @code{memset}, @code{strtok},
5173 or @code{strspn}, which have no @acronym{BSD} equivalent, then macros won't
5174 suffice; you must provide an implementation of each function. An easy
5175 way to incorporate your implementations only when needed (since the ones
5176 in system C libraries may be hand optimized) is to, taking @code{memchr}
5177 for example, put it in @file{memchr.c} and use
5178 @samp{AC_REPLACE_FUNCS([memchr])}.
5181 @defmac AC_HEADER_SYS_WAIT
5182 @acindex{HEADER_SYS_WAIT}
5183 @cvindex HAVE_SYS_WAIT_H
5184 @hdrindex{sys/wait.h}
5185 If @file{sys/wait.h} exists and is compatible with Posix, define
5186 @code{HAVE_SYS_WAIT_H}. Incompatibility can occur if @file{sys/wait.h}
5187 does not exist, or if it uses the old @acronym{BSD} @code{union wait} instead
5188 of @code{int} to store a status value. If @file{sys/wait.h} is not
5189 Posix compatible, then instead of including it, define the
5190 Posix macros with their usual interpretations. Here is an
5195 #include <sys/types.h>
5197 # include <sys/wait.h>
5200 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
5203 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
5209 @cvindex _POSIX_VERSION
5211 @code{_POSIX_VERSION} is defined when @file{unistd.h} is included on
5212 Posix systems. If there is no @file{unistd.h}, it is definitely
5213 not a Posix system. However, some non-Posix systems do
5214 have @file{unistd.h}.
5216 The way to check whether the system supports Posix is:
5221 # include <sys/types.h>
5222 # include <unistd.h>
5225 #ifdef _POSIX_VERSION
5226 /* Code for Posix systems. */
5231 @defmac AC_HEADER_TIME
5232 @acindex{HEADER_TIME}
5233 @cvindex TIME_WITH_SYS_TIME
5235 @hdrindex{sys/time.h}
5236 If a program may include both @file{time.h} and @file{sys/time.h},
5237 define @code{TIME_WITH_SYS_TIME}. On some older systems,
5238 @file{sys/time.h} includes @file{time.h}, but @file{time.h} is not
5239 protected against multiple inclusion, so programs should not explicitly
5240 include both files. This macro is useful in programs that use, for
5241 example, @code{struct timeval} as well as
5242 @code{struct tm}. It is best used in conjunction with
5243 @code{HAVE_SYS_TIME_H}, which can be checked for using
5244 @code{AC_CHECK_HEADERS([sys/time.h])}.
5248 #if TIME_WITH_SYS_TIME
5249 # include <sys/time.h>
5252 # if HAVE_SYS_TIME_H
5253 # include <sys/time.h>
5263 @defmac AC_HEADER_TIOCGWINSZ
5264 @acindex{HEADER_TIOCGWINSZ}
5265 @cvindex GWINSZ_IN_SYS_IOCTL
5266 @hdrindex{sys/ioctl.h}
5267 @hdrindex{termios.h}
5268 @c FIXME: I need clarifications from Jim.
5269 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
5270 define @code{GWINSZ_IN_SYS_IOCTL}. Otherwise @code{TIOCGWINSZ} can be
5271 found in @file{<termios.h>}.
5278 # include <termios.h>
5281 #if GWINSZ_IN_SYS_IOCTL
5282 # include <sys/ioctl.h>
5288 @node Generic Headers
5289 @subsection Generic Header Checks
5291 These macros are used to find system header files not covered by the
5292 ``particular'' test macros. If you need to check the contents of a header
5293 as well as find out whether it is present, you have to write your own
5294 test for it (@pxref{Writing Tests}).
5296 @defmac AC_CHECK_HEADER (@var{header-file}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5297 @acindex{CHECK_HEADER}
5298 If the system header file @var{header-file} is compilable, execute shell
5299 commands @var{action-if-found}, otherwise execute
5300 @var{action-if-not-found}. If you just want to define a symbol if the
5301 header file is available, consider using @code{AC_CHECK_HEADERS}
5304 For compatibility issues with older versions of Autoconf, please read
5308 @defmac AC_CHECK_HEADERS (@var{header-file}@dots{}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5309 @acindex{CHECK_HEADERS}
5310 @cvindex HAVE_@var{header}
5311 For each given system header file @var{header-file} in the
5312 blank-separated argument list that exists, define
5313 @code{HAVE_@var{header-file}} (in all capitals). If @var{action-if-found}
5314 is given, it is additional shell code to execute when one of the header
5315 files is found. You can give it a value of @samp{break} to break out of
5316 the loop on the first match. If @var{action-if-not-found} is given, it
5317 is executed when one of the header files is not found.
5319 For compatibility issues with older versions of Autoconf, please read
5323 Previous versions of Autoconf merely checked whether the header was
5324 accepted by the preprocessor. This was changed because the old test was
5325 inappropriate for typical uses. Headers are typically used to compile,
5326 not merely to preprocess, and the old behavior sometimes accepted
5327 headers that clashed at compile-time. If you need to check whether a
5328 header is preprocessable, you can use @code{AC_PREPROC_IFELSE}
5329 (@pxref{Running the Preprocessor}).
5331 This scheme, which improves the robustness of the test, also requires
5332 that you make sure that headers that must be included before the
5333 @var{header-file} be part of the @var{includes}, (@pxref{Default
5334 Includes}). If looking for @file{bar.h}, which requires that
5335 @file{foo.h} be included before if it exists, we suggest the following
5339 AC_CHECK_HEADERS([foo.h])
5340 AC_CHECK_HEADERS([bar.h], [], [],
5347 The following variant generates smaller, faster @command{configure}
5348 files if you do not need the full power of @code{AC_CHECK_HEADERS}.
5350 @defmac AC_CHECK_HEADERS_ONCE (@var{header-file}@dots{})
5351 @acindex{CHECK_HEADERS_ONCE}
5352 @cvindex HAVE_@var{header}
5353 For each given system header file @var{header-file} in the
5354 blank-separated argument list that exists, define
5355 @code{HAVE_@var{header-file}} (in all capitals).
5356 This is a once-only variant of @code{AC_CHECK_HEADERS}. It generates the
5357 checking code at most once, so that @command{configure} is smaller and
5358 faster; but the checks cannot be conditionalized and are always done once,
5359 early during the @command{configure} run.
5363 @section Declarations
5364 @cindex Declaration, checking
5366 The following macros check for the declaration of variables and
5367 functions. If there is no macro specifically defined to check for a
5368 symbol you need, then you can use the general macros (@pxref{Generic
5369 Declarations}) or, for more complex tests, you may use
5370 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
5373 * Particular Declarations:: Macros to check for certain declarations
5374 * Generic Declarations:: How to find other declarations
5377 @node Particular Declarations
5378 @subsection Particular Declaration Checks
5380 There are no specific macros for declarations.
5382 @node Generic Declarations
5383 @subsection Generic Declaration Checks
5385 These macros are used to find declarations not covered by the ``particular''
5388 @defmac AC_CHECK_DECL (@var{symbol}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5389 @acindex{CHECK_DECL}
5390 If @var{symbol} (a function or a variable) is not declared in
5391 @var{includes} and a declaration is needed, run the shell commands
5392 @var{action-if-not-found}, otherwise @var{action-if-found}. If no
5393 @var{includes} are specified, the default includes are used
5394 (@pxref{Default Includes}).
5396 This macro actually tests whether it is valid to use @var{symbol} as an
5397 r-value, not if it is really declared, because it is much safer to avoid
5398 introducing extra declarations when they are not needed.
5401 @defmac AC_CHECK_DECLS (@var{symbols}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5402 @acindex{CHECK_DECLS}
5403 @cvindex HAVE_DECL_@var{symbol}
5404 For each of the @var{symbols} (@emph{comma}-separated list), define
5405 @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
5406 @var{symbol} is declared, otherwise to @samp{0}. If
5407 @var{action-if-not-found} is given, it is additional shell code to
5408 execute when one of the function declarations is needed, otherwise
5409 @var{action-if-found} is executed.
5411 This macro uses an m4 list as first argument:
5413 AC_CHECK_DECLS([strdup])
5414 AC_CHECK_DECLS([strlen])
5415 AC_CHECK_DECLS([malloc, realloc, calloc, free])
5418 Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not
5419 declared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} instead
5420 of leaving @code{HAVE_DECL_@var{symbol}} undeclared. When you are
5421 @emph{sure} that the check was performed, use
5422 @code{HAVE_DECL_@var{symbol}} just like any other result of Autoconf:
5425 #if !HAVE_DECL_SYMBOL
5426 extern char *symbol;
5431 If the test may have not been performed, however, because it is safer
5432 @emph{not} to declare a symbol than to use a declaration that conflicts
5433 with the system's one, you should use:
5436 #if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
5437 void *malloc (size_t *s);
5442 You fall into the second category only in extreme situations: either
5443 your files may be used without being configured, or they are used during
5444 the configuration. In most cases the traditional approach is enough.
5447 @defmac AC_CHECK_DECLS_ONCE (@var{symbols})
5448 @acindex{CHECK_DECLS_ONCE}
5449 @cvindex HAVE_DECL_@var{symbol}
5450 For each of the @var{symbols} (@emph{comma}-separated list), define
5451 @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
5452 @var{symbol} is declared in the default include files, otherwise to
5453 @samp{0}. This is a once-only variant of @code{AC_CHECK_DECLS}. It
5454 generates the checking code at most once, so that @command{configure} is
5455 smaller and faster; but the checks cannot be conditionalized and are
5456 always done once, early during the @command{configure} run.
5462 @cindex Structure, checking
5464 The following macros check for the presence of certain members in C
5465 structures. If there is no macro specifically defined to check for a
5466 member you need, then you can use the general structure-member macros
5467 (@pxref{Generic Structures}) or, for more complex tests, you may use
5468 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
5471 * Particular Structures:: Macros to check for certain structure members
5472 * Generic Structures:: How to find other structure members
5475 @node Particular Structures
5476 @subsection Particular Structure Checks
5478 The following macros check for certain structures or structure members.
5480 @defmac AC_STRUCT_DIRENT_D_INO
5481 @acindex{STRUCT_DIRENT_D_INO}
5482 @cvindex HAVE_STRUCT_DIRENT_D_INO
5483 Perform all the actions of @code{AC_HEADER_DIRENT} (@pxref{Particular
5484 Headers}). Then, if @code{struct dirent} contains a @code{d_ino}
5485 member, define @code{HAVE_STRUCT_DIRENT_D_INO}.
5487 @code{HAVE_STRUCT_DIRENT_D_INO} indicates only the presence of
5488 @code{d_ino}, not whether its contents are always reliable.
5489 Traditionally, a zero @code{d_ino} indicated a deleted directory entry,
5490 though modern systems hide this detail from the user and never return
5491 zero @code{d_ino} values.
5494 @defmac AC_STRUCT_DIRENT_D_TYPE
5495 @acindex{STRUCT_DIRENT_D_TYPE}
5496 @cvindex HAVE_STRUCT_DIRENT_D_TYPE
5497 Perform all the actions of @code{AC_HEADER_DIRENT} (@pxref{Particular
5498 Headers}). Then, if @code{struct dirent} contains a @code{d_type}
5499 member, define @code{HAVE_STRUCT_DIRENT_D_TYPE}.
5502 @defmac AC_STRUCT_ST_BLKSIZE
5503 @acindex{STRUCT_ST_BLKSIZE}
5504 @cvindex HAVE_STRUCT_STAT_ST_BLKSIZE
5505 @cvindex HAVE_ST_BLKSIZE
5506 If @code{struct stat} contains an @code{st_blksize} member, define
5507 @code{HAVE_STRUCT_STAT_ST_BLKSIZE}. The former name,
5508 @code{HAVE_ST_BLKSIZE} is to be avoided, as its support will cease in
5509 the future. This macro is obsoleted, and should be replaced by
5512 AC_CHECK_MEMBERS([struct stat.st_blksize])
5516 @defmac AC_STRUCT_ST_BLOCKS
5517 @acindex{STRUCT_ST_BLOCKS}
5518 @cvindex HAVE_STRUCT_STAT_ST_BLOCKS
5519 @cvindex HAVE_ST_BLOCKS
5521 If @code{struct stat} contains an @code{st_blocks} member, define
5522 @code{HAVE_STRUCT_STAT_ST_BLOCKS}. Otherwise, require an
5523 @code{AC_LIBOBJ} replacement of @samp{fileblocks}. The former name,
5524 @code{HAVE_ST_BLOCKS} is to be avoided, as its support will cease in the
5528 @defmac AC_STRUCT_ST_RDEV
5529 @acindex{STRUCT_ST_RDEV}
5530 @cvindex HAVE_ST_RDEV
5531 @cvindex HAVE_STRUCT_STAT_ST_RDEV
5532 If @code{struct stat} contains an @code{st_rdev} member, define
5533 @code{HAVE_STRUCT_STAT_ST_RDEV}. The former name for this macro,
5534 @code{HAVE_ST_RDEV}, is to be avoided as it will cease to be supported
5535 in the future. Actually, even the new macro is obsolete and should be
5538 AC_CHECK_MEMBERS([struct stat.st_rdev])
5542 @defmac AC_STRUCT_TM
5544 @cvindex TM_IN_SYS_TIME
5546 @hdrindex{sys/time.h}
5547 If @file{time.h} does not define @code{struct tm}, define
5548 @code{TM_IN_SYS_TIME}, which means that including @file{sys/time.h}
5549 had better define @code{struct tm}.
5552 @defmac AC_STRUCT_TIMEZONE
5553 @acindex{STRUCT_TIMEZONE}
5554 @cvindex HAVE_TM_ZONE
5555 @cvindex HAVE_TZNAME
5556 Figure out how to get the current timezone. If @code{struct tm} has a
5557 @code{tm_zone} member, define @code{HAVE_STRUCT_TM_TM_ZONE} (and the
5558 obsoleted @code{HAVE_TM_ZONE}). Otherwise, if the external array
5559 @code{tzname} is found, define @code{HAVE_TZNAME}; if it is declared,
5560 define @code{HAVE_DECL_TZNAME}.
5563 @node Generic Structures
5564 @subsection Generic Structure Checks
5566 These macros are used to find structure members not covered by the
5567 ``particular'' test macros.
5569 @defmac AC_CHECK_MEMBER (@var{aggregate}.@var{member}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5570 @acindex{CHECK_MEMBER}
5571 Check whether @var{member} is a member of the aggregate @var{aggregate}.
5572 If no @var{includes} are specified, the default includes are used
5573 (@pxref{Default Includes}).
5576 AC_CHECK_MEMBER([struct passwd.pw_gecos], [],
5577 [AC_MSG_ERROR([We need `passwd.pw_gecos'!])],
5581 You can use this macro for sub-members:
5584 AC_CHECK_MEMBER(struct top.middle.bot)
5588 @defmac AC_CHECK_MEMBERS (@var{members}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5589 @acindex{CHECK_MEMBERS}
5590 Check for the existence of each @samp{@var{aggregate}.@var{member}} of
5591 @var{members} using the previous macro. When @var{member} belongs to
5592 @var{aggregate}, define @code{HAVE_@var{aggregate}_@var{member}} (in all
5593 capitals, with spaces and dots replaced by underscores). If
5594 @var{action-if-found} is given, it is executed for each of the found
5595 members. If @var{action-if-not-found} is given, it is executed for each
5596 of the members that could not be found.
5598 This macro uses m4 lists:
5600 AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize])
5610 The following macros check for C types, either builtin or typedefs. If
5611 there is no macro specifically defined to check for a type you need, and
5612 you don't need to check for any special properties of it, then you can
5613 use a general type-check macro.
5616 * Particular Types:: Special handling to find certain types
5617 * Generic Types:: How to find other types
5620 @node Particular Types
5621 @subsection Particular Type Checks
5623 @hdrindex{sys/types.h}
5626 @hdrindex{inttypes.h}
5627 These macros check for particular C types in @file{sys/types.h},
5628 @file{stdlib.h}, @file{stdint.h}, @file{inttypes.h} and others, if they
5631 The Gnulib @code{stdint} module is an alternate way to define many of
5632 these symbols; it is useful if you prefer your code to assume a
5633 C99-or-better environment. @xref{Gnulib}.
5635 @defmac AC_TYPE_GETGROUPS
5636 @acindex{TYPE_GETGROUPS}
5637 @cvindex GETGROUPS_T
5638 Define @code{GETGROUPS_T} to be whichever of @code{gid_t} or @code{int}
5639 is the base type of the array argument to @code{getgroups}.
5642 @defmac AC_TYPE_INT8_T
5643 @acindex{TYPE_INT8_T}
5644 @cvindex HAVE_INT8_T
5646 If @file{stdint.h} or @file{inttypes.h} defines the type @code{int8_t},
5647 define @code{HAVE_INT8_T}. Otherwise, define @code{int8_t} to a signed
5648 integer type that is exactly 8 bits wide and that uses two's complement
5649 representation, if such a type exists.
5652 @defmac AC_TYPE_INT16_T
5653 @acindex{TYPE_INT16_T}
5654 @cvindex HAVE_INT16_T
5656 This is like @code{AC_TYPE_INT8_T}, except for 16-bit integers.
5659 @defmac AC_TYPE_INT32_T
5660 @acindex{TYPE_INT32_T}
5661 @cvindex HAVE_INT32_T
5663 This is like @code{AC_TYPE_INT8_T}, except for 32-bit integers.
5666 @defmac AC_TYPE_INT64_T
5667 @acindex{TYPE_INT64_T}
5668 @cvindex HAVE_INT64_T
5670 This is like @code{AC_TYPE_INT8_T}, except for 64-bit integers.
5673 @defmac AC_TYPE_INTMAX_T
5674 @acindex{TYPE_INTMAX_T}
5675 @cvindex HAVE_INTMAX_T
5677 If @file{stdint.h} or @file{inttypes.h} defines the type @code{intmax_t},
5678 define @code{HAVE_INTMAX_T}. Otherwise, define @code{intmax_t} to the
5679 widest signed integer type.
5682 @defmac AC_TYPE_INTPTR_T
5683 @acindex{TYPE_INTPTR_T}
5684 @cvindex HAVE_INTPTR_T
5686 If @file{stdint.h} or @file{inttypes.h} defines the type @code{intptr_t},
5687 define @code{HAVE_INTPTR_T}. Otherwise, define @code{intptr_t} to a
5688 signed integer type wide enough to hold a pointer, if such a type
5692 @defmac AC_TYPE_LONG_DOUBLE
5693 @acindex{TYPE_LONG_DOUBLE}
5694 @cvindex HAVE_LONG_DOUBLE
5695 If the C compiler supports a working @code{long double} type, define
5696 @code{HAVE_LONG_DOUBLE}. The @code{long double} type might have the
5697 same range and precision as @code{double}.
5700 @defmac AC_TYPE_LONG_DOUBLE_WIDER
5701 @acindex{TYPE_LONG_DOUBLE_WIDER}
5702 @cvindex HAVE_LONG_DOUBLE_WIDER
5703 If the C compiler supports a working @code{long double} type with more
5704 range or precision than the @code{double} type, define
5705 @code{HAVE_LONG_DOUBLE_WIDER}.
5708 @defmac AC_TYPE_LONG_LONG_INT
5709 @acindex{TYPE_LONG_LONG_INT}
5710 @cvindex HAVE_LONG_LONG_INT
5711 If the C compiler supports a working @code{long long int} type, define
5712 @code{HAVE_LONG_LONG_INT}.
5715 @defmac AC_TYPE_MBSTATE_T
5716 @acindex{TYPE_MBSTATE_T}
5719 Define @code{HAVE_MBSTATE_T} if @code{<wchar.h>} declares the
5720 @code{mbstate_t} type. Also, define @code{mbstate_t} to be a type if
5721 @code{<wchar.h>} does not declare it.
5724 @defmac AC_TYPE_MODE_T
5725 @acindex{TYPE_MODE_T}
5727 Define @code{mode_t} to a suitable type, if standard headers do not
5731 @defmac AC_TYPE_OFF_T
5732 @acindex{TYPE_OFF_T}
5734 Define @code{off_t} to a suitable type, if standard headers do not
5738 @defmac AC_TYPE_PID_T
5739 @acindex{TYPE_PID_T}
5741 Define @code{pid_t} to a suitable type, if standard headers do not
5745 @defmac AC_TYPE_SIGNAL
5746 @acindex{TYPE_SIGNAL}
5749 If @file{signal.h} declares @code{signal} as returning a pointer to a
5750 function returning @code{void}, define @code{RETSIGTYPE} to be
5751 @code{void}; otherwise, define it to be @code{int}.
5753 Define signal handlers as returning type @code{RETSIGTYPE}:
5766 @defmac AC_TYPE_SIZE_T
5767 @acindex{TYPE_SIZE_T}
5769 Define @code{size_t} to a suitable type, if standard headers do not
5773 @defmac AC_TYPE_SSIZE_T
5774 @acindex{TYPE_SSIZE_T}
5776 Define @code{ssize_t} to a suitable type, if standard headers do not
5780 @defmac AC_TYPE_UID_T
5781 @acindex{TYPE_UID_T}
5784 Define @code{uid_t} and @code{gid_t} to suitable types, if standard
5785 headers do not define them.
5788 @defmac AC_TYPE_UINT8_T
5789 @acindex{TYPE_UINT8_T}
5790 @cvindex HAVE_UINT8_T
5792 If @file{stdint.h} or @file{inttypes.h} defines the type @code{uint8_t},
5793 define @code{HAVE_UINT8_T}. Otherwise, define @code{uint8_t} to an
5794 unsigned integer type that is exactly 8 bits wide, if such a type
5798 @defmac AC_TYPE_UINT16_T
5799 @acindex{TYPE_UINT16_T}
5800 @cvindex HAVE_UINT16_T
5802 This is like @code{AC_TYPE_UINT8_T}, except for 16-bit unsigned integers.
5805 @defmac AC_TYPE_UINT32_T
5806 @acindex{TYPE_UINT32_T}
5807 @cvindex HAVE_UINT32_T
5809 This is like @code{AC_TYPE_UINT8_T}, except for 32-bit unsigned integers.
5812 @defmac AC_TYPE_UINT64_T
5813 @acindex{TYPE_UINT64_T}
5814 @cvindex HAVE_UINT64_T
5816 This is like @code{AC_TYPE_UINT8_T}, except for 64-bit unsigned integers.
5819 @defmac AC_TYPE_UINTMAX_T
5820 @acindex{TYPE_UINTMAX_T}
5821 @cvindex HAVE_UINTMAX_T
5823 If @file{stdint.h} or @file{inttypes.h} defines the type @code{uintmax_t},
5824 define @code{HAVE_UINTMAX_T}. Otherwise, define @code{uintmax_t} to the
5825 widest unsigned integer type.
5828 @defmac AC_TYPE_UINTPTR_T
5829 @acindex{TYPE_UINTPTR_T}
5830 @cvindex HAVE_UINTPTR_T
5832 If @file{stdint.h} or @file{inttypes.h} defines the type @code{uintptr_t},
5833 define @code{HAVE_UINTPTR_T}. Otherwise, define @code{uintptr_t} to an
5834 unsigned integer type wide enough to hold a pointer, if such a type
5838 @defmac AC_TYPE_UNSIGNED_LONG_LONG_INT
5839 @acindex{TYPE_UNSIGNED_LONG_LONG_INT}
5840 @cvindex HAVE_UNSIGNED_LONG_LONG_INT
5841 If the C compiler supports a working @code{unsigned long long int} type,
5842 define @code{HAVE_UNSIGNED_LONG_LONG_INT}.
5846 @subsection Generic Type Checks
5848 These macros are used to check for types not covered by the ``particular''
5851 @defmac AC_CHECK_TYPE (@var{type}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5852 @acindex{CHECK_TYPE}
5853 Check whether @var{type} is defined. It may be a compiler builtin type
5854 or defined by the @var{includes} (@pxref{Default Includes}).
5858 @defmac AC_CHECK_TYPES (@var{types}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5859 @acindex{CHECK_TYPES}
5860 For each @var{type} of the @var{types} that is defined, define
5861 @code{HAVE_@var{type}} (in all capitals). If no @var{includes} are
5862 specified, the default includes are used (@pxref{Default Includes}). If
5863 @var{action-if-found} is given, it is additional shell code to execute
5864 when one of the types is found. If @var{action-if-not-found} is given,
5865 it is executed when one of the types is not found.
5867 This macro uses m4 lists:
5869 AC_CHECK_TYPES([ptrdiff_t])
5870 AC_CHECK_TYPES([unsigned long long int, uintmax_t])
5875 Autoconf, up to 2.13, used to provide to another version of
5876 @code{AC_CHECK_TYPE}, broken by design. In order to keep backward
5877 compatibility, a simple heuristics, quite safe but not totally, is
5878 implemented. In case of doubt, read the documentation of the former
5879 @code{AC_CHECK_TYPE}, see @ref{Obsolete Macros}.
5882 @node Compilers and Preprocessors
5883 @section Compilers and Preprocessors
5885 @cindex Preprocessors
5888 All the tests for compilers (@code{AC_PROG_CC}, @code{AC_PROG_CXX},
5889 @code{AC_PROG_F77}) define the output variable @code{EXEEXT} based on
5890 the output of the compiler, typically to the empty string if
5891 Posix and @samp{.exe} if a @acronym{DOS} variant.
5894 They also define the output variable @code{OBJEXT} based on the
5895 output of the compiler, after @file{.c} files have been excluded, typically
5896 to @samp{o} if Posix, @samp{obj} if a @acronym{DOS} variant.
5898 If the compiler being used does not produce executables, the tests fail. If
5899 the executables can't be run, and cross-compilation is not enabled, they
5900 fail too. @xref{Manual Configuration}, for more on support for cross
5904 * Specific Compiler Characteristics:: Some portability issues
5905 * Generic Compiler Characteristics:: Language independent tests and features
5906 * C Compiler:: Checking its characteristics
5907 * C++ Compiler:: Likewise
5908 * Objective C Compiler:: Likewise
5909 * Erlang Compiler and Interpreter:: Likewise
5910 * Fortran Compiler:: Likewise
5913 @node Specific Compiler Characteristics
5914 @subsection Specific Compiler Characteristics
5916 Some compilers exhibit different behaviors.
5919 @item Static/Dynamic Expressions
5920 Autoconf relies on a trick to extract one bit of information from the C
5921 compiler: using negative array sizes. For instance the following
5922 excerpt of a C source demonstrates how to test whether @samp{int}s are 4
5929 static int test_array [sizeof (int) == 4 ? 1 : -1];
5936 To our knowledge, there is a single compiler that does not support this
5937 trick: the HP C compilers (the real one, not only the ``bundled'') on
5938 HP-UX 11.00. They incorrectly reject the above program with the diagnostic
5939 ``Variable-length arrays cannot have static storage.''
5940 This bug comes from HP compilers' mishandling of @code{sizeof (int)},
5941 not from the @code{? 1 : -1}, and
5942 Autoconf works around this problem by casting @code{sizeof (int)} to
5943 @code{long int} before comparing it.
5946 @node Generic Compiler Characteristics
5947 @subsection Generic Compiler Characteristics
5949 @defmac AC_CHECK_SIZEOF (@var{type}, @ovar{unused}, @dvar{includes, default-includes})
5950 @acindex{CHECK_SIZEOF}
5951 Define @code{SIZEOF_@var{type}} (@pxref{Standard Symbols}) to be the
5952 size in bytes of @var{type}. If @samp{type} is unknown, it gets a size
5953 of 0. If no @var{includes} are specified, the default includes are used
5954 (@pxref{Default Includes}). If you provide @var{include}, be sure to
5955 include @file{stdio.h} which is required for this macro to run.
5957 This macro now works even when cross-compiling. The @var{unused}
5958 argument was used when cross-compiling.
5960 For example, the call
5963 AC_CHECK_SIZEOF([int *])
5967 defines @code{SIZEOF_INT_P} to be 8 on DEC Alpha AXP systems.
5970 @defmac AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, default-includes})
5971 @acindex{CHECK_ALIGNOF}
5972 Define @code{ALIGNOF_@var{type}} (@pxref{Standard Symbols}) to be the
5973 alignment in bytes of @var{type}. If @samp{type} is unknown, it gets a size
5974 of 0. If no @var{includes} are specified, the default includes are used
5975 (@pxref{Default Includes}). If you provide @var{include}, be sure to
5976 include @file{stddef.h} and @file{stdio.h} which are required for this
5977 macro to work correctly.
5980 @defmac AC_LANG_WERROR
5981 @acindex{LANG_WERROR}
5982 Normally Autoconf ignores warnings generated by the compiler, linker, and
5983 preprocessor. If this macro is used, warnings will be treated as fatal
5984 errors instead for the current language. This macro is useful when the
5985 results of configuration will be used where warnings are unacceptable; for
5986 instance, if parts of a program are built with the GCC @samp{-Werror}
5987 option. If the whole program will be built using @samp{-Werror} it is
5988 often simpler to put @samp{-Werror} in the compiler flags (@code{CFLAGS},
5993 @subsection C Compiler Characteristics
5995 The following macros provide ways to find and exercise a C Compiler.
5996 There are a few constructs that ought to be avoided, but do not deserve
5997 being checked for, since they can easily be worked around.
6000 @item Don't use lines containing solitary backslashes
6001 They tickle a bug in the HP-UX C compiler (checked on HP-UX 10.20,
6002 11.00, and 11i). When given the following source:
6007 * A comment with backslash-newlines in it. %@{ %@} *\
6011 " A string with backslash-newlines in it %@{ %@} \\
6013 char apostrophe = '\\
6021 the compiler incorrectly fails with the diagnostics ``Non-terminating
6022 comment at end of file'' and ``Missing @samp{#endif} at end of file.''
6023 Removing the lines with solitary backslashes solves the problem.
6025 @item Don't compile several files at once if output matters to you
6026 Some compilers, such as the HP's, reports the name of the file it is
6027 compiling @emph{when} they are several. For instance:
6036 This can cause problems if you observe the output of the compiler to
6037 detect failures. Invoking @samp{cc -c a.c && cc -c b.c && cc -o c a.o
6038 b.o} solves the issue.
6040 @item Don't rely on @code{#error} failing
6041 The @sc{irix} C compiler does not fail when #error is preprocessed; it
6042 simply emits a diagnostic and continues, exiting successfully. So,
6043 instead of an error directive like @code{#error "Unsupported word size"}
6044 it is more portable to use an invalid directive like @code{#Unsupported
6045 word size} in Autoconf tests. In ordinary source code, @code{#error} is
6046 OK, since installers with inadequate compilers like @sc{irix} can simply
6047 examine these compilers' diagnostic output.
6049 @item Don't rely on correct @code{#line} support
6050 On Solaris 8, @command{c89} (Sun WorkShop 6 update 2 C 5.3 Patch
6051 111679-08 2002/05/09)) diagnoses @code{#line} directives whose line
6052 numbers are greater than 32767. In addition, nothing in Posix
6053 makes this invalid. That is why Autoconf stopped issuing
6054 @code{#line} directives.
6057 @defmac AC_PROG_CC (@ovar{compiler-search-list})
6061 Determine a C compiler to use. If @code{CC} is not already set in the
6062 environment, check for @code{gcc} and @code{cc}, then for other C
6063 compilers. Set output variable @code{CC} to the name of the compiler
6066 This macro may, however, be invoked with an optional first argument
6067 which, if specified, must be a blank-separated list of C compilers to
6068 search for. This just gives the user an opportunity to specify an
6069 alternative search list for the C compiler. For example, if you didn't
6070 like the default order, then you could invoke @code{AC_PROG_CC} like
6074 AC_PROG_CC([gcc cl cc])
6077 If the C compiler does not handle function prototypes correctly by
6078 default, try to add an option to output variable @code{CC} to make it
6079 so. This macro tries various options that select standard-conformance
6080 modes on various systems.
6082 After calling this macro you can check whether the C compiler has been
6083 set to accept @acronym{ANSI} C89 (@acronym{ISO} C90); if not, the shell
6085 @code{ac_cv_prog_cc_c89} is set to @samp{no}. See also
6086 @code{AC_C_PROTOTYPES} below.
6088 If using the @acronym{GNU} C compiler, set shell variable @code{GCC} to
6089 @samp{yes}. If output variable @code{CFLAGS} was not already set, set
6090 it to @option{-g -O2} for the @acronym{GNU} C compiler (@option{-O2} on systems
6091 where GCC does not accept @option{-g}), or @option{-g} for other compilers.
6094 @defmac AC_PROG_CC_C_O
6095 @acindex{PROG_CC_C_O}
6096 @cvindex NO_MINUS_C_MINUS_O
6097 If the C compiler does not accept the @option{-c} and @option{-o} options
6098 simultaneously, define @code{NO_MINUS_C_MINUS_O}. This macro actually
6099 tests both the compiler found by @code{AC_PROG_CC}, and, if different,
6100 the first @code{cc} in the path. The test fails if one fails. This
6101 macro was created for @acronym{GNU} Make to choose the default C compilation
6109 Set output variable @code{CPP} to a command that runs the
6110 C preprocessor. If @samp{$CC -E} doesn't work, @file{/lib/cpp} is used.
6111 It is only portable to run @code{CPP} on files with a @file{.c}
6114 Some preprocessors don't indicate missing include files by the error
6115 status. For such preprocessors an internal variable is set that causes
6116 other macros to check the standard error from the preprocessor and
6117 consider the test failed if any warnings have been reported.
6118 For most preprocessors, though, warnings do not cause include-file
6119 tests to fail unless @code{AC_PROG_CPP_WERROR} is also specified.
6122 @defmac AC_PROG_CPP_WERROR
6123 @acindex{PROG_CPP_WERROR}
6125 This acts like @code{AC_PROG_CPP}, except it treats warnings from the
6126 preprocessor as errors even if the preprocessor exit status indicates
6127 success. This is useful for avoiding headers that generate mandatory
6128 warnings, such as deprecation notices.
6132 The following macros check for C compiler or machine architecture
6133 features. To check for characteristics not listed here, use
6134 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
6135 @code{AC_RUN_IFELSE} (@pxref{Runtime}).
6137 @defmac AC_PROG_CC_STDC
6138 @acindex{PROG_CC_STDC}
6139 If the C compiler cannot compile @acronym{ISO} Standard C (currently
6140 C99), try to add an option to output variable @code{CC} to make it work.
6141 If the compiler does not support C99, fall back to supporting
6142 @acronym{ANSI} C89 (@acronym{ISO} C90).
6144 After calling this macro you can check whether the C compiler has been
6145 set to accept Standard C; if not, the shell variable
6146 @code{ac_cv_prog_cc_stdc} is set to @samp{no}.
6149 @defmac AC_PROG_CC_C89
6150 @acindex{PROG_CC_C89}
6151 If the C compiler is not in @acronym{ANSI} C89 (@acronym{ISO} C90) mode by
6152 default, try to add an option to output variable @code{CC} to make it
6153 so. This macro tries various options that select @acronym{ANSI} C89 on
6154 some system or another. It considers the compiler to be in
6155 @acronym{ANSI} C89 mode if it handles function prototypes correctly.
6157 After calling this macro you can check whether the C compiler has been
6158 set to accept @acronym{ANSI} C89; if not, the shell variable
6159 @code{ac_cv_prog_cc_c89} is set to @samp{no}.
6161 This macro is called automatically by @code{AC_PROG_CC}.
6164 @defmac AC_PROG_CC_C99
6165 @acindex{PROG_CC_C99}
6166 If the C compiler is not in C99 mode by default, try to add an
6167 option to output variable @code{CC} to make it so. This macro tries
6168 various options that select C99 on some system or another. It
6169 considers the compiler to be in C99 mode if it handles @code{_Bool},
6170 flexible arrays, @code{inline}, @code{long long int}, mixed code and
6171 declarations, named initialization of structs, @code{restrict}, varargs
6172 macros, variable declarations in @code{for} loops and variable length
6175 After calling this macro you can check whether the C compiler has been
6176 set to accept C99; if not, the shell variable
6177 @code{ac_cv_prog_cc_c99} is set to @samp{no}.
6180 @defmac AC_C_BACKSLASH_A
6181 @acindex{HAVE_C_BACKSLASH_A}
6182 Define @samp{HAVE_C_BACKSLASH_A} to 1 if the C compiler understands
6186 @defmac AC_C_BIGENDIAN (@ovar{action-if-true}, @ovar{action-if-false}, @ovar{action-if-unknown})
6187 @acindex{C_BIGENDIAN}
6188 @cvindex WORDS_BIGENDIAN
6190 If words are stored with the most significant byte first (like Motorola
6191 and SPARC CPUs), execute @var{action-if-true}. If words are stored with
6192 the least significant byte first (like Intel and VAX CPUs), execute
6193 @var{action-if-false}.
6195 This macro runs a test-case if endianness cannot be determined from the
6196 system header files. When cross-compiling, the test-case is not run but
6197 grep'ed for some magic values. @var{action-if-unknown} is executed if
6198 the latter case fails to determine the byte sex of the host system.
6200 The default for @var{action-if-true} is to define
6201 @samp{WORDS_BIGENDIAN}. The default for @var{action-if-false} is to do
6202 nothing. And finally, the default for @var{action-if-unknown} is to
6203 abort configure and tell the installer which variable he should preset
6204 to bypass this test.
6210 If the C compiler does not fully support the @code{const} keyword,
6211 define @code{const} to be empty. Some C compilers that do
6212 not define @code{__STDC__} do support @code{const}; some compilers that
6213 define @code{__STDC__} do not completely support @code{const}. Programs
6214 can simply use @code{const} as if every C compiler supported it; for
6215 those that don't, the @file{Makefile} or configuration header file will
6218 Occasionally installers use a C++ compiler to compile C code, typically
6219 because they lack a C compiler. This causes problems with @code{const},
6220 because C and C++ treat @code{const} differently. For example:
6227 is valid in C but not in C++. These differences unfortunately cannot be
6228 papered over by defining @code{const} to be empty.
6230 If @command{autoconf} detects this situation, it leaves @code{const} alone,
6231 as this generally yields better results in practice. However, using a
6232 C++ compiler to compile C code is not recommended or supported, and
6233 installers who run into trouble in this area should get a C compiler
6234 like GCC to compile their C code.
6237 @defmac AC_C_RESTRICT
6238 @acindex{C_RESTRICT}
6240 If the C compiler recognizes the @code{restrict} keyword, don't do anything.
6241 If it recognizes only a variant spelling (@code{__restrict},
6242 @code{__restrict__}, or @code{_Restrict}), then define
6243 @code{restrict} to that.
6244 Otherwise, define @code{restrict} to be empty.
6245 Thus, programs may simply use @code{restrict} as if every C compiler
6246 supported it; for those that do not, the @file{Makefile}
6247 or configuration header defines it away.
6249 Although support in C++ for the @code{restrict} keyword is not
6250 required, several C++ compilers do accept the keyword.
6251 This macro works for them, too.
6254 @defmac AC_C_VOLATILE
6255 @acindex{C_VOLATILE}
6257 If the C compiler does not understand the keyword @code{volatile},
6258 define @code{volatile} to be empty. Programs can simply use
6259 @code{volatile} as if every C compiler supported it; for those that do
6260 not, the @file{Makefile} or configuration header will define it as
6263 If the correctness of your program depends on the semantics of
6264 @code{volatile}, simply defining it to be empty does, in a sense, break
6265 your code. However, given that the compiler does not support
6266 @code{volatile}, you are at its mercy anyway. At least your
6267 program will compile, when it wouldn't before.
6269 In general, the @code{volatile} keyword is a standard C feature, so
6270 you might expect that @code{volatile} is available only when
6271 @code{__STDC__} is defined. However, Ultrix 4.3's native compiler does
6272 support volatile, but does not define @code{__STDC__}.
6278 If the C compiler supports the keyword @code{inline}, do nothing.
6279 Otherwise define @code{inline} to @code{__inline__} or @code{__inline}
6280 if it accepts one of those, otherwise define @code{inline} to be empty.
6283 @defmac AC_C_CHAR_UNSIGNED
6284 @acindex{C_CHAR_UNSIGNED}
6285 @cvindex __CHAR_UNSIGNED__
6286 If the C type @code{char} is unsigned, define @code{__CHAR_UNSIGNED__},
6287 unless the C compiler predefines it.
6290 @defmac AC_C_STRINGIZE
6291 @acindex{C_STRINGIZE}
6292 @cvindex HAVE_STRINGIZE
6293 If the C preprocessor supports the stringizing operator, define
6294 @code{HAVE_STRINGIZE}. The stringizing operator is @samp{#} and is
6295 found in macros such as this:
6304 @cvindex HAVE_TYPEOF
6306 If the C compiler supports GCC's @code{typeof} syntax either directly or
6307 through a different spelling of the keyword (e.g., @code{__typeof__}),
6308 define @code{HAVE_TYPEOF}. If the support is available only through a
6309 different spelling, define @code{typeof} to that spelling.
6312 @defmac AC_C_PROTOTYPES
6313 @acindex{C_PROTOTYPES}
6315 @cvindex __PROTOTYPES
6317 If function prototypes are understood by the compiler (as determined by
6318 @code{AC_PROG_CC}), define @code{PROTOTYPES} and @code{__PROTOTYPES}.
6319 Defining @code{__PROTOTYPES} is for the benefit of
6320 header files that cannot use macros that infringe on user name space.
6323 @defmac AC_PROG_GCC_TRADITIONAL
6324 @acindex{PROG_GCC_TRADITIONAL}
6326 Add @option{-traditional} to output variable @code{CC} if using the
6327 @acronym{GNU} C compiler and @code{ioctl} does not work properly without
6328 @option{-traditional}. That usually happens when the fixed header files
6329 have not been installed on an old system. Since recent versions of the
6330 @acronym{GNU} C compiler fix the header files automatically when installed,
6331 this macro is becoming obsolete.
6336 @subsection C++ Compiler Characteristics
6339 @defmac AC_PROG_CXX (@ovar{compiler-search-list})
6343 Determine a C++ compiler to use. Check whether the environment variable
6344 @code{CXX} or @code{CCC} (in that order) is set; if so, then set output
6345 variable @code{CXX} to its value.
6347 Otherwise, if the macro is invoked without an argument, then search for
6348 a C++ compiler under the likely names (first @code{g++} and @code{c++}
6349 then other names). If none of those checks succeed, then as a last
6350 resort set @code{CXX} to @code{g++}.
6352 This macro may, however, be invoked with an optional first argument
6353 which, if specified, must be a blank-separated list of C++ compilers to
6354 search for. This just gives the user an opportunity to specify an
6355 alternative search list for the C++ compiler. For example, if you
6356 didn't like the default order, then you could invoke @code{AC_PROG_CXX}
6360 AC_PROG_CXX([gcc cl KCC CC cxx cc++ xlC aCC c++ g++])
6363 If using the @acronym{GNU} C++ compiler, set shell variable @code{GXX} to
6364 @samp{yes}. If output variable @code{CXXFLAGS} was not already set, set
6365 it to @option{-g -O2} for the @acronym{GNU} C++ compiler (@option{-O2} on
6366 systems where G++ does not accept @option{-g}), or @option{-g} for other
6370 @defmac AC_PROG_CXXCPP
6371 @acindex{PROG_CXXCPP}
6373 Set output variable @code{CXXCPP} to a command that runs the C++
6374 preprocessor. If @samp{$CXX -E} doesn't work, @file{/lib/cpp} is used.
6375 It is portable to run @code{CXXCPP} only on files with a @file{.c},
6376 @file{.C}, @file{.cc}, or @file{.cpp} extension.
6378 Some preprocessors don't indicate missing include files by the error
6379 status. For such preprocessors an internal variable is set that causes
6380 other macros to check the standard error from the preprocessor and
6381 consider the test failed if any warnings have been reported. However,
6382 it is not known whether such broken preprocessors exist for C++.
6386 @node Objective C Compiler
6387 @subsection Objective C Compiler Characteristics
6390 @defmac AC_PROG_OBJC (@ovar{compiler-search-list})
6394 Determine an Objective C compiler to use. If @code{OBJC} is not already
6395 set in the environment, check for Objective C compilers. Set output
6396 variable @code{OBJC} to the name of the compiler found.
6398 This macro may, however, be invoked with an optional first argument
6399 which, if specified, must be a blank-separated list of Objective C compilers to
6400 search for. This just gives the user an opportunity to specify an
6401 alternative search list for the Objective C compiler. For example, if you
6402 didn't like the default order, then you could invoke @code{AC_PROG_OBJC}
6406 AC_PROG_OBJC([gcc objcc objc])
6409 If using the @acronym{GNU} Objective C compiler, set shell variable
6410 @code{GOBJC} to @samp{yes}. If output variable @code{OBJCFLAGS} was not
6411 already set, set it to @option{-g -O2} for the @acronym{GNU} Objective C
6412 compiler (@option{-O2} on systems where @command{gcc} does not accept
6413 @option{-g}), or @option{-g} for other compilers.
6416 @defmac AC_PROG_OBJCCPP
6417 @acindex{PROG_OBJCCPP}
6419 Set output variable @code{OBJCCPP} to a command that runs the Objective C
6420 preprocessor. If @samp{$OBJC -E} doesn't work, @file{/lib/cpp} is used.
6424 @node Erlang Compiler and Interpreter
6425 @subsection Erlang Compiler and Interpreter Characteristics
6428 Autoconf defines the following macros for determining paths to the essential
6429 Erlang/OTP programs:
6431 @defmac AC_ERLANG_PATH_ERLC (@ovar{value-if-not-found}, @ovar{path})
6432 @acindex{ERLANG_PATH_ERLC}
6435 Determine an Erlang compiler to use. If @code{ERLC} is not already set in the
6436 environment, check for @command{erlc}. Set output variable @code{ERLC} to the
6437 complete path of the compiler command found. In addition, if @code{ERLCFLAGS}
6438 is not set in the environment, set it to an empty value.
6440 The two optional arguments have the same meaning as the two last arguments of
6441 macro @code{AC_PROG_PATH} for looking for the @command{erlc} program. For
6442 example, to look for @command{erlc} only in the @file{/usr/lib/erlang/bin}
6446 AC_ERLANG_PATH_ERLC([not found], [/usr/lib/erlang/bin])
6450 @defmac AC_ERLANG_NEED_ERLC (@ovar{path})
6451 @acindex{ERLANG_NEED_ERLC}
6452 A simplified variant of the @code{AC_ERLANG_PATH_ERLC} macro, that prints an
6453 error message and exits the @command{configure} script if the @command{erlc}
6454 program is not found.
6457 @defmac AC_ERLANG_PATH_ERL (@ovar{value-if-not-found}, @ovar{path})
6458 @acindex{ERLANG_PATH_ERL}
6460 Determine an Erlang interpreter to use. If @code{ERL} is not already set in the
6461 environment, check for @command{erl}. Set output variable @code{ERL} to the
6462 complete path of the interpreter command found.
6464 The two optional arguments have the same meaning as the two last arguments of
6465 macro @code{AC_PROG_PATH} for looking for the @command{erl} program. For
6466 example, to look for @command{erl} only in the @file{/usr/lib/erlang/bin}
6470 AC_ERLANG_PATH_ERL([not found], [/usr/lib/erlang/bin])
6474 @defmac AC_ERLANG_NEED_ERL (@ovar{path})
6475 @acindex{ERLANG_NEED_ERL}
6476 A simplified variant of the @code{AC_ERLANG_PATH_ERL} macro, that prints an
6477 error message and exits the @command{configure} script if the @command{erl}
6478 program is not found.
6482 @node Fortran Compiler
6483 @subsection Fortran Compiler Characteristics
6487 The Autoconf Fortran support is divided into two categories: legacy
6488 Fortran 77 macros (@code{F77}), and modern Fortran macros (@code{FC}).
6489 The former are intended for traditional Fortran 77 code, and have output
6490 variables like @code{F77}, @code{FFLAGS}, and @code{FLIBS}. The latter
6491 are for newer programs that can (or must) compile under the newer
6492 Fortran standards, and have output variables like @code{FC},
6493 @code{FCFLAGS}, and @code{FCLIBS}.
6495 Except for two new macros @code{AC_FC_SRCEXT} and
6496 @code{AC_FC_FREEFORM} (see below), the @code{FC} and @code{F77} macros
6497 behave almost identically, and so they are documented together in this
6501 @defmac AC_PROG_F77 (@ovar{compiler-search-list})
6505 Determine a Fortran 77 compiler to use. If @code{F77} is not already
6506 set in the environment, then check for @code{g77} and @code{f77}, and
6507 then some other names. Set the output variable @code{F77} to the name
6508 of the compiler found.
6510 This macro may, however, be invoked with an optional first argument
6511 which, if specified, must be a blank-separated list of Fortran 77
6512 compilers to search for. This just gives the user an opportunity to
6513 specify an alternative search list for the Fortran 77 compiler. For
6514 example, if you didn't like the default order, then you could invoke
6515 @code{AC_PROG_F77} like this:
6518 AC_PROG_F77([fl32 f77 fort77 xlf g77 f90 xlf90])
6521 If using @code{g77} (the @acronym{GNU} Fortran 77 compiler), then
6522 @code{AC_PROG_F77} will set the shell variable @code{G77} to @samp{yes}.
6523 If the output variable @code{FFLAGS} was not already set in the
6524 environment, then set it to @option{-g -02} for @code{g77} (or @option{-O2}
6525 where @code{g77} does not accept @option{-g}). Otherwise, set
6526 @code{FFLAGS} to @option{-g} for all other Fortran 77 compilers.
6529 @defmac AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect})
6533 Determine a Fortran compiler to use. If @code{FC} is not already set in
6534 the environment, then @code{dialect} is a hint to indicate what Fortran
6535 dialect to search for; the default is to search for the newest available
6536 dialect. Set the output variable @code{FC} to the name of the compiler
6539 By default, newer dialects are preferred over older dialects, but if
6540 @code{dialect} is specified then older dialects are preferred starting
6541 with the specified dialect. @code{dialect} can currently be one of
6542 Fortran 77, Fortran 90, or Fortran 95. However, this is only a hint of
6543 which compiler @emph{name} to prefer (e.g., @code{f90} or @code{f95}),
6544 and no attempt is made to guarantee that a particular language standard
6545 is actually supported. Thus, it is preferable that you avoid the
6546 @code{dialect} option, and use AC_PROG_FC only for code compatible with
6547 the latest Fortran standard.
6549 This macro may, alternatively, be invoked with an optional first argument
6550 which, if specified, must be a blank-separated list of Fortran
6551 compilers to search for, just as in @code{AC_PROG_F77}.
6553 If the output variable @code{FCFLAGS} was not already set in the
6554 environment, then set it to @option{-g -02} for @acronym{GNU} @code{g77} (or
6555 @option{-O2} where @code{g77} does not accept @option{-g}). Otherwise,
6556 set @code{FCFLAGS} to @option{-g} for all other Fortran compilers.
6559 @defmac AC_PROG_F77_C_O
6560 @defmacx AC_PROG_FC_C_O
6561 @acindex{PROG_F77_C_O}
6562 @acindex{PROG_FC_C_O}
6563 @cvindex F77_NO_MINUS_C_MINUS_O
6564 @cvindex FC_NO_MINUS_C_MINUS_O
6565 Test whether the Fortran compiler accepts the options @option{-c} and
6566 @option{-o} simultaneously, and define @code{F77_NO_MINUS_C_MINUS_O} or
6567 @code{FC_NO_MINUS_C_MINUS_O}, respectively, if it does not.
6570 The following macros check for Fortran compiler characteristics.
6571 To check for characteristics not listed here, use
6572 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
6573 @code{AC_RUN_IFELSE} (@pxref{Runtime}), making sure to first set the
6574 current language to Fortran 77 or Fortran via @code{AC_LANG([Fortran 77])}
6575 or @code{AC_LANG(Fortran)} (@pxref{Language Choice}).
6578 @defmac AC_F77_LIBRARY_LDFLAGS
6579 @defmacx AC_FC_LIBRARY_LDFLAGS
6580 @acindex{F77_LIBRARY_LDFLAGS}
6582 @acindex{FC_LIBRARY_LDFLAGS}
6584 Determine the linker flags (e.g., @option{-L} and @option{-l}) for the
6585 @dfn{Fortran intrinsic and runtime libraries} that are required to
6586 successfully link a Fortran program or shared library. The output
6587 variable @code{FLIBS} or @code{FCLIBS} is set to these flags (which
6588 should be included after @code{LIBS} when linking).
6590 This macro is intended to be used in those situations when it is
6591 necessary to mix, e.g., C++ and Fortran source code in a single
6592 program or shared library (@pxref{Mixing Fortran 77 With C and C++, , ,
6593 automake, @acronym{GNU} Automake}).
6595 For example, if object files from a C++ and Fortran compiler must be
6596 linked together, then the C++ compiler/linker must be used for linking
6597 (since special C++-ish things need to happen at link time like calling
6598 global constructors, instantiating templates, enabling exception
6601 However, the Fortran intrinsic and runtime libraries must be linked in
6602 as well, but the C++ compiler/linker doesn't know by default how to add
6603 these Fortran 77 libraries. Hence, this macro was created to determine
6604 these Fortran libraries.
6606 The macros @code{AC_F77_DUMMY_MAIN} and @code{AC_FC_DUMMY_MAIN} or
6607 @code{AC_F77_MAIN} and @code{AC_FC_MAIN} will probably also be necessary to
6608 link C/C++ with Fortran; see below.
6611 @defmac AC_F77_DUMMY_MAIN (@ovar{action-if-found}, @ovar{action-if-not-found})
6612 @defmacx AC_FC_DUMMY_MAIN (@ovar{action-if-found}, @ovar{action-if-not-found})
6613 @acindex{F77_DUMMY_MAIN}
6614 @cvindex F77_DUMMY_MAIN
6615 With many compilers, the Fortran libraries detected by
6616 @code{AC_F77_LIBRARY_LDFLAGS} or @code{AC_FC_LIBRARY_LDFLAGS} provide
6617 their own @code{main} entry function that initializes things like
6618 Fortran I/O, and which then calls a user-provided entry function named
6619 (say) @code{MAIN__} to run the user's program. The
6620 @code{AC_F77_DUMMY_MAIN} and @code{AC_FC_DUMMY_MAIN} or
6621 @code{AC_F77_MAIN} and @code{AC_FC_MAIN} macros figure out how to deal with
6624 When using Fortran for purely numerical functions (no I/O, etc.)@: often
6625 one prefers to provide one's own @code{main} and skip the Fortran
6626 library initializations. In this case, however, one may still need to
6627 provide a dummy @code{MAIN__} routine in order to prevent linking errors
6628 on some systems. @code{AC_F77_DUMMY_MAIN} or @code{AC_FC_DUMMY_MAIN}
6629 detects whether any such routine is @emph{required} for linking, and
6630 what its name is; the shell variable @code{F77_DUMMY_MAIN} or
6631 @code{FC_DUMMY_MAIN} holds this name, @code{unknown} when no solution
6632 was found, and @code{none} when no such dummy main is needed.
6634 By default, @var{action-if-found} defines @code{F77_DUMMY_MAIN} or
6635 @code{FC_DUMMY_MAIN} to the name of this routine (e.g., @code{MAIN__})
6636 @emph{if} it is required. @ovar{action-if-not-found} defaults to
6637 exiting with an error.
6639 In order to link with Fortran routines, the user's C/C++ program should
6640 then include the following code to define the dummy main if it is
6644 #ifdef F77_DUMMY_MAIN
6648 int F77_DUMMY_MAIN() @{ return 1; @}
6652 (Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
6654 Note that this macro is called automatically from @code{AC_F77_WRAPPERS}
6655 or @code{AC_FC_WRAPPERS}; there is generally no need to call it
6656 explicitly unless one wants to change the default actions.
6665 As discussed above, many Fortran libraries allow you to provide an entry
6666 point called (say) @code{MAIN__} instead of the usual @code{main}, which
6667 is then called by a @code{main} function in the Fortran libraries that
6668 initializes things like Fortran I/O@. The
6669 @code{AC_F77_MAIN} and @code{AC_FC_MAIN} macros detect whether it is
6670 @emph{possible} to utilize such an alternate main function, and defines
6671 @code{F77_MAIN} and @code{FC_MAIN} to the name of the function. (If no
6672 alternate main function name is found, @code{F77_MAIN} and @code{FC_MAIN} are
6673 simply defined to @code{main}.)
6675 Thus, when calling Fortran routines from C that perform things like I/O,
6676 one should use this macro and name the "main" function
6677 @code{F77_MAIN} or @code{FC_MAIN} instead of @code{main}.
6680 @defmac AC_F77_WRAPPERS
6681 @defmacx AC_FC_WRAPPERS
6682 @acindex{F77_WRAPPERS}
6685 @acindex{FC_WRAPPERS}
6688 Defines C macros @code{F77_FUNC (name, NAME)}, @code{FC_FUNC (name, NAME)},
6689 @code{F77_FUNC_(name, NAME)}, and @code{FC_FUNC_(name, NAME)} to properly
6690 mangle the names of C/C++ identifiers, and identifiers with underscores,
6691 respectively, so that they match the name-mangling scheme used by the
6694 Fortran is case-insensitive, and in order to achieve this the Fortran
6695 compiler converts all identifiers into a canonical case and format. To
6696 call a Fortran subroutine from C or to write a C function that is
6697 callable from Fortran, the C program must explicitly use identifiers in
6698 the format expected by the Fortran compiler. In order to do this, one
6699 simply wraps all C identifiers in one of the macros provided by
6700 @code{AC_F77_WRAPPERS} or @code{AC_FC_WRAPPERS}. For example, suppose
6701 you have the following Fortran 77 subroutine:
6704 subroutine foobar (x, y)
6705 double precision x, y
6711 You would then declare its prototype in C or C++ as:
6714 #define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)
6716 extern "C" /* prevent C++ name mangling */
6718 void FOOBAR_F77(double *x, double *y);
6721 Note that we pass both the lowercase and uppercase versions of the
6722 function name to @code{F77_FUNC} so that it can select the right one.
6723 Note also that all parameters to Fortran 77 routines are passed as
6724 pointers (@pxref{Mixing Fortran 77 With C and C++, , , automake, @acronym{GNU}
6727 (Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
6729 Although Autoconf tries to be intelligent about detecting the
6730 name-mangling scheme of the Fortran compiler, there may be Fortran
6731 compilers that it doesn't support yet. In this case, the above code
6732 will generate a compile-time error, but some other behavior
6733 (e.g., disabling Fortran-related features) can be induced by checking
6734 whether @code{F77_FUNC} or @code{FC_FUNC} is defined.
6736 Now, to call that routine from a C program, we would do something like:
6740 double x = 2.7183, y;
6741 FOOBAR_F77 (&x, &y);
6745 If the Fortran identifier contains an underscore (e.g., @code{foo_bar}),
6746 you should use @code{F77_FUNC_} or @code{FC_FUNC_} instead of
6747 @code{F77_FUNC} or @code{FC_FUNC} (with the same arguments). This is
6748 because some Fortran compilers mangle names differently if they contain
6752 @defmac AC_F77_FUNC (@var{name}, @ovar{shellvar})
6753 @defmacx AC_FC_FUNC (@var{name}, @ovar{shellvar})
6756 Given an identifier @var{name}, set the shell variable @var{shellvar} to
6757 hold the mangled version @var{name} according to the rules of the
6758 Fortran linker (see also @code{AC_F77_WRAPPERS} or
6759 @code{AC_FC_WRAPPERS}). @var{shellvar} is optional; if it is not
6760 supplied, the shell variable will be simply @var{name}. The purpose of
6761 this macro is to give the caller a way to access the name-mangling
6762 information other than through the C preprocessor as above, for example,
6763 to call Fortran routines from some language other than C/C++.
6766 @defmac AC_FC_SRCEXT (@var{ext}, @ovar{action-if-success}, @ovar{action-if-failure})
6768 By default, the @code{FC} macros perform their tests using a @file{.f}
6769 extension for source-code files. Some compilers, however, only enable
6770 newer language features for appropriately named files, e.g., Fortran 90
6771 features only for @file{.f90} files. On the other hand, some other
6772 compilers expect all source files to end in @file{.f} and require
6773 special flags to support other file name extensions. The
6774 @code{AC_FC_SRCEXT} macro deals with both of these issues.
6776 The @code{AC_FC_SRCEXT} tries to get the @code{FC} compiler to accept files
6777 ending with the extension .@var{ext} (i.e., @var{ext} does @emph{not}
6778 contain the dot). If any special compiler flags are needed for this, it
6779 stores them in the output variable @code{FCFLAGS_}@var{ext}. This
6780 extension and these flags are then used for all subsequent @code{FC} tests
6781 (until @code{AC_FC_SRCEXT} is called again).
6783 For example, you would use @code{AC_FC_SRCEXT(f90)} to employ the
6784 @file{.f90} extension in future tests, and it would set a
6785 @code{FCFLAGS_f90} output variable with any extra flags that are needed
6786 to compile such files.
6788 The @code{FCFLAGS_}@var{ext} can @emph{not} be simply absorbed into
6789 @code{FCFLAGS}, for two reasons based on the limitations of some
6790 compilers. First, only one @code{FCFLAGS_}@var{ext} can be used at a
6791 time, so files with different extensions must be compiled separately.
6792 Second, @code{FCFLAGS_}@var{ext} must appear @emph{immediately} before
6793 the source-code file name when compiling. So, continuing the example
6794 above, you might compile a @file{foo.f90} file in your Makefile with the
6799 $(FC) -c $(FCFLAGS) $(FCFLAGS_f90) foo.f90
6802 If @code{AC_FC_SRCEXT} succeeds in compiling files with the @var{ext}
6803 extension, it calls @ovar{action-if-success} (defaults to nothing). If
6804 it fails, and cannot find a way to make the @code{FC} compiler accept such
6805 files, it calls @ovar{action-if-failure} (defaults to exiting with an
6810 @defmac AC_FC_FREEFORM (@ovar{action-if-success}, @ovar{action-if-failure})
6811 @acindex{FC_FREEFORM}
6813 The @code{AC_FC_FREEFORM} tries to ensure that the Fortran compiler
6814 (@code{$FC}) allows free-format source code (as opposed to the older
6815 fixed-format style from Fortran 77). If necessary, it may add some
6816 additional flags to @code{FCFLAGS}.
6818 This macro is most important if you are using the default @file{.f}
6819 extension, since many compilers interpret this extension as indicating
6820 fixed-format source unless an additional flag is supplied. If you
6821 specify a different extension with @code{AC_FC_SRCEXT}, such as
6822 @file{.f90} or @file{.f95}, then @code{AC_FC_FREEFORM} will ordinarily
6823 succeed without modifying @code{FCFLAGS}.
6825 If @code{AC_FC_FREEFORM} succeeds in compiling free-form source, it
6826 calls @ovar{action-if-success} (defaults to nothing). If it fails, it
6827 calls @ovar{action-if-failure} (defaults to exiting with an error
6831 @node System Services
6832 @section System Services
6834 The following macros check for operating system services or capabilities.
6839 @cindex X Window System
6840 Try to locate the X Window System include files and libraries. If the
6841 user gave the command line options @option{--x-includes=@var{dir}} and
6842 @option{--x-libraries=@var{dir}}, use those directories.
6844 If either or both were not given, get the missing values by running
6845 @code{xmkmf} (or an executable pointed to by the @code{XMKMF}
6846 environment variable) on a trivial @file{Imakefile} and examining the
6847 @file{Makefile} that it produces. Setting @code{XMKMF} to @samp{false}
6848 will disable this method.
6850 If this method fails to find the X Window System, @command{configure}
6851 will look for the files in several directories where they often reside.
6852 If either method is successful, set the shell variables
6853 @code{x_includes} and @code{x_libraries} to their locations, unless they
6854 are in directories the compiler searches by default.
6856 If both methods fail, or the user gave the command line option
6857 @option{--without-x}, set the shell variable @code{no_x} to @samp{yes};
6858 otherwise set it to the empty string.
6861 @defmac AC_PATH_XTRA
6865 @ovindex X_EXTRA_LIBS
6867 @cvindex X_DISPLAY_MISSING
6868 An enhanced version of @code{AC_PATH_X}. It adds the C compiler flags
6869 that X needs to output variable @code{X_CFLAGS}, and the X linker flags
6870 to @code{X_LIBS}. Define @code{X_DISPLAY_MISSING} if X is not
6873 This macro also checks for special libraries that some systems need in
6874 order to compile X programs. It adds any that the system needs to
6875 output variable @code{X_EXTRA_LIBS}. And it checks for special X11R6
6876 libraries that need to be linked with before @option{-lX11}, and adds
6877 any found to the output variable @code{X_PRE_LIBS}.
6879 @c This is an incomplete kludge. Make a real way to do it.
6880 @c If you need to check for other X functions or libraries yourself, then
6881 @c after calling this macro, add the contents of @code{X_EXTRA_LIBS} to
6882 @c @code{LIBS} temporarily, like this: (FIXME - add example)
6885 @defmac AC_SYS_INTERPRETER
6886 @acindex{SYS_INTERPRETER}
6887 Check whether the system supports starting scripts with a line of the
6888 form @samp{#!/bin/sh} to select the interpreter to use for the script.
6889 After running this macro, shell code in @file{configure.ac} can check
6890 the shell variable @code{interpval}; it will be set to @samp{yes}
6891 if the system supports @samp{#!}, @samp{no} if not.
6894 @defmac AC_SYS_LARGEFILE
6895 @acindex{SYS_LARGEFILE}
6896 @cvindex _FILE_OFFSET_BITS
6897 @cvindex _LARGE_FILES
6899 @cindex Large file support
6902 @uref{http://www.unix-systems.org/version2/whatsnew/lfs20mar.html,
6903 large-file support}. On some hosts, one must use special compiler
6904 options to build programs that can access large files. Append any such
6905 options to the output variable @code{CC}. Define
6906 @code{_FILE_OFFSET_BITS} and @code{_LARGE_FILES} if necessary.
6908 Large-file support can be disabled by configuring with the
6909 @option{--disable-largefile} option.
6911 If you use this macro, check that your program works even when
6912 @code{off_t} is wider than @code{long int}, since this is common when
6913 large-file support is enabled. For example, it is not correct to print
6914 an arbitrary @code{off_t} value @code{X} with @code{printf ("%ld",
6917 The LFS introduced the @code{fseeko} and @code{ftello} functions to
6918 replace their C counterparts @code{fseek} and @code{ftell} that do not
6919 use @code{off_t}. Take care to use @code{AC_FUNC_FSEEKO} to make their
6920 prototypes available when using them and large-file support is
6924 @defmac AC_SYS_LONG_FILE_NAMES
6925 @acindex{SYS_LONG_FILE_NAMES}
6926 @cvindex HAVE_LONG_FILE_NAMES
6927 If the system supports file names longer than 14 characters, define
6928 @code{HAVE_LONG_FILE_NAMES}.
6931 @defmac AC_SYS_POSIX_TERMIOS
6932 @acindex{SYS_POSIX_TERMIOS}
6933 @cindex Posix termios headers
6934 @cindex termios Posix headers
6935 Check to see if the Posix termios headers and functions are available on the
6936 system. If so, set the shell variable @code{ac_cv_sys_posix_termios} to
6937 @samp{yes}. If not, set the variable to @samp{no}.
6940 @node Posix Variants
6941 @section Posix Variants
6943 The following macros check for certain operating systems that need
6944 special treatment for some programs, due to exceptional oddities in
6945 their header files or libraries. These macros are warts; they will be
6946 replaced by a more systematic approach, based on the functions they make
6947 available or the environments they provide.
6951 @cvindex _ALL_SOURCE
6952 If on @acronym{AIX}, define @code{_ALL_SOURCE}.
6953 Allows the use of some @acronym{BSD}
6954 functions. Should be called before any macros that run the C compiler.
6957 @defmac AC_GNU_SOURCE
6958 @acindex{GNU_SOURCE}
6959 @cvindex _GNU_SOURCE
6960 If using the @acronym{GNU} C library, define @code{_GNU_SOURCE}.
6961 Allows the use of some @acronym{GNU} functions. Should be called
6962 before any macros that run the C compiler.
6965 @defmac AC_ISC_POSIX
6968 For @sc{interactive} Systems Corporation Unix, add @option{-lcposix} to output
6969 variable @code{LIBS} if necessary for Posix facilities. Call this
6970 after @code{AC_PROG_CC} and before any other macros that use Posix
6971 interfaces. @sc{interactive} Unix is no longer sold, and Sun says that
6972 they will drop support for it on 2006-07-23, so this macro is becoming
6979 @cvindex _POSIX_SOURCE
6980 @cvindex _POSIX_1_SOURCE
6981 If on Minix, define @code{_MINIX} and @code{_POSIX_SOURCE} and define
6982 @code{_POSIX_1_SOURCE} to be 2. This allows the use of Posix
6983 facilities. Should be called before any macros that run the C compiler.
6986 @defmac AC_USE_SYSTEM_EXTENSIONS
6987 @acindex{USE_SYSTEM_EXTENSIONS}
6988 @cvindex _ALL_SOURCE
6989 @cvindex _GNU_SOURCE
6991 @cvindex _POSIX_1_SOURCE
6992 @cvindex _POSIX_PTHREAD_SEMANTICS
6993 @cvindex _POSIX_SOURCE
6994 @cvindex __EXTENSIONS__
6995 If possible, enable extensions to Posix on hosts that normally disable
6996 the extensions, typically due to standards-conformance namespace issues.
6997 This may involve defining @code{__EXTENSIONS__} and
6998 @code{_POSIX_PTHREAD_SEMANTICS}, which are macros used by Solaris. This
6999 macro also has the combined effects of @code{AC_GNU_SOURCE},
7000 @code{AC_AIX}, and @code{AC_MINIX}.
7004 @node Erlang Libraries
7005 @section Erlang Libraries
7006 @cindex Erlang, Library, checking
7008 The following macros check for an installation of Erlang/OTP, and for the
7009 presence of certain Erlang libraries. All those macros require the
7010 configuration of an Erlang interpreter and an Erlang compiler
7011 (@pxref{Erlang Compiler and Interpreter}).
7013 @defmac AC_ERLANG_SUBST_ROOT_DIR
7014 @acindex{ERLANG_SUBST_ROOT_DIR}
7015 @ovindex ERLANG_ROOT_DIR
7017 Set the output variable @code{ERLANG_ROOT_DIR} to the path to the base directory
7018 in which Erlang/OTP is installed (as returned by Erlang's @code{code:root_dir/0}
7019 function). The result of this test is cached if caching is enabled when running
7020 @command{configure}.
7023 @defmac AC_ERLANG_SUBST_LIB_DIR
7024 @acindex{ERLANG_SUBST_LIB_DIR}
7025 @ovindex ERLANG_LIB_DIR
7027 Set the output variable @code{ERLANG_LIB_DIR} to the path of the library
7028 directory of Erlang/OTP (as returned by Erlang's
7029 @code{code:lib_dir/0} function), which subdirectories each contain an installed
7030 Erlang/OTP library. The result of this test is cached if caching is enabled
7031 when running @command{configure}.
7034 @defmac AC_ERLANG_CHECK_LIB (@var{library}, @ovar{action-if-found}, @ovar{action-if-not-found})
7035 @acindex{ERLANG_CHECK_LIB}
7036 @ovindex ERLANG_LIB_DIR_@var{library}
7038 Test whether the Erlang/OTP library @var{library} is installed by calling
7039 Erlang's @code{code:lib_dir/1} function. The result of this test is cached if
7040 caching is enabled when running @command{configure}. @var{action-if-found} is a
7041 list of shell commands to run if the library is installed;
7042 @var{action-if-not-found} is a list of shell commands to run if it is not.
7043 Additionally, if the library is installed, the output variable
7044 @samp{ERLANG_LIB_DIR_@var{library}} is set to the path to the library
7045 installation directory. For example, to check if library @code{stdlib} is
7049 AC_ERLANG_CHECK_LIB([stdlib],
7050 [echo "stdlib is installed in $ERLANG_LIB_DIR_stdlib"],
7051 [AC_MSG_ERROR([stdlib was not found!])])
7055 In addition to the above macros, which test installed Erlang libraries, the
7056 following macros determine the paths to the directories into which newly built
7057 Erlang libraries are to be installed:
7059 @defmac AC_ERLANG_SUBST_INSTALL_LIB_DIR
7060 @acindex{ERLANG_SUBST_INSTALL_LIB_DIR}
7061 @ovindex ERLANG_INSTALL_LIB_DIR
7063 Set the @code{ERLANG_INSTALL_LIB_DIR} output variable to the directory into
7064 which every built Erlang library should be installed in a separate subdirectory.
7065 If this variable is not set in the environment when @command{configure} runs,
7066 its default value is @code{$ERLANG_LIB_DIR}, which value is set by the
7067 @code{AC_ERLANG_SUBST_LIB_DIR} macro.
7070 @defmac AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR (@var{library}, @var{version})
7071 @acindex{ERLANG_SUBST_INSTALL_LIB_SUBDIR}
7072 @ovindex ERLANG_INSTALL_LIB_DIR_@var{library}
7074 Set the @samp{ERLANG_INSTALL_LIB_DIR_@var{library}} output variable to the
7075 directory into which the built Erlang library @var{library} version
7076 @var{version} should be installed. If this variable is not set in the
7077 environment when @command{configure} runs, its default value is
7078 @samp{$ERLANG_INSTALL_LIB_DIR/@var{library}-@var{version}}, the value of the
7079 @code{ERLANG_INSTALL_LIB_DIR} variable being set by the
7080 @code{AC_ERLANG_SUBST_INSTALL_LIB_DIR} macro.
7087 @c ========================================================= Writing Tests
7090 @chapter Writing Tests
7092 If the existing feature tests don't do something you need, you have to
7093 write new ones. These macros are the building blocks. They provide
7094 ways for other macros to check whether various kinds of features are
7095 available and report the results.
7097 This chapter contains some suggestions and some of the reasons why the
7098 existing tests are written the way they are. You can also learn a lot
7099 about how to write Autoconf tests by looking at the existing ones. If
7100 something goes wrong in one or more of the Autoconf tests, this
7101 information can help you understand the assumptions behind them, which
7102 might help you figure out how to best solve the problem.
7104 These macros check the output of the compiler system of the current
7105 language (@pxref{Language Choice}). They do not cache the results of
7106 their tests for future use (@pxref{Caching Results}), because they don't
7107 know enough about the information they are checking for to generate a
7108 cache variable name. They also do not print any messages, for the same
7109 reason. The checks for particular kinds of features call these macros
7110 and do cache their results and print messages about what they're
7113 When you write a feature test that could be applicable to more than one
7114 software package, the best thing to do is encapsulate it in a new macro.
7115 @xref{Writing Autoconf Macros}, for how to do that.
7118 * Language Choice:: Selecting which language to use for testing
7119 * Writing Test Programs:: Forging source files for compilers
7120 * Running the Preprocessor:: Detecting preprocessor symbols
7121 * Running the Compiler:: Detecting language or header features
7122 * Running the Linker:: Detecting library features
7123 * Runtime:: Testing for runtime features
7124 * Systemology:: A zoology of operating systems
7125 * Multiple Cases:: Tests for several possible values
7128 @node Language Choice
7129 @section Language Choice
7132 Autoconf-generated @command{configure} scripts check for the C compiler and
7133 its features by default. Packages that use other programming languages
7134 (maybe more than one, e.g., C and C++) need to test features of the
7135 compilers for the respective languages. The following macros determine
7136 which programming language is used in the subsequent tests in
7137 @file{configure.ac}.
7139 @defmac AC_LANG (@var{language})
7140 Do compilation tests using the compiler, preprocessor, and file
7141 extensions for the specified @var{language}.
7143 Supported languages are:
7147 Do compilation tests using @code{CC} and @code{CPP} and use extension
7148 @file{.c} for test programs. Use compilation flags: @code{CPPFLAGS} with
7149 @code{CPP}, and both @code{CPPFLAGS} and @code{CFLAGS} with @code{CC}.
7152 Do compilation tests using @code{CXX} and @code{CXXCPP} and use
7153 extension @file{.C} for test programs. Use compilation flags:
7154 @code{CPPFLAGS} with @code{CXXPP}, and both @code{CPPFLAGS} and
7155 @code{CXXFLAGS} with @code{CXX}.
7158 Do compilation tests using @code{F77} and use extension @file{.f} for
7159 test programs. Use compilation flags: @code{FFLAGS}.
7162 Do compilation tests using @code{FC} and use extension @file{.f} (or
7163 whatever has been set by @code{AC_FC_SRCEXT}) for test programs. Use
7164 compilation flags: @code{FCFLAGS}.
7170 Compile and execute tests using @code{ERLC} and @code{ERL} and use extension
7171 @file{.erl} for test Erlang modules. Use compilation flags: @code{ERLCFLAGS}.
7174 Do compilation tests using @code{OBJC} and @code{OBJCCPP} and use
7175 extension @file{.m} for test programs. Use compilation flags:
7176 @code{CPPFLAGS} with @code{OBJCPP}, and both @code{CPPFLAGS} and
7177 @code{OBJCFLAGS} with @code{OBJC}.
7181 @defmac AC_LANG_PUSH (@var{language})
7183 Remember the current language (as set by @code{AC_LANG}) on a stack, and
7184 then select the @var{language}. Use this macro and @code{AC_LANG_POP}
7185 in macros that need to temporarily switch to a particular language.
7188 @defmac AC_LANG_POP (@ovar{language})
7190 Select the language that is saved on the top of the stack, as set by
7191 @code{AC_LANG_PUSH}, and remove it from the stack.
7193 If given, @var{language} specifies the language we just @emph{quit}. It
7194 is a good idea to specify it when it's known (which should be the
7195 case@dots{}), since Autoconf will detect inconsistencies.
7198 AC_LANG_PUSH([Fortran 77])
7199 # Perform some tests on Fortran 77.
7201 AC_LANG_POP([Fortran 77])
7205 @defmac AC_LANG_ASSERT (@var{language})
7206 @acindex{LANG_ASSERT} Check statically that the current language is
7207 @var{language}. You should use this in your language specific macros
7208 to avoid that they be called with an inappropriate language.
7210 This macro runs only at @command{autoconf} time, and incurs no cost at
7211 @command{configure} time. Sadly enough and because Autoconf is a two
7212 layer language @footnote{Because M4 is not aware of Sh code,
7213 especially conditionals, some optimizations that look nice statically
7214 may produce incorrect results at runtime.}, the macros
7215 @code{AC_LANG_PUSH} and @code{AC_LANG_POP} cannot be ``optimizing'',
7216 therefore as much as possible you ought to avoid using them to wrap
7217 your code, rather, require from the user to run the macro with a
7218 correct current language, and check it with @code{AC_LANG_ASSERT}.
7219 And anyway, that may help the user understand she is running a Fortran
7220 macro while expecting a result about her Fortran 77 compiler@dots{}
7224 @defmac AC_REQUIRE_CPP
7225 @acindex{REQUIRE_CPP}
7226 Ensure that whichever preprocessor would currently be used for tests has
7227 been found. Calls @code{AC_REQUIRE} (@pxref{Prerequisite Macros}) with an
7228 argument of either @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP},
7229 depending on which language is current.
7233 @node Writing Test Programs
7234 @section Writing Test Programs
7236 Autoconf tests follow a common scheme: feed some program with some
7237 input, and most of the time, feed a compiler with some source file.
7238 This section is dedicated to these source samples.
7241 * Guidelines:: General rules for writing test programs
7242 * Test Functions:: Avoiding pitfalls in test programs
7243 * Generating Sources:: Source program boilerplate
7247 @subsection Guidelines for Test Programs
7249 The most important rule to follow when writing testing samples is:
7251 @center @emph{Look for realism.}
7253 This motto means that testing samples must be written with the same
7254 strictness as real programs are written. In particular, you should
7255 avoid ``shortcuts'' and simplifications.
7257 Don't just play with the preprocessor if you want to prepare a
7258 compilation. For instance, using @command{cpp} to check whether a header is
7259 functional might let your @command{configure} accept a header which will
7260 cause some @emph{compiler} error. Do not hesitate checking header with
7261 other headers included before, especially required headers.
7263 Make sure the symbols you use are properly defined, i.e., refrain for
7264 simply declaring a function yourself instead of including the proper
7267 Test programs should not write to standard output. They
7268 should exit with status 0 if the test succeeds, and with status 1
7269 otherwise, so that success
7270 can be distinguished easily from a core dump or other failure;
7271 segmentation violations and other failures produce a nonzero exit
7272 status. Unless you arrange for @code{exit} to be declared, test
7273 programs should @code{return}, not @code{exit}, from @code{main},
7274 because on many systems @code{exit} is not declared by default.
7276 Test programs can use @code{#if} or @code{#ifdef} to check the values of
7277 preprocessor macros defined by tests that have already run. For
7278 example, if you call @code{AC_HEADER_STDBOOL}, then later on in
7279 @file{configure.ac} you can have a test program that includes
7280 @file{stdbool.h} conditionally:
7285 # include <stdbool.h>
7290 If a test program needs to use or create a data file, give it a name
7291 that starts with @file{conftest}, such as @file{conftest.data}. The
7292 @command{configure} script cleans up by running @samp{rm -f -r conftest*}
7293 after running test programs and if the script is interrupted.
7295 @node Test Functions
7296 @subsection Test Functions
7298 These days it's safe to assume support for function prototypes
7299 (introduced in C89).
7301 Functions that test programs declare should also be conditionalized for
7302 C++, which requires @samp{extern "C"} prototypes. Make sure to not
7303 include any header files containing clashing prototypes.
7309 void *valloc (size_t);
7312 If a test program calls a function with invalid parameters (just to see
7313 whether it exists), organize the program to ensure that it never invokes
7314 that function. You can do this by calling it in another function that is
7315 never invoked. You can't do it by putting it after a call to
7316 @code{exit}, because GCC version 2 knows that @code{exit} never returns
7317 and optimizes out any code that follows it in the same block.
7319 If you include any header files, be sure to call the functions
7320 relevant to them with the correct number of arguments, even if they are
7321 just 0, to avoid compilation errors due to prototypes. GCC version 2
7322 has internal prototypes for several functions that it automatically
7323 inlines; for example, @code{memcpy}. To avoid errors when checking for
7324 them, either pass them the correct number of arguments or redeclare them
7325 with a different return type (such as @code{char}).
7328 @node Generating Sources
7329 @subsection Generating Sources
7331 Autoconf provides a set of macros that can be used to generate test
7332 source files. They are written to be language generic, i.e., they
7333 actually depend on the current language (@pxref{Language Choice}) to
7334 ``format'' the output properly.
7337 @defmac AC_LANG_CONFTEST (@var{source})
7338 @acindex{LANG_CONFTEST}
7339 Save the @var{source} text in the current test source file:
7340 @file{conftest.@var{extension}} where the @var{extension} depends on the
7343 Note that the @var{source} is evaluated exactly once, like regular
7344 Autoconf macro arguments, and therefore (i) you may pass a macro
7345 invocation, (ii) if not, be sure to double quote if needed.
7348 @defmac AC_LANG_SOURCE (@var{source})
7349 @acindex{LANG_SOURCE}
7350 Expands into the @var{source}, with the definition of
7351 all the @code{AC_DEFINE} performed so far.
7354 For instance executing (observe the double quotation!):
7357 AC_INIT([Hello], [1.0], [bug-hello@@example.org])
7358 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7359 [Greetings string.])
7362 [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
7363 gcc -E -dD -o - conftest.c
7373 #define PACKAGE_NAME "Hello"
7374 #define PACKAGE_TARNAME "hello"
7375 #define PACKAGE_VERSION "1.0"
7376 #define PACKAGE_STRING "Hello 1.0"
7377 #define PACKAGE_BUGREPORT "bug-hello@@example.org"
7378 #define HELLO_WORLD "Hello, World\n"
7380 const char hw[] = "Hello, World\n";
7383 When the test language is Fortran or Erlang, the @code{AC_DEFINE} definitions
7384 are not automatically translated into constants in the source code by this
7387 @defmac AC_LANG_PROGRAM (@var{prologue}, @var{body})
7388 @acindex{LANG_PROGRAM}
7389 Expands into a source file which consists of the @var{prologue}, and
7390 then @var{body} as body of the main function (e.g., @code{main} in
7391 C). Since it uses @code{AC_LANG_SOURCE}, the features of the latter are
7398 AC_INIT([Hello], [1.0], [bug-hello@@example.org])
7399 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7400 [Greetings string.])
7402 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
7403 [[fputs (hw, stdout);]])])
7404 gcc -E -dD -o - conftest.c
7414 #define PACKAGE_NAME "Hello"
7415 #define PACKAGE_TARNAME "hello"
7416 #define PACKAGE_VERSION "1.0"
7417 #define PACKAGE_STRING "Hello 1.0"
7418 #define PACKAGE_BUGREPORT "bug-hello@@example.org"
7419 #define HELLO_WORLD "Hello, World\n"
7421 const char hw[] = "Hello, World\n";
7431 In Erlang tests, the created source file is that of an Erlang module called
7432 @code{conftest} (@file{conftest.erl}). This module defines and exports at least
7433 one @code{start/0} function, which is called to perform the test. The
7434 @var{prologue} is optional code that is inserted between the module header and
7435 the @code{start/0} function definition. @var{body} is the body of the
7436 @code{start/0} function without the final period (@pxref{Runtime}, about
7437 constraints on this function's behaviour).
7442 AC_INIT([Hello], [1.0], [bug-hello@@example.org])
7445 [AC_LANG_PROGRAM([[-define(HELLO_WORLD, "Hello, world!").]],
7446 [[io:format("~s~n", [?HELLO_WORLD])]])])
7456 -define(HELLO_WORLD, "Hello, world!").
7458 io:format("~s~n", [?HELLO_WORLD])
7462 @defmac AC_LANG_CALL (@var{prologue}, @var{function})
7464 Expands into a source file which consists of the @var{prologue}, and
7465 then a call to the @var{function} as body of the main function (e.g.,
7466 @code{main} in C). Since it uses @code{AC_LANG_PROGRAM}, the feature
7467 of the latter are available.
7469 This function will probably be replaced in the future by a version
7470 which would enable specifying the arguments. The use of this macro is
7471 not encouraged, as it violates strongly the typing system.
7473 This macro cannot be used for Erlang tests.
7476 @defmac AC_LANG_FUNC_LINK_TRY (@var{function})
7477 @acindex{LANG_FUNC_LINK_TRY}
7478 Expands into a source file which uses the @var{function} in the body of
7479 the main function (e.g., @code{main} in C). Since it uses
7480 @code{AC_LANG_PROGRAM}, the features of the latter are available.
7482 As @code{AC_LANG_CALL}, this macro is documented only for completeness.
7483 It is considered to be severely broken, and in the future will be
7484 removed in favor of actual function calls (with properly typed
7487 This macro cannot be used for Erlang tests.
7490 @node Running the Preprocessor
7491 @section Running the Preprocessor
7493 Sometimes one might need to run the preprocessor on some source file.
7494 @emph{Usually it is a bad idea}, as you typically need to @emph{compile}
7495 your project, not merely run the preprocessor on it; therefore you
7496 certainly want to run the compiler, not the preprocessor. Resist the
7497 temptation of following the easiest path.
7499 Nevertheless, if you need to run the preprocessor, then use
7500 @code{AC_PREPROC_IFELSE}.
7502 The macros described in this section cannot be used for tests in Erlang or
7503 Fortran, since those languages require no preprocessor.
7505 @defmac AC_PREPROC_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
7506 @acindex{PREPROC_IFELSE}
7507 Run the preprocessor of the current language (@pxref{Language Choice})
7508 on the @var{input}, run the shell commands @var{action-if-true} on
7509 success, @var{action-if-false} otherwise. The @var{input} can be made
7510 by @code{AC_LANG_PROGRAM} and friends.
7512 This macro uses @code{CPPFLAGS}, but not @code{CFLAGS}, because
7513 @option{-g}, @option{-O}, etc.@: are not valid options to many C
7516 It is customary to report unexpected failures with
7517 @code{AC_MSG_FAILURE}.
7523 AC_INIT([Hello], [1.0], [bug-hello@@example.org])
7524 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7525 [Greetings string.])
7527 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
7528 [[fputs (hw, stdout);]])],
7529 [AC_MSG_RESULT([OK])],
7530 [AC_MSG_FAILURE([unexpected preprocessor failure])])
7537 checking for gcc... gcc
7538 checking for C compiler default output file name... a.out
7539 checking whether the C compiler works... yes
7540 checking whether we are cross compiling... no
7541 checking for suffix of executables...
7542 checking for suffix of object files... o
7543 checking whether we are using the GNU C compiler... yes
7544 checking whether gcc accepts -g... yes
7545 checking for gcc option to accept ISO C89... none needed
7546 checking how to run the C preprocessor... gcc -E
7552 The macro @code{AC_TRY_CPP} (@pxref{Obsolete Macros}) used to play the
7553 role of @code{AC_PREPROC_IFELSE}, but double quotes its argument, making
7554 it impossible to use it to elaborate sources. You are encouraged to
7555 get rid of your old use of the macro @code{AC_TRY_CPP} in favor of
7556 @code{AC_PREPROC_IFELSE}, but, in the first place, are you sure you need
7557 to run the @emph{preprocessor} and not the compiler?
7559 @defmac AC_EGREP_HEADER (@var{pattern}, @var{header-file}, @var{action-if-found}, @ovar{action-if-not-found})
7560 @acindex{EGREP_HEADER}
7561 If the output of running the preprocessor on the system header file
7562 @var{header-file} matches the extended regular expression
7563 @var{pattern}, execute shell commands @var{action-if-found}, otherwise
7564 execute @var{action-if-not-found}.
7567 @defmac AC_EGREP_CPP (@var{pattern}, @var{program}, @ovar{action-if-found}, @ovar{action-if-not-found})
7569 @var{program} is the text of a C or C++ program, on which shell
7570 variable, back quote, and backslash substitutions are performed. If the
7571 output of running the preprocessor on @var{program} matches the
7572 extended regular expression @var{pattern}, execute shell commands
7573 @var{action-if-found}, otherwise execute @var{action-if-not-found}.
7578 @node Running the Compiler
7579 @section Running the Compiler
7581 To check for a syntax feature of the current language's (@pxref{Language
7582 Choice}) compiler, such as whether it recognizes a certain keyword, or
7583 simply to try some library feature, use @code{AC_COMPILE_IFELSE} to try
7584 to compile a small program that uses that feature.
7586 @defmac AC_COMPILE_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
7587 @acindex{COMPILE_IFELSE}
7588 Run the compiler and compilation flags of the current language
7589 (@pxref{Language Choice}) on the @var{input}, run the shell commands
7590 @var{action-if-true} on success, @var{action-if-false} otherwise. The
7591 @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.
7593 It is customary to report unexpected failures with
7594 @code{AC_MSG_FAILURE}. This macro does not try to link; use
7595 @code{AC_LINK_IFELSE} if you need to do that (@pxref{Running the
7600 For tests in Erlang, the @var{input} must be the source code of a module named
7601 @code{conftest}. @code{AC_COMPILE_IFELSE} generates a @file{conftest.beam}
7602 file that can be interpreted by the Erlang virtual machine (@code{ERL}). It is
7603 recommended to use @code{AC_LANG_PROGRAM} to specify the test program, to ensure
7604 that the Erlang module has the right name.
7606 @node Running the Linker
7607 @section Running the Linker
7609 To check for a library, a function, or a global variable, Autoconf
7610 @command{configure} scripts try to compile and link a small program that
7611 uses it. This is unlike Metaconfig, which by default uses @code{nm} or
7612 @code{ar} on the C library to try to figure out which functions are
7613 available. Trying to link with the function is usually a more reliable
7614 approach because it avoids dealing with the variations in the options
7615 and output formats of @code{nm} and @code{ar} and in the location of the
7616 standard libraries. It also allows configuring for cross-compilation or
7617 checking a function's runtime behavior if needed. On the other hand,
7618 it can be slower than scanning the libraries once, but accuracy is more
7619 important than speed.
7621 @code{AC_LINK_IFELSE} is used to compile test programs to test for
7622 functions and global variables. It is also used by @code{AC_CHECK_LIB}
7623 to check for libraries (@pxref{Libraries}), by adding the library being
7624 checked for to @code{LIBS} temporarily and trying to link a small
7628 @defmac AC_LINK_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
7629 @acindex{LINK_IFELSE}
7630 Run the compiler (and compilation flags) and the linker of the current
7631 language (@pxref{Language Choice}) on the @var{input}, run the shell
7632 commands @var{action-if-true} on success, @var{action-if-false}
7633 otherwise. The @var{input} can be made by @code{AC_LANG_PROGRAM} and
7636 @code{LDFLAGS} and @code{LIBS} are used for linking, in addition to the
7637 current compilation flags.
7639 It is customary to report unexpected failures with
7640 @code{AC_MSG_FAILURE}. This macro does not try to execute the program;
7641 use @code{AC_RUN_IFELSE} if you need to do that (@pxref{Runtime}).
7644 The @code{AC_LINK_IFELSE} macro cannot be used for Erlang tests, since Erlang
7645 programs are interpreted and do not require linking.
7650 @section Checking Runtime Behavior
7652 Sometimes you need to find out how a system performs at runtime, such
7653 as whether a given function has a certain capability or bug. If you
7654 can, make such checks when your program runs instead of when it is
7655 configured. You can check for things like the machine's endianness when
7656 your program initializes itself.
7658 If you really need to test for a runtime behavior while configuring,
7659 you can write a test program to determine the result, and compile and
7660 run it using @code{AC_RUN_IFELSE}. Avoid running test programs if
7661 possible, because this prevents people from configuring your package for
7664 @defmac AC_RUN_IFELSE (@var{input}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{action-if-cross-compiling})
7665 @acindex{RUN_IFELSE}
7666 If @var{program} compiles and links successfully and returns an exit
7667 status of 0 when executed, run shell commands @var{action-if-true}.
7668 Otherwise, run shell commands @var{action-if-false}.
7670 The @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.
7671 @code{LDFLAGS} and @code{LIBS} are used for linking, in addition to the
7672 compilation flags of the current language (@pxref{Language Choice}).
7674 If the compiler being used does not produce executables that run on the
7675 system where @command{configure} is being run, then the test program is
7676 not run. If the optional shell commands @var{action-if-cross-compiling}
7677 are given, they are run instead. Otherwise, @command{configure} prints
7678 an error message and exits.
7680 In the @var{action-if-false} section, the failing exit status is
7681 available in the shell variable @samp{$?}. This exit status might be
7682 that of a failed compilation, or it might be that of a failed program
7685 It is customary to report unexpected failures with
7686 @code{AC_MSG_FAILURE}.
7689 Try to provide a pessimistic default value to use when cross-compiling
7690 makes runtime tests impossible. You do this by passing the optional
7691 last argument to @code{AC_RUN_IFELSE}. @command{autoconf} prints a
7692 warning message when creating @command{configure} each time it
7693 encounters a call to @code{AC_RUN_IFELSE} with no
7694 @var{action-if-cross-compiling} argument given. You may ignore the
7695 warning, though users will not be able to configure your package for
7696 cross-compiling. A few of the macros distributed with Autoconf produce
7697 this warning message.
7699 To configure for cross-compiling you can also choose a value for those
7700 parameters based on the canonical system name (@pxref{Manual
7701 Configuration}). Alternatively, set up a test results cache file with
7702 the correct values for the host system (@pxref{Caching Results}).
7704 @ovindex cross_compiling
7705 To provide a default for calls of @code{AC_RUN_IFELSE} that are embedded
7706 in other macros, including a few of the ones that come with Autoconf,
7707 you can test whether the shell variable @code{cross_compiling} is set to
7708 @samp{yes}, and then use an alternate method to get the results instead
7709 of calling the macros.
7711 A C or C++ runtime test should be portable.
7712 @xref{Portable C and C++}.
7714 Erlang tests must exit themselves the Erlang VM by calling the @code{halt/1}
7715 function: the given status code is used to determine the success of the test
7716 (status is @code{0}) or its failure (status is different than @code{0}), as
7717 explained above. It must be noted that data output through the standard output
7718 (e.g. using @code{io:format/2}) may be truncated when halting the VM.
7719 Therefore, if a test must output configuration information, it is recommended
7720 to create and to output data into the temporary file named @file{conftest.out},
7721 using the functions of module @code{file}. The @code{conftest.out} file is
7722 automatically deleted by the @code{AC_RUN_IFELSE} macro. For instance, a
7723 simplified implementation of Autoconf's @code{AC_ERLANG_SUBST_LIB_DIR} macro is:
7726 AC_INIT([LibdirTest], [1.0], [bug-libdirtest@@example.org])
7730 [AC_LANG_PROGRAM([], [dnl
7731 file:write_file("conftest.out", code:lib_dir()),
7733 [echo "code:lib_dir() returned: `cat conftest.out`"],
7734 [AC_MSG_FAILURE([test Erlang program execution failed])])
7739 @section Systemology
7742 This section aims at presenting some systems and pointers to
7743 documentation. It may help you addressing particular problems reported
7746 @uref{http://www.opengroup.org/susv3, Posix-conforming systems} are
7747 derived from the @uref{http://www.bell-labs.com/history/unix/, Unix
7750 The @uref{http://bhami.com/rosetta.html, Rosetta Stone for Unix}
7751 contains a table correlating the features of various Posix-conforming
7752 systems. @uref{http://www.levenez.com/unix/, Unix History} is a
7753 simplified diagram of how many Unix systems were derived from each
7759 Darwin is also known as Mac OS X@. Beware that the file system @emph{can} be
7760 case-preserving, but case insensitive. This can cause nasty problems,
7761 since for instance the installation attempt for a package having an
7762 @file{INSTALL} file can result in @samp{make install} report that
7763 nothing was to be done!
7765 That's all dependent on whether the file system is a UFS (case
7766 sensitive) or HFS+ (case preserving). By default Apple wants you to
7767 install the OS on HFS+. Unfortunately, there are some pieces of
7768 software which really need to be built on UFS@. We may want to rebuild
7769 Darwin to have both UFS and HFS+ available (and put the /local/build
7772 @item @acronym{QNX} 4.25
7773 @cindex @acronym{QNX} 4.25
7774 @c FIXME: Please, if you feel like writing something more precise,
7775 @c it'd be great. In particular, I can't understand the difference with
7777 @acronym{QNX} is a realtime operating system running on Intel architecture
7778 meant to be scalable from the small embedded systems to the hundred
7779 processor super-computer. It claims to be Posix certified. More
7780 information is available on the
7781 @uref{http://www.qnx.com/, @acronym{QNX} home page}.
7785 @uref{http://h30097.www3.hp.com/docs/,
7786 Documentation of several versions of Tru64} is available in different
7789 @item Unix version 7
7790 @cindex Unix version 7
7792 Officially this was called the ``Seventh Edition'' of ``the @sc{unix}
7793 time-sharing system'' but we use the more-common name ``Unix version 7''.
7794 Documentation is available in the
7795 @uref{http://plan9.bell-labs.com/7thEdMan/, Unix Seventh Edition Manual}.
7796 Previous versions of Unix are called ``Unix version 6'', etc., but
7797 they were not as widely used.
7801 @node Multiple Cases
7802 @section Multiple Cases
7804 Some operations are accomplished in several possible ways, depending on
7805 the OS variant. Checking for them essentially requires a ``case
7806 statement''. Autoconf does not directly provide one; however, it is
7807 easy to simulate by using a shell variable to keep track of whether a
7808 way to perform the operation has been found yet.
7810 Here is an example that uses the shell variable @code{fstype} to keep
7811 track of whether the remaining cases need to be checked.
7815 AC_MSG_CHECKING([how to get file system type])
7817 # The order of these tests is important.
7818 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statvfs.h>
7819 #include <sys/fstyp.h>]])],
7820 [AC_DEFINE([FSTYPE_STATVFS], [1],
7821 [Define if statvfs exists.])
7823 if test $fstype = no; then
7824 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
7825 #include <sys/fstyp.h>]])],
7826 [AC_DEFINE([FSTYPE_USG_STATFS], [1],
7827 [Define if USG statfs.])
7830 if test $fstype = no; then
7831 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
7832 #include <sys/vmount.h>]])]),
7833 [AC_DEFINE([FSTYPE_AIX_STATFS], [1],
7834 [Define if AIX statfs.])
7837 # (more cases omitted here)
7838 AC_MSG_RESULT([$fstype])
7842 @c ====================================================== Results of Tests.
7845 @chapter Results of Tests
7847 Once @command{configure} has determined whether a feature exists, what can
7848 it do to record that information? There are four sorts of things it can
7849 do: define a C preprocessor symbol, set a variable in the output files,
7850 save the result in a cache file for future @command{configure} runs, and
7851 print a message letting the user know the result of the test.
7854 * Defining Symbols:: Defining C preprocessor symbols
7855 * Setting Output Variables:: Replacing variables in output files
7856 * Caching Results:: Speeding up subsequent @command{configure} runs
7857 * Printing Messages:: Notifying @command{configure} users
7860 @node Defining Symbols
7861 @section Defining C Preprocessor Symbols
7863 A common action to take in response to a feature test is to define a C
7864 preprocessor symbol indicating the results of the test. That is done by
7865 calling @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}.
7867 By default, @code{AC_OUTPUT} places the symbols defined by these macros
7868 into the output variable @code{DEFS}, which contains an option
7869 @option{-D@var{symbol}=@var{value}} for each symbol defined. Unlike in
7870 Autoconf version 1, there is no variable @code{DEFS} defined while
7871 @command{configure} is running. To check whether Autoconf macros have
7872 already defined a certain C preprocessor symbol, test the value of the
7873 appropriate cache variable, as in this example:
7876 AC_CHECK_FUNC([vprintf], [AC_DEFINE([HAVE_VPRINTF], [1],
7877 [Define if vprintf exists.])])
7878 if test "$ac_cv_func_vprintf" != yes; then
7879 AC_CHECK_FUNC([_doprnt], [AC_DEFINE([HAVE_DOPRNT], [1],
7880 [Define if _doprnt exists.])])
7884 If @code{AC_CONFIG_HEADERS} has been called, then instead of creating
7885 @code{DEFS}, @code{AC_OUTPUT} creates a header file by substituting the
7886 correct values into @code{#define} statements in a template file.
7887 @xref{Configuration Headers}, for more information about this kind of
7890 @defmac AC_DEFINE (@var{variable}, @var{value}, @ovar{description})
7891 @defmacx AC_DEFINE (@var{variable})
7893 Define the C preprocessor variable @var{variable} to @var{value} (verbatim).
7894 @var{value} should not contain literal newlines, and if you are not
7895 using @code{AC_CONFIG_HEADERS} it should not contain any @samp{#}
7896 characters, as @command{make} tends to eat them. To use a shell variable,
7897 use @code{AC_DEFINE_UNQUOTED} instead.
7898 @var{description} is only useful if you are using
7899 @code{AC_CONFIG_HEADERS}. In this case, @var{description} is put into
7900 the generated @file{config.h.in} as the comment before the macro define.
7901 The following example defines the C preprocessor variable
7902 @code{EQUATION} to be the string constant @samp{"$a > $b"}:
7905 AC_DEFINE([EQUATION], ["$a > $b"],
7909 If neither @var{value} nor @var{description} are given, then
7910 @var{value} defaults to 1 instead of to the empty string. This is for
7911 backwards compatibility with older versions of Autoconf, but this usage
7912 is obsolescent and may be withdrawn in future versions of Autoconf.
7915 @defmac AC_DEFINE_UNQUOTED (@var{variable}, @var{value}, @ovar{description})
7916 @defmacx AC_DEFINE_UNQUOTED (@var{variable})
7917 @acindex{DEFINE_UNQUOTED}
7918 Like @code{AC_DEFINE}, but three shell expansions are
7919 performed---once---on @var{variable} and @var{value}: variable expansion
7920 (@samp{$}), command substitution (@samp{`}), and backslash escaping
7921 (@samp{\}). Single and double quote characters in the value have no
7922 special meaning. Use this macro instead of @code{AC_DEFINE} when
7923 @var{variable} or @var{value} is a shell variable. Examples:
7926 AC_DEFINE_UNQUOTED([config_machfile], ["$machfile"],
7927 [Configuration machine file.])
7928 AC_DEFINE_UNQUOTED([GETGROUPS_T], [$ac_cv_type_getgroups],
7929 [getgroups return type.])
7930 AC_DEFINE_UNQUOTED([$ac_tr_hdr], [1],
7931 [Translated header name.])
7935 Due to a syntactical bizarreness of the Bourne shell, do not use
7936 semicolons to separate @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}
7937 calls from other macro calls or shell code; that can cause syntax errors
7938 in the resulting @command{configure} script. Use either blanks or
7939 newlines. That is, do this:
7942 AC_CHECK_HEADER([elf.h],
7943 [AC_DEFINE([SVR4], [1], [System V Release 4]) LIBS="-lelf $LIBS"])
7950 AC_CHECK_HEADER([elf.h],
7951 [AC_DEFINE([SVR4], [1], [System V Release 4])
7952 LIBS="-lelf $LIBS"])
7959 AC_CHECK_HEADER([elf.h],
7960 [AC_DEFINE([SVR4], [1], [System V Release 4]); LIBS="-lelf $LIBS"])
7963 @node Setting Output Variables
7964 @section Setting Output Variables
7965 @cindex Output variables
7967 Another way to record the results of tests is to set @dfn{output
7968 variables}, which are shell variables whose values are substituted into
7969 files that @command{configure} outputs. The two macros below create new
7970 output variables. @xref{Preset Output Variables}, for a list of output
7971 variables that are always available.
7973 @defmac AC_SUBST (@var{variable}, @ovar{value})
7975 Create an output variable from a shell variable. Make @code{AC_OUTPUT}
7976 substitute the variable @var{variable} into output files (typically one
7977 or more @file{Makefile}s). This means that @code{AC_OUTPUT} will
7978 replace instances of @samp{@@@var{variable}@@} in input files with the
7979 value that the shell variable @var{variable} has when @code{AC_OUTPUT}
7980 is called. The value can contain newlines.
7981 The substituted value is not rescanned for more output variables;
7982 occurrences of @samp{@@@var{variable}@@} in the value are inserted
7983 literally into the output file. (The algorithm uses the special marker
7984 @code{|#_!!_#|} internally, so the substituted value cannot contain
7987 If @var{value} is given, in addition assign it to @var{variable}.
7989 The string @var{variable} is passed to @code{m4_pattern_allow}
7990 (@pxref{Forbidden Patterns}).
7993 @defmac AC_SUBST_FILE (@var{variable})
7994 @acindex{SUBST_FILE}
7995 Another way to create an output variable from a shell variable. Make
7996 @code{AC_OUTPUT} insert (without substitutions) the contents of the file
7997 named by shell variable @var{variable} into output files. This means
7998 that @code{AC_OUTPUT} will replace instances of
7999 @samp{@@@var{variable}@@} in output files (such as @file{Makefile.in})
8000 with the contents of the file that the shell variable @var{variable}
8001 names when @code{AC_OUTPUT} is called. Set the variable to
8002 @file{/dev/null} for cases that do not have a file to insert.
8003 This substitution occurs only when the @samp{@@@var{variable}@@} is on a
8004 line by itself, optionally surrounded by spaces and tabs. The
8005 substitution replaces the whole line, including the spaces, tabs, and
8006 the terminating newline.
8008 This macro is useful for inserting @file{Makefile} fragments containing
8009 special dependencies or other @code{make} directives for particular host
8010 or target types into @file{Makefile}s. For example, @file{configure.ac}
8014 AC_SUBST_FILE([host_frag])
8015 host_frag=$srcdir/conf/sun4.mh
8019 and then a @file{Makefile.in} could contain:
8025 The string @var{variable} is passed to @code{m4_pattern_allow}
8026 (@pxref{Forbidden Patterns}).
8029 @cindex Previous Variable
8030 @cindex Variable, Precious
8031 Running @command{configure} in varying environments can be extremely
8032 dangerous. If for instance the user runs @samp{CC=bizarre-cc
8033 ./configure}, then the cache, @file{config.h}, and many other output
8034 files will depend upon @command{bizarre-cc} being the C compiler. If
8035 for some reason the user runs @command{./configure} again, or if it is
8036 run via @samp{./config.status --recheck}, (@xref{Automatic Remaking},
8037 and @pxref{config.status Invocation}), then the configuration can be
8038 inconsistent, composed of results depending upon two different
8041 Environment variables that affect this situation, such as @samp{CC}
8042 above, are called @dfn{precious variables}, and can be declared as such
8043 by @code{AC_ARG_VAR}.
8045 @defmac AC_ARG_VAR (@var{variable}, @var{description})
8047 Declare @var{variable} is a precious variable, and include its
8048 @var{description} in the variable section of @samp{./configure --help}.
8050 Being precious means that
8053 @var{variable} is @code{AC_SUBST}'d.
8056 The value of @var{variable} when @command{configure} was launched is
8057 saved in the cache, including if it was not specified on the command
8058 line but via the environment. Indeed, while @command{configure} can
8059 notice the definition of @code{CC} in @samp{./configure CC=bizarre-cc},
8060 it is impossible to notice it in @samp{CC=bizarre-cc ./configure},
8061 which, unfortunately, is what most users do.
8063 We emphasize that it is the @emph{initial} value of @var{variable} which
8064 is saved, not that found during the execution of @command{configure}.
8065 Indeed, specifying @samp{./configure FOO=foo} and letting
8066 @samp{./configure} guess that @code{FOO} is @code{foo} can be two very
8070 @var{variable} is checked for consistency between two
8071 @command{configure} runs. For instance:
8074 $ @kbd{./configure --silent --config-cache}
8075 $ @kbd{CC=cc ./configure --silent --config-cache}
8076 configure: error: `CC' was not set in the previous run
8077 configure: error: changes in the environment can compromise \
8079 configure: error: run `make distclean' and/or \
8080 `rm config.cache' and start over
8084 and similarly if the variable is unset, or if its content is changed.
8088 @var{variable} is kept during automatic reconfiguration
8089 (@pxref{config.status Invocation}) as if it had been passed as a command
8090 line argument, including when no cache is used:
8093 $ @kbd{CC=/usr/bin/cc ./configure undeclared_var=raboof --silent}
8094 $ @kbd{./config.status --recheck}
8095 running /bin/sh ./configure undeclared_var=raboof --silent \
8096 CC=/usr/bin/cc --no-create --no-recursion
8102 @node Caching Results
8103 @section Caching Results
8106 To avoid checking for the same features repeatedly in various
8107 @command{configure} scripts (or in repeated runs of one script),
8108 @command{configure} can optionally save the results of many checks in a
8109 @dfn{cache file} (@pxref{Cache Files}). If a @command{configure} script
8110 runs with caching enabled and finds a cache file, it reads the results
8111 of previous runs from the cache and avoids rerunning those checks. As a
8112 result, @command{configure} can then run much faster than if it had to
8113 perform all of the checks every time.
8115 @defmac AC_CACHE_VAL (@var{cache-id}, @var{commands-to-set-it})
8117 Ensure that the results of the check identified by @var{cache-id} are
8118 available. If the results of the check were in the cache file that was
8119 read, and @command{configure} was not given the @option{--quiet} or
8120 @option{--silent} option, print a message saying that the result was
8121 cached; otherwise, run the shell commands @var{commands-to-set-it}. If
8122 the shell commands are run to determine the value, the value will be
8123 saved in the cache file just before @command{configure} creates its output
8124 files. @xref{Cache Variable Names}, for how to choose the name of the
8125 @var{cache-id} variable.
8127 The @var{commands-to-set-it} @emph{must have no side effects} except for
8128 setting the variable @var{cache-id}, see below.
8131 @defmac AC_CACHE_CHECK (@var{message}, @var{cache-id}, @var{commands-to-set-it})
8132 @acindex{CACHE_CHECK}
8133 A wrapper for @code{AC_CACHE_VAL} that takes care of printing the
8134 messages. This macro provides a convenient shorthand for the most
8135 common way to use these macros. It calls @code{AC_MSG_CHECKING} for
8136 @var{message}, then @code{AC_CACHE_VAL} with the @var{cache-id} and
8137 @var{commands} arguments, and @code{AC_MSG_RESULT} with @var{cache-id}.
8139 The @var{commands-to-set-it} @emph{must have no side effects} except for
8140 setting the variable @var{cache-id}, see below.
8143 It is very common to find buggy macros using @code{AC_CACHE_VAL} or
8144 @code{AC_CACHE_CHECK}, because people are tempted to call
8145 @code{AC_DEFINE} in the @var{commands-to-set-it}. Instead, the code that
8146 @emph{follows} the call to @code{AC_CACHE_VAL} should call
8147 @code{AC_DEFINE}, by examining the value of the cache variable. For
8148 instance, the following macro is broken:
8152 AC_DEFUN([AC_SHELL_TRUE],
8153 [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
8154 [ac_cv_shell_true_works=no
8155 (true) 2>/dev/null && ac_cv_shell_true_works=yes
8156 if test "$ac_cv_shell_true_works" = yes; then
8157 AC_DEFINE([TRUE_WORKS], [1],
8158 [Define if `true(1)' works properly.])
8165 This fails if the cache is enabled: the second time this macro is run,
8166 @code{TRUE_WORKS} @emph{will not be defined}. The proper implementation
8171 AC_DEFUN([AC_SHELL_TRUE],
8172 [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
8173 [ac_cv_shell_true_works=no
8174 (true) 2>/dev/null && ac_cv_shell_true_works=yes])
8175 if test "$ac_cv_shell_true_works" = yes; then
8176 AC_DEFINE([TRUE_WORKS], [1],
8177 [Define if `true(1)' works properly.])
8183 Also, @var{commands-to-set-it} should not print any messages, for
8184 example with @code{AC_MSG_CHECKING}; do that before calling
8185 @code{AC_CACHE_VAL}, so the messages are printed regardless of whether
8186 the results of the check are retrieved from the cache or determined by
8187 running the shell commands.
8190 * Cache Variable Names:: Shell variables used in caches
8191 * Cache Files:: Files @command{configure} uses for caching
8192 * Cache Checkpointing:: Loading and saving the cache file
8195 @node Cache Variable Names
8196 @subsection Cache Variable Names
8197 @cindex Cache variable
8199 The names of cache variables should have the following format:
8202 @var{package-prefix}_cv_@var{value-type}_@var{specific-value}_@ovar{additional-options}
8206 for example, @samp{ac_cv_header_stat_broken} or
8207 @samp{ac_cv_prog_gcc_traditional}. The parts of the variable name are:
8210 @item @var{package-prefix}
8211 An abbreviation for your package or organization; the same prefix you
8212 begin local Autoconf macros with, except lowercase by convention.
8213 For cache values used by the distributed Autoconf macros, this value is
8217 Indicates that this shell variable is a cache value. This string
8218 @emph{must} be present in the variable name, including the leading
8221 @item @var{value-type}
8222 A convention for classifying cache values, to produce a rational naming
8223 system. The values used in Autoconf are listed in @ref{Macro Names}.
8225 @item @var{specific-value}
8226 Which member of the class of cache values this test applies to.
8227 For example, which function (@samp{alloca}), program (@samp{gcc}), or
8228 output variable (@samp{INSTALL}).
8230 @item @var{additional-options}
8231 Any particular behavior of the specific member that this test applies to.
8232 For example, @samp{broken} or @samp{set}. This part of the name may
8233 be omitted if it does not apply.
8236 The values assigned to cache variables may not contain newlines.
8237 Usually, their values will be Boolean (@samp{yes} or @samp{no}) or the
8238 names of files or functions; so this is not an important restriction.
8241 @subsection Cache Files
8243 A cache file is a shell script that caches the results of configure
8244 tests run on one system so they can be shared between configure scripts
8245 and configure runs. It is not useful on other systems. If its contents
8246 are invalid for some reason, the user may delete or edit it.
8248 By default, @command{configure} uses no cache file,
8249 to avoid problems caused by accidental
8250 use of stale cache files.
8252 To enable caching, @command{configure} accepts @option{--config-cache} (or
8253 @option{-C}) to cache results in the file @file{config.cache}.
8254 Alternatively, @option{--cache-file=@var{file}} specifies that
8255 @var{file} be the cache file. The cache file is created if it does not
8256 exist already. When @command{configure} calls @command{configure} scripts in
8257 subdirectories, it uses the @option{--cache-file} argument so that they
8258 share the same cache. @xref{Subdirectories}, for information on
8259 configuring subdirectories with the @code{AC_CONFIG_SUBDIRS} macro.
8261 @file{config.status} only pays attention to the cache file if it is
8262 given the @option{--recheck} option, which makes it rerun
8263 @command{configure}.
8265 It is wrong to try to distribute cache files for particular system types.
8266 There is too much room for error in doing that, and too much
8267 administrative overhead in maintaining them. For any features that
8268 can't be guessed automatically, use the standard method of the canonical
8269 system type and linking files (@pxref{Manual Configuration}).
8271 The site initialization script can specify a site-wide cache file to
8272 use, instead of the usual per-program cache. In this case, the cache
8273 file will gradually accumulate information whenever someone runs a new
8274 @command{configure} script. (Running @command{configure} merges the new cache
8275 results with the existing cache file.) This may cause problems,
8276 however, if the system configuration (e.g., the installed libraries or
8277 compilers) changes and the stale cache file is not deleted.
8279 @node Cache Checkpointing
8280 @subsection Cache Checkpointing
8282 If your configure script, or a macro called from @file{configure.ac}, happens
8283 to abort the configure process, it may be useful to checkpoint the cache
8284 a few times at key points using @code{AC_CACHE_SAVE}. Doing so will
8285 reduce the amount of time it takes to re-run the configure script with
8286 (hopefully) the error that caused the previous abort corrected.
8288 @c FIXME: Do we really want to document this guy?
8289 @defmac AC_CACHE_LOAD
8290 @acindex{CACHE_LOAD}
8291 Loads values from existing cache file, or creates a new cache file if a
8292 cache file is not found. Called automatically from @code{AC_INIT}.
8295 @defmac AC_CACHE_SAVE
8296 @acindex{CACHE_SAVE}
8297 Flushes all cached values to the cache file. Called automatically from
8298 @code{AC_OUTPUT}, but it can be quite useful to call
8299 @code{AC_CACHE_SAVE} at key points in @file{configure.ac}.
8305 @r{ @dots{} AC_INIT, etc. @dots{}}
8307 # Checks for programs.
8309 AC_PROG_GCC_TRADITIONAL
8310 @r{ @dots{} more program checks @dots{}}
8315 # Checks for libraries.
8316 AC_CHECK_LIB([nsl], [gethostbyname])
8317 AC_CHECK_LIB([socket], [connect])
8318 @r{ @dots{} more lib checks @dots{}}
8323 # Might abort@dots{}
8324 AM_PATH_GTK([1.0.2], [], [AC_MSG_ERROR([GTK not in path])])
8325 AM_PATH_GTKMM([0.9.5], [], [AC_MSG_ERROR([GTK not in path])])
8327 @r{ @dots{} AC_OUTPUT, etc. @dots{}}
8330 @node Printing Messages
8331 @section Printing Messages
8332 @cindex Messages, from @command{configure}
8334 @command{configure} scripts need to give users running them several kinds
8335 of information. The following macros print messages in ways appropriate
8336 for each kind. The arguments to all of them get enclosed in shell
8337 double quotes, so the shell performs variable and back-quote
8338 substitution on them.
8340 These macros are all wrappers around the @command{echo} shell command,
8341 and will direct output to the appropriate file descriptor (@pxref{File
8342 Descriptor Macros}).
8343 @command{configure} scripts should rarely need to run @command{echo} directly
8344 to print messages for the user. Using these macros makes it easy to
8345 change how and when each kind of message is printed; such changes need
8346 only be made to the macro definitions and all the callers will change
8349 To diagnose static issues, i.e., when @command{autoconf} is run, see
8350 @ref{Reporting Messages}.
8352 @defmac AC_MSG_CHECKING (@var{feature-description})
8353 @acindex{MSG_CHECKING}
8354 Notify the user that @command{configure} is checking for a particular
8355 feature. This macro prints a message that starts with @samp{checking }
8356 and ends with @samp{...} and no newline. It must be followed by a call
8357 to @code{AC_MSG_RESULT} to print the result of the check and the
8358 newline. The @var{feature-description} should be something like
8359 @samp{whether the Fortran compiler accepts C++ comments} or @samp{for
8362 This macro prints nothing if @command{configure} is run with the
8363 @option{--quiet} or @option{--silent} option.
8366 @defmac AC_MSG_RESULT (@var{result-description})
8367 @acindex{MSG_RESULT}
8368 Notify the user of the results of a check. @var{result-description} is
8369 almost always the value of the cache variable for the check, typically
8370 @samp{yes}, @samp{no}, or a file name. This macro should follow a call
8371 to @code{AC_MSG_CHECKING}, and the @var{result-description} should be
8372 the completion of the message printed by the call to
8373 @code{AC_MSG_CHECKING}.
8375 This macro prints nothing if @command{configure} is run with the
8376 @option{--quiet} or @option{--silent} option.
8379 @defmac AC_MSG_NOTICE (@var{message})
8380 @acindex{MSG_NOTICE}
8381 Deliver the @var{message} to the user. It is useful mainly to print a
8382 general description of the overall purpose of a group of feature checks,
8386 AC_MSG_NOTICE([checking if stack overflow is detectable])
8389 This macro prints nothing if @command{configure} is run with the
8390 @option{--quiet} or @option{--silent} option.
8393 @defmac AC_MSG_ERROR (@var{error-description}, @ovar{exit-status})
8395 Notify the user of an error that prevents @command{configure} from
8396 completing. This macro prints an error message to the standard error
8397 output and exits @command{configure} with @var{exit-status} (1 by default).
8398 @var{error-description} should be something like @samp{invalid value
8401 The @var{error-description} should start with a lower-case letter, and
8402 ``cannot'' is preferred to ``can't''.
8405 @defmac AC_MSG_FAILURE (@var{error-description}, @ovar{exit-status})
8406 @acindex{MSG_FAILURE}
8407 This @code{AC_MSG_ERROR} wrapper notifies the user of an error that
8408 prevents @command{configure} from completing @emph{and} that additional
8409 details are provided in @file{config.log}. This is typically used when
8410 abnormal results are found during a compilation.
8413 @defmac AC_MSG_WARN (@var{problem-description})
8415 Notify the @command{configure} user of a possible problem. This macro
8416 prints the message to the standard error output; @command{configure}
8417 continues running afterward, so macros that call @code{AC_MSG_WARN} should
8418 provide a default (back-up) behavior for the situations they warn about.
8419 @var{problem-description} should be something like @samp{ln -s seems to
8425 @c ====================================================== Programming in M4.
8427 @node Programming in M4
8428 @chapter Programming in M4
8431 Autoconf is written on top of two layers: @dfn{M4sugar}, which provides
8432 convenient macros for pure M4 programming, and @dfn{M4sh}, which
8433 provides macros dedicated to shell script generation.
8435 As of this version of Autoconf, these two layers are still experimental,
8436 and their interface might change in the future. As a matter of fact,
8437 @emph{anything that is not documented must not be used}.
8440 * M4 Quotation:: Protecting macros from unwanted expansion
8441 * Using autom4te:: The Autoconf executables backbone
8442 * Programming in M4sugar:: Convenient pure M4 macros
8443 * Programming in M4sh:: Common shell Constructs
8444 * File Descriptor Macros:: File descriptor macros for input and output
8448 @section M4 Quotation
8449 @cindex M4 quotation
8452 @c FIXME: Grmph, yet another quoting myth: quotation has *never*
8453 @c prevented `expansion' of $1. Unless it refers to the expansion
8454 @c of the value of $1? Anyway, we need a rewrite here@enddots{}
8456 The most common problem with existing macros is an improper quotation.
8457 This section, which users of Autoconf can skip, but which macro writers
8458 @emph{must} read, first justifies the quotation scheme that was chosen
8459 for Autoconf and then ends with a rule of thumb. Understanding the
8460 former helps one to follow the latter.
8463 * Active Characters:: Characters that change the behavior of M4
8464 * One Macro Call:: Quotation and one macro call
8465 * Quotation and Nested Macros:: Macros calling macros
8466 * Changequote is Evil:: Worse than INTERCAL: M4 + changequote
8467 * Quadrigraphs:: Another way to escape special characters
8468 * Quotation Rule Of Thumb:: One parenthesis, one quote
8471 @node Active Characters
8472 @subsection Active Characters
8474 To fully understand where proper quotation is important, you first need
8475 to know what the special characters are in Autoconf: @samp{#} introduces
8476 a comment inside which no macro expansion is performed, @samp{,}
8477 separates arguments, @samp{[} and @samp{]} are the quotes themselves,
8478 and finally @samp{(} and @samp{)} (which M4 tries to match by
8481 In order to understand the delicate case of macro calls, we first have
8482 to present some obvious failures. Below they are ``obvious-ified'',
8483 but when you find them in real life, they are usually in disguise.
8485 Comments, introduced by a hash and running up to the newline, are opaque
8486 tokens to the top level: active characters are turned off, and there is
8490 # define([def], ine)
8491 @result{}# define([def], ine)
8494 Each time there can be a macro expansion, there is a quotation
8495 expansion, i.e., one level of quotes is stripped:
8501 @result{}int tab[10];
8504 Without this in mind, the reader will try hopelessly to use her macro
8508 define([array], [int tab[10];])
8516 How can you correctly output the intended results@footnote{Using
8520 @node One Macro Call
8521 @subsection One Macro Call
8523 Let's proceed on the interaction between active characters and macros
8524 with this small macro, which just returns its first argument:
8531 The two pairs of quotes above are not part of the arguments of
8532 @code{define}; rather, they are understood by the top level when it
8533 tries to find the arguments of @code{define}. Therefore, assuming
8534 @code{car} is not already defined, it is equivalent to write:
8541 But, while it is acceptable for a @file{configure.ac} to avoid unnecessary
8542 quotes, it is bad practice for Autoconf macros which must both be more
8543 robust and also advocate perfect style.
8545 At the top level, there are only two possibilities: either you
8551 [car(foo, bar, baz)]
8552 @result{}car(foo, bar, baz)
8555 Let's pay attention to the special characters:
8559 @error{}EOF in argument list
8562 The closing parenthesis is hidden in the comment; with a hypothetical
8563 quoting, the top level understood it this way:
8570 Proper quotation, of course, fixes the problem:
8577 Here are more examples:
8600 With this in mind, we can explore the cases where macros invoke
8604 @node Quotation and Nested Macros
8605 @subsection Quotation and Nested Macros
8607 The examples below use the following macros:
8611 define([active], [ACT, IVE])
8612 define([array], [int tab[10]])
8615 Each additional embedded macro call introduces other possible
8616 interesting quotations:
8627 In the first case, the top level looks for the arguments of @code{car},
8628 and finds @samp{active}. Because M4 evaluates its arguments
8629 before applying the macro, @samp{active} is expanded, which results in:
8637 In the second case, the top level gives @samp{active} as first and only
8638 argument of @code{car}, which results in:
8646 i.e., the argument is evaluated @emph{after} the macro that invokes it.
8647 In the third case, @code{car} receives @samp{[active]}, which results in:
8655 exactly as we already saw above.
8657 The example above, applied to a more realistic example, gives:
8664 car([[int tab[10];]])
8665 @result{}int tab[10];
8669 Huh? The first case is easily understood, but why is the second wrong,
8670 and the third right? To understand that, you must know that after
8671 M4 expands a macro, the resulting text is immediately subjected
8672 to macro expansion and quote removal. This means that the quote removal
8673 occurs twice---first before the argument is passed to the @code{car}
8674 macro, and second after the @code{car} macro expands to the first
8677 As the author of the Autoconf macro @code{car}, you then consider it to
8678 be incorrect that your users have to double-quote the arguments of
8679 @code{car}, so you ``fix'' your macro. Let's call it @code{qar} for
8683 define([qar], [[$1]])
8687 and check that @code{qar} is properly fixed:
8691 @result{}int tab[10];
8695 Ahhh! That's much better.
8697 But note what you've done: now that the arguments are literal strings,
8698 if the user wants to use the results of expansions as arguments, she has
8699 to use an @emph{unquoted} macro call:
8707 where she wanted to reproduce what she used to do with @code{car}:
8715 Worse yet: she wants to use a macro that produces a set of @code{cpp}
8719 define([my_includes], [#include <stdio.h>])
8721 @result{}#include <stdio.h>
8723 @error{}EOF in argument list
8726 This macro, @code{qar}, because it double quotes its arguments, forces
8727 its users to leave their macro calls unquoted, which is dangerous.
8728 Commas and other active symbols are interpreted by M4 before
8729 they are given to the macro, often not in the way the users expect.
8730 Also, because @code{qar} behaves differently from the other macros,
8731 it's an exception that should be avoided in Autoconf.
8733 @node Changequote is Evil
8734 @subsection @code{changequote} is Evil
8735 @cindex @code{changequote}
8737 The temptation is often high to bypass proper quotation, in particular
8738 when it's late at night. Then, many experienced Autoconf hackers
8739 finally surrender to the dark side of the force and use the ultimate
8740 weapon: @code{changequote}.
8742 The M4 builtin @code{changequote} belongs to a set of primitives that
8743 allow one to adjust the syntax of the language to adjust it to one's
8744 needs. For instance, by default M4 uses @samp{`} and @samp{'} as
8745 quotes, but in the context of shell programming (and actually of most
8746 programming languages), that's about the worst choice one can make:
8747 because of strings and back-quoted expressions in shell code (such as
8748 @samp{'this'} and @samp{`that`}), because of literal characters in usual
8749 programming languages (as in @samp{'0'}), there are many unbalanced
8750 @samp{`} and @samp{'}. Proper M4 quotation then becomes a nightmare, if
8751 not impossible. In order to make M4 useful in such a context, its
8752 designers have equipped it with @code{changequote}, which makes it
8753 possible to choose another pair of quotes. M4sugar, M4sh, Autoconf, and
8754 Autotest all have chosen to use @samp{[} and @samp{]}. Not especially
8755 because they are unlikely characters, but @emph{because they are
8756 characters unlikely to be unbalanced}.
8758 There are other magic primitives, such as @code{changecom} to specify
8759 what syntactic forms are comments (it is common to see
8760 @samp{changecom(<!--, -->)} when M4 is used to produce HTML pages),
8761 @code{changeword} and @code{changesyntax} to change other syntactic
8762 details (such as the character to denote the @var{n}th argument, @samp{$} by
8763 default, the parenthesis around arguments, etc.).
8765 These primitives are really meant to make M4 more useful for specific
8766 domains: they should be considered like command line options:
8767 @option{--quotes}, @option{--comments}, @option{--words}, and
8768 @code{--syntax}. Nevertheless, they are implemented as M4 builtins, as
8769 it makes M4 libraries self contained (no need for additional options).
8771 There lies the problem@enddots{}
8775 The problem is that it is then tempting to use them in the middle of an
8776 M4 script, as opposed to its initialization. This, if not carefully
8777 thought out, can lead to disastrous effects: @emph{you are changing the
8778 language in the middle of the execution}. Changing and restoring the
8779 syntax is often not enough: if you happened to invoke macros in between,
8780 these macros will be lost, as the current syntax will probably not be
8781 the one they were implemented with.
8783 @c FIXME: I've been looking for a short, real case example, but I
8788 @subsection Quadrigraphs
8789 @cindex quadrigraphs
8790 @cindex @samp{@@S|@@}
8791 @cindex @samp{@@&t@@}
8792 @c Info cannot handle `:' in index entries.
8793 @c @cindex @samp{@@<:@@}
8794 @c @cindex @samp{@@:>@@}
8795 @c @cindex @samp{@@%:@@}
8797 When writing an Autoconf macro you may occasionally need to generate
8798 special characters that are difficult to express with the standard
8799 Autoconf quoting rules. For example, you may need to output the regular
8800 expression @samp{[^[]}, which matches any character other than @samp{[}.
8801 This expression contains unbalanced brackets so it cannot be put easily
8804 You can work around this problem by using one of the following
8820 Quadrigraphs are replaced at a late stage of the translation process,
8821 after @command{m4} is run, so they do not get in the way of M4 quoting.
8822 For example, the string @samp{^@@<:@@}, independently of its quotation,
8823 will appear as @samp{^[} in the output.
8825 The empty quadrigraph can be used:
8828 @item to mark trailing spaces explicitly
8830 Trailing spaces are smashed by @command{autom4te}. This is a feature.
8832 @item to produce other quadrigraphs
8834 For instance @samp{@@<@@&t@@:@@} produces @samp{@@<:@@}.
8836 @item to escape @emph{occurrences} of forbidden patterns
8838 For instance you might want to mention @code{AC_FOO} in a comment, while
8839 still being sure that @command{autom4te} will still catch unexpanded
8840 @samp{AC_*}. Then write @samp{AC@@&t@@_FOO}.
8843 The name @samp{@@&t@@} was suggested by Paul Eggert:
8846 I should give some credit to the @samp{@@&t@@} pun. The @samp{&} is my
8847 own invention, but the @samp{t} came from the source code of the
8848 @sc{algol68c} compiler, written by Steve Bourne (of Bourne shell fame),
8849 and which used @samp{mt} to denote the empty string. In C, it would
8850 have looked like something like:
8853 char const mt[] = "";
8857 but of course the source code was written in Algol 68.
8859 I don't know where he got @samp{mt} from: it could have been his own
8860 invention, and I suppose it could have been a common pun around the
8861 Cambridge University computer lab at the time.
8864 @node Quotation Rule Of Thumb
8865 @subsection Quotation Rule Of Thumb
8867 To conclude, the quotation rule of thumb is:
8869 @center @emph{One pair of quotes per pair of parentheses.}
8871 Never over-quote, never under-quote, in particular in the definition of
8872 macros. In the few places where the macros need to use brackets
8873 (usually in C program text or regular expressions), properly quote
8874 @emph{the arguments}!
8876 It is common to read Autoconf programs with snippets like:
8880 changequote(<<, >>)dnl
8882 #ifndef tzname /* For SGI. */
8883 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
8885 changequote([, ])dnl
8886 [atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)
8890 which is incredibly useless since @code{AC_TRY_LINK} is @emph{already}
8891 double quoting, so you just need:
8896 #ifndef tzname /* For SGI. */
8897 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
8900 [ac_cv_var_tzname=yes],
8901 [ac_cv_var_tzname=no])
8905 The M4-fluent reader will note that these two examples are rigorously
8906 equivalent, since M4 swallows both the @samp{changequote(<<, >>)}
8907 and @samp{<<} @samp{>>} when it @dfn{collects} the arguments: these
8908 quotes are not part of the arguments!
8910 Simplified, the example above is just doing this:
8913 changequote(<<, >>)dnl
8915 changequote([, ])dnl
8925 With macros that do not double quote their arguments (which is the
8926 rule), double-quote the (risky) literals:
8929 AC_LINK_IFELSE([AC_LANG_PROGRAM(
8931 #ifndef tzname /* For SGI. */
8932 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
8934 [atoi (*tzname);])],
8935 [ac_cv_var_tzname=yes],
8936 [ac_cv_var_tzname=no])
8939 Please note that the macro @code{AC_TRY_LINK} is obsolete, so you really
8940 should be using @code{AC_LINK_IFELSE} instead.
8942 @xref{Quadrigraphs}, for what to do if you run into a hopeless case
8943 where quoting does not suffice.
8945 When you create a @command{configure} script using newly written macros,
8946 examine it carefully to check whether you need to add more quotes in
8947 your macros. If one or more words have disappeared in the M4
8948 output, you need more quotes. When in doubt, quote.
8950 However, it's also possible to put on too many layers of quotes. If
8951 this happens, the resulting @command{configure} script may contain
8952 unexpanded macros. The @command{autoconf} program checks for this problem
8953 by looking for the string @samp{AC_} in @file{configure}. However, this
8954 heuristic does not work in general: for example, it does not catch
8955 overquoting in @code{AC_DEFINE} descriptions.
8958 @c ---------------------------------------- Using autom4te
8960 @node Using autom4te
8961 @section Using @command{autom4te}
8963 The Autoconf suite, including M4sugar, M4sh, and Autotest, in addition
8964 to Autoconf per se, heavily rely on M4. All these different uses
8965 revealed common needs factored into a layer over @command{m4}:
8966 @command{autom4te}@footnote{
8968 Yet another great name from Lars J. Aas.
8972 @command{autom4te} is a preprocessor that is like @command{m4}.
8973 It supports M4 extensions designed for use in tools like Autoconf.
8976 * autom4te Invocation:: A @acronym{GNU} M4 wrapper
8977 * Customizing autom4te:: Customizing the Autoconf package
8980 @node autom4te Invocation
8981 @subsection Invoking @command{autom4te}
8983 The command line arguments are modeled after M4's:
8986 autom4te @var{options} @var{files}
8990 where the @var{files} are directly passed to @command{m4}. In addition
8991 to the regular expansion, it handles the replacement of the quadrigraphs
8992 (@pxref{Quadrigraphs}), and of @samp{__oline__}, the current line in the
8993 output. It supports an extended syntax for the @var{files}:
8996 @item @var{file}.m4f
8997 This file is an M4 frozen file. Note that @emph{all the previous files
8998 are ignored}. See the option @option{--melt} for the rationale.
9001 If found in the library path, the @var{file} is included for expansion,
9002 otherwise it is ignored instead of triggering a failure.
9007 Of course, it supports the Autoconf common subset of options:
9012 Print a summary of the command line options and exit.
9016 Print the version number of Autoconf and exit.
9020 Report processing steps.
9024 Don't remove the temporary files and be even more verbose.
9026 @item --include=@var{dir}
9028 Also look for input files in @var{dir}. Multiple invocations
9031 @item --output=@var{file}
9032 @itemx -o @var{file}
9033 Save output (script or trace) to @var{file}. The file @option{-} stands
9034 for the standard output.
9039 As an extension of @command{m4}, it includes the following options:
9042 @item --warnings=@var{category}
9043 @itemx -W @var{category}
9045 @c FIXME: Point to the M4sugar macros, not Autoconf's.
9046 Report the warnings related to @var{category} (which can actually be a
9047 comma separated list). @xref{Reporting Messages}, macro
9048 @code{AC_DIAGNOSE}, for a comprehensive list of categories. Special
9053 report all the warnings
9059 treats warnings as errors
9061 @item no-@var{category}
9062 disable warnings falling into @var{category}
9065 Warnings about @samp{syntax} are enabled by default, and the environment
9066 variable @env{WARNINGS}, a comma separated list of categories, is
9067 honored. @command{autom4te -W @var{category}} will actually
9068 behave as if you had run:
9071 autom4te --warnings=syntax,$WARNINGS,@var{category}
9075 For example, if you want to disable @command{autom4te}'s defaults and
9076 @env{WARNINGS}, but enable the warnings about obsolete
9077 constructs, you would use @option{-W none,obsolete}.
9080 @cindex Macro invocation stack
9081 @command{autom4te} displays a back trace for errors, but not for
9082 warnings; if you want them, just pass @option{-W error}.
9086 Do not use frozen files. Any argument @code{@var{file}.m4f} will be
9087 replaced with @code{@var{file}.m4}. This helps tracing the macros which
9088 are executed only when the files are frozen, typically
9089 @code{m4_define}. For instance, running:
9092 autom4te --melt 1.m4 2.m4f 3.m4 4.m4f input.m4
9096 is roughly equivalent to running:
9099 m4 1.m4 2.m4 3.m4 4.m4 input.m4
9106 autom4te 1.m4 2.m4f 3.m4 4.m4f input.m4
9113 m4 --reload-state=4.m4f input.m4
9118 Produce a frozen state file. @command{autom4te} freezing is stricter
9119 than M4's: it must produce no warnings, and no output other than empty
9120 lines (a line with white space is @emph{not} empty) and comments
9121 (starting with @samp{#}). Please, note that contrary to @command{m4},
9122 this options takes no argument:
9125 autom4te 1.m4 2.m4 3.m4 --freeze --output=3.m4f
9132 m4 1.m4 2.m4 3.m4 --freeze-state=3.m4f
9135 @item --mode=@var{octal-mode}
9136 @itemx -m @var{octal-mode}
9137 Set the mode of the non-traces output to @var{octal-mode}; by default
9143 @cindex @file{autom4te.cache}
9144 As another additional feature over @command{m4}, @command{autom4te}
9145 caches its results. @acronym{GNU} M4 is able to produce a regular
9146 output and traces at the same time. Traces are heavily used in the
9147 @acronym{GNU} Build System: @command{autoheader} uses them to build
9148 @file{config.h.in}, @command{autoreconf} to determine what
9149 @acronym{GNU} Build System components are used, @command{automake} to
9150 ``parse'' @file{configure.ac} etc. To save the long runs of
9151 @command{m4}, traces are cached while performing regular expansion,
9152 and conversely. This cache is (actually, the caches are) stored in
9153 the directory @file{autom4te.cache}. @emph{It can safely be removed}
9154 at any moment (especially if for some reason @command{autom4te}
9155 considers it is trashed).
9158 @item --cache=@var{directory}
9159 @itemx -C @var{directory}
9160 Specify the name of the directory where the result should be cached.
9161 Passing an empty value disables caching. Be sure to pass a relative
9162 file name, as for the time being, global caches are not supported.
9165 Don't cache the results.
9169 If a cache is used, consider it obsolete (but update it anyway).
9174 Because traces are so important to the @acronym{GNU} Build System,
9175 @command{autom4te} provides high level tracing features as compared to
9176 M4, and helps exploiting the cache:
9179 @item --trace=@var{macro}[:@var{format}]
9180 @itemx -t @var{macro}[:@var{format}]
9181 Trace the invocations of @var{macro} according to the @var{format}.
9182 Multiple @option{--trace} arguments can be used to list several macros.
9183 Multiple @option{--trace} arguments for a single macro are not
9184 cumulative; instead, you should just make @var{format} as long as
9187 The @var{format} is a regular string, with newlines if desired, and
9188 several special escape codes. It defaults to @samp{$f:$l:$n:$%}. It can
9189 use the following special escapes:
9193 The character @samp{$}.
9196 The file name from which @var{macro} is called.
9199 The line number from which @var{macro} is called.
9202 The depth of the @var{macro} call. This is an M4 technical detail that
9203 you probably don't want to know about.
9206 The name of the @var{macro}.
9209 The @var{num}th argument of the call to @var{macro}.
9213 @itemx $@{@var{separator}@}@@
9214 All the arguments passed to @var{macro}, separated by the character
9215 @var{sep} or the string @var{separator} (@samp{,} by default). Each
9216 argument is quoted, i.e., enclosed in a pair of square brackets.
9220 @itemx $@{@var{separator}@}*
9221 As above, but the arguments are not quoted.
9225 @itemx $@{@var{separator}@}%
9226 As above, but the arguments are not quoted, all new line characters in
9227 the arguments are smashed, and the default separator is @samp{:}.
9229 The escape @samp{$%} produces single-line trace outputs (unless you put
9230 newlines in the @samp{separator}), while @samp{$@@} and @samp{$*} do
9234 @xref{autoconf Invocation}, for examples of trace uses.
9236 @item --preselect=@var{macro}
9237 @itemx -p @var{macro}
9238 Cache the traces of @var{macro}, but do not enable traces. This is
9239 especially important to save CPU cycles in the future. For instance,
9240 when invoked, @command{autoconf} preselects all the macros that
9241 @command{autoheader}, @command{automake}, @command{autoreconf} etc.@: will
9242 trace, so that running @command{m4} is not needed to trace them: the
9243 cache suffices. This results in a huge speed-up.
9248 @cindex Autom4te Library
9249 Finally, @command{autom4te} introduces the concept of @dfn{Autom4te
9250 libraries}. They consists in a powerful yet extremely simple feature:
9251 sets of combined command line arguments:
9254 @item --language=@var{language}
9255 @itemx -l @var{language}
9256 Use the @var{language} Autom4te library. Current languages include:
9260 create M4sugar output.
9263 create M4sh executable shell scripts.
9266 create Autotest executable test suites.
9268 @item Autoconf-without-aclocal-m4
9269 create Autoconf executable configure scripts without
9270 reading @file{aclocal.m4}.
9273 create Autoconf executable configure scripts. This language inherits
9274 all the characteristics of @code{Autoconf-without-aclocal-m4} and will
9275 additionally read @file{aclocal.m4}.
9278 @item --prepend-include=@var{dir}
9280 Prepend directory @var{dir} to the search path. This is used to include
9281 the language-specific files before any third-party macros.
9285 @cindex @file{autom4te.cfg}
9286 As an example, if Autoconf is installed in its default location,
9287 @file{/usr/local}, the command @samp{autom4te -l m4sugar foo.m4} is
9288 strictly equivalent to the command:
9291 autom4te --prepend-include /usr/local/share/autoconf \
9292 m4sugar/m4sugar.m4f --warnings syntax foo.m4
9296 Recursive expansion applies here: the command @samp{autom4te -l m4sh foo.m4}
9297 is the same as @samp{autom4te --language M4sugar m4sugar/m4sh.m4f
9301 autom4te --prepend-include /usr/local/share/autoconf \
9302 m4sugar/m4sugar.m4f m4sugar/m4sh.m4f --mode 777 foo.m4
9306 The definition of the languages is stored in @file{autom4te.cfg}.
9308 @node Customizing autom4te
9309 @subsection Customizing @command{autom4te}
9311 One can customize @command{autom4te} via @file{~/.autom4te.cfg} (i.e.,
9312 as found in the user home directory), and @file{./.autom4te.cfg} (i.e.,
9313 as found in the directory from which @command{autom4te} is run). The
9314 order is first reading @file{autom4te.cfg}, then @file{~/.autom4te.cfg},
9315 then @file{./.autom4te.cfg}, and finally the command line arguments.
9317 In these text files, comments are introduced with @code{#}, and empty
9318 lines are ignored. Customization is performed on a per-language basis,
9319 wrapped in between a @samp{begin-language: "@var{language}"},
9320 @samp{end-language: "@var{language}"} pair.
9322 Customizing a language stands for appending options (@pxref{autom4te
9323 Invocation}) to the current definition of the language. Options, and
9324 more generally arguments, are introduced by @samp{args:
9325 @var{arguments}}. You may use the traditional shell syntax to quote the
9328 As an example, to disable Autoconf caches (@file{autom4te.cache})
9329 globally, include the following lines in @file{~/.autom4te.cfg}:
9332 ## ------------------ ##
9333 ## User Preferences. ##
9334 ## ------------------ ##
9336 begin-language: "Autoconf-without-aclocal-m4"
9338 end-language: "Autoconf-without-aclocal-m4"
9342 @node Programming in M4sugar
9343 @section Programming in M4sugar
9346 M4 by itself provides only a small, but sufficient, set of all-purpose
9347 macros. M4sugar introduces additional generic macros. Its name was
9348 coined by Lars J. Aas: ``Readability And Greater Understanding Stands 4
9352 * Redefined M4 Macros:: M4 builtins changed in M4sugar
9353 * Looping constructs:: Iteration in M4
9354 * Evaluation Macros:: More quotation and evaluation control
9355 * Text processing Macros:: String manipulation in M4
9356 * Forbidden Patterns:: Catching unexpanded macros
9359 @node Redefined M4 Macros
9360 @subsection Redefined M4 Macros
9383 With a few exceptions, all the M4 native macros are moved in the
9384 @samp{m4_} pseudo-namespace, e.g., M4sugar renames @code{define} as
9385 @code{m4_define} etc.
9387 Some M4 macros are redefined, and are slightly incompatible with their
9392 This macro kept its original name: no @code{m4_dnl} is defined.
9395 @defmac m4_defn (@var{macro})
9397 Contrary to the M4 builtin, this macro fails if @var{macro} is not
9398 defined. See @code{m4_undefine}.
9401 @defmac m4_exit (@var{exit-status})
9403 This macro corresponds to @code{m4exit}.
9406 @defmac m4_if (@var{comment})
9407 @defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal}, @ovar{not-equal})
9408 @defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal}, @dots{})
9410 This macro corresponds to @code{ifelse}.
9413 @defmac m4_include (@var{file})
9414 @defmacx m4_sinclude (@var{file})
9417 Like the M4 builtins, but warn against multiple inclusions of @var{file}.
9420 @defmac m4_bpatsubst (@var{string}, @var{regexp}, @ovar{replacement})
9422 This macro corresponds to @code{patsubst}. The name @code{m4_patsubst}
9423 is kept for future versions of M4sh, on top of @acronym{GNU} M4 which will
9424 provide extended regular expression syntax via @code{epatsubst}.
9427 @defmac m4_popdef (@var{macro})
9429 Contrary to the M4 builtin, this macro fails if @var{macro} is not
9430 defined. See @code{m4_undefine}.
9433 @defmac m4_bregexp (@var{string}, @var{regexp}, @ovar{replacement})
9435 This macro corresponds to @code{regexp}. The name @code{m4_regexp}
9436 is kept for future versions of M4sh, on top of @acronym{GNU} M4 which will
9437 provide extended regular expression syntax via @code{eregexp}.
9440 @defmac m4_wrap (@var{text})
9442 This macro corresponds to @code{m4wrap}.
9444 You are encouraged to end @var{text} with @samp{[]}, so that there are
9445 no risks that two consecutive invocations of @code{m4_wrap} result in an
9446 unexpected pasting of tokens, as in
9449 m4_define([foo], [Foo])
9450 m4_define([bar], [Bar])
9451 m4_define([foobar], [FOOBAR])
9458 @defmac m4_undefine (@var{macro})
9460 Contrary to the M4 builtin, this macro fails if @var{macro} is not
9464 m4_ifdef([@var{macro}], [m4_undefine([@var{macro}])])
9468 to recover the behavior of the builtin.
9473 @node Looping constructs
9474 @subsection Looping constructs
9476 The following macros implement loops in M4.
9478 @defmac m4_for (@var{var}, @var{first}, @var{last}, @ovar{step}, @var{expression})
9480 Loop over the numeric values between @var{first} and @var{last}
9481 including bounds by increments of @var{step}. For each iteration,
9482 expand @var{expression} with the numeric value assigned to @var{var}.
9483 If @var{step} is omitted, it defaults to @samp{1} or @samp{-1} depending
9484 on the order of the limits. If given, @var{step} has to match this
9488 @defmac m4_foreach (@var{var}, @var{list}, @var{expression})
9490 Loop over the comma-separated m4 list @var{list}, assigning each value
9491 to @var{var}, and expand @var{expression}. The following example will
9495 m4_foreach([myvar], [[foo], [bar, baz]],
9502 @defmac m4_foreach_w (@var{var}, @var{list}, @var{expression})
9504 Loop over the whitespace-separated list @var{list}, assigning each value
9505 to @var{var}, and expand @var{expression}.
9507 The deprecated macro @code{AC_FOREACH} is an alias of
9508 @code{m4_foreach_w}.
9513 @node Evaluation Macros
9514 @subsection Evaluation Macros
9516 The following macros give some control over the order of the evaluation
9517 by adding or removing levels of quotes. They are meant for hard-core M4
9520 @defmac m4_dquote (@var{arg1}, @dots{})
9522 Return the arguments as a quoted list of quoted arguments.
9525 @defmac m4_quote (@var{arg1}, @dots{})
9527 Return the arguments as a single entity, i.e., wrap them into a pair of
9531 The following example aims at emphasizing the difference between (i), not
9532 using these macros, (ii), using @code{m4_quote}, and (iii), using
9536 $ @kbd{cat example.m4}
9537 # Overquote, so that quotes are visible.
9538 m4_define([show], [$[]1 = [$1], $[]@@ = [$@@]])
9541 show(m4_quote(a, b))
9542 show(m4_dquote(a, b))
9543 $ @kbd{autom4te -l m4sugar example.m4}
9544 $1 = a, $@@ = [a],[b]
9545 $1 = a,b, $@@ = [a,b]
9546 $1 = [a],[b], $@@ = [[a],[b]]
9551 @node Text processing Macros
9552 @subsection Text processing Macros
9554 The following macros may be used to manipulate strings in M4.
9555 They are not intended for casual use.
9557 @defmac m4_re_escape (@var{string})
9559 Backslash-escape all characters in @var{string} that are active in
9563 @defmac m4_tolower (@var{string})
9564 @defmacx m4_toupper (@var{string})
9567 Return @var{string} with letters converted to upper or lower case,
9571 @defmac m4_split (@var{string}, @ovar{regexp})
9573 Split @var{string} into an M4 list of elements quoted by @samp{[} and
9574 @samp{]}, while keeping white space at the beginning and at the end.
9575 If @var{regexp} is given, use it instead of @samp{[\t ]+} for splitting.
9576 If @var{string} is empty, the result is an empty list.
9579 @defmac m4_normalize (@var{string})
9581 Remove leading and trailing spaces and tabs, sequences of
9582 backslash-then-newline, and replace multiple spaces and tabs with a
9586 @defmac m4_append (@var{macro-name}, @var{string}, @ovar{separator})
9587 @defmacx m4_append_uniq (@var{macro-name}, @var{string}, @ovar{separator})
9589 @msindex{append_uniq}
9590 Redefine @var{macro-name} to its former contents with @var{separator}
9591 and @var{string} added at the end. If @var{macro-name} was undefined
9592 before (but not if it was defined but empty), then no @var{separator} is
9593 added. @code{m4_append} can be used to grow strings, and
9594 @code{m4_append_uniq} to grow strings without duplicating substrings.
9599 @node Forbidden Patterns
9600 @subsection Forbidden Patterns
9601 @cindex Forbidden patterns
9602 @cindex Patterns, forbidden
9604 M4sugar provides a means to define suspicious patterns, patterns
9605 describing tokens which should not be found in the output. For
9606 instance, if an Autoconf @file{configure} script includes tokens such as
9607 @samp{AC_DEFINE}, or @samp{dnl}, then most probably something went
9608 wrong (typically a macro was not evaluated because of overquotation).
9610 M4sugar forbids all the tokens matching @samp{^m4_} and @samp{^dnl$}.
9612 @defmac m4_pattern_forbid (@var{pattern})
9613 @msindex{pattern_forbid}
9614 Declare that no token matching @var{pattern} must be found in the output.
9615 Comments are not checked; this can be a problem if, for instance, you
9616 have some macro left unexpanded after an @samp{#include}. No consensus
9617 is currently found in the Autoconf community, as some people consider it
9618 should be valid to name macros in comments (which doesn't make sense to
9619 the author of this documentation, as @samp{#}-comments should document
9620 the output, not the input, documented by @samp{dnl} comments).
9623 Of course, you might encounter exceptions to these generic rules, for
9624 instance you might have to refer to @samp{$m4_flags}.
9626 @defmac m4_pattern_allow (@var{pattern})
9627 @msindex{pattern_allow}
9628 Any token matching @var{pattern} is allowed, including if it matches an
9629 @code{m4_pattern_forbid} pattern.
9632 @node Programming in M4sh
9633 @section Programming in M4sh
9635 @c FIXME: Eventually will become a chapter, as it is not related to
9636 @c programming in M4 per se.
9638 M4sh, pronounced ``mash'', is aiming at producing portable Bourne shell
9639 scripts. This name was coined by Lars J. Aas, who notes that,
9640 according to the Webster's Revised Unabridged Dictionary (1913):
9643 Mash \Mash\, n. [Akin to G. meisch, maisch, meische, maische, mash,
9644 wash, and prob.@: to AS. miscian to mix. See ``Mix''.]
9648 A mass of mixed ingredients reduced to a soft pulpy state by beating or
9652 A mixture of meal or bran and water fed to animals.
9655 A mess; trouble. [Obs.] --Beau.@: & Fl.
9660 For the time being, it is not mature enough to be widely used.
9662 M4sh provides portable alternatives for some common shell constructs
9663 that unfortunately are not portable in practice.
9665 @c Deprecated, to be replaced by a better API
9667 @defmac AS_BASENAME (@var{file-name})
9669 Output the non-directory portion of @var{file-name}. For example,
9670 if @code{$file} is @samp{/one/two/three}, the command
9671 @code{base=`AS_BASENAME(["$file"])`} sets @code{base} to @samp{three}.
9675 @defmac AS_BOURNE_COMPATIBLE
9676 @asindex{BOURNE_COMPATIBLE}
9677 Set up the shell to be more compatible with the Bourne shell as
9678 standardized by Posix, if possible. This may involve setting
9679 environment variables, or setting options, or similar
9680 implementation-specific actions.
9683 @defmac AS_CASE (@var{word}, @ovar{pattern1}, @ovar{if-matched1}, @dots{}, @ovar{default})
9685 Expand into a shell @samp{case} statement, where @var{word} is matched
9686 against one or more patterns. @var{if-matched} is run if the
9687 corresponding pattern matched @var{word}, else @var{default} is run.
9690 @defmac AS_DIRNAME (@var{file-name})
9692 Output the directory portion of @var{file-name}. For example,
9693 if @code{$file} is @samp{/one/two/three}, the command
9694 @code{dir=`AS_DIRNAME(["$file"])`} sets @code{dir} to @samp{/one/two}.
9697 @defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false})
9699 Run shell code @var{test1}. If @var{test1} exits with a zero status then
9700 run shell code @var{run-if-true1}, else examine further tests. If no test
9701 exits with a zero status, run shell code @var{run-if-false}, with
9702 simplifications if either @var{run-if-true1} or @var{run-if-false1}
9703 is empty. For example,
9706 AS_IF([test "$foo" = yes], [HANDLE_FOO([yes])],
9707 [test "$foo" != no], [HANDLE_FOO([maybe])],
9708 [echo foo not specified])
9712 will make sure any @code{AC_REQUIRE}'s macros of @code{HANDLE_FOO} will
9713 be expanded before the first test.
9716 @defmac AS_MKDIR_P (@var{file-name})
9718 Make the directory @var{file-name}, including intervening directories
9719 as necessary. This is equivalent to @samp{mkdir -p @var{file-name}},
9720 except that it is portable to older versions of @command{mkdir} that
9721 lack support for the @option{-p} option. Also, @code{AS_MKDIR_P}
9722 succeeds if @var{file-name} is a symbolic link to an existing directory,
9723 even though Posix is unclear whether @samp{mkdir -p} should
9724 succeed in that case. If creation of @var{file-name} fails, exit the
9728 @defmac AS_SHELL_SANITIZE
9729 @asindex{SHELL_SANITIZE}
9730 Initialize the shell suitably for @code{configure} scripts. This has
9731 the effect of @code{AS_BOURNE_COMPATIBLE}, and sets some other
9732 environment variables for predictable results from configuration tests.
9733 For example, it sets @env{LC_ALL} to change to the default C locale.
9734 @xref{Special Shell Variables}.
9737 @defmac AS_TR_CPP (@var{expression})
9739 Transform @var{expression} into a valid right-hand side for a C @code{#define}.
9744 $ echo "#define AS_TR_CPP([HAVE_$type]) 1"
9745 #define HAVE_CHAR_P 1
9749 @defmac AS_TR_SH (@var{expression})
9751 Transform @var{expression} into a valid shell variable name. For example:
9754 $ header="sys/some file.h"
9755 $ AS_TR_SH([HAVE_$header])=yes
9756 $ if test "$HAVE_sys_some_file_h" = yes; then echo "Have it!"; fi
9761 @defmac AS_SET_CATFILE (@var{var}, @var{dir}, @var{file})
9762 @asindex{SET_CATFILE}
9763 Set the shell variable @var{var} to @var{dir}/@var{file}, but
9764 optimizing the common cases (@var{dir} or @var{file} is @samp{.},
9765 @var{file} is absolute, etc.).
9769 @node File Descriptor Macros
9770 @section File Descriptor Macros
9772 @cindex standard input
9773 @cindex file descriptors
9775 @cindex low-level output
9776 @cindex output, low-level
9778 The following macros define file descriptors used to output messages
9779 (or input values) from @file{configure} scripts.
9783 echo "$wombats found" >&AS_MESSAGE_LOG_FD
9784 echo 'Enter desired kangaroo count:' >&AS_MESSAGE_FD
9785 read kangaroos <&AS_ORIGINAL_STDIN_FD`
9789 However doing so is seldom needed, because Autoconf provides higher
9790 level macros as described below.
9792 @defmac AS_MESSAGE_FD
9793 @asindex{MESSAGE_FD}
9794 The file descriptor for @samp{checking for...} messages and results.
9795 Normally this directs messages to the standard output, however when
9796 @command{configure} is run with the @code{-q} option, messages sent to
9797 @code{AS_MESSAGE_FD} will be discarded.
9799 If you want to display some messages, consider using one of the printing
9800 macros (@pxref{Printing Messages}) instead. Copies of messages output
9801 via these macros will additionally be recorded in @file{config.log}.
9804 @defmac AS_MESSAGE_LOG_FD
9805 @asindex{MESSAGE_LOG_FD}
9807 The file descriptor for messages logged to @file{config.log}. Macros
9808 that run tools, like @code{AC_COMPILE_IFELSE} (@pxref{Running the
9809 Compiler}), redirect all output to this descriptor. You may want to do
9810 so if you develop such a low-level macro.
9813 @defmac AS_ORIGINAL_STDIN_FD
9814 @asindex{ORIGINAL_STDIN_FD}
9815 The file descriptor for the original standard input.
9817 When @command{configure} runs, it may accidentally execute an
9818 interactive command that has the same name as the non-interactive meant
9819 to be used or checked. If the standard input was the terminal, such
9820 interactive programs would cause @command{configure} to stop, pending
9821 some user input. Therefore @command{configure} redirects its standard
9822 input from @file{/dev/null} during its initialization. This is not
9823 normally a problem, since @command{configure} normally does not need
9826 In the extreme case where your @file{configure} script really needs to
9827 obtain some values from the original standard input, you can read them
9828 explicitly from @code{AS_ORIGINAL_STDIN_FD}.
9832 @c =================================================== Writing Autoconf Macros.
9834 @node Writing Autoconf Macros
9835 @chapter Writing Autoconf Macros
9837 When you write a feature test that could be applicable to more than one
9838 software package, the best thing to do is encapsulate it in a new macro.
9839 Here are some instructions and guidelines for writing Autoconf macros.
9842 * Macro Definitions:: Basic format of an Autoconf macro
9843 * Macro Names:: What to call your new macros
9844 * Reporting Messages:: Notifying @command{autoconf} users
9845 * Dependencies Between Macros:: What to do when macros depend on other macros
9846 * Obsoleting Macros:: Warning about old ways of doing things
9847 * Coding Style:: Writing Autoconf macros @`a la Autoconf
9850 @node Macro Definitions
9851 @section Macro Definitions
9854 Autoconf macros are defined using the @code{AC_DEFUN} macro, which is
9855 similar to the M4 builtin @code{m4_define} macro. In addition to
9856 defining a macro, @code{AC_DEFUN} adds to it some code that is used to
9857 constrain the order in which macros are called (@pxref{Prerequisite
9860 An Autoconf macro definition looks like this:
9863 AC_DEFUN(@var{macro-name}, @var{macro-body})
9866 You can refer to any arguments passed to the macro as @samp{$1},
9867 @samp{$2}, etc. @xref{Definitions, , How to define new macros, m4.info,
9868 @acronym{GNU} m4}, for more complete information on writing M4 macros.
9870 Be sure to properly quote both the @var{macro-body} @emph{and} the
9871 @var{macro-name} to avoid any problems if the macro happens to have
9872 been previously defined.
9874 Each macro should have a header comment that gives its prototype, and a
9875 brief description. When arguments have default values, display them in
9876 the prototype. For example:
9879 # AC_MSG_ERROR(ERROR, [EXIT-STATUS = 1])
9880 # --------------------------------------
9881 m4_define([AC_MSG_ERROR],
9882 [@{ AS_MESSAGE([error: $1], [2])
9883 exit m4_default([$2], [1]); @}])
9886 Comments about the macro should be left in the header comment. Most
9887 other comments will make their way into @file{configure}, so just keep
9888 using @samp{#} to introduce comments.
9891 If you have some very special comments about pure M4 code, comments
9892 that make no sense in @file{configure} and in the header comment, then
9893 use the builtin @code{dnl}: it causes M4 to discard the text
9894 through the next newline.
9896 Keep in mind that @code{dnl} is rarely needed to introduce comments;
9897 @code{dnl} is more useful to get rid of the newlines following macros
9898 that produce no output, such as @code{AC_REQUIRE}.
9902 @section Macro Names
9904 All of the Autoconf macros have all-uppercase names starting with
9905 @samp{AC_} to prevent them from accidentally conflicting with other
9906 text. All shell variables that they use for internal purposes have
9907 mostly-lowercase names starting with @samp{ac_}. To ensure that your
9908 macros don't conflict with present or future Autoconf macros, you should
9909 prefix your own macro names and any shell variables they use with some
9910 other sequence. Possibilities include your initials, or an abbreviation
9911 for the name of your organization or software package.
9913 Most of the Autoconf macros' names follow a structured naming convention
9914 that indicates the kind of feature check by the name. The macro names
9915 consist of several words, separated by underscores, going from most
9916 general to most specific. The names of their cache variables use the
9917 same convention (@pxref{Cache Variable Names}, for more information on
9920 The first word of the name after @samp{AC_} usually tells the category
9921 of the feature being tested. Here are the categories used in Autoconf for
9922 specific test macros, the kind of macro that you are more likely to
9923 write. They are also used for cache variables, in all-lowercase. Use
9924 them where applicable; where they're not, invent your own categories.
9928 C language builtin features.
9930 Declarations of C variables in header files.
9932 Functions in libraries.
9934 Posix group owners of files.
9940 Absolute names of files, including programs.
9942 The base names of programs.
9944 Members of aggregates.
9946 Operating system features.
9948 C builtin or declared types.
9950 C variables in libraries.
9953 After the category comes the name of the particular feature being
9954 tested. Any further words in the macro name indicate particular aspects
9955 of the feature. For example, @code{AC_FUNC_UTIME_NULL} checks the
9956 behavior of the @code{utime} function when called with a @code{NULL}
9959 An internal macro should have a name that starts with an underscore;
9960 Autoconf internals should therefore start with @samp{_AC_}.
9961 Additionally, a macro that is an internal subroutine of another macro
9962 should have a name that starts with an underscore and the name of that
9963 other macro, followed by one or more words saying what the internal
9964 macro does. For example, @code{AC_PATH_X} has internal macros
9965 @code{_AC_PATH_X_XMKMF} and @code{_AC_PATH_X_DIRECT}.
9967 @node Reporting Messages
9968 @section Reporting Messages
9969 @cindex Messages, from @command{autoconf}
9971 When macros statically diagnose abnormal situations, benign or fatal,
9972 they should report them using these macros. For dynamic issues, i.e.,
9973 when @command{configure} is run, see @ref{Printing Messages}.
9975 @defmac AC_DIAGNOSE (@var{category}, @var{message})
9977 Report @var{message} as a warning (or as an error if requested by the
9978 user) if warnings of the @var{category} are turned on. You are
9979 encouraged to use standard categories, which currently include:
9983 messages that don't fall into one of the following categories. Use of an
9984 empty @var{category} is equivalent.
9987 related to cross compilation issues.
9990 use of an obsolete construct.
9993 dubious syntactic constructs, incorrectly ordered macro calls.
9997 @defmac AC_WARNING (@var{message})
9999 Equivalent to @samp{AC_DIAGNOSE([syntax], @var{message})}, but you are
10000 strongly encouraged to use a finer grained category.
10003 @defmac AC_FATAL (@var{message})
10005 Report a severe error @var{message}, and have @command{autoconf} die.
10008 When the user runs @samp{autoconf -W error}, warnings from
10009 @code{AC_DIAGNOSE} and @code{AC_WARNING} are reported as error, see
10010 @ref{autoconf Invocation}.
10012 @node Dependencies Between Macros
10013 @section Dependencies Between Macros
10014 @cindex Dependencies between macros
10016 Some Autoconf macros depend on other macros having been called first in
10017 order to work correctly. Autoconf provides a way to ensure that certain
10018 macros are called if needed and a way to warn the user if macros are
10019 called in an order that might cause incorrect operation.
10022 * Prerequisite Macros:: Ensuring required information
10023 * Suggested Ordering:: Warning about possible ordering problems
10024 * One-Shot Macros:: Ensuring a macro is called only once
10027 @node Prerequisite Macros
10028 @subsection Prerequisite Macros
10029 @cindex Prerequisite macros
10030 @cindex Macros, prerequisites
10032 A macro that you write might need to use values that have previously
10033 been computed by other macros. For example, @code{AC_DECL_YYTEXT}
10034 examines the output of @code{flex} or @code{lex}, so it depends on
10035 @code{AC_PROG_LEX} having been called first to set the shell variable
10038 Rather than forcing the user of the macros to keep track of the
10039 dependencies between them, you can use the @code{AC_REQUIRE} macro to do
10040 it automatically. @code{AC_REQUIRE} can ensure that a macro is only
10041 called if it is needed, and only called once.
10043 @defmac AC_REQUIRE (@var{macro-name})
10045 If the M4 macro @var{macro-name} has not already been called, call it
10046 (without any arguments). Make sure to quote @var{macro-name} with
10047 square brackets. @var{macro-name} must have been defined using
10048 @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
10049 that it has been called.
10051 @code{AC_REQUIRE} must be used inside an @code{AC_DEFUN}'d macro; it
10052 must not be called from the top level.
10055 @code{AC_REQUIRE} is often misunderstood. It really implements
10056 dependencies between macros in the sense that if one macro depends upon
10057 another, the latter will be expanded @emph{before} the body of the
10058 former. To be more precise, the required macro will be expanded before
10059 the outermost @code{AC_DEFUN}'d macro in the current expansion stack.
10060 In particular, @samp{AC_REQUIRE([FOO])} is not replaced with the body of
10061 @code{FOO}. For instance, this definition of macros:
10065 AC_DEFUN([TRAVOLTA],
10066 [test "$body_temperature_in_celsius" -gt "38" &&
10067 dance_floor=occupied])
10068 AC_DEFUN([NEWTON_JOHN],
10069 [test "$hair_style" = "curly" &&
10070 dance_floor=occupied])
10074 AC_DEFUN([RESERVE_DANCE_FLOOR],
10075 [if date | grep '^Sat.*pm' >/dev/null 2>&1; then
10076 AC_REQUIRE([TRAVOLTA])
10077 AC_REQUIRE([NEWTON_JOHN])
10083 with this @file{configure.ac}
10086 AC_INIT([Dance Manager], [1.0], [bug-dance@@example.org])
10087 RESERVE_DANCE_FLOOR
10088 if test "$dance_floor" = occupied; then
10089 AC_MSG_ERROR([cannot pick up here, let's move])
10094 will not leave you with a better chance to meet a kindred soul at
10095 other times than Saturday night since it expands into:
10099 test "$body_temperature_in_Celsius" -gt "38" &&
10100 dance_floor=occupied
10101 test "$hair_style" = "curly" &&
10102 dance_floor=occupied
10104 if date | grep '^Sat.*pm' >/dev/null 2>&1; then
10111 This behavior was chosen on purpose: (i) it prevents messages in
10112 required macros from interrupting the messages in the requiring macros;
10113 (ii) it avoids bad surprises when shell conditionals are used, as in:
10118 AC_REQUIRE([SOME_CHECK])
10125 The helper macros @code{AS_IF} and @code{AS_CASE} may be used to
10126 enforce expansion of required macros outside of shell conditional
10127 constructs. You are furthermore encouraged to put all @code{AC_REQUIRE}s
10128 at the beginning of a macro. You can use @code{dnl} to avoid the empty
10131 @node Suggested Ordering
10132 @subsection Suggested Ordering
10133 @cindex Macros, ordering
10134 @cindex Ordering macros
10136 Some macros should be run before another macro if both are called, but
10137 neither @emph{requires} that the other be called. For example, a macro
10138 that changes the behavior of the C compiler should be called before any
10139 macros that run the C compiler. Many of these dependencies are noted in
10142 Autoconf provides the @code{AC_BEFORE} macro to warn users when macros
10143 with this kind of dependency appear out of order in a
10144 @file{configure.ac} file. The warning occurs when creating
10145 @command{configure} from @file{configure.ac}, not when running
10146 @command{configure}.
10148 For example, @code{AC_PROG_CPP} checks whether the C compiler
10149 can run the C preprocessor when given the @option{-E} option. It should
10150 therefore be called after any macros that change which C compiler is
10151 being used, such as @code{AC_PROG_CC}. So @code{AC_PROG_CC} contains:
10154 AC_BEFORE([$0], [AC_PROG_CPP])dnl
10158 This warns the user if a call to @code{AC_PROG_CPP} has already occurred
10159 when @code{AC_PROG_CC} is called.
10161 @defmac AC_BEFORE (@var{this-macro-name}, @var{called-macro-name})
10163 Make M4 print a warning message to the standard error output if
10164 @var{called-macro-name} has already been called. @var{this-macro-name}
10165 should be the name of the macro that is calling @code{AC_BEFORE}. The
10166 macro @var{called-macro-name} must have been defined using
10167 @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
10168 that it has been called.
10171 @node One-Shot Macros
10172 @subsection One-Shot Macros
10173 @cindex One-shot macros
10174 @cindex Macros, called once
10176 Some macros should be called only once, either because calling them
10177 multiple time is unsafe, or because it is bad style. For instance
10178 Autoconf ensures that @code{AC_CANONICAL_BUILD} and cousins
10179 (@pxref{Canonicalizing}) are evaluated only once, because it makes no
10180 sense to run these expensive checks more than once. Such one-shot
10181 macros can be defined using @code{AC_DEFUN_ONCE}.
10183 @defmac AC_DEFUN_ONCE (@var{macro-name}, @var{macro-body})
10184 @acindex{DEFUN_ONCE}
10186 Declare macro @var{macro-name} like @code{AC_DEFUN} would (@pxref{Macro
10187 Definitions}), and emit a warning any time the macro is called more than
10191 Obviously it is not sensible to evaluate a macro defined by
10192 @code{AC_DEFUN_ONCE} in a macro defined by @code{AC_DEFUN}, most of the
10193 times you will want to use @code{AC_REQUIRE} (@pxref{Prerequisite
10196 @node Obsoleting Macros
10197 @section Obsoleting Macros
10198 @cindex Obsoleting macros
10199 @cindex Macros, obsoleting
10201 Configuration and portability technology has evolved over the years.
10202 Often better ways of solving a particular problem are developed, or
10203 ad-hoc approaches are systematized. This process has occurred in many
10204 parts of Autoconf. One result is that some of the macros are now
10205 considered @dfn{obsolete}; they still work, but are no longer considered
10206 the best thing to do, hence they should be replaced with more modern
10207 macros. Ideally, @command{autoupdate} should replace the old macro calls
10208 with their modern implementation.
10210 Autoconf provides a simple means to obsolete a macro.
10212 @defmac AU_DEFUN (@var{old-macro}, @var{implementation}, @ovar{message})
10214 Define @var{old-macro} as @var{implementation}. The only difference
10215 with @code{AC_DEFUN} is that the user will be warned that
10216 @var{old-macro} is now obsolete.
10218 If she then uses @command{autoupdate}, the call to @var{old-macro} will be
10219 replaced by the modern @var{implementation}. @var{message} should
10220 include information on what to do after running @command{autoupdate};
10221 @command{autoupdate} will print it as a warning, and include it
10222 in the updated @file{configure.ac} file.
10224 The details of this macro are hairy: if @command{autoconf} encounters an
10225 @code{AU_DEFUN}ed macro, all macros inside its second argument are expanded
10226 as usual. However, when @command{autoupdate} is run, only M4 and M4sugar
10227 macros will be expanded here, while all other macros are disabled and will
10228 appear literally in the updated @file{configure.ac}.
10231 @defmac AU_ALIAS (@var{old-name}, @var{new-name})
10233 Used if the @var{old-name} is to be replaced by a call to @var{new-macro}
10234 with the same parameters. This happens for example if the macro was renamed.
10238 @section Coding Style
10239 @cindex Coding style
10241 The Autoconf macros follow a strict coding style. You are encouraged to
10242 follow this style, especially if you intend to distribute your macro,
10243 either by contributing it to Autoconf itself, or via other means.
10245 The first requirement is to pay great attention to the quotation. For
10246 more details, see @ref{Autoconf Language}, and @ref{M4 Quotation}.
10248 Do not try to invent new interfaces. It is likely that there is a macro
10249 in Autoconf that resembles the macro you are defining: try to stick to
10250 this existing interface (order of arguments, default values, etc.). We
10251 @emph{are} conscious that some of these interfaces are not perfect;
10252 nevertheless, when harmless, homogeneity should be preferred over
10255 Be careful about clashes both between M4 symbols and between shell
10258 If you stick to the suggested M4 naming scheme (@pxref{Macro Names}),
10259 you are unlikely to generate conflicts. Nevertheless, when you need to
10260 set a special value, @emph{avoid using a regular macro name}; rather,
10261 use an ``impossible'' name. For instance, up to version 2.13, the macro
10262 @code{AC_SUBST} used to remember what @var{symbol}s were already defined
10263 by setting @code{AC_SUBST_@var{symbol}}, which is a regular macro name.
10264 But since there is a macro named @code{AC_SUBST_FILE}, it was just
10265 impossible to @samp{AC_SUBST(FILE)}! In this case,
10266 @code{AC_SUBST(@var{symbol})} or @code{_AC_SUBST(@var{symbol})} should
10267 have been used (yes, with the parentheses).
10268 @c or better yet, high-level macros such as @code{m4_expand_once}
10270 No Autoconf macro should ever enter the user-variable name space; i.e.,
10271 except for the variables that are the actual result of running the
10272 macro, all shell variables should start with @code{ac_}. In
10273 addition, small macros or any macro that is likely to be embedded in
10274 other macros should be careful not to use obvious names.
10277 Do not use @code{dnl} to introduce comments: most of the comments you
10278 are likely to write are either header comments which are not output
10279 anyway, or comments that should make their way into @file{configure}.
10280 There are exceptional cases where you do want to comment special M4
10281 constructs, in which case @code{dnl} is right, but keep in mind that it
10284 M4 ignores the leading blanks and newlines before each argument.
10285 Use this feature to
10286 indent in such a way that arguments are (more or less) aligned with the
10287 opening parenthesis of the macro being called. For instance, instead of
10290 AC_CACHE_CHECK(for EMX OS/2 environment,
10292 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __EMX__;])],
10293 [ac_cv_emxos2=yes], [ac_cv_emxos2=no])])
10300 AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
10301 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
10302 [ac_cv_emxos2=yes],
10303 [ac_cv_emxos2=no])])
10310 AC_CACHE_CHECK([for EMX OS/2 environment],
10312 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
10313 [return __EMX__;])],
10314 [ac_cv_emxos2=yes],
10315 [ac_cv_emxos2=no])])
10318 When using @code{AC_RUN_IFELSE} or any macro that cannot work when
10319 cross-compiling, provide a pessimistic value (typically @samp{no}).
10321 Feel free to use various tricks to prevent auxiliary tools, such as
10322 syntax-highlighting editors, from behaving improperly. For instance,
10326 m4_bpatsubst([$1], [$"])
10333 m4_bpatsubst([$1], [$""])
10337 so that Emacsen do not open an endless ``string'' at the first quote.
10338 For the same reasons, avoid:
10348 test $[@@%:@@] != 0
10352 Otherwise, the closing bracket would be hidden inside a @samp{#}-comment,
10353 breaking the bracket-matching highlighting from Emacsen. Note the
10354 preferred style to escape from M4: @samp{$[1]}, @samp{$[@@]}, etc. Do
10355 not escape when it is unnecessary. Common examples of useless quotation
10356 are @samp{[$]$1} (write @samp{$$1}), @samp{[$]var} (use @samp{$var}),
10357 etc. If you add portability issues to the picture, you'll prefer
10358 @samp{$@{1+"$[@@]"@}} to @samp{"[$]@@"}, and you'll prefer do something
10359 better than hacking Autoconf @code{:-)}.
10361 When using @command{sed}, don't use @option{-e} except for indenting
10362 purposes. With the @code{s} and @code{y} commands, the preferred
10363 separator is @samp{/} unless @samp{/} itself might appear in the pattern
10364 or replacement, in which case you should use @samp{|}, or optionally
10365 @samp{,} if you know the pattern and replacement cannot contain a file
10366 name. If none of these characters will do, choose a printable character
10367 that cannot appear in the pattern or replacement. Characters from the
10368 set @samp{"#$&'()*;<=>?`|~} are good choices if the pattern or
10369 replacement might contain a file name, since they have special meaning
10370 to the shell and are less likely to occur in file names.
10372 @xref{Macro Definitions}, for details on how to define a macro. If a
10373 macro doesn't use @code{AC_REQUIRE}, is expected to never be the object
10374 of an @code{AC_REQUIRE} directive, and macros required by other macros
10375 inside arguments will not need to be expanded before this macro, then
10376 use @code{m4_define}. In case of doubt, use @code{AC_DEFUN}.
10377 All the @code{AC_REQUIRE} statements should be at the beginning of the
10378 macro, @code{dnl}'ed.
10380 You should not rely on the number of arguments: instead of checking
10381 whether an argument is missing, test that it is not empty. It provides
10382 both a simpler and a more predictable interface to the user, and saves
10383 room for further arguments.
10385 Unless the macro is short, try to leave the closing @samp{])} at the
10386 beginning of a line, followed by a comment that repeats the name of the
10387 macro being defined. This introduces an additional newline in
10388 @command{configure}; normally, that is not a problem, but if you want to
10389 remove it you can use @samp{[]dnl} on the last line. You can similarly
10390 use @samp{[]dnl} after a macro call to remove its newline. @samp{[]dnl}
10391 is recommended instead of @samp{dnl} to ensure that M4 does not
10392 interpret the @samp{dnl} as being attached to the preceding text or
10393 macro output. For example, instead of:
10396 AC_DEFUN([AC_PATH_X],
10397 [AC_MSG_CHECKING([for X])
10399 @r{# @dots{}omitted@dots{}}
10400 AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
10408 AC_DEFUN([AC_PATH_X],
10409 [AC_REQUIRE_CPP()[]dnl
10410 AC_MSG_CHECKING([for X])
10411 @r{# @dots{}omitted@dots{}}
10412 AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
10417 If the macro is long, try to split it into logical chunks. Typically,
10418 macros that check for a bug in a function and prepare its
10419 @code{AC_LIBOBJ} replacement should have an auxiliary macro to perform
10420 this setup. Do not hesitate to introduce auxiliary macros to factor
10423 In order to highlight the recommended coding style, here is a macro
10424 written the old way:
10427 dnl Check for EMX on OS/2.
10429 AC_DEFUN(_AC_EMXOS2,
10430 [AC_CACHE_CHECK(for EMX OS/2 environment, ac_cv_emxos2,
10431 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return __EMX__;)],
10432 ac_cv_emxos2=yes, ac_cv_emxos2=no)])
10433 test "$ac_cv_emxos2" = yes && EMXOS2=yes])
10442 # Check for EMX on OS/2.
10443 m4_define([_AC_EMXOS2],
10444 [AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
10445 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
10446 [ac_cv_emxos2=yes],
10447 [ac_cv_emxos2=no])])
10448 test "$ac_cv_emxos2" = yes && EMXOS2=yes[]dnl
10455 @c ============================================= Portable Shell Programming
10457 @node Portable Shell
10458 @chapter Portable Shell Programming
10459 @cindex Portable shell programming
10461 When writing your own checks, there are some shell-script programming
10462 techniques you should avoid in order to make your code portable. The
10463 Bourne shell and upward-compatible shells like the Korn shell and Bash
10464 have evolved over the years, but to prevent trouble, do not take
10465 advantage of features that were added after Unix version 7, circa
10466 1977 (@pxref{Systemology}).
10468 You should not use shell functions, aliases, negated character
10469 classes, or other features that are not found in all Bourne-compatible
10470 shells; restrict yourself to the lowest common denominator. Even
10471 @code{unset} is not supported by all shells!
10473 Some old systems have quite
10474 small limits on the length of the @samp{#!} line; for instance, 32
10475 bytes (not including the newline) on SunOS 4.
10476 A few ancient 4.2@acronym{BSD} based systems (such as Dynix circa 1984)
10477 required a single space between the @samp{#!} and the @samp{/}, but
10478 these are no longer of practical concern.
10480 The set of external programs you should run in a @command{configure} script
10481 is fairly small. @xref{Utilities in Makefiles, , Utilities in
10482 Makefiles, standards, @acronym{GNU} Coding Standards}, for the list. This
10483 restriction allows users to start out with a fairly small set of
10484 programs and build the rest, avoiding too many interdependencies between
10487 Some of these external utilities have a portable subset of features; see
10488 @ref{Limitations of Usual Tools}.
10490 There are other sources of documentation about shells. The
10491 specification for the Posix
10492 @uref{http://www.opengroup.org/susv3/utilities/xcu_chap02.html, Shell
10493 Command Language}, though more generous than the restrictive shell
10494 subset described above, is fairly portable nowadays. Also please see
10495 @uref{http://www.faqs.org/faqs/unix-faq/shell/, the Shell FAQs}.
10498 * Shellology:: A zoology of shells
10499 * Here-Documents:: Quirks and tricks
10500 * File Descriptors:: FDs and redirections
10501 * File System Conventions:: File names
10502 * Shell Substitutions:: Variable and command expansions
10503 * Assignments:: Varying side effects of assignments
10504 * Parentheses:: Parentheses in shell scripts
10505 * Slashes:: Slashes in shell scripts
10506 * Special Shell Variables:: Variables you should not change
10507 * Limitations of Builtins:: Portable use of not so portable /bin/sh
10508 * Limitations of Usual Tools:: Portable use of portable tools
10509 * Limitations of Make:: Portable Makefiles
10513 @section Shellology
10516 There are several families of shells, most prominently the Bourne family
10517 and the C shell family which are deeply incompatible. If you want to
10518 write portable shell scripts, avoid members of the C shell family. The
10519 @uref{http://www.faqs.org/faqs/unix-faq/shell/shell-differences/, the
10520 Shell difference FAQ} includes a small history of Posix shells, and a
10521 comparison between several of them.
10523 Below we describe some of the members of the Bourne shell family.
10528 Ash is often used on @acronym{GNU}/Linux and @acronym{BSD}
10529 systems as a light-weight Bourne-compatible shell. Ash 0.2 has some
10530 bugs that are fixed in the 0.3.x series, but portable shell scripts
10531 should work around them, since version 0.2 is still shipped with many
10532 @acronym{GNU}/Linux distributions.
10534 To be compatible with Ash 0.2:
10538 don't use @samp{$?} after expanding empty or unset variables,
10539 or at the start of an @command{eval}:
10545 echo "Do not use it: $?"
10547 eval 'echo "Do not use it: $?"'
10551 don't use command substitution within variable expansion:
10558 beware that single builtin substitutions are not performed by a
10559 subshell, hence their effect applies to the current shell! @xref{Shell
10560 Substitutions}, item ``Command Substitution''.
10565 To detect whether you are running Bash, test whether
10566 @code{BASH_VERSION} is set. To require
10567 Posix compatibility, run @samp{set -o posix}. @xref{Bash POSIX
10568 Mode, , Bash Posix Mode, bash, The @acronym{GNU} Bash Reference
10569 Manual}, for details.
10571 @item Bash 2.05 and later
10572 @cindex Bash 2.05 and later
10573 Versions 2.05 and later of Bash use a different format for the
10574 output of the @command{set} builtin, designed to make evaluating its
10575 output easier. However, this output is not compatible with earlier
10576 versions of Bash (or with many other shells, probably). So if
10577 you use Bash 2.05 or higher to execute @command{configure},
10578 you'll need to use Bash 2.05 for all other build tasks as well.
10583 @prindex @samp{ksh}
10584 @prindex @samp{ksh88}
10585 @prindex @samp{ksh93}
10586 The Korn shell is compatible with the Bourne family and it mostly
10587 conforms to Posix. It has two major variants commonly
10588 called @samp{ksh88} and @samp{ksh93}, named after the years of initial
10589 release. It is usually called @command{ksh}, but is called @command{sh}
10590 on some hosts if you set your path appropriately.
10592 Solaris systems have three variants:
10593 @prindex @command{/usr/bin/ksh} on Solaris
10594 @command{/usr/bin/ksh} is @samp{ksh88}; it is
10595 standard on Solaris 2.0 and later.
10596 @prindex @command{/usr/xpg4/bin/sh} on Solaris
10597 @command{/usr/xpg4/bin/sh} is a Posix-compliant variant of
10598 @samp{ksh88}; it is standard on Solaris 9 and later.
10599 @prindex @command{/usr/dt/bin/dtksh} on Solaris
10600 @command{/usr/dt/bin/dtksh} is @samp{ksh93}.
10601 Variants that are not standard may be parts of optional
10602 packages. There is no extra charge for these packages, but they are
10603 not part of a minimal OS install and therefore some installations may
10606 Starting with Tru64 Version 4.0, the Korn shell @command{/usr/bin/ksh}
10607 is also available as @command{/usr/bin/posix/sh}. If the environment
10608 variable @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations of
10609 the standard shell conform to Posix.
10612 @prindex @samp{pdksh}
10613 A public-domain clone of the Korn shell called @command{pdksh} is widely
10614 available: it has most of the @samp{ksh88} features along with a few of
10615 its own. It will usually set @code{KSH_VERSION}, except if invoked as
10616 @command{/bin/sh} on Open@acronym{BSD}, and similarly to Bash you can require
10617 Posix compatibility by running @samp{set -o posix}. Unfortunately, with
10618 @command{pdksh} 5.2.14 (the latest stable version as of February 2006)
10619 Posix mode is buggy and causes @command{pdksh} to depart from Posix in
10620 at least one respect:
10623 $ echo "`echo \"hello\"`"
10626 $ echo "`echo \"hello\"`"
10630 The last line of output contains spurious quotes. This is yet another
10631 reason why portable shell code should not contain
10632 @code{"`@dots{}\"@dots{}\"@dots{}`"} constructs (@pxref{Shell
10637 To detect whether you are running @command{zsh}, test whether
10638 @code{ZSH_VERSION} is set. By default @command{zsh} is @emph{not}
10639 compatible with the Bourne shell: you must execute @samp{emulate sh},
10640 and for @command{zsh} versions before 3.1.6-dev-18 you must also
10641 set @code{NULLCMD} to @samp{:}. @xref{Compatibility, , Compatibility,
10642 zsh, The Z Shell Manual}, for details.
10644 The default Mac OS X @command{sh} was originally Zsh; it was changed to
10645 Bash in Mac OS X 10.2.
10648 The following discussion between Russ Allbery and Robert Lipe is worth
10655 The @acronym{GNU} assumption that @command{/bin/sh} is the one and only shell
10656 leads to a permanent deadlock. Vendors don't want to break users'
10657 existing shell scripts, and there are some corner cases in the Bourne
10658 shell that are not completely compatible with a Posix shell. Thus,
10659 vendors who have taken this route will @emph{never} (OK@dots{}``never say
10660 never'') replace the Bourne shell (as @command{/bin/sh}) with a
10668 This is exactly the problem. While most (at least most System V's) do
10669 have a Bourne shell that accepts shell functions most vendor
10670 @command{/bin/sh} programs are not the Posix shell.
10672 So while most modern systems do have a shell @emph{somewhere} that meets the
10673 Posix standard, the challenge is to find it.
10676 @node Here-Documents
10677 @section Here-Documents
10678 @cindex Here documents
10679 @cindex Shell here documents
10681 Don't rely on @samp{\} being preserved just because it has no special
10682 meaning together with the next symbol. In the native @command{sh}
10683 on Open@acronym{BSD} 2.7 @samp{\"} expands to @samp{"} in here-documents with
10684 unquoted delimiter. As a general rule, if @samp{\\} expands to @samp{\}
10685 use @samp{\\} to get @samp{\}.
10687 With Open@acronym{BSD} 2.7's @command{sh}
10703 bash-2.04$ @kbd{cat <<EOF
10711 Many older shells (including the Bourne shell) implement here-documents
10712 inefficiently. And some shells mishandle large here-documents: for
10713 example, Solaris @command{dtksh}, which is derived from Korn shell
10714 version M-12/28/93d, mishandles variable expansion that occurs on
10715 1024-byte buffer boundaries within a here-document. Users can generally
10716 fix these problems by using a faster or more reliable shell, e.g., by
10717 using the command @samp{CONFIG_SHELL=/bin/bash /bin/bash ./configure} rather
10718 than plain @samp{./configure}.
10720 Some shells can be extremely inefficient when there are a lot of
10721 here-documents inside a single statement. For instance if your
10722 @file{configure.ac} includes something like:
10726 if <cross_compiling>; then
10727 assume this and that
10731 check something else
10739 A shell parses the whole @code{if}/@code{fi} construct, creating
10740 temporary files for each here document in it. Some shells create links
10741 for such here-documents on every @code{fork}, so that the clean-up code
10742 they had installed correctly removes them. It is creating the links
10743 that can take the shell forever.
10745 Moving the tests out of the @code{if}/@code{fi}, or creating multiple
10746 @code{if}/@code{fi} constructs, would improve the performance
10747 significantly. Anyway, this kind of construct is not exactly the
10748 typical use of Autoconf. In fact, it's even not recommended, because M4
10749 macros can't look into shell conditionals, so we may fail to expand a
10750 macro when it was expanded before in a conditional path, and the
10751 condition turned out to be false at runtime, and we end up not
10752 executing the macro at all.
10754 @node File Descriptors
10755 @section File Descriptors
10756 @cindex Descriptors
10757 @cindex File descriptors
10758 @cindex Shell file descriptors
10760 Some file descriptors shall not be used, since some systems, admittedly
10761 arcane, use them for special purpose:
10764 3 --- some systems may open it to @samp{/dev/tty}.
10765 4 --- used on the Kubota Titan.
10768 Don't redirect the same file descriptor several times, as you are doomed
10769 to failure under Ultrix.
10772 ULTRIX V4.4 (Rev. 69) System #31: Thu Aug 10 19:42:23 GMT 1995
10774 $ @kbd{eval 'echo matter >fullness' >void}
10776 $ @kbd{eval '(echo matter >fullness)' >void}
10778 $ @kbd{(eval '(echo matter >fullness)') >void}
10779 Ambiguous output redirect.
10783 In each case the expected result is of course @file{fullness} containing
10784 @samp{matter} and @file{void} being empty.
10786 Don't try to redirect the standard error of a command substitution: it
10787 must be done @emph{inside} the command substitution: when running
10788 @samp{: `cd /zorglub` 2>/dev/null} expect the error message to
10789 escape, while @samp{: `cd /zorglub 2>/dev/null`} works properly.
10791 It is worth noting that Zsh (but not Ash nor Bash) makes it possible
10792 in assignments though: @samp{foo=`cd /zorglub` 2>/dev/null}.
10794 Most shells, if not all (including Bash, Zsh, Ash), output traces on
10795 stderr, even for sub-shells. This might result in undesirable content
10796 if you meant to capture the standard-error output of the inner command:
10799 $ @kbd{ash -x -c '(eval "echo foo >&2") 2>stderr'}
10801 + eval echo foo >&2
10804 $ @kbd{bash -x -c '(eval "echo foo >&2") 2>stderr'}
10806 + eval 'echo foo >&2'
10809 $ @kbd{zsh -x -c '(eval "echo foo >&2") 2>stderr'}
10810 @i{# Traces on startup files deleted here.}
10812 +zsh:1> eval echo foo >&2
10818 You'll appreciate the various levels of detail@enddots{}
10820 One workaround is to grep out uninteresting lines, hoping not to remove
10821 good ones@enddots{}
10823 Don't try to move/delete open files, such as in @samp{exec >foo; mv foo
10824 bar}; see @ref{Limitations of Builtins}, @command{mv} for more details.
10826 Don't rely on open file descriptors being open in child processes. In
10827 @command{ksh}, file descriptors above 2 which are opened using
10828 @samp{exec n>file} are closed by a subsequent @samp{exec} (such as
10829 that involved in the fork-and-exec which runs a program or script).
10830 Thus, using sh, we have:
10849 Within the process which runs the @samp{descrips} script, file
10850 descriptor number 5 is closed.
10852 @node File System Conventions
10853 @section File System Conventions
10854 @cindex File system conventions
10856 Autoconf uses shell-script processing extensively, so the file names
10857 that it processes should not contain characters that are special to the
10858 shell. Special characters include space, tab, newline, @sc{nul}, and
10862 " # $ & ' ( ) * ; < = > ? [ \ ` |
10865 Also, file names should not begin with @samp{~} or @samp{-}, and should
10866 not contain @samp{-} immediately after @samp{/}.
10868 These restrictions apply not only to the files that you distribute, but
10869 also to the absolute file names of your source, build, and destination
10870 directories. Autoconf-generated @command{configure} scripts warn of
10871 violations to the above restrictions.
10873 On some Posix-like platforms, @samp{!} and @samp{^} are special too, so
10874 they should be avoided.
10876 Posix lets implementations treat leading @file{//} specially, but
10877 requires leading @file{///} and beyond to be equivalent to @file{/}.
10878 Most Unix variants treat @file{//} like @file{/}. However, some treat
10879 @file{//} as a ``super-root'' that can provide access to files that are
10880 not otherwise reachable from @file{/}. The super-root tradition began
10881 with Apollo Domain/OS, which died out long ago, but unfortunately Cygwin
10884 While @command{autoconf} and friends will usually be run on some Posix
10885 variety, it can and will be used on other systems, most notably @acronym{DOS}
10886 variants. This impacts several assumptions regarding file names.
10889 For example, the following code:
10896 foo_dir=$dots$foo_dir ;;
10901 will fail to properly detect absolute file names on those systems, because
10902 they can use a drivespec, and will usually use a backslash as directory
10903 separator. If you want to be portable to @acronym{DOS} variants (at the
10904 price of rejecting valid but oddball Posix file names like @file{a:\b}),
10905 you can check for absolute file names like this:
10909 [\\/]* | ?:[\\/]* ) # Absolute
10912 foo_dir=$dots$foo_dir ;;
10917 Make sure you quote the brackets if appropriate and keep the backslash as
10918 first character (@pxref{Limitations of Builtins}).
10920 Also, because the colon is used as part of a drivespec, these systems don't
10921 use it as path separator. When creating or accessing paths, you can use the
10922 @code{PATH_SEPARATOR} output variable instead. @command{configure} sets this
10923 to the appropriate value (@samp{:} or @samp{;}) when it starts up.
10925 File names need extra care as well. While @acronym{DOS} variants
10926 that are Posixy enough to run @command{autoconf} (such as @acronym{DJGPP}) will
10927 usually be able to handle long file names properly, there are still
10928 limitations that can seriously break packages. Several of these issues
10929 can be easily detected by the
10930 @uref{ftp://ftp.gnu.org/gnu/non-gnu/doschk/doschk-1.1.tar.gz, doschk}
10933 A short overview follows; problems are marked with @sc{sfn}/@sc{lfn} to
10934 indicate where they apply: @sc{sfn} means the issues are only relevant to
10935 plain @acronym{DOS}, not to @acronym{DOS} under Microsoft Windows
10936 variants, while @sc{lfn} identifies problems that exist even under
10937 Microsoft Windows variants.
10940 @item No multiple dots (@sc{sfn})
10941 @acronym{DOS} cannot handle multiple dots in file names. This is an especially
10942 important thing to remember when building a portable configure script,
10943 as @command{autoconf} uses a .in suffix for template files.
10945 This is perfectly OK on Posix variants:
10948 AC_CONFIG_HEADERS([config.h])
10949 AC_CONFIG_FILES([source.c foo.bar])
10954 but it causes problems on @acronym{DOS}, as it requires @samp{config.h.in},
10955 @samp{source.c.in} and @samp{foo.bar.in}. To make your package more portable
10956 to @acronym{DOS}-based environments, you should use this instead:
10959 AC_CONFIG_HEADERS([config.h:config.hin])
10960 AC_CONFIG_FILES([source.c:source.cin foo.bar:foobar.in])
10964 @item No leading dot (@sc{sfn})
10965 @acronym{DOS} cannot handle file names that start with a dot. This is usually
10966 not a very important issue for @command{autoconf}.
10968 @item Case insensitivity (@sc{lfn})
10969 @acronym{DOS} is case insensitive, so you cannot, for example, have both a
10970 file called @samp{INSTALL} and a directory called @samp{install}. This
10971 also affects @command{make}; if there's a file called @samp{INSTALL} in
10972 the directory, @samp{make install} will do nothing (unless the
10973 @samp{install} target is marked as PHONY).
10975 @item The 8+3 limit (@sc{sfn})
10976 Because the @acronym{DOS} file system only stores the first 8 characters of
10977 the file name and the first 3 of the extension, those must be unique.
10978 That means that @file{foobar-part1.c}, @file{foobar-part2.c} and
10979 @file{foobar-prettybird.c} all resolve to the same file name
10980 (@file{FOOBAR-P.C}). The same goes for @file{foo.bar} and
10981 @file{foo.bartender}.
10983 The 8+3 limit is not usually a problem under Microsoft Windows, as it
10985 tails in the short version of file names to make them unique. However, a
10986 registry setting can turn this behavior off. While this makes it
10987 possible to share file trees containing long file names between @sc{sfn}
10988 and @sc{lfn} environments, it also means the above problem applies there
10991 @item Invalid characters (@sc{lfn})
10992 Some characters are invalid in @acronym{DOS} file names, and should therefore
10993 be avoided. In a @sc{lfn} environment, these are @samp{/}, @samp{\},
10994 @samp{?}, @samp{*}, @samp{:}, @samp{<}, @samp{>}, @samp{|} and @samp{"}.
10995 In a @sc{sfn} environment, other characters are also invalid. These
10996 include @samp{+}, @samp{,}, @samp{[} and @samp{]}.
10998 @item Invalid names (@sc{lfn})
10999 Some @acronym{DOS} file names are reserved, and cause problems if you
11000 try to use files with those names. These names include @file{CON},
11001 @file{AUX}, @file{COM1}, @file{COM2}, @file{COM3}, @file{COM4},
11002 @file{LPT1}, @file{LPT2}, @file{LPT3}, @file{NUL}, and @file{PRN}.
11003 File names are case insensitive, so even names like
11004 @file{aux/config.guess} are disallowed.
11008 @node Shell Substitutions
11009 @section Shell Substitutions
11010 @cindex Shell substitutions
11012 Contrary to a persistent urban legend, the Bourne shell does not
11013 systematically split variables and back-quoted expressions, in particular
11014 on the right-hand side of assignments and in the argument of @code{case}.
11015 For instance, the following code:
11018 case "$given_srcdir" in
11019 .) top_srcdir="`echo "$dots" | sed 's,/$,,'`" ;;
11020 *) top_srcdir="$dots$given_srcdir" ;;
11025 is more readable when written as:
11028 case $given_srcdir in
11029 .) top_srcdir=`echo "$dots" | sed 's,/$,,'` ;;
11030 *) top_srcdir=$dots$given_srcdir ;;
11035 and in fact it is even @emph{more} portable: in the first case of the
11036 first attempt, the computation of @code{top_srcdir} is not portable,
11037 since not all shells properly understand @code{"`@dots{}"@dots{}"@dots{}`"}.
11038 Worse yet, not all shells understand @code{"`@dots{}\"@dots{}\"@dots{}`"}
11039 the same way. There is just no portable way to use double-quoted
11040 strings inside double-quoted back-quoted expressions (pfew!).
11044 @cindex @samp{"$@@"}
11045 One of the most famous shell-portability issues is related to
11046 @samp{"$@@"}. When there are no positional arguments, Posix says
11047 that @samp{"$@@"} is supposed to be equivalent to nothing, but the
11048 original Unix version 7 Bourne shell treated it as equivalent to
11049 @samp{""} instead, and this behavior survives in later implementations
11050 like Digital Unix 5.0.
11052 The traditional way to work around this portability problem is to use
11053 @samp{$@{1+"$@@"@}}. Unfortunately this method does not work with
11054 Zsh (3.x and 4.x), which is used on Mac OS X@. When emulating
11055 the Bourne shell, Zsh performs word splitting on @samp{$@{1+"$@@"@}}:
11058 zsh $ @kbd{emulate sh}
11059 zsh $ @kbd{for i in "$@@"; do echo $i; done}
11062 zsh $ @kbd{for i in $@{1+"$@@"@}; do echo $i; done}
11069 Zsh handles plain @samp{"$@@"} properly, but we can't use plain
11070 @samp{"$@@"} because of the portability problems mentioned above.
11071 One workaround relies on Zsh's ``global aliases'' to convert
11072 @samp{$@{1+"$@@"@}} into @samp{"$@@"} by itself:
11075 test "$@{ZSH_VERSION+set@}" = set && alias -g '$@{1+"$@@"@}'='"$@@"'
11078 A more conservative workaround is to avoid @samp{"$@@"} if it is
11079 possible that there may be no positional arguments. For example,
11083 cat conftest.c "$@@"
11086 you can use this instead:
11090 0) cat conftest.c;;
11091 *) cat conftest.c "$@@";;
11097 @cindex positional parameters
11098 The 10th, 11th, @dots{} positional parameters can be accessed only after
11099 a @code{shift}. The 7th Edition shell reported an error if given
11100 @code{$@{10@}}, and
11101 Solaris 10 @command{/bin/sh} still acts that way:
11104 $ @kbd{set 1 2 3 4 5 6 7 8 9 10}
11105 $ @kbd{echo $@{10@}}
11109 @item $@{@var{var}:-@var{value}@}
11110 @c Info cannot handle `:' in index entries.
11111 @c @cindex $@{@var{var}:-@var{value}@}
11112 Old @acronym{BSD} shells, including the Ultrix @code{sh}, don't accept the
11113 colon for any shell substitution, and complain and die.
11115 @item $@{@var{var}=@var{literal}@}
11116 @cindex $@{@var{var}=@var{literal}@}
11120 : $@{var='Some words'@}
11124 otherwise some shells, such as on Digital Unix V 5.0, will die because
11125 of a ``bad substitution''.
11129 Solaris @command{/bin/sh} has a frightening bug in its interpretation
11130 of this. Imagine you need set a variable to a string containing
11131 @samp{@}}. This @samp{@}} character confuses Solaris @command{/bin/sh}
11132 when the affected variable was already set. This bug can be exercised
11137 $ @kbd{foo=$@{foo='@}'@}}
11140 $ @kbd{foo=$@{foo='@}' # no error; this hints to what the bug is}
11143 $ @kbd{foo=$@{foo='@}'@}}
11149 It seems that @samp{@}} is interpreted as matching @samp{$@{}, even
11150 though it is enclosed in single quotes. The problem doesn't happen
11151 using double quotes.
11153 @item $@{@var{var}=@var{expanded-value}@}
11154 @cindex $@{@var{var}=@var{expanded-value}@}
11160 : $@{var="$default"@}
11164 will set @var{var} to @samp{M-yM-uM-,M-yM-aM-a}, i.e., the 8th bit of
11165 each char will be set. You won't observe the phenomenon using a simple
11166 @samp{echo $var} since apparently the shell resets the 8th bit when it
11167 expands $var. Here are two means to make this shell confess its sins:
11170 $ @kbd{cat -v <<EOF
11179 $ @kbd{set | grep '^var=' | cat -v}
11182 One classic incarnation of this bug is:
11186 : $@{list="$default"@}
11193 You'll get @samp{a b c} on a single line. Why? Because there are no
11194 spaces in @samp{$list}: there are @samp{M- }, i.e., spaces with the 8th
11195 bit set, hence no IFS splitting is performed!!!
11197 One piece of good news is that Ultrix works fine with @samp{:
11198 $@{list=$default@}}; i.e., if you @emph{don't} quote. The bad news is
11199 then that @acronym{QNX} 4.25 then sets @var{list} to the @emph{last} item of
11202 The portable way out consists in using a double assignment, to switch
11203 the 8th bit twice on Ultrix:
11206 list=$@{list="$default"@}
11210 @dots{}but beware of the @samp{@}} bug from Solaris (see above). For safety,
11214 test "$@{var+set@}" = set || var=@var{@{value@}}
11218 @item `@var{commands}`
11219 @cindex `@var{commands}`
11220 @cindex Command Substitution
11221 Posix requires shells to trim all trailing newlines from command
11222 output before substituting it, so assignments like
11223 @samp{dir=`echo "$file" | tr a A`} will not work as expected if
11224 @samp{$file} ends in a newline.
11226 While in general it makes no sense, do not substitute a single builtin
11227 with side effects, because Ash 0.2, trying to optimize, does not fork a
11228 subshell to perform the command.
11230 For instance, if you wanted to check that @command{cd} is silent, do not
11231 use @samp{test -z "`cd /`"} because the following can happen:
11236 $ @kbd{test -z "`cd /`" && pwd}
11241 The result of @samp{foo=`exit 1`} is left as an exercise to the reader.
11243 The MSYS shell leaves a stray byte in the expansion of a double-quoted
11244 command substitution of a native program, if the end of the substution
11245 is not aligned with the end of the double quote. This may be worked
11246 around by inserting another pair of quotes:
11249 $ @kbd{echo "`printf 'foo\r\n'` bar" > broken}
11250 $ @kbd{echo "`printf 'foo\r\n'`"" bar" | cmp - broken}
11251 - broken differ: char 4, line 1
11255 @item $(@var{commands})
11256 @cindex $(@var{commands})
11257 This construct is meant to replace @samp{`@var{commands}`},
11258 and it has most of the problems listed under @code{`@var{commands}`}.
11260 This construct can be
11261 nested while this is impossible to do portably with back quotes.
11262 Unfortunately it is not yet universally supported. Most notably, even recent
11263 releases of Solaris don't support it:
11266 $ @kbd{showrev -c /bin/sh | grep version}
11267 Command version: SunOS 5.10 Generic January 2005
11268 $ @kbd{echo $(echo blah)}
11269 syntax error: `(' unexpected
11273 nor does @sc{irix} 6.5's Bourne shell:
11276 IRIX firebird-image 6.5 07151432 IP22
11277 $ @kbd{echo $(echo blah)}
11281 If you do use @samp{$(@var{commands})}, make sure that the commands
11282 do not start with a parenthesis, as that would cause confusion with
11283 a different notation @samp{$((@var{expression}))} that in modern
11284 shells is an arithmetic expression not a command. To avoid the
11285 confusion, insert a space between the two opening parentheses.
11287 Avoid @var{commands} that contain unbalanced parentheses in
11288 here-documents, comments, or case statement patterns, as many shells
11289 mishandle them. For example, Bash 3.1, @samp{ksh88}, @command{pdksh}
11290 5.2.14, and Zsh 4.2.6 all mishandle the following valid command:
11293 echo $(case x in x) echo hello;; esac)
11298 Always quote @samp{^}, otherwise traditional shells such as
11299 @command{/bin/sh} on Solaris 10 treat this like @samp{|}.
11305 @section Assignments
11306 @cindex Shell assignments
11308 When setting several variables in a row, be aware that the order of the
11309 evaluation is undefined. For instance @samp{foo=1 foo=2; echo $foo}
11310 gives @samp{1} with Solaris @command{/bin/sh}, but @samp{2} with Bash.
11312 @samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}.
11314 Don't rely on the following to find @file{subdir/program}:
11317 PATH=subdir$PATH_SEPARATOR$PATH program
11321 as this does not work with Zsh 3.0.6. Use something like this
11325 (PATH=subdir$PATH_SEPARATOR$PATH; export PATH; exec program)
11328 Don't rely on the exit status of an assignment: Ash 0.2 does not change
11329 the status and propagates that of the last statement:
11332 $ @kbd{false || foo=bar; echo $?}
11334 $ @kbd{false || foo=`:`; echo $?}
11339 and to make things even worse, @acronym{QNX} 4.25 just sets the exit status
11343 $ @kbd{foo=`exit 1`; echo $?}
11347 To assign default values, follow this algorithm:
11351 If the default value is a literal and does not contain any closing
11355 : $@{var='my literal'@}
11359 If the default value contains no closing brace, has to be expanded, and
11360 the variable being initialized will never be IFS-split (i.e., it's not a
11364 : $@{var="$default"@}
11368 If the default value contains no closing brace, has to be expanded, and
11369 the variable being initialized will be IFS-split (i.e., it's a list),
11373 var=$@{var="$default"@}
11377 If the default value contains a closing brace, then use:
11380 test "$@{var+set@}" = set || var='$@{indirection@}'
11384 In most cases @samp{var=$@{var="$default"@}} is fine, but in case of
11385 doubt, just use the latter. @xref{Shell Substitutions}, items
11386 @samp{$@{@var{var}:-@var{value}@}} and @samp{$@{@var{var}=@var{value}@}}
11390 @section Parentheses in Shell Scripts
11391 @cindex Shell parentheses
11393 Beware of two opening parentheses in a row, as some shell
11394 implementations mishandle them. For example, @samp{pdksh} 5.2.14
11395 misparses the following code:
11398 if ((true) || false); then
11404 To work around this problem, insert a space between the two opening
11405 parentheses. There is a similar problem and workaround with
11406 @samp{$((}; see @ref{Shell Substitutions}.
11408 Posix requires support for @code{case} patterns with opening
11409 parentheses like this:
11413 (*.c) echo "C source code";;
11418 but the @code{(} in this example is not portable to many older Bourne
11419 shell implementations. It can be omitted safely.
11422 @section Slashes in Shell Scripts
11423 @cindex Shell slashes
11425 Unpatched Tru64 5.1 @command{sh} omits the last slash of command-line
11426 arguments that contain two trailing slashes:
11429 $ echo / // /// //// .// //.
11435 $ echo abc | tr -t ab //
11441 However, our understanding is that patches are available, so perhaps
11442 it's not worth worrying about working around this horrendous bug.
11444 @node Special Shell Variables
11445 @section Special Shell Variables
11446 @cindex Shell variables
11447 @cindex Special shell variables
11449 Some shell variables should not be used, since they can have a deep
11450 influence on the behavior of the shell. In order to recover a sane
11451 behavior from the shell, some variables should be unset, but
11452 @command{unset} is not portable (@pxref{Limitations of Builtins}) and a
11453 fallback value is needed.
11455 As a general rule, shell variable names containing a lower-case letter
11456 are safe; you can define and use these variables without worrying about
11457 their effect on the underlying system, and without worrying about
11458 whether the shell will change them unexpectedly. (The exception is the
11459 shell variable @code{status}, as described below.)
11461 Here is a list of names that are known to cause trouble. This list is
11462 not exhaustive, but you should be safe if you avoid the name
11463 @code{status} and names containing only upper-case letters and
11466 @c Alphabetical order, case insensitive, `A' before `a'.
11469 Many shells reserve @samp{$_} for various purposes, e.g., the name of
11470 the last command executed.
11474 In Tru64, if @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations of
11475 the standard shell conform to Posix.
11476 Autoconf-generated scripts export this variable when they start up.
11480 When this variable is set it specifies a list of directories to search
11481 when invoking @code{cd} with a relative file name. Posix
11482 1003.1-2001 says that if a nonempty directory name from @env{CDPATH}
11483 is used successfully, @code{cd} prints the resulting absolute
11484 file name. Unfortunately this output can break idioms like
11485 @samp{abs=`cd src && pwd`} because @code{abs} receives the name twice.
11486 Also, many shells do not conform to this part of Posix; for
11487 example, @command{zsh} prints the result only if a directory name
11488 other than @file{.} was chosen from @env{CDPATH}.
11490 In practice the shells that have this problem also support
11491 @command{unset}, so you can work around the problem as follows:
11494 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
11497 Autoconf-generated scripts automatically unset @env{CDPATH} if
11498 possible, so you need not worry about this problem in those scripts.
11502 In the MKS shell, case statements and file name generation are
11503 case-insensitive unless @env{DUALCASE} is nonzero.
11504 Autoconf-generated scripts export this variable when they start up.
11518 These variables should not matter for shell scripts, since they are
11519 supposed to affect only interactive shells. However, at least one
11520 shell (the pre-3.0 @sc{uwin} Korn shell) gets confused about
11521 whether it is interactive, which means that (for example) a @env{PS1}
11522 with a side effect can unexpectedly modify @samp{$?}. To work around
11523 this bug, Autoconf-generated scripts do something like this:
11526 (unset ENV) >/dev/null 2>&1 && unset ENV MAIL MAILPATH
11534 Long ago, shell scripts inherited @env{IFS} from the environment,
11535 but this caused many problems so modern shells ignore any environment
11536 settings for @env{IFS}.
11538 Don't set the first character of @code{IFS} to backslash. Indeed,
11539 Bourne shells use the first character (backslash) when joining the
11540 components in @samp{"$@@"} and some shells then re-interpret (!)@: the
11541 backslash escapes, so you can end up with backspace and other strange
11544 The proper value for @code{IFS} (in regular code, not when performing
11545 splits) is @samp{@key{SPC}@key{TAB}@key{RET}}. The first character is
11546 especially important, as it is used to join the arguments in @samp{@@*}.
11558 @evindex LC_COLLATE
11560 @evindex LC_MESSAGES
11561 @evindex LC_MONETARY
11562 @evindex LC_NUMERIC
11565 Autoconf-generated scripts normally set all these variables to
11566 @samp{C} because so much configuration code assumes the C locale and
11567 Posix requires that locale environment variables be set to
11568 @samp{C} if the C locale is desired. However, some older, nonstandard
11569 systems (notably @acronym{SCO}) break if locale environment variables
11570 are set to @samp{C}, so when running on these systems
11571 Autoconf-generated scripts unset the variables instead.
11576 @env{LANGUAGE} is not specified by Posix, but it is a @acronym{GNU}
11577 extension that overrides @env{LC_ALL} in some cases, so
11578 Autoconf-generated scripts set it too.
11581 @itemx LC_IDENTIFICATION
11582 @itemx LC_MEASUREMENT
11585 @itemx LC_TELEPHONE
11586 @evindex LC_ADDRESS
11587 @evindex LC_IDENTIFICATION
11588 @evindex LC_MEASUREMENT
11591 @evindex LC_TELEPHONE
11593 These locale environment variables are @acronym{GNU} extensions. They
11594 are treated like their Posix brethren (@env{LC_COLLATE},
11595 etc.)@: as described above.
11598 Most modern shells provide the current line number in @code{LINENO}.
11599 Its value is the line number of the beginning of the current command.
11600 Autoconf attempts to execute @command{configure} with a modern shell.
11601 If no such shell is available, it attempts to implement @code{LINENO}
11602 with a Sed prepass that replaces each instance of the string
11603 @code{$LINENO} (not followed by an alphanumeric character) with the
11606 You should not rely on @code{LINENO} within @command{eval}, as the
11607 behavior differs in practice. Also, the possibility of the Sed
11608 prepass means that you should not rely on @code{$LINENO} when quoted,
11609 when in here-documents, or when in long commands that cross line
11610 boundaries. Subshells should be OK, though. In the following
11611 example, lines 1, 6, and 9 are portable, but the other instances of
11612 @code{LINENO} are not:
11622 ( echo 6. $LINENO )
11623 eval 'echo 7. $LINENO'
11629 $ @kbd{bash-2.05 lineno}
11640 $ @kbd{zsh-3.0.6 lineno}
11651 $ @kbd{pdksh-5.2.14 lineno}
11662 $ @kbd{sed '=' <lineno |}
11668 > @kbd{ s,^\([0-9]*\)\(.*\)[$]LINENO\([^a-zA-Z0-9_]\),\1\2\1\3,}
11671 > @kbd{ s,^[0-9]*\n,,}
11687 When executing the command @samp{>foo}, @command{zsh} executes
11688 @samp{$NULLCMD >foo} unless it is operating in Bourne shell
11689 compatibility mode and the @command{zsh} version is newer
11690 than 3.1.6-dev-18. If you are using an older @command{zsh}
11691 and forget to set @env{NULLCMD},
11692 your script might be suspended waiting for data on its standard input.
11694 @item PATH_SEPARATOR
11695 @evindex PATH_SEPARATOR
11696 On @acronym{DJGPP} systems, the @env{PATH_SEPARATOR} environment
11697 variable can be set to either @samp{:} or @samp{;} to control the path
11698 separator Bash uses to set up certain environment variables (such as
11699 @env{PATH}). You can set this variable to @samp{;} if you want
11700 @command{configure} to use @samp{;} as a separator; this might be useful
11701 if you plan to use non-Posix shells to execute files. @xref{File System
11702 Conventions}, for more information about @code{PATH_SEPARATOR}.
11706 Posix 1003.1-2001 requires that @command{cd} and
11707 @command{pwd} must update the @env{PWD} environment variable to point
11708 to the logical name of the current directory, but traditional shells
11709 do not support this. This can cause confusion if one shell instance
11710 maintains @env{PWD} but a subsidiary and different shell does not know
11711 about @env{PWD} and executes @command{cd}; in this case @env{PWD} will
11712 point to the wrong directory. Use @samp{`pwd`} rather than
11716 Many shells provide @code{RANDOM}, a variable that returns a different
11717 integer each time it is used. Most of the time, its value does not
11718 change when it is not used, but on @sc{irix} 6.5 the value changes all
11719 the time. This can be observed by using @command{set}. It is common
11720 practice to use @code{$RANDOM} as part of a file name, but code
11721 shouldn't rely on @code{$RANDOM} expanding to a nonempty string.
11724 This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6),
11725 hence read-only. Do not use it.
11728 @node Limitations of Builtins
11729 @section Limitations of Shell Builtins
11730 @cindex Shell builtins
11731 @cindex Limitations of shell builtins
11733 No, no, we are serious: some shells do have limitations! :)
11735 You should always keep in mind that any builtin or command may support
11736 options, and therefore have a very different behavior with arguments
11737 starting with a dash. For instance, the innocent @samp{echo "$word"}
11738 can give unexpected results when @code{word} starts with a dash. It is
11739 often possible to avoid this problem using @samp{echo "x$word"}, taking
11740 the @samp{x} into account later in the pipe.
11744 @prindex @command{.}
11745 Use @command{.} only with regular files (use @samp{test -f}). Bash
11746 2.03, for instance, chokes on @samp{. /dev/null}. Also, remember that
11747 @command{.} uses @env{PATH} if its argument contains no slashes, so if
11748 you want to use @command{.} on a file @file{foo} in the current
11749 directory, you must use @samp{. ./foo}.
11752 @prindex @command{!}
11753 The Unix version 7 shell did not support
11754 negating the exit status of commands with @command{!}, and this feature
11755 is still absent from more modern shells (e.g., Solaris @command{/bin/sh}).
11756 Shell code like this:
11759 if ! cmp file1 file2 >/dev/null 2>&1; then
11760 echo files differ or trouble
11764 is therefore not portable in practice. Typically it is easy to rewrite
11768 cmp file1 file2 >/dev/null 2>&1 ||
11769 echo files differ or trouble
11772 More generally, one can always rewrite @samp{! @var{command}} as:
11775 if @var{command}; then (exit 1); else :; fi
11778 @item @command{break}
11779 @c ------------------
11780 @prindex @command{break}
11781 The use of @samp{break 2} etc.@: is safe.
11784 @item @command{case}
11785 @c -----------------
11786 @prindex @command{case}
11787 You don't need to quote the argument; no splitting is performed.
11789 You don't need the final @samp{;;}, but you should use it.
11791 Because of a bug in its @code{fnmatch}, Bash fails to properly
11792 handle backslashes in character classes:
11795 bash-2.02$ @kbd{case /tmp in [/\\]*) echo OK;; esac}
11800 This is extremely unfortunate, since you are likely to use this code to
11801 handle Posix or @sc{ms-dos} absolute file names. To work around this
11802 bug, always put the backslash first:
11805 bash-2.02$ @kbd{case '\TMP' in [\\/]*) echo OK;; esac}
11807 bash-2.02$ @kbd{case /tmp in [\\/]*) echo OK;; esac}
11811 Many Bourne shells cannot handle closing brackets in character classes
11814 Some shells also have problems with backslash escaping in case you do not want
11815 to match the backslash: both a backslash and the escaped character match this
11816 pattern. To work around this, specify the character class in a variable, so
11817 that quote removal does not apply afterwards, and the special characters don't
11818 have to be backslash-escaped:
11821 $ @kbd{case '\' in [\<]) echo OK;; esac}
11823 $ @kbd{scanset='[<]'; case '\' in $scanset) echo OK;; esac}
11827 Even with this, Solaris @command{ksh} matches a backslash if the set
11829 of the characters @samp{|}, @samp{&}, @samp{(}, or @samp{)}.
11831 Conversely, Tru64 @command{ksh} (circa 2003) erroneously always matches
11832 a closing parenthesis if not specified in a character class:
11835 $ @kbd{case foo in *\)*) echo fail ;; esac}
11837 $ @kbd{case foo in *')'*) echo fail ;; esac}
11841 Some shells, such as Ash 0.3.8, are confused by an empty
11842 @code{case}/@code{esac}:
11845 ash-0.3.8 $ @kbd{case foo in esac;}
11846 @error{}Syntax error: ";" unexpected (expecting ")")
11849 Many shells still do not support parenthesized cases, which is a pity
11850 for those of us using tools that rely on balanced parentheses. For
11851 instance, Solaris @command{/bin/sh}:
11854 $ @kbd{case foo in (foo) echo foo;; esac}
11855 @error{}syntax error: `(' unexpected
11861 @prindex @command{cd}
11862 Posix 1003.1-2001 requires that @command{cd} must support
11863 the @option{-L} (``logical'') and @option{-P} (``physical'') options,
11864 with @option{-L} being the default. However, traditional shells do
11865 not support these options, and their @command{cd} command has the
11866 @option{-P} behavior.
11868 Portable scripts should assume neither option is supported, and should
11869 assume neither behavior is the default. This can be a bit tricky,
11870 since the Posix default behavior means that, for example,
11871 @samp{ls ..} and @samp{cd ..} may refer to different directories if
11872 the current logical directory is a symbolic link. It is safe to use
11873 @command{cd @var{dir}} if @var{dir} contains no @file{..} components.
11874 Also, Autoconf-generated scripts check for this problem when computing
11875 variables like @code{ac_top_srcdir} (@pxref{Configuration Actions}),
11876 so it is safe to @command{cd} to these variables.
11878 Also please see the discussion of the @command{pwd} command.
11881 @item @command{echo}
11882 @c -----------------
11883 @prindex @command{echo}
11884 The simple @command{echo} is probably the most surprising source of
11885 portability troubles. It is not possible to use @samp{echo} portably
11886 unless both options and escape sequences are omitted. New applications
11887 which are not aiming at portability should use @samp{printf} instead of
11890 Don't expect any option. @xref{Preset Output Variables}, @code{ECHO_N}
11891 etc.@: for a means to simulate @option{-n}.
11893 Do not use backslashes in the arguments, as there is no consensus on
11894 their handling. On @samp{echo '\n' | wc -l}, the @command{sh} of
11895 Digital Unix 4.0 and @acronym{MIPS RISC/OS} 4.52, answer 2, but the Solaris
11896 @command{/bin/sh}, Bash, and Zsh (in @command{sh} emulation mode) report 1.
11897 Please note that the problem is truly @command{echo}: all the shells
11898 understand @samp{'\n'} as the string composed of a backslash and an
11901 Because of these problems, do not pass a string containing arbitrary
11902 characters to @command{echo}. For example, @samp{echo "$foo"} is safe
11903 if you know that @var{foo}'s value cannot contain backslashes and cannot
11904 start with @samp{-}, but otherwise you should use a here-document like
11914 @item @command{eval}
11915 @c -----------------
11916 @prindex @command{eval}
11917 In some shell implementations (e.g., older @command{ash}, Open@acronym{BSD} 3.8
11918 @command{sh}, @command{pdksh} v5.2.14 99/07/13.2, and @command{zsh}
11919 4.2.5), the arguments of @samp{eval} are evaluated in a context where
11920 @samp{$?} is 0, so they exhibit behavior like this:
11923 $ false; eval 'echo $?'
11927 The correct behavior here is to output a nonzero value,
11928 but portable scripts should not rely on this.
11930 You should not rely on @code{LINENO} within @command{eval}.
11931 @xref{Special Shell Variables}.
11933 @item @command{exit}
11934 @c -----------------
11935 @prindex @command{exit}
11936 The default value of @command{exit} is supposed to be @code{$?};
11937 unfortunately, some shells, such as the @acronym{DJGPP} port of Bash 2.04, just
11938 perform @samp{exit 0}.
11941 bash-2.04$ @kbd{foo=`exit 1` || echo fail}
11943 bash-2.04$ @kbd{foo=`(exit 1)` || echo fail}
11945 bash-2.04$ @kbd{foo=`(exit 1); exit` || echo fail}
11949 Using @samp{exit $?} restores the expected behavior.
11951 Some shell scripts, such as those generated by @command{autoconf}, use a
11952 trap to clean up before exiting. If the last shell command exited with
11953 nonzero status, the trap also exits with nonzero status so that the
11954 invoker can tell that an error occurred.
11956 Unfortunately, in some shells, such as Solaris @command{/bin/sh}, an exit
11957 trap ignores the @code{exit} command's argument. In these shells, a trap
11958 cannot determine whether it was invoked by plain @code{exit} or by
11959 @code{exit 1}. Instead of calling @code{exit} directly, use the
11960 @code{AC_MSG_ERROR} macro that has a workaround for this problem.
11963 @item @command{export}
11964 @c -------------------
11965 @prindex @command{export}
11966 The builtin @command{export} dubs a shell variable @dfn{environment
11967 variable}. Each update of exported variables corresponds to an update
11968 of the environment variables. Conversely, each environment variable
11969 received by the shell when it is launched should be imported as a shell
11970 variable marked as exported.
11972 Alas, many shells, such as Solaris @command{/bin/sh},
11973 @sc{irix} 6.3, @sc{irix} 5.2,
11974 @acronym{AIX} 4.1.5, and Digital Unix 4.0, forget to
11975 @command{export} the environment variables they receive. As a result,
11976 two variables coexist: the environment variable and the shell
11977 variable. The following code demonstrates this failure:
11988 when run with @samp{FOO=foo} in the environment, these shells will print
11989 alternately @samp{foo} and @samp{bar}, although it should only print
11990 @samp{foo} and then a sequence of @samp{bar}s.
11992 Therefore you should @command{export} again each environment variable
11996 @item @command{false}
11997 @c ------------------
11998 @prindex @command{false}
11999 Don't expect @command{false} to exit with status 1: in native
12000 Solaris it exits with status 255.
12003 @item @command{for}
12004 @c ----------------
12005 @prindex @command{for}
12006 To loop over positional arguments, use:
12016 You may @emph{not} leave the @code{do} on the same line as @code{for},
12017 since some shells improperly grok:
12025 If you want to explicitly refer to the positional arguments, given the
12026 @samp{$@@} bug (@pxref{Shell Substitutions}), use:
12029 for arg in $@{1+"$@@"@}; do
12035 But keep in mind that Zsh, even in Bourne shell emulation mode, performs
12036 word splitting on @samp{$@{1+"$@@"@}}; see @ref{Shell Substitutions},
12037 item @samp{$@@}, for more.
12042 @prindex @command{if}
12043 Using @samp{!} is not portable. Instead of:
12046 if ! cmp -s file file.new; then
12055 if cmp -s file file.new; then :; else
12060 There are shells that do not reset the exit status from an @command{if}:
12063 $ @kbd{if (exit 42); then true; fi; echo $?}
12068 whereas a proper shell should have printed @samp{0}. This is especially
12069 bad in Makefiles since it produces false failures. This is why properly
12070 written Makefiles, such as Automake's, have such hairy constructs:
12073 if test -f "$file"; then
12074 install "$file" "$dest"
12081 @item @command{printf}
12082 @c ------------------
12083 @prindex @command{printf}
12084 A format string starting with a @samp{-} can cause problems.
12085 Bash (e.g., 2.05b) will interpret it as an options string and
12086 give an error. And @samp{--} to mark the end of options is not good
12087 in the Net@acronym{BSD} Almquist shell (e.g., 0.4.6) which will take that
12088 literally as the format string. Putting the @samp{-} in a @samp{%c}
12089 or @samp{%s} is probably the easiest way to avoid doubt,
12096 @item @command{read}
12097 @c ------------------
12098 @prindex @command{read}
12099 Not all shells support @option{-r} (Solaris @command{/bin/sh} for example).
12102 @item @command{pwd}
12103 @c ----------------
12104 @prindex @command{pwd}
12105 With modern shells, plain @command{pwd} outputs a ``logical''
12106 directory name, some of whose components may be symbolic links. These
12107 directory names are in contrast to ``physical'' directory names, whose
12108 components are all directories.
12110 Posix 1003.1-2001 requires that @command{pwd} must support
12111 the @option{-L} (``logical'') and @option{-P} (``physical'') options,
12112 with @option{-L} being the default. However, traditional shells do
12113 not support these options, and their @command{pwd} command has the
12114 @option{-P} behavior.
12116 Portable scripts should assume neither option is supported, and should
12117 assume neither behavior is the default. Also, on many hosts
12118 @samp{/bin/pwd} is equivalent to @samp{pwd -P}, but Posix
12119 does not require this behavior and portable scripts should not rely on
12122 Typically it's best to use plain @command{pwd}. On modern hosts this
12123 outputs logical directory names, which have the following advantages:
12127 Logical names are what the user specified.
12129 Physical names may not be portable from one installation
12130 host to another due to network file system gymnastics.
12132 On modern hosts @samp{pwd -P} may fail due to lack of permissions to
12133 some parent directory, but plain @command{pwd} cannot fail for this
12137 Also please see the discussion of the @command{cd} command.
12140 @item @command{set}
12141 @c ----------------
12142 @prindex @command{set}
12143 This builtin faces the usual problem with arguments starting with a
12144 dash. Modern shells such as Bash or Zsh understand @option{--} to specify
12145 the end of the options (any argument after @option{--} is a parameter,
12146 even @samp{-x} for instance), but most shells simply stop the option
12147 processing as soon as a non-option argument is found. Therefore, use
12148 @samp{dummy} or simply @samp{x} to end the option processing, and use
12149 @command{shift} to pop it out:
12152 set x $my_list; shift
12155 Avoid @samp{set -}, e.g., @samp{set - $my_list}. Posix no
12156 longer requires support for this command, and in traditional shells
12157 @samp{set - $my_list} resets the @samp{-v} and @samp{-x} options, which
12158 makes scripts harder to debug.
12160 Some nonstandard shells do not recognize more than one option
12161 (e.g., @samp{set -e -x} assigns @samp{-x} to the command line). It is
12162 better to combine them:
12169 @item @command{shift}
12170 @c ------------------
12171 @prindex @command{shift}
12172 Not only is @command{shift}ing a bad idea when there is nothing left to
12173 shift, but in addition it is not portable: the shell of @acronym{MIPS
12174 RISC/OS} 4.52 refuses to do it.
12176 Don't use @samp{shift 2} etc.; it was not in the 7th Edition Bourne shell,
12177 and it is also absent in many pre-Posix shells.
12180 @item @command{source}
12181 @c -------------------
12182 @prindex @command{source}
12183 This command is not portable, as Posix does not require it; use
12184 @command{.} instead.
12187 @item @command{test}
12188 @c -----------------
12189 @prindex @command{test}
12190 The @code{test} program is the way to perform many file and string
12191 tests. It is often invoked by the alternate name @samp{[}, but using
12192 that name in Autoconf code is asking for trouble since it is an M4 quote
12195 If you need to make multiple checks using @code{test}, combine them with
12196 the shell operators @samp{&&} and @samp{||} instead of using the
12197 @code{test} operators @option{-a} and @option{-o}. On System V, the
12198 precedence of @option{-a} and @option{-o} is wrong relative to the unary
12199 operators; consequently, Posix does not specify them, so using them
12200 is nonportable. If you combine @samp{&&} and @samp{||} in the same
12201 statement, keep in mind that they have equal precedence.
12203 It is safe to use @samp{!} as a @command{test} operator. For example,
12204 @samp{if test ! -d foo; @dots{}} is portable even though @samp{if ! test
12205 -d foo; @dots{}} is not.
12208 @item @command{test} (files)
12209 @c -------------------------
12210 To enable @command{configure} scripts to support cross-compilation, they
12211 shouldn't do anything that tests features of the build system instead of
12212 the host system. But occasionally you may find it necessary to check
12213 whether some arbitrary file exists. To do so, use @samp{test -f} or
12214 @samp{test -r}. Do not use @samp{test -x}, because 4.3@acronym{BSD} does not
12215 have it. Do not use @samp{test -e} either, because Solaris @command{/bin/sh}
12216 lacks it. To test for symbolic links on systems that have them, use
12217 @samp{test -h} rather than @samp{test -L}; either form conforms to
12218 Posix 1003.1-2001, but older shells like Solaris 8
12219 @code{/bin/sh} support only @option{-h}.
12221 @item @command{test} (strings)
12222 @c ---------------------------
12223 Avoid @samp{test "@var{string}"}, in particular if @var{string} might
12224 start with a dash, since @code{test} might interpret its argument as an
12225 option (e.g., @samp{@var{string} = "-n"}).
12227 Contrary to a common belief, @samp{test -n @var{string}} and
12228 @samp{test -z @var{string}} @strong{are} portable. Nevertheless many
12229 shells (such as Solaris, @acronym{AIX} 3.2, @sc{unicos} 10.0.0.6,
12230 Digital Unix 4, etc.)@: have bizarre precedence and may be confused if
12231 @var{string} looks like an operator:
12235 test: argument expected
12238 If there are risks, use @samp{test "x@var{string}" = x} or @samp{test
12239 "x@var{string}" != x} instead.
12241 It is common to find variations of the following idiom:
12244 test -n "`echo $ac_feature | sed 's/[-a-zA-Z0-9_]//g'`" &&
12249 to take an action when a token matches a given pattern. Such constructs
12250 should always be avoided by using:
12253 echo "$ac_feature" | grep '[^-a-zA-Z0-9_]' >/dev/null 2>&1 &&
12258 Use @code{case} where possible since it is faster, being a shell builtin:
12262 case $ac_feature in
12263 *[!-a-zA-Z0-9_]*) @var{action};;
12267 Alas, negated character classes are probably not portable, although no
12268 shell is known to not support the Posix syntax @samp{[!@dots{}]}
12269 (when in interactive mode, @command{zsh} is confused by the
12270 @samp{[!@dots{}]} syntax and looks for an event in its history because of
12271 @samp{!}). Many shells do not support the alternative syntax
12272 @samp{[^@dots{}]} (Solaris, Digital Unix, etc.).
12274 One solution can be:
12277 expr "$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null &&
12285 expr "X$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null &&
12289 @samp{expr "X@var{foo}" : "X@var{bar}"} is more robust than @samp{echo
12290 "X@var{foo}" | grep "^X@var{bar}"}, because it avoids problems when
12291 @samp{@var{foo}} contains backslashes.
12294 @item @command{trap}
12295 @c -----------------
12296 @prindex @command{trap}
12297 It is safe to trap at least the signals 1, 2, 13, and 15. You can also
12298 trap 0, i.e., have the @command{trap} run when the script ends (either via an
12299 explicit @command{exit}, or the end of the script).
12301 Posix says that @samp{trap - 1 2 13 15} resets the traps for the
12302 specified signals to their default values, but many common shells (e.g.,
12303 Solaris @command{/bin/sh}) misinterpret this and attempt to execute a
12304 ``command'' named @command{-} when the specified conditions arise.
12305 There is no portable workaround, except for @samp{trap - 0}, for which
12306 @samp{trap '' 0} is a portable substitute.
12308 Although Posix is not absolutely clear on this point, it is widely
12309 admitted that when entering the trap @samp{$?} should be set to the exit
12310 status of the last command run before the trap. The ambiguity can be
12311 summarized as: ``when the trap is launched by an @command{exit}, what is
12312 the @emph{last} command run: that before @command{exit}, or
12313 @command{exit} itself?''
12315 Bash considers @command{exit} to be the last command, while Zsh and
12316 Solaris @command{/bin/sh} consider that when the trap is run it is
12317 @emph{still} in the @command{exit}, hence it is the previous exit status
12318 that the trap receives:
12321 $ @kbd{cat trap.sh}
12324 $ @kbd{zsh trap.sh}
12326 $ @kbd{bash trap.sh}
12330 The portable solution is then simple: when you want to @samp{exit 42},
12331 run @samp{(exit 42); exit 42}, the first @command{exit} being used to
12332 set the exit status to 42 for Zsh, and the second to trigger the trap
12333 and pass 42 as exit status for Bash.
12335 The shell in Free@acronym{BSD} 4.0 has the following bug: @samp{$?} is
12336 reset to 0 by empty lines if the code is inside @command{trap}.
12339 $ @kbd{trap 'false}
12347 Fortunately, this bug only affects @command{trap}.
12349 @item @command{true}
12350 @c -----------------
12351 @prindex @command{true}
12352 @c Info cannot handle `:' in index entries.
12353 @c @prindex @command{:}
12354 Don't worry: as far as we know @command{true} is portable.
12355 Nevertheless, it's not always a builtin (e.g., Bash 1.x), and the
12356 portable shell community tends to prefer using @command{:}. This has a
12357 funny side effect: when asked whether @command{false} is more portable
12358 than @command{true} Alexandre Oliva answered:
12361 In a sense, yes, because if it doesn't exist, the shell will produce an
12362 exit status of failure, which is correct for @command{false}, but not
12363 for @command{true}.
12367 @item @command{unset}
12368 @c ------------------
12369 @prindex @command{unset}
12370 You cannot assume the support of @command{unset}. Nevertheless, because
12371 it is extremely useful to disable embarrassing variables such as
12372 @code{PS1}, you can test for its existence and use
12373 it @emph{provided} you give a neutralizing value when @command{unset} is
12377 if (unset FOO) >/dev/null 2>&1; then
12382 $unset PS1 || PS1='$ '
12385 @xref{Special Shell Variables}, for some neutralizing values. Also, see
12386 @ref{Limitations of Builtins}, documentation of @command{export}, for
12387 the case of environment variables.
12390 @node Limitations of Usual Tools
12391 @section Limitations of Usual Tools
12392 @cindex Limitations of usual tools
12394 The small set of tools you can expect to find on any machine can still
12395 include some limitations you should be aware of.
12399 @c ----------------
12401 Don't leave white space before the opening parenthesis in a user function call.
12402 Posix does not allow this and @acronym{GNU} Awk rejects it:
12405 $ @kbd{gawk 'function die () @{ print "Aaaaarg!" @}
12406 BEGIN @{ die () @}'}
12407 gawk: cmd. line:2: BEGIN @{ die () @}
12408 gawk: cmd. line:2: ^ parse error
12409 $ @kbd{gawk 'function die () @{ print "Aaaaarg!" @}
12410 BEGIN @{ die() @}'}
12414 If you want your program to be deterministic, don't depend on @code{for}
12418 $ @kbd{cat for.awk}
12425 $ @kbd{gawk -f for.awk </dev/null}
12428 $ @kbd{nawk -f for.awk </dev/null}
12433 Some Awk implementations, such as HP-UX 11.0's native one, mishandle anchors:
12436 $ @kbd{echo xfoo | $AWK '/foo|^bar/ @{ print @}'}
12437 $ @kbd{echo bar | $AWK '/foo|^bar/ @{ print @}'}
12439 $ @kbd{echo xfoo | $AWK '/^bar|foo/ @{ print @}'}
12441 $ @kbd{echo bar | $AWK '/^bar|foo/ @{ print @}'}
12446 Either do not depend on such patterns (i.e., use @samp{/^(.*foo|bar)/},
12447 or use a simple test to reject such implementations.
12449 @acronym{AIX} version 5.2 has an arbitrary limit of 399 on the the
12450 length of regular expressions and literal strings in an Awk program.
12452 Traditional Awk implementations derived from Unix version 7, such as
12453 Solaris @command{/bin/awk}, have many limitations and do not
12454 conform to Posix. Nowadays @code{AC_PROG_AWK} (@pxref{Particular
12455 Programs}) will find you an Awk that doesn't have these problems, but if
12456 for some reason you prefer not to use @code{AC_PROG_AWK} you may need to
12459 Traditional Awk does not support multidimensional arrays or user-defined
12462 Traditional Awk does not support the @option{-v} option. You can use
12463 assignments after the program instead, e.g., @command{$AWK '@{print v
12464 $1@}' v=x}; however, don't forget that such assignments are not
12465 evaluated until they are encountered (e.g., after any @code{BEGIN}
12468 Traditional Awk does not support the keywords @code{delete} or @code{do}.
12470 Traditional Awk does not support the expressions
12471 @code{@var{a}?@var{b}:@var{c}}, @code{!@var{a}}, @code{@var{a}^@var{b}},
12472 or @code{@var{a}^=@var{b}}.
12474 Traditional Awk does not support the predefined @code{CONVFMT} variable.
12476 Traditional Awk supports only the predefined functions @code{exp},
12477 @code{int}, @code{length}, @code{log}, @code{split}, @code{sprintf},
12478 @code{sqrt}, and @code{substr}.
12480 Traditional Awk @code{getline} is not at all compatible with Posix;
12483 Traditional Awk @code{split} supports only two arguments.
12485 Traditional Awk has a limit of 99
12486 fields in a record. You may be able to circumvent this problem by using
12490 @item @command{basename}
12491 @c ---------------------
12492 @prindex @command{basename}
12493 Not all hosts have a working @command{basename}.
12494 You can use @command{expr} instead.
12496 @c AS_BASENAME is to be replaced by a better API.
12498 Not all hosts have a working @command{basename}, and you should instead
12499 use @code{AS_BASENAME} (@pxref{Programming in M4sh}), followed by
12500 @command{expr} if you need to strip a suffix. For example:
12503 a=`basename "$aname"` # This is not portable.
12504 a=`AS_BASENAME(["$aname"])` # This is more portable.
12506 # This is not portable.
12507 c=`basename "$cname" .c`
12509 # This is more portable.
12510 c=`AS_BASENAME(["$cname"])`
12512 ?*.c) c=`expr "X$c" : 'X\(.*\)\.c'`;;
12518 @item @command{cat}
12519 @c ----------------
12520 @prindex @command{cat}
12521 Don't rely on any option.
12526 @prindex @command{cc}
12527 The command @samp{cc -c foo.c} traditionally produces an object file
12528 named @file{foo.o}. Most compilers allow @option{-c} to be combined
12529 with @option{-o} to specify a different object file name, but
12530 Posix does not require this combination and a few compilers
12531 lack support for it. @xref{C Compiler}, for how @acronym{GNU} Make
12532 tests for this feature with @code{AC_PROG_CC_C_O}.
12534 When a compilation such as @samp{cc -o foo foo.c} fails, some compilers
12535 (such as @sc{cds} on Reliant Unix) leave a @file{foo.o}.
12537 HP-UX @command{cc} doesn't accept @file{.S} files to preprocess and
12538 assemble. @samp{cc -c foo.S} will appear to succeed, but in fact does
12541 The default executable, produced by @samp{cc foo.c}, can be
12544 @item @file{a.out} --- usual Posix convention.
12545 @item @file{b.out} --- i960 compilers (including @command{gcc}).
12546 @item @file{a.exe} --- @acronym{DJGPP} port of @command{gcc}.
12547 @item @file{a_out.exe} --- GNV @command{cc} wrapper for DEC C on OpenVMS.
12548 @item @file{foo.exe} --- various MS-DOS compilers.
12551 The C compiler's traditional name is @command{cc}, but other names like
12552 @command{gcc} are common. Posix 1003.1-2001 specifies the
12553 name @command{c99}, but older Posix editions specified
12554 @command{c89} and anyway these standard names are rarely used in
12555 practice. Typically the C compiler is invoked from makefiles that use
12556 @samp{$(CC)}, so the value of the @samp{CC} make variable selects the
12560 @item @command{chmod}
12561 @c ------------------
12562 @prindex @command{chmod}
12563 Avoid usages like @samp{chmod -w file}; use @samp{chmod a-w file}
12564 instead, for two reasons. First, plain @samp{-w} does not necessarily
12565 make the file unwritable, since it does not affect mode bits that
12566 correspond to bits in the file mode creation mask. Second,
12567 Posix says that the @samp{-w} might be interpreted as an
12568 implementation-specific option, not as a mode; Posix suggests
12569 using @samp{chmod -- -w file} to avoid this confusion, but unfortunately
12570 @samp{--} does not work on some older hosts.
12573 @item @command{cmp}
12574 @c ----------------
12575 @prindex @command{cmp}
12576 @command{cmp} performs a raw data comparison of two files, while
12577 @command{diff} compares two text files. Therefore, if you might compare
12578 DOS files, even if only checking whether two files are different, use
12579 @command{diff} to avoid spurious differences due to differences of
12585 @prindex @command{cp}
12586 Avoid the @option{-r} option, since its behavior is not specified by
12587 Posix. Use @option{-R} instead. On @acronym{GNU} hosts the two options
12588 are equivalent, but on Solaris hosts (for example) @command{cp -r}
12589 reads from pipes instead of replicating them.
12591 Some @command{cp} implementations (e.g., @acronym{BSD/OS} 4.2) do not allow
12592 trailing slashes at the end of nonexistent destination directories. To
12593 avoid this problem, omit the trailing slashes. For example, use
12594 @samp{cp -R source /tmp/newdir} rather than @samp{cp -R source
12595 /tmp/newdir/} if @file{/tmp/newdir} does not exist.
12597 @c This is thanks to Ian.
12598 SunOS 4 @command{cp} does not support @option{-f}, although its
12599 @command{mv} does. It's possible to deduce why @command{mv} and
12600 @command{cp} are different with respect to @option{-f}. @command{mv}
12601 prompts by default before overwriting a read-only file. @command{cp}
12602 does not. Therefore, @command{mv} requires a @option{-f} option, but
12603 @command{cp} does not. @command{mv} and @command{cp} behave differently
12604 with respect to read-only files because the simplest form of
12605 @command{cp} cannot overwrite a read-only file, but the simplest form of
12606 @command{mv} can. This is because @command{cp} opens the target for
12607 write access, whereas @command{mv} simply calls @code{link} (or, in
12608 newer systems, @code{rename}).
12609 @c Ian said: ``I don't think -p or -r are portable''!!! How can you live
12612 @cindex timestamp resolution
12613 Traditionally, file timestamps had 1-second resolution, and @samp{cp
12614 -p} copied the timestamps exactly. However, many modern file systems
12615 have timestamps with 1-nanosecond resolution. Unfortunately, @samp{cp
12616 -p} implementations truncate timestamps when copying files, so this
12617 can result in the destination file appearing to be older than the
12618 source. The exact amount of truncation depends on the resolution of
12619 the system calls that @command{cp} uses; traditionally this was
12620 @code{utime}, which has 1-second resolution, but some newer
12621 @command{cp} implementations use @code{utimes}, which has
12622 1-microsecond resolution. These newer implementations include @acronym{GNU}
12623 Core Utilities 5.0.91 or later, and Solaris 8 (sparc) patch 109933-02 or
12624 later. Unfortunately as of January 2006 there is still no system
12625 call to set time stamps to the full nanosecond resolution.
12627 Bob Proulx notes that @samp{cp -p} always @emph{tries} to copy
12628 ownerships. But whether it actually does copy ownerships or not is a
12629 system dependent policy decision implemented by the kernel. If the
12630 kernel allows it then it happens. If the kernel does not allow it then
12631 it does not happen. It is not something @command{cp} itself has control
12634 In Unix System V any user can chown files to any other user, and System
12635 V also has a non-sticky @file{/tmp}. That probably derives from the
12636 heritage of System V in a business environment without hostile users.
12637 @acronym{BSD} changed this
12638 to be a more secure model where only root can @command{chown} files and
12639 a sticky @file{/tmp} is used. That undoubtedly derives from the heritage
12640 of @acronym{BSD} in a campus environment.
12642 @acronym{GNU}/Linux and Solaris by default follow @acronym{BSD}, but
12643 can be configured to allow a System V style @command{chown}. On the
12644 other hand, @acronym{HP-UX} follows System V, but can
12645 be configured to use the modern security model and disallow
12646 @command{chown}. Since it is an administrator-configurable parameter
12647 you can't use the name of the kernel as an indicator of the behavior.
12651 @item @command{date}
12652 @c -----------------
12653 @prindex @command{date}
12654 Some versions of @command{date} do not recognize special % directives,
12655 and unfortunately, instead of complaining, they just pass them through,
12656 and exit with success:
12660 OSF1 medusa.sis.pasteur.fr V5.1 732 alpha
12666 @item @command{diff}
12667 @c -----------------
12668 @prindex @command{diff}
12669 Option @option{-u} is nonportable.
12671 Some implementations, such as Tru64's, fail when comparing to
12672 @file{/dev/null}. Use an empty file instead.
12675 @item @command{dirname}
12676 @c --------------------
12677 @prindex @command{dirname}
12678 Not all hosts have a working @command{dirname}, and you should instead
12679 use @code{AS_DIRNAME} (@pxref{Programming in M4sh}). For example:
12682 dir=`dirname "$file"` # This is not portable.
12683 dir=`AS_DIRNAME(["$file"])` # This is more portable.
12687 @item @command{egrep}
12688 @c ------------------
12689 @prindex @command{egrep}
12690 Posix 1003.1-2001 no longer requires @command{egrep},
12691 but many older hosts do not yet support the Posix
12692 replacement @code{grep -E}. Also, some traditional implementations do
12693 not work on long input lines. To work around these problems, invoke
12694 @code{AC_PROG_EGREP} and then use @code{$EGREP}.
12696 Portable extended regular expressions should use @samp{\} only to escape
12697 characters in the string @samp{$()*+.?[\^@{|}. For example, @samp{\@}}
12698 is not portable, even though it typically matches @samp{@}}.
12700 The empty alternative is not portable, use @samp{?} instead. For
12701 instance with Digital Unix v5.0:
12704 > printf "foo\n|foo\n" | $EGREP '^(|foo|bar)$'
12706 > printf "bar\nbar|\n" | $EGREP '^(foo|bar|)$'
12708 > printf "foo\nfoo|\n|bar\nbar\n" | $EGREP '^(foo||bar)$'
12713 @command{$EGREP} also suffers the limitations of @command{grep}.
12715 @item @command{expr}
12716 @c -----------------
12717 @prindex @command{expr}
12718 No @command{expr} keyword starts with @samp{X}, so use @samp{expr
12719 X"@var{word}" : 'X@var{regex}'} to keep @command{expr} from
12720 misinterpreting @var{word}.
12722 Don't use @code{length}, @code{substr}, @code{match} and @code{index}.
12724 @item @command{expr} (@samp{|})
12725 @prindex @command{expr} (@samp{|})
12726 You can use @samp{|}. Although Posix does require that @samp{expr
12727 ''} return the empty string, it does not specify the result when you
12728 @samp{|} together the empty string (or zero) with the empty string. For
12735 Posix 1003.2-1992 returns the empty string
12736 for this case, but traditional Unix returns @samp{0} (Solaris is
12737 one such example). In Posix 1003.1-2001, the specification was
12738 changed to match traditional Unix's behavior (which is
12739 bizarre, but it's too late to fix this). Please note that the same
12740 problem does arise when the empty string results from a computation,
12744 expr bar : foo \| foo : bar
12748 Avoid this portability problem by avoiding the empty string.
12751 @item @command{expr} (@samp{:})
12752 @c ----------------------------
12753 @prindex @command{expr}
12754 Portable @command{expr} regular expressions should use @samp{\} to
12755 escape only characters in the string @samp{$()*.0123456789[\^n@{@}}.
12756 For example, alternation, @samp{\|}, is common but Posix does not
12757 require its support, so it should be avoided in portable scripts.
12758 Similarly, @samp{\+} and @samp{\?} should be avoided.
12760 Portable @command{expr} regular expressions should not begin with
12761 @samp{^}. Patterns are automatically anchored so leading @samp{^} is
12764 The Posix standard is ambiguous as to whether
12765 @samp{expr 'a' : '\(b\)'} outputs @samp{0} or the empty string.
12766 In practice, it outputs the empty string on most platforms, but portable
12767 scripts should not assume this. For instance, the @acronym{QNX} 4.25 native
12768 @command{expr} returns @samp{0}.
12770 One might think that a way to get a uniform behavior would be to use
12771 the empty string as a default value:
12774 expr a : '\(b\)' \| ''
12778 Unfortunately this behaves exactly as the original expression; see the
12779 @samp{@command{expr} (@samp{|})} entry for more information.
12781 Older @command{expr} implementations (e.g., SunOS 4 @command{expr} and
12782 Solaris 8 @command{/usr/ucb/expr}) have a silly length limit that causes
12783 @command{expr} to fail if the matched substring is longer than 120
12784 bytes. In this case, you might want to fall back on @samp{echo|sed} if
12785 @command{expr} fails.
12787 On Mac OS X 10.4, @command{expr} mishandles the pattern @samp{[^-]} in
12788 some cases. For example, the command @samp{expr
12789 Xpowerpc-apple-darwin8.1.0 : 'X[^-]*-[^-]*-\(.*\)'} outputs
12790 @samp{apple-darwin8.1.0} rather than the correct @samp{darwin8.1.0}.
12791 This particular case can be worked around by substituting @samp{[^--]}
12794 Don't leave, there is some more!
12796 The @acronym{QNX} 4.25 @command{expr}, in addition of preferring @samp{0} to
12797 the empty string, has a funny behavior in its exit status: it's always 1
12798 when parentheses are used!
12801 $ @kbd{val=`expr 'a' : 'a'`; echo "$?: $val"}
12803 $ @kbd{val=`expr 'a' : 'b'`; echo "$?: $val"}
12806 $ @kbd{val=`expr 'a' : '\(a\)'`; echo "?: $val"}
12808 $ @kbd{val=`expr 'a' : '\(b\)'`; echo "?: $val"}
12813 In practice this can be a big problem if you are ready to catch failures
12814 of @command{expr} programs with some other method (such as using
12815 @command{sed}), since you may get twice the result. For instance
12818 $ @kbd{expr 'a' : '\(a\)' || echo 'a' | sed 's/^\(a\)$/\1/'}
12822 will output @samp{a} on most hosts, but @samp{aa} on @acronym{QNX} 4.25. A
12823 simple workaround consists in testing @command{expr} and use a variable
12824 set to @command{expr} or to @command{false} according to the result.
12826 Tru64 @command{expr} incorrectly treats the result as a number, if it
12827 can be interpreted that way:
12830 $ @kbd{expr 00001 : '.*\(...\)'}
12835 @item @command{fgrep}
12836 @c ------------------
12837 @prindex @command{fgrep}
12838 Posix 1003.1-2001 no longer requires @command{fgrep},
12839 but many older hosts do not yet support the Posix
12840 replacement @code{grep -F}. Also, some traditional implementations do
12841 not work on long input lines. To work around these problems, invoke
12842 @code{AC_PROG_FGREP} and then use @code{$FGREP}.
12845 @item @command{find}
12846 @c -----------------
12847 @prindex @command{find}
12848 The option @option{-maxdepth} seems to be @acronym{GNU} specific.
12849 Tru64 v5.1, Net@acronym{BSD} 1.5 and Solaris @command{find}
12850 commands do not understand it.
12852 The replacement of @samp{@{@}} is guaranteed only if the argument is
12853 exactly @emph{@{@}}, not if it's only a part of an argument. For
12854 instance on DU, and HP-UX 10.20 and HP-UX 11:
12858 $ @kbd{find . -name foo -exec echo "@{@}-@{@}" \;}
12863 while @acronym{GNU} @command{find} reports @samp{./foo-./foo}.
12866 @item @command{grep}
12867 @c -----------------
12868 @prindex @command{grep}
12869 Portable scripts can rely on the @command{grep} options @option{-c},
12870 @option{-l}, @option{-n}, and @option{-v}, but should avoid other
12871 options. For example, don't use @option{-w}, as Posix does not require
12872 it and Irix 6.5.16m's @command{grep} does not support it.
12874 Some of the options required by Posix are not portable in practice.
12875 Don't use @samp{grep -q} to suppress output, because many @command{grep}
12876 implementations (e.g., Solaris) do not support @option{-q}.
12877 Don't use @samp{grep -s} to suppress output either, because Posix
12878 says @option{-s} does not suppress output, only some error messages;
12879 also, the @option{-s} option of traditional @command{grep} behaved
12880 like @option{-q} does in most modern implementations. Instead,
12881 redirect the standard output and standard error (in case the file
12882 doesn't exist) of @code{grep} to @file{/dev/null}. Check the exit
12883 status of @code{grep} to determine whether it found a match.
12885 Some traditional @command{grep} implementations do not work on long
12886 input lines. Also, many implementations do not support multiple regexps
12887 with @option{-e}: they either reject @samp{-e} entirely (e.g., Solaris)
12888 or honor only the last pattern (e.g., @acronym{IRIX} 6.5). To
12889 work around these problems, invoke @code{AC_PROG_GREP} and then use
12892 Another possible workaround for the multiple @samp{-e} problem is to
12893 separate the patterns by newlines, for example:
12901 except that this will fail with traditional @command{grep}
12902 implementations and with Open@acronym{BSD} 3.8 @command{grep}.
12904 Traditional @command{grep} implementations (e.g., Solaris) do not
12905 support the @option{-E} or @samp{-F} options. To work around these
12906 problems, invoke @code{AC_PROG_EGREP} and then use @code{$EGREP}, and
12907 similarly for @code{AC_PROG_FGREP} and @code{$FGREP}.
12909 Portable @command{grep} regular expressions should use @samp{\} only to
12910 escape characters in the string @samp{$()*.0123456789[\^@{@}}. For example,
12911 alternation, @samp{\|}, is common but Posix does not require its
12912 support in basic regular expressions, so it should be avoided in
12913 portable scripts. Solaris @command{grep} does not support it.
12914 Similarly, @samp{\+} and @samp{\?} should be avoided.
12917 @item @command{join}
12918 @c -----------------
12919 @prindex @command{join}
12920 Solaris 8 @command{join} has bugs when the second operand is standard
12921 input, and when standard input is a pipe. For example, the following
12922 shell script causes Solaris 8 @command{join} to loop forever:
12929 cat file | join file -
12932 Use @samp{join - file} instead.
12937 @prindex @command{ln}
12938 @cindex Symbolic links
12939 Don't rely on @command{ln} having a @option{-f} option. Symbolic links
12940 are not available on old systems; use @samp{$(LN_S)} as a portable substitute.
12942 For versions of the @acronym{DJGPP} before 2.04,
12943 @command{ln} emulates symbolic links
12944 to executables by generating a stub that in turn calls the real
12945 program. This feature also works with nonexistent files like in the
12946 Posix spec. So @samp{ln -s file link} will generate @file{link.exe},
12947 which will attempt to call @file{file.exe} if run. But this feature only
12948 works for executables, so @samp{cp -p} is used instead for these
12949 systems. @acronym{DJGPP} versions 2.04 and later have full support
12950 for symbolic links.
12955 @prindex @command{ls}
12956 @cindex Listing directories
12957 The portable options are @option{-acdilrtu}. Modern practice is for
12958 @option{-l} to output both owner and group, but traditional
12959 @command{ls} omits the group.
12961 @c From Bruce Lilly:
12965 @c Unix System V (TWG-TCP/IP) (dim.blilly.com)
12969 @c $ /bin/ls a.exe 2>/dev/null
12973 @c fndcmd:fndcmd.sl 1.68
12975 @c Unix dim SYSTEM5 3.51m mc68k
12977 @c It's an AT&T 3B1. See http://www.faqs.org/faqs/3b1-faq/ or any
12978 @c mirror of the 3B1 FAQ. It's actually SVR2.2.
12979 Modern practice is for all diagnostics to go to standard error, but
12980 traditional @samp{ls foo} prints the message @samp{foo not found} to
12981 standard output if @file{foo} does not exist. Be careful when writing
12982 shell commands like @samp{sources=`ls *.c 2>/dev/null`}, since with
12983 traditional @command{ls} this is equivalent to @samp{sources="*.c not
12984 found"} if there are no @samp{.c} files.
12987 @item @command{mkdir}
12988 @c ------------------
12989 @prindex @command{mkdir}
12990 @cindex Making directories
12991 None of @command{mkdir}'s options are portable to older systems. Instead of
12992 @samp{mkdir -p @var{file-name}}, you should use use
12993 @code{AS_MKDIR_P(@var{file-name})} (@pxref{Programming in M4sh}).
12995 Posix does not clearly specify whether @samp{mkdir -p foo}
12996 should succeed when @file{foo} is a symbolic link to an already-existing
12997 directory. The @acronym{GNU} Core Utilities 5.1.0 @command{mkdir}
12998 succeeds, but Solaris @command{mkdir} fails.
13000 Not all @code{mkdir -p} implementations are thread-safe. When it is not
13001 and you call @code{mkdir -p a/b} and @code{mkdir -p a/c} at the same
13002 time, both will detect that @file{a/} is missing, one will create
13003 @file{a/}, then the other will try to create @file{a/} and die with a
13004 @code{File exists} error. At least Solaris 10, Net@acronym{BSD} 1.6, and Open@acronym{BSD}
13005 3.4 have an unsafe @code{mkdir -p}. The @acronym{GNU} Core Utilities
13006 (since @samp{fileutils}
13007 version 4.0c), Free@acronym{BSD} 5.0, and Net@acronym{BSD}-current are
13009 race-free @code{mkdir -p}. This possible race is harmful in parallel
13010 builds when several @file{Makefile} rules call @code{mkdir -p} to
13011 construct directories. You may use @command{mkinstalldirs} or
13012 @code{install-sh -d} as a safe replacement, provided these scripts are
13013 recent enough (the copies shipped with Automake 1.8.3 are OK, those from
13014 older versions are not thread-safe either).
13017 @item @command{mktemp}
13018 @c -------------------
13019 @prindex @command{mktemp}
13020 @cindex Creating temporary files
13021 Shell scripts can use temporary files safely with @command{mktemp}, but
13022 it does not exist on all systems. A portable way to create a safe
13023 temporary file name is to create a temporary directory with mode 700 and
13024 use a file inside this directory. Both methods prevent attackers from
13025 gaining control, though @command{mktemp} is far less likely to fail
13026 gratuitously under attack.
13028 Here is sample code to create a new temporary directory safely:
13031 # Create a temporary directory $tmp in $TMPDIR (default /tmp).
13032 # Use mktemp if possible; otherwise fall back on mkdir,
13033 # with $RANDOM to make collisions less likely.
13037 (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
13039 test -n "$tmp" && test -d "$tmp"
13041 tmp=$TMPDIR/foo$$-$RANDOM
13042 (umask 077 && mkdir "$tmp")
13049 @prindex @command{mv}
13050 @cindex Moving open files
13051 The only portable options are @option{-f} and @option{-i}.
13053 Moving individual files between file systems is portable (it was in Unix
13055 but it is not always atomic: when doing @samp{mv new existing}, there's
13056 a critical section where neither the old nor the new version of
13057 @file{existing} actually exists.
13059 On some systems moving files from @file{/tmp} can sometimes cause
13060 undesirable (but perfectly valid) warnings, even if you created these
13061 files. This is because @file{/tmp} belongs to a group that ordinary
13062 users are not members of, and files created in @file{/tmp} inherit
13063 @file{/tmp}'s group. When the file is copied, @command{mv} issues
13064 a diagnostic without failing:
13067 $ @kbd{touch /tmp/foo}
13068 $ @kbd{mv /tmp/foo .}
13069 @error{}mv: ./foo: set owner/group (was: 100/0): Operation not permitted
13077 This annoying behavior conforms to Posix, unfortunately.
13079 Moving directories across mount points is not portable, use @command{cp}
13082 Moving/Deleting open files isn't portable. The following can't be done
13083 on @acronym{DOS} variants:
13098 @item @command{sed}
13099 @c ----------------
13100 @prindex @command{sed}
13101 Patterns should not include the separator (unless escaped), even as part
13102 of a character class. In conformance with Posix, the Cray
13103 @command{sed} will reject @samp{s/[^/]*$//}: use @samp{s,[^/]*$,,}.
13105 Avoid empty patterns within parentheses (i.e., @samp{\(\)}). Posix does
13106 not require support for empty patterns, and Unicos 9 @command{sed} rejects
13109 Unicos 9 @command{sed} loops endlessly on patterns like @samp{.*\n.*}.
13111 Sed scripts should not use branch labels longer than 8 characters and
13112 should not contain comments. HP-UX sed has a limit of 99 commands and
13113 48 labels, which can not be circumvented by using more than one script
13114 file. It can execute up to 19 reads with the @samp{r} command per cycle.
13116 Avoid redundant @samp{;}, as some @command{sed} implementations, such as
13117 Net@acronym{BSD} 1.4.2's, incorrectly try to interpret the second
13118 @samp{;} as a command:
13121 $ @kbd{echo a | sed 's/x/x/;;s/x/x/'}
13122 sed: 1: "s/x/x/;;s/x/x/": invalid command code ;
13125 Input should not have unreasonably long lines, since some @command{sed}
13126 implementations have an input buffer limited to 4000 bytes.
13128 Portable @command{sed} regular expressions should use @samp{\} only to escape
13129 characters in the string @samp{$()*.0123456789[\^n@{@}}. For example,
13130 alternation, @samp{\|}, is common but Posix does not require its
13131 support, so it should be avoided in portable scripts. Solaris
13132 @command{sed} does not support alternation; e.g., @samp{sed '/a\|b/d'}
13133 deletes only lines that contain the literal string @samp{a|b}.
13134 Similarly, @samp{\+} and @samp{\?} should be avoided.
13136 Anchors (@samp{^} and @samp{$}) inside groups are not portable.
13138 Nested parenthesization in patterns (e.g., @samp{\(\(a*\)b*)\)}) is
13139 quite portable to modern hosts, but is not supported by some older
13140 @command{sed} implementations like SVR3.
13142 Some @command{sed} implementations, e.g., Solaris,
13143 restrict the special role of the asterisk to one-character regular expressions.
13144 This may lead to unexpected behavior:
13147 $ @kbd{echo '1*23*4' | /usr/bin/sed 's/\(.\)*/x/g'}
13149 $ @kbd{echo '1*23*4' | /usr/xpg4/bin/sed 's/\(.\)*/x/g'}
13153 The @option{-e} option is portable.
13154 Some people prefer to use it:
13157 sed -e '@var{command-1}' \
13158 -e '@var{command-2}'
13162 as opposed to the equivalent:
13172 The following usage is sometimes equivalent:
13175 sed '@var{command-1};@var{command-2}'
13178 but Posix says that this use of a semicolon has undefined effect if
13179 @var{command-1}'s verb is @samp{@{}, @samp{a}, @samp{b}, @samp{c},
13180 @samp{i}, @samp{r}, @samp{t}, @samp{w}, @samp{:}, or @samp{#}, so you
13181 should use semicolon only with simple scripts that do not use these
13184 Commands inside @{ @} brackets are further restricted. Posix says that
13185 they cannot be preceded by addresses, @samp{!}, or @samp{;}, and that
13186 each command must be followed immediately by a newline, without any
13187 intervening blanks or semicolons. The closing bracket must be alone on
13188 a line, other than white space preceding or following it.
13190 Contrary to yet another urban legend, you may portably use @samp{&} in
13191 the replacement part of the @code{s} command to mean ``what was
13192 matched''. All descendants of Unix version 7 @command{sed}
13194 don't have first hand experience with older @command{sed}s) have
13197 Posix requires that you must not have any white space between
13198 @samp{!} and the following command. It is OK to have blanks between
13199 the address and the @samp{!}. For instance, on Solaris:
13202 $ @kbd{echo "foo" | sed -n '/bar/ ! p'}
13203 @error{}Unrecognized command: /bar/ ! p
13204 $ @kbd{echo "foo" | sed -n '/bar/! p'}
13205 @error{}Unrecognized command: /bar/! p
13206 $ @kbd{echo "foo" | sed -n '/bar/ !p'}
13210 Posix also says that you should not combine @samp{!} and @samp{;}. If
13211 you use @samp{!}, it is best to put it on a command that is delimited by
13212 newlines rather than @samp{;}.
13214 Also note that Posix requires that the @samp{b}, @samp{t}, @samp{r}, and
13215 @samp{w} commands be followed by exactly one space before their argument.
13216 On the other hand, no white space is allowed between @samp{:} and the
13217 subsequent label name.
13219 @item @command{sed} (@samp{t})
13220 @c ---------------------------
13221 @prindex @command{sed} (@samp{t})
13222 Some old systems have @command{sed} that ``forget'' to reset their
13223 @samp{t} flag when starting a new cycle. For instance on @acronym{MIPS
13224 RISC/OS}, and on @sc{irix} 5.3, if you run the following @command{sed}
13225 script (the line numbers are not actual part of the texts):
13228 s/keep me/kept/g # a
13264 Why? When processing line 1, (a) matches, therefore sets the @samp{t}
13265 flag, (b)b jumps to (d), and the output is produced. When processing
13266 line 2, the @samp{t} flag is still set (this is the bug). Command (a)
13267 fails to match, but @command{sed} is not supposed to clear the @samp{t}
13268 flag when a substitution fails. Command (b) sees that the flag is set,
13269 therefore it clears it, and jumps to (d), hence you get @samp{delete me}
13270 instead of @samp{deleted}. When processing line (3), @samp{t} is clear,
13271 (a) matches, so the flag is set, hence (b) clears the flags and jumps.
13272 Finally, since the flag is clear, line 4 is processed properly.
13274 There are two things one should remember about @samp{t} in @command{sed}.
13275 Firstly, always remember that @samp{t} jumps if @emph{some} substitution
13276 succeeded, not only the immediately preceding substitution. Therefore,
13277 always use a fake @samp{t clear} followed by a @samp{:clear} on the next
13278 line, to reset the @samp{t} flag where needed.
13280 Secondly, you cannot rely on @command{sed} to clear the flag at each new
13283 One portable implementation of the script above is:
13294 @item @command{touch}
13295 @c ------------------
13296 @prindex @command{touch}
13297 @cindex timestamp resolution
13298 If you specify the desired timestamp (e.g., with the @option{-r}
13299 option), @command{touch} typically uses the @code{utime} or
13300 @code{utimes} system call, which can result in the same kind of
13301 timestamp truncation problems that @samp{cp -p} has.
13303 On some old @acronym{BSD} systems, @command{touch} or any command that
13304 results in an empty file does not update the timestamps, so use a
13305 command like @command{echo} as a workaround.
13307 @acronym{GNU} @command{touch} 3.16r (and presumably all before that)
13308 fails to work on SunOS 4.1.3 when the empty file is on an
13309 @acronym{NFS}-mounted 4.2 volume.
13314 @node Limitations of Make
13315 @section Limitations of Make
13316 @prindex @command{make}
13317 @cindex Limitations of @command{make}
13319 @command{make} itself suffers a great number of limitations, only a few
13320 of which are listed here. First of all, remember that since commands
13321 are executed by the shell, all its weaknesses are inherited@enddots{}
13326 Posix says that the @samp{$<} construct in makefiles can be
13327 used only in inference rules and in the @samp{.DEFAULT} rule; its
13328 meaning in ordinary rules is unspecified. Solaris @command{make}
13329 for instance will replace it with the empty string. Open@acronym{BSD} (3.0 and
13330 later) @command{make} will diagnose these uses and error out.
13332 @item Command execution
13333 Since 1992 Posix has required that @command{make} must invoke
13334 each command with the equivalent of a @samp{sh -c} subshell. However,
13335 many @command{make} implementations, including @acronym{BSD} make through 2004,
13336 use @samp{sh -e -c} instead, and the @option{-e} option causes the
13337 subshell to exit immediately if a subsidiary simple-command fails. For
13338 example, the command @samp{touch T; rm -f U} will always attempt to
13339 remove @file{U} with Posix make, but incompatible
13340 @command{make} implementations skip the @command{rm} if the
13341 @command{touch} fails. One way to work around this is to reword the
13342 affected simple-commands so that they always succeed, e.g., @samp{touch
13345 @item Leading underscore in macro names
13346 Some @command{make}s don't support leading underscores in macro names,
13347 such as on NEWS-OS 4.2R.
13350 $ @kbd{cat Makefile}
13353 all:; @@echo this is test
13355 Make: Must be a separator on rules line 2. Stop.
13356 $ @kbd{cat Makefile2}
13359 all:; @@echo this is test
13360 $ @kbd{make -f Makefile2}
13364 @item Trailing backslash in macro
13365 @c This has been seen on ia64 hpux 11.20, and on one hppa hpux 10.20,
13366 @c but another hppa hpux 10.20 didn't have it. Bob Proulx
13367 @c <bob@proulx.com> thinks it was in hpux 8.0 too.
13368 On some versions of HP-UX, @command{make} will read multiple newlines
13369 following a backslash, continuing to the next non-empty line. For
13383 shows @code{FOO} equal to @code{one BAR = two}. Other @command{make}s
13384 sensibly let a backslash continue only to the immediately following
13387 @item Escaped newline in comments
13389 According to Posix, @file{Makefile} comments start with @code{#}
13390 and continue until an unescaped newline is reached.
13393 % @kbd{cat Makefile}
13400 % @kbd{make} # GNU make
13405 However in Real World this is not always the case. Some implementations
13406 discards anything from @code{#} up to the end of line, ignoring any
13407 trailing backslash.
13410 % @kbd{pmake} # BSD make
13411 "Makefile", line 3: Need an operator
13412 Fatal errors encountered -- cannot continue
13416 Therefore, if you want to comment out a multi-line definition, prefix each
13417 line with @code{#}, not only the first.
13427 OSF/1 4.0d's @command{make} cannot process @file{Makefile}s with lines
13428 longer than 38912 bytes. It exits with a @code{Line too long}
13429 diagnostic. A later version, Tru64 5.1's @command{make} has been
13430 reported to crash with lines around 20 kB.
13432 @item @code{make macro=value} and sub-@command{make}s.
13434 A command-line variable definition such as @code{foo=bar} overrides any
13435 definition of @code{foo} in the @file{Makefile}. Some @command{make}
13436 implementations (such as @acronym{GNU} @command{make}) will propagate this
13437 override to sub-invocations of @command{make}. Some other implementation
13438 will not pass the substitution along to sub-@command{make}s.
13441 % @kbd{cat Makefile}
13448 % @kbd{make foo=bar} # GNU make 3.79.1
13451 make[1]: Entering directory `/home/adl'
13453 make[1]: Leaving directory `/home/adl'
13454 % @kbd{pmake foo=bar} # BSD make
13460 You have a few possibilities if you do want the @code{foo=bar} override
13461 to propagate to sub-@command{make}s. One is to use the @code{-e}
13462 option, which causes all environment variables to have precedence over
13463 the @file{Makefile} macro definitions, and declare foo as an environment
13467 % @kbd{env foo=bar make -e}
13470 The @code{-e} option is propagated to sub-@command{make}s automatically,
13471 and since the environment is inherited between @command{make}
13472 invocations, the @code{foo} macro will be overridden in
13473 sub-@code{make}s as expected.
13475 This syntax (@code{foo=bar make -e}) is portable only when used
13476 outside of a @file{Makefile}, for instance from a script or from the
13477 command line. When run inside a @command{make} rule, @acronym{GNU}
13478 @command{make} 3.80 and prior versions forget to propagate the
13479 @code{-e} option to sub-@command{make}s.
13481 Moreover, using @code{-e} could have unexpected side-effects if your
13482 environment contains some other macros usually defined by the
13483 Makefile. (See also the note about @code{make -e} and @code{SHELL}
13486 Another way to propagate overrides to sub-@command{make}s is to do it
13487 manually, from your @file{Makefile}:
13493 $(MAKE) foo=$(foo) two
13498 You need to foresee all macros that a user might want to override if
13501 @item The @code{SHELL} macro
13502 @cindex @code{SHELL} and @command{make}
13503 @cindex @command{make} and @code{SHELL}
13505 Posix-compliant @command{make}s internally use the @code{$(SHELL)}
13506 macro to spawn shell processes and execute @file{Makefile} rules. This
13507 is a builtin macro supplied by @command{make}, but it can be modified
13508 from the @file{Makefile} or a command-line argument.
13510 Not all @command{make}s will define this @code{SHELL} macro. OSF/Tru64
13511 @command{make} is an example; this implementation will always use
13512 @code{/bin/sh}. So it's a good idea to always define @code{SHELL} in
13513 your @file{Makefile}s. If you use Autoconf, do
13519 Do not force @code{SHELL = /bin/sh} because that is not correct
13520 everywhere. For instance @acronym{DJGPP} lacks @code{/bin/sh}, and when
13521 its @acronym{GNU} @code{make} port sees such a setting it enters a special
13522 emulation mode where features like pipes and redirections are emulated
13523 on top of DOS's @command{command.com}. Unfortunately this emulation is
13524 incomplete; for instance it does not handle command substitutions.
13525 On @acronym{DJGPP} @code{SHELL} should point to Bash.
13527 Posix-compliant @command{make}s should never acquire the value of
13528 $(SHELL) from the environment, even when @code{make -e} is used
13529 (otherwise, think about what would happen to your rules if
13530 @code{SHELL=/bin/tcsh}).
13532 However not all @command{make} implementations will make this exception.
13533 For instance it's not surprising that OSF/Tru64 @command{make} doesn't
13534 protect @code{SHELL}, since it doesn't use it.
13537 % @kbd{cat Makefile}
13543 % @kbd{env SHELL=/bin/tcsh FOO=bar make -e} # OSF1 V4.0 Make
13546 % @kbd{env SHELL=/bin/tcsh FOO=bar gmake -e} # GNU make
13551 @item Comments in rules
13552 @cindex Comments in @file{Makefile} rules
13553 @cindex @file{Makefile} rules and comments
13555 Never put comments in a rule.
13557 Some @command{make} treat anything starting with a tab as a command for
13558 the current rule, even if the tab is immediately followed by a @code{#}.
13559 The @command{make} from Tru64 Unix V5.1 is one of them. The following
13560 @file{Makefile} will run @code{# foo} through the shell.
13567 @item The @file{obj/} subdirectory.
13568 @cindex @file{obj/}, subdirectory
13569 @cindex @acronym{BSD} @command{make} and @file{obj/}
13571 Never name one of your subdirectories @file{obj/} if you don't like
13574 If an @file{obj/} directory exists, @acronym{BSD} @command{make} will enter it
13575 before reading @file{Makefile}. Hence the @file{Makefile} in the
13576 current directory will not be read.
13579 % @kbd{cat Makefile}
13582 % @kbd{cat obj/Makefile}
13585 % @kbd{make} # GNU make
13588 % @kbd{pmake} # BSD make
13593 @item @code{make -k}
13594 @cindex @code{make -k}
13596 Do not rely on the exit status of @code{make -k}. Some implementations
13597 reflect whether they encountered an error in their exit status; other
13598 implementations always succeed.
13601 % @kbd{cat Makefile}
13604 % @kbd{make -k; echo exit status: $?} # GNU make
13606 make: *** [all] Error 1
13608 % @kbd{pmake -k; echo exit status: $?} # BSD make
13610 *** Error code 1 (continuing)
13615 @cindex @code{VPATH}
13617 There is no @code{VPATH} support specified in Posix. Many
13618 @command{make}s have a form of @code{VPATH} support, but its
13619 implementation is not consistent amongst @command{make}s.
13621 Maybe the best suggestion to give to people who need the @code{VPATH}
13622 feature is to choose a @command{make} implementation and stick to it.
13623 Since the resulting @file{Makefile}s are not portable anyway, better
13624 choose a portable @command{make} (hint, hint).
13626 Here are a couple of known issues with some @code{VPATH}
13631 @item @code{VPATH} and double-colon rules
13632 @cindex @code{VPATH} and double-colon rules
13633 @cindex double-colon rules and @code{VPATH}
13635 Any assignment to @code{VPATH} causes Sun @command{make} to only execute
13636 the first set of double-colon rules. (This comment has been here since
13637 1994 and the context has been lost. It's probably about SunOS 4. If
13638 you can reproduce this, please send us a test case for illustration.)
13640 @item @code{$<} not supported in explicit rules
13641 @cindex explicit rules, @code{$<}, and @code{VPATH}
13642 @cindex @code{$<}, explicit rules, and @code{VPATH}
13643 @cindex @code{VPATH}, explicit rules, and @code{$<}
13645 As said elsewhere, using @code{$<} in explicit rules is not portable.
13646 The prerequisite file must be named explicitly in the rule. If you want
13647 to find the prerequisite via a @code{VPATH} search, you have to code the
13648 whole thing manually. For instance, using the following pattern:
13653 cp `test -f if.c || echo $(VPATH)/`if.c f.c
13656 @item Automatic rule rewriting
13657 @cindex @code{VPATH} and automatic rule rewriting
13658 @cindex automatic rule rewriting and @code{VPATH}
13660 Some @command{make} implementations, such as SunOS 4 @command{make} or
13661 OSF1/Tru64 @command{make}, will search prerequisites in @code{VPATH} and
13662 rewrite all their occurrences in the rule appropriately.
13673 would execute @code{cp ../pkg/src/if.c f.c} if @file{if.c} was
13674 found in @file{../pkg/src}. That sounds great.
13676 However, for the sake of other @command{make} implementations, we can't
13677 rely on this, and we have to search @code{VPATH} manually:
13682 cp `test -f if.c || echo $(VPATH)/`if.c f.c
13686 However the "prerequisite rewriting" still applies here. So if
13687 @file{if.c} is in @file{../pkg/src}, SunOS 4 @command{make} and OSF1/Tru64
13688 @command{make} will execute
13691 @code{cp `test -f ../pkg/src/if.c || echo ../pkg/src/`if.c f.c}
13702 and thus fails. Oops.
13704 One workaround is to make sure that @file{if.c} never appears as a plain word
13705 in the rule. For instance these three rules would be safe.
13710 cp `test -f ./if.c || echo $(VPATH)/`if.c f.c
13712 cp `test -f 'ig.c' || echo $(VPATH)/`ig.c g.c
13714 cp `test -f "ih.c" || echo $(VPATH)/`ih.c h.c
13717 Things get worse when your prerequisites are in a macro.
13721 HEADERS = f.h g.h h.h
13722 install-HEADERS: $(HEADERS)
13723 for i in $(HEADERS); do \
13724 $(INSTALL) -m 644 \
13725 `test -f $$i || echo $(VPATH)/`$$i \
13726 $(DESTDIR)$(includedir)/$$i; \
13730 The above @code{install-HEADERS} rule is not SunOS-4-proof because @code{for
13731 i in $(HEADERS);} will be expanded as @code{for i in f.h g.h h.h;}
13732 where @code{f.h} and @code{g.h} are plain words and are hence
13733 subject to @code{VPATH} adjustments.
13735 If the three files are in @file{../pkg/src}, the rule is run as:
13738 for i in ../pkg/src/f.h ../pkg/src/g.h h.h; do \
13740 `test -f $i || echo ../pkg/src/`$i \
13741 /usr/local/include/$i; \
13745 where the two first @command{install} calls will fail. For instance,
13746 consider the @code{f.h} installation:
13750 `test -f ../pkg/src/f.h || \
13753 /usr/local/include/../pkg/src/f.h;
13761 /usr/local/include/../pkg/src/f.h;
13764 Note that the manual @code{VPATH} search did not cause any problems here;
13765 however this command installs @file{f.h} in an incorrect directory.
13767 Trying to quote @code{$(HEADERS)} in some way, as we did for
13768 @code{foo.c} a few @file{Makefile}s ago, does not help:
13771 install-HEADERS: $(HEADERS)
13772 headers='$(HEADERS)'; \
13773 for i in $$headers; do \
13774 $(INSTALL) -m 644 \
13775 `test -f $$i || echo $(VPATH)/`$$i \
13776 $(DESTDIR)$(includedir)/$$i; \
13780 Now, @code{headers='$(HEADERS)'} macroexpands to:
13783 headers='f.h g.h h.h'
13787 but @code{g.h} is still a plain word. (As an aside, the idiom
13788 @code{headers='$(HEADERS)'; for i in $$headers;} is a good
13789 idea if @code{$(HEADERS)} can be empty, because some shells diagnose a
13790 syntax error on @code{for i in;}.)
13792 One workaround is to strip this unwanted @file{../pkg/src/} prefix manually:
13795 HEADERS = f.h g.h h.h
13796 install-HEADERS: $(HEADERS)
13797 headers='$(HEADERS)'; \
13798 for i in $$headers; do \
13799 i=`expr "$$i" : '$(VPATH)/\(.*\)'`;
13800 $(INSTALL) -m 644 \
13801 `test -f $$i || echo $(VPATH)/`$$i \
13802 $(DESTDIR)$(includedir)/$$i; \
13806 Automake does something similar. However the above hack works only if
13807 the files listed in @code{HEADERS} are in the current directory or a
13808 subdirectory; they should not be in an enclosing directory. If we had
13809 @code{HEADERS = ../f.h}, the above fragment would fail in a VPATH
13810 build with OSF1/Tru64 @command{make}. The reason is that not only does
13811 OSF1/Tru64 @command{make} rewrite dependencies, but it also simplifies
13812 them. Hence @code{../f.h} will become @code{../pkg/f.h} instead of
13813 @code{../pkg/src/../f.h}. This obviously defeats any attempt to strip
13814 a leading @file{../pkg/src/} component.
13816 The following example makes the behavior of OSF1/Tru64 @command{make}
13830 Dependency @file{../foo} was found in @file{sub/../foo}, but OSF1/Tru64
13831 @command{make} simplified it as @file{foo}. (Note that the @file{sub/}
13832 directory does not even exist, this just means that the simplification
13833 occurred before the file was checked for.)
13835 For the record here is how SunOS 4 @command{make} behaves on this
13839 make: Fatal error: Don't know how to make target `../foo'
13847 @item OSF/Tru64 @command{make} creates prerequisite directories magically
13848 @cindex @code{VPATH} and prerequisite directories
13849 @cindex prerequisite directories and @code{VPATH}
13851 When a prerequisite is a sub-directory of @code{VPATH}, Tru64
13852 @command{make} will create it in the current directory.
13855 % @kbd{mkdir -p foo/bar build}
13857 % @kbd{cat >Makefile <<END
13866 This can yield unexpected results if a rule uses a manual @code{VPATH}
13867 search as presented before.
13872 command `test -d foo/bar || echo ../`foo/bar
13875 The above @command{command} will be run on the empty @file{foo/bar}
13876 directory that was created in the current directory.
13878 @item target lookup
13879 @cindex @code{VPATH}, resolving target pathnames
13881 @acronym{GNU} @command{make} uses a rather complex algorithm to decide when it
13882 should use files found via a @code{VPATH} search. @xref{Search
13883 Algorithm, , How Directory Searches are Performed, make, The @acronym{GNU} Make
13886 If a target needs to be rebuilt, @acronym{GNU} @command{make} discards the
13887 file name found during the @code{VPATH} search for this target, and
13888 builds the file locally using the file name given in the @file{Makefile}.
13889 If a target does not need to be rebuilt, @acronym{GNU} @command{make} uses the
13890 file name found during the @code{VPATH} search.
13892 Other @command{make} implementations, like Net@acronym{BSD} @command{make}, are
13893 easier to describe: the file name found during the @code{VPATH} search
13894 will be used whether the target needs to be rebuilt or not. Therefore
13895 new files are created locally, but existing files are updated at their
13896 @code{VPATH} location.
13898 Open@acronym{BSD} and Free@acronym{BSD} @command{make}s, however, will
13900 @code{VPATH} search for a dependency which has an explicit rule.
13901 This is extremely annoying.
13903 When attempting a @code{VPATH} build for an autoconfiscated package
13904 (e.g., @code{mkdir build && cd build && ../configure}), this means the
13906 @command{make} will build everything locally in the @file{build}
13907 directory, while @acronym{BSD} @command{make} will build new files locally and
13908 update existing files in the source directory.
13911 % @kbd{cat Makefile}
13914 foo.x bar.x: newer.x
13915 @@echo Building $@@
13916 % @kbd{touch ../bar.x}
13917 % @kbd{touch ../newer.x}
13918 % @kbd{make} # GNU make
13921 % @kbd{pmake} # NetBSD make
13924 % @kbd{fmake} # FreeBSD make, OpenBSD make
13927 % @kbd{tmake} # Tru64 make
13930 % @kbd{touch ../bar.x}
13931 % @kbd{make} # GNU make
13933 % @kbd{pmake} # NetBSD make
13935 % @kbd{fmake} # FreeBSD make, OpenBSD make
13938 % @kbd{tmake} # Tru64 make
13943 Note how Net@acronym{BSD} @command{make} updates @file{../bar.x} in its
13944 VPATH location, and how Free@acronym{BSD}, Open@acronym{BSD}, and Tru64
13945 @command{make} always
13946 update @file{bar.x}, even when @file{../bar.x} is up to date.
13948 Another point worth mentioning is that once @acronym{GNU} @command{make} has
13949 decided to ignore a @code{VPATH} file name (e.g., it ignored
13950 @file{../bar.x} in the above example) it will continue to ignore it when
13951 the target occurs as a prerequisite of another rule.
13953 The following example shows that @acronym{GNU} @command{make} does not look up
13954 @file{bar.x} in @code{VPATH} before performing the @code{.x.y} rule,
13955 because it ignored the @code{VPATH} result of @file{bar.x} while running
13956 the @code{bar.x: newer.x} rule.
13959 % @kbd{cat Makefile}
13963 @@echo Building $@@
13967 % @kbd{touch ../bar.x}
13968 % @kbd{touch ../newer.x}
13969 % @kbd{make} # GNU make
13972 cp: cannot stat `bar.x': No such file or directory
13973 make: *** [bar.y] Error 1
13974 % @kbd{pmake} # NetBSD make
13978 % @kbd{fmake} # FreeBSD make, OpenBSD make
13979 echo Building bar.x
13981 cp: cannot stat `bar.x': No such file or directory
13983 % @kbd{tmake} # Tru64 make
13985 cp: bar.x: No such file or directory
13989 Note that if you drop away the command from the @code{bar.x: newer.x}
13990 rule, @acronym{GNU} @command{make} will magically start to work: it
13991 knows that @code{bar.x} hasn't been updated, therefore it doesn't
13992 discard the result from @code{VPATH} (@file{../bar.x}) in succeeding
13993 uses. Tru64 will also work, but Free@acronym{BSD} and Open@acronym{BSD}
13997 % @kbd{cat Makefile}
14004 % @kbd{touch ../bar.x}
14005 % @kbd{touch ../newer.x}
14006 % @kbd{make} # GNU make
14009 % @kbd{pmake} # NetBSD make
14012 % @kbd{fmake} # FreeBSD make, OpenBSD make
14014 cp: cannot stat `bar.x': No such file or directory
14016 % @kbd{tmake} # Tru64 make
14020 It seems the sole solution that would please every @command{make}
14021 implementation is to never rely on @code{VPATH} searches for targets.
14022 In other words, @code{VPATH} should be reserved to unbuilt sources.
14025 @c end item about VPATH
14027 @item Single Suffix Rules and Separated Dependencies
14028 @cindex Single Suffix Inference Rule
14029 @cindex Rule, Single Suffix Inference
14030 A @dfn{Single Suffix Rule} is basically a usual suffix (inference) rule
14031 (@samp{.from.to:}), but which @emph{destination} suffix is empty
14034 @cindex Separated Dependencies
14035 @dfn{Separated dependencies} simply refers to listing the prerequisite
14036 of a target, without defining a rule. Usually one can list on the one
14037 hand side, the rules, and on the other hand side, the dependencies.
14039 Solaris @command{make} does not support separated dependencies for
14040 targets defined by single suffix rules:
14043 $ @kbd{cat Makefile}
14048 $ @kbd{touch foo.in}
14055 while @acronym{GNU} Make does:
14061 Makefile foo foo.in
14064 Note it works without the @samp{foo: foo.in} dependency.
14067 $ @kbd{cat Makefile}
14076 and it works with double suffix inference rules:
14079 $ @kbd{cat Makefile}
14081 .SUFFIXES: .in .out
14088 As a result, in such a case, you have to write target rules.
14090 @item Timestamp Resolution
14091 @cindex timestamp resolution
14092 Traditionally, file timestamps had 1-second resolution, and
14093 @command{make} used those timestamps to determine whether one file was
14094 newer than the other. However, many modern file systems have
14095 timestamps with 1-nanosecond resolution. Some @command{make}
14096 implementations look at the entire timestamp; others ignore the
14097 fractional part, which can lead to incorrect results. Normally this
14098 is not a problem, but in some extreme cases you may need to use tricks
14099 like @samp{sleep 1} to work around timestamp truncation bugs.
14101 Commands like @samp{cp -p} and @samp{touch -r} typically do not copy
14102 file timestamps to their full resolutions (@pxref{Limitations of Usual
14103 Tools}). Hence you should be wary of rules like this:
14110 as @file{dest} will often appear to be older than @file{src} after the
14111 timestamp is truncated, and this can cause @command{make} to do
14112 needless rework the next time it is invoked. To work around this
14113 problem, you can use a timestamp file, e.g.:
14126 @c ======================================== Portable C and C++ Programming
14128 @node Portable C and C++
14129 @chapter Portable C and C++ Programming
14130 @cindex Portable C and C++ programming
14132 C and C++ programs often use low-level features of the underlying
14133 system, and therefore are often more difficult to make portable to other
14136 Several standards have been developed to help make your programs more
14137 portable. If you write programs with these standards in mind, you can
14138 have greater confidence that your programs will work on a wide variety
14139 of systems. @xref{Standards, , Language Standards Supported by GCC,
14140 gcc, Using the GNU Compiler Collection (GCC)}, for a list of C-related
14141 standards. Many programs also assume the
14142 @uref{http://www.opengroup.org/susv3, Posix standard}.
14144 Some old code is written to be portable to K&R C, which predates any C
14145 standard. K&R C compilers are no longer of practical interest, though,
14146 and the rest of section assumes at least C89, the first C standard.
14148 Program portability is a huge topic, and this section can only briefly
14149 introduce common pitfalls. @xref{System Portability, , Portability
14150 between System Types, standards, @acronym{GNU} Coding Standards}, for
14154 * Varieties of Unportability:: How to make your programs unportable
14155 * Integer Overflow:: When integers get too large
14156 * Null Pointers:: Properties of null pointers
14157 * Buffer Overruns:: Subscript errors and the like
14158 * Floating Point Portability:: Portable floating-point arithmetic
14159 * Exiting Portably:: Exiting and the exit status
14162 @node Varieties of Unportability
14163 @section Varieties of Unportability
14164 @cindex portability
14166 Autoconf tests and ordinary programs often need to test what is allowed
14167 on a system, and therefore they may need to deliberately exceed the
14168 boundaries of what the standards allow, if only to see whether an
14169 optional feature is present. When you write such a program, you should
14170 keep in mind the difference between constraints, unspecified behavior,
14171 and undefined behavior.
14173 In C, a @dfn{constraint} is a rule that the compiler must enforce. An
14174 example constraint is that C programs must not declare a bit-field with
14175 negative width. Tests can therefore reliably assume that programs with
14176 negative-width bit-fields will be rejected by a compiler that conforms
14179 @dfn{Unspecified behavior} is valid behavior, where the standard allows
14180 multiple possibilities. For example, the order of evaluation of
14181 function arguments is unspecified. Some unspecified behavior is
14182 @dfn{implementation-defined}, i.e., documented by the implementation,
14183 but since Autoconf tests cannot read the documentation they cannot
14184 distinguish between implementation-defined and other unspecified
14185 behavior. It is common for Autoconf tests to probe implementations to
14186 determine otherwise-unspecified behavior.
14188 @dfn{Undefined behavior} is invalid behavior, where the standard allows
14189 the implementation to do anything it pleases. For example,
14190 dereferencing a null pointer leads to undefined behavior. If possible,
14191 test programs should avoid undefined behavior, since a program with
14192 undefined behavior might succeed on a test that should fail.
14194 The above rules apply to programs that are intended to conform to the
14195 standard. However, strictly-conforming programs are quite rare, since
14196 the standards are so limiting. A major goal of Autoconf is to support
14197 programs that use implementation features not described by the standard,
14198 and it is fairly common for test programs to violate the above rules, if
14199 the programs work well enough in practice.
14201 @node Integer Overflow
14202 @section Integer Overflow
14203 @cindex overflow, arithmetic
14205 In C, signed integer overflow leads to undefined behavior. However,
14206 many programs and Autoconf tests assume that integer overflow silently
14207 wraps around modulo a power of 2 so long as you cast the resulting value
14208 to an integer type or store it into an integer variable. Such programs
14209 are portable to the vast majority of modern platforms. C99 has a way of
14210 specifying this portability (the LIA-1 option) but this is not
14211 universally supported yet. GCC users might consider using the
14212 @option{-ftrapv} option if they are worried about porting their code to
14213 the rare platforms where overflow does not wrap around.
14215 In contrast, unsigned integer overflow reliably wraps around modulo the
14218 @node Null Pointers
14219 @section Properties of Null Pointers
14220 @cindex null pointers
14222 Most modern hosts reliably fail when you attempt to dereference a null
14225 On almost all modern hosts, null pointers use an all-bits-zero internal
14226 representation, so you can reliably use @code{memset} with 0 to set all
14227 the pointers in an array to null values.
14229 If @code{p} is a null pointer to an object type, the C expression
14230 @code{p + 0} always evaluates to @code{p} on modern hosts, even though
14231 the standard says that it has undefined behavior.
14233 @node Buffer Overruns
14234 @section Buffer Overruns and Subscript Errors
14235 @cindex buffer overruns
14237 Buffer overruns and subscript errors are the most common dangerous
14238 errors in C programs. They result in undefined behavior because storing
14239 outside an array typically modifies storage that is used by some other
14240 object, and most modern systems lack runtime checks to catch these
14241 errors. Programs should not rely on buffer overruns being caught.
14243 There is one exception to the usual rule that a portable program cannot
14244 address outside an array. In C, it is valid to compute the address just
14245 past an object, e.g., @code{&a[N]} where @code{a} has @code{N} elements,
14246 so long as you do not dereference the resulting pointer. But it is not
14247 valid to compute the address just before an object, e.g., @code{&a[-1]};
14248 nor is it valid to compute two past the end, e.g., @code{&a[N+1]}. On
14249 most platforms @code{&a[-1] < &a[0] && &a[N] < &a[N+1]}, but this is not
14250 reliable in general, and it is usually easy enough to avoid the
14251 potential portability problem, e.g., by allocating an extra unused array
14252 element at the start or end.
14254 @uref{http://valgrind.org/, Valgrind} can catch many overruns. GCC
14255 users might also consider using the @option{-fmudflap} option to catch
14258 Buffer overruns are usually caused by off-by-one errors, but there are
14259 more subtle ways to get them.
14261 Using @code{int} values to index into an array or compute array sizes
14262 will cause problems on typical 64-bit hosts where an array index might
14263 be @math{2^31} or larger.
14265 If you add or multiply two numbers to calculate an array size, e.g.,
14266 @code{malloc (x * sizeof y + z)}, havoc will ensue if the addition or
14267 multiplication overflows.
14269 Many implementations of the @code{alloca} function silently misbehave
14270 and can generate buffer overflows if given sizes that are too large.
14271 The size limits are implementation dependent, but are at least 4000
14272 bytes on all platforms that we know about.
14274 The standard functions @code{asctime}, @code{asctime_r}, @code{ctime},
14275 @code{ctime_r}, and @code{gets} are prone to buffer overflows, and
14276 portable code should not use them unless the inputs are known to be
14277 within certain limits. The time-related functions can overflow their
14278 buffers if given time stamps out of range (e.g., a year less than -999
14279 or greater than 9999). Time-related buffer overflows cannot happen with
14280 recent-enough versions of the GNU C library, but are possible with other
14281 implementations. The @code{gets} function is the worst, since it almost
14282 invariably overflows its buffer when presented with an input line larger
14285 @node Floating Point Portability
14286 @section Floating Point Portability
14287 @cindex floating point
14289 Almost all modern systems use IEEE-754 floating point, and it is safe to
14290 assume IEEE-754 in most portable code these days. For more information,
14291 please see David Goldberg's classic paper
14292 @uref{http://www.validlab.com/goldberg/paper.pdf, What Every Computer
14293 Scientist Should Know About Floating-Point Arithmetic}.
14295 @node Exiting Portably
14296 @section Exiting Portably
14297 @cindex exiting portably
14299 A C or C++ program can exit with status @var{N} by returning
14300 @var{N} from the @code{main} function. Portable programs are supposed
14301 to exit either with status 0 or @code{EXIT_SUCCESS} to succeed, or with
14302 status @code{EXIT_FAILURE} to fail, but in practice it is portable to
14303 fail by exiting with status 1, and test programs that assume Posix can
14304 fail by exiting with status values from 1 through 255. Programs on
14305 SunOS 2.0 (1985) through 3.5.2 (1988) incorrectly exited with zero
14306 status when @code{main} returned nonzero, but ancient systems like these
14307 are no longer of practical concern.
14309 A program can also exit with status @var{N} by passing @var{N} to the
14310 @code{exit} function, and a program can fail by calling the @code{abort}
14311 function. If a program is specialized to just some platforms, it can fail
14312 by calling functions specific to those platforms, e.g., @code{_exit}
14313 (Posix) and @code{_Exit} (C99). However, like other functions, an exit
14314 function should be declared, typically by including a header. For
14315 example, if a C program calls @code{exit}, it should include @file{stdlib.h}
14316 either directly or via the default includes (@pxref{Default Includes}).
14318 A program can fail due to undefined behavior such as dereferencing a null
14319 pointer, but this is not recommended as undefined behavior allows an
14320 implementation to do whatever it pleases and this includes exiting
14324 @c ================================================== Manual Configuration
14326 @node Manual Configuration
14327 @chapter Manual Configuration
14329 A few kinds of features can't be guessed automatically by running test
14330 programs. For example, the details of the object-file format, or
14331 special options that need to be passed to the compiler or linker. You
14332 can check for such features using ad-hoc means, such as having
14333 @command{configure} check the output of the @code{uname} program, or
14334 looking for libraries that are unique to particular systems. However,
14335 Autoconf provides a uniform method for handling unguessable features.
14338 * Specifying Names:: Specifying the system type
14339 * Canonicalizing:: Getting the canonical system type
14340 * Using System Type:: What to do with the system type
14343 @node Specifying Names
14344 @section Specifying the System Type
14345 @cindex System type
14347 Like other @acronym{GNU} @command{configure} scripts, Autoconf-generated
14348 @command{configure} scripts can make decisions based on a canonical name
14349 for the system type, which has the form:
14350 @samp{@var{cpu}-@var{vendor}-@var{os}}, where @var{os} can be
14351 @samp{@var{system}} or @samp{@var{kernel}-@var{system}}
14353 @command{configure} can usually guess the canonical name for the type of
14354 system it's running on. To do so it runs a script called
14355 @command{config.guess}, which infers the name using the @code{uname}
14356 command or symbols predefined by the C preprocessor.
14358 Alternately, the user can specify the system type with command line
14359 arguments to @command{configure}. Doing so is necessary when
14360 cross-compiling. In the most complex case of cross-compiling, three
14361 system types are involved. The options to specify them are:
14364 @item --build=@var{build-type}
14365 the type of system on which the package is being configured and
14366 compiled. It defaults to the result of running @command{config.guess}.
14368 @item --host=@var{host-type}
14369 the type of system on which the package will run. By default it is the
14370 same as the build machine. Specifying it enables the cross-compilation
14373 @item --target=@var{target-type}
14374 the type of system for which any compiler tools in the package will
14375 produce code (rarely needed). By default, it is the same as host.
14378 If you mean to override the result of @command{config.guess}, use
14379 @option{--build}, not @option{--host}, since the latter enables
14380 cross-compilation. For historical reasons, passing @option{--host} also
14381 changes the build type. Therefore, whenever you specify @code{--host},
14382 be sure to specify @code{--build} too; this will be fixed in the
14383 future. So, to enter cross-compilation mode, use a command like this
14386 ./configure --build=i686-pc-linux-gnu --host=m68k-coff
14390 Note that if you do not specify @option{--host}, @command{configure} will
14391 fail if it can't run the code generated by the specified compiler. For
14392 example, configuring as follows will fail:
14395 ./configure CC=m68k-coff-gcc
14398 In the future, when cross-compiling Autoconf will @emph{not}
14399 accept tools (compilers, linkers, assemblers) whose name is not
14400 prefixed with the host type. The only case when this may be
14401 useful is when you really are not cross-compiling, but only
14402 building for a least-common-denominator architecture: an example
14403 is building for @code{i386-pc-linux-gnu} while running on an
14404 @code{i686-pc-linux-gnu} architecture. In this case, some particular
14405 pairs might be similar enough to let you get away with the system
14406 compilers, but in general the compiler might make bogus assumptions
14407 on the host: if you know what you are doing, please create symbolic
14408 links from the host compiler to the build compiler.
14410 @cindex @command{config.sub}
14411 @command{configure} recognizes short aliases for many system types; for
14412 example, @samp{decstation} can be used instead of
14413 @samp{mips-dec-ultrix4.2}. @command{configure} runs a script called
14414 @command{config.sub} to canonicalize system type aliases.
14416 This section deliberately omits the description of the obsolete
14417 interface; see @ref{Hosts and Cross-Compilation}.
14420 @node Canonicalizing
14421 @section Getting the Canonical System Type
14422 @cindex System type
14423 @cindex Canonical system type
14425 The following macros make the system type available to @command{configure}
14428 @ovindex build_alias
14429 @ovindex host_alias
14430 @ovindex target_alias
14432 The variables @samp{build_alias}, @samp{host_alias}, and
14433 @samp{target_alias} are always exactly the arguments of @option{--build},
14434 @option{--host}, and @option{--target}; in particular, they are left empty
14435 if the user did not use them, even if the corresponding
14436 @code{AC_CANONICAL} macro was run. Any configure script may use these
14437 variables anywhere. These are the variables that should be used when in
14438 interaction with the user.
14440 If you need to recognize some special environments based on their system
14441 type, run the following macros to get canonical system names. These
14442 variables are not set before the macro call.
14444 If you use these macros, you must distribute @command{config.guess} and
14445 @command{config.sub} along with your source code. @xref{Output}, for
14446 information about the @code{AC_CONFIG_AUX_DIR} macro which you can use
14447 to control in which directory @command{configure} looks for those scripts.
14450 @defmac AC_CANONICAL_BUILD
14451 @acindex{CANONICAL_BUILD}
14454 @ovindex build_vendor
14456 Compute the canonical build-system type variable, @code{build}, and its
14457 three individual parts @code{build_cpu}, @code{build_vendor}, and
14460 If @option{--build} was specified, then @code{build} is the
14461 canonicalization of @code{build_alias} by @command{config.sub},
14462 otherwise it is determined by the shell script @command{config.guess}.
14465 @defmac AC_CANONICAL_HOST
14466 @acindex{CANONICAL_HOST}
14469 @ovindex host_vendor
14471 Compute the canonical host-system type variable, @code{host}, and its
14472 three individual parts @code{host_cpu}, @code{host_vendor}, and
14475 If @option{--host} was specified, then @code{host} is the
14476 canonicalization of @code{host_alias} by @command{config.sub},
14477 otherwise it defaults to @code{build}.
14480 @defmac AC_CANONICAL_TARGET
14481 @acindex{CANONICAL_TARGET}
14483 @ovindex target_cpu
14484 @ovindex target_vendor
14486 Compute the canonical target-system type variable, @code{target}, and its
14487 three individual parts @code{target_cpu}, @code{target_vendor}, and
14490 If @option{--target} was specified, then @code{target} is the
14491 canonicalization of @code{target_alias} by @command{config.sub},
14492 otherwise it defaults to @code{host}.
14495 Note that there can be artifacts due to the backward compatibility
14496 code. See @xref{Hosts and Cross-Compilation}, for more.
14498 @node Using System Type
14499 @section Using the System Type
14501 In @file{configure.ac} the system type is generally used by one or more
14502 @code{case} statements to select system-specifics. Shell wildcards can
14503 be used to match a group of system types.
14505 For example, an extra assembler code object file could be chosen, giving
14506 access to a CPU cycle counter register. @code{$(CYCLE_OBJ)} in the
14507 following would be used in a @file{Makefile} to add the object to a
14508 program or library.
14512 alpha*-*-*) CYCLE_OBJ=rpcc.o ;;
14513 i?86-*-*) CYCLE_OBJ=rdtsc.o ;;
14516 AC_SUBST([CYCLE_OBJ])
14519 @code{AC_CONFIG_LINKS} (@pxref{Configuration Links}) is another good way
14520 to select variant source files, for example optimized code for some
14521 CPUs. The configured CPU type doesn't always indicate exact CPU types,
14522 so some runtime capability checks may be necessary too.
14526 alpha*-*-*) AC_CONFIG_LINKS([dither.c:alpha/dither.c]) ;;
14527 powerpc*-*-*) AC_CONFIG_LINKS([dither.c:powerpc/dither.c]) ;;
14528 *-*-*) AC_CONFIG_LINKS([dither.c:generic/dither.c]) ;;
14532 The host system type can also be used to find cross-compilation tools
14533 with @code{AC_CHECK_TOOL} (@pxref{Generic Programs}).
14535 The above examples all show @samp{$host}, since this is where the code
14536 is going to run. Only rarely is it necessary to test @samp{$build}
14537 (which is where the build is being done).
14539 Whenever you're tempted to use @samp{$host} it's worth considering
14540 whether some sort of probe would be better. New system types come along
14541 periodically or previously missing features are added. Well-written
14542 probes can adapt themselves to such things, but hard-coded lists of
14543 names won't. Here are some guidelines,
14547 Availability of libraries and library functions should always be checked
14550 Variant behavior of system calls is best identified with runtime tests
14551 if possible, but bug workarounds or obscure difficulties might have to
14552 be driven from @samp{$host}.
14554 Assembler code is inevitably highly CPU-specific and is best selected
14555 according to @samp{$host_cpu}.
14557 Assembler variations like underscore prefix on globals or ELF versus
14558 COFF type directives are however best determined by probing, perhaps
14559 even examining the compiler output.
14562 @samp{$target} is for use by a package creating a compiler or similar.
14563 For ordinary packages it's meaningless and should not be used. It
14564 indicates what the created compiler should generate code for, if it can
14565 cross-compile. @samp{$target} generally selects various hard-coded CPU
14566 and system conventions, since usually the compiler or tools under
14567 construction will themselves determine how the target will work.
14570 @c ===================================================== Site Configuration.
14572 @node Site Configuration
14573 @chapter Site Configuration
14575 @command{configure} scripts support several kinds of local configuration
14576 decisions. There are ways for users to specify where external software
14577 packages are, include or exclude optional features, install programs
14578 under modified names, and set default values for @command{configure}
14582 * Help Formatting:: Customizing @samp{configure --help}
14583 * External Software:: Working with other optional software
14584 * Package Options:: Selecting optional features
14585 * Pretty Help Strings:: Formatting help string
14586 * Site Details:: Configuring site details
14587 * Transforming Names:: Changing program names when installing
14588 * Site Defaults:: Giving @command{configure} local defaults
14591 @node Help Formatting
14592 @section Controlling Help Output
14594 Users will consult @samp{configure --help} to learn of configuration
14595 decisions specific to your package. By default, @command{configure}
14596 breaks this output into sections for each type of option; within each
14597 section, help strings appear in the order @file{configure.ac} defines
14603 --enable-bar include bar
14610 @defmac AC_PRESERVE_HELP_ORDER
14611 @acindex{PRESERVE_HELP_ORDER}
14613 Request an alternate @option{--help} format, in which options of all
14614 types appear together, in the order defined. Call this macro before any
14615 @code{AC_ARG_ENABLE} or @code{AC_ARG_WITH}.
14618 Optional Features and Packages:
14620 --enable-bar include bar
14626 @node External Software
14627 @section Working With External Software
14628 @cindex External software
14630 Some packages require, or can optionally use, other software packages
14631 that are already installed. The user can give @command{configure}
14632 command line options to specify which such external software to use.
14633 The options have one of these forms:
14635 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
14638 --with-@var{package}[=@var{arg}]
14639 --without-@var{package}
14642 For example, @option{--with-gnu-ld} means work with the @acronym{GNU} linker
14643 instead of some other linker. @option{--with-x} means work with The X
14646 The user can give an argument by following the package name with
14647 @samp{=} and the argument. Giving an argument of @samp{no} is for
14648 packages that are used by default; it says to @emph{not} use the
14649 package. An argument that is neither @samp{yes} nor @samp{no} could
14650 include a name or number of a version of the other package, to specify
14651 more precisely which other package this program is supposed to work
14652 with. If no argument is given, it defaults to @samp{yes}.
14653 @option{--without-@var{package}} is equivalent to
14654 @option{--with-@var{package}=no}.
14656 @command{configure} scripts do not complain about
14657 @option{--with-@var{package}} options that they do not support. This
14658 behavior permits configuring a source tree containing multiple packages
14659 with a top-level @command{configure} script when the packages support
14660 different options, without spurious error messages about options that
14661 some of the packages support. An unfortunate side effect is that option
14662 spelling errors are not diagnosed. No better approach to this problem
14663 has been suggested so far.
14665 For each external software package that may be used, @file{configure.ac}
14666 should call @code{AC_ARG_WITH} to detect whether the @command{configure}
14667 user asked to use it. Whether each package is used or not by default,
14668 and which arguments are valid, is up to you.
14670 @defmac AC_ARG_WITH (@var{package}, @var{help-string}, @ovar{action-if-given}, @ovar{action-if-not-given})
14672 If the user gave @command{configure} the option @option{--with-@var{package}}
14673 or @option{--without-@var{package}}, run shell commands
14674 @var{action-if-given}. If neither option was given, run shell commands
14675 @var{action-if-not-given}. The name @var{package} indicates another
14676 software package that this program should work with. It should consist
14677 only of alphanumeric characters and dashes.
14679 The option's argument is available to the shell commands
14680 @var{action-if-given} in the shell variable @code{withval}, which is
14681 actually just the value of the shell variable @code{with_@var{package}},
14682 with any @option{-} characters changed into @samp{_}. You may use that
14683 variable instead, if you wish.
14685 The argument @var{help-string} is a description of the option that
14688 --with-readline support fancy command line editing
14692 @var{help-string} may be more than one line long, if more detail is
14693 needed. Just make sure the columns line up in @samp{configure
14694 --help}. Avoid tabs in the help string. You'll need to enclose the
14695 help string in @samp{[} and @samp{]} in order to produce the leading
14698 You should format your @var{help-string} with the macro
14699 @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
14701 The following example shows how to use the @code{AC_ARG_WITH} macro in
14702 a common situation. You want to let the user decide whether to enable
14703 support for an external library (e.g., the readline library); if the user
14704 specified neither @option{--with-readline} nor @option{--without-readline},
14705 you want to enable support for readline only if the library is available
14708 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
14710 AC_ARG_WITH([readline],
14711 [AS_HELP_STRING([--with-readline],
14712 [support fancy command line editing @@<:@@default=check@@:>@@])],
14714 [with_readline=check])
14717 AS_IF([test "x$with_readline" != xno],
14718 [AC_CHECK_LIB([readline], [main],
14719 [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
14720 AC_DEFINE([HAVE_LIBREADLINE], [1],
14721 [Define if you have libreadline])
14723 [if test "x$with_readline" != xcheck; then
14725 [--with-readline was given, but test for readline failed])
14730 The next example shows how to use @code{AC_ARG_WITH} to give the user the
14731 possibility to enable support for the readline library, in case it is still
14732 experimental and not well tested, and is therefore disabled by default.
14734 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
14736 AC_ARG_WITH([readline],
14737 [AS_HELP_STRING([--with-readline],
14738 [enable experimental support for readline])],
14740 [with_readline=no])
14743 AS_IF([test "x$with_readline" != xno],
14744 [AC_CHECK_LIB([readline], [main],
14745 [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
14746 AC_DEFINE([HAVE_LIBREADLINE], [1],
14747 [Define if you have libreadline])
14750 [--with-readline was given, but test for readline failed])],
14754 The last example shows how to use @code{AC_ARG_WITH} to give the user the
14755 possibility to disable support for the readline library, given that it is
14756 an important feature and that it should be enabled by default.
14758 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
14760 AC_ARG_WITH([readline],
14761 [AS_HELP_STRING([--without-readline],
14762 [disable support for readline])],
14764 [with_readline=yes])
14767 AS_IF([test "x$with_readline" != xno],
14768 [AC_CHECK_LIB([readline], [main],
14769 [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
14770 AC_DEFINE([HAVE_LIBREADLINE], [1],
14771 [Define if you have libreadline])
14774 [readline test failed (--without-readline to disable)])],
14778 These three examples can be easily adapted to the case where
14779 @code{AC_ARG_ENABLE} should be preferred to @code{AC_ARG_WITH} (see
14780 @ref{Package Options}).
14783 @defmac AC_WITH (@var{package}, @var{action-if-given}, @ovar{action-if-not-given})
14785 This is an obsolete version of @code{AC_ARG_WITH} that does not
14786 support providing a help string.
14789 @node Package Options
14790 @section Choosing Package Options
14791 @cindex Package options
14792 @cindex Options, package
14794 If a software package has optional compile-time features, the user can
14795 give @command{configure} command line options to specify whether to
14796 compile them. The options have one of these forms:
14798 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
14801 --enable-@var{feature}[=@var{arg}]
14802 --disable-@var{feature}
14805 These options allow users to choose which optional features to build and
14806 install. @option{--enable-@var{feature}} options should never make a
14807 feature behave differently or cause one feature to replace another.
14808 They should only cause parts of the program to be built rather than left
14811 The user can give an argument by following the feature name with
14812 @samp{=} and the argument. Giving an argument of @samp{no} requests
14813 that the feature @emph{not} be made available. A feature with an
14814 argument looks like @option{--enable-debug=stabs}. If no argument is
14815 given, it defaults to @samp{yes}. @option{--disable-@var{feature}} is
14816 equivalent to @option{--enable-@var{feature}=no}.
14818 @command{configure} scripts do not complain about
14819 @option{--enable-@var{feature}} options that they do not support.
14820 This behavior permits configuring a source tree containing multiple
14821 packages with a top-level @command{configure} script when the packages
14822 support different options, without spurious error messages about options
14823 that some of the packages support.
14824 An unfortunate side effect is that option spelling errors are not diagnosed.
14825 No better approach to this problem has been suggested so far.
14827 For each optional feature, @file{configure.ac} should call
14828 @code{AC_ARG_ENABLE} to detect whether the @command{configure} user asked
14829 to include it. Whether each feature is included or not by default, and
14830 which arguments are valid, is up to you.
14832 @defmac AC_ARG_ENABLE (@var{feature}, @var{help-string}, @ovar{action-if-given}, @ovar{action-if-not-given})
14833 @acindex{ARG_ENABLE}
14834 If the user gave @command{configure} the option
14835 @option{--enable-@var{feature}} or @option{--disable-@var{feature}}, run
14836 shell commands @var{action-if-given}. If neither option was given, run
14837 shell commands @var{action-if-not-given}. The name @var{feature}
14838 indicates an optional user-level facility. It should consist only of
14839 alphanumeric characters and dashes.
14841 The option's argument is available to the shell commands
14842 @var{action-if-given} in the shell variable @code{enableval}, which is
14843 actually just the value of the shell variable
14844 @code{enable_@var{feature}}, with any @option{-} characters changed into
14845 @samp{_}. You may use that variable instead, if you wish. The
14846 @var{help-string} argument is like that of @code{AC_ARG_WITH}
14847 (@pxref{External Software}).
14849 You should format your @var{help-string} with the macro
14850 @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
14852 See the examples suggested with the definition of @code{AC_ARG_WITH}
14853 (@pxref{External Software}) to get an idea of possible applications of
14854 @code{AC_ARG_ENABLE}.
14857 @defmac AC_ENABLE (@var{feature}, @var{action-if-given}, @ovar{action-if-not-given})
14859 This is an obsolete version of @code{AC_ARG_ENABLE} that does not
14860 support providing a help string.
14864 @node Pretty Help Strings
14865 @section Making Your Help Strings Look Pretty
14866 @cindex Help strings
14868 Properly formatting the @samp{help strings} which are used in
14869 @code{AC_ARG_WITH} (@pxref{External Software}) and @code{AC_ARG_ENABLE}
14870 (@pxref{Package Options}) can be challenging. Specifically, you want
14871 your own @samp{help strings} to line up in the appropriate columns of
14872 @samp{configure --help} just like the standard Autoconf @samp{help
14873 strings} do. This is the purpose of the @code{AS_HELP_STRING} macro.
14875 @defmac AS_HELP_STRING (@var{left-hand-side}, @var{right-hand-side})
14876 @acindex{HELP_STRING}
14878 Expands into an help string that looks pretty when the user executes
14879 @samp{configure --help}. It is typically used in @code{AC_ARG_WITH}
14880 (@pxref{External Software}) or @code{AC_ARG_ENABLE} (@pxref{Package
14881 Options}). The following example will make this clearer.
14885 [AS_HELP_STRING([--with-foo],
14886 [use foo (default is no)])],
14887 [use_foo=$withval],
14891 The second argument of @code{AS_HELP_STRING} is
14892 not a literal, and should not be double quoted.
14893 @xref{Autoconf Language}, for a more detailed explanation.
14894 Then the last few lines of @samp{configure --help} will appear like
14898 --enable and --with options recognized:
14899 --with-foo use foo (default is no)
14902 The @code{AS_HELP_STRING} macro is particularly helpful when the
14903 @var{left-hand-side} and/or @var{right-hand-side} are composed of macro
14904 arguments, as shown in the following example.
14907 AC_DEFUN([MY_ARG_WITH],
14909 [AS_HELP_STRING([--with-$1], [use $1 (default is $2)])],
14910 [use_[]$1=$withval],
14917 @section Configuring Site Details
14918 @cindex Site details
14920 Some software packages require complex site-specific information. Some
14921 examples are host names to use for certain services, company names, and
14922 email addresses to contact. Since some configuration scripts generated
14923 by Metaconfig ask for such information interactively, people sometimes
14924 wonder how to get that information in Autoconf-generated configuration
14925 scripts, which aren't interactive.
14927 Such site configuration information should be put in a file that is
14928 edited @emph{only by users}, not by programs. The location of the file
14929 can either be based on the @code{prefix} variable, or be a standard
14930 location such as the user's home directory. It could even be specified
14931 by an environment variable. The programs should examine that file at
14932 runtime, rather than at compile time. Runtime configuration is more
14933 convenient for users and makes the configuration process simpler than
14934 getting the information while configuring. @xref{Directory Variables, ,
14935 Variables for Installation Directories, standards, @acronym{GNU} Coding
14936 Standards}, for more information on where to put data files.
14938 @node Transforming Names
14939 @section Transforming Program Names When Installing
14940 @cindex Transforming program names
14941 @cindex Program names, transforming
14943 Autoconf supports changing the names of programs when installing them.
14944 In order to use these transformations, @file{configure.ac} must call the
14945 macro @code{AC_ARG_PROGRAM}.
14947 @defmac AC_ARG_PROGRAM
14948 @acindex{ARG_PROGRAM}
14949 @ovindex program_transform_name
14950 Place in output variable @code{program_transform_name} a sequence of
14951 @code{sed} commands for changing the names of installed programs.
14953 If any of the options described below are given to @command{configure},
14954 program names are transformed accordingly. Otherwise, if
14955 @code{AC_CANONICAL_TARGET} has been called and a @option{--target} value
14956 is given, the target type followed by a dash is used as a prefix.
14957 Otherwise, no program name transformation is done.
14961 * Transformation Options:: @command{configure} options to transform names
14962 * Transformation Examples:: Sample uses of transforming names
14963 * Transformation Rules:: @file{Makefile} uses of transforming names
14966 @node Transformation Options
14967 @subsection Transformation Options
14969 You can specify name transformations by giving @command{configure} these
14970 command line options:
14973 @item --program-prefix=@var{prefix}
14974 prepend @var{prefix} to the names;
14976 @item --program-suffix=@var{suffix}
14977 append @var{suffix} to the names;
14979 @item --program-transform-name=@var{expression}
14980 perform @code{sed} substitution @var{expression} on the names.
14983 @node Transformation Examples
14984 @subsection Transformation Examples
14986 These transformations are useful with programs that can be part of a
14987 cross-compilation development environment. For example, a
14988 cross-assembler running on a Sun 4 configured with
14989 @option{--target=i960-vxworks} is normally installed as
14990 @file{i960-vxworks-as}, rather than @file{as}, which could be confused
14991 with a native Sun 4 assembler.
14993 You can force a program name to begin with @file{g}, if you don't want
14994 @acronym{GNU} programs installed on your system to shadow other programs with
14995 the same name. For example, if you configure @acronym{GNU} @code{diff} with
14996 @option{--program-prefix=g}, then when you run @samp{make install} it is
14997 installed as @file{/usr/local/bin/gdiff}.
14999 As a more sophisticated example, you could use
15002 --program-transform-name='s/^/g/; s/^gg/g/; s/^gless/less/'
15006 to prepend @samp{g} to most of the program names in a source tree,
15007 excepting those like @code{gdb} that already have one and those like
15008 @code{less} and @code{lesskey} that aren't @acronym{GNU} programs. (That is
15009 assuming that you have a source tree containing those programs that is
15010 set up to use this feature.)
15012 One way to install multiple versions of some programs simultaneously is
15013 to append a version number to the name of one or both. For example, if
15014 you want to keep Autoconf version 1 around for awhile, you can configure
15015 Autoconf version 2 using @option{--program-suffix=2} to install the
15016 programs as @file{/usr/local/bin/autoconf2},
15017 @file{/usr/local/bin/autoheader2}, etc. Nevertheless, pay attention
15018 that only the binaries are renamed, therefore you'd have problems with
15019 the library files which might overlap.
15021 @node Transformation Rules
15022 @subsection Transformation Rules
15024 Here is how to use the variable @code{program_transform_name} in a
15025 @file{Makefile.in}:
15028 PROGRAMS = cp ls rm
15029 transform = @@program_transform_name@@
15031 for p in $(PROGRAMS); do \
15032 $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p | \
15033 sed '$(transform)'`; \
15037 for p in $(PROGRAMS); do \
15038 rm -f $(DESTDIR)$(bindir)/`echo $$p | sed '$(transform)'`; \
15042 It is guaranteed that @code{program_transform_name} is never empty, and
15043 that there are no useless separators. Therefore you may safely embed
15044 @code{program_transform_name} within a sed program using @samp{;}:
15047 transform = @@program_transform_name@@
15048 transform_exe = s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/
15051 Whether to do the transformations on documentation files (Texinfo or
15052 @code{man}) is a tricky question; there seems to be no perfect answer,
15053 due to the several reasons for name transforming. Documentation is not
15054 usually particular to a specific architecture, and Texinfo files do not
15055 conflict with system documentation. But they might conflict with
15056 earlier versions of the same files, and @code{man} pages sometimes do
15057 conflict with system documentation. As a compromise, it is probably
15058 best to do name transformations on @code{man} pages but not on Texinfo
15061 @node Site Defaults
15062 @section Setting Site Defaults
15063 @cindex Site defaults
15065 Autoconf-generated @command{configure} scripts allow your site to provide
15066 default values for some configuration values. You do this by creating
15067 site- and system-wide initialization files.
15069 @evindex CONFIG_SITE
15070 If the environment variable @code{CONFIG_SITE} is set, @command{configure}
15071 uses its value as the name of a shell script to read. Otherwise, it
15072 reads the shell script @file{@var{prefix}/share/config.site} if it exists,
15073 then @file{@var{prefix}/etc/config.site} if it exists. Thus,
15074 settings in machine-specific files override those in machine-independent
15075 ones in case of conflict.
15077 Site files can be arbitrary shell scripts, but only certain kinds of
15078 code are really appropriate to be in them. Because @command{configure}
15079 reads any cache file after it has read any site files, a site file can
15080 define a default cache file to be shared between all Autoconf-generated
15081 @command{configure} scripts run on that system (@pxref{Cache Files}). If
15082 you set a default cache file in a site file, it is a good idea to also
15083 set the output variable @code{CC} in that site file, because the cache
15084 file is only valid for a particular compiler, but many systems have
15087 You can examine or override the value set by a command line option to
15088 @command{configure} in a site file; options set shell variables that have
15089 the same names as the options, with any dashes turned into underscores.
15090 The exceptions are that @option{--without-} and @option{--disable-} options
15091 are like giving the corresponding @option{--with-} or @option{--enable-}
15092 option and the value @samp{no}. Thus, @option{--cache-file=localcache}
15093 sets the variable @code{cache_file} to the value @samp{localcache};
15094 @option{--enable-warnings=no} or @option{--disable-warnings} sets the variable
15095 @code{enable_warnings} to the value @samp{no}; @option{--prefix=/usr} sets the
15096 variable @code{prefix} to the value @samp{/usr}; etc.
15098 Site files are also good places to set default values for other output
15099 variables, such as @code{CFLAGS}, if you need to give them non-default
15100 values: anything you would normally do, repetitively, on the command
15101 line. If you use non-default values for @var{prefix} or
15102 @var{exec_prefix} (wherever you locate the site file), you can set them
15103 in the site file if you specify it with the @code{CONFIG_SITE}
15104 environment variable.
15106 You can set some cache values in the site file itself. Doing this is
15107 useful if you are cross-compiling, where it is impossible to check features
15108 that require running a test program. You could ``prime the cache'' by
15109 setting those values correctly for that system in
15110 @file{@var{prefix}/etc/config.site}. To find out the names of the cache
15111 variables you need to set, look for shell variables with @samp{_cv_} in
15112 their names in the affected @command{configure} scripts, or in the Autoconf
15113 M4 source code for those macros.
15115 The cache file is careful to not override any variables set in the site
15116 files. Similarly, you should not override command-line options in the
15117 site files. Your code should check that variables such as @code{prefix}
15118 and @code{cache_file} have their default values (as set near the top of
15119 @command{configure}) before changing them.
15121 Here is a sample file @file{/usr/share/local/gnu/share/config.site}. The
15122 command @samp{configure --prefix=/usr/share/local/gnu} would read this
15123 file (if @code{CONFIG_SITE} is not set to a different file).
15126 # config.site for configure
15128 # Change some defaults.
15129 test "$prefix" = NONE && prefix=/usr/share/local/gnu
15130 test "$exec_prefix" = NONE && exec_prefix=/usr/local/gnu
15131 test "$sharedstatedir" = '$prefix/com' && sharedstatedir=/var
15132 test "$localstatedir" = '$prefix/var' && localstatedir=/var
15134 # Give Autoconf 2.x generated configure scripts a shared default
15135 # cache file for feature test results, architecture-specific.
15136 if test "$cache_file" = /dev/null; then
15137 cache_file="$prefix/var/config.cache"
15138 # A cache file is only valid for one C compiler.
15144 @c ============================================== Running configure Scripts.
15146 @node Running configure Scripts
15147 @chapter Running @command{configure} Scripts
15148 @cindex @command{configure}
15150 Below are instructions on how to configure a package that uses a
15151 @command{configure} script, suitable for inclusion as an @file{INSTALL}
15152 file in the package. A plain-text version of @file{INSTALL} which you
15153 may use comes with Autoconf.
15156 * Basic Installation:: Instructions for typical cases
15157 * Compilers and Options:: Selecting compilers and optimization
15158 * Multiple Architectures:: Compiling for multiple architectures at once
15159 * Installation Names:: Installing in different directories
15160 * Optional Features:: Selecting optional features
15161 * System Type:: Specifying the system type
15162 * Sharing Defaults:: Setting site-wide defaults for @command{configure}
15163 * Defining Variables:: Specifying the compiler etc.
15164 * configure Invocation:: Changing how @command{configure} runs
15168 @include install.texi
15171 @c ============================================== Recreating a Configuration
15173 @node config.status Invocation
15174 @chapter Recreating a Configuration
15175 @cindex @command{config.status}
15177 The @command{configure} script creates a file named @file{config.status},
15178 which actually configures, @dfn{instantiates}, the template files. It
15179 also records the configuration options that were specified when the
15180 package was last configured in case reconfiguring is needed.
15184 ./config.status @var{option}@dots{} [@var{file}@dots{}]
15187 It configures the @var{files}; if none are specified, all the templates
15188 are instantiated. The files must be specified without their
15189 dependencies, as in
15192 ./config.status foobar
15199 ./config.status foobar:foo.in:bar.in
15202 The supported @var{option}s are:
15207 Print a summary of the command line options, the list of the template
15212 Print the version number of Autoconf and exit.
15217 Do not print progress messages.
15221 Don't remove the temporary files.
15223 @item --file=@var{file}[:@var{template}]
15224 Require that @var{file} be instantiated as if
15225 @samp{AC_CONFIG_FILES(@var{file}:@var{template})} was used. Both
15226 @var{file} and @var{template} may be @samp{-} in which case the standard
15227 output and/or standard input, respectively, is used. If a
15228 @var{template} file name is relative, it is first looked for in the build
15229 tree, and then in the source tree. @xref{Configuration Actions}, for
15232 This option and the following ones provide one way for separately
15233 distributed packages to share the values computed by @command{configure}.
15234 Doing so can be useful if some of the packages need a superset of the
15235 features that one of them, perhaps a common library, does. These
15236 options allow a @file{config.status} file to create files other than the
15237 ones that its @file{configure.ac} specifies, so it can be used for a
15240 @item --header=@var{file}[:@var{template}]
15241 Same as @option{--file} above, but with @samp{AC_CONFIG_HEADERS}.
15244 Ask @file{config.status} to update itself and exit (no instantiation).
15245 This option is useful if you change @command{configure}, so that the
15246 results of some tests might be different from the previous run. The
15247 @option{--recheck} option re-runs @command{configure} with the same arguments
15248 you used before, plus the @option{--no-create} option, which prevents
15249 @command{configure} from running @file{config.status} and creating
15250 @file{Makefile} and other files, and the @option{--no-recursion} option,
15251 which prevents @command{configure} from running other @command{configure}
15252 scripts in subdirectories. (This is so other @file{Makefile} rules can
15253 run @file{config.status} when it changes; @pxref{Automatic Remaking},
15257 @file{config.status} checks several optional environment variables that
15258 can alter its behavior:
15260 @defvar CONFIG_SHELL
15261 @evindex CONFIG_SHELL
15262 The shell with which to run @command{configure} for the @option{--recheck}
15263 option. It must be Bourne-compatible. The default is a shell that
15264 supports @code{LINENO} if available, and @file{/bin/sh} otherwise.
15265 Invoking @command{configure} by hand bypasses this setting, so you may
15266 need to use a command like @samp{CONFIG_SHELL=/bin/bash /bin/bash ./configure}
15267 to insure that the same shell is used everywhere. The absolute name of the
15268 shell should be passed.
15271 @defvar CONFIG_STATUS
15272 @evindex CONFIG_STATUS
15273 The file name to use for the shell script that records the
15274 configuration. The default is @file{./config.status}. This variable is
15275 useful when one package uses parts of another and the @command{configure}
15276 scripts shouldn't be merged because they are maintained separately.
15279 You can use @file{./config.status} in your Makefiles. For example, in
15280 the dependencies given above (@pxref{Automatic Remaking}),
15281 @file{config.status} is run twice when @file{configure.ac} has changed.
15282 If that bothers you, you can make each run only regenerate the files for
15287 stamp-h: config.h.in config.status
15288 ./config.status config.h
15291 Makefile: Makefile.in config.status
15292 ./config.status Makefile
15296 The calling convention of @file{config.status} has changed; see
15297 @ref{Obsolete config.status Use}, for details.
15300 @c =================================================== Obsolete Constructs
15302 @node Obsolete Constructs
15303 @chapter Obsolete Constructs
15304 @cindex Obsolete constructs
15306 Autoconf changes, and throughout the years some constructs have been
15307 obsoleted. Most of the changes involve the macros, but in some cases
15308 the tools themselves, or even some concepts, are now considered
15311 You may completely skip this chapter if you are new to Autoconf. Its
15312 intention is mainly to help maintainers updating their packages by
15313 understanding how to move to more modern constructs.
15316 * Obsolete config.status Use:: Different calling convention
15317 * acconfig.h:: Additional entries in @file{config.h.in}
15318 * autoupdate Invocation:: Automatic update of @file{configure.ac}
15319 * Obsolete Macros:: Backward compatibility macros
15320 * Autoconf 1:: Tips for upgrading your files
15321 * Autoconf 2.13:: Some fresher tips
15324 @node Obsolete config.status Use
15325 @section Obsolete @file{config.status} Invocation
15327 @file{config.status} now supports arguments to specify the files to
15328 instantiate; see @ref{config.status Invocation}, for more details.
15329 Before, environment variables had to be used.
15331 @defvar CONFIG_COMMANDS
15332 @evindex CONFIG_COMMANDS
15333 The tags of the commands to execute. The default is the arguments given
15334 to @code{AC_OUTPUT} and @code{AC_CONFIG_COMMANDS} in
15335 @file{configure.ac}.
15338 @defvar CONFIG_FILES
15339 @evindex CONFIG_FILES
15340 The files in which to perform @samp{@@@var{variable}@@} substitutions.
15341 The default is the arguments given to @code{AC_OUTPUT} and
15342 @code{AC_CONFIG_FILES} in @file{configure.ac}.
15345 @defvar CONFIG_HEADERS
15346 @evindex CONFIG_HEADERS
15347 The files in which to substitute C @code{#define} statements. The
15348 default is the arguments given to @code{AC_CONFIG_HEADERS}; if that
15349 macro was not called, @file{config.status} ignores this variable.
15352 @defvar CONFIG_LINKS
15353 @evindex CONFIG_LINKS
15354 The symbolic links to establish. The default is the arguments given to
15355 @code{AC_CONFIG_LINKS}; if that macro was not called,
15356 @file{config.status} ignores this variable.
15359 In @ref{config.status Invocation}, using this old interface, the example
15365 stamp-h: config.h.in config.status
15366 CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_FILES= \
15367 CONFIG_HEADERS=config.h ./config.status
15370 Makefile: Makefile.in config.status
15371 CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_HEADERS= \
15372 CONFIG_FILES=Makefile ./config.status
15377 (If @file{configure.ac} does not call @code{AC_CONFIG_HEADERS}, there is
15378 no need to set @code{CONFIG_HEADERS} in the @code{make} rules. Equally
15379 for @code{CONFIG_COMMANDS}, etc.)
15383 @section @file{acconfig.h}
15385 @cindex @file{acconfig.h}
15386 @cindex @file{config.h.top}
15387 @cindex @file{config.h.bot}
15389 In order to produce @file{config.h.in}, @command{autoheader} needs to
15390 build or to find templates for each symbol. Modern releases of Autoconf
15391 use @code{AH_VERBATIM} and @code{AH_TEMPLATE} (@pxref{Autoheader
15392 Macros}), but in older releases a file, @file{acconfig.h}, contained the
15393 list of needed templates. @command{autoheader} copied comments and
15394 @code{#define} and @code{#undef} statements from @file{acconfig.h} in
15395 the current directory, if present. This file used to be mandatory if
15396 you @code{AC_DEFINE} any additional symbols.
15398 Modern releases of Autoconf also provide @code{AH_TOP} and
15399 @code{AH_BOTTOM} if you need to prepend/append some information to
15400 @file{config.h.in}. Ancient versions of Autoconf had a similar feature:
15401 if @file{./acconfig.h} contains the string @samp{@@TOP@@},
15402 @command{autoheader} copies the lines before the line containing
15403 @samp{@@TOP@@} into the top of the file that it generates. Similarly,
15404 if @file{./acconfig.h} contains the string @samp{@@BOTTOM@@},
15405 @command{autoheader} copies the lines after that line to the end of the
15406 file it generates. Either or both of those strings may be omitted. An
15407 even older alternate way to produce the same effect in ancient versions
15408 of Autoconf is to create the files @file{@var{file}.top} (typically
15409 @file{config.h.top}) and/or @file{@var{file}.bot} in the current
15410 directory. If they exist, @command{autoheader} copies them to the
15411 beginning and end, respectively, of its output.
15413 In former versions of Autoconf, the files used in preparing a software
15414 package for distribution were:
15417 configure.ac --. .------> autoconf* -----> configure
15419 [aclocal.m4] --+ `---.
15421 +--> [autoheader*] -> [config.h.in]
15422 [acconfig.h] ----. |
15429 Using only the @code{AH_} macros, @file{configure.ac} should be
15430 self-contained, and should not depend upon @file{acconfig.h} etc.
15433 @node autoupdate Invocation
15434 @section Using @command{autoupdate} to Modernize @file{configure.ac}
15435 @cindex @command{autoupdate}
15437 The @command{autoupdate} program updates a @file{configure.ac} file that
15438 calls Autoconf macros by their old names to use the current macro names.
15439 In version 2 of Autoconf, most of the macros were renamed to use a more
15440 uniform and descriptive naming scheme. @xref{Macro Names}, for a
15441 description of the new scheme. Although the old names still work
15442 (@pxref{Obsolete Macros}, for a list of the old macros and the corresponding
15443 new names), you can make your @file{configure.ac} files more readable
15444 and make it easier to use the current Autoconf documentation if you
15445 update them to use the new macro names.
15447 @evindex SIMPLE_BACKUP_SUFFIX
15448 If given no arguments, @command{autoupdate} updates @file{configure.ac},
15449 backing up the original version with the suffix @file{~} (or the value
15450 of the environment variable @code{SIMPLE_BACKUP_SUFFIX}, if that is
15451 set). If you give @command{autoupdate} an argument, it reads that file
15452 instead of @file{configure.ac} and writes the updated file to the
15456 @command{autoupdate} accepts the following options:
15461 Print a summary of the command line options and exit.
15465 Print the version number of Autoconf and exit.
15469 Report processing steps.
15473 Don't remove the temporary files.
15477 Force the update even if the file has not changed. Disregard the cache.
15479 @item --include=@var{dir}
15480 @itemx -I @var{dir}
15481 Also look for input files in @var{dir}. Multiple invocations accumulate.
15482 Directories are browsed from last to first.
15485 @node Obsolete Macros
15486 @section Obsolete Macros
15488 Several macros are obsoleted in Autoconf, for various reasons (typically
15489 they failed to quote properly, couldn't be extended for more recent
15490 issues, etc.). They are still supported, but deprecated: their use
15493 During the jump from Autoconf version 1 to version 2, most of the
15494 macros were renamed to use a more uniform and descriptive naming scheme,
15495 but their signature did not change. @xref{Macro Names}, for a
15496 description of the new naming scheme. Below, if there is just the mapping
15497 from old names to new names for these macros, the reader is invited to
15498 refer to the definition of the new macro for the signature and the
15503 @code{AC_FUNC_ALLOCA}
15506 @defmac AC_ARG_ARRAY
15507 @acindex{ARG_ARRAY}
15508 removed because of limited usefulness
15513 This macro is obsolete; it does nothing.
15516 @defmac AC_C_LONG_DOUBLE
15517 @acindex{C_LONG_DOUBLE}
15518 @cvindex HAVE_LONG_DOUBLE
15519 If the C compiler supports a working @code{long double} type with more
15520 range or precision than the @code{double} type, define
15521 @code{HAVE_LONG_DOUBLE}.
15523 You should use @code{AC_TYPE_LONG_DOUBLE} or
15524 @code{AC_TYPE_LONG_DOUBLE_WIDER} instead. @xref{Particular Types}.
15527 @defmac AC_CANONICAL_SYSTEM
15528 @acindex{CANONICAL_SYSTEM}
15529 Determine the system type and set output variables to the names of the
15530 canonical system types. @xref{Canonicalizing}, for details about the
15531 variables this macro sets.
15533 The user is encouraged to use either @code{AC_CANONICAL_BUILD}, or
15534 @code{AC_CANONICAL_HOST}, or @code{AC_CANONICAL_TARGET}, depending on
15535 the needs. Using @code{AC_CANONICAL_TARGET} is enough to run the two
15539 @defmac AC_CHAR_UNSIGNED
15540 @acindex{CHAR_UNSIGNED}
15541 @code{AC_C_CHAR_UNSIGNED}
15544 @defmac AC_CHECK_TYPE (@var{type}, @var{default})
15545 @acindex{CHECK_TYPE}
15546 Autoconf, up to 2.13, used to provide this version of
15547 @code{AC_CHECK_TYPE}, deprecated because of its flaws. Firstly, although
15548 it is a member of the @code{CHECK} clan, singular sub-family, it does
15549 more than just checking. Secondly, missing types are not
15550 @code{typedef}'d, they are @code{#define}'d, which can lead to
15551 incompatible code in the case of pointer types.
15553 This use of @code{AC_CHECK_TYPE} is obsolete and discouraged; see
15554 @ref{Generic Types}, for the description of the current macro.
15556 If the type @var{type} is not defined, define it to be the C (or C++)
15557 builtin type @var{default}, e.g., @samp{short int} or @samp{unsigned int}.
15559 This macro is equivalent to:
15562 AC_CHECK_TYPE([@var{type}], [],
15563 [AC_DEFINE_UNQUOTED([@var{type}], [@var{default}],
15564 [Define to `@var{default}'
15565 if <sys/types.h> does not define.])])
15568 In order to keep backward compatibility, the two versions of
15569 @code{AC_CHECK_TYPE} are implemented, selected by a simple heuristics:
15573 If there are three or four arguments, the modern version is used.
15576 If the second argument appears to be a C or C++ type, then the
15577 obsolete version is used. This happens if the argument is a C or C++
15578 @emph{builtin} type or a C identifier ending in @samp{_t}, optionally
15579 followed by one of @samp{[(* } and then by a string of zero or more
15580 characters taken from the set @samp{[]()* _a-zA-Z0-9}.
15583 If the second argument is spelled with the alphabet of valid C and C++
15584 types, the user is warned and the modern version is used.
15587 Otherwise, the modern version is used.
15591 You are encouraged either to use a valid builtin type, or to use the
15592 equivalent modern code (see above), or better yet, to use
15593 @code{AC_CHECK_TYPES} together with
15597 typedef loff_t off_t;
15601 @c end of AC_CHECK_TYPE
15603 @defmac AC_CHECKING (@var{feature-description})
15605 Same as @samp{AC_MSG_NOTICE([checking @var{feature-description}@dots{}]}.
15608 @defmac AC_COMPILE_CHECK (@var{echo-text}, @var{includes}, @var{function-body}, @var{action-if-found}, @ovar{action-if-not-found})
15609 @acindex{COMPILE_CHECK}
15610 This is an obsolete version of @code{AC_TRY_COMPILE} itself replaced by
15611 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}), with the
15612 addition that it prints @samp{checking for @var{echo-text}} to the
15613 standard output first, if @var{echo-text} is non-empty. Use
15614 @code{AC_MSG_CHECKING} and @code{AC_MSG_RESULT} instead to print
15615 messages (@pxref{Printing Messages}).
15623 @defmac AC_CROSS_CHECK
15624 @acindex{CROSS_CHECK}
15625 Same as @code{AC_C_CROSS}, which is obsolete too, and does nothing
15631 Check for the Cygwin environment in which case the shell variable
15632 @code{CYGWIN} is set to @samp{yes}. Don't use this macro, the dignified
15633 means to check the nature of the host is using
15634 @code{AC_CANONICAL_HOST}. As a matter of fact this macro is defined as:
15637 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
15639 *cygwin* ) CYGWIN=yes;;
15644 Beware that the variable @code{CYGWIN} has a very special meaning when
15645 running Cygwin, and should not be changed. That's yet another reason
15646 not to use this macro.
15649 @defmac AC_DECL_SYS_SIGLIST
15650 @acindex{DECL_SYS_SIGLIST}
15651 @cvindex SYS_SIGLIST_DECLARED
15655 AC_CHECK_DECLS([sys_siglist], [], [],
15656 [#include <signal.h>
15657 /* NetBSD declares sys_siglist in unistd.h. */
15659 # include <unistd.h>
15665 @defmac AC_DECL_YYTEXT
15666 @acindex{DECL_YYTEXT}
15667 Does nothing, now integrated in @code{AC_PROG_LEX}.
15670 @defmac AC_DIR_HEADER
15671 @acindex{DIR_HEADER}
15676 Like calling @code{AC_FUNC_CLOSEDIR_VOID} and@code{AC_HEADER_DIRENT},
15677 but defines a different set of C preprocessor macros to indicate which
15678 header file is found:
15680 @multitable {@file{sys/ndir.h}} {Old Symbol} {@code{HAVE_SYS_NDIR_H}}
15681 @item Header @tab Old Symbol @tab New Symbol
15682 @item @file{dirent.h} @tab @code{DIRENT} @tab @code{HAVE_DIRENT_H}
15683 @item @file{sys/ndir.h} @tab @code{SYSNDIR} @tab @code{HAVE_SYS_NDIR_H}
15684 @item @file{sys/dir.h} @tab @code{SYSDIR} @tab @code{HAVE_SYS_DIR_H}
15685 @item @file{ndir.h} @tab @code{NDIR} @tab @code{HAVE_NDIR_H}
15689 @defmac AC_DYNIX_SEQ
15690 @acindex{DYNIX_SEQ}
15691 If on DYNIX/ptx, add @option{-lseq} to output variable
15692 @code{LIBS}. This macro used to be defined as
15695 AC_CHECK_LIB([seq], [getmntent], [LIBS="-lseq $LIBS"])
15699 now it is just @code{AC_FUNC_GETMNTENT}.
15705 Defined the output variable @code{EXEEXT} based on the output of the
15706 compiler, which is now done automatically. Typically set to empty
15707 string if Posix and @samp{.exe} if a @acronym{DOS} variant.
15712 Similar to @code{AC_CYGWIN} but checks for the EMX environment on OS/2
15713 and sets @code{EMXOS2}.
15718 @code{AC_MSG_ERROR}
15726 @defmac AC_FIND_XTRA
15727 @acindex{FIND_XTRA}
15728 @code{AC_PATH_XTRA}
15733 @code{m4_foreach_w}
15736 @defmac AC_FUNC_CHECK
15737 @acindex{FUNC_CHECK}
15738 @code{AC_CHECK_FUNC}
15741 @defmac AC_FUNC_WAIT3
15742 @acindex{FUNC_WAIT3}
15743 @cvindex HAVE_WAIT3
15744 If @code{wait3} is found and fills in the contents of its third argument
15745 (a @samp{struct rusage *}), which HP-UX does not do, define
15748 These days portable programs should use @code{waitpid}, not
15749 @code{wait3}, as @code{wait3} has been removed from Posix.
15752 @defmac AC_GCC_TRADITIONAL
15753 @acindex{GCC_TRADITIONAL}
15754 @code{AC_PROG_GCC_TRADITIONAL}
15757 @defmac AC_GETGROUPS_T
15758 @acindex{GETGROUPS_T}
15759 @code{AC_TYPE_GETGROUPS}
15762 @defmac AC_GETLOADAVG
15763 @acindex{GETLOADAVG}
15764 @code{AC_FUNC_GETLOADAVG}
15767 @defmac AC_HAVE_FUNCS
15768 @acindex{HAVE_FUNCS}
15769 @code{AC_CHECK_FUNCS}
15772 @defmac AC_HAVE_HEADERS
15773 @acindex{HAVE_HEADERS}
15774 @code{AC_CHECK_HEADERS}
15777 @defmac AC_HAVE_LIBRARY (@var{library}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
15778 @acindex{HAVE_LIBRARY}
15779 This macro is equivalent to calling @code{AC_CHECK_LIB} with a
15780 @var{function} argument of @code{main}. In addition, @var{library} can
15781 be written as any of @samp{foo}, @option{-lfoo}, or @samp{libfoo.a}. In
15782 all of those cases, the compiler is passed @option{-lfoo}. However,
15783 @var{library} cannot be a shell variable; it must be a literal name.
15786 @defmac AC_HAVE_POUNDBANG
15787 @acindex{HAVE_POUNDBANG}
15788 @code{AC_SYS_INTERPRETER} (different calling convention)
15791 @defmac AC_HEADER_CHECK
15792 @acindex{HEADER_CHECK}
15793 @code{AC_CHECK_HEADER}
15796 @defmac AC_HEADER_EGREP
15797 @acindex{HEADER_EGREP}
15798 @code{AC_EGREP_HEADER}
15801 @defmac AC_HELP_STRING
15802 @acindex{HELP_STRING}
15803 @code{AS_HELP_STRING}
15806 @defmac AC_INIT (@var{unique-file-in-source-dir})
15808 Formerly @code{AC_INIT} used to have a single argument, and was
15813 AC_CONFIG_SRCDIR(@var{unique-file-in-source-dir})
15822 @defmac AC_INT_16_BITS
15823 @acindex{INT_16_BITS}
15824 @cvindex INT_16_BITS
15825 If the C type @code{int} is 16 bits wide, define @code{INT_16_BITS}.
15826 Use @samp{AC_CHECK_SIZEOF(int)} instead.
15829 @defmac AC_IRIX_SUN
15831 If on @sc{irix} (Silicon Graphics Unix), add @option{-lsun} to output
15832 @code{LIBS}. If you were using it to get @code{getmntent}, use
15833 @code{AC_FUNC_GETMNTENT} instead. If you used it for the NIS versions
15834 of the password and group functions, use @samp{AC_CHECK_LIB(sun,
15835 getpwnam)}. Up to Autoconf 2.13, it used to be
15838 AC_CHECK_LIB([sun], [getmntent], [LIBS="-lsun $LIBS"])
15842 now it is defined as
15846 AC_CHECK_LIB([sun], [getpwnam])
15852 Same as @samp{AC_LANG([C])}.
15855 @defmac AC_LANG_CPLUSPLUS
15856 @acindex{LANG_CPLUSPLUS}
15857 Same as @samp{AC_LANG([C++])}.
15860 @defmac AC_LANG_FORTRAN77
15861 @acindex{LANG_FORTRAN77}
15862 Same as @samp{AC_LANG([Fortran 77])}.
15865 @defmac AC_LANG_RESTORE
15866 @acindex{LANG_RESTORE}
15867 Select the @var{language} that is saved on the top of the stack, as set
15868 by @code{AC_LANG_SAVE}, remove it from the stack, and call
15869 @code{AC_LANG(@var{language})}.
15872 @defmac AC_LANG_SAVE
15873 @acindex{LANG_SAVE}
15874 Remember the current language (as set by @code{AC_LANG}) on a stack.
15875 The current language does not change. @code{AC_LANG_PUSH} is preferred.
15878 @defmac AC_LINK_FILES (@var{source}@dots{}, @var{dest}@dots{})
15879 @acindex{LINK_FILES}
15880 This is an obsolete version of @code{AC_CONFIG_LINKS}. An updated
15884 AC_LINK_FILES(config/$machine.h config/$obj_format.h,
15892 AC_CONFIG_LINKS([host.h:config/$machine.h
15893 object.h:config/$obj_format.h])
15899 @code{AC_PROG_LN_S}
15902 @defmac AC_LONG_64_BITS
15903 @acindex{LONG_64_BITS}
15904 @cvindex LONG_64_BITS
15905 Define @code{LONG_64_BITS} if the C type @code{long int} is 64 bits wide.
15906 Use the generic macro @samp{AC_CHECK_SIZEOF([long int])} instead.
15909 @defmac AC_LONG_DOUBLE
15910 @acindex{LONG_DOUBLE}
15911 If the C compiler supports a working @code{long double} type with more
15912 range or precision than the @code{double} type, define
15913 @code{HAVE_LONG_DOUBLE}.
15915 You should use @code{AC_TYPE_LONG_DOUBLE} or
15916 @code{AC_TYPE_LONG_DOUBLE_WIDER} instead. @xref{Particular Types}.
15919 @defmac AC_LONG_FILE_NAMES
15920 @acindex{LONG_FILE_NAMES}
15921 @code{AC_SYS_LONG_FILE_NAMES}
15924 @defmac AC_MAJOR_HEADER
15925 @acindex{MAJOR_HEADER}
15926 @code{AC_HEADER_MAJOR}
15929 @defmac AC_MEMORY_H
15931 @cvindex NEED_MEMORY_H
15932 Used to define @code{NEED_MEMORY_H} if the @code{mem} functions were
15933 defined in @file{memory.h}. Today it is equivalent to
15934 @samp{AC_CHECK_HEADERS([memory.h])}. Adjust your code to depend upon
15935 @code{HAVE_MEMORY_H}, not @code{NEED_MEMORY_H}; see @ref{Standard
15941 Similar to @code{AC_CYGWIN} but checks for the MinGW compiler
15942 environment and sets @code{MINGW32}.
15945 @defmac AC_MINUS_C_MINUS_O
15946 @acindex{MINUS_C_MINUS_O}
15947 @code{AC_PROG_CC_C_O}
15952 @code{AC_FUNC_MMAP}
15957 @code{AC_TYPE_MODE_T}
15963 Defined the output variable @code{OBJEXT} based on the output of the
15964 compiler, after .c files have been excluded. Typically set to @samp{o}
15965 if Posix, @samp{obj} if a @acronym{DOS} variant.
15966 Now the compiler checking macros handle
15967 this automatically.
15970 @defmac AC_OBSOLETE (@var{this-macro-name}, @ovar{suggestion})
15972 Make M4 print a message to the standard error output warning that
15973 @var{this-macro-name} is obsolete, and giving the file and line number
15974 where it was called. @var{this-macro-name} should be the name of the
15975 macro that is calling @code{AC_OBSOLETE}. If @var{suggestion} is given,
15976 it is printed at the end of the warning message; for example, it can be
15977 a suggestion for what to use instead of @var{this-macro-name}.
15982 AC_OBSOLETE([$0], [; use AC_CHECK_HEADERS(unistd.h) instead])dnl
15985 You are encouraged to use @code{AU_DEFUN} instead, since it gives better
15986 services to the user.
15991 @code{AC_TYPE_OFF_T}
15994 @defmac AC_OUTPUT (@ovar{file}@dots{}, @ovar{extra-cmds}, @ovar{init-cmds})
15996 The use of @code{AC_OUTPUT} with argument is deprecated. This obsoleted
15997 interface is equivalent to:
16001 AC_CONFIG_FILES(@var{file}@dots{})
16002 AC_CONFIG_COMMANDS([default],
16003 @var{extra-cmds}, @var{init-cmds})
16009 @defmac AC_OUTPUT_COMMANDS (@var{extra-cmds}, @ovar{init-cmds})
16010 @acindex{OUTPUT_COMMANDS}
16011 Specify additional shell commands to run at the end of
16012 @file{config.status}, and shell commands to initialize any variables
16013 from @command{configure}. This macro may be called multiple times. It is
16014 obsolete, replaced by @code{AC_CONFIG_COMMANDS}.
16016 Here is an unrealistic example:
16020 AC_OUTPUT_COMMANDS([echo this is extra $fubar, and so on.],
16022 AC_OUTPUT_COMMANDS([echo this is another, extra, bit],
16026 Aside from the fact that @code{AC_CONFIG_COMMANDS} requires an
16027 additional key, an important difference is that
16028 @code{AC_OUTPUT_COMMANDS} is quoting its arguments twice, unlike
16029 @code{AC_CONFIG_COMMANDS}. This means that @code{AC_CONFIG_COMMANDS}
16030 can safely be given macro calls as arguments:
16033 AC_CONFIG_COMMANDS(foo, [my_FOO()])
16037 Conversely, where one level of quoting was enough for literal strings
16038 with @code{AC_OUTPUT_COMMANDS}, you need two with
16039 @code{AC_CONFIG_COMMANDS}. The following lines are equivalent:
16043 AC_OUTPUT_COMMANDS([echo "Square brackets: []"])
16044 AC_CONFIG_COMMANDS([default], [[echo "Square brackets: []"]])
16051 @code{AC_TYPE_PID_T}
16056 @code{AC_PREFIX_PROGRAM}
16059 @defmac AC_PROGRAMS_CHECK
16060 @acindex{PROGRAMS_CHECK}
16061 @code{AC_CHECK_PROGS}
16064 @defmac AC_PROGRAMS_PATH
16065 @acindex{PROGRAMS_PATH}
16066 @code{AC_PATH_PROGS}
16069 @defmac AC_PROGRAM_CHECK
16070 @acindex{PROGRAM_CHECK}
16071 @code{AC_CHECK_PROG}
16074 @defmac AC_PROGRAM_EGREP
16075 @acindex{PROGRAM_EGREP}
16076 @code{AC_EGREP_CPP}
16079 @defmac AC_PROGRAM_PATH
16080 @acindex{PROGRAM_PATH}
16081 @code{AC_PATH_PROG}
16084 @defmac AC_REMOTE_TAPE
16085 @acindex{REMOTE_TAPE}
16086 removed because of limited usefulness
16089 @defmac AC_RESTARTABLE_SYSCALLS
16090 @acindex{RESTARTABLE_SYSCALLS}
16091 @code{AC_SYS_RESTARTABLE_SYSCALLS}
16094 @defmac AC_RETSIGTYPE
16095 @acindex{RETSIGTYPE}
16096 @code{AC_TYPE_SIGNAL}
16101 removed because of limited usefulness
16104 @defmac AC_SCO_INTL
16107 If on SCO Unix, add @option{-lintl} to output variable @code{LIBS}. This
16108 macro used to do this:
16111 AC_CHECK_LIB([intl], [strftime], [LIBS="-lintl $LIBS"])
16115 Now it just calls @code{AC_FUNC_STRFTIME} instead.
16118 @defmac AC_SETVBUF_REVERSED
16119 @acindex{SETVBUF_REVERSED}
16120 @code{AC_FUNC_SETVBUF_REVERSED}
16123 @defmac AC_SET_MAKE
16125 @code{AC_PROG_MAKE_SET}
16128 @defmac AC_SIZEOF_TYPE
16129 @acindex{SIZEOF_TYPE}
16130 @code{AC_CHECK_SIZEOF}
16135 @code{AC_TYPE_SIZE_T}
16138 @defmac AC_STAT_MACROS_BROKEN
16139 @acindex{STAT_MACROS_BROKEN}
16140 @code{AC_HEADER_STAT}
16143 @defmac AC_STDC_HEADERS
16144 @acindex{STDC_HEADERS}
16145 @code{AC_HEADER_STDC}
16150 @code{AC_FUNC_STRCOLL}
16153 @defmac AC_ST_BLKSIZE
16154 @acindex{ST_BLKSIZE}
16155 @code{AC_CHECK_MEMBERS}
16158 @defmac AC_ST_BLOCKS
16159 @acindex{ST_BLOCKS}
16160 @code{AC_STRUCT_ST_BLOCKS}
16165 @code{AC_CHECK_MEMBERS}
16168 @defmac AC_SYS_RESTARTABLE_SYSCALLS
16169 @acindex{SYS_RESTARTABLE_SYSCALLS}
16170 @cvindex HAVE_RESTARTABLE_SYSCALLS
16171 If the system automatically restarts a system call that is interrupted
16172 by a signal, define @code{HAVE_RESTARTABLE_SYSCALLS}. This macro does
16173 not check whether system calls are restarted in general---it checks whether a
16174 signal handler installed with @code{signal} (but not @code{sigaction})
16175 causes system calls to be restarted. It does not check whether system calls
16176 can be restarted when interrupted by signals that have no handler.
16178 These days portable programs should use @code{sigaction} with
16179 @code{SA_RESTART} if they want restartable system calls. They should
16180 not rely on @code{HAVE_RESTARTABLE_SYSCALLS}, since nowadays whether a
16181 system call is restartable is a dynamic issue, not a configuration-time
16185 @defmac AC_SYS_SIGLIST_DECLARED
16186 @acindex{SYS_SIGLIST_DECLARED}
16187 @code{AC_DECL_SYS_SIGLIST}
16190 @defmac AC_TEST_CPP
16192 @code{AC_TRY_CPP}, replaced by @code{AC_PREPROC_IFELSE}.
16195 @defmac AC_TEST_PROGRAM
16196 @acindex{TEST_PROGRAM}
16197 @code{AC_TRY_RUN}, replaced by @code{AC_RUN_IFELSE}.
16200 @defmac AC_TIMEZONE
16202 @code{AC_STRUCT_TIMEZONE}
16205 @defmac AC_TIME_WITH_SYS_TIME
16206 @acindex{TIME_WITH_SYS_TIME}
16207 @code{AC_HEADER_TIME}
16210 @defmac AC_TRY_COMPILE (@var{includes}, @var{function-body}, @ovar{action-if-found}, @ovar{action-if-not-found})
16211 @acindex{TRY_COMPILE}
16216 [AC_LANG_PROGRAM([[@var{includes}]],
16217 [[@var{function-body}]])],
16218 [@var{action-if-true}],
16219 [@var{action-if-false}])
16223 @xref{Running the Compiler}.
16225 This macro double quotes both @var{includes} and @var{function-body}.
16227 For C and C++, @var{includes} is any @code{#include} statements needed
16228 by the code in @var{function-body} (@var{includes} will be ignored if
16229 the currently selected language is Fortran or Fortran 77). The compiler
16230 and compilation flags are determined by the current language
16231 (@pxref{Language Choice}).
16234 @defmac AC_TRY_CPP (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
16240 [AC_LANG_SOURCE([[@var{input}]])],
16241 [@var{action-if-true}],
16242 [@var{action-if-false}])
16246 @xref{Running the Preprocessor}.
16248 This macro double quotes the @var{input}.
16251 @defmac AC_TRY_LINK (@var{includes}, @var{function-body}, @ovar{action-if-found}, @ovar{action-if-not-found})
16257 [AC_LANG_PROGRAM([[@var{includes}]],
16258 [[@var{function-body}]])],
16259 [@var{action-if-true}],
16260 [@var{action-if-false}])
16264 @xref{Running the Compiler}.
16266 This macro double quotes both @var{includes} and @var{function-body}.
16268 Depending on the current language (@pxref{Language Choice}), create a
16269 test program to see whether a function whose body consists of
16270 @var{function-body} can be compiled and linked. If the file compiles
16271 and links successfully, run shell commands @var{action-if-found},
16272 otherwise run @var{action-if-not-found}.
16274 This macro double quotes both @var{includes} and @var{function-body}.
16276 For C and C++, @var{includes} is any @code{#include} statements needed
16277 by the code in @var{function-body} (@var{includes} will be ignored if
16278 the currently selected language is Fortran or Fortran 77). The compiler
16279 and compilation flags are determined by the current language
16280 (@pxref{Language Choice}), and in addition @code{LDFLAGS} and
16281 @code{LIBS} are used for linking.
16284 @defmac AC_TRY_LINK_FUNC (@var{function}, @ovar{action-if-found}, @ovar{action-if-not-found})
16285 @acindex{TRY_LINK_FUNC}
16286 This macro is equivalent to
16287 @samp{AC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])],
16288 [@var{action-if-found}], [@var{action-if-not-found}])}.
16291 @defmac AC_TRY_RUN (@var{program}, @ovar{action-if-true}, @ovar{action-if-false}, @ovar{action-if-cross-compiling})
16297 [AC_LANG_SOURCE([[@var{program}]])],
16298 [@var{action-if-true}],
16299 [@var{action-if-false}],
16300 [@var{action-if-cross-compiling}])
16309 @code{AC_TYPE_UID_T}
16312 @defmac AC_UNISTD_H
16314 Same as @samp{AC_CHECK_HEADERS([unistd.h])}.
16320 Define @code{USG} if the @acronym{BSD} string functions are defined in
16321 @file{strings.h}. You should no longer depend upon @code{USG}, but on
16322 @code{HAVE_STRING_H}; see @ref{Standard Symbols}.
16325 @defmac AC_UTIME_NULL
16326 @acindex{UTIME_NULL}
16327 @code{AC_FUNC_UTIME_NULL}
16330 @defmac AC_VALIDATE_CACHED_SYSTEM_TUPLE (@ovar{cmd})
16331 @acindex{VALIDATE_CACHED_SYSTEM_TUPLE}
16332 If the cache file is inconsistent with the current host, target and
16333 build system types, it used to execute @var{cmd} or print a default
16334 error message. This is now handled by default.
16337 @defmac AC_VERBOSE (@var{result-description})
16339 @code{AC_MSG_RESULT}.
16344 @code{AC_FUNC_VFORK}
16349 @code{AC_FUNC_VPRINTF}
16354 @code{AC_FUNC_WAIT3}
16362 @defmac AC_WORDS_BIGENDIAN
16363 @acindex{WORDS_BIGENDIAN}
16364 @code{AC_C_BIGENDIAN}
16367 @defmac AC_XENIX_DIR
16368 @acindex{XENIX_DIR}
16370 This macro used to add @option{-lx} to output variable @code{LIBS} if on
16371 Xenix. Also, if @file{dirent.h} is being checked for, added
16372 @option{-ldir} to @code{LIBS}. Now it is merely an alias of
16373 @code{AC_HEADER_DIRENT} instead, plus some code to detect whether
16374 running @sc{xenix} on which you should not depend:
16377 AC_MSG_CHECKING([for Xenix])
16378 AC_EGREP_CPP([yes],
16379 [#if defined M_XENIX && !defined M_UNIX
16382 [AC_MSG_RESULT([yes]); XENIX=yes],
16383 [AC_MSG_RESULT([no]); XENIX=])
16387 @defmac AC_YYTEXT_POINTER
16388 @acindex{YYTEXT_POINTER}
16389 @code{AC_DECL_YYTEXT}
16393 @section Upgrading From Version 1
16394 @cindex Upgrading autoconf
16395 @cindex Autoconf upgrading
16397 Autoconf version 2 is mostly backward compatible with version 1.
16398 However, it introduces better ways to do some things, and doesn't
16399 support some of the ugly things in version 1. So, depending on how
16400 sophisticated your @file{configure.ac} files are, you might have to do
16401 some manual work in order to upgrade to version 2. This chapter points
16402 out some problems to watch for when upgrading. Also, perhaps your
16403 @command{configure} scripts could benefit from some of the new features in
16404 version 2; the changes are summarized in the file @file{NEWS} in the
16405 Autoconf distribution.
16408 * Changed File Names:: Files you might rename
16409 * Changed Makefiles:: New things to put in @file{Makefile.in}
16410 * Changed Macros:: Macro calls you might replace
16411 * Changed Results:: Changes in how to check test results
16412 * Changed Macro Writing:: Better ways to write your own macros
16415 @node Changed File Names
16416 @subsection Changed File Names
16418 If you have an @file{aclocal.m4} installed with Autoconf (as opposed to
16419 in a particular package's source directory), you must rename it to
16420 @file{acsite.m4}. @xref{autoconf Invocation}.
16422 If you distribute @file{install.sh} with your package, rename it to
16423 @file{install-sh} so @code{make} builtin rules won't inadvertently
16424 create a file called @file{install} from it. @code{AC_PROG_INSTALL}
16425 looks for the script under both names, but it is best to use the new name.
16427 If you were using @file{config.h.top}, @file{config.h.bot}, or
16428 @file{acconfig.h}, you still can, but you will have less clutter if you
16429 use the @code{AH_} macros. @xref{Autoheader Macros}.
16431 @node Changed Makefiles
16432 @subsection Changed Makefiles
16434 Add @samp{@@CFLAGS@@}, @samp{@@CPPFLAGS@@}, and @samp{@@LDFLAGS@@} in
16435 your @file{Makefile.in} files, so they can take advantage of the values
16436 of those variables in the environment when @command{configure} is run.
16437 Doing this isn't necessary, but it's a convenience for users.
16439 Also add @samp{@@configure_input@@} in a comment to each input file for
16440 @code{AC_OUTPUT}, so that the output files will contain a comment saying
16441 they were produced by @command{configure}. Automatically selecting the
16442 right comment syntax for all the kinds of files that people call
16443 @code{AC_OUTPUT} on became too much work.
16445 Add @file{config.log} and @file{config.cache} to the list of files you
16446 remove in @code{distclean} targets.
16448 If you have the following in @file{Makefile.in}:
16451 prefix = /usr/local
16452 exec_prefix = $(prefix)
16456 you must change it to:
16459 prefix = @@prefix@@
16460 exec_prefix = @@exec_prefix@@
16464 The old behavior of replacing those variables without @samp{@@}
16465 characters around them has been removed.
16467 @node Changed Macros
16468 @subsection Changed Macros
16470 Many of the macros were renamed in Autoconf version 2. You can still
16471 use the old names, but the new ones are clearer, and it's easier to find
16472 the documentation for them. @xref{Obsolete Macros}, for a table showing the
16473 new names for the old macros. Use the @command{autoupdate} program to
16474 convert your @file{configure.ac} to using the new macro names.
16475 @xref{autoupdate Invocation}.
16477 Some macros have been superseded by similar ones that do the job better,
16478 but are not call-compatible. If you get warnings about calling obsolete
16479 macros while running @command{autoconf}, you may safely ignore them, but
16480 your @command{configure} script will generally work better if you follow
16481 the advice that is printed about what to replace the obsolete macros with. In
16482 particular, the mechanism for reporting the results of tests has
16483 changed. If you were using @command{echo} or @code{AC_VERBOSE} (perhaps
16484 via @code{AC_COMPILE_CHECK}), your @command{configure} script's output will
16485 look better if you switch to @code{AC_MSG_CHECKING} and
16486 @code{AC_MSG_RESULT}. @xref{Printing Messages}. Those macros work best
16487 in conjunction with cache variables. @xref{Caching Results}.
16491 @node Changed Results
16492 @subsection Changed Results
16494 If you were checking the results of previous tests by examining the
16495 shell variable @code{DEFS}, you need to switch to checking the values of
16496 the cache variables for those tests. @code{DEFS} no longer exists while
16497 @command{configure} is running; it is only created when generating output
16498 files. This difference from version 1 is because properly quoting the
16499 contents of that variable turned out to be too cumbersome and
16500 inefficient to do every time @code{AC_DEFINE} is called. @xref{Cache
16503 For example, here is a @file{configure.ac} fragment written for Autoconf
16507 AC_HAVE_FUNCS(syslog)
16509 *-DHAVE_SYSLOG*) ;;
16510 *) # syslog is not in the default libraries. See if it's in some other.
16512 for lib in bsd socket inet; do
16513 AC_CHECKING(for syslog in -l$lib)
16514 LIBS="-l$lib $saved_LIBS"
16515 AC_HAVE_FUNCS(syslog)
16517 *-DHAVE_SYSLOG*) break ;;
16525 Here is a way to write it for version 2:
16528 AC_CHECK_FUNCS([syslog])
16529 if test $ac_cv_func_syslog = no; then
16530 # syslog is not in the default libraries. See if it's in some other.
16531 for lib in bsd socket inet; do
16532 AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG])
16533 LIBS="-l$lib $LIBS"; break])
16538 If you were working around bugs in @code{AC_DEFINE_UNQUOTED} by adding
16539 backslashes before quotes, you need to remove them. It now works
16540 predictably, and does not treat quotes (except back quotes) specially.
16541 @xref{Setting Output Variables}.
16543 All of the Boolean shell variables set by Autoconf macros now use
16544 @samp{yes} for the true value. Most of them use @samp{no} for false,
16545 though for backward compatibility some use the empty string instead. If
16546 you were relying on a shell variable being set to something like 1 or
16547 @samp{t} for true, you need to change your tests.
16549 @node Changed Macro Writing
16550 @subsection Changed Macro Writing
16552 When defining your own macros, you should now use @code{AC_DEFUN}
16553 instead of @code{define}. @code{AC_DEFUN} automatically calls
16554 @code{AC_PROVIDE} and ensures that macros called via @code{AC_REQUIRE}
16555 do not interrupt other macros, to prevent nested @samp{checking@dots{}}
16556 messages on the screen. There's no actual harm in continuing to use the
16557 older way, but it's less convenient and attractive. @xref{Macro
16560 You probably looked at the macros that came with Autoconf as a guide for
16561 how to do things. It would be a good idea to take a look at the new
16562 versions of them, as the style is somewhat improved and they take
16563 advantage of some new features.
16565 If you were doing tricky things with undocumented Autoconf internals
16566 (macros, variables, diversions), check whether you need to change
16567 anything to account for changes that have been made. Perhaps you can
16568 even use an officially supported technique in version 2 instead of
16569 kludging. Or perhaps not.
16571 To speed up your locally written feature tests, add caching to them.
16572 See whether any of your tests are of general enough usefulness to
16573 encapsulate them into macros that you can share.
16576 @node Autoconf 2.13
16577 @section Upgrading From Version 2.13
16578 @cindex Upgrading autoconf
16579 @cindex Autoconf upgrading
16581 The introduction of the previous section (@pxref{Autoconf 1}) perfectly
16582 suits this section@enddots{}
16585 Autoconf version 2.50 is mostly backward compatible with version 2.13.
16586 However, it introduces better ways to do some things, and doesn't
16587 support some of the ugly things in version 2.13. So, depending on how
16588 sophisticated your @file{configure.ac} files are, you might have to do
16589 some manual work in order to upgrade to version 2.50. This chapter
16590 points out some problems to watch for when upgrading. Also, perhaps
16591 your @command{configure} scripts could benefit from some of the new
16592 features in version 2.50; the changes are summarized in the file
16593 @file{NEWS} in the Autoconf distribution.
16597 * Changed Quotation:: Broken code which used to work
16598 * New Macros:: Interaction with foreign macros
16599 * Hosts and Cross-Compilation:: Bugward compatibility kludges
16600 * AC_LIBOBJ vs LIBOBJS:: LIBOBJS is a forbidden token
16601 * AC_FOO_IFELSE vs AC_TRY_FOO:: A more generic scheme for testing sources
16604 @node Changed Quotation
16605 @subsection Changed Quotation
16607 The most important changes are invisible to you: the implementation of
16608 most macros have completely changed. This allowed more factorization of
16609 the code, better error messages, a higher uniformity of the user's
16610 interface etc. Unfortunately, as a side effect, some construct which
16611 used to (miraculously) work might break starting with Autoconf 2.50.
16612 The most common culprit is bad quotation.
16614 For instance, in the following example, the message is not properly
16619 AC_CHECK_HEADERS(foo.h, ,
16620 AC_MSG_ERROR(cannot find foo.h, bailing out))
16625 Autoconf 2.13 simply ignores it:
16628 $ @kbd{autoconf-2.13; ./configure --silent}
16629 creating cache ./config.cache
16630 configure: error: cannot find foo.h
16635 while Autoconf 2.50 will produce a broken @file{configure}:
16638 $ @kbd{autoconf-2.50; ./configure --silent}
16639 configure: error: cannot find foo.h
16640 ./configure: exit: bad non-numeric arg `bailing'
16641 ./configure: exit: bad non-numeric arg `bailing'
16645 The message needs to be quoted, and the @code{AC_MSG_ERROR} invocation
16649 AC_INIT([Example], [1.0], [bug-example@@example.org])
16650 AC_CHECK_HEADERS([foo.h], [],
16651 [AC_MSG_ERROR([cannot find foo.h, bailing out])])
16655 Many many (and many more) Autoconf macros were lacking proper quotation,
16656 including no less than@dots{} @code{AC_DEFUN} itself!
16659 $ @kbd{cat configure.in}
16660 AC_DEFUN([AC_PROG_INSTALL],
16661 [# My own much better version
16666 $ @kbd{autoconf-2.13}
16667 autoconf: Undefined macros:
16668 ***BUG in Autoconf--please report*** AC_FD_MSG
16669 ***BUG in Autoconf--please report*** AC_EPI
16670 configure.in:1:AC_DEFUN([AC_PROG_INSTALL],
16671 configure.in:5:AC_PROG_INSTALL
16672 $ @kbd{autoconf-2.50}
16678 @subsection New Macros
16680 @cindex undefined macro
16681 @cindex @code{_m4_divert_diversion}
16683 While Autoconf was relatively dormant in the late 1990s, Automake
16684 provided Autoconf-like macros for a while. Starting with Autoconf 2.50
16685 in 2001, Autoconf provided
16686 versions of these macros, integrated in the @code{AC_} namespace,
16687 instead of @code{AM_}. But in order to ease the upgrading via
16688 @command{autoupdate}, bindings to such @code{AM_} macros are provided.
16690 Unfortunately older versions of Automake (e.g., Automake 1.4)
16691 did not quote the names of these macros.
16692 Therefore, when @command{m4} finds something like
16693 @samp{AC_DEFUN(AM_TYPE_PTRDIFF_T, @dots{})} in @file{aclocal.m4},
16694 @code{AM_TYPE_PTRDIFF_T} is
16695 expanded, replaced with its Autoconf definition.
16697 Fortunately Autoconf catches pre-@code{AC_INIT} expansions, and will
16698 complain, in its own words:
16701 $ @kbd{cat configure.ac}
16702 AC_INIT([Example], [1.0], [bug-example@@example.org])
16704 $ @kbd{aclocal-1.4}
16706 aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversion
16707 aclocal.m4:17: the top level
16708 autom4te: m4 failed with exit status: 1
16712 Modern versions of Automake no longer define most of these
16713 macros, and will properly quote the names of the remaining macros.
16714 If you must use an old Automake, do not depend upon macros from Automake
16715 as it is simply not its job
16716 to provide macros (but the one it requires itself):
16719 $ @kbd{cat configure.ac}
16720 AC_INIT([Example], [1.0], [bug-example@@example.org])
16722 $ @kbd{rm aclocal.m4}
16724 autoupdate: `configure.ac' is updated
16725 $ @kbd{cat configure.ac}
16726 AC_INIT([Example], [1.0], [bug-example@@example.org])
16727 AC_CHECK_TYPES([ptrdiff_t])
16728 $ @kbd{aclocal-1.4}
16734 @node Hosts and Cross-Compilation
16735 @subsection Hosts and Cross-Compilation
16736 @cindex Cross compilation
16738 Based on the experience of compiler writers, and after long public
16739 debates, many aspects of the cross-compilation chain have changed:
16743 the relationship between the build, host, and target architecture types,
16746 the command line interface for specifying them to @command{configure},
16749 the variables defined in @command{configure},
16752 the enabling of cross-compilation mode.
16757 The relationship between build, host, and target have been cleaned up:
16758 the chain of default is now simply: target defaults to host, host to
16759 build, and build to the result of @command{config.guess}. Nevertheless,
16760 in order to ease the transition from 2.13 to 2.50, the following
16761 transition scheme is implemented. @emph{Do not rely on it}, as it will
16762 be completely disabled in a couple of releases (we cannot keep it, as it
16763 proves to cause more problems than it cures).
16765 They all default to the result of running @command{config.guess}, unless
16766 you specify either @option{--build} or @option{--host}. In this case,
16767 the default becomes the system type you specified. If you specify both,
16768 and they're different, @command{configure} will enter cross compilation
16769 mode, so it won't run any tests that require execution.
16771 Hint: if you mean to override the result of @command{config.guess},
16772 prefer @option{--build} over @option{--host}. In the future,
16773 @option{--host} will not override the name of the build system type.
16774 Whenever you specify @code{--host}, be sure to specify @code{--build}
16779 For backward compatibility, @command{configure} will accept a system
16780 type as an option by itself. Such an option will override the
16781 defaults for build, host, and target system types. The following
16782 configure statement will configure a cross toolchain that will run on
16783 Net@acronym{BSD}/alpha but generate code for @acronym{GNU} Hurd/sparc, which is
16784 also the build platform.
16787 ./configure --host=alpha-netbsd sparc-gnu
16792 In Autoconf 2.13 and before, the variables @code{build}, @code{host},
16793 and @code{target} had a different semantics before and after the
16794 invocation of @code{AC_CANONICAL_BUILD} etc. Now, the argument of
16795 @option{--build} is strictly copied into @code{build_alias}, and is left
16796 empty otherwise. After the @code{AC_CANONICAL_BUILD}, @code{build} is
16797 set to the canonicalized build type. To ease the transition, before,
16798 its contents is the same as that of @code{build_alias}. Do @emph{not}
16799 rely on this broken feature.
16801 For consistency with the backward compatibility scheme exposed above,
16802 when @option{--host} is specified but @option{--build} isn't, the build
16803 system will be assumed to be the same as @option{--host}, and
16804 @samp{build_alias} will be set to that value. Eventually, this
16805 historically incorrect behavior will go away.
16809 The former scheme to enable cross-compilation proved to cause more harm
16810 than good, in particular, it used to be triggered too easily, leaving
16811 regular end users puzzled in front of cryptic error messages.
16812 @command{configure} could even enter cross-compilation mode only
16813 because the compiler was not functional. This is mainly because
16814 @command{configure} used to try to detect cross-compilation, instead of
16815 waiting for an explicit flag from the user.
16817 Now, @command{configure} enters cross-compilation mode if and only if
16818 @option{--host} is passed.
16820 That's the short documentation. To ease the transition between 2.13 and
16821 its successors, a more complicated scheme is implemented. @emph{Do not
16822 rely on the following}, as it will be removed in the near future.
16824 If you specify @option{--host}, but not @option{--build}, when
16825 @command{configure} performs the first compiler test it will try to run
16826 an executable produced by the compiler. If the execution fails, it will
16827 enter cross-compilation mode. This is fragile. Moreover, by the time
16828 the compiler test is performed, it may be too late to modify the
16829 build-system type: other tests may have already been performed.
16830 Therefore, whenever you specify @code{--host}, be sure to specify
16831 @code{--build} too.
16834 ./configure --build=i686-pc-linux-gnu --host=m68k-coff
16838 will enter cross-compilation mode. The former interface, which
16839 consisted in setting the compiler to a cross-compiler without informing
16840 @command{configure} is obsolete. For instance, @command{configure} will
16841 fail if it can't run the code generated by the specified compiler if you
16842 configure as follows:
16845 ./configure CC=m68k-coff-gcc
16849 @node AC_LIBOBJ vs LIBOBJS
16850 @subsection @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}
16852 Up to Autoconf 2.13, the replacement of functions was triggered via the
16853 variable @code{LIBOBJS}. Since Autoconf 2.50, the macro
16854 @code{AC_LIBOBJ} should be used instead (@pxref{Generic Functions}).
16855 Starting at Autoconf 2.53, the use of @code{LIBOBJS} is an error.
16857 This change is mandated by the unification of the @acronym{GNU} Build System
16858 components. In particular, the various fragile techniques used to parse
16859 a @file{configure.ac} are all replaced with the use of traces. As a
16860 consequence, any action must be traceable, which obsoletes critical
16861 variable assignments. Fortunately, @code{LIBOBJS} was the only problem,
16862 and it can even be handled gracefully (read, ``without your having to
16863 change something'').
16865 There were two typical uses of @code{LIBOBJS}: asking for a replacement
16866 function, and adjusting @code{LIBOBJS} for Automake and/or Libtool.
16870 As for function replacement, the fix is immediate: use
16871 @code{AC_LIBOBJ}. For instance:
16874 LIBOBJS="$LIBOBJS fnmatch.o"
16875 LIBOBJS="$LIBOBJS malloc.$ac_objext"
16879 should be replaced with:
16882 AC_LIBOBJ([fnmatch])
16883 AC_LIBOBJ([malloc])
16889 When used with Automake 1.10 or newer, a suitable value for
16890 @code{LIBOBJDIR} is set so that the @code{LIBOBJS} and @code{LTLIBOBJS}
16891 can be referenced from any @file{Makefile.am}. Even without Automake,
16892 arranging for @code{LIBOBJDIR} to be set correctly will enable
16893 referencing @code{LIBOBJS} and @code{LTLIBOBJS} in another directory.
16894 The @code{LIBOJBDIR} feature is experimental.
16897 @node AC_FOO_IFELSE vs AC_TRY_FOO
16898 @subsection @code{AC_FOO_IFELSE} vs.@: @code{AC_TRY_FOO}
16900 Since Autoconf 2.50, internal codes uses @code{AC_PREPROC_IFELSE},
16901 @code{AC_COMPILE_IFELSE}, @code{AC_LINK_IFELSE}, and
16902 @code{AC_RUN_IFELSE} on one hand and @code{AC_LANG_SOURCES},
16903 and @code{AC_LANG_PROGRAM} on the other hand instead of the deprecated
16904 @code{AC_TRY_CPP}, @code{AC_TRY_COMPILE}, @code{AC_TRY_LINK}, and
16905 @code{AC_TRY_RUN}. The motivations where:
16908 a more consistent interface: @code{AC_TRY_COMPILE} etc.@: were double
16909 quoting their arguments;
16912 the combinatoric explosion is solved by decomposing on the one hand the
16913 generation of sources, and on the other hand executing the program;
16916 this scheme helps supporting more languages than plain C and C++.
16919 In addition to the change of syntax, the philosophy has changed too:
16920 while emphasis was put on speed at the expense of accuracy, today's
16921 Autoconf promotes accuracy of the testing framework at, ahem@dots{}, the
16925 As a perfect example of what is @emph{not} to be done, here is how to
16926 find out whether a header file contains a particular declaration, such
16927 as a typedef, a structure, a structure member, or a function. Use
16928 @code{AC_EGREP_HEADER} instead of running @code{grep} directly on the
16929 header file; on some systems the symbol might be defined in another
16930 header file that the file you are checking @samp{#include}s.
16932 As a (bad) example, here is how you should not check for C preprocessor
16933 symbols, either defined by header files or predefined by the C
16934 preprocessor: using @code{AC_EGREP_CPP}:
16942 ], is_aix=yes, is_aix=no)
16946 The above example, properly written would (i) use
16947 @code{AC_LANG_PROGRAM}, and (ii) run the compiler:
16951 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
16952 [[#if !defined _AIX
16953 error: This isn't AIX!
16962 @c ============================= Generating Test Suites with Autotest
16964 @node Using Autotest
16965 @chapter Generating Test Suites with Autotest
16970 @strong{N.B.: This section describes an experimental feature which will
16971 be part of Autoconf in a forthcoming release. Although we believe
16972 Autotest is stabilizing, this documentation describes an interface which
16973 might change in the future: do not depend upon Autotest without
16974 subscribing to the Autoconf mailing lists.}
16977 It is paradoxical that portable projects depend on nonportable tools
16978 to run their test suite. Autoconf by itself is the paragon of this
16979 problem: although it aims at perfectly portability, up to 2.13 its
16980 test suite was using Deja@acronym{GNU}, a rich and complex testing
16981 framework, but which is far from being standard on Posix systems.
16982 Worse yet, it was likely to be missing on the most fragile platforms,
16983 the very platforms that are most likely to torture Autoconf and
16984 exhibit deficiencies.
16986 To circumvent this problem, many package maintainers have developed their
16987 own testing framework, based on simple shell scripts whose sole outputs
16988 are exit status values describing whether the test succeeded. Most of
16989 these tests share common patterns, and this can result in lots of
16990 duplicated code and tedious maintenance.
16992 Following exactly the same reasoning that yielded to the inception of
16993 Autoconf, Autotest provides a test suite generation framework, based on
16994 M4 macros building a portable shell script. The suite itself is
16995 equipped with automatic logging and tracing facilities which greatly
16996 diminish the interaction with bug reporters, and simple timing reports.
16998 Autoconf itself has been using Autotest for years, and we do attest that
16999 it has considerably improved the strength of the test suite and the
17000 quality of bug reports. Other projects are known to use some generation
17001 of Autotest, such as Bison, Free Recode, Free Wdiff, @acronym{GNU} Tar, each of
17002 them with different needs, and this usage has validated Autotest as a general
17005 Nonetheless, compared to Deja@acronym{GNU}, Autotest is inadequate for
17006 interactive tool testing, which is probably its main limitation.
17009 * Using an Autotest Test Suite:: Autotest and the user
17010 * Writing testsuite.at:: Autotest macros
17011 * testsuite Invocation:: Running @command{testsuite} scripts
17012 * Making testsuite Scripts:: Using autom4te to create @command{testsuite}
17015 @node Using an Autotest Test Suite
17016 @section Using an Autotest Test Suite
17019 * testsuite Scripts:: The concepts of Autotest
17020 * Autotest Logs:: Their contents
17023 @node testsuite Scripts
17024 @subsection @command{testsuite} Scripts
17026 @cindex @command{testsuite}
17028 Generating testing or validation suites using Autotest is rather easy.
17029 The whole validation suite is held in a file to be processed through
17030 @command{autom4te}, itself using @acronym{GNU} M4 under the scene, to
17031 produce a stand-alone Bourne shell script which then gets distributed.
17032 Neither @command{autom4te} nor @acronym{GNU} M4 are needed at
17033 the installer's end.
17036 Each test of the validation suite should be part of some test group. A
17037 @dfn{test group} is a sequence of interwoven tests that ought to be
17038 executed together, usually because one test in the group creates data
17039 files than a later test in the same group needs to read. Complex test
17040 groups make later debugging more tedious. It is much better to
17041 keep only a few tests per test group. Ideally there is only one test
17044 For all but the simplest packages, some file such as @file{testsuite.at}
17045 does not fully hold all test sources, as these are often easier to
17046 maintain in separate files. Each of these separate files holds a single
17047 test group, or a sequence of test groups all addressing some common
17048 functionality in the package. In such cases, @file{testsuite.at}
17049 merely initializes the validation suite, and sometimes does elementary
17050 health checking, before listing include statements for all other test
17051 files. The special file @file{package.m4}, containing the
17052 identification of the package, is automatically included if found.
17054 A convenient alternative consists in moving all the global issues
17055 (local Autotest macros, elementary health checking, and @code{AT_INIT}
17056 invocation) into the file @code{local.at}, and making
17057 @file{testsuite.at} be a simple list of @code{m4_include} of sub test
17058 suites. In such case, generating the whole test suite or pieces of it
17059 is only a matter of choosing the @command{autom4te} command line
17062 The validation scripts that Autotest produces are by convention called
17063 @command{testsuite}. When run, @command{testsuite} executes each test
17064 group in turn, producing only one summary line per test to say if that
17065 particular test succeeded or failed. At end of all tests, summarizing
17066 counters get printed. One debugging directory is left for each test
17067 group which failed, if any: such directories are named
17068 @file{testsuite.dir/@var{nn}}, where @var{nn} is the sequence number of
17069 the test group, and they include:
17072 @item a debugging script named @file{run} which reruns the test in
17073 @dfn{debug mode} (@pxref{testsuite Invocation}). The automatic generation
17074 of debugging scripts has the purpose of easing the chase for bugs.
17076 @item all the files created with @code{AT_DATA}
17078 @item a log of the run, named @file{testsuite.log}
17081 In the ideal situation, none of the tests fail, and consequently no
17082 debugging directory is left behind for validation.
17084 It often happens in practice that individual tests in the validation
17085 suite need to get information coming out of the configuration process.
17086 Some of this information, common for all validation suites, is provided
17087 through the file @file{atconfig}, automatically created by
17088 @code{AC_CONFIG_TESTDIR}. For configuration informations which your
17089 testing environment specifically needs, you might prepare an optional
17090 file named @file{atlocal.in}, instantiated by @code{AC_CONFIG_FILES}.
17091 The configuration process produces @file{atconfig} and @file{atlocal}
17092 out of these two input files, and these two produced files are
17093 automatically read by the @file{testsuite} script.
17095 Here is a diagram showing the relationship between files.
17098 Files used in preparing a software package for distribution:
17103 subfile-1.at ->. [local.at] ---->+
17105 subfile-i.at ---->-- testsuite.at -->-- autom4te* -->testsuite
17111 Files used in configuring a software package:
17116 [atlocal.in] --> config.status* --<
17122 Files created during the test suite execution:
17125 atconfig -->. .--> testsuite.log
17129 [atlocal] ->' `--> [testsuite.dir]
17133 @node Autotest Logs
17134 @subsection Autotest Logs
17136 When run, the test suite creates a log file named after itself, e.g., a
17137 test suite named @command{testsuite} creates @file{testsuite.log}. It
17138 contains a lot of information, usually more than maintainers actually
17139 need, but therefore most of the time it contains all that is needed:
17142 @item command line arguments
17143 @c akim s/to consist in/to consist of/
17144 A very bad but unfortunately widespread Posix habit consists of
17145 setting environment variables before the command, such as in
17146 @samp{CC=my-home-grown-cc ./testsuite}. The test suite will not
17147 know this change, hence (i) it cannot report it to you, and (ii)
17148 it cannot preserve the value of @code{CC} for subsequent runs.
17149 Autoconf faced exactly the same problem, and solved it by asking
17150 users to pass the variable definitions as command line arguments.
17151 Autotest requires this rule, too, but has no means to enforce it; the log
17152 then contains a trace of the variables that were changed by the user.
17154 @item @file{ChangeLog} excerpts
17155 The topmost lines of all the @file{ChangeLog}s found in the source
17156 hierarchy. This is especially useful when bugs are reported against
17157 development versions of the package, since the version string does not
17158 provide sufficient information to know the exact state of the sources
17159 the user compiled. Of course, this relies on the use of a
17162 @item build machine
17163 Running a test suite in a cross-compile environment is not an easy task,
17164 since it would mean having the test suite run on a machine @var{build},
17165 while running programs on a machine @var{host}. It is much simpler to
17166 run both the test suite and the programs on @var{host}, but then, from
17167 the point of view of the test suite, there remains a single environment,
17168 @var{host} = @var{build}. The log contains relevant information on the
17169 state of the build machine, including some important environment
17171 @c FIXME: How about having an M4sh macro to say `hey, log the value
17172 @c of `@dots{}'? This would help both Autoconf and Autotest.
17174 @item tested programs
17175 The absolute file name and answers to @option{--version} of the tested
17176 programs (see @ref{Writing testsuite.at}, @code{AT_TESTED}).
17178 @item configuration log
17179 The contents of @file{config.log}, as created by @command{configure},
17180 are appended. It contains the configuration flags and a detailed report
17181 on the configuration itself.
17185 @node Writing testsuite.at
17186 @section Writing @file{testsuite.at}
17188 The @file{testsuite.at} is a Bourne shell script making use of special
17189 Autotest M4 macros. It often contains a call to @code{AT_INIT} near
17190 its beginning followed by one call to @code{m4_include} per source file
17191 for tests. Each such included file, or the remainder of
17192 @file{testsuite.at} if include files are not used, contain a sequence of
17193 test groups. Each test group begins with a call to @code{AT_SETUP},
17194 then an arbitrary number of shell commands or calls to @code{AT_CHECK},
17195 and then completes with a call to @code{AT_CLEANUP}.
17197 @defmac AT_INIT (@ovar{name})
17199 @c FIXME: Not clear, plus duplication of the information.
17200 Initialize Autotest. Giving a @var{name} to the test suite is
17201 encouraged if your package includes several test suites. In any case,
17202 the test suite always displays the package name and version. It also
17203 inherits the package bug report address.
17206 @defmac AT_COPYRIGHT (@var{copyright-notice})
17207 @atindex{COPYRIGHT}
17208 @cindex Copyright Notice
17209 State that, in addition to the Free Software Foundation's copyright on
17210 the Autotest macros, parts of your test suite are covered by
17211 @var{copyright-notice}.
17213 The @var{copyright-notice} will show up in both the head of
17214 @command{testsuite} and in @samp{testsuite --version}.
17217 @defmac AT_TESTED (@var{executables})
17219 Log the file name and answer to @option{--version} of each program in
17220 space-separated list @var{executables}. Several invocations register
17221 new executables, in other words, don't fear registering one program
17225 Autotest test suites rely on @env{PATH} to find the tested program.
17226 This avoids the need to generate absolute names of the various tools, and
17227 makes it possible to test installed programs. Therefore, knowing which
17228 programs are being exercised is crucial to understanding problems in
17229 the test suite itself, or its occasional misuses. It is a good idea to
17230 also subscribe foreign programs you depend upon, to avoid incompatible
17235 @defmac AT_SETUP (@var{test-group-name})
17237 This macro starts a group of related tests, all to be executed in the
17238 same subshell. It accepts a single argument, which holds a few words
17239 (no more than about 30 or 40 characters) quickly describing the purpose
17240 of the test group being started.
17243 @defmac AT_KEYWORDS (@var{keywords})
17245 Associate the space-separated list of @var{keywords} to the enclosing
17246 test group. This makes it possible to run ``slices'' of the test suite.
17247 For instance, if some of your test groups exercise some @samp{foo}
17248 feature, then using @samp{AT_KEYWORDS(foo)} lets you run
17249 @samp{./testsuite -k foo} to run exclusively these test groups. The
17250 @var{title} of the test group is automatically recorded to
17251 @code{AT_KEYWORDS}.
17253 Several invocations within a test group accumulate new keywords. In
17254 other words, don't fear registering the same keyword several times in a
17258 @defmac AT_CAPTURE_FILE (@var{file})
17259 @atindex{CAPTURE_FILE}
17260 If the current test group fails, log the contents of @var{file}.
17261 Several identical calls within one test group have no additional effect.
17264 @defmac AT_XFAIL_IF (@var{shell-condition})
17266 Determine whether the test is expected to fail because it is a known
17267 bug (for unsupported features, you should skip the test).
17268 @var{shell-condition} is a shell expression such as a @code{test}
17269 command; you can instantiate this macro many times from within the
17270 same test group, and one of the conditions will be enough to turn
17271 the test into an expected failure.
17276 End the current test group.
17281 @defmac AT_DATA (@var{file}, @var{contents})
17283 Initialize an input data @var{file} with given @var{contents}. Of
17284 course, the @var{contents} have to be properly quoted between square
17285 brackets to protect against included commas or spurious M4
17286 expansion. The contents ought to end with an end of line.
17289 @defmac AT_CHECK (@var{commands}, @dvar{status, @samp{0}}, @dvar{stdout, @samp{}}, @dvar{stderr, @samp{}}, @ovar{run-if-fail}, @ovar{run-if-pass})
17291 Execute a test by performing given shell @var{commands}. These commands
17292 should normally exit with @var{status}, while producing expected
17293 @var{stdout} and @var{stderr} contents. If @var{commands} exit with
17294 status 77, then the whole test group is skipped. Otherwise, if this test
17295 fails, run shell commands @var{run-if-fail} or, if this test passes, run shell
17296 commands @var{run-if-pass}.
17298 The @var{commands} @emph{must not} redirect the standard output, nor the
17301 If @var{status}, or @var{stdout}, or @var{stderr} is @samp{ignore}, then
17302 the corresponding value is not checked.
17304 The special value @samp{expout} for @var{stdout} means the expected
17305 output of the @var{commands} is the content of the file @file{expout}.
17306 If @var{stdout} is @samp{stdout}, then the standard output of the
17307 @var{commands} is available for further tests in the file @file{stdout}.
17308 Similarly for @var{stderr} with @samp{expout} and @samp{stderr}.
17312 @node testsuite Invocation
17313 @section Running @command{testsuite} Scripts
17314 @cindex @command{testsuite}
17316 Autotest test suites support the following arguments:
17321 Display the list of options and exit successfully.
17325 Display the version of the test suite and exit successfully.
17329 Remove all the files the test suite might have created and exit. Meant
17330 for @code{clean} Makefile targets.
17334 List all the tests (or only the selection), including their possible
17340 By default all tests are performed (or described with
17341 @option{--list}) in the default environment first silently, then
17342 verbosely, but the environment, set of tests, and verbosity level can be
17346 @item @var{variable}=@var{value}
17347 Set the environment @var{variable} to @var{value}. Use this rather
17348 than @samp{FOO=foo ./testsuite} as debugging scripts would then run in a
17349 different environment.
17351 @cindex @code{AUTOTEST_PATH}
17352 The variable @code{AUTOTEST_PATH} specifies the testing path to prepend
17353 to @env{PATH}. Relative directory names (not starting with
17354 @samp{/}) are considered to be relative to the top level of the
17355 package being built. All directories are made absolute, first
17356 starting from the top level @emph{build} tree, then from the
17357 @emph{source} tree. For instance @samp{./testsuite
17358 AUTOTEST_PATH=tests:bin} for a @file{/src/foo-1.0} source package built
17359 in @file{/tmp/foo} results in @samp{/tmp/foo/tests:/tmp/foo/bin} and
17360 then @samp{/src/foo-1.0/tests:/src/foo-1.0/bin} being prepended to
17364 @itemx @var{number}-@var{number}
17365 @itemx @var{number}-
17366 @itemx -@var{number}
17367 Add the corresponding test groups, with obvious semantics, to the
17370 @item --keywords=@var{keywords}
17371 @itemx -k @var{keywords}
17372 Add to the selection the test groups with title or keywords (arguments
17373 to @code{AT_SETUP} or @code{AT_KEYWORDS}) that match @emph{all} keywords
17374 of the comma separated list @var{keywords}, case-insensitively. Use
17375 @samp{!} immediately before the keyword to invert the selection for this
17376 keyword. By default, the keywords match whole words; enclose them in
17377 @samp{.*} to also match parts of words.
17379 For example, running
17382 @kbd{./testsuite -k 'autoupdate,.*FUNC.*'}
17386 will select all tests tagged @samp{autoupdate} @emph{and} with tags
17387 containing @samp{FUNC} (as in @samp{AC_CHECK_FUNC}, @samp{AC_FUNC_FNMATCH},
17391 @kbd{./testsuite -k '!autoupdate' -k '.*FUNC.*'}
17395 will select all tests not tagged @samp{autoupdate} @emph{or} with tags
17396 containing @samp{FUNC}.
17400 If any test fails, immediately abort testing. It implies
17401 @option{--debug}: post test group clean up, and top-level logging
17402 are inhibited. This option is meant for the full test
17403 suite, it is not really useful for generated debugging scripts.
17407 Force more verbosity in the detailed output of what is being done. This
17408 is the default for debugging scripts.
17412 Do not remove the files after a test group was performed ---but they are
17413 still removed @emph{before}, therefore using this option is sane when
17414 running several test groups. Create debugging scripts. Do not
17415 overwrite the top-level
17416 log (in order to preserve supposedly existing full log file). This is
17417 the default for debugging scripts, but it can also be useful to debug
17418 the testsuite itself.
17422 Trigger shell tracing of the test groups.
17426 @node Making testsuite Scripts
17427 @section Making @command{testsuite} Scripts
17429 For putting Autotest into movement, you need some configuration and
17430 Makefile machinery. We recommend, at least if your package uses deep or
17431 shallow hierarchies, that you use @file{tests/} as the name of the
17432 directory holding all your tests and their @file{Makefile}. Here is a
17433 check list of things to do.
17438 @cindex @file{package.m4}
17439 Make sure to create the file @file{package.m4}, which defines the
17440 identity of the package. It must define @code{AT_PACKAGE_STRING}, the
17441 full signature of the package, and @code{AT_PACKAGE_BUGREPORT}, the
17442 address to which bug reports should be sent. For sake of completeness,
17443 we suggest that you also define @code{AT_PACKAGE_NAME},
17444 @code{AT_PACKAGE_TARNAME}, and @code{AT_PACKAGE_VERSION}.
17445 @xref{Initializing configure}, for a description of these variables. We
17446 suggest the following Makefile excerpt:
17449 $(srcdir)/package.m4: $(top_srcdir)/configure.ac
17451 echo '# Signature of the current package.'; \
17452 echo 'm4_define([AT_PACKAGE_NAME], [@@PACKAGE_NAME@@])'; \
17453 echo 'm4_define([AT_PACKAGE_TARNAME], [@@PACKAGE_TARNAME@@])'; \
17454 echo 'm4_define([AT_PACKAGE_VERSION], [@@PACKAGE_VERSION@@])'; \
17455 echo 'm4_define([AT_PACKAGE_STRING], [@@PACKAGE_STRING@@])'; \
17456 echo 'm4_define([AT_PACKAGE_BUGREPORT], [@@PACKAGE_BUGREPORT@@])'; \
17457 @} >$(srcdir)/package.m4
17461 Be sure to distribute @file{package.m4} and to put it into the source
17462 hierarchy: the test suite ought to be shipped!
17465 Invoke @code{AC_CONFIG_TESTDIR}.
17467 @defmac AC_CONFIG_TESTDIR (@var{directory}, @dvar{test-path, @var{directory}})
17468 @acindex{CONFIG_TESTDIR}
17469 An Autotest test suite is to be configured in @var{directory}. This
17470 macro requires the instantiation of @file{@var{directory}/atconfig} from
17471 @file{@var{directory}/atconfig.in}, and sets the default
17472 @code{AUTOTEST_PATH} to @var{test-path} (@pxref{testsuite Invocation}).
17476 Still within @file{configure.ac}, as appropriate, ensure that some
17477 @code{AC_CONFIG_FILES} command includes substitution for
17478 @file{tests/atlocal}.
17481 The @file{tests/Makefile.in} should be modified so the validation in
17482 your package is triggered by @samp{make check}. An example is provided
17486 With Automake, here is a minimal example about how to link @samp{make
17487 check} with a validation suite.
17490 EXTRA_DIST = testsuite.at $(TESTSUITE) atlocal.in
17491 TESTSUITE = $(srcdir)/testsuite
17493 check-local: atconfig atlocal $(TESTSUITE)
17494 $(SHELL) $(TESTSUITE) $(TESTSUITEFLAGS)
17496 installcheck-local: atconfig atlocal $(TESTSUITE)
17497 $(SHELL) $(TESTSUITE) AUTOTEST_PATH="$(bindir)" \
17500 AUTOTEST = $(AUTOM4TE) --language=autotest
17501 $(TESTSUITE): $(srcdir)/testsuite.at
17502 $(AUTOTEST) -I $(srcdir) -o $@@.tmp $@@.at
17506 You might want to list explicitly the dependencies, i.e., the list of
17507 the files @file{testsuite.at} includes.
17509 With strict Autoconf, you might need to add lines inspired from the
17515 atconfig: $(top_builddir)/config.status
17516 cd $(top_builddir) && \
17517 $(SHELL) ./config.status $(subdir)/$@@
17519 atlocal: $(srcdir)/atlocal.in $(top_builddir)/config.status
17520 cd $(top_builddir) && \
17521 $(SHELL) ./config.status $(subdir)/$@@
17525 and manage to have @file{atconfig.in} and @code{$(EXTRA_DIST)}
17530 @c =============================== Frequent Autoconf Questions, with answers
17533 @chapter Frequent Autoconf Questions, with answers
17535 Several questions about Autoconf come up occasionally. Here some of them
17539 * Distributing:: Distributing @command{configure} scripts
17540 * Why GNU m4:: Why not use the standard M4?
17541 * Bootstrapping:: Autoconf and @acronym{GNU} M4 require each other?
17542 * Why Not Imake:: Why @acronym{GNU} uses @command{configure} instead of Imake
17543 * Defining Directories:: Passing @code{datadir} to program
17544 * autom4te.cache:: What is it? Can I remove it?
17545 * Present But Cannot Be Compiled:: Compiler and Preprocessor Disagree
17549 @section Distributing @command{configure} Scripts
17553 What are the restrictions on distributing @command{configure}
17554 scripts that Autoconf generates? How does that affect my
17555 programs that use them?
17558 There are no restrictions on how the configuration scripts that Autoconf
17559 produces may be distributed or used. In Autoconf version 1, they were
17560 covered by the @acronym{GNU} General Public License. We still encourage
17561 software authors to distribute their work under terms like those of the
17562 @acronym{GPL}, but doing so is not required to use Autoconf.
17564 Of the other files that might be used with @command{configure},
17565 @file{config.h.in} is under whatever copyright you use for your
17566 @file{configure.ac}. @file{config.sub} and @file{config.guess} have an
17567 exception to the @acronym{GPL} when they are used with an Autoconf-generated
17568 @command{configure} script, which permits you to distribute them under the
17569 same terms as the rest of your package. @file{install-sh} is from the X
17570 Consortium and is not copyrighted.
17573 @section Why Require @acronym{GNU} M4?
17576 Why does Autoconf require @acronym{GNU} M4?
17579 Many M4 implementations have hard-coded limitations on the size and
17580 number of macros that Autoconf exceeds. They also lack several
17581 builtin macros that it would be difficult to get along without in a
17582 sophisticated application like Autoconf, including:
17592 Autoconf requires version 1.4.3 or later of @acronym{GNU} M4.
17594 Since only software maintainers need to use Autoconf, and since @acronym{GNU}
17595 M4 is simple to configure and install, it seems reasonable to require
17596 @acronym{GNU} M4 to be installed also. Many maintainers of @acronym{GNU} and
17597 other free software already have most of the @acronym{GNU} utilities
17598 installed, since they prefer them.
17600 @node Bootstrapping
17601 @section How Can I Bootstrap?
17605 If Autoconf requires @acronym{GNU} M4 and @acronym{GNU} M4 has an Autoconf
17606 @command{configure} script, how do I bootstrap? It seems like a chicken
17610 This is a misunderstanding. Although @acronym{GNU} M4 does come with a
17611 @command{configure} script produced by Autoconf, Autoconf is not required
17612 in order to run the script and install @acronym{GNU} M4. Autoconf is only
17613 required if you want to change the M4 @command{configure} script, which few
17614 people have to do (mainly its maintainer).
17616 @node Why Not Imake
17617 @section Why Not Imake?
17621 Why not use Imake instead of @command{configure} scripts?
17624 Several people have written addressing this question, so I include
17625 adaptations of their explanations here.
17627 The following answer is based on one written by Richard Pixley:
17630 Autoconf generated scripts frequently work on machines that it has
17631 never been set up to handle before. That is, it does a good job of
17632 inferring a configuration for a new system. Imake cannot do this.
17634 Imake uses a common database of host specific data. For X11, this makes
17635 sense because the distribution is made as a collection of tools, by one
17636 central authority who has control over the database.
17638 @acronym{GNU} tools are not released this way. Each @acronym{GNU} tool has a
17639 maintainer; these maintainers are scattered across the world. Using a
17640 common database would be a maintenance nightmare. Autoconf may appear
17641 to be this kind of database, but in fact it is not. Instead of listing
17642 host dependencies, it lists program requirements.
17644 If you view the @acronym{GNU} suite as a collection of native tools, then the
17645 problems are similar. But the @acronym{GNU} development tools can be
17646 configured as cross tools in almost any host+target permutation. All of
17647 these configurations can be installed concurrently. They can even be
17648 configured to share host independent files across hosts. Imake doesn't
17649 address these issues.
17651 Imake templates are a form of standardization. The @acronym{GNU} coding
17652 standards address the same issues without necessarily imposing the same
17657 Here is some further explanation, written by Per Bothner:
17660 One of the advantages of Imake is that it easy to generate large
17661 Makefiles using @code{cpp}'s @samp{#include} and macro mechanisms.
17662 However, @code{cpp} is not programmable: it has limited conditional
17663 facilities, and no looping. And @code{cpp} cannot inspect its
17666 All of these problems are solved by using @code{sh} instead of
17667 @code{cpp}. The shell is fully programmable, has macro substitution,
17668 can execute (or source) other shell scripts, and can inspect its
17673 Paul Eggert elaborates more:
17676 With Autoconf, installers need not assume that Imake itself is already
17677 installed and working well. This may not seem like much of an advantage
17678 to people who are accustomed to Imake. But on many hosts Imake is not
17679 installed or the default installation is not working well, and requiring
17680 Imake to install a package hinders the acceptance of that package on
17681 those hosts. For example, the Imake template and configuration files
17682 might not be installed properly on a host, or the Imake build procedure
17683 might wrongly assume that all source files are in one big directory
17684 tree, or the Imake configuration might assume one compiler whereas the
17685 package or the installer needs to use another, or there might be a
17686 version mismatch between the Imake expected by the package and the Imake
17687 supported by the host. These problems are much rarer with Autoconf,
17688 where each package comes with its own independent configuration
17691 Also, Imake often suffers from unexpected interactions between
17692 @command{make} and the installer's C preprocessor. The fundamental problem
17693 here is that the C preprocessor was designed to preprocess C programs,
17694 not @file{Makefile}s. This is much less of a problem with Autoconf,
17695 which uses the general-purpose preprocessor M4, and where the
17696 package's author (rather than the installer) does the preprocessing in a
17701 Finally, Mark Eichin notes:
17704 Imake isn't all that extensible, either. In order to add new features to
17705 Imake, you need to provide your own project template, and duplicate most
17706 of the features of the existing one. This means that for a sophisticated
17707 project, using the vendor-provided Imake templates fails to provide any
17708 leverage---since they don't cover anything that your own project needs
17709 (unless it is an X11 program).
17711 On the other side, though:
17713 The one advantage that Imake has over @command{configure}:
17714 @file{Imakefile}s tend to be much shorter (likewise, less redundant)
17715 than @file{Makefile.in}s. There is a fix to this, however---at least
17716 for the Kerberos V5 tree, we've modified things to call in common
17717 @file{post.in} and @file{pre.in} @file{Makefile} fragments for the
17718 entire tree. This means that a lot of common things don't have to be
17719 duplicated, even though they normally are in @command{configure} setups.
17723 @node Defining Directories
17724 @section How Do I @code{#define} Installation Directories?
17727 My program needs library files, installed in @code{datadir} and
17731 AC_DEFINE_UNQUOTED([DATADIR], [$datadir],
17732 [Define to the read-only architecture-independent
17740 #define DATADIR "$@{prefix@}/share"
17744 As already explained, this behavior is on purpose, mandated by the
17745 @acronym{GNU} Coding Standards, see @ref{Installation Directory
17746 Variables}. There are several means to achieve a similar goal:
17750 Do not use @code{AC_DEFINE} but use your @file{Makefile} to pass the
17751 actual value of @code{datadir} via compilation flags, see
17752 @ref{Installation Directory Variables}, for the details.
17755 This solution can be simplified when compiling a program: you may either
17756 extend the @code{CPPFLAGS}:
17759 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
17763 or create a dedicated header file:
17766 DISTCLEANFILES = datadir.h
17767 datadir.h: Makefile
17768 echo '#define DATADIR "$(datadir)"' >$@@
17772 Use @code{AC_DEFINE} but have @command{configure} compute the literal
17773 value of @code{datadir} and others. Many people have wrapped macros to
17774 automate this task. For instance, the macro @code{AC_DEFINE_DIR} from
17775 the @uref{http://autoconf-archive.cryp.to/, Autoconf Macro
17778 This solution does not conform to the @acronym{GNU} Coding Standards.
17781 Note that all the previous solutions hard wire the absolute name of
17782 these directories in the executables, which is not a good property. You
17783 may try to compute the names relative to @code{prefix}, and try to
17784 find @code{prefix} at runtime, this way your package is relocatable.
17785 Some macros are already available to address this issue: see
17786 @code{adl_COMPUTE_RELATIVE_PATHS} and
17787 @code{adl_COMPUTE_STANDARD_RELATIVE_PATHS} on the
17788 @uref{http://autoconf-archive.cryp.to/,
17789 Autoconf Macro Archive}.
17793 @node autom4te.cache
17794 @section What is @file{autom4te.cache}?
17797 What is this directory @file{autom4te.cache}? Can I safely remove it?
17800 In the @acronym{GNU} Build System, @file{configure.ac} plays a central
17801 role and is read by many tools: @command{autoconf} to create
17802 @file{configure}, @command{autoheader} to create @file{config.h.in},
17803 @command{automake} to create @file{Makefile.in}, @command{autoscan} to
17804 check the completeness of @file{configure.ac}, @command{autoreconf} to
17805 check the @acronym{GNU} Build System components that are used. To
17806 ``read @file{configure.ac}'' actually means to compile it with M4,
17807 which can be a very long process for complex @file{configure.ac}.
17809 This is why all these tools, instead of running directly M4, invoke
17810 @command{autom4te} (@pxref{autom4te Invocation}) which, while answering to
17811 a specific demand, stores additional information in
17812 @file{autom4te.cache} for future runs. For instance, if you run
17813 @command{autoconf}, behind the scenes, @command{autom4te} will also
17814 store information for the other tools, so that when you invoke
17815 @command{autoheader} or @command{automake} etc., re-processing
17816 @file{configure.ac} is not needed. The speed up is frequently of 30%,
17817 and is increasing with the size of @file{configure.ac}.
17819 But it is and remains being simply a cache: you can safely remove it.
17824 Can I permanently get rid of it?
17827 The creation of this cache can be disabled from
17828 @file{~/.autom4te.cfg}, see @ref{Customizing autom4te}, for more
17829 details. You should be aware that disabling the cache slows down the
17830 Autoconf test suite by 40%. The more @acronym{GNU} Build System
17831 components are used, the more the cache is useful; for instance
17832 running @samp{autoreconf -f} on the Core Utilities is twice slower without
17833 the cache @emph{although @option{--force} implies that the cache is
17834 not fully exploited}, and eight times slower than without
17838 @node Present But Cannot Be Compiled
17839 @section Header Present But Cannot Be Compiled
17841 The most important guideline to bear in mind when checking for
17842 features is to mimic as much as possible the intended use.
17843 Unfortunately, old versions of @code{AC_CHECK_HEADER} and
17844 @code{AC_CHECK_HEADERS} failed to follow this idea, and called
17845 the preprocessor, instead of the compiler, to check for headers. As a
17846 result, incompatibilities between headers went unnoticed during
17847 configuration, and maintainers finally had to deal with this issue
17850 As of Autoconf 2.56 both checks are performed, and @code{configure}
17851 complains loudly if the compiler and the preprocessor do not agree.
17852 For the time being the result used is that of the preprocessor, to give
17853 maintainers time to adjust their @file{configure.ac}, but in the
17854 future, only the compiler will be considered.
17856 Consider the following example:
17859 $ @kbd{cat number.h}
17860 typedef int number;
17862 const number pi = 3;
17863 $ @kbd{cat configure.ac}
17864 AC_INIT([Example], [1.0], [bug-example@@example.org])
17865 AC_CHECK_HEADERS([pi.h])
17866 $ @kbd{autoconf -Wall}
17867 $ @kbd{./configure}
17868 checking for gcc... gcc
17869 checking for C compiler default output file name... a.out
17870 checking whether the C compiler works... yes
17871 checking whether we are cross compiling... no
17872 checking for suffix of executables...
17873 checking for suffix of object files... o
17874 checking whether we are using the GNU C compiler... yes
17875 checking whether gcc accepts -g... yes
17876 checking for gcc option to accept ISO C89... none needed
17877 checking how to run the C preprocessor... gcc -E
17878 checking for grep that handles long lines and -e... grep
17879 checking for egrep... grep -E
17880 checking for ANSI C header files... yes
17881 checking for sys/types.h... yes
17882 checking for sys/stat.h... yes
17883 checking for stdlib.h... yes
17884 checking for string.h... yes
17885 checking for memory.h... yes
17886 checking for strings.h... yes
17887 checking for inttypes.h... yes
17888 checking for stdint.h... yes
17889 checking for unistd.h... yes
17890 checking pi.h usability... no
17891 checking pi.h presence... yes
17892 configure: WARNING: pi.h: present but cannot be compiled
17893 configure: WARNING: pi.h: check for missing prerequisite headers?
17894 configure: WARNING: pi.h: see the Autoconf documentation
17895 configure: WARNING: pi.h: section "Present But Cannot Be Compiled"
17896 configure: WARNING: pi.h: proceeding with the preprocessor's result
17897 configure: WARNING: pi.h: in the future, the compiler will take precedence
17898 configure: WARNING: ## -------------------------------------- ##
17899 configure: WARNING: ## Report this to bug-example@@example.org ##
17900 configure: WARNING: ## -------------------------------------- ##
17901 checking for pi.h... yes
17905 The proper way the handle this case is using the fourth argument
17906 (@pxref{Generic Headers}):
17909 $ @kbd{cat configure.ac}
17910 AC_INIT([Example], [1.0], [bug-example@@example.org])
17911 AC_CHECK_HEADERS([number.h pi.h], [], [],
17912 [[#if HAVE_NUMBER_H
17913 # include <number.h>
17916 $ @kbd{autoconf -Wall}
17917 $ @kbd{./configure}
17918 checking for gcc... gcc
17919 checking for C compiler default output... a.out
17920 checking whether the C compiler works... yes
17921 checking whether we are cross compiling... no
17922 checking for suffix of executables...
17923 checking for suffix of object files... o
17924 checking whether we are using the GNU C compiler... yes
17925 checking whether gcc accepts -g... yes
17926 checking for gcc option to accept ANSI C... none needed
17927 checking for number.h... yes
17928 checking for pi.h... yes
17931 See @ref{Particular Headers}, for a list of headers with their
17934 @c ===================================================== History of Autoconf.
17937 @chapter History of Autoconf
17938 @cindex History of autoconf
17940 You may be wondering, Why was Autoconf originally written? How did it
17941 get into its present form? (Why does it look like gorilla spit?) If
17942 you're not wondering, then this chapter contains no information useful
17943 to you, and you might as well skip it. If you @emph{are} wondering,
17944 then let there be light@enddots{}
17947 * Genesis:: Prehistory and naming of @command{configure}
17948 * Exodus:: The plagues of M4 and Perl
17949 * Leviticus:: The priestly code of portability arrives
17950 * Numbers:: Growth and contributors
17951 * Deuteronomy:: Approaching the promises of easy configuration
17957 In June 1991 I was maintaining many of the @acronym{GNU} utilities for the
17958 Free Software Foundation. As they were ported to more platforms and
17959 more programs were added, the number of @option{-D} options that users
17960 had to select in the @file{Makefile} (around 20) became burdensome.
17961 Especially for me---I had to test each new release on a bunch of
17962 different systems. So I wrote a little shell script to guess some of
17963 the correct settings for the fileutils package, and released it as part
17964 of fileutils 2.0. That @command{configure} script worked well enough that
17965 the next month I adapted it (by hand) to create similar @command{configure}
17966 scripts for several other @acronym{GNU} utilities packages. Brian Berliner
17967 also adapted one of my scripts for his @acronym{CVS} revision control system.
17969 Later that summer, I learned that Richard Stallman and Richard Pixley
17970 were developing similar scripts to use in the @acronym{GNU} compiler tools;
17971 so I adapted my @command{configure} scripts to support their evolving
17972 interface: using the file name @file{Makefile.in} as the templates;
17973 adding @samp{+srcdir}, the first option (of many); and creating
17974 @file{config.status} files.
17979 As I got feedback from users, I incorporated many improvements, using
17980 Emacs to search and replace, cut and paste, similar changes in each of
17981 the scripts. As I adapted more @acronym{GNU} utilities packages to use
17982 @command{configure} scripts, updating them all by hand became impractical.
17983 Rich Murphey, the maintainer of the @acronym{GNU} graphics utilities, sent me
17984 mail saying that the @command{configure} scripts were great, and asking if
17985 I had a tool for generating them that I could send him. No, I thought,
17986 but I should! So I started to work out how to generate them. And the
17987 journey from the slavery of hand-written @command{configure} scripts to the
17988 abundance and ease of Autoconf began.
17990 Cygnus @command{configure}, which was being developed at around that time,
17991 is table driven; it is meant to deal mainly with a discrete number of
17992 system types with a small number of mainly unguessable features (such as
17993 details of the object file format). The automatic configuration system
17994 that Brian Fox had developed for Bash takes a similar approach. For
17995 general use, it seems to me a hopeless cause to try to maintain an
17996 up-to-date database of which features each variant of each operating
17997 system has. It's easier and more reliable to check for most features on
17998 the fly---especially on hybrid systems that people have hacked on
17999 locally or that have patches from vendors installed.
18001 I considered using an architecture similar to that of Cygnus
18002 @command{configure}, where there is a single @command{configure} script that
18003 reads pieces of @file{configure.in} when run. But I didn't want to have
18004 to distribute all of the feature tests with every package, so I settled
18005 on having a different @command{configure} made from each
18006 @file{configure.in} by a preprocessor. That approach also offered more
18007 control and flexibility.
18009 I looked briefly into using the Metaconfig package, by Larry Wall,
18010 Harlan Stenn, and Raphael Manfredi, but I decided not to for several
18011 reasons. The @command{Configure} scripts it produces are interactive,
18012 which I find quite inconvenient; I didn't like the ways it checked for
18013 some features (such as library functions); I didn't know that it was
18014 still being maintained, and the @command{Configure} scripts I had
18015 seen didn't work on many modern systems (such as System V R4 and NeXT);
18016 it wasn't very flexible in what it could do in response to a feature's
18017 presence or absence; I found it confusing to learn; and it was too big
18018 and complex for my needs (I didn't realize then how much Autoconf would
18019 eventually have to grow).
18021 I considered using Perl to generate my style of @command{configure}
18022 scripts, but decided that M4 was better suited to the job of simple
18023 textual substitutions: it gets in the way less, because output is
18024 implicit. Plus, everyone already has it. (Initially I didn't rely on
18025 the @acronym{GNU} extensions to M4.) Also, some of my friends at the
18026 University of Maryland had recently been putting M4 front ends on
18027 several programs, including @code{tvtwm}, and I was interested in trying
18028 out a new language.
18033 Since my @command{configure} scripts determine the system's capabilities
18034 automatically, with no interactive user intervention, I decided to call
18035 the program that generates them Autoconfig. But with a version number
18036 tacked on, that name would be too long for old Unix file systems,
18037 so I shortened it to Autoconf.
18039 In the fall of 1991 I called together a group of fellow questers after
18040 the Holy Grail of portability (er, that is, alpha testers) to give me
18041 feedback as I encapsulated pieces of my handwritten scripts in M4 macros
18042 and continued to add features and improve the techniques used in the
18043 checks. Prominent among the testers were Fran@,{c}ois Pinard, who came up
18044 with the idea of making an Autoconf shell script to run M4
18045 and check for unresolved macro calls; Richard Pixley, who suggested
18046 running the compiler instead of searching the file system to find
18047 include files and symbols, for more accurate results; Karl Berry, who
18048 got Autoconf to configure @TeX{} and added the macro index to the
18049 documentation; and Ian Lance Taylor, who added support for creating a C
18050 header file as an alternative to putting @option{-D} options in a
18051 @file{Makefile}, so he could use Autoconf for his @acronym{UUCP} package.
18052 The alpha testers cheerfully adjusted their files again and again as the
18053 names and calling conventions of the Autoconf macros changed from
18054 release to release. They all contributed many specific checks, great
18055 ideas, and bug fixes.
18060 In July 1992, after months of alpha testing, I released Autoconf 1.0,
18061 and converted many @acronym{GNU} packages to use it. I was surprised by how
18062 positive the reaction to it was. More people started using it than I
18063 could keep track of, including people working on software that wasn't
18064 part of the @acronym{GNU} Project (such as TCL, FSP, and Kerberos V5).
18065 Autoconf continued to improve rapidly, as many people using the
18066 @command{configure} scripts reported problems they encountered.
18068 Autoconf turned out to be a good torture test for M4 implementations.
18069 Unix M4 started to dump core because of the length of the
18070 macros that Autoconf defined, and several bugs showed up in @acronym{GNU}
18071 M4 as well. Eventually, we realized that we needed to use some
18072 features that only @acronym{GNU} M4 has. 4.3@acronym{BSD} M4, in
18073 particular, has an impoverished set of builtin macros; the System V
18074 version is better, but still doesn't provide everything we need.
18076 More development occurred as people put Autoconf under more stresses
18077 (and to uses I hadn't anticipated). Karl Berry added checks for X11.
18078 david zuhn contributed C++ support. Fran@,{c}ois Pinard made it diagnose
18079 invalid arguments. Jim Blandy bravely coerced it into configuring
18080 @acronym{GNU} Emacs, laying the groundwork for several later improvements.
18081 Roland McGrath got it to configure the @acronym{GNU} C Library, wrote the
18082 @command{autoheader} script to automate the creation of C header file
18083 templates, and added a @option{--verbose} option to @command{configure}.
18084 Noah Friedman added the @option{--autoconf-dir} option and
18085 @code{AC_MACRODIR} environment variable. (He also coined the term
18086 @dfn{autoconfiscate} to mean ``adapt a software package to use
18087 Autoconf''.) Roland and Noah improved the quoting protection in
18088 @code{AC_DEFINE} and fixed many bugs, especially when I got sick of
18089 dealing with portability problems from February through June, 1993.
18092 @section Deuteronomy
18094 A long wish list for major features had accumulated, and the effect of
18095 several years of patching by various people had left some residual
18096 cruft. In April 1994, while working for Cygnus Support, I began a major
18097 revision of Autoconf. I added most of the features of the Cygnus
18098 @command{configure} that Autoconf had lacked, largely by adapting the
18099 relevant parts of Cygnus @command{configure} with the help of david zuhn
18100 and Ken Raeburn. These features include support for using
18101 @file{config.sub}, @file{config.guess}, @option{--host}, and
18102 @option{--target}; making links to files; and running @command{configure}
18103 scripts in subdirectories. Adding these features enabled Ken to convert
18104 @acronym{GNU} @code{as}, and Rob Savoye to convert Deja@acronym{GNU}, to using
18107 I added more features in response to other peoples' requests. Many
18108 people had asked for @command{configure} scripts to share the results of
18109 the checks between runs, because (particularly when configuring a large
18110 source tree, like Cygnus does) they were frustratingly slow. Mike
18111 Haertel suggested adding site-specific initialization scripts. People
18112 distributing software that had to unpack on MS-DOS asked for a way to
18113 override the @file{.in} extension on the file names, which produced file
18114 names like @file{config.h.in} containing two dots. Jim Avera did an
18115 extensive examination of the problems with quoting in @code{AC_DEFINE}
18116 and @code{AC_SUBST}; his insights led to significant improvements.
18117 Richard Stallman asked that compiler output be sent to @file{config.log}
18118 instead of @file{/dev/null}, to help people debug the Emacs
18119 @command{configure} script.
18121 I made some other changes because of my dissatisfaction with the quality
18122 of the program. I made the messages showing results of the checks less
18123 ambiguous, always printing a result. I regularized the names of the
18124 macros and cleaned up coding style inconsistencies. I added some
18125 auxiliary utilities that I had developed to help convert source code
18126 packages to use Autoconf. With the help of Fran@,{c}ois Pinard, I made
18127 the macros not interrupt each others' messages. (That feature revealed
18128 some performance bottlenecks in @acronym{GNU} M4, which he hastily
18129 corrected!) I reorganized the documentation around problems people want
18130 to solve. And I began a test suite, because experience had shown that
18131 Autoconf has a pronounced tendency to regress when we change it.
18133 Again, several alpha testers gave invaluable feedback, especially
18134 Fran@,{c}ois Pinard, Jim Meyering, Karl Berry, Rob Savoye, Ken Raeburn,
18137 Finally, version 2.0 was ready. And there was much rejoicing. (And I
18138 have free time again. I think. Yeah, right.)
18141 @c ========================================================== Appendices
18143 @node Copying This Manual
18144 @appendix Copying This Manual
18148 * GNU Free Documentation License:: License for copying this manual
18157 * Environment Variable Index:: Index of environment variables used
18158 * Output Variable Index:: Index of variables set in output files
18159 * Preprocessor Symbol Index:: Index of C preprocessor symbols defined
18160 * Autoconf Macro Index:: Index of Autoconf macros
18161 * M4 Macro Index:: Index of M4, M4sugar, and M4sh macros
18162 * Autotest Macro Index:: Index of Autotest macros
18163 * Program & Function Index:: Index of those with portability problems
18164 * Concept Index:: General index
18167 @node Environment Variable Index
18168 @appendixsec Environment Variable Index
18170 This is an alphabetical list of the environment variables that Autoconf
18175 @node Output Variable Index
18176 @appendixsec Output Variable Index
18178 This is an alphabetical list of the variables that Autoconf can
18179 substitute into files that it creates, typically one or more
18180 @file{Makefile}s. @xref{Setting Output Variables}, for more information
18181 on how this is done.
18185 @node Preprocessor Symbol Index
18186 @appendixsec Preprocessor Symbol Index
18188 This is an alphabetical list of the C preprocessor symbols that the
18189 Autoconf macros define. To work with Autoconf, C source code needs to
18190 use these names in @code{#if} directives.
18194 @node Autoconf Macro Index
18195 @appendixsec Autoconf Macro Index
18197 This is an alphabetical list of the Autoconf macros.
18198 @ifset shortindexflag
18199 To make the list easier to use, the macros are listed without their
18200 preceding @samp{AC_}.
18205 @node M4 Macro Index
18206 @appendixsec M4 Macro Index
18208 This is an alphabetical list of the M4, M4sugar, and M4sh macros.
18209 @ifset shortindexflag
18210 To make the list easier to use, the macros are listed without their
18211 preceding @samp{m4_} or @samp{AS_}.
18216 @node Autotest Macro Index
18217 @appendixsec Autotest Macro Index
18219 This is an alphabetical list of the Autotest macros.
18220 @ifset shortindexflag
18221 To make the list easier to use, the macros are listed without their
18222 preceding @samp{AT_}.
18227 @node Program & Function Index
18228 @appendixsec Program and Function Index
18230 This is an alphabetical list of the programs and functions which
18231 portability is discussed in this document.
18235 @node Concept Index
18236 @appendixsec Concept Index
18238 This is an alphabetical list of the files, tools, and concepts
18239 introduced in this document.
18245 @c LocalWords: texinfo setfilename autoconf texi settitle setchapternewpage
18246 @c LocalWords: setcontentsaftertitlepage finalout ARG ovar varname dvar acx
18247 @c LocalWords: makeinfo dvi defcodeindex ev ov CPP cv Autotest mv defindex fn
18248 @c LocalWords: shortindexflag iftex ifset acindex ACindex ifclear ahindex fu
18249 @c LocalWords: asindex MSindex atindex ATindex auindex hdrindex prindex FIXME
18250 @c LocalWords: msindex alloca fnindex Aaarg indices FSF's dircategory ifnames
18251 @c LocalWords: direntry autoscan autoreconf autoheader autoupdate config FDs
18252 @c LocalWords: testsuite titlepage Elliston Demaille vskip filll ifnottex hmm
18253 @c LocalWords: insertcopying Autoconf's detailmenu Automake Libtool Posix ois
18254 @c LocalWords: Systemology Checkpointing Changequote INTERCAL changequote dfn
18255 @c LocalWords: Quadrigraphs builtins Shellology acconfig Bugward LIBOBJ Imake
18256 @c LocalWords: LIBOBJS IFELSE cindex flushright Pinard Metaconfig uref Simons
18257 @c LocalWords: distclean uninstall noindent versioning Tromey dir
18258 @c LocalWords: SAMS samp aclocal acsite underquoted emph itemx prepend SUBST
18259 @c LocalWords: evindex automake Gettext autopoint gettext symlink libtoolize
18260 @c LocalWords: defmac INIT tarname ovindex cvindex BUGREPORT PREREQ asis PROG
18261 @c LocalWords: SRCDIR srcdir globbing afterwards cmds foos fooo foooo init cd
18262 @c LocalWords: builddir timestamp src Imakefile chmod defvar CFLAGS CPPFLAGS
18263 @c LocalWords: CXXFLAGS DEFS DHAVE defvarx FCFLAGS FFLAGS LDFLAGS bindir GCC
18264 @c LocalWords: datadir datarootdir docdir dvidir htmldir libdir ifnothtml kbd
18265 @c LocalWords: includedir infodir libexecdir localedir localstatedir mandir
18266 @c LocalWords: oldincludedir pdfdir PDF psdir PostScript sbindir sysconfdir
18267 @c LocalWords: sharedstatedir DDATADIR sed tmp pkgdatadir VPATH conf unistd
18268 @c LocalWords: undef endif builtin FUNCS ifndef STACKSEG getb GETB YMP fubar
18269 @c LocalWords: PRE dest SUBDIRS subdirs fi struct STDC stdlib stddef INTTYPES
18270 @c LocalWords: inttypes STDINT stdint AWK AIX Solaris NeXT env EGREP FGREP yy
18271 @c LocalWords: LEXLIB YYTEXT lfl nonportable Automake's LN RANLIB byacc INETD
18272 @c LocalWords: inetd prog PROGS progs ranlib lmp lXt lX nsl gethostbyname UX
18273 @c LocalWords: NextStep isinf isnan glibc IRIX sunmath lm lsunmath pre sizeof
18274 @c LocalWords: ld inline malloc OSF putenv setenv FreeBSD realloc SunOS MinGW
18275 @c LocalWords: snprintf vsnprintf sprintf vsprintf sscanf gcc strerror ifdef
18276 @c LocalWords: strnlen sysconf PAGESIZE unsetenv va fallback memcpy dst FUNC
18277 @c LocalWords: PowerPC GNUC libPW pragma Olibcalls CHOWN chown CLOSEDIR VFORK
18278 @c LocalWords: closedir FNMATCH fnmatch vfork FSEEKO LARGEFILE fseeko SVR sc
18279 @c LocalWords: largefile GETGROUPS getgroups GETLOADAVG DGUX UMAX NLIST KMEM
18280 @c LocalWords: GETLODAVG SETGID getloadavg nlist setgid setuid GETMNTENT irix
18281 @c LocalWords: getmntent UnixWare GETPGRP getpgid getpgrp Posix's pid LSTAT
18282 @c LocalWords: lstat rpl MEMCMP memcmp OpenStep MBRTOWC mbrtowc MKTIME mktime
18283 @c LocalWords: localtime MMAP mmap OBSTACK obstack obstacks ARGTYPES timeval
18284 @c LocalWords: SETPGRP setpgrp defmacx Hurd SETVBUF setvbuf STRCOLL strcoll
18285 @c LocalWords: STRTOD strtod DECL STRFTIME strftime SCO UTIME utime VPRINTF
18286 @c LocalWords: DOPRNT vprintf doprnt sp unfixable LIBSOURCE LIBSOURCES Eggert
18287 @c LocalWords: linux netinet ia Tru XFree DIRENT NDIR dirent ndir multitable
18288 @c LocalWords: NAMLEN strlen namlen MKDEV SYSMACROS makedev RESOLV resolv DNS
18289 @c LocalWords: inet structs NAMESER arpa NETDB netdb UTekV UTS autom GCC's kB
18290 @c LocalWords: STDBOOL BOOL stdbool conformant cplusplus bool Bool stdarg tm
18291 @c LocalWords: ctype strchr strrchr rindex bcopy memmove memchr WEXITSTATUS
18292 @c LocalWords: WIFEXITED TIOCGWINSZ GWINSZ termios preprocess preprocessable
18293 @c LocalWords: DECLS strdup calloc BLKSIZE blksize RDEV rdev TZNAME tzname pw
18294 @c LocalWords: passwd gecos pwd MBSTATE mbstate wchar RETSIGTYPE hup UID uid
18295 @c LocalWords: gid ptrdiff uintmax EXEEXT OBJEXT Ae Onolimit conftest AXP str
18296 @c LocalWords: ALIGNOF WERROR Werror cpp HP's WorkShop egcs un fied stdc CXX
18297 @c LocalWords: varargs BIGENDIAN Endianness SPARC endianness grep'ed CONST FC
18298 @c LocalWords: const STRINGIZE stringizing PARAMS unprotoize protos KCC cxx
18299 @c LocalWords: xlC aCC CXXCPP FREEFORM xlf FLIBS FCLIBS ish SRCEXT XTRA LFS
18300 @c LocalWords: ISC lcposix MINIX Minix conditionalized inlines hw dD confdefs
18301 @c LocalWords: fputs stdout PREPROC ar UFS HFS QNX realtime fstype STATVFS se
18302 @c LocalWords: statvfs STATFS statfs func machfile hdr lelf raboof DEFUN GTK
18303 @c LocalWords: GTKMM Grmph ified ine defn baz EOF qar Ahhh changecom algol io
18304 @c LocalWords: changeword quadrigraphs quadrigraph dnl SGI atoi overquoting
18305 @c LocalWords: Aas Wcross sep args namespace undefine bpatsubst popdef dquote
18306 @c LocalWords: bregexp Overquote overquotation meisch maisch meische maische
18307 @c LocalWords: miscian DIRNAME dirname MKDIR CATFILE XMKMF TRAVOLTA celsius
18308 @c LocalWords: EMX emxos Emacsen Korn DYNIX subshell posix Ksh ksh Pdksh Zsh
18309 @c LocalWords: pdksh zsh Allbery Lipe Kubota UWS zorglub stderr eval esac lfn
18310 @c LocalWords: drivespec Posixy DJGPP doschk prettybird LPT pfew Zsh's yu yaa
18311 @c LocalWords: yM uM aM firebird IP subdir misparses ok Unpatched abc bc zA
18312 @c LocalWords: CDPATH DUALCASE LINENO prepass Subshells lineno NULLCMD cmp wc
18313 @c LocalWords: MAILPATH scanset arg NetBSD Almquist printf expr cp
18314 @c LocalWords: Oliva awk Aaaaarg cmd regex xfoo GNV OpenVMS unwriteable te VM
18315 @c LocalWords: coreutils sparc Proulx SysV nbar nfoo maxdepth acdilrtu TWG mc
18316 @c LocalWords: mkdir exe uname OpenBSD Fileutils mktemp umask TMPDIR guid os
18317 @c LocalWords: fooXXXXXX Unicos parenthesization utimes hpux hppa unescaped
18318 @c LocalWords: pmake DOS's gmake ifoo DESTDIR autoconfiscated pc coff mips gg
18319 @c LocalWords: dec ultrix cpu wildcards rpcc rdtsc powerpc behaviour readline
18320 @c LocalWords: withval vxworks gless localcache usr LOFF loff CYGWIN Cygwin
18321 @c LocalWords: cygwin SIGLIST siglist SYSNDIR SYSDIR ptx lseq rusage elif MSC
18322 @c LocalWords: lfoo POUNDBANG lsun NIS getpwnam SYSCALLS RSH INTL lintl aix
18323 @c LocalWords: intl lx ldir syslog bsd EPI toolchain netbsd objext de KNR nn
18324 @c LocalWords: fication LTLIBOBJS Wdiff TESTDIR atconfig atlocal akim XFAIL
18325 @c LocalWords: ChangeLog prepended errexit smallexample TESTSUITEFLAGS GPL er
18326 @c LocalWords: installcheck autotest indir Pixley Bothner Eichin Kerberos adl
18327 @c LocalWords: DISTCLEANFILES preprocessor's fileutils Stallman Murphey Stenn
18328 @c LocalWords: Manfredi Autoconfig TCL FSP david zuhn Blandy MACRODIR Raeburn
18329 @c LocalWords: autoconfiscate Savoye Haertel Avera Meyering fdl appendixsec
18330 @c LocalWords: printindex american LIBOBJDIR LibdirTest ERLCFLAGS OBJCFLAGS
18331 @c LocalWords: VER Gnulib online xyes strcpy TYPEOF typeof OBJC objcc objc ln
18332 @c LocalWords: GOBJC OBJCCPP OTP ERLC erl valloc decr dumpdef errprint incr
18333 @c LocalWords: esyscmd len maketemp pushdef substr syscmd sysval translit txt
18334 @c LocalWords: sinclude foreach myvar tolower toupper uniq BASENAME STDIN ig
18335 @c LocalWords: Dynix descrips basename aname cname ih macroexpands xno xcheck
18336 @c LocalWords: LIBREADLINE lreadline lncurses libreadline
18338 @c Local Variables:
18340 @c ispell-local-dictionary: "american"