Debian Codegraph @

doc/autoconf.texi

raw
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename autoconf.info
4 @settitle Autoconf
5
6 @finalout
7 @setchapternewpage odd
8
9 @include version.texi
10
11 @c A simple macro for optional variables.
12 @macro ovar{varname}
13 @r{[}@var{\varname\}@r{]}
14 @end macro
15
16 @c I don't like the way URL are displayed in TeX with @uref.
17 @ifhtml
18 @macro href{url, title}
19 @uref{\url\, \title\}
20 @end macro
21 @end ifhtml
22 @ifnothtml
23 @macro href{url, title}
24 \title\@footnote{\title\, @url{\url\}.}
25 @end macro
26 @end ifnothtml
27
28
29 @dircategory GNU admin
30 @direntry
31 * Autoconf: (autoconf). Create source code configuration scripts
32 @end direntry
33
34 @dircategory Individual utilities
35 @direntry
36 * autoscan: (autoconf)autoscan Invocation.
37 Semi-automatic @file{configure.ac} writing
38 * ifnames: (autoconf)ifnames Invocation.
39 Listing the conditionals in source code
40 * autoconf: (autoconf)autoconf Invocation.
41 How to create configuration scripts
42 * autoreconf: (autoconf)autoreconf Invocation.
43 Remaking multiple @code{configure} scripts
44 * configure: (autoconf)configure Invocation.
45 Configuring a package
46 * config.status: (autoconf)config.status Invocation.
47 Recreating a configuration
48 @end direntry
49
50 @ifinfo
51 Autoconf: Creating Automatic Configuration Scripts, by David MacKenzie.
52
53 This file documents the GNU Autoconf package for creating scripts to
54 configure source code packages using templates and an @code{m4} macro
55 package.
56
57 Copyright 2003-2023,2025 Thomas E. Dickey@*
58 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 Free
59 Software Foundation, Inc.
60
61 Permission is granted to make and distribute verbatim copies of this
62 manual provided the copyright notice and this permission notice are
63 preserved on all copies.
64
65 @ignore
66 Permission is granted to process this file through TeX and print the
67 results, provided the printed document carries copying permission notice
68 identical to this one except for the removal of this paragraph (this
69 paragraph not being relevant to the printed manual).
70
71 @end ignore
72 Permission is granted to copy and distribute modified versions of this
73 manual under the conditions for verbatim copying, provided that the
74 entire resulting derived work is distributed under the terms of a
75 permission notice identical to this one.
76
77 Permission is granted to copy and distribute translations of this manual
78 into another language, under the above conditions for modified versions,
79 except that this permission notice may be stated in a translation
80 approved by the Foundation.
81 @end ifinfo
82
83 @titlepage
84 @title Autoconf
85 @subtitle Creating Automatic Configuration Scripts
86 @subtitle Edition @value{EDITION}, for Autoconf version @value{VERSION}
87 @subtitle @value{UPDATED}
88 @author David MacKenzie and Ben Elliston
89 @c I think I've rewritten all of Noah and Roland's contributions by now.
90
91 @page
92 @vskip 0pt plus 1filll
93 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
94 2001 Free Software Foundation, Inc.
95
96 Permission is granted to make and distribute verbatim copies of this
97 manual provided the copyright notice and this permission notice are
98 preserved on all copies.
99
100 Permission is granted to copy and distribute modified versions of this
101 manual under the conditions for verbatim copying, provided that the
102 entire resulting derived work is distributed under the terms of a
103 permission notice identical to this one.
104
105 Permission is granted to copy and distribute translations of this manual
106 into another language, under the above conditions for modified versions,
107 except that this permission notice may be stated in a translation
108 approved by the Foundation.
109 @end titlepage
110
111 @contents
112
113 @c Define an environment variable index.
114 @defcodeindex ev
115 @c Define an output variable index.
116 @defcodeindex ov
117 @c Define a CPP variable index.
118 @defcodeindex cv
119 @c Define an Autoconf macro index that @defmac doesn't write to.
120 @defcodeindex ma
121 @c Define an M4sugar macro index that @defmac doesn't write to.
122 @defcodeindex ms
123
124 @node Top, Introduction, (dir), (dir)
125 @comment node-name, next, previous, up
126
127 @ifinfo
128 This file documents the GNU Autoconf package for creating scripts to
129 configure source code packages using templates and the GNU M4 macro
130 package. This is edition @value{EDITION}, for Autoconf version
131 @value{VERSION}.
132
133 @end ifinfo
134
135 @c The master menu, created with texinfo-master-menu, goes here.
136
137 @menu
138 * Introduction:: Autoconf's purpose, strengths, and weaknesses
139 * The GNU build system:: A set of tools for portable software packages
140 * Making configure Scripts:: How to organize and produce Autoconf scripts
141 * Setup:: Initialization and output
142 * Existing Tests:: Macros that check for particular features
143 * Writing Tests:: How to write new feature checks
144 * Results:: What to do with results from feature checks
145 * Programming in M4:: Layers on top of which Autoconf is written
146 * Writing Autoconf Macros:: Adding new macros to Autoconf
147 * Portable Shell:: Shell script portability pitfalls
148 * Manual Configuration:: Selecting features that can't be guessed
149 * Site Configuration:: Local defaults for @code{configure}
150 * Running configure scripts:: How to use the Autoconf output
151 * config.status Invocation:: Recreating a configuration
152 * Obsolete Constructs:: Kept for backward compatibility
153 * Questions:: Questions about Autoconf, with answers
154 * History:: History of Autoconf
155 * Environment Variable Index:: Index of environment variables used
156 * Output Variable Index:: Index of variables set in output files
157 * Preprocessor Symbol Index:: Index of C preprocessor symbols defined
158 * Autoconf Macro Index:: Index of Autoconf macros
159 * M4 Macro Index:: Index of M4, M4sugar, and M4sh macros
160 * Concept Index:: General index
161
162 @detailmenu
163 --- The Detailed Node Listing ---
164
165 The GNU build system
166
167 * Automake:: Escaping Makefile hell
168 * Libtool:: Building libraries portably
169 * Pointers:: More info on the GNU build system
170
171 Making @code{configure} Scripts
172
173 * Writing configure.ac:: What to put in an Autoconf input file
174 * autoscan Invocation:: Semi-automatic @file{configure.ac} writing
175 * ifnames Invocation:: Listing the conditionals in source code
176 * autoconf Invocation:: How to create configuration scripts
177 * autoreconf Invocation:: Remaking multiple @code{configure} scripts
178
179 Writing @file{configure.ac}
180
181 * Shell Script Compiler:: Autoconf as solution of a problem
182 * Autoconf Language:: Programming in Autoconf
183 * configure.ac Layout:: Standard organization of configure.ac
184
185 Initialization and Output Files
186
187 * Notices:: Copyright, version numbers in @code{configure}
188 * Input:: Where Autoconf should find files
189 * Output:: Outputting results from the configuration
190 * Configuration Actions:: Preparing the output based on results
191 * Configuration Files:: Creating output files
192 * Makefile Substitutions:: Using output variables in @file{Makefile}s
193 * Configuration Headers:: Creating a configuration header file
194 * Configuration Commands:: Running arbitrary instantiation commands
195 * Configuration Links:: Links depending from the configuration
196 * Subdirectories:: Configuring independent packages together
197 * Default Prefix:: Changing the default installation prefix
198
199 Substitutions in Makefiles
200
201 * Preset Output Variables:: Output variables that are always set
202 * Installation Directory Variables:: Other preset output variables
203 * Build Directories:: Supporting multiple concurrent compiles
204 * Automatic Remaking:: Makefile rules for configuring
205
206 Configuration Header Files
207
208 * Header Templates:: Input for the configuration headers
209 * autoheader Invocation:: How to create configuration templates
210 * Autoheader Macros:: How to specify CPP templates
211
212 Existing Tests
213
214 * Common Behavior:: Macros' standard schemes
215 * Alternative Programs:: Selecting between alternative programs
216 * Files:: Checking for the existence of files
217 * Libraries:: Library archives that might be missing
218 * Library Functions:: C library functions that might be missing
219 * Header Files:: Header files that might be missing
220 * Declarations:: Declarations that may be missing
221 * Structures:: Structures or members that might be missing
222 * Types:: Types that might be missing
223 * Compilers and Preprocessors:: Checking for compiling programs
224 * System Services:: Operating system services
225 * UNIX Variants:: Special kludges for specific UNIX variants
226
227 Common Behavior
228
229 * Standard Symbols:: Symbols defined by the macros
230 * Default Includes:: Includes used by the generic macros
231
232 Alternative Programs
233
234 * Particular Programs:: Special handling to find certain programs
235 * Generic Programs:: How to find other programs
236
237 Library Functions
238
239 * Function Portability:: Pitfalls with usual functions
240 * Particular Functions:: Special handling to find certain functions
241 * Generic Functions:: How to find other functions
242
243 Header Files
244
245 * Particular Headers:: Special handling to find certain headers
246 * Generic Headers:: How to find other headers
247
248 Declarations
249
250 * Particular Declarations:: Macros to check for certain declarations
251 * Generic Declarations:: How to find other declarations
252
253 Structures
254
255 * Particular Structures:: Macros to check for certain structure members
256 * Generic Structures:: How to find other structure members
257
258 Types
259
260 * Particular Types:: Special handling to find certain types
261 * Generic Types:: How to find other types
262
263 Compilers and Preprocessors
264
265 * Generic Compiler Characteristics:: Language independent tests
266 * C Compiler:: Checking its characteristics
267 * C++ Compiler:: Likewise
268 * Fortran 77 Compiler:: Likewise
269
270 Writing Tests
271
272 * Examining Declarations:: Detecting header files and declarations
273 * Examining Syntax:: Detecting language syntax features
274 * Examining Libraries:: Detecting functions and global variables
275 * Run Time:: Testing for run-time features
276 * Systemology:: A zoology of operating systems
277 * Multiple Cases:: Tests for several possible values
278 * Language Choice:: Selecting which language to use for testing
279
280 Checking Run Time Behavior
281
282 * Test Programs:: Running test programs
283 * Guidelines:: General rules for writing test programs
284 * Test Functions:: Avoiding pitfalls in test programs
285
286 Results of Tests
287
288 * Defining Symbols:: Defining C preprocessor symbols
289 * Setting Output Variables:: Replacing variables in output files
290 * Caching Results:: Speeding up subsequent @code{configure} runs
291 * Printing Messages:: Notifying @code{configure} users
292
293 Caching Results
294
295 * Cache Variable Names:: Shell variables used in caches
296 * Cache Files:: Files @code{configure} uses for caching
297 * Cache Checkpointing:: Loading and saving the cache file
298
299 Programming in M4
300
301 * M4 Quotation:: Protecting macros from unwanted expansion
302 * Programming in M4sugar:: Convenient pure M4 macros
303
304 M4 Quotation
305
306 * Active Characters:: Characters that change the behavior of m4
307 * One Macro Call:: Quotation and one macro call
308 * Quotation and Nested Macros:: Macros calling macros
309 * Quadrigraphs:: Another way to escape special characters
310 * Quotation Rule Of Thumb:: One parenthesis, one quote
311
312 Programming in M4sugar
313
314 * Redefined M4 Macros:: M4 builtins changed in M4sugar
315 * Forbidden Patterns:: Catching unexpanded macros
316
317 Writing Autoconf Macros
318
319 * Macro Definitions:: Basic format of an Autoconf macro
320 * Macro Names:: What to call your new macros
321 * Reporting Messages:: Notifying @code{autoconf} users
322 * Dependencies Between Macros:: What to do when macros depend on other macros
323 * Obsoleting Macros:: Warning about old ways of doing things
324 * Coding Style:: Writing Autoconf macros @`a la Autoconf
325
326 Dependencies Between Macros
327
328 * Prerequisite Macros:: Ensuring required information
329 * Suggested Ordering:: Warning about possible ordering problems
330
331 Portable Shell Programming
332
333 * Shellology:: A zoology of shells
334 * Here-Documents:: Quirks and tricks
335 * File Descriptors:: FDs and redirections
336 * File System Conventions:: File- and pathnames
337 * Shell Substitutions:: Variable and command expansions
338 * Assignments:: Varying side effects of assignments
339 * Special Shell Variables:: Variables you should not change
340 * Limitations of Builtins:: Portable use of not so portable /bin/sh
341 * Limitations of Usual Tools:: Portable use of portable tools
342 * Limitations of Make:: Portable Makefiles
343
344 Manual Configuration
345
346 * Specifying Names:: Specifying the system type
347 * Canonicalizing:: Getting the canonical system type
348 * Using System Type:: What to do with the system type
349
350 Site Configuration
351
352 * External Software:: Working with other optional software
353 * Package Options:: Selecting optional features
354 * Pretty Help Strings:: Formatting help string
355 * Site Details:: Configuring site details
356 * Transforming Names:: Changing program names when installing
357 * Site Defaults:: Giving @code{configure} local defaults
358
359 Transforming Program Names When Installing
360
361 * Transformation Options:: @code{configure} options to transform names
362 * Transformation Examples:: Sample uses of transforming names
363 * Transformation Rules:: @file{Makefile} uses of transforming names
364
365 Running @code{configure} Scripts
366
367 * Basic Installation:: Instructions for typical cases
368 * Compilers and Options:: Selecting compilers and optimization
369 * Multiple Architectures:: Compiling for multiple architectures at once
370 * Installation Names:: Installing in different directories
371 * Optional Features:: Selecting optional features
372 * System Type:: Specifying the system type
373 * Sharing Defaults:: Setting site-wide defaults for @code{configure}
374 * Environment Variables:: Defining environment variables.
375 * configure Invocation:: Changing how @code{configure} runs
376
377 Obsolete Constructs
378
379 * Obsolete config.status Use:: Different calling convention
380 * acconfig.h:: Additional entries in @file{config.h.in}
381 * autoupdate Invocation:: Automatic update of @file{configure.ac}
382 * Obsolete Macros:: Backward compatibility macros
383 * Autoconf 1:: Tips for upgrading your files
384 * Autoconf 2.13:: Some fresher tips
385
386 Upgrading From Version 1
387
388 * Changed File Names:: Files you might rename
389 * Changed Makefiles:: New things to put in @file{Makefile.in}
390 * Changed Macros:: Macro calls you might replace
391 * Changed Results:: Changes in how to check test results
392 * Changed Macro Writing:: Better ways to write your own macros
393
394 Upgrading From Version 2.13
395
396 * Changed Quotation:: Broken code which used to work
397 * New Macros:: Interaction with foreign macros
398
399 Questions About Autoconf
400
401 * Distributing:: Distributing @code{configure} scripts
402 * Why GNU m4:: Why not use the standard M4?
403 * Bootstrapping:: Autoconf and GNU M4 require each other?
404 * Why Not Imake:: Why GNU uses @code{configure} instead of Imake
405
406 History of Autoconf
407
408 * Genesis:: Prehistory and naming of @code{configure}
409 * Exodus:: The plagues of M4 and Perl
410 * Leviticus:: The priestly code of portability arrives
411 * Numbers:: Growth and contributors
412 * Deuteronomy:: Approaching the promises of easy configuration
413
414 @end detailmenu
415 @end menu
416
417 @c ============================================================= Introduction.
418
419 @node Introduction, The GNU build system, Top, Top
420 @chapter Introduction
421
422 @flushright
423 A physicist, an engineer, and a computer scientist were discussing the
424 nature of God. ``Surely a Physicist,'' said the physicist, ``because
425 early in the Creation, God made Light; and you know, Maxwell's
426 equations, the dual nature of electromagnetic waves, the relativistic
427 consequences@dots{}'' ``An Engineer!,'' said the engineer, ``because
428 before making Light, God split the Chaos into Land and Water; it takes a
429 hell of an engineer to handle that big amount of mud, and orderly
430 separation of solids from liquids@dots{}'' The computer scientist
431 shouted: ``And the Chaos, where do you think it was coming from, hmm?''
432
433 ---Anonymous
434 @end flushright
435 @c (via Franc,ois Pinard)
436
437 Autoconf is a tool for producing shell scripts that automatically
438 configure software source code packages to adapt to many kinds of
439 @sc{unix}-like systems. The configuration scripts produced by Autoconf
440 are independent of Autoconf when they are run, so their users do not
441 need to have Autoconf.
442
443 The configuration scripts produced by Autoconf require no manual user
444 intervention when run; they do not normally even need an argument
445 specifying the system type. Instead, they individually test for the
446 presence of each feature that the software package they are for might need.
447 (Before each check, they print a one-line message stating what they are
448 checking for, so the user doesn't get too bored while waiting for the
449 script to finish.) As a result, they deal well with systems that are
450 hybrids or customized from the more common @sc{unix} variants. There is
451 no need to maintain files that list the features supported by each
452 release of each variant of @sc{unix}.
453
454 For each software package that Autoconf is used with, it creates a
455 configuration script from a template file that lists the system features
456 that the package needs or can use. After the shell code to recognize
457 and respond to a system feature has been written, Autoconf allows it to
458 be shared by many software packages that can use (or need) that feature.
459 If it later turns out that the shell code needs adjustment for some
460 reason, it needs to be changed in only one place; all of the
461 configuration scripts can be regenerated automatically to take advantage
462 of the updated code.
463
464 The Metaconfig package is similar in purpose to Autoconf, but the
465 scripts it produces require manual user intervention, which is quite
466 inconvenient when configuring large source trees. Unlike Metaconfig
467 scripts, Autoconf scripts can support cross-compiling, if some care is
468 taken in writing them.
469
470 Autoconf does not solve all problems related to making portable software
471 packages---for a more complete solution, it should be used in concert
472 with other GNU build tools like Automake and Libtool. These other tools
473 take on jobs like the creation of a portable, recursive @file{Makefile}
474 with all of the standard targets, linking of shared libraries, and so
475 on. @xref{The GNU build system}, for more information.
476
477 Autoconf imposes some restrictions on the names of macros used with
478 @code{#if} in C programs (@pxref{Preprocessor Symbol Index}).
479
480 Autoconf requires @sc{gnu} M4 in order to generate the scripts. It uses
481 features that some @sc{unix} versions of M4, including @sc{gnu} M4 1.3,
482 do not have. You must use version 1.4 or later of @sc{gnu} M4.
483
484 @xref{Autoconf 1}, for information about upgrading from version 1.
485 @xref{History}, for the story of Autoconf's development.
486 @xref{Questions}, for answers to some common questions about Autoconf.
487
488
489 See the @href{http://www.gnu.org/software/autoconf/autoconf.html,
490 Autoconf web page} for up-to-date information, details on the mailing
491 lists, pointers to a list of known bugs, etc.
492
493 Mail suggestions to @email{autoconf@@gnu.org, the Autoconf mailing
494 list}.
495
496 Bug reports should be preferably submitted to the
497 @href{http://sources.redhat.com/cgi-bin/gnatsweb.pl?database=autoconf,
498 Autoconf Gnats database}, or sent to @email{bug-autoconf@@gnu.org, the
499 Autoconf Bugs mailing list}. If possible, first check that your bug is
500 not already solved in current development versions, and that it has not
501 been reported yet. Be sure to include all the needed information and a
502 short @file{configure.ac} that demonstrates the problem.
503
504 Autoconf's development tree is accessible via @sc{cvs}; see the Autoconf
505 web page for details. There is also a
506 @href{http://subversions.gnu.org/cgi-bin/cvsweb/autoconf/, @sc{cvs}web
507 interface to the Autoconf development tree}. Patches relative to the
508 current @sc{cvs} version can be sent for review to the
509 @email{autoconf-patches@@gnu.org, Autoconf Patches mailing list}.
510
511 Because of its mission, Autoconf includes only a set of often-used
512 macros that have already demonstrated their usefulness. Nevertheless,
513 if you wish to share your macros, or find existing ones, see the
514 @href{http://www.gnu.org/software/ac-archive/, Autoconf Macro
515 Archive}, which is kindly run by @email{simons@@computer.org,
516 Peter Simons}.
517
518
519 @c ================================================= The GNU build system
520
521 @node The GNU build system, Making configure Scripts, Introduction, Top
522 @chapter The GNU build system
523
524 Autoconf solves an important problem---reliable discovery of
525 system-specific build and runtime information---but this is only one
526 piece of the puzzle for the development of portable software. To this
527 end, the GNU project has developed a suite of integrated utilities to
528 finish the job Autoconf started: the GNU build system, whose most
529 important components are Autoconf, Automake, and Libtool. In this
530 chapter, we introduce you to those tools, point you to sources of more
531 information, and try to convince you to use the entire GNU build system
532 for your software.
533
534 @menu
535 * Automake:: Escaping Makefile hell
536 * Libtool:: Building libraries portably
537 * Pointers:: More info on the GNU build system
538 @end menu
539
540 @node Automake, Libtool, The GNU build system, The GNU build system
541 @section Automake
542
543 The ubiquity of @code{make} means that a @code{Makefile} is almost the
544 only viable way to distribute automatic build rules for software, but
545 one quickly runs into @code{make}'s numerous limitations. Its lack of
546 support for automatic dependency tracking, recursive builds in
547 subdirectories, reliable timestamps (e.g. for network filesystems), and
548 so on, mean that developers must painfully (and often incorrectly)
549 reinvent the wheel for each project. Portability is non-trivial, thanks
550 to the quirks of @code{make} on many systems. On top of all this is the
551 manual labor required to implement the many standard targets that users
552 have come to expect (@code{make install}, @code{make distclean},
553 @code{make uninstall}, etc.). Since you are, of course, using Autoconf,
554 you also have to insert repetitive code in your @code{Makefile.in} to
555 recognize @code{@@CC@@}, @code{@@CFLAGS@@}, and other substitutions
556 provided by @code{configure}. Into this mess steps @dfn{Automake}.
557 @cindex Automake
558
559 Automake allows you to specify your build needs in a @code{Makefile.am}
560 file with a vastly simpler and more powerful syntax than that of a plain
561 @code{Makefile}, and then generates a portable @code{Makefile.in} for
562 use with Autoconf. For example, the @code{Makefile.am} to build and
563 install a simple ``Hello world'' program might look like:
564
565 @example
566 bin_PROGRAMS = hello
567 hello_SOURCES = hello.c
568 @end example
569
570 @noindent
571 The resulting @code{Makefile.in} (~400 lines) automatically supports all
572 the standard targets, the substitutions provided by Autoconf, automatic
573 dependency tracking, @code{VPATH} building, and so on. @code{make} will
574 build the @code{hello} program, and @code{make install} will install it
575 in @file{/usr/local/bin} (or whatever prefix was given to
576 @code{configure}, if not @file{/usr/local}).
577
578 Automake may require that additional tools be present on the
579 @emph{developer's} machine. For example, the @code{Makefile.in} that
580 the developer works with may not be portable (e.g. it might use special
581 features of your compiler to automatically generate dependency
582 information). Running @code{make dist}, however, produces a
583 @file{hello-1.0.tar.gz} package (or whatever the program/version is)
584 with a @code{Makefile.in} that will work on any system.
585
586 The benefits of Automake increase for larger packages (especially ones
587 with subdirectories), but even for small programs the added convenience
588 and portability can be substantial. And that's not all@dots{}
589
590 @node Libtool, Pointers, Automake, The GNU build system
591 @section Libtool
592
593 Very often, one wants to build not only programs, but libraries, so that
594 other programs can benefit from the fruits of your labor. Ideally, one
595 would like to produce @emph{shared} (dynamically-linked) libraries,
596 which can be used by multiple programs without duplication on disk or in
597 memory and can be updated independently of the linked programs.
598 Producing shared libraries portably, however, is the stuff of
599 nightmares---each system has its own incompatible tools, compiler flags,
600 and magic incantations. Fortunately, GNU provides a solution:
601 @dfn{Libtool}.
602 @cindex Libtool
603
604 Libtool handles all the requirements of building shared libraries for
605 you, and at this time seems to be the @emph{only} way to do so with any
606 portability. It also handles many other headaches, such as: the
607 interaction of @code{Makefile} rules with the variable suffixes of
608 shared libraries, linking reliably to shared libraries before they are
609 installed by the superuser, and supplying a consistent versioning system
610 (so that different versions of a library can be installed or upgraded
611 without breaking binary compatibility). Although Libtool, like
612 Autoconf, can be used on its own, it is most simply utilized in
613 conjunction with Automake---there, Libtool is used automatically
614 whenever shared libraries are needed, and you need not know its syntax.
615
616 @node Pointers, , Libtool, The GNU build system
617 @section Pointers
618
619 Developers who are used to the simplicity of @code{make} for small
620 projects on a single system might be daunted at the prospect of learning
621 to use Automake and Autoconf. As your software is distributed to more
622 and more users, however, you will otherwise quickly find yourself
623 putting lots of effort into reinventing the services that the GNU build
624 tools provide, and making the same mistakes that they once made and
625 overcame. (Besides, since you're already learning Autoconf, Automake
626 will be a piece of cake.)
627
628 There are a number of places that you can go to for more information on
629 the GNU build tools.
630
631 @itemize @minus
632
633 @item Web
634
635 The home pages for
636 @href{http://www.gnu.org/software/autoconf/,Autoconf}, and
637 @href{http://www.gnu.org/software/libtool/,Libtool}.
638
639 @item Books
640
641 The book @cite{GNU Autoconf, Automake and Libtool}@footnote{@cite{GNU
642 Autoconf, Automake and Libtool}, by G. V. Vaughan, B. Elliston,
643 T. Tromey, and I. L. Taylor. New Riders, 2000, ISBN 1578701902.}
644 describes the complete GNU build environment. You can also find the
645 entire book on-line at @href{http://sources.redhat.com/autobook/,``The
646 Goat Book'' home page}.
647
648 @item Tutorials and Examples
649
650 The @href{http://sources.redhat.com/autoconf/,Autoconf Developer Page}
651 maintains links to a number of Autoconf/Automake tutorials online, and
652 also links to the @href{http://www.gnu.org/software/ac-archive/,
653 Autoconf Macro Archive}.
654
655 @end itemize
656
657 @c ================================================= Making configure Scripts.
658
659 @node Making configure Scripts, Setup, The GNU build system, Top
660 @chapter Making @code{configure} Scripts
661 @cindex @file{aclocal.m4}
662 @cindex @code{configure}
663
664 The configuration scripts that Autoconf produces are by convention
665 called @code{configure}. When run, @code{configure} creates several
666 files, replacing configuration parameters in them with appropriate
667 values. The files that @code{configure} creates are:
668
669 @itemize @minus
670 @item
671 one or more @file{Makefile} files, one in each subdirectory of the
672 package (@pxref{Makefile Substitutions});
673
674 @item
675 optionally, a C header file, the name of which is configurable,
676 containing @code{#define} directives (@pxref{Configuration Headers});
677
678 @item
679 a shell script called @file{config.status} that, when run, will recreate
680 the files listed above (@pxref{config.status Invocation});
681
682 @item
683 an optional shell script normally called @file{config.cache}
684 (created when using @samp{configure --config-cache}) that
685 saves the results of running many of the tests (@pxref{Cache Files});
686
687 @item
688 a file called @file{config.log} containing any messages produced by
689 compilers, to help debugging if @code{configure} makes a mistake.
690 @end itemize
691
692 @cindex @file{configure.in}
693 @cindex @file{configure.ac}
694 To create a @code{configure} script with Autoconf, you need to write an
695 Autoconf input file @file{configure.ac} (or @file{configure.in}) and run
696 @code{autoconf} on it. If you write your own feature tests to
697 supplement those that come with Autoconf, you might also write files
698 called @file{aclocal.m4} and @file{acsite.m4}. If you use a C header
699 file to contain @code{#define} directives, you might also run
700 @code{autoheader}, and you will distribute the generated file
701 @file{config.h.in} with the package.
702
703 Here is a diagram showing how the files that can be used in
704 configuration are produced. Programs that are executed are suffixed by
705 @samp{*}. Optional files are enclosed in square brackets (@samp{[]}).
706 @code{autoconf} and @code{autoheader} also read the installed Autoconf
707 macro files (by reading @file{autoconf.m4}).
708
709 @noindent
710 Files used in preparing a software package for distribution:
711 @example
712 your source files --> [autoscan*] --> [configure.scan] --> configure.ac
713
714 @group
715 configure.ac --.
716 | .------> autoconf* -----> configure
717 [aclocal.m4] --+---+
718 | `-----> [autoheader*] --> [config.h.in]
719 [acsite.m4] ---'
720 @end group
721
722 Makefile.in -------------------------------> Makefile.in
723 @end example
724
725 @noindent
726 Files used in configuring a software package:
727 @example
728 @group
729 .-------------> [config.cache]
730 configure* ------------+-------------> config.log
731 |
732 [config.h.in] -. v .-> [config.h] -.
733 +--> config.status* -+ +--> make*
734 Makefile.in ---' `-> Makefile ---'
735 @end group
736 @end example
737
738 @menu
739 * Writing configure.ac:: What to put in an Autoconf input file
740 * autoscan Invocation:: Semi-automatic @file{configure.ac} writing
741 * ifnames Invocation:: Listing the conditionals in source code
742 * autoconf Invocation:: How to create configuration scripts
743 * autoreconf Invocation:: Remaking multiple @code{configure} scripts
744 @end menu
745
746 @node Writing configure.ac, autoscan Invocation, Making configure Scripts, Making configure Scripts
747 @section Writing @file{configure.ac}
748
749 To produce a @code{configure} script for a software package, create a
750 file called @file{configure.ac} that contains invocations of the
751 Autoconf macros that test the system features your package needs or can
752 use. Autoconf macros already exist to check for many features; see
753 @ref{Existing Tests}, for their descriptions. For most other features,
754 you can use Autoconf template macros to produce custom checks; see
755 @ref{Writing Tests}, for information about them. For especially tricky
756 or specialized features, @file{configure.ac} might need to contain some
757 hand-crafted shell commands; see @ref{Portable Shell}. The
758 @code{autoscan} program can give you a good start in writing
759 @file{configure.ac} (@pxref{autoscan Invocation}, for more information).
760
761 Previous versions of Autoconf promoted the name @file{configure.in},
762 which is somewhat ambiguous (the tool needed to produce this file is not
763 described by its extension), and introduces a slight confusion with
764 @file{config.h.in} and so on (for which @samp{.in} means ``to be
765 processed by @code{configure}''). Using @file{configure.ac} is now
766 preferred.
767
768 @menu
769 * Shell Script Compiler:: Autoconf as solution of a problem
770 * Autoconf Language:: Programming in Autoconf
771 * configure.ac Layout:: Standard organization of configure.ac
772 @end menu
773
774 @node Shell Script Compiler, Autoconf Language, Writing configure.ac, Writing configure.ac
775 @subsection A Shell Script Compiler
776
777 Just as for any other computer language, in order to properly program
778 @file{configure.ac} in Autoconf you must understand @emph{what} problem
779 the language tries to address and @emph{how} it does so.
780
781 The problem Autoconf addresses is that the world is a mess. After all,
782 you are using Autoconf in order to have your package compile easily on
783 all sorts of different systems, some of them being extremely hostile.
784 Autoconf itself bears the price for these differences: @code{configure}
785 must run on all those systems, and thus @code{configure} must limit itself
786 to their lowest common denominator of features.
787
788 Naturally, you might then think of shell scripts; who needs
789 @code{autoconf}? A set of properly written shell functions is enough to
790 make it easy to write @code{configure} scripts by hand. Sigh!
791 Unfortunately, shell functions do not belong to the least common
792 denominator; therefore, where you would like to define a function and
793 use it ten times, you would instead need to copy its body ten times.
794
795 So, what is really needed is some kind of compiler, @code{autoconf},
796 that takes an Autoconf program, @file{configure.ac}, and transforms it
797 into a portable shell script, @code{configure}.
798
799 How does @code{autoconf} perform this task?
800
801 There are two obvious possibilities: creating a brand new language or
802 extending an existing one. The former option is very attractive: all
803 sorts of optimizations could easily be implemented in the compiler and
804 many rigorous checks could be performed on the Autoconf program
805 (e.g. rejecting any non-portable construct). Alternatively, you can
806 extend an existing language, such as the @code{sh} (Bourne shell)
807 language.
808
809 Autoconf does the latter: it is a layer on top of @code{sh}. It was
810 therefore most convenient to implement @code{autoconf} as a macro
811 expander: a program that repeatedly performs @dfn{macro expansions} on
812 text input, replacing macro calls with macro bodies and producing a pure
813 @code{sh} script in the end. Instead of implementing a dedicated
814 Autoconf macro expander, it is natural to use an existing
815 general-purpose macro language, such as M4, and implement the extensions
816 as a set of M4 macros.
817
818
819 @node Autoconf Language, configure.ac Layout, Shell Script Compiler, Writing configure.ac
820 @subsection The Autoconf Language
821 @cindex quotation
822
823 The Autoconf language is very different from many other computer
824 languages because it treats actual code the same as plain text. Whereas
825 in C, for instance, data and instructions have very different syntactic
826 status, in Autoconf their status is rigorously the same. Therefore, we
827 need a means to distinguish literal strings from text to be expanded:
828 quotation.
829
830 When calling macros that take arguments, there must not be any blank
831 space between the macro name and the open parenthesis. Arguments should
832 be enclosed within the M4 quote characters @samp{[} and @samp{]}, and be
833 separated by commas. Any leading spaces in arguments are ignored,
834 unless they are quoted. You may safely leave out the quotes when the
835 argument is simple text, but @emph{always} quote complex arguments such
836 as other macro calls. This rule applies recursively for every macro
837 call, including macros called from other macros.
838
839 For instance:
840
841 @example
842 AC_CHECK_HEADER([stdio.h],
843 [AC_DEFINE([HAVE_STDIO_H])],
844 [AC_MSG_ERROR([Sorry, can't do anything for you])])
845 @end example
846
847 @noindent
848 is quoted properly. You may safely simplify its quotation to:
849
850 @example
851 AC_CHECK_HEADER(stdio.h,
852 [AC_DEFINE(HAVE_STDIO_H)],
853 [AC_MSG_ERROR([Sorry, can't do anything for you])])
854 @end example
855
856 @noindent
857 Notice that the argument of @code{AC_MSG_ERROR} is still quoted;
858 otherwise, its comma would have been interpreted as an argument separator.
859
860 The following example is wrong and dangerous, as it is underquoted:
861
862 @example
863 AC_CHECK_HEADER(stdio.h,
864 AC_DEFINE(HAVE_STDIO_H),
865 AC_MSG_ERROR([Sorry, can't do anything for you]))
866 @end example
867
868 In other cases, you may have to use text that also resembles a macro
869 call. You must quote that text even when it is not passed as a macro
870 argument:
871
872 @example
873 echo "Hard rock was here! --[AC_DC]"
874 @end example
875
876 @noindent
877 which will result in
878
879 @example
880 echo "Hard rock was here! --AC_DC"
881 @end example
882
883 @noindent
884 When you use the same text in a macro argument, you must therefore have
885 an extra quotation level (since one is stripped away by the macro
886 substitution). In general, then, it is a good idea to @emph{use double
887 quoting for all literal string arguments}:
888
889 @example
890 AC_MSG_WARN([[AC_DC stinks --Iron Maiden]])
891 @end example
892
893 You are now able to understand one of the constructs of Autoconf that
894 has been continually misunderstood@dots{} The rule of thumb is that
895 @emph{whenever you expect macro expansion, expect quote expansion};
896 i.e., expect one level of quotes to be lost. For instance:
897
898 @example
899 AC_COMPILE_IFELSE([char b[10];],, [AC_MSG_ERROR([you lose])])
900 @end example
901
902 @noindent
903 is incorrect: here, the first argument of @code{AC_COMPILE_IFELSE} is
904 @samp{char b[10];} and will be expanded once, which results in
905 @samp{char b10;}. (There was an idiom common in Autoconf's past to
906 address this issue via the M4 @code{changequote} primitive, but do not
907 use it!) Let's take a closer look: the author meant the first argument
908 to be understood as a literal, and therefore it must be quoted twice:
909
910 @example
911 AC_COMPILE_IFELSE([[char b[10];]],, [AC_MSG_ERROR([you lose])])
912 @end example
913
914 @noindent
915 Voil@`a, you actually produce @samp{char b[10];} this time!
916
917 The careful reader will notice that, according to these guidelines, the
918 ``properly'' quoted @code{AC_CHECK_HEADER} example above is actually
919 lacking three pairs of quotes! Nevertheless, for the sake of readability,
920 double quotation of literals is used only where needed in this manual.
921
922 Some macros take optional arguments, which this documentation represents
923 as @ovar{arg} (not to be confused with the quote characters). You may
924 just leave them empty, or use @samp{[]} to make the emptiness of the
925 argument explicit, or you may simply omit the trailing commas. The
926 three lines below are equivalent:
927
928 @example
929 AC_CHECK_HEADERS(stdio.h, [], [], [])
930 AC_CHECK_HEADERS(stdio.h,,,)
931 AC_CHECK_HEADERS(stdio.h)
932 @end example
933
934 It is best to put each macro call on its own line in
935 @file{configure.ac}. Most of the macros don't add extra newlines; they
936 rely on the newline after the macro call to terminate the commands.
937 This approach makes the generated @code{configure} script a little
938 easier to read by not inserting lots of blank lines. It is generally
939 safe to set shell variables on the same line as a macro call, because
940 the shell allows assignments without intervening newlines.
941
942 You can include comments in @file{configure.ac} files by starting them
943 with the @samp{#}. For example, it is helpful to begin
944 @file{configure.ac} files with a line like this:
945
946 @example
947 # Process this file with autoconf to produce a configure script.
948 @end example
949
950 @node configure.ac Layout, , Autoconf Language, Writing configure.ac
951 @subsection Standard @file{configure.ac} Layout
952
953 The order in which @file{configure.ac} calls the Autoconf macros is not
954 important, with a few exceptions. Every @file{configure.ac} must
955 contain a call to @code{AC_INIT} before the checks, and a call to
956 @code{AC_OUTPUT} at the end (@pxref{Output}). Additionally, some macros
957 rely on other macros having been called first, because they check
958 previously set values of some variables to decide what to do. These
959 macros are noted in the individual descriptions (@pxref{Existing
960 Tests}), and they also warn you when @code{configure} is created if they
961 are called out of order.
962
963 To encourage consistency, here is a suggested order for calling the
964 Autoconf macros. Generally speaking, the things near the end of this
965 list are those that could depend on things earlier in it. For example,
966 library functions could be affected by types and libraries.
967
968 @display
969 @group
970 Autoconf requirements
971 @code{AC_INIT(@var{package}, @var{version}, @var{bug-report-address})}
972 information on the package
973 checks for programs
974 checks for libraries
975 checks for header files
976 checks for types
977 checks for structures
978 checks for compiler characteristics
979 checks for library functions
980 checks for system services
981 @code{AC_CONFIG_FILES(@r{[}@var{file@dots{}}@r{]})}
982 @code{AC_OUTPUT}
983 @end group
984 @end display
985
986
987 @node autoscan Invocation, ifnames Invocation, Writing configure.ac, Making configure Scripts
988 @section Using @code{autoscan} to Create @file{configure.ac}
989 @cindex @code{autoscan}
990
991 The @code{autoscan} program can help you create and/or maintain a
992 @file{configure.ac} file for a software package. @code{autoscan}
993 examines source files in the directory tree rooted at a directory given
994 as a command line argument, or the current directory if none is given.
995 It searches the source files for common portability problems and creates
996 a file @file{configure.scan} which is a preliminary @file{configure.ac}
997 for that package, and checks a possibly existing @file{configure.ac} for
998 completeness.
999
1000 When using @command{autoscan} to create a @file{configure.ac}, you
1001 should manually examine @file{configure.scan} before renaming it to
1002 @file{configure.ac}; it will probably need some adjustments.
1003 Occasionally, @code{autoscan} outputs a macro in the wrong order
1004 relative to another macro, so that @code{autoconf} produces a warning;
1005 you need to move such macros manually. Also, if you want the package to
1006 use a configuration header file, you must add a call to
1007 @code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers}). You might
1008 also have to change or add some @code{#if} directives to your program in
1009 order to make it work with Autoconf (@pxref{ifnames Invocation}, for
1010 information about a program that can help with that job).
1011
1012 When using @command{autoscan} to maintain a @file{configure.ac}, simply
1013 consider adding its suggestions. The file @file{autoscan.log} will
1014 contain detailed information on why a macro is requested.
1015
1016 @code{autoscan} uses several data files (installed along with Autoconf)
1017 to determine which macros to output when it finds particular symbols in
1018 a package's source files. These data files all have the same format:
1019 each line consists of a symbol, whitespace, and the Autoconf macro to
1020 output if that symbol is encountered. Lines starting with @samp{#} are
1021 comments.
1022
1023 @code{autoscan} is only installed if you already have Perl installed.
1024 @code{autoscan} accepts the following options:
1025
1026 @table @option
1027 @item --help
1028 @itemx -h
1029 Print a summary of the command line options and exit.
1030
1031 @item --version
1032 @itemx -V
1033 Print the version number of Autoconf and exit.
1034
1035 @item --verbose
1036 @itemx -v
1037 Print the names of the files it examines and the potentially interesting
1038 symbols it finds in them. This output can be voluminous.
1039
1040 @item --autoconf-dir=@var{dir}
1041 @itemx -A @var{dir}
1042 @evindex AC_MACRODIR
1043 Override the location where the installed Autoconf data files are looked
1044 for. You can also set the @code{AC_MACRODIR} environment variable to a
1045 directory; this option overrides the environment variable.
1046
1047 This option is rarely needed and dangerous; it is only used when one
1048 plays with different versions of Autoconf simultaneously.
1049 @end table
1050
1051 @node ifnames Invocation, autoconf Invocation, autoscan Invocation, Making configure Scripts
1052 @section Using @code{ifnames} to List Conditionals
1053 @cindex @code{ifnames}
1054
1055 @code{ifnames} can help you write @file{configure.ac} for a software
1056 package. It prints the identifiers that the package already uses in C
1057 preprocessor conditionals. If a package has already been set up to have
1058 some portability, @code{ifnames} can thus help you figure out what its
1059 @code{configure} needs to check for. It may help fill in some gaps in a
1060 @file{configure.ac} generated by @code{autoscan} (@pxref{autoscan
1061 Invocation}).
1062
1063 @code{ifnames} scans all of the C source files named on the command line
1064 (or the standard input, if none are given) and writes to the standard
1065 output a sorted list of all the identifiers that appear in those files
1066 in @code{#if}, @code{#elif}, @code{#ifdef}, or @code{#ifndef}
1067 directives. It prints each identifier on a line, followed by a
1068 space-separated list of the files in which that identifier occurs.
1069
1070 @noindent
1071 @code{ifnames} accepts the following options:
1072
1073 @table @option
1074 @item --help
1075 @itemx -h
1076 Print a summary of the command line options and exit.
1077
1078 @item --version
1079 @itemx -V
1080 Print the version number of Autoconf and exit.
1081 @end table
1082
1083 @node autoconf Invocation, autoreconf Invocation, ifnames Invocation, Making configure Scripts
1084 @section Using @code{autoconf} to Create @code{configure}
1085 @cindex @code{autoconf}
1086
1087 To create @code{configure} from @file{configure.ac}, run the
1088 @code{autoconf} program with no arguments. @code{autoconf} processes
1089 @file{configure.ac} with the @code{m4} macro processor, using the
1090 Autoconf macros. If you give @code{autoconf} an argument, it reads that
1091 file instead of @file{configure.ac} and writes the configuration script
1092 to the standard output instead of to @code{configure}. If you give
1093 @code{autoconf} the argument @option{-}, it reads from the standard
1094 input instead of @file{configure.ac} and writes the configuration script
1095 to the standard output.
1096
1097 The Autoconf macros are defined in several files. Some of the files are
1098 distributed with Autoconf; @code{autoconf} reads them first. Then it
1099 looks for the optional file @file{acsite.m4} in the directory that
1100 contains the distributed Autoconf macro files, and for the optional file
1101 @file{aclocal.m4} in the current directory. Those files can contain
1102 your site's or the package's own Autoconf macro definitions
1103 (@pxref{Writing Autoconf Macros}, for more information). If a macro is defined
1104 in more than one of the files that @code{autoconf} reads, the last
1105 definition it reads overrides the earlier ones.
1106
1107 @code{autoconf} accepts the following options:
1108
1109 @table @option
1110 @item --help
1111 @itemx -h
1112 Print a summary of the command line options and exit.
1113
1114 @item --version
1115 @itemx -V
1116 Print the version number of Autoconf and exit.
1117
1118 @item --verbose
1119 @itemx -v
1120 Report processing steps.
1121
1122 @item --debug
1123 @itemx -d
1124 Don't remove the temporary files.
1125
1126 @item --autoconf-dir=@var{dir}
1127 @itemx -A @var{dir}
1128 @evindex AC_MACRODIR
1129 Override the location where the installed Autoconf data files are looked
1130 for. You can also set the @code{AC_MACRODIR} environment variable to a
1131 directory; this option overrides the environment variable.
1132
1133 This option is rarely needed and dangerous; it is only used when one
1134 plays with different versions of Autoconf simultaneously.
1135
1136 @item --localdir=@var{dir}
1137 @itemx -l @var{dir}
1138 Look for the package file @file{aclocal.m4} in directory @var{dir}
1139 instead of in the current directory.
1140
1141 @item --output=@var{file}
1142 @itemx -o @var{file}
1143 Save output (script or trace) to @var{file}. The file @option{-} stands
1144 for the standard output.
1145
1146 @item --warnings=@var{category}
1147 @itemx -W @var{category}
1148 @evindex WARNINGS
1149 Report the warnings related to @var{category} (which can actually be a
1150 comma separated list). @xref{Reporting Messages}, macro
1151 @code{AC_DIAGNOSE}, for a comprehensive list of categories. Special
1152 values include:
1153
1154 @table @samp
1155 @item all
1156 report all the warnings
1157
1158 @item none
1159 report none
1160
1161 @item error
1162 treats warnings as errors
1163
1164 @item no-@var{category}
1165 disable warnings falling into @var{category}
1166 @end table
1167
1168 Warnings about @samp{syntax} are enabled by default, and the environment
1169 variable @code{WARNINGS}, a comma separated list of categories, is
1170 honored. @command{autoconf -W @var{category}} will actually
1171 behave as if you had run:
1172
1173 @example
1174 autoconf --warnings=syntax,$WARNINGS,@var{category}
1175 @end example
1176
1177 @noindent
1178 If you want to disable @command{autoconf}'s defaults and @code{WARNINGS},
1179 but (for example) enable the warnings about obsolete constructs, you
1180 would use @option{-W none,obsolete}.
1181
1182 @cindex Back trace
1183 @cindex Macro invocation stack
1184 @command{autoconf} displays a back trace for errors, but not for
1185 warnings; if you want them, just pass @option{-W error}. For instance,
1186 on this @file{configure.ac}:
1187
1188 @example
1189 AC_DEFUN([INNER],
1190 [AC_TRY_RUN([true])])
1191
1192 AC_DEFUN([OUTER],
1193 [INNER])
1194
1195 AC_INIT
1196 OUTER
1197 @end example
1198
1199 @noindent
1200 you get:
1201
1202 @example
1203 $ autoconf -Wcross
1204 configure.ac:8: warning: AC_TRY_RUN called without default \
1205 to allow cross compiling
1206 $ autoconf -Wcross,error
1207 configure.ac:8: error: AC_TRY_RUN called without default \
1208 to allow cross compiling
1209 acgeneral.m4:3044: AC_TRY_RUN is expanded from...
1210 configure.ac:2: INNER is expanded from...
1211 configure.ac:5: OUTER is expanded from...
1212 configure.ac:8: the top level
1213 @end example
1214
1215 @item --trace=@var{macro}[:@var{format}]
1216 @itemx -t @var{macro}[:@var{format}]
1217 Do not create the @code{configure} script, but list the calls to
1218 @var{macro} according to the @var{format}. Multiple @option{--trace}
1219 arguments can be used to list several macros. Multiple @option{--trace}
1220 arguments for a single macro are not cumulative; instead, you should
1221 just make @var{format} as long as needed.
1222
1223 The @var{format} is a regular string, with newlines if desired, and
1224 several special escape codes. It defaults to @samp{$f:$l:$n:$%}; see
1225 below for details on the @var{format}.
1226
1227 @item --initialization
1228 @itemx -i
1229 By default, @option{--trace} does not trace the initialization of the
1230 Autoconf macros (typically the @code{AC_DEFUN} definitions). This
1231 results in a noticeable speedup, but can be disabled by this option.
1232 @end table
1233
1234
1235 It is often necessary to check the content of a @file{configure.ac}
1236 file, but parsing it yourself is extremely fragile and error-prone. It
1237 is suggested that you rely upon @option{--trace} to scan
1238 @file{configure.ac}.
1239
1240 The @var{format} of @option{--trace} can use the following special
1241 escapes:
1242
1243 @table @samp
1244 @item $$
1245 The character @samp{$}.
1246
1247 @item $f
1248 The filename from which @var{macro} is called.
1249
1250 @item $l
1251 The line number from which @var{macro} is called.
1252
1253 @item $d
1254 The depth of the @var{macro} call. This is an M4 technical detail that
1255 you probably don't want to know about.
1256
1257 @item $n
1258 The name of the @var{macro}.
1259
1260 @item $@var{num}
1261 The @var{num}th argument of the call to @var{macro}.
1262
1263 @item $@@
1264 @itemx $@var{sep}@@
1265 @itemx $@{@var{separator}@}@@
1266 All the arguments passed to @var{macro}, separated by the character
1267 @var{sep} or the string @var{separator} (@samp{,} by default). Each
1268 argument is quoted, i.e. enclosed in a pair of square brackets.
1269
1270 @item $*
1271 @itemx $@var{sep}*
1272 @itemx $@{@var{separator}@}*
1273 As above, but the arguments are not quoted.
1274
1275 @item $%
1276 @itemx $@var{sep}%
1277 @itemx $@{@var{separator}@}%
1278 As above, but the arguments are not quoted, all new line characters in
1279 the arguments are smashed, and the default separator is @samp{:}.
1280
1281 The escape @samp{$%} produces single-line trace outputs (unless you put
1282 newlines in the @samp{separator}), while @samp{$@@} and @samp{$*} do
1283 not.
1284 @end table
1285
1286 For instance, to find the list of variables that are substituted, use:
1287
1288 @example
1289 @group
1290 $ autoconf -t AC_SUBST
1291 configure.ac:2:AC_SUBST:ECHO_C
1292 configure.ac:2:AC_SUBST:ECHO_N
1293 configure.ac:2:AC_SUBST:ECHO_T
1294 @i{More traces deleted}
1295 @end group
1296 @end example
1297
1298 @noindent
1299 The example below highlights the difference between @samp{$@@},
1300 @samp{$*}, and @strong{$%}.
1301
1302 @example
1303 @group
1304 $ cat configure.ac
1305 AC_DEFINE(This, is, [an
1306 [example]])
1307 $ autoconf -t 'AC_DEFINE:@@: $@@
1308 *: $*
1309 $: $%'
1310 @@: [This],[is],[an
1311 [example]]
1312 *: This,is,an
1313 [example]
1314 $: This:is:an [example]
1315 @end group
1316 @end example
1317
1318 @noindent
1319 The @var{format} gives you a lot of freedom:
1320
1321 @example
1322 @group
1323 $ autoconf -t 'AC_SUBST:$$ac_subst@{"$1"@} = "$f:$l";'
1324 $ac_subst@{"ECHO_C"@} = "configure.ac:2";
1325 $ac_subst@{"ECHO_N"@} = "configure.ac:2";
1326 $ac_subst@{"ECHO_T"@} = "configure.ac:2";
1327 @i{More traces deleted}
1328 @end group
1329 @end example
1330
1331 @noindent
1332 A long @var{separator} can be used to improve the readability of complex
1333 structures, and to ease its parsing (for instance when no single
1334 character is suitable as a separator)):
1335
1336 @example
1337 @group
1338 $ autoconf -t 'AM_MISSING_PROG:$@{|:::::|@}*'
1339 AUTOCONF|:::::|autoconf|:::::|$missing_dir
1340 @i{More traces deleted}
1341 @end group
1342 @end example
1343
1344 @node autoreconf Invocation, , autoconf Invocation, Making configure Scripts
1345 @section Using @code{autoreconf} to Update @code{configure} Scripts
1346 @cindex @code{autoreconf}
1347
1348 If you have a lot of Autoconf-generated @code{configure} scripts, the
1349 @code{autoreconf} program can save you some work. It runs
1350 @code{autoconf} (and @code{autoheader}, where appropriate) repeatedly to
1351 remake the Autoconf @code{configure} scripts and configuration header
1352 templates in the directory tree rooted at the current directory. By
1353 default, it only remakes those files that are older than their
1354 @file{configure.ac} or (if present) @file{aclocal.m4}. Since
1355 @code{autoheader} does not change the timestamp of its output file if
1356 the file wouldn't be changing, this is not necessarily the minimum
1357 amount of work. If you install a new version of Autoconf, you can make
1358 @code{autoreconf} remake @emph{all} of the files by giving it the
1359 @option{--force} option.
1360
1361 If you give @code{autoreconf} the @option{--autoconf-dir=@var{dir}} or
1362 @option{--localdir=@var{dir}} options, it passes them down to
1363 @code{autoconf} and @code{autoheader} (with relative paths adjusted
1364 properly).
1365
1366 @code{autoreconf} does not support having, in the same directory tree,
1367 both directories that are parts of a larger package (sharing
1368 @file{aclocal.m4} and @file{acconfig.h}) and directories that are
1369 independent packages (each with their own @file{aclocal.m4} and
1370 @file{acconfig.h}). It assumes that they are all part of the same
1371 package if you use @option{--localdir}, or that each directory is a
1372 separate package if you don't use it. This restriction may be removed
1373 in the future.
1374
1375 @xref{Automatic Remaking}, for @file{Makefile} rules to automatically
1376 remake @code{configure} scripts when their source files change. That
1377 method handles the timestamps of configuration header templates
1378 properly, but does not pass @option{--autoconf-dir=@var{dir}} or
1379 @option{--localdir=@var{dir}}.
1380
1381 @noindent
1382 @code{autoreconf} accepts the following options:
1383
1384 @table @option
1385 @item --help
1386 @itemx -h
1387 Print a summary of the command line options and exit.
1388
1389 @item --version
1390 @itemx -V
1391 Print the version number of Autoconf and exit.
1392
1393 @item --verbose
1394 Print the name of each directory where @code{autoreconf} runs
1395 @code{autoconf} (and @code{autoheader}, if appropriate).
1396
1397 @item --debug
1398 @itemx -d
1399 Don't remove the temporary files.
1400
1401 @item --force
1402 @itemx -f
1403 Remake even @file{configure} scripts and configuration headers that are
1404 newer than their input files (@file{configure.ac} and, if present,
1405 @file{aclocal.m4}).
1406
1407 @item --install
1408 @itemx -i
1409 Copy missing auxiliary files. This option is similar to the option
1410 @code{--add-missing} in other tools.
1411
1412 @item --symlink
1413 @itemx -s
1414 Instead of copying missing auxiliary files, install symbolic links.
1415
1416 @item --localdir=@var{dir}
1417 @itemx -l @var{dir}
1418 Have @code{autoconf} and @code{autoheader} look for the package files
1419 @file{aclocal.m4} and (@code{autoheader} only) @file{acconfig.h} (but
1420 not @file{@var{file}.top} and @file{@var{file}.bot}) in directory
1421 @var{dir} instead of in the directory containing each @file{configure.ac}.
1422
1423 @item --autoconf-dir=@var{dir}
1424 @itemx -A @var{dir}
1425 @evindex AC_MACRODIR
1426 Override the location where the installed Autoconf data files are looked
1427 for. You can also set the @code{AC_MACRODIR} environment variable to a
1428 directory; this option overrides the environment variable.
1429
1430 This option is rarely needed and dangerous; it is only used when one
1431 plays with different versions of Autoconf simultaneously.
1432
1433 @item --m4dir=@var{dir}
1434 @itemx -M @var{dir}
1435 Specify location of additional macro files (@file{m4} by default).
1436 @end table
1437
1438
1439 @c ========================================= Initialization and Output Files.
1440
1441 @node Setup, Existing Tests, Making configure Scripts, Top
1442 @chapter Initialization and Output Files
1443
1444 Autoconf-generated @code{configure} scripts need some information about
1445 how to initialize, such as how to find the package's source files; and
1446 about the output files to produce. The following sections describe
1447 initialization and the creation of output files.
1448
1449 @menu
1450 * Notices:: Copyright, version numbers in @code{configure}
1451 * Input:: Where Autoconf should find files
1452 * Output:: Outputting results from the configuration
1453 * Configuration Actions:: Preparing the output based on results
1454 * Configuration Files:: Creating output files
1455 * Makefile Substitutions:: Using output variables in @file{Makefile}s
1456 * Configuration Headers:: Creating a configuration header file
1457 * Configuration Commands:: Running arbitrary instantiation commands
1458 * Configuration Links:: Links depending from the configuration
1459 * Subdirectories:: Configuring independent packages together
1460 * Default Prefix:: Changing the default installation prefix
1461 @end menu
1462
1463 @node Notices, Input, Setup, Setup
1464 @section Notices in @code{configure}
1465
1466 The following macros manage version numbers for @code{configure}
1467 scripts. Using them is optional.
1468
1469 @c FIXME: AC_PREREQ should not be here, but where should it go?
1470 @defmac AC_PREREQ (@var{version})
1471 @maindex PREREQ
1472 @cindex Version
1473 Ensure that a recent enough version of Autoconf is being used. If the
1474 version of Autoconf being used to create @code{configure} is earlier
1475 than @var{version}, print an error message to the standard error output
1476 and do not create @code{configure}. For example:
1477
1478 @example
1479 AC_PREREQ(@value{VERSION})
1480 @end example
1481
1482 This macro is the only macro that may be used before @code{AC_INIT}, but
1483 for consistency, you are invited not to do so.
1484 @end defmac
1485
1486 @defmac AC_COPYRIGHT (@var{copyright-notice})
1487 @maindex COPYRIGHT
1488 @cindex Copyright Notice
1489 State that, in addition to the Free Software Foundation's copyright on
1490 the Autoconf macros, parts of your @code{configure} are covered by the
1491 @var{copyright-notice}.
1492
1493 The @var{copyright-notice} will show up in both the head of
1494 @code{configure} and in @samp{configure --version}.
1495 @end defmac
1496
1497
1498 @defmac AC_REVISION (@var{revision-info})
1499 @maindex REVISION
1500 @cindex Revision
1501 Copy revision stamp @var{revision-info} into the @code{configure}
1502 script, with any dollar signs or double-quotes removed. This macro lets
1503 you put a revision stamp from @file{configure.ac} into @code{configure}
1504 without @sc{rcs} or @code{cvs} changing it when you check in
1505 @code{configure}. That way, you can determine easily which revision of
1506 @file{configure.ac} a particular @code{configure} corresponds to.
1507
1508 For example, this line in @file{configure.ac}:
1509
1510 @c The asis prevents RCS from changing the example in the manual.
1511 @example
1512 AC_REVISION($@asis{Revision: 1.30 }$)
1513 @end example
1514
1515 @noindent
1516 produces this in @code{configure}:
1517
1518 @example
1519 #! /bin/sh
1520 # From configure.ac Revision: 1.30
1521 @end example
1522 @end defmac
1523
1524
1525 @node Input, Output, Notices, Setup
1526 @section Finding @code{configure} Input
1527
1528 Every @code{configure} script must call @code{AC_INIT} before doing
1529 anything else. The only other required macro is @code{AC_OUTPUT}
1530 (@pxref{Output}).
1531
1532 @defmac AC_INIT (@var{package}, @var{version}, @ovar{bug-report-address})
1533 @maindex INIT
1534 Process any command-line arguments and perform various initializations
1535 and verifications. Set the name of the @var{package} and its
1536 @var{version}. The optional argument @var{bug-report-address} should be
1537 the email to which users should send bug reports.
1538 @end defmac
1539
1540 @defmac AC_CONFIG_SRCDIR (@var{unique-file-in-source-dir})
1541 @maindex CONFIG_SRCDIR
1542 @var{unique-file-in-source-dir} is some file that is in the package's
1543 source directory; @code{configure} checks for this file's existence to
1544 make sure that the directory that it is told contains the source code in
1545 fact does. Occasionally people accidentally specify the wrong directory
1546 with @option{--srcdir}; this is a safety check. @xref{configure
1547 Invocation}, for more information.
1548 @end defmac
1549
1550
1551 @c FIXME: Remove definitively once --install explained.
1552 @c
1553 @c Small packages may store all their macros in @code{aclocal.m4}. As the
1554 @c set of macros grows, or for maintenance reasons, a maintainer may prefer
1555 @c to split the macros in several files. In this case, Autoconf must be
1556 @c told which files to load, and in which order.
1557 @c
1558 @c @defmac AC_INCLUDE (@var{file}@dots{})
1559 @c @maindex INCLUDE
1560 @c @c FIXME: There is no longer shell globbing.
1561 @c Read the macro definitions that appear in the listed files. A list of
1562 @c space-separated filenames or shell globbing patterns is expected. The
1563 @c files will be read in the order they're listed.
1564 @c
1565 @c Because the order of definition of macros is important (only the last
1566 @c definition of a macro is used), beware that it is @code{AC_INIT} that
1567 @c loads @file{acsite.m4} and @file{aclocal.m4}. Note that
1568 @c @code{AC_INCLUDE}ing a file before @code{AC_INIT} or within
1569 @c @file{aclocal.m4} is different from doing so after @code{AC_INIT}: in
1570 @c the latter case, non-macro lines from included files may end up in the
1571 @c @file{configure} script, whereas in the former case, they'd be discarded
1572 @c just like any text that appear before @code{AC_INIT}.
1573 @c @end defmac
1574
1575 Packages that do manual configuration or use the @code{install} program
1576 might need to tell @code{configure} where to find some other shell
1577 scripts by calling @code{AC_CONFIG_AUX_DIR}, though the default places
1578 it looks are correct for most cases.
1579
1580 @defmac AC_CONFIG_AUX_DIR (@var{dir})
1581 @maindex CONFIG_AUX_DIR
1582 Use the auxiliary build tools (e.g., @file{install-sh},
1583 @file{config.sub}, @file{config.guess}, Cygnus @code{configure},
1584 Automake and Libtool scripts etc.) that are in directory @var{dir}.
1585 These are auxiliary files used in configuration. @var{dir} can be
1586 either absolute or relative to @file{@var{srcdir}}. The default is
1587 @file{@var{srcdir}} or @file{@var{srcdir}/..} or
1588 @file{@var{srcdir}/../..}, whichever is the first that contains
1589 @file{install-sh}. The other files are not checked for, so that using
1590 @code{AC_PROG_INSTALL} does not automatically require distributing the
1591 other auxiliary files. It checks for @file{install.sh} also, but that
1592 name is obsolete because some @command{make} have a rule that creates
1593 @file{install} from it if there is no @file{Makefile}.
1594 @end defmac
1595
1596
1597 @node Output, Configuration Actions, Input, Setup
1598 @section Outputting Files
1599
1600 Every Autoconf-generated @code{configure} script must finish by calling
1601 @code{AC_OUTPUT}. It is the macro that generates @file{config.status},
1602 which will create the @file{Makefile}s and any other files resulting
1603 from configuration. The only other required macro is @code{AC_INIT}
1604 (@pxref{Input}).
1605
1606 @defmac AC_OUTPUT
1607 @maindex OUTPUT
1608 @cindex Instantiation
1609 Generate @file{config.status} and launch it. Call this macro once, at
1610 the end of @file{configure.ac}.
1611
1612 @file{config.status} will take all the configuration actions: all the
1613 output files (see @ref{Configuration Files}, macro
1614 @code{AC_CONFIG_FILES}), header files (see @ref{Configuration Headers},
1615 macro @code{AC_CONFIG_HEADERS}), commands (see @ref{Configuration
1616 Commands}, macro @code{AC_CONFIG_COMMANDS}), links (see
1617 @ref{Configuration Links}, macro @code{AC_CONFIG_LINKS}), subdirectories
1618 to configure (see @ref{Subdirectories}, macro @code{AC_CONFIG_SUBDIRS})
1619 are honored.
1620 @end defmac
1621
1622 Historically, the usage of @code{AC_OUTPUT} was somewhat different.
1623 @xref{Obsolete Macros}, for a description of the arguments that
1624 @code{AC_OUTPUT} used to support.
1625
1626
1627 If you run @code{make} on subdirectories, you should run it using the
1628 @code{make} variable @code{MAKE}. Most versions of @code{make} set
1629 @code{MAKE} to the name of the @code{make} program plus any options it
1630 was given. (But many do not include in it the values of any variables
1631 set on the command line, so those are not passed on automatically.)
1632 Some old versions of @code{make} do not set this variable. The
1633 following macro allows you to use it even with those versions.
1634
1635 @defmac AC_PROG_MAKE_SET
1636 @maindex PROG_MAKE_SET
1637 @ovindex SET_MAKE
1638 If @code{make} predefines the variable @code{MAKE}, define output
1639 variable @code{SET_MAKE} to be empty. Otherwise, define @code{SET_MAKE}
1640 to contain @samp{MAKE=make}. Calls @code{AC_SUBST} for @code{SET_MAKE}.
1641 @end defmac
1642
1643 To use this macro, place a line like this in each @file{Makefile.in}
1644 that runs @code{MAKE} on other directories:
1645
1646 @example
1647 @@SET_MAKE@@
1648 @end example
1649
1650
1651
1652 @node Configuration Actions, Configuration Files, Output, Setup
1653 @section Taking Configuration Actions
1654
1655 @file{configure} is designed so that it appears to do everything itself,
1656 but there is actually a hidden slave: @file{config.status}.
1657 @file{configure} is in charge of examining your system, but it is
1658 @file{config.status} that actually takes the proper actions based on the
1659 results of @file{configure}. The most typical task of
1660 @file{config.status} is to @emph{instantiate} files.
1661
1662 This section describes the common behavior of the four standard
1663 instantiating macros: @code{AC_CONFIG_FILES}, @code{AC_CONFIG_HEADERS},
1664 @code{AC_CONFIG_COMMANDS} and @code{AC_CONFIG_LINKS}. They all
1665 have this prototype:
1666
1667 @c Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
1668 @c awful.
1669 @example
1670 AC_CONFIG_FOOS(@var{tag}@dots{}, [@var{commands}], [@var{init-cmds}])
1671 @end example
1672
1673 @noindent
1674 where the arguments are:
1675
1676 @table @var
1677 @item @var{tag}@dots{}
1678 A whitespace-separated list of tags, which are typically the names of
1679 the files to instantiate.
1680
1681 @item commands
1682 Shell commands output literally into @file{config.status}, and
1683 associated with a tag that the user can use to tell @file{config.status}
1684 which the commands to run. The commands are run each time a @var{tag}
1685 request is given to @file{config.status}; typically, each time the file
1686 @file{@var{tag}} is created.
1687
1688 @item init-cmds
1689 Shell commands output @emph{unquoted} near the beginning of
1690 @file{config.status}, and executed each time @file{config.status} runs
1691 (regardless of the tag). Because they are unquoted, for example,
1692 @samp{$var} will be output as the value of @code{var}. @var{init-cmds}
1693 is typically used by @file{configure} to give @file{config.status} some
1694 variables it needs to run the @var{commands}.
1695 @end table
1696
1697 All these macros can be called multiple times, with different
1698 @var{tag}s, of course!
1699
1700 You are encouraged to use literals as @var{tags}. In particular, you
1701 should avoid
1702
1703 @example
1704 @dots{} && my_foos="$my_foos fooo"
1705 @dots{} && my_foos="$my_foos foooo"
1706 AC_CONFIG_FOOS($my_foos)
1707 @end example
1708
1709 @noindent
1710 and use this instead:
1711
1712 @example
1713 @dots{} && AC_CONFIG_FOOS(fooo)
1714 @dots{} && AC_CONFIG_FOOS(foooo)
1715 @end example
1716
1717 The macro @code{AC_CONFIG_FILES} and @code{AC_CONFIG_HEADERS} use
1718 specials @var{tag}s: they may have the form @samp{@var{output}} or
1719 @samp{@var{output}:@var{inputs}}. The file @var{output} is instantiated
1720 from its templates, @var{inputs} if specified, defaulting to
1721 @samp{@var{output}.in}.
1722
1723 For instance
1724 @samp{AC_CONFIG_FILES(Makefile:boiler/top.mk:boiler/bot.mk)} asks for
1725 the creation of @file{Makefile} that will be the expansion of the
1726 output variables in the concatenation of @file{boiler/top.mk} and
1727 @file{boiler/bot.mk}.
1728
1729 The special value @samp{-} might be used to denote the standard output
1730 when used in @var{output}, or the standard input when used in the
1731 @var{inputs}. You most probably don't need to use this in
1732 @file{configure.ac}, but it is convenient when using the command line
1733 interface of @file{./config.status}, see @ref{config.status Invocation},
1734 for more details.
1735
1736 The @var{inputs} may be absolute or relative filenames. In the latter
1737 case they are first looked for in the build tree, and then in the source
1738 tree.
1739
1740
1741 @node Configuration Files, Makefile Substitutions, Configuration Actions, Setup
1742 @section Creating Configuration Files
1743
1744 Be sure to read the previous section, @ref{Configuration Actions}.
1745
1746 @defmac AC_CONFIG_FILES (@var{file}@dots{}, @ovar{cmds}, @ovar{init-cmds})
1747 @maindex CONFIG_FILES
1748 Make @code{AC_OUTPUT} create each @file{@var{file}} by copying an input
1749 file (by default @file{@var{file}.in}), substituting the output variable
1750 values.
1751 @c Before we used to have this feature, which was later rejected
1752 @c because it complicates the write of Makefiles:
1753 @c If the file would be unchanged, it is left untouched, to preserve
1754 @c timestamp.
1755 This macro is one of the instantiating macros, see @ref{Configuration
1756 Actions}. @xref{Makefile Substitutions}, for more information on using
1757 output variables. @xref{Setting Output Variables}, for more information
1758 on creating them. This macro creates the directory that the file is in
1759 if it doesn't exist. Usually, @file{Makefile}s are created this way,
1760 but other files, such as @file{.gdbinit}, can be specified as well.
1761
1762 Typical calls to @code{AC_CONFIG_FILES} look like this:
1763
1764 @example
1765 AC_CONFIG_FILES(Makefile src/Makefile man/Makefile X/Imakefile)
1766 AC_CONFIG_FILES(autoconf, chmod +x autoconf)
1767 @end example
1768
1769 You can override an input file name by appending to @var{file} a
1770 colon-separated list of input files. Examples:
1771
1772 @example
1773 AC_CONFIG_FILES(Makefile:boiler/top.mk:boiler/bot.mk
1774 lib/Makefile:boiler/lib.mk)
1775 @end example
1776
1777 @noindent
1778 Doing this allows you to keep your file names acceptable to MS-DOS, or
1779 to prepend and/or append boilerplate to the file.
1780 @end defmac
1781
1782
1783
1784 @node Makefile Substitutions, Configuration Headers, Configuration Files, Setup
1785 @section Substitutions in Makefiles
1786
1787 Each subdirectory in a distribution that contains something to be
1788 compiled or installed should come with a file @file{Makefile.in}, from
1789 which @code{configure} will create a @file{Makefile} in that directory.
1790 To create a @file{Makefile}, @code{configure} performs a simple variable
1791 substitution, replacing occurrences of @samp{@@@var{variable}@@} in
1792 @file{Makefile.in} with the value that @code{configure} has determined
1793 for that variable. Variables that are substituted into output files in
1794 this way are called @dfn{output variables}. They are ordinary shell
1795 variables that are set in @code{configure}. To make @code{configure}
1796 substitute a particular variable into the output files, the macro
1797 @code{AC_SUBST} must be called with that variable name as an argument.
1798 Any occurrences of @samp{@@@var{variable}@@} for other variables are
1799 left unchanged. @xref{Setting Output Variables}, for more information
1800 on creating output variables with @code{AC_SUBST}.
1801
1802 A software package that uses a @code{configure} script should be
1803 distributed with a file @file{Makefile.in}, but no @file{Makefile}; that
1804 way, the user has to properly configure the package for the local system
1805 before compiling it.
1806
1807 @xref{Makefile Conventions,, Makefile Conventions, standards, The
1808 GNU Coding Standards}, for more information on what to put in
1809 @file{Makefile}s.
1810
1811 @menu
1812 * Preset Output Variables:: Output variables that are always set
1813 * Installation Directory Variables:: Other preset output variables
1814 * Build Directories:: Supporting multiple concurrent compiles
1815 * Automatic Remaking:: Makefile rules for configuring
1816 @end menu
1817
1818 @node Preset Output Variables, Installation Directory Variables, Makefile Substitutions, Makefile Substitutions
1819 @subsection Preset Output Variables
1820
1821 Some output variables are preset by the Autoconf macros. Some of the
1822 Autoconf macros set additional output variables, which are mentioned in
1823 the descriptions for those macros. @xref{Output Variable Index}, for a
1824 complete list of output variables. @xref{Installation Directory
1825 Variables}, for the list of the preset ones related to installation
1826 directories. Below are listed the other preset ones. They all are
1827 precious variables (@pxref{Setting Output Variables},
1828 @code{AC_ARG_VAR}).
1829
1830 @c Just say no to ASCII sorting! We're humans, not computers.
1831 @c These variables are listed as they would be in a dictionary:
1832 @c actor
1833 @c Actress
1834 @c actress
1835
1836 @defvar CFLAGS
1837 @ovindex CFLAGS
1838 Debugging and optimization options for the C compiler. If it is not set
1839 in the environment when @code{configure} runs, the default value is set
1840 when you call @code{AC_PROG_CC} (or empty if you don't). @code{configure}
1841 uses this variable when compiling programs to test for C features.
1842 @end defvar
1843
1844 @defvar configure_input
1845 @ovindex configure_input
1846 A comment saying that the file was generated automatically by
1847 @code{configure} and giving the name of the input file.
1848 @code{AC_OUTPUT} adds a comment line containing this variable to the top
1849 of every @file{Makefile} it creates. For other files, you should
1850 reference this variable in a comment at the top of each input file. For
1851 example, an input shell script should begin like this:
1852
1853 @example
1854 #! /bin/sh
1855 # @@configure_input@@
1856 @end example
1857
1858 @noindent
1859 The presence of that line also reminds people editing the file that it
1860 needs to be processed by @code{configure} in order to be used.
1861 @end defvar
1862
1863 @defvar CPPFLAGS
1864 @ovindex CPPFLAGS
1865 Header file search directory (@option{-I@var{dir}}) and any other
1866 miscellaneous options for the C and C++ preprocessors and compilers. If
1867 it is not set in the environment when @code{configure} runs, the default
1868 value is empty. @code{configure} uses this variable when compiling or
1869 preprocessing programs to test for C and C++ features.
1870 @end defvar
1871
1872 @defvar CXXFLAGS
1873 @ovindex CXXFLAGS
1874 Debugging and optimization options for the C++ compiler. If it is not
1875 set in the environment when @code{configure} runs, the default value is
1876 set when you call @code{AC_PROG_CXX} (or empty if you don't).
1877 @code{configure} uses this variable when compiling programs to test for
1878 C++ features.
1879 @end defvar
1880
1881 @defvar DEFS
1882 @ovindex DEFS
1883 @option{-D} options to pass to the C compiler. If @code{AC_CONFIG_HEADERS}
1884 is called, @code{configure} replaces @samp{@@DEFS@@} with
1885 @option{-DHAVE_CONFIG_H} instead (@pxref{Configuration Headers}). This
1886 variable is not defined while @code{configure} is performing its tests,
1887 only when creating the output files. @xref{Setting Output Variables}, for
1888 how to check the results of previous tests.
1889 @end defvar
1890
1891 @defvar ECHO_C
1892 @defvarx ECHO_N
1893 @defvarx ECHO_T
1894 @ovindex ECHO_C
1895 @ovindex ECHO_N
1896 @ovindex ECHO_T
1897 How does one suppress the trailing newline from @code{echo} for
1898 question-answer message pairs? These variables provide a way:
1899
1900 @example
1901 echo $ECHO_N "And the winner is... $ECHO_C"
1902 sleep 100000000000
1903 echo "$@{ECHO_T@}dead."
1904 @end example
1905
1906 @noindent
1907 Some old and uncommon @code{echo} implementations offer no means to
1908 achieve this, in which case @code{ECHO_T} is set to tab. You might not
1909 want to use it.
1910 @end defvar
1911
1912 @defvar FFLAGS
1913 @ovindex FFLAGS
1914 Debugging and optimization options for the Fortran 77 compiler. If it
1915 is not set in the environment when @code{configure} runs, the default
1916 value is set when you call @code{AC_PROG_F77} (or empty if you don't).
1917 @code{configure} uses this variable when compiling programs to test for
1918 Fortran 77 features.
1919 @end defvar
1920
1921 @defvar LDFLAGS
1922 @ovindex LDFLAGS
1923 Stripping (@option{-s}), path (@option{-L}), and any other miscellaneous
1924 options for the linker. Don't use this variable to pass library names
1925 (@option{-l}) to the linker, use @code{LIBS} instead. If it is not set
1926 in the environment when @code{configure} runs, the default value is empty.
1927 @code{configure} uses this variable when linking programs to test for
1928 C, C++ and Fortran 77 features.
1929 @end defvar
1930
1931 @defvar LIBS
1932 @ovindex LIBS
1933 @option{-l} options to pass to the linker. The default value is empty,
1934 but some Autoconf macros may prepend extra libraries to this variable if
1935 those libraries are found and provide necessary functions, see
1936 @ref{Libraries}. @code{configure} uses this variable when linking
1937 programs to test for C, C++ and Fortran 77 features.
1938 @end defvar
1939
1940 @defvar srcdir
1941 @ovindex srcdir
1942 The directory that contains the source code for that @file{Makefile}.
1943 @end defvar
1944
1945 @defvar top_srcdir
1946 @ovindex top_srcdir
1947 The top-level source code directory for the package. In the top-level
1948 directory, this is the same as @code{srcdir}.
1949 @end defvar
1950
1951 @node Installation Directory Variables, Build Directories, Preset Output Variables, Makefile Substitutions
1952 @subsection Installation Directory Variables
1953
1954 The following variables specify the directories where the package will
1955 be installed, see @ref{Directory Variables,, Variables for Installation
1956 Directories, standards, The GNU Coding Standards}, for more information.
1957 See the end of this section for details on when and how to use these
1958 variables.
1959
1960 @defvar bindir
1961 @ovindex bindir
1962 The directory for installing executables that users run.
1963 @end defvar
1964
1965 @defvar datadir
1966 @ovindex datadir
1967 The directory for installing read-only architecture-independent data.
1968 @end defvar
1969
1970 @defvar exec_prefix
1971 @ovindex exec_prefix
1972 The installation prefix for architecture-dependent files. By default
1973 it's the same as @var{prefix}. You should avoid installing anything
1974 directly to @var{exec_prefix}. However, the default value for
1975 directories containing architecture-dependent files should be relative
1976 to @var{exec_prefix}.
1977 @end defvar
1978
1979 @defvar includedir
1980 @ovindex includedir
1981 The directory for installing C header files.
1982 @end defvar
1983
1984 @defvar infodir
1985 @ovindex infodir
1986 The directory for installing documentation in Info format.
1987 @end defvar
1988
1989 @defvar libdir
1990 @ovindex libdir
1991 The directory for installing object code libraries.
1992 @end defvar
1993
1994 @defvar libexecdir
1995 @ovindex libexecdir
1996 The directory for installing executables that other programs run.
1997 @end defvar
1998
1999 @defvar localstatedir
2000 @ovindex localstatedir
2001 The directory for installing modifiable single-machine data.
2002 @end defvar
2003
2004 @defvar mandir
2005 @ovindex mandir
2006 The top-level directory for installing documentation in man format.
2007 @end defvar
2008
2009 @defvar oldincludedir
2010 @ovindex oldincludedir
2011 The directory for installing C header files for non-gcc compilers.
2012 @end defvar
2013
2014 @defvar prefix
2015 @ovindex prefix
2016 The common installation prefix for all files. If @var{exec_prefix}
2017 is defined to a different value, @var{prefix} is used only for
2018 architecture-independent files.
2019 @end defvar
2020
2021 @defvar sbindir
2022 @ovindex sbindir
2023 The directory for installing executables that system
2024 administrators run.
2025 @end defvar
2026
2027 @defvar sharedstatedir
2028 @ovindex sharedstatedir
2029 The directory for installing modifiable architecture-independent data.
2030 @end defvar
2031
2032 @defvar sysconfdir
2033 @ovindex sysconfdir
2034 The directory for installing read-only single-machine data.
2035 @end defvar
2036
2037
2038 Most of these variables have values that rely on @code{prefix} or
2039 @code{exec_prefix}. It is on purpose that the directory output
2040 variables keep them unexpanded: typically @samp{@@datadir@@} will be
2041 replaced by @samp{$@{prefix@}/share}, not @samp{/usr/local/share}.
2042
2043 This behavior is mandated by the @sc{gnu} coding standards, so that when
2044 the user runs:
2045
2046 @table @samp
2047 @item make
2048 she can still specify a different prefix from the one specified to
2049 @command{configure}, in which case, if needed, the package shall hard
2050 code dependencies to her late desires.
2051
2052 @item make install
2053 she can specify a different installation location, in which case the
2054 package @emph{must} still depend on the location which was compiled in
2055 (i.e., never recompile when @samp{make install} is run). This is an
2056 extremely important feature, as many people may decide to install all
2057 the files of a package grouped together, and then install links from
2058 the final locations to there.
2059 @end table
2060
2061 In order to support these features, it is essential that @code{datadir}
2062 remains being defined as @samp{$@{prefix@}/share} to depend upon the
2063 current value of @code{prefix}.
2064
2065 A corollary is that you should not use these variables but in Makefiles.
2066 For instance, instead of trying to evaluate @code{datadir} in
2067 @file{configure} and hardcoding it in Makefiles using
2068 e.g. @samp{AC_DEFINE_UNQUOTED(DATADIR, "$datadir")}, you should add
2069 @samp{-DDATADIR="$(datadir)"} to your @code{CPPFLAGS}.
2070
2071 Similarly you should not rely on @code{AC_OUTPUT_FILES} to replace
2072 @code{datadir} and friends in your shell scripts and other files, rather
2073 let @command{make} manage their replacement. For instance Autoconf
2074 ships templates of its shell scripts ending with @samp{.sh}, and uses
2075 this Makefile snippet:
2076
2077 @example
2078 .sh:
2079 rm -f $@@ $@@.tmp
2080 sed 's,@@datadir\@@,$(pkgdatadir),g' $< >$@@.tmp
2081 chmod +x $@@.tmp
2082 mv $@@.tmp $@@
2083 @end example
2084
2085 Three things are noteworthy:
2086
2087 @table @samp
2088 @item @@datadir\@@
2089 The backslash prevents @command{configure} from replacing
2090 @samp{@@datadir@@} in the sed expression itself.
2091
2092 @item $(pkgdatadir)
2093 Don't use @samp{@@pkgdatadir@@}! Use the matching makefile variable
2094 instead.
2095
2096 @item ,
2097 Don't use @samp{/} in the sed expression(s) since most probably the
2098 variables you use, such as @samp{$(pkgdatadir)}, will contain
2099 some.
2100 @end table
2101
2102
2103 @node Build Directories, Automatic Remaking, Installation Directory Variables, Makefile Substitutions
2104 @subsection Build Directories
2105
2106 You can support compiling a software package for several architectures
2107 simultaneously from the same copy of the source code. The object files
2108 for each architecture are kept in their own directory.
2109
2110 To support doing this, @code{make} uses the @code{VPATH} variable to
2111 find the files that are in the source directory. @sc{gnu} @code{make}
2112 and most other recent @code{make} programs can do this. Older
2113 @code{make} programs do not support @code{VPATH}; when using them, the
2114 source code must be in the same directory as the object files.
2115
2116 To support @code{VPATH}, each @file{Makefile.in} should contain two
2117 lines that look like:
2118
2119 @example
2120 srcdir = @@srcdir@@
2121 VPATH = @@srcdir@@
2122 @end example
2123
2124 Do not set @code{VPATH} to the value of another variable, for example
2125 @samp{VPATH = $(srcdir)}, because some versions of @code{make} do not do
2126 variable substitutions on the value of @code{VPATH}.
2127
2128 @code{configure} substitutes in the correct value for @code{srcdir} when
2129 it produces @file{Makefile}.
2130
2131 Do not use the @code{make} variable @code{$<}, which expands to the
2132 file name of the file in the source directory (found with @code{VPATH}),
2133 except in implicit rules. (An implicit rule is one such as @samp{.c.o},
2134 which tells how to create a @file{.o} file from a @file{.c} file.) Some
2135 versions of @code{make} do not set @code{$<} in explicit rules; they
2136 expand it to an empty value.
2137
2138 Instead, @file{Makefile} command lines should always refer to source
2139 files by prefixing them with @samp{$(srcdir)/}. For example:
2140
2141 @example
2142 time.info: time.texinfo
2143 $(MAKEINFO) $(srcdir)/time.texinfo
2144 @end example
2145
2146 @node Automatic Remaking, , Build Directories, Makefile Substitutions
2147 @subsection Automatic Remaking
2148
2149 You can put rules like the following in the top-level @file{Makefile.in}
2150 for a package to automatically update the configuration information when
2151 you change the configuration files. This example includes all of the
2152 optional files, such as @file{aclocal.m4} and those related to
2153 configuration header files. Omit from the @file{Makefile.in} rules for
2154 any of these files that your package does not use.
2155
2156 The @samp{$(srcdir)/} prefix is included because of limitations in the
2157 @code{VPATH} mechanism.
2158
2159 The @file{stamp-} files are necessary because the timestamps of
2160 @file{config.h.in} and @file{config.h} will not be changed if remaking
2161 them does not change their contents. This feature avoids unnecessary
2162 recompilation. You should include the file @file{stamp-h.in} your
2163 package's distribution, so @command{make} will consider
2164 @file{config.h.in} up to date. Don't use @command{touch}
2165 (@pxref{Limitations of Usual Tools}), rather use @command{echo} (using
2166 @command{date} would cause needless differences, hence @sc{cvs}
2167 conflicts etc.).
2168
2169 @example
2170 @group
2171 $(srcdir)/configure: configure.ac aclocal.m4
2172 cd $(srcdir) && autoconf
2173
2174 # autoheader might not change config.h.in, so touch a stamp file.
2175 $(srcdir)/config.h.in: stamp-h.in
2176 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
2177 cd $(srcdir) && autoheader
2178 echo timestamp > $(srcdir)/stamp-h.in
2179
2180 config.h: stamp-h
2181 stamp-h: config.h.in config.status
2182 ./config.status
2183
2184 Makefile: Makefile.in config.status
2185 ./config.status
2186
2187 config.status: configure
2188 ./config.status --recheck
2189 @end group
2190 @end example
2191
2192 @noindent
2193 (Be careful if you copy these lines directly into your Makefile, as you
2194 will need to convert the indented lines to start with the tab character.)
2195
2196 In addition, you should use @samp{AC_CONFIG_FILES(stamp-h, echo
2197 timestamp > stamp-h)} so @file{config.status} will ensure that
2198 @file{config.h} is considered up to date. @xref{Output}, for more
2199 information about @code{AC_OUTPUT}.
2200
2201 @xref{config.status Invocation}, for more examples of handling
2202 configuration-related dependencies.
2203
2204 @node Configuration Headers, Configuration Commands, Makefile Substitutions, Setup
2205 @section Configuration Header Files
2206 @cindex Configuration Header
2207 @cindex @file{config.h}
2208
2209 When a package tests more than a few C preprocessor symbols, the command
2210 lines to pass @option{-D} options to the compiler can get quite long.
2211 This causes two problems. One is that the @code{make} output is hard to
2212 visually scan for errors. More seriously, the command lines can exceed
2213 the length limits of some operating systems. As an alternative to
2214 passing @option{-D} options to the compiler, @code{configure} scripts can
2215 create a C header file containing @samp{#define} directives. The
2216 @code{AC_CONFIG_HEADERS} macro selects this kind of output. It should
2217 be called right after @code{AC_INIT}.
2218
2219 The package should @samp{#include} the configuration header file before
2220 any other header files, to prevent inconsistencies in declarations (for
2221 example, if it redefines @code{const}). Use @samp{#include <config.h>}
2222 instead of @samp{#include "config.h"}, and pass the C compiler a
2223 @option{-I.} option (or @option{-I..}; whichever directory contains
2224 @file{config.h}). That way, even if the source directory is configured
2225 itself (perhaps to make a distribution), other build directories can
2226 also be configured without finding the @file{config.h} from the source
2227 directory.
2228
2229 @defmac AC_CONFIG_HEADERS (@var{header} @dots{}, @ovar{cmds}, @ovar{init-cmds})
2230 @maindex CONFIG_HEADERS
2231 @cvindex HAVE_CONFIG_H
2232 This macro is one of the instantiating macros, see @ref{Configuration
2233 Actions}. Make @code{AC_OUTPUT} create the file(s) in the
2234 whitespace-separated list @var{header} containing C preprocessor
2235 @code{#define} statements, and replace @samp{@@DEFS@@} in generated
2236 files with @option{-DHAVE_CONFIG_H} instead of the value of @code{DEFS}.
2237 The usual name for @var{header} is @file{config.h}.
2238
2239 If @var{header} already exists and its contents are identical to what
2240 @code{AC_OUTPUT} would put in it, it is left alone. Doing this allows
2241 some changes in configuration without needlessly causing object files
2242 that depend on the header file to be recompiled.
2243
2244 Usually the input file is named @file{@var{header}.in}; however, you can
2245 override the input file name by appending to @var{header}, a
2246 colon-separated list of input files. Examples:
2247
2248 @example
2249 AC_CONFIG_HEADERS(config.h:config.hin)
2250 AC_CONFIG_HEADERS(defines.h:defs.pre:defines.h.in:defs.post)
2251 @end example
2252
2253 @noindent
2254 Doing this allows you to keep your file names acceptable to MS-DOS, or
2255 to prepend and/or append boilerplate to the file.
2256 @end defmac
2257
2258 @xref{Configuration Actions}, for more details on @var{header}.
2259
2260 @menu
2261 * Header Templates:: Input for the configuration headers
2262 * autoheader Invocation:: How to create configuration templates
2263 * Autoheader Macros:: How to specify CPP templates
2264 @end menu
2265
2266 @node Header Templates, autoheader Invocation, Configuration Headers, Configuration Headers
2267 @subsection Configuration Header Templates
2268 @cindex Configuration Header Template
2269 @cindex @file{config.h.in}
2270
2271 Your distribution should contain a template file that looks as you want
2272 the final header file to look, including comments, with @code{#undef}
2273 statements which are used as hooks. For example, suppose your
2274 @file{configure.ac} makes these calls:
2275
2276 @example
2277 AC_CONFIG_HEADERS(conf.h)
2278 AC_CHECK_HEADERS(unistd.h)
2279 @end example
2280
2281 @noindent
2282 Then you could have code like the following in @file{conf.h.in}. On
2283 systems that have @file{unistd.h}, @code{configure} will @samp{#define}
2284 @samp{HAVE_UNISTD_H} to 1. On other systems, the whole line will be
2285 commented out (in case the system predefines that symbol).
2286
2287 @example
2288 @group
2289 /* Define as 1 if you have unistd.h. */
2290 #undef HAVE_UNISTD_H
2291 @end group
2292 @end example
2293
2294 You can then decode the configuration header using the preprocessor
2295 directives:
2296
2297 @example
2298 @group
2299 #include <conf.h>
2300
2301 #if HAVE_UNISTD_H
2302 # include <unistd.h>
2303 #else
2304 /* We are in trouble. */
2305 #endif
2306 @end group
2307 @end example
2308
2309 The use of old form templates, with @samp{#define} instead of
2310 @samp{#undef} is strongly discouraged.
2311
2312 Since it is a tedious task to keep a template header up to date, you may
2313 use @code{autoheader} to generate it, see @ref{autoheader Invocation}.
2314
2315
2316 @node autoheader Invocation, Autoheader Macros, Header Templates, Configuration Headers
2317 @subsection Using @code{autoheader} to Create @file{config.h.in}
2318 @cindex @code{autoheader}
2319
2320 The @command{autoheader} program can create a template file of C
2321 @samp{#define} statements for @code{configure} to use. If
2322 @file{configure.ac} invokes @code{AC_CONFIG_HEADERS(@var{file})},
2323 @command{autoheader} creates @file{@var{file}.in}; if multiple file
2324 arguments are given, the first one is used. Otherwise,
2325 @command{autoheader} creates @file{config.h.in}.
2326
2327 In order to do its job, @command{autoheader} needs you to document all
2328 of the symbols that you might use; i.e., there must be at least one
2329 @code{AC_DEFINE} or one @code{AC_DEFINE_UNQUOTED} using its third
2330 argument for each symbol (@pxref{Defining Symbols}). An additional
2331 constraint is that the first argument of @code{AC_DEFINE} must be a
2332 literal. Note that all symbols defined by Autoconf's built-in tests are
2333 already documented properly; you only need to document those that you
2334 define yourself.
2335
2336 You might wonder why @command{autoheader} is needed: after all, why
2337 would @command{configure} need to ``patch'' a @file{config.h.in} to
2338 produce a @file{config.h} instead of just creating @file{config.h} from
2339 scratch? Well, when everything rocks, the answer is just that we are
2340 wasting our time maintaining @command{autoheader}: generating
2341 @file{config.h} directly is all that is needed. When things go wrong,
2342 however, you'll be thankful for the existence of @command{autoheader}.
2343
2344 The fact that the symbols are documented is important in order to
2345 @emph{check} that @file{config.h} makes sense. The fact that there is a
2346 well defined list of symbols that should be @code{#define}'d (or not) is
2347 also important for people who are porting packages to environments where
2348 @command{configure} cannot be run: they just have to @emph{fill in the
2349 blanks}.
2350
2351 But let's come back to the point: @command{autoheader}'s invocation@dots{}
2352
2353 If you give @command{autoheader} an argument, it uses that file instead
2354 of @file{configure.ac} and writes the header file to the standard output
2355 instead of to @file{config.h.in}. If you give @command{autoheader} an
2356 argument of @option{-}, it reads the standard input instead of
2357 @file{configure.ac} and writes the header file to the standard output.
2358
2359 @code{autoheader} accepts the following options:
2360
2361 @table @option
2362 @item --help
2363 @itemx -h
2364 Print a summary of the command line options and exit.
2365
2366 @item --version
2367 @itemx -V
2368 Print the version number of Autoconf and exit.
2369
2370 @item --debug
2371 @itemx -d
2372 Don't remove the temporary files.
2373
2374 @item --verbose
2375 @itemx -v
2376 Report processing steps.
2377
2378 @item --autoconf-dir=@var{dir}
2379 @itemx -A @var{dir}
2380 @evindex AC_MACRODIR
2381 Override the location where the installed Autoconf data files are looked
2382 for. You can also set the @code{AC_MACRODIR} environment variable to a
2383 directory; this option overrides the environment variable.
2384
2385 This option is rarely needed and dangerous; it is only used when one
2386 plays with different versions of Autoconf simultaneously.
2387
2388 @item --localdir=@var{dir}
2389 @itemx -l @var{dir}
2390 Look for the package files @file{aclocal.m4} and @file{acconfig.h} (but
2391 not @file{@var{file}.top} and @file{@var{file}.bot}) in directory
2392 @var{dir} instead of in the current directory.
2393
2394 @item --warnings=@var{category}
2395 @itemx -W @var{category}
2396 @evindex WARNINGS
2397 Report the warnings related to @var{category} (which can actually be a
2398 comma separated list). Current categories include:
2399
2400 @table @samp
2401 @item obsolete
2402 report the uses of obsolete constructs
2403
2404 @item all
2405 report all the warnings
2406
2407 @item none
2408 report none
2409
2410 @item error
2411 treats warnings as errors
2412
2413 @item no-@var{category}
2414 disable warnings falling into @var{category}
2415 @end table
2416
2417 @end table
2418
2419
2420
2421 @node Autoheader Macros, , autoheader Invocation, Configuration Headers
2422 @subsection Autoheader Macros
2423
2424 @code{autoheader} scans @file{configure.ac} and figures out which C
2425 preprocessor symbols it might define. It knows how to generate
2426 templates for symbols defined by @code{AC_CHECK_HEADERS},
2427 @code{AC_CHECK_FUNCS} etc., but if you @code{AC_DEFINE} any additional
2428 symbol, you must define a template for it. If there are missing
2429 templates, @code{autoheader} fails with an error message.
2430
2431 The simplest way to create a template for a @var{symbol} is to supply
2432 the @var{description} argument to an @samp{AC_DEFINE(@var{symbol})}; see
2433 @ref{Defining Symbols}. You may also use one of the following macros.
2434
2435 @defmac AH_VERBATIM (@var{key}, @var{template})
2436 @maindex AH_VERBATIM
2437 @maindex VERBATIM
2438 Tell @code{autoheader} to include the @var{template} as-is in the header
2439 template file. This @var{template} is associated with the @var{key},
2440 which is used to sort all the different templates and guarantee their
2441 uniqueness. It should be the symbol that can be @code{AC_DEFINE}'d.
2442
2443 For example:
2444
2445 @example
2446 AH_VERBATIM([_GNU_SOURCE],
2447 [/* Enable GNU extensions on systems that have them. */
2448 #ifndef _GNU_SOURCE
2449 # define _GNU_SOURCE
2450 #endif])
2451 @end example
2452 @end defmac
2453
2454
2455 @defmac AH_TEMPLATE (@var{key}, @var{description})
2456 @maindex AH_TEMPLATE
2457 @maindex TEMPLATE
2458 Tell @code{autoheader} to generate a template for @var{key}. This macro
2459 generates standard templates just like @code{AC_DEFINE} when a
2460 @var{description} is given.
2461
2462 For example:
2463
2464 @example
2465 AH_TEMPLATE([CRAY_STACKSEG_END],
2466 [Define to one of _getb67, GETB67, getb67
2467 for Cray-2 and Cray-YMP systems. This
2468 function is required for alloca.c support
2469 on those systems.])
2470 @end example
2471
2472 @noindent
2473 will generate the following template, with the description properly
2474 justified.
2475
2476 @example
2477 /* Define to one of _getb67, GETB67, getb67 for Cray-2 and
2478 Cray-YMP systems. This function is required for alloca.c
2479 support on those systems. */
2480 #undef CRAY_STACKSEG_END
2481 @end example
2482 @end defmac
2483
2484
2485 @defmac AH_TOP (@var{text})
2486 @maindex AH_TOP
2487 @maindex TOP
2488 Include @var{text} at the top of the header template file.
2489 @end defmac
2490
2491
2492 @defmac AH_BOTTOM (@var{text})
2493 @maindex AH_BOTTOM
2494 @maindex BOTTOM
2495 Include @var{text} at the bottom of the header template file.
2496 @end defmac
2497
2498
2499 @node Configuration Commands, Configuration Links, Configuration Headers, Setup
2500 @section Running Arbitrary Configuration Commands
2501
2502 You execute arbitrary commands either before, during and after
2503 @file{config.status} is run. The three following macros accumulate the
2504 commands to run when they are called multiple times.
2505 @code{AC_CONFIG_COMMANDS} replaces the obsolete macro
2506 @code{AC_OUTPUT_COMMANDS}, see @ref{Obsolete Macros}, for details.
2507
2508 @defmac AC_CONFIG_COMMANDS (@var{tag}@dots{}, @ovar{cmds}, @ovar{init-cmds})
2509 @maindex CONFIG_COMMANDS
2510 Specify additional shell commands to run at the end of
2511 @file{config.status}, and shell commands to initialize any variables
2512 from @code{configure}. Associate the commands to the @var{tag}. Since
2513 typically the @var{cmds} create a file, @var{tag} should naturally be
2514 the name of that file. This macro is one of the instantiating macros,
2515 see @ref{Configuration Actions}.
2516
2517 Here is an unrealistic example:
2518 @example
2519 fubar=42
2520 AC_CONFIG_COMMANDS(fubar,
2521 [echo this is extra $fubar, and so on.],
2522 [fubar=$fubar])
2523 @end example
2524
2525 Here is a better one:
2526 @example
2527 AC_CONFIG_COMMANDS(time-stamp, [date >time-stamp])
2528 @end example
2529 @end defmac
2530
2531 @defmac AC_CONFIG_COMMANDS_PRE (@var{cmds})
2532 @maindex OUTPUT_COMMANDS_PRE
2533 Execute the @var{cmds} right before creating @file{config.status}. A
2534 typical use is computing values derived from variables built during the
2535 execution of @code{configure}:
2536
2537 @example
2538 AC_CONFIG_COMMANDS_PRE(
2539 [LTLIBOBJS=`echo $LIBOBJS | sed 's/\.o/\.lo/g'`
2540 AC_SUBST(LTLIBOBJS)])
2541 @end example
2542 @end defmac
2543
2544 @defmac AC_CONFIG_COMMANDS_POST (@var{cmds})
2545 @maindex OUTPUT_COMMANDS_POST
2546 Execute the @var{cmds} right after creating @file{config.status}.
2547 @end defmac
2548
2549
2550
2551
2552 @node Configuration Links, Subdirectories, Configuration Commands, Setup
2553 @section Creating Configuration Links
2554
2555 You may find it convenient to create links whose destinations depend upon
2556 results of tests. One can use @code{AC_CONFIG_COMMANDS} but the
2557 creation of relative symbolic links can be delicate when the package is
2558 built in another directory than its sources.
2559
2560 @defmac AC_CONFIG_LINKS (@var{dest}:@var{source}@dots{}, @ovar{cmds}, @ovar{init-cmds})
2561 @maindex CONFIG_LINKS
2562 @cindex Links
2563 Make @code{AC_OUTPUT} link each of the existing files @var{source} to
2564 the corresponding link name @var{dest}. Makes a symbolic link if
2565 possible, otherwise a hard link. The @var{dest} and @var{source} names
2566 should be relative to the top level source or build directory. This
2567 macro is one of the instantiating macros, see @ref{Configuration
2568 Actions}.
2569
2570 For example, this call:
2571
2572 @example
2573 AC_CONFIG_LINKS(host.h:config/$machine.h
2574 object.h:config/$obj_format.h)
2575 @end example
2576
2577 @noindent
2578 creates in the current directory @file{host.h} as a link to
2579 @file{@var{srcdir}/config/$machine.h}, and @file{object.h} as a
2580 link to @file{@var{srcdir}/config/$obj_format.h}.
2581
2582 The tempting value @samp{.} for @var{dest} is invalid: it makes it
2583 impossible for @samp{config.status} to guess the links to establish.
2584
2585 One can then run:
2586 @example
2587 ./config.status host.h object.h
2588 @end example
2589 @noindent
2590 to create the links.
2591 @end defmac
2592
2593
2594
2595 @node Subdirectories, Default Prefix, Configuration Links, Setup
2596 @section Configuring Other Packages in Subdirectories
2597
2598 In most situations, calling @code{AC_OUTPUT} is sufficient to produce
2599 @file{Makefile}s in subdirectories. However, @code{configure} scripts
2600 that control more than one independent package can use
2601 @code{AC_CONFIG_SUBDIRS} to run @code{configure} scripts for other
2602 packages in subdirectories.
2603
2604 @defmac AC_CONFIG_SUBDIRS (@var{dir} @dots{})
2605 @maindex CONFIG_SUBDIRS
2606 @ovindex subdirs
2607 Make @code{AC_OUTPUT} run @code{configure} in each subdirectory
2608 @var{dir} in the given whitespace-separated list. Each @var{dir} should
2609 be a literal, i.e., please do not use:
2610
2611 @example
2612 if test "$package_foo_enabled" = yes; then
2613 $my_subdirs="$my_subdirs foo"
2614 fi
2615 AC_CONFIG_SUBDIRS($my_subdirs)
2616 @end example
2617
2618 @noindent
2619 because this prevents @samp{./configure --help=recursive} from
2620 displaying the options of the package @code{foo}. Rather, you should
2621 write:
2622
2623 @example
2624 if test "$package_foo_enabled" = yes then;
2625 AC_CONFIG_SUBDIRS(foo)
2626 fi
2627 @end example
2628
2629 If a given @var{dir} is not found, no error is reported, so a
2630 @code{configure} script can configure whichever parts of a large source
2631 tree are present. If a given @var{dir} contains @code{configure.gnu},
2632 it is run instead of @code{configure}. This is for packages that might
2633 use a non-autoconf script @code{Configure}, which can't be called
2634 through a wrapper @code{configure} since it would be the same file on
2635 case-insensitive filesystems. Likewise, if a @var{dir} contains
2636 @file{configure.ac} but no @code{configure}, the Cygnus @code{configure}
2637 script found by @code{AC_CONFIG_AUX_DIR} is used.
2638
2639 The subdirectory @code{configure} scripts are given the same command
2640 line options that were given to this @code{configure} script, with minor
2641 changes if needed (e.g., to adjust a relative path for the cache file or
2642 source directory). This macro also sets the output variable
2643 @code{subdirs} to the list of directories @samp{@var{dir} @dots{}}.
2644 @file{Makefile} rules can use this variable to determine which
2645 subdirectories to recurse into. This macro may be called multiple
2646 times.
2647 @end defmac
2648
2649 @node Default Prefix, , Subdirectories, Setup
2650 @section Default Prefix
2651
2652 By default, @code{configure} sets the prefix for files it installs to
2653 @file{/usr/local}. The user of @code{configure} can select a different
2654 prefix using the @option{--prefix} and @option{--exec-prefix} options.
2655 There are two ways to change the default: when creating
2656 @code{configure}, and when running it.
2657
2658 Some software packages might want to install in a directory besides
2659 @file{/usr/local} by default. To accomplish that, use the
2660 @code{AC_PREFIX_DEFAULT} macro.
2661
2662 @defmac AC_PREFIX_DEFAULT (@var{prefix})
2663 @maindex PREFIX_DEFAULT
2664 Set the default installation prefix to @var{prefix} instead of
2665 @file{/usr/local}.
2666 @end defmac
2667
2668 It may be convenient for users to have @code{configure} guess the
2669 installation prefix from the location of a related program that they
2670 have already installed. If you wish to do that, you can call
2671 @code{AC_PREFIX_PROGRAM}.
2672
2673 @defmac AC_PREFIX_PROGRAM (@var{program})
2674 @maindex PREFIX_PROGRAM
2675 If the user did not specify an installation prefix (using the
2676 @option{--prefix} option), guess a value for it by looking for
2677 @var{program} in @code{PATH}, the way the shell does. If @var{program}
2678 is found, set the prefix to the parent of the directory containing
2679 @var{program}; otherwise leave the prefix specified in
2680 @file{Makefile.in} unchanged. For example, if @var{program} is
2681 @code{gcc} and the @code{PATH} contains @file{/usr/local/gnu/bin/gcc},
2682 set the prefix to @file{/usr/local/gnu}.
2683 @end defmac
2684
2685
2686
2687 @c ======================================================== Existing tests
2688
2689 @node Existing Tests, Writing Tests, Setup, Top
2690 @chapter Existing Tests
2691
2692 These macros test for particular system features that packages might
2693 need or want to use. If you need to test for a kind of feature that
2694 none of these macros check for, you can probably do it by calling
2695 primitive test macros with appropriate arguments (@pxref{Writing
2696 Tests}).
2697
2698 These tests print messages telling the user which feature they're
2699 checking for, and what they find. They cache their results for future
2700 @code{configure} runs (@pxref{Caching Results}).
2701
2702 Some of these macros set output variables. @xref{Makefile
2703 Substitutions}, for how to get their values. The phrase ``define
2704 @var{name}'' is used below as a shorthand to mean ``define C
2705 preprocessor symbol @var{name} to the value 1''. @xref{Defining
2706 Symbols}, for how to get those symbol definitions into your program.
2707
2708 @menu
2709 * Common Behavior:: Macros' standard schemes
2710 * Alternative Programs:: Selecting between alternative programs
2711 * Files:: Checking for the existence of files
2712 * Libraries:: Library archives that might be missing
2713 * Library Functions:: C library functions that might be missing
2714 * Header Files:: Header files that might be missing
2715 * Declarations:: Declarations that may be missing
2716 * Structures:: Structures or members that might be missing
2717 * Types:: Types that might be missing
2718 * Compilers and Preprocessors:: Checking for compiling programs
2719 * System Services:: Operating system services
2720 * UNIX Variants:: Special kludges for specific UNIX variants
2721 @end menu
2722
2723 @node Common Behavior, Alternative Programs, Existing Tests, Existing Tests
2724 @section Common Behavior
2725
2726 Much effort has been expended to make Autoconf easy to learn. The most
2727 obvious way to reach this goal is simply to enforce standard interfaces
2728 and behaviors, avoiding exceptions as much as possible. Because of
2729 history and inertia, unfortunately, there are still too many exceptions
2730 in Autoconf; nevertheless, this section describes some of the common
2731 rules.
2732
2733 @menu
2734 * Standard Symbols:: Symbols defined by the macros
2735 * Default Includes:: Includes used by the generic macros
2736 @end menu
2737
2738 @node Standard Symbols, Default Includes, Common Behavior, Common Behavior
2739 @subsection Standard Symbols
2740
2741 All the generic macros that @code{AC_DEFINE} a symbol as a result of
2742 their test transform their @var{argument}s to a standard alphabet.
2743 First, @var{argument} is converted to upper case and any asterisks
2744 (@samp{*}) are each converted to @samp{P}. Any remaining characters
2745 that are not alphanumeric are converted to underscores.
2746
2747 For instance,
2748
2749 @example
2750 AC_CHECK_TYPES(struct $Expensive*)
2751 @end example
2752
2753 @noindent
2754 will define the symbol @samp{HAVE_STRUCT__EXPENSIVEP} if the check succeeds.
2755
2756
2757 @node Default Includes, , Standard Symbols, Common Behavior
2758 @subsection Default Includes
2759 @cindex Includes, default
2760
2761 Several tests depend upon a set of header files. Since these headers
2762 are not universally available, tests actually have to provide a set of
2763 protected includes, such as:
2764
2765 @example
2766 @group
2767 #if TIME_WITH_SYS_TIME
2768 # include <sys/time.h>
2769 # include <time.h>
2770 #else
2771 # if HAVE_SYS_TIME_H
2772 # include <sys/time.h>
2773 # else
2774 # include <time.h>
2775 # endif
2776 #endif
2777 @end group
2778 @end example
2779
2780 @noindent
2781 Unless you know exactly what you are doing, you should avoid using
2782 unconditional includes, and check the existence of the headers you
2783 include beforehand (@pxref{Header Files}).
2784
2785 Most generic macros provide the following default set of includes:
2786
2787 @example
2788 @group
2789 #include <stdio.h>
2790 #if HAVE_SYS_TYPES_H
2791 # include <sys/types.h>
2792 #endif
2793 #if HAVE_SYS_STAT_H
2794 # include <sys/stat.h>
2795 #endif
2796 #if STDC_HEADERS
2797 # include <stdlib.h>
2798 # include <stddef.h>
2799 #else
2800 # if HAVE_STDLIB_H
2801 # include <stdlib.h>
2802 # endif
2803 #endif
2804 #if HAVE_STRING_H
2805 # if !STDC_HEADERS && HAVE_MEMORY_H
2806 # include <memory.h>
2807 # endif
2808 # include <string.h>
2809 #endif
2810 #if HAVE_STRINGS_H
2811 # include <strings.h>
2812 #endif
2813 #if HAVE_INTTYPES_H
2814 # include <inttypes.h>
2815 #else
2816 # if HAVE_STDINT_H
2817 # include <stdint.h>
2818 # endif
2819 #endif
2820 #if HAVE_UNISTD_H
2821 # include <unistd.h>
2822 #endif
2823 @end group
2824 @end example
2825
2826 If the default includes are used, then Autoconf will automatically check
2827 for the presence of these headers and their compatibility, i.e., you
2828 don't need to run @code{AC_HEADERS_STDC}, nor check for @file{stdlib.h}
2829 etc.
2830
2831 These headers are checked for in the same order as they are included.
2832 For instance, on some systems @file{string.h} and @file{strings.h} both
2833 exist, but conflict. Then @code{HAVE_STRING_H} will be defined, but
2834 @code{HAVE_STRINGS_H} won't.
2835
2836 @node Alternative Programs, Files, Common Behavior, Existing Tests
2837 @section Alternative Programs
2838 @cindex Programs, checking
2839
2840 These macros check for the presence or behavior of particular programs.
2841 They are used to choose between several alternative programs and to
2842 decide what to do once one has been chosen. If there is no macro
2843 specifically defined to check for a program you need, and you don't need
2844 to check for any special properties of it, then you can use one of the
2845 general program-check macros.
2846
2847 @menu
2848 * Particular Programs:: Special handling to find certain programs
2849 * Generic Programs:: How to find other programs
2850 @end menu
2851
2852 @node Particular Programs, Generic Programs, Alternative Programs, Alternative Programs
2853 @subsection Particular Program Checks
2854
2855 These macros check for particular programs---whether they exist, and
2856 in some cases whether they support certain features.
2857
2858 @defmac AC_PROG_AWK
2859 @maindex PROG_AWK
2860 @ovindex AWK
2861 Check for @code{mawk}, @code{gawk}, @code{nawk}, and @code{awk}, in that
2862 order, and set output variable @code{AWK} to the first one that is found.
2863 It tries @code{mawk} first because that is reported to be the
2864 fastest implementation.
2865 @end defmac
2866
2867
2868 @defmac AC_PROG_EGREP
2869 @ovindex EGREP
2870 Check for @code{grep -E}, @code{egrep} in that
2871 order, and set output variable @code{EGREP} to the first one that is found.
2872 @end defmac
2873
2874
2875 @defmac AC_PROG_FGREP
2876 @ovindex FGREP
2877 Check for @code{grep -F}, @code{fgrep} in that
2878 order, and set output variable @code{FGREP} to the first one that is found.
2879 @end defmac
2880
2881
2882 @defmac AC_PROG_GREP
2883 @ovindex GREP
2884 Check for @code{grep}, @code{ggrep} in that
2885 order, and set output variable @code{GREP} to the first one that is found.
2886 @end defmac
2887
2888
2889 @defmac AC_PROG_INSTALL
2890 @maindex PROG_INSTALL
2891 @ovindex INSTALL
2892 @ovindex INSTALL_PROGRAM
2893 @ovindex INSTALL_DATA
2894 @ovindex INSTALL_SCRIPT
2895 Set output variable @code{INSTALL} to the path of a @sc{bsd} compatible
2896 @code{install} program, if one is found in the current @code{PATH}.
2897 Otherwise, set @code{INSTALL} to @samp{@var{dir}/install-sh -c},
2898 checking the directories specified to @code{AC_CONFIG_AUX_DIR} (or its
2899 default directories) to determine @var{dir} (@pxref{Output}). Also set
2900 the variables @code{INSTALL_PROGRAM} and @code{INSTALL_SCRIPT} to
2901 @samp{$@{INSTALL@}} and @code{INSTALL_DATA} to @samp{$@{INSTALL@} -m 644}.
2902
2903 This macro screens out various instances of @code{install} known not to
2904 work. It prefers to find a C program rather than a shell script, for
2905 speed. Instead of @file{install-sh}, it can also use @file{install.sh},
2906 but that name is obsolete because some @code{make} programs have a rule
2907 that creates @file{install} from it if there is no @file{Makefile}.
2908
2909 Autoconf comes with a copy of @file{install-sh} that you can use. If
2910 you use @code{AC_PROG_INSTALL}, you must include either
2911 @file{install-sh} or @file{install.sh} in your distribution, or
2912 @code{configure} will produce an error message saying it can't find
2913 them---even if the system you're on has a good @code{install} program.
2914 This check is a safety measure to prevent you from accidentally leaving
2915 that file out, which would prevent your package from installing on
2916 systems that don't have a @sc{bsd}-compatible @code{install} program.
2917
2918 If you need to use your own installation program because it has features
2919 not found in standard @code{install} programs, there is no reason to use
2920 @code{AC_PROG_INSTALL}; just put the file name of your program into your
2921 @file{Makefile.in} files.
2922 @end defmac
2923
2924 @defmac AC_PROG_LEX
2925 @maindex PROG_LEX
2926 @ovindex LEX
2927 @ovindex LEXLIB
2928 @cvindex YYTEXT_POINTER
2929 @ovindex LEX_OUTPUT_ROOT
2930 If @code{flex} is found, set output variable @code{LEX} to @samp{flex}
2931 and @code{LEXLIB} to @option{-lfl}, if that library is in a standard
2932 place. Otherwise set @code{LEX} to @samp{lex} and @code{LEXLIB} to
2933 @option{-ll}.
2934
2935 Define @code{YYTEXT_POINTER} if @code{yytext} is a @samp{char *} instead
2936 of a @samp{char []}. Also set output variable @code{LEX_OUTPUT_ROOT} to
2937 the base of the file name that the lexer generates; usually
2938 @file{lex.yy}, but sometimes something else. These results vary
2939 according to whether @code{lex} or @code{flex} is being used.
2940
2941 You are encouraged to use Flex in your sources, since it is both more
2942 pleasant to use than plain Lex and the C source it produces is portable.
2943 In order to ensure portability, however, you must either provide a
2944 function @code{yywrap} or, if you don't use it (e.g., your scanner has
2945 no @samp{#include}-like feature), simply include a @samp{%noyywrap}
2946 statement in the scanner's source. Once this done, the scanner is
2947 portable (unless @emph{you} felt free to use nonportable constructs) and
2948 does not depend on any library. In this case, and in this case only, it
2949 is suggested that you use this Autoconf snippet:
2950
2951 @example
2952 AC_PROG_LEX
2953 if test "$LEX" != flex; then
2954 LEX="$SHELL $missing_dir/missing flex"
2955 AC_SUBST(LEX_OUTPUT_ROOT, lex.yy)
2956 AC_SUBST(LEXLIB, '')
2957 fi
2958 @end example
2959
2960 The shell script @command{missing} can be found in the Automake
2961 distribution.
2962
2963 To ensure backward compatibility, Automake's @code{AM_PROG_LEX} invokes
2964 (indirectly) this macro twice, which will cause an annoying but benign
2965 ``@code{AC_PROG_LEX} invoked multiple times'' warning. Future versions
2966 of Automake will fix this issue, meanwhile, just ignore this message.
2967 @end defmac
2968
2969 @defmac AC_PROG_LN_S
2970 @maindex PROG_LN_S
2971 @ovindex LN_S
2972 If @samp{ln -s} works on the current file system (the operating system
2973 and file system support symbolic links), set the output variable
2974 @code{LN_S} to @samp{ln -s}; otherwise, if @samp{ln} works, set
2975 @code{LN_S} to @samp{ln} and otherwise set it to @samp{cp -p}.
2976
2977 If you make a link a directory other than the current directory, its
2978 meaning depends on whether @samp{ln} or @samp{ln -s} is used. To safely
2979 create links using @samp{$(LN_S)}, either find out which form is used
2980 and adjust the arguments, or always invoke @code{ln} in the directory
2981 where the link is to be created.
2982
2983 In other words, it does not work to do:
2984 @example
2985 $(LN_S) foo /x/bar
2986 @end example
2987
2988 Instead, do:
2989
2990 @example
2991 (cd /x && $(LN_S) foo bar)
2992 @end example
2993 @end defmac
2994
2995 @defmac AC_PROG_RANLIB
2996 @maindex PROG_RANLIB
2997 @ovindex RANLIB
2998 Set output variable @code{RANLIB} to @samp{ranlib} if @code{ranlib}
2999 is found, and otherwise to @samp{:} (do nothing).
3000 @end defmac
3001
3002 @defmac AC_PROG_YACC
3003 @maindex PROG_YACC
3004 @ovindex YACC
3005 If @code{byacc} is found, set @code{YACC} to @samp{byacc}.
3006 Otherwise, if @code{bison} is found,
3007 set output variable @code{YACC} to @samp{bison -y}.
3008 Finally, if neither @code{byacc} or @code{bison} is found,
3009 set @code{YACC} to @samp{yacc}.
3010 @end defmac
3011
3012 @node Generic Programs, , Particular Programs, Alternative Programs
3013 @subsection Generic Program and File Checks
3014
3015 These macros are used to find programs not covered by the ``particular''
3016 test macros. If you need to check the behavior of a program as well as
3017 find out whether it is present, you have to write your own test for it
3018 (@pxref{Writing Tests}). By default, these macros use the environment
3019 variable @code{PATH}. If you need to check for a program that might not
3020 be in the user's @code{PATH}, you can pass a modified path to use
3021 instead, like this:
3022
3023 @example
3024 AC_PATH_PROG(INETD, inetd, /usr/libexec/inetd,
3025 $PATH:/usr/libexec:/usr/sbin:/usr/etc:etc)
3026 @end example
3027
3028 You are strongly encouraged to declare the @var{variable} passed to
3029 @code{AC_CHECK_PROG} etc. as precious, @xref{Setting Output Variables},
3030 @code{AC_ARG_VAR}, for more details.
3031
3032 @defmac AC_CHECK_PROG (@var{variable}, @var{prog-to-check-for}, @var{value-if-found}, @ovar{value-if-not-found}, @ovar{path}, @ovar{reject})
3033 @maindex CHECK_PROG
3034 Check whether program @var{prog-to-check-for} exists in @code{PATH}. If
3035 it is found, set @var{variable} to @var{value-if-found}, otherwise to
3036 @var{value-if-not-found}, if given. Always pass over @var{reject} (an
3037 absolute file name) even if it is the first found in the search path; in
3038 that case, set @var{variable} using the absolute file name of the
3039 @var{prog-to-check-for} found that is not @var{reject}. If
3040 @var{variable} was already set, do nothing. Calls @code{AC_SUBST} for
3041 @var{variable}.
3042 @end defmac
3043
3044 @defmac AC_CHECK_PROGS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3045 @maindex CHECK_PROGS
3046 Check for each program in the whitespace-separated list
3047 @var{progs-to-check-for} exists on the @code{PATH}. If it is found, set
3048 @var{variable} to the name of that program. Otherwise, continue
3049 checking the next program in the list. If none of the programs in the
3050 list are found, set @var{variable} to @var{value-if-not-found}; if
3051 @var{value-if-not-found} is not specified, the value of @var{variable}
3052 is not changed. Calls @code{AC_SUBST} for @var{variable}.
3053 @end defmac
3054
3055 @defmac AC_CHECK_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3056 @maindex CHECK_TOOL
3057 Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
3058 with a prefix of the host type as determined by
3059 @code{AC_CANONICAL_HOST}, followed by a dash (@pxref{Canonicalizing}).
3060 For example, if the user runs @samp{configure --host=i386-gnu}, then
3061 this call:
3062 @example
3063 AC_CHECK_TOOL(RANLIB, ranlib, :)
3064 @end example
3065 @noindent
3066 sets @code{RANLIB} to @file{i386-gnu-ranlib} if that program exists in
3067 @code{PATH}, or otherwise to @samp{ranlib} if that program exists in
3068 @code{PATH}, or to @samp{:} if neither program exists.
3069 @end defmac
3070
3071 @defmac AC_CHECK_TOOLS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3072 @maindex CHECK_TOOLS
3073 Like @code{AC_CHECK_TOOL}, each of the tools in the list @var{progs-to-check-for} are
3074 checked with a prefix of the host type as determined by @code{AC_CANONICAL_HOST},
3075 followed by a dash (@pxref{Canonicalizing}). If none of the tools can be found with a
3076 prefix, then the first one without a prefix is used. If a tool is found, set
3077 @var{variable} to the name of that program. If none of the tools in the
3078 list are found, set @var{variable} to @var{value-if-not-found}; if
3079 @var{value-if-not-found} is not specified, the value of @var{variable}
3080 is not changed. Calls @code{AC_SUBST} for @var{variable}.
3081 @end defmac
3082
3083 @defmac AC_PATH_PROG (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3084 @maindex PATH_PROG
3085 Like @code{AC_CHECK_PROG}, but set @var{variable} to the entire
3086 path of @var{prog-to-check-for} if found.
3087 @end defmac
3088
3089 @defmac AC_PATH_PROGS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3090 @maindex PATH_PROGS
3091 Like @code{AC_CHECK_PROGS}, but if any of @var{progs-to-check-for}
3092 are found, set @var{variable} to the entire path of the program
3093 found.
3094 @end defmac
3095
3096 @defmac AC_PATH_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3097 @maindex PATH_TOOL
3098 Like @code{AC_CHECK_TOOL}, but set @var{variable} to the entire
3099 path of the program if it is found.
3100 @end defmac
3101
3102
3103 @node Files, Libraries, Alternative Programs, Existing Tests
3104 @section Files
3105 @cindex File, checking
3106
3107 You might also need to check for the existence of files. Before using
3108 these macros, ask yourself whether a run time test might not be a better
3109 solution. Be aware that, like most Autoconf macros, they test a feature
3110 of the host machine, and therefore, they die when cross-compiling.
3111
3112 @defmac AC_CHECK_FILE (@var{file}, @ovar{action-if-found}, @ovar{action-if-not-found})
3113 @maindex CHECK_FILE
3114 Check whether file @var{file} exists on the native system. If it is
3115 found, execute @var{action-if-found}, otherwise do
3116 @var{action-if-not-found}, if given.
3117 @end defmac
3118
3119 @defmac AC_CHECK_FILES (@var{files}, @ovar{action-if-found}, @ovar{action-if-not-found})
3120 @maindex CHECK_FILES
3121 Executes @code{AC_CHECK_FILE} once for each file listed in @var{files}.
3122 Additionally, defines @samp{HAVE_@var{file}} (@pxref{Standard Symbols})
3123 for each file found.
3124 @end defmac
3125
3126
3127 @node Libraries, Library Functions, Files, Existing Tests
3128 @section Library Files
3129 @cindex Library, checking
3130
3131 The following macros check for the presence of certain C, C++ or Fortran
3132 77 library archive files.
3133
3134 @defmac AC_CHECK_LIB (@var{library}, @var{function}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
3135 @maindex CHECK_LIB
3136 Depending on the current language(@pxref{Language Choice}), try to
3137 ensure that the C, C++, or Fortran 77 function @var{function} is
3138 available by checking whether a test program can be linked with the
3139 library @var{library} to get the function. @var{library} is the base
3140 name of the library; e.g., to check for @option{-lmp}, use @samp{mp} as
3141 the @var{library} argument.
3142
3143 @var{action-if-found} is a list of shell commands to run if the link
3144 with the library succeeds; @var{action-if-not-found} is a list of shell
3145 commands to run if the link fails. If @var{action-if-found} is not
3146 specified, the default action will prepend @option{-l@var{library}} to
3147 @code{LIBS} and define @samp{HAVE_LIB@var{library}} (in all
3148 capitals). This macro is intended to support building of @code{LIBS} in
3149 a right-to-left (least-dependent to most-dependent) fashion such that
3150 library dependencies are satisfied as a natural side-effect of
3151 consecutive tests. Some linkers are very sensitive to library ordering
3152 so the order in which @code{LIBS} is generated is important to reliable
3153 detection of libraries.
3154
3155 If linking with @var{library} results in unresolved symbols that would
3156 be resolved by linking with additional libraries, give those libraries
3157 as the @var{other-libraries} argument, separated by spaces:
3158 e.g. @option{-lXt -lX11}. Otherwise, this macro will fail to detect
3159 that @var{library} is present, because linking the test program will
3160 always fail with unresolved symbols. The @var{other-libraries} argument
3161 should be limited to cases where it is desirable to test for one library
3162 in the presence of another that is not already in @code{LIBS}.
3163 @end defmac
3164
3165
3166 @defmac AC_SEARCH_LIBS (@var{function}, @var{search-libs}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
3167 @maindex SEARCH_LIBS
3168 Search for a library defining @var{function} if it's not already
3169 available. This equates to calling @code{AC_TRY_LINK_FUNC} first
3170 with no libraries, then for each library listed in @var{search-libs}.
3171
3172 Add @option{-l@var{library}} to @code{LIBS} for the first library found
3173 to contain @var{function}, and run @var{action-if-found}. If the
3174 function is not found, run @var{action-if-not-found}.
3175
3176 If linking with @var{library} results in unresolved symbols that would
3177 be resolved by linking with additional libraries, give those libraries
3178 as the @var{other-libraries} argument, separated by spaces:
3179 e.g. @option{-lXt -lX11}. Otherwise, this macro will fail to detect
3180 that @var{function} is present, because linking the test program will
3181 always fail with unresolved symbols.
3182 @end defmac
3183
3184
3185
3186 @node Library Functions, Header Files, Libraries, Existing Tests
3187 @section Library Functions
3188
3189 The following macros check for particular C library functions.
3190 If there is no macro specifically defined to check for a function you need,
3191 and you don't need to check for any special properties of
3192 it, then you can use one of the general function-check macros.
3193
3194 @menu
3195 * Function Portability:: Pitfalls with usual functions
3196 * Particular Functions:: Special handling to find certain functions
3197 * Generic Functions:: How to find other functions
3198 @end menu
3199
3200 @node Function Portability, Particular Functions, Library Functions, Library Functions
3201 @subsection Portability of Classical Functions
3202
3203 Most usual functions can either be missing, or be buggy, or be limited
3204 on some architectures. This section tries to make an inventory of these
3205 portability issues. By definition, this list will always require
3206 additions, please help us keeping it as complete as possible
3207
3208 @table @code
3209
3210 @item unlink
3211 The @sc{posix} spec says that @code{unlink} causes the given files to be
3212 removed only after there are no more open file handles for it. Not all
3213 OS's support this behaviour though. So even on systems that provide
3214 @code{unlink}, you cannot portably assume it is OK to call it on files
3215 that are open. For example, on Windows 9x and ME, such a call would fail;
3216 on DOS it could even lead to file system corruption, as the file might end
3217 up being written to after the OS has removed it.
3218
3219 @end table
3220
3221
3222 @node Particular Functions, Generic Functions, Function Portability, Library Functions
3223 @subsection Particular Function Checks
3224 @cindex Function, checking
3225
3226 These macros check for particular C functions---whether they exist, and
3227 in some cases how they respond when given certain arguments.
3228
3229 @defmac AC_FUNC_ALLOCA
3230 @maindex FUNC_ALLOCA
3231 @cvindex C_ALLOCA
3232 @cvindex HAVE_ALLOCA_H
3233 @ovindex ALLOCA
3234 Check how to get @code{alloca}. Tries to get a builtin version by
3235 checking for @file{alloca.h} or the predefined C preprocessor macros
3236 @code{__GNUC__} and @code{_AIX}. If this macro finds @file{alloca.h},
3237 it defines @code{HAVE_ALLOCA_H}.
3238
3239 If those attempts fail, it looks for the function in the standard C
3240 library. If any of those methods succeed, it defines
3241 @code{HAVE_ALLOCA}. Otherwise, it sets the output variable
3242 @code{ALLOCA} to @samp{alloca.o} and defines @code{C_ALLOCA} (so
3243 programs can periodically call @samp{alloca(0)} to garbage collect).
3244 This variable is separate from @code{LIBOBJS} so multiple programs can
3245 share the value of @code{ALLOCA} without needing to create an actual
3246 library, in case only some of them use the code in @code{LIBOBJS}.
3247
3248 This macro does not try to get @code{alloca} from the System V R3
3249 @file{libPW} or the System V R4 @file{libucb} because those libraries
3250 contain some incompatible functions that cause trouble. Some versions
3251 do not even contain @code{alloca} or contain a buggy version. If you
3252 still want to use their @code{alloca}, use @code{ar} to extract
3253 @file{alloca.o} from them instead of compiling @file{alloca.c}.
3254
3255 Source files that use @code{alloca} should start with a piece of code
3256 like the following, to declare it properly. In some versions of AIX,
3257 the declaration of @code{alloca} must precede everything else except for
3258 comments and preprocessor directives. The @code{#pragma} directive is
3259 indented so that pre-@sc{ansi} C compilers will ignore it, rather than
3260 choke on it.
3261
3262 @example
3263 @group
3264 /* AIX requires this to be the first thing in the file. */
3265 #ifndef __GNUC__
3266 # if HAVE_ALLOCA_H
3267 # include <alloca.h>
3268 # else
3269 # ifdef _AIX
3270 #pragma alloca
3271 # else
3272 # ifndef alloca /* predefined by HP cc +Olibcalls */
3273 char *alloca ();
3274 # endif
3275 # endif
3276 # endif
3277 #endif
3278 @end group
3279 @end example
3280 @end defmac
3281
3282 @defmac AC_FUNC_CHOWN
3283 @maindex FUNC_CHOWN
3284 If the @code{chown} function is available and works (in particular, it
3285 should accept @option{-1} for @code{uid} and @code{gid}), define
3286 @code{HAVE_CHOWN}.
3287 @end defmac
3288
3289
3290 @defmac AC_FUNC_CLOSEDIR_VOID
3291 @maindex FUNC_CLOSEDIR_VOID
3292 @cvindex CLOSEDIR_VOID
3293 If the @code{closedir} function does not return a meaningful value,
3294 define @code{CLOSEDIR_VOID}. Otherwise, callers ought to check its
3295 return value for an error indicator.
3296 @end defmac
3297
3298 @defmac AC_FUNC_ERROR_AT_LINE
3299 @maindex FUNC_ERROR_AT_LINE
3300 If the @code{error_at_line} function is not found, require an
3301 @code{AC_LIBOBJ} replacement of @samp{error}.
3302 @end defmac
3303
3304 @defmac AC_FUNC_FNMATCH
3305 @maindex FUNC_FNMATCH
3306 If the @code{fnmatch} function is available and works (unlike the one on
3307 Solaris 2.4), define @code{HAVE_FNMATCH}.
3308 @end defmac
3309
3310 @defmac AC_FUNC_FORK
3311 @maindex FUNC_FORK
3312 @cvindex HAVE_VFORK_H
3313 @cvindex HAVE_WORKING_FORK
3314 @cvindex HAVE_WORKING_VFORK
3315 @cvindex vfork
3316 This macro checks for the @code{fork} and @code{vfork} functions. If a
3317 working @code{fork} is found, define @code{HAVE_WORKING_FORK}. This macro
3318 checks whether @code{fork} is just a stub by trying to run it.
3319
3320 If @file{vfork.h} is found, define @code{HAVE_VFORK_H}. If a working
3321 @code{vfork} is found, define @code{HAVE_WORKING_VFORK}. Otherwise,
3322 define @code{vfork} to be @code{fork} for backward compatibility with
3323 previous versions of @command{autoconf}. This macro checks for several known
3324 errors in implementations of @code{vfork} and considers the system to not
3325 have a working @code{vfork} if it detects any of them. It is not considered
3326 to be an implementation error if a child's invocation of @code{signal}
3327 modifies the parent's signal handler, since child processes rarely change
3328 their signal handlers.
3329
3330 Since this macro defines @code{vfork} only for backward compatibility with
3331 previous versions of @command{autoconf} you're encouraged to define it
3332 yourself in new code:
3333 @example
3334 @group
3335 #if !HAVE_WORKING_VFORK
3336 # define vfork fork
3337 #endif
3338 @end group
3339 @end example
3340 @end defmac
3341
3342 @defmac AC_FUNC_FSEEKO
3343 @maindex FUNC_FSEEKO
3344 @cvindex _LARGEFILE_SOURCE
3345 If the @code{fseeko} function is available, define @code{HAVE_FSEEKO}.
3346 Define @code{_LARGEFILE_SOURCE} if necessary.
3347 @end defmac
3348
3349 @defmac AC_FUNC_GETGROUPS
3350 @maindex FUNC_GETGROUPS
3351 @ovindex GETGROUPS_LIBS
3352 If the @code{getgroups} function is available and works (unlike on
3353 Ultrix 4.3, where @samp{getgroups (0, 0)} always fails), define
3354 @code{HAVE_GETGROUPS}. Set @code{GETGROUPS_LIBS} to any libraries
3355 needed to get that function. This macro runs @code{AC_TYPE_GETGROUPS}.
3356 @end defmac
3357
3358 @defmac AC_FUNC_GETLOADAVG
3359 @maindex FUNC_GETLOADAVG
3360 @cvindex SVR4
3361 @cvindex DGUX
3362 @cvindex UMAX
3363 @cvindex UMAX4_3
3364 @cvindex NLIST_STRUCT
3365 @cvindex NLIST_NAME_UNION
3366 @cvindex GETLODAVG_PRIVILEGED
3367 @cvindex NEED_SETGID
3368 @cvindex C_GETLOADAVG
3369 @ovindex LIBOBJS
3370 @ovindex NEED_SETGID
3371 @ovindex KMEM_GROUP
3372 @ovindex GETLOADAVG_LIBS
3373 Check how to get the system load averages. If the system has the
3374 @code{getloadavg} function, define @code{HAVE_GETLOADAVG}, and set
3375 @code{GETLOADAVG_LIBS} to any libraries needed to get that function.
3376 Also add @code{GETLOADAVG_LIBS} to @code{LIBS}.
3377
3378 Otherwise, require an @code{AC_LIBOBJ} replacement (@file{getloadavg.c})
3379 of @samp{getloadavg}, and possibly define several other C preprocessor
3380 macros and output variables:
3381
3382 @enumerate
3383 @item
3384 Define @code{C_GETLOADAVG}.
3385
3386 @item
3387 Define @code{SVR4}, @code{DGUX}, @code{UMAX}, or @code{UMAX4_3} if on
3388 those systems.
3389
3390 @item
3391 If @file{nlist.h} is found, define @code{NLIST_STRUCT}.
3392
3393 @item
3394 If @samp{struct nlist} has an @samp{n_un.n_name} member, define
3395 @code{HAVE_STRUCT_NLIST_N_UN_N_NAME}. The obsolete symbol
3396 @code{NLIST_NAME_UNION} is still defined, but do not depend upon it.
3397
3398 @item
3399 Programs may need to be installed setgid (or setuid) for
3400 @code{getloadavg} to work. In this case, define
3401 @code{GETLOADAVG_PRIVILEGED}, set the output variable @code{NEED_SETGID}
3402 to @samp{true} (and otherwise to @samp{false}), and set
3403 @code{KMEM_GROUP} to the name of the group that should own the installed
3404 program.
3405 @end enumerate
3406 @end defmac
3407
3408 @defmac AC_FUNC_GETMNTENT
3409 @maindex FUNC_GETMNTENT
3410 @cvindex HAVE_GETMNTENT
3411 Check for @code{getmntent} in the @file{sun}, @file{seq}, and @file{gen}
3412 libraries, for Irix 4, PTX, and Unixware, respectively. Then, if
3413 @code{getmntent} is available, define @code{HAVE_GETMNTENT}.
3414 @end defmac
3415
3416 @defmac AC_FUNC_GETPGRP
3417 @maindex FUNC_GETPGRP
3418 @cvindex GETPGRP_VOID
3419 If @code{getpgrp} takes no argument (the @sc{posix.1} version), define
3420 @code{GETPGRP_VOID}. Otherwise, it is the @sc{bsd} version, which takes
3421 a process ID as an argument. This macro does not check whether
3422 @code{getpgrp} exists at all; if you need to work in that situation,
3423 first call @code{AC_CHECK_FUNC} for @code{getpgrp}.
3424 @end defmac
3425
3426 @defmac AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
3427 @maindex FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
3428 @cvindex LSTAT_FOLLOWS_SLASHED_SYMLINK
3429 If @file{link} is a symbolic link, then @code{lstat} should treat
3430 @file{link/} the same as @file{link/.}. However, many older
3431 @code{lstat} implementations incorrectly ignore trailing slashes.
3432
3433 It is safe to assume that if @code{lstat} incorrectly ignores
3434 trailing slashes, then other symbolic-link-aware functions like
3435 @code{unlink} and @code{unlink} also incorrectly ignore trailing slashes.
3436
3437 If @code{lstat} behaves properly, define
3438 @code{LSTAT_FOLLOWS_SLASHED_SYMLINK}, otherwise require an
3439 @code{AC_LIBOBJ} replacement of @code{lstat}.
3440 @end defmac
3441
3442 @defmac AC_FUNC_MALLOC
3443 @maindex FUNC_MALLOC
3444 If the @code{malloc} works correctly (@samp{malloc (0)} returns a valid
3445 pointer), define @code{HAVE_MALLOC}.
3446 @end defmac
3447
3448 @defmac AC_FUNC_MEMCMP
3449 @maindex FUNC_MEMCMP
3450 @ovindex LIBOBJS
3451 If the @code{memcmp} function is not available, or does not work on
3452 8-bit data (like the one on SunOS 4.1.3), or fails when comparing 16
3453 bytes or more and with at least one buffer not starting on a 4-byte
3454 boundary (such as the one on NeXT x86 OpenStep), require an
3455 @code{AC_LIBOBJ} replacement for @samp{memcmp}.
3456 @end defmac
3457
3458 @defmac AC_FUNC_MKTIME
3459 @maindex FUNC_MKTIME
3460 @ovindex LIBOBJS
3461 If the @code{mktime} function is not available, or does not work
3462 correctly, require an @code{AC_LIBOBJ} replacement for @samp{mktime}.
3463 @end defmac
3464
3465 @defmac AC_FUNC_MMAP
3466 @maindex FUNC_MMAP
3467 @cvindex HAVE_MMAP
3468 If the @code{mmap} function exists and works correctly, define
3469 @code{HAVE_MMAP}. Only checks private fixed mapping of already-mapped
3470 memory.
3471 @end defmac
3472
3473 @defmac AC_FUNC_OBSTACK
3474 @maindex FUNC_OBSTACK
3475 @cvindex HAVE_OBSTACK
3476 @cindex obstack
3477 If the obstacks are found, define @code{HAVE_OBSTACK}, else require an
3478 @code{AC_LIBOBJ} replacement for @samp{obstack}.
3479 @end defmac
3480
3481 @defmac AC_FUNC_SELECT_ARGTYPES
3482 @maindex FUNC_SELECT_ARGTYPES
3483 @cvindex SELECT_TYPE_ARG1
3484 @cvindex SELECT_TYPE_ARG234
3485 @cvindex SELECT_TYPE_ARG5
3486 Determines the correct type to be passed for each of the
3487 @code{select} function's arguments, and defines those types
3488 in @code{SELECT_TYPE_ARG1}, @code{SELECT_TYPE_ARG234}, and
3489 @code{SELECT_TYPE_ARG5} respectively. @code{SELECT_TYPE_ARG1} defaults
3490 to @samp{int}, @code{SELECT_TYPE_ARG234} defaults to @samp{int *},
3491 and @code{SELECT_TYPE_ARG5} defaults to @samp{struct timeval *}.
3492 @end defmac
3493
3494 @defmac AC_FUNC_SETPGRP
3495 @maindex FUNC_SETPGRP
3496 @cvindex SETPGRP_VOID
3497 If @code{setpgrp} takes no argument (the @sc{posix.1} version), define
3498 @code{SETPGRP_VOID}. Otherwise, it is the @sc{bsd} version, which takes
3499 two process IDs as arguments. This macro does not check whether
3500 @code{setpgrp} exists at all; if you need to work in that situation,
3501 first call @code{AC_CHECK_FUNC} for @code{setpgrp}.
3502 @end defmac
3503
3504 @defmac AC_FUNC_STAT
3505 @defmacx AC_FUNC_LSTAT
3506 @maindex FUNC_STAT
3507 @maindex FUNC_LSTAT
3508 @cvindex HAVE_STAT_EMPTY_STRING_BUG
3509 @cvindex HAVE_LSTAT_EMPTY_STRING_BUG
3510 Determine whether @code{stat} or @code{lstat} have the bug that it
3511 succeeds when given the zero-length file name argument. The @code{stat}
3512 and @code{lstat} from SunOS 4.1.4 and the Hurd (as of 1998-11-01) do
3513 this.
3514
3515 If it does, then define @code{HAVE_STAT_EMPTY_STRING_BUG} (or
3516 @code{HAVE_LSTAT_EMPTY_STRING_BUG}) and ask for an @code{AC_LIBOBJ}
3517 replacement of it.
3518 @end defmac
3519
3520 @defmac AC_FUNC_SETVBUF_REVERSED
3521 @maindex FUNC_SETVBUF_REVERSED
3522 @cvindex SETVBUF_REVERSED
3523 If @code{setvbuf} takes the buffering type as its second argument and
3524 the buffer pointer as the third, instead of the other way around, define
3525 @code{SETVBUF_REVERSED}.
3526 @end defmac
3527
3528 @defmac AC_FUNC_STRCOLL
3529 @maindex FUNC_STRCOLL
3530 @cvindex HAVE_STRCOLL
3531 If the @code{strcoll} function exists and works correctly, define
3532 @code{HAVE_STRCOLL}. This does a bit more than
3533 @samp{AC_CHECK_FUNCS(strcoll)}, because some systems have incorrect
3534 definitions of @code{strcoll} that should not be used.
3535 @end defmac
3536
3537 @defmac AC_FUNC_STRTOD
3538 @maindex FUNC_STRTOD
3539 @ovindex POW_LIB
3540 If the @code{strtod} function does not exist or doesn't work correctly,
3541 ask for an @code{AC_LIBOBJ} replacement of @samp{strtod}. In this case,
3542 because @file{strtod.c} is likely to need @samp{pow}, set the output
3543 variable @code{POW_LIB} to the extra library needed.
3544 @end defmac
3545
3546 @defmac AC_FUNC_STRERROR_R
3547 @maindex FUNC_STRERROR_R
3548 @cvindex HAVE_STRERROR_R
3549 @cvindex HAVE_WORKING_STRERROR_R
3550 If @code{strerror_r} is available, define @code{HAVE_STRERROR_R}. If
3551 its implementation correctly returns a @code{char *}, define
3552 @code{HAVE_WORKING_STRERROR_R}. On at least DEC UNIX 4.0[A-D] and HP-UX
3553 B.10.20, @code{strerror_r} returns @code{int}. Actually, this tests
3554 only whether it returns a scalar or an array, but that should be enough.
3555 This is used by the common @file{error.c}.
3556 @end defmac
3557
3558 @defmac AC_FUNC_STRFTIME
3559 @maindex FUNC_STRFTIME
3560 @cvindex HAVE_STRFTIME
3561 Check for @code{strftime} in the @file{intl} library, for SCO @sc{unix}.
3562 Then, if @code{strftime} is available, define @code{HAVE_STRFTIME}.
3563 @end defmac
3564
3565 @defmac AC_FUNC_UTIME_NULL
3566 @maindex FUNC_UTIME_NULL
3567 @cvindex HAVE_UTIME_NULL
3568 If @samp{utime(@var{file}, NULL)} sets @var{file}'s timestamp to
3569 the present, define @code{HAVE_UTIME_NULL}.
3570 @end defmac
3571
3572 @defmac AC_FUNC_VPRINTF
3573 @maindex FUNC_VPRINTF
3574 @cvindex HAVE_VPRINTF
3575 @cvindex HAVE_DOPRNT
3576 If @code{vprintf} is found, define @code{HAVE_VPRINTF}. Otherwise, if
3577 @code{_doprnt} is found, define @code{HAVE_DOPRNT}. (If @code{vprintf}
3578 is available, you may assume that @code{vfprintf} and @code{vsprintf}
3579 are also available.)
3580 @end defmac
3581
3582 @node Generic Functions, , Particular Functions, Library Functions
3583 @subsection Generic Function Checks
3584
3585 These macros are used to find functions not covered by the ``particular''
3586 test macros. If the functions might be in libraries other than the
3587 default C library, first call @code{AC_CHECK_LIB} for those libraries.
3588 If you need to check the behavior of a function as well as find out
3589 whether it is present, you have to write your own test for
3590 it (@pxref{Writing Tests}).
3591
3592 @defmac AC_CHECK_FUNC (@var{function}, @ovar{action-if-found}, @ovar{action-if-not-found})
3593 @maindex CHECK_FUNC
3594 If C function @var{function} is available, run shell commands
3595 @var{action-if-found}, otherwise @var{action-if-not-found}. If you just
3596 want to define a symbol if the function is available, consider using
3597 @code{AC_CHECK_FUNCS} instead. This macro checks for functions with C
3598 linkage even when @code{AC_LANG(C++)} has been called, since C is more
3599 standardized than C++. (@pxref{Language Choice}, for more information
3600 about selecting the language for checks.)
3601 @end defmac
3602
3603 @defmac AC_CHECK_FUNCS (@var{function}@dots{}, @ovar{action-if-found}, @ovar{action-if-not-found})
3604 @maindex CHECK_FUNCS
3605 @cvindex HAVE_@var{function}
3606 For each @var{function} in the whitespace-separated argument list,
3607 define @code{HAVE_@var{function}} (in all capitals) if it is available.
3608 If @var{action-if-found} is given, it is additional shell code to
3609 execute when one of the functions is found. You can give it a value of
3610 @samp{break} to break out of the loop on the first match. If
3611 @var{action-if-not-found} is given, it is executed when one of the
3612 functions is not found.
3613 @end defmac
3614
3615 Autoconf follows a philosophy that was formed over the years by those
3616 who have struggled for portability: isolate the portability issues in
3617 specific files, and then program as if you were in a @sc{posix}
3618 environment. Some functions may be missing or unfixable, and your
3619 package must be ready to replace them.
3620
3621 Use the first three of the following macros to specify a function to be
3622 replaced, and the last one (@code{AC_REPLACE_FUNCS}) to check for and
3623 replace the function if needed.
3624
3625 @defmac AC_LIBOBJ (@var{function})
3626 @maindex LIBOBJ
3627 @ovindex LIBOBJS
3628 Specify that @samp{@var{function}.c} must be included in the executables
3629 to replace a missing or broken implementation of @var{function}.
3630
3631 Technically, it adds @samp{@var{function}.$ac_objext} to the output
3632 variable @code{LIBOBJS} and calls @code{AC_LIBSOURCE} for
3633 @samp{@var{function}.c}. You should not directly change @code{LIBOBJS},
3634 since this is not traceable.
3635 @end defmac
3636
3637 @defmac AC_LIBSOURCE (@var{file})
3638 @maindex LIBSOURCE
3639 Specify that @var{file} might be needed to compile the project. If you
3640 need to know what files might be needed by a @file{configure.ac}, you
3641 should trace @code{AC_LIBSOURCE}. @var{file} must be a literal.
3642
3643 This macro is called automatically from @code{AC_LIBOBJ}, but you must
3644 call it explicitly if you pass a shell variable to @code{AC_LIBOBJ}. In
3645 that case, since shell variables cannot be traced statically, you must
3646 pass to @code{AC_LIBSOURCE} any possible files that the shell variable
3647 might cause @code{AC_LIBOBJ} to need. For example, if you want to pass
3648 a variable @code{$foo_or_bar} to @code{AC_LIBOBJ} that holds either
3649 @code{"foo"} or @code{"bar"}, you should do:
3650
3651 @example
3652 AC_LIBSOURCE(foo.c)
3653 AC_LIBSOURCE(bar.c)
3654 AC_LIBOBJ($foo_or_bar)
3655 @end example
3656
3657 @noindent
3658 There is usually a way to avoid this, however, and you are encouraged to
3659 simply call @code{AC_LIBOBJ} with literal arguments.
3660
3661 Note that this macro replaces the obsolete @code{AC_LIBOBJ_DECL}, with
3662 slightly different semantics: the old macro took the function name,
3663 e.g. @code{foo}, as its argument rather than the file name.
3664 @end defmac
3665
3666 @defmac AC_LIBSOURCES (@var{files})
3667 @maindex LIBSOURCES
3668 Like @code{AC_LIBSOURCE}, but accepts one or more @var{files} in a
3669 comma-separated M4 list. Thus, the above example might be rewritten:
3670
3671 @example
3672 AC_LIBSOURCES([foo.c, bar.c])
3673 AC_LIBOBJ($foo_or_bar)
3674 @end example
3675 @end defmac
3676
3677 @defmac AC_REPLACE_FUNCS (@var{function}@dots{})
3678 @maindex REPLACE_FUNCS
3679 @ovindex LIBOBJS
3680 Like @code{AC_CHECK_FUNCS}, but uses @samp{AC_LIBOBJ(@var{function})} as
3681 @var{action-if-not-found}. You can declare your replacement function by
3682 enclosing the prototype in @samp{#if !HAVE_@var{function}}. If the
3683 system has the function, it probably declares it in a header file you
3684 should be including, so you shouldn't redeclare it lest your declaration
3685 conflict.
3686 @end defmac
3687
3688 @node Header Files, Declarations, Library Functions, Existing Tests
3689 @section Header Files
3690 @cindex Header, checking
3691
3692 The following macros check for the presence of certain C header files.
3693 If there is no macro specifically defined to check for a header file you need,
3694 and you don't need to check for any special properties of
3695 it, then you can use one of the general header-file check macros.
3696
3697 @menu
3698 * Particular Headers:: Special handling to find certain headers
3699 * Generic Headers:: How to find other headers
3700 @end menu
3701
3702 @node Particular Headers, Generic Headers, Header Files, Header Files
3703 @subsection Particular Header Checks
3704
3705 These macros check for particular system header files---whether they
3706 exist, and in some cases whether they declare certain symbols.
3707
3708 @defmac AC_HEADER_DIRENT
3709 @maindex HEADER_DIRENT
3710 @cvindex HAVE_DIRENT_H
3711 @cvindex HAVE_NDIR_H
3712 @cvindex HAVE_SYS_DIR_H
3713 @cvindex HAVE_SYS_NDIR_H
3714 Check for the following header files. For the first one that is
3715 found and defines @samp{DIR}, define the listed C preprocessor macro:
3716
3717 @multitable {@file{sys/ndir.h}} {@code{HAVE_SYS_NDIR_H}}
3718 @item @file{dirent.h} @tab @code{HAVE_DIRENT_H}
3719 @item @file{sys/ndir.h} @tab @code{HAVE_SYS_NDIR_H}
3720 @item @file{sys/dir.h} @tab @code{HAVE_SYS_DIR_H}
3721 @item @file{ndir.h} @tab @code{HAVE_NDIR_H}
3722 @end multitable
3723
3724 The directory-library declarations in your source code should look
3725 something like the following:
3726
3727 @example
3728 @group
3729 #if HAVE_DIRENT_H
3730 # include <dirent.h>
3731 # define NAMLEN(dirent) strlen((dirent)->d_name)
3732 #else
3733 # define dirent direct
3734 # define NAMLEN(dirent) (dirent)->d_namlen
3735 # if HAVE_SYS_NDIR_H
3736 # include <sys/ndir.h>
3737 # endif
3738 # if HAVE_SYS_DIR_H
3739 # include <sys/dir.h>
3740 # endif
3741 # if HAVE_NDIR_H
3742 # include <ndir.h>
3743 # endif
3744 #endif
3745 @end group
3746 @end example
3747
3748 Using the above declarations, the program would declare variables to be
3749 of type @code{struct dirent}, not @code{struct direct}, and would access
3750 the length of a directory entry name by passing a pointer to a
3751 @code{struct dirent} to the @code{NAMLEN} macro.
3752
3753 This macro also checks for the SCO Xenix @file{dir} and @file{x} libraries.
3754 @end defmac
3755
3756 @defmac AC_HEADER_MAJOR
3757 @maindex HEADER_MAJOR
3758 @cvindex MAJOR_IN_MKDEV
3759 @cvindex MAJOR_IN_SYSMACROS
3760 If @file{sys/types.h} does not define @code{major}, @code{minor}, and
3761 @code{makedev}, but @file{sys/mkdev.h} does, define
3762 @code{MAJOR_IN_MKDEV}; otherwise, if @file{sys/sysmacros.h} does, define
3763 @code{MAJOR_IN_SYSMACROS}.
3764 @end defmac
3765
3766
3767 @defmac AC_HEADER_STAT
3768 @maindex HEADER_STAT
3769 @maindex STAT_MACROS_BROKEN
3770 If the macros @code{S_ISDIR}, @code{S_ISREG} et al. defined in
3771 @file{sys/stat.h} do not work properly (returning false positives),
3772 define @code{STAT_MACROS_BROKEN}. This is the case on Tektronix UTekV,
3773 Amdahl UTS and Motorola System V/88.
3774 @end defmac
3775
3776
3777 @defmac AC_HEADER_STDC
3778 @maindex HEADER_STDC
3779 @cvindex STDC_HEADERS
3780 Define @code{STDC_HEADERS} if the system has @sc{ansi} C header files.
3781 Specifically, this macro checks for @file{stdlib.h}, @file{stdarg.h},
3782 @file{string.h}, and @file{float.h}; if the system has those, it
3783 probably has the rest of the @sc{ansi} C header files. This macro also
3784 checks whether @file{string.h} declares @code{memchr} (and thus
3785 presumably the other @code{mem} functions), whether @file{stdlib.h}
3786 declare @code{free} (and thus presumably @code{malloc} and other related
3787 functions), and whether the @file{ctype.h} macros work on characters
3788 with the high bit set, as @sc{ansi} C requires.
3789
3790 Use @code{STDC_HEADERS} instead of @code{__STDC__} to determine whether
3791 the system has @sc{ansi}-compliant header files (and probably C library
3792 functions) because many systems that have GCC do not have @sc{ansi} C
3793 header files.
3794
3795 On systems without @sc{ansi} C headers, there is so much variation that
3796 it is probably easier to declare the functions you use than to figure
3797 out exactly what the system header files declare. Some systems contain
3798 a mix of functions @sc{ansi} and @sc{bsd}; some are mostly @sc{ansi} but
3799 lack @samp{memmove}; some define the @sc{bsd} functions as macros in
3800 @file{string.h} or @file{strings.h}; some have only the @sc{bsd}
3801 functions but @file{string.h}; some declare the memory functions in
3802 @file{memory.h}, some in @file{string.h}; etc. It is probably
3803 sufficient to check for one string function and one memory function; if
3804 the library has the @sc{ansi} versions of those then it probably has
3805 most of the others. If you put the following in @file{configure.ac}:
3806
3807 @example
3808 AC_HEADER_STDC
3809 AC_CHECK_FUNCS(strchr memcpy)
3810 @end example
3811
3812 @noindent
3813 then, in your code, you can put declarations like this:
3814
3815 @example
3816 @group
3817 #if STDC_HEADERS
3818 # include <string.h>
3819 #else
3820 # if !HAVE_STRCHR
3821 # define strchr index
3822 # define strrchr rindex
3823 # endif
3824 char *strchr (), *strrchr ();
3825 # if !HAVE_MEMCPY
3826 # define memcpy(d, s, n) bcopy ((s), (d), (n))
3827 # define memmove(d, s, n) bcopy ((s), (d), (n))
3828 # endif
3829 #endif
3830 @end group
3831 @end example
3832
3833 @noindent
3834 If you use a function like @code{memchr}, @code{memset}, @code{strtok},
3835 or @code{strspn}, which have no @sc{bsd} equivalent, then macros won't
3836 suffice; you must provide an implementation of each function. An easy
3837 way to incorporate your implementations only when needed (since the ones
3838 in system C libraries may be hand optimized) is to, taking @code{memchr}
3839 for example, put it in @file{memchr.c} and use
3840 @samp{AC_REPLACE_FUNCS(memchr)}.
3841 @end defmac
3842
3843 @defmac AC_HEADER_SYS_WAIT
3844 @maindex HEADER_SYS_WAIT
3845 @cvindex HAVE_SYS_WAIT_H
3846 If @file{sys/wait.h} exists and is compatible with @sc{posix.1}, define
3847 @code{HAVE_SYS_WAIT_H}. Incompatibility can occur if @file{sys/wait.h}
3848 does not exist, or if it uses the old @sc{bsd} @code{union wait} instead
3849 of @code{int} to store a status value. If @file{sys/wait.h} is not
3850 @sc{posix.1} compatible, then instead of including it, define the
3851 @sc{posix.1} macros with their usual interpretations. Here is an
3852 example:
3853
3854 @example
3855 @group
3856 #include <sys/types.h>
3857 #if HAVE_SYS_WAIT_H
3858 # include <sys/wait.h>
3859 #endif
3860 #ifndef WEXITSTATUS
3861 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
3862 #endif
3863 #ifndef WIFEXITED
3864 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
3865 #endif
3866 @end group
3867 @end example
3868 @end defmac
3869
3870 @cvindex _POSIX_VERSION
3871 @code{_POSIX_VERSION} is defined when @file{unistd.h} is included on
3872 @sc{posix.1} systems. If there is no @file{unistd.h}, it is definitely
3873 not a @sc{posix.1} system. However, some non-@sc{posix.1} systems do
3874 have @file{unistd.h}.
3875
3876 The way to check if the system supports @sc{posix.1} is:
3877
3878 @example
3879 @group
3880 #if HAVE_UNISTD_H
3881 # include <sys/types.h>
3882 # include <unistd.h>
3883 #endif
3884
3885 #ifdef _POSIX_VERSION
3886 /* Code for POSIX.1 systems. */
3887 #endif
3888 @end group
3889 @end example
3890
3891 @defmac AC_HEADER_TIME
3892 @maindex HEADER_TIME
3893 @cvindex TIME_WITH_SYS_TIME
3894 If a program may include both @file{time.h} and @file{sys/time.h},
3895 define @code{TIME_WITH_SYS_TIME}. On some older systems,
3896 @file{sys/time.h} includes @file{time.h}, but @file{time.h} is not
3897 protected against multiple inclusion, so programs should not explicitly
3898 include both files. This macro is useful in programs that use, for
3899 example, @code{struct timeval} or @code{struct timezone} as well as
3900 @code{struct tm}. It is best used in conjunction with
3901 @code{HAVE_SYS_TIME_H}, which can be checked for using
3902 @code{AC_CHECK_HEADERS(sys/time.h)}.
3903
3904 @example
3905 @group
3906 #if TIME_WITH_SYS_TIME
3907 # include <sys/time.h>
3908 # include <time.h>
3909 #else
3910 # if HAVE_SYS_TIME_H
3911 # include <sys/time.h>
3912 # else
3913 # include <time.h>
3914 # endif
3915 #endif
3916 @end group
3917 @end example
3918 @end defmac
3919
3920
3921 @defmac AC_HEADER_TIOCGWINSZ
3922 @maindex HEADER_TIOCGWINSZ
3923 @cvindex GWINSZ_IN_SYS_IOCTL
3924 @c FIXME: I need clarifications from Jim.
3925 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
3926 define @code{GWINSZ_IN_SYS_IOCTL}. Otherwise @code{TIOCGWINSZ} can be
3927 found in @file{<termios.h>}.
3928
3929 Use:
3930
3931 @example
3932 @group
3933 #if HAVE_TERMIOS_H
3934 # include <termios.h>
3935 #endif
3936
3937 #if GWINSZ_IN_SYS_IOCTL
3938 # include <sys/ioctl.h>
3939 #endif
3940 @end group
3941 @end example
3942 @end defmac
3943
3944 @node Generic Headers, , Particular Headers, Header Files
3945 @subsection Generic Header Checks
3946
3947 These macros are used to find system header files not covered by the
3948 ``particular'' test macros. If you need to check the contents of a header
3949 as well as find out whether it is present, you have to write your own
3950 test for it (@pxref{Writing Tests}).
3951
3952 @defmac AC_CHECK_HEADER (@var{header-file}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
3953 @maindex CHECK_HEADER
3954 If the system header file @var{header-file} is usable, execute shell
3955 commands @var{action-if-found}, otherwise execute
3956 @var{action-if-not-found}. If you just want to define a symbol if the
3957 header file is available, consider using @code{AC_CHECK_HEADERS}
3958 instead.
3959
3960 The meaning of ``usable'' depends upon the content of @var{includes}:
3961
3962 @table @asis
3963 @item if @var{includes} is empty
3964 check whether
3965
3966 @example
3967 @var{header-file}
3968 @end example
3969
3970 @noindent
3971 can be @emph{preprocessed} without error.
3972
3973 @item if @var{include} is set
3974 Check whether
3975
3976 @example
3977 @var{includes}
3978 #include <@var{header-file}>
3979 @end example
3980
3981 @noindent
3982 can be @emph{compiled} without error. You may use
3983 @code{AC_CHECK_HEADER} (and @code{AC_CHECK_HEADERS}) to check whether
3984 two headers are compatible.
3985 @end table
3986
3987 You may pass any kind of dummy content for @var{includes}, such as a
3988 single space, a comment, to check whether @var{header-file} compiles
3989 with success.
3990 @end defmac
3991
3992 @defmac AC_CHECK_HEADERS (@var{header-file}@dots{}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
3993 @maindex CHECK_HEADERS
3994 @cvindex HAVE_@var{header}
3995 For each given system header file @var{header-file} in the
3996 whitespace-separated argument list that exists, define
3997 @code{HAVE_@var{header-file}} (in all capitals). If @var{action-if-found}
3998 is given, it is additional shell code to execute when one of the header
3999 files is found. You can give it a value of @samp{break} to break out of
4000 the loop on the first match. If @var{action-if-not-found} is given, it
4001 is executed when one of the header files is not found.
4002
4003 Be sure to read the documentation of @code{AC_CHECK_HEADER} to
4004 understand the influence of @var{includes}.
4005 @end defmac
4006
4007 @node Declarations, Structures, Header Files, Existing Tests
4008 @section Declarations
4009 @cindex Declaration, checking
4010
4011 The following macros check for the declaration of variables and
4012 functions. If there is no macro specifically defined to check for a
4013 symbol you need, then you can use the general macros (@pxref{Generic
4014 Declarations}) or, for more complex tests, you may use
4015 @code{AC_TRY_COMPILE} (@pxref{Examining Syntax}).
4016
4017 @menu
4018 * Particular Declarations:: Macros to check for certain declarations
4019 * Generic Declarations:: How to find other declarations
4020 @end menu
4021
4022 @node Particular Declarations, Generic Declarations, Declarations, Declarations
4023 @subsection Particular Declaration Checks
4024
4025 The following macros check for certain declarations.
4026
4027 @defmac AC_DECL_SYS_SIGLIST
4028 @maindex DECL_SYS_SIGLIST
4029 @cvindex SYS_SIGLIST_DECLARED
4030 Define @code{SYS_SIGLIST_DECLARED} if the variable @code{sys_siglist}
4031 is declared in a system header file, either @file{signal.h} or
4032 @file{unistd.h}.
4033 @end defmac
4034
4035 @node Generic Declarations, , Particular Declarations, Declarations
4036 @subsection Generic Declaration Checks
4037
4038 These macros are used to find declarations not covered by the ``particular''
4039 test macros.
4040
4041 @defmac AC_CHECK_DECL (@var{symbol}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
4042 @maindex CHECK_DECL
4043 If @var{symbol} (a function or a variable) is not declared in
4044 @var{includes} and a declaration is needed, run the shell commands
4045 @var{action-if-not-found}, otherwise @var{action-if-found}. If no
4046 @var{includes} are specified, the default includes are used
4047 (@pxref{Default Includes}).
4048
4049 This macro actually tests whether it is valid to use @var{symbol} as an
4050 r-value, not if it is really declared, because it is much safer to avoid
4051 introducing extra declarations when they are not needed.
4052 @end defmac
4053
4054 @defmac AC_CHECK_DECLS (@var{symbols}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
4055 @maindex CHECK_DECLS
4056 @cvindex HAVE_DECL_@var{symbol}
4057 For each of the @var{symbols} (@emph{comma}-separated list), define
4058 @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
4059 @var{symbol} is declared, otherwise to @samp{0}. If
4060 @var{action-if-not-found} is given, it is additional shell code to
4061 execute when one of the function declarations is needed, otherwise
4062 @var{action-if-found} is executed.
4063
4064 This macro uses an m4 list as first argument:
4065 @example
4066 AC_CHECK_DECLS(strdup)
4067 AC_CHECK_DECLS([strlen])
4068 AC_CHECK_DECLS([malloc, realloc, calloc, free])
4069 @end example
4070
4071 Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not
4072 declared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} instead
4073 of leaving @code{HAVE_DECL_@var{symbol}} undeclared. When you are
4074 @emph{sure} that the check was performed, use
4075 @code{HAVE_DECL_@var{symbol}} just like any other result of Autoconf:
4076
4077 @example
4078 #if !HAVE_DECL_SYMBOL
4079 extern char *symbol;
4080 #endif
4081 @end example
4082
4083 @noindent
4084 If the test may have not been performed, however, because it is safer
4085 @emph{not} to declare a symbol than to use a declaration that conflicts
4086 with the system's one, you should use:
4087
4088 @example
4089 #if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
4090 char *malloc (size_t *s);
4091 #endif
4092 @end example
4093
4094 @noindent
4095 You fall into the second category only in extreme situations: either
4096 your files may be used without being configured, or they are used during
4097 the configuration. In most cases the traditional approach is enough.
4098 @end defmac
4099
4100
4101 @node Structures, Types, Declarations, Existing Tests
4102 @section Structures
4103 @cindex Structure, checking
4104
4105 The following macros check for the presence of certain members in C
4106 structures. If there is no macro specifically defined to check for a
4107 member you need, then you can use the general structure-member macro
4108 (@pxref{Generic Structures}) or, for more complex tests, you may use
4109 @code{AC_TRY_COMPILE} (@pxref{Examining Syntax}).
4110
4111 @menu
4112 * Particular Structures:: Macros to check for certain structure members
4113 * Generic Structures:: How to find other structure members
4114 @end menu
4115
4116 @node Particular Structures, Generic Structures, Structures, Structures
4117 @subsection Particular Structure Checks
4118
4119 The following macros check for certain structures or structure members.
4120
4121 @defmac AC_STRUCT_ST_BLKSIZE
4122 @maindex STRUCT_ST_BLKSIZE
4123 @cvindex HAVE_STRUCT_STAT_ST_BLKSIZE
4124 @cvindex HAVE_ST_BLKSIZE
4125 If @code{struct stat} contains an @code{st_blksize} member, define
4126 @code{HAVE_STRUCT_STAT_ST_BLKSIZE}. The former name,
4127 @code{HAVE_ST_BLKSIZE} is to be avoided, as its support will cease in
4128 the future. This macro is obsoleted, and should be replaced by
4129
4130 @example
4131 AC_CHECK_MEMBERS([struct stat.st_blksize])
4132 @end example
4133 @end defmac
4134
4135 @defmac AC_STRUCT_ST_BLOCKS
4136 @maindex STRUCT_ST_BLOCKS
4137 @cvindex HAVE_STRUCT_STAT_ST_BLOCKS
4138 @cvindex HAVE_ST_BLOCKS
4139 @ovindex LIBOBJS
4140 If @code{struct stat} contains an @code{st_blocks} member, define
4141 @code{HAVE_STRUCT STAT_ST_BLOCKS}. Otherwise, require an
4142 @code{AC_LIBOBJ} replacement of @samp{fileblocks}. The former name,
4143 @code{HAVE_ST_BLOCKS} is to be avoided, as its support will cease in the
4144 future.
4145 @end defmac
4146
4147 @defmac AC_STRUCT_ST_RDEV
4148 @maindex STRUCT_ST_RDEV
4149 @cvindex HAVE_ST_RDEV
4150 @cvindex HAVE_STRUCT_STAT_ST_RDEV
4151 If @code{struct stat} contains an @code{st_rdev} member, define
4152 @code{HAVE_STRUCT_STAT_ST_RDEV}. The former name for this macro,
4153 @code{HAVE_ST_RDEV}, is to be avoided as it will cease to be supported
4154 in the future. Actually, even the new macro is obsolete, and should be
4155 replaced by:
4156 @example
4157 AC_CHECK_MEMBERS([struct stat.st_rdev])
4158 @end example
4159 @end defmac
4160
4161 @defmac AC_STRUCT_TM
4162 @maindex STRUCT_TM
4163 @cvindex TM_IN_SYS_TIME
4164 If @file{time.h} does not define @code{struct tm}, define
4165 @code{TM_IN_SYS_TIME}, which means that including @file{sys/time.h}
4166 had better define @code{struct tm}.
4167 @end defmac
4168
4169 @defmac AC_STRUCT_TIMEZONE
4170 @maindex STRUCT_TIMEZONE
4171 @cvindex HAVE_TM_ZONE
4172 @cvindex HAVE_TZNAME
4173 Figure out how to get the current timezone. If @code{struct tm} has a
4174 @code{tm_zone} member, define @code{HAVE_STRUCT_TM_TM_ZONE} (and the
4175 obsoleted @code{HAVE_TM_ZONE}). Otherwise, if the external array
4176 @code{tzname} is found, define @code{HAVE_TZNAME}.
4177 @end defmac
4178
4179 @node Generic Structures, , Particular Structures, Structures
4180 @subsection Generic Structure Checks
4181
4182 These macros are used to find structure members not covered by the
4183 ``particular'' test macros.
4184
4185 @defmac AC_CHECK_MEMBER (@var{aggregate}.@var{member}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
4186 @maindex CHECK_MEMBER
4187 Check whether @var{member} is a member of the aggregate @var{aggregate}.
4188 If no @var{includes} are specified, the default includes are used
4189 (@pxref{Default Includes}).
4190
4191 @example
4192 AC_CHECK_MEMBER(struct passwd.pw_gecos,,
4193 [AC_MSG_ERROR([We need `passwd.pw_gecos'!])],
4194 [#include <pwd.h>])
4195 @end example
4196
4197 You can use this macro for sub-members:
4198
4199 @example
4200 AC_CHECK_MEMBER(struct top.middle.bot)
4201 @end example
4202 @end defmac
4203
4204 @defmac AC_CHECK_MEMBERS (@var{members}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
4205 @maindex CHECK_MEMBERS
4206 Check for the existence of each @samp{@var{aggregate}.@var{member}} of
4207 @var{members} using the previous macro. When @var{member} belongs to
4208 @var{aggregate}, define @code{HAVE_@var{aggregate}_@var{member}} (in all
4209 capitals, with spaces and dots replaced by underscores).
4210
4211 This macro uses m4 lists:
4212 @example
4213 AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize])
4214 @end example
4215 @end defmac
4216
4217
4218 @node Types, Compilers and Preprocessors, Structures, Existing Tests
4219 @section Types
4220
4221 The following macros check for C types, either builtin or typedefs. If
4222 there is no macro specifically defined to check for a type you need, and
4223 you don't need to check for any special properties of it, then you can
4224 use a general type-check macro.
4225
4226 @menu
4227 * Particular Types:: Special handling to find certain types
4228 * Generic Types:: How to find other types
4229 @end menu
4230
4231 @node Particular Types, Generic Types, Types, Types
4232 @subsection Particular Type Checks
4233
4234 These macros check for particular C types in @file{sys/types.h},
4235 @file{stdlib.h} and others, if they exist.
4236
4237 @defmac AC_TYPE_GETGROUPS
4238 @maindex TYPE_GETGROUPS
4239 @cvindex GETGROUPS_T
4240 Define @code{GETGROUPS_T} to be whichever of @code{gid_t} or @code{int}
4241 is the base type of the array argument to @code{getgroups}.
4242 @end defmac
4243
4244 @defmac AC_TYPE_MODE_T
4245 @maindex TYPE_MODE_T
4246 @cvindex mode_t
4247 Equivalent to @samp{AC_CHECK_TYPE(mode_t, int)}.
4248 @end defmac
4249
4250 @defmac AC_TYPE_OFF_T
4251 @maindex TYPE_OFF_T
4252 @cvindex off_t
4253 Equivalent to @samp{AC_CHECK_TYPE(off_t, long)}.
4254 @end defmac
4255
4256 @defmac AC_TYPE_PID_T
4257 @maindex TYPE_PID_T
4258 @cvindex pid_t
4259 Equivalent to @samp{AC_CHECK_TYPE(pid_t, int)}.
4260 @end defmac
4261
4262 @defmac AC_TYPE_SIGNAL
4263 @maindex TYPE_SIGNAL
4264 @cvindex RETSIGTYPE
4265 If @file{signal.h} declares @code{signal} as returning a pointer to a
4266 function returning @code{void}, define @code{RETSIGTYPE} to be
4267 @code{void}; otherwise, define it to be @code{int}.
4268
4269 Define signal handlers as returning type @code{RETSIGTYPE}:
4270
4271 @example
4272 @group
4273 RETSIGTYPE
4274 hup_handler ()
4275 @{
4276 @dots{}
4277 @}
4278 @end group
4279 @end example
4280 @end defmac
4281
4282 @defmac AC_TYPE_SIZE_T
4283 @maindex TYPE_SIZE_T
4284 @cvindex size_t
4285 Equivalent to @samp{AC_CHECK_TYPE(size_t, unsigned)}.
4286 @end defmac
4287
4288 @defmac AC_TYPE_UID_T
4289 @maindex TYPE_UID_T
4290 @cvindex uid_t
4291 @cvindex gid_t
4292 If @code{uid_t} is not defined, define @code{uid_t} to be @code{int} and
4293 @code{gid_t} to be @code{int}.
4294 @end defmac
4295
4296 @node Generic Types, , Particular Types, Types
4297 @subsection Generic Type Checks
4298
4299 These macros are used to check for types not covered by the ``particular''
4300 test macros.
4301
4302 @defmac AC_CHECK_TYPE (@var{type}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
4303 @maindex CHECK_TYPE
4304 Check whether @var{type} is defined. It may be a compiler builtin type
4305 or defined by the @ovar{includes} (@pxref{Default Includes}).
4306 @end defmac
4307
4308
4309 @defmac AC_CHECK_TYPES (@var{types}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
4310 @maindex CHECK_TYPES
4311 For each @var{type} of the @var{types} that is defined, define
4312 @code{HAVE_@var{type}} (in all capitals). If no @var{includes} are
4313 specified, the default includes are used (@pxref{Default Includes}). If
4314 @var{action-if-found} is given, it is additional shell code to execute
4315 when one of the types is found. If @var{action-if-not-found} is given,
4316 it is executed when one of the types is not found.
4317
4318 This macro uses m4 lists:
4319 @example
4320 AC_CHECK_TYPES(ptrdiff_t)
4321 AC_CHECK_TYPES([unsigned long long, uintmax_t])
4322 @end example
4323
4324 @end defmac
4325
4326 Autoconf, up to 2.13, used to provide to another version of
4327 @code{AC_CHECK_TYPE}, broken by design. In order to keep backward
4328 compatibility, a simple heuristics, quite safe but not totally, is
4329 implemented. In case of doubt, read the documentation of the former
4330 @code{AC_CHECK_TYPE}, see @ref{Obsolete Macros}.
4331
4332
4333 @node Compilers and Preprocessors, System Services, Types, Existing Tests
4334 @section Compilers and Preprocessors
4335
4336 @ovindex EXEEXT
4337 All the tests for compilers (@code{AC_PROG_CC}, @code{AC_PROG_CXX},
4338 @code{AC_PROG_F77}) define the output variable @code{EXEEXT} based on
4339 the output of the compiler, typically to the empty string if Unix and
4340 @samp{.exe} if Win32 or OS/2.
4341
4342 @ovindex OBJEXT
4343 They also define the output variable @code{OBJEXT} based on the
4344 output of the compiler, after .c files have been excluded, typically
4345 to @samp{o} if Unix, @samp{obj} if Win32.
4346
4347 If the compiler being used does not produce executables, they fail. If
4348 the executables can't be run, and cross-compilation is not enabled, they
4349 fail too. @xref{Manual Configuration}, for more on support for cross
4350 compiling.
4351
4352 @menu
4353 * Generic Compiler Characteristics:: Language independent tests
4354 * C Compiler:: Checking its characteristics
4355 * C++ Compiler:: Likewise
4356 * Fortran 77 Compiler:: Likewise
4357 @end menu
4358
4359 @node Generic Compiler Characteristics, C Compiler, Compilers and Preprocessors, Compilers and Preprocessors
4360 @subsection Generic Compiler Characteristics
4361
4362 @defmac AC_CHECK_SIZEOF (@var{type}, @ovar{unused}, @ovar{includes})
4363 @maindex CHECK_SIZEOF
4364 Define @code{SIZEOF_@var{type}} (@pxref{Standard Symbols}) to be the
4365 size in bytes of @var{type}. If @samp{type} is unknown, it gets a size
4366 of 0. If no @var{includes} are specified, the default includes are used
4367 (@pxref{Default Includes}). If you provide @var{include}, make sure to
4368 include @file{stdio.h} which is required for this macro to run.
4369
4370 This macro now works even when cross-compiling. The @var{unused}
4371 argument was used when cross-compiling.
4372
4373 For example, the call
4374
4375 @example
4376 AC_CHECK_SIZEOF(int *)
4377 @end example
4378
4379 @noindent
4380 defines @code{SIZEOF_INT_P} to be 8 on DEC Alpha AXP systems.
4381 @end defmac
4382
4383
4384 @node C Compiler, C++ Compiler, Generic Compiler Characteristics, Compilers and Preprocessors
4385 @subsection C Compiler Characteristics
4386
4387 @defmac AC_PROG_CC (@ovar{compiler-search-list})
4388 @maindex PROG_CC
4389 @ovindex CC
4390 @ovindex CFLAGS
4391 Determine a C compiler to use. If @code{CC} is not already set in the
4392 environment, check for @code{gcc} and @code{cc}, then for other C
4393 compilers. Set output variable @code{CC} to the name of the compiler
4394 found.
4395
4396 This macro may, however, be invoked with an optional first argument
4397 which, if specified, must be a space separated list of C compilers to
4398 search for. This just gives the user an opportunity to specify an
4399 alternative search list for the C compiler. For example, if you didn't
4400 like the default order, then you could invoke @code{AC_PROG_CC} like
4401 this:
4402
4403 @example
4404 AC_PROG_CC(cl egcs gcc cc)
4405 @end example
4406
4407 If using the @sc{gnu} C compiler, set shell variable @code{GCC} to
4408 @samp{yes}. If output variable @code{CFLAGS} was not already set, set
4409 it to @option{-g -O2} for the @sc{gnu} C compiler (@option{-O2} on systems
4410 where GCC does not accept @option{-g}), or @option{-g} for other compilers.
4411 @end defmac
4412
4413 @defmac AC_PROG_CC_C_O
4414 @maindex PROG_CC_C_O
4415 @cvindex NO_MINUS_C_MINUS_O
4416 If the C compiler does not accept the @option{-c} and @option{-o} options
4417 simultaneously, define @code{NO_MINUS_C_MINUS_O}. This macro actually
4418 tests both the compiler found by @code{AC_PROG_CC}, and, if different,
4419 the first @code{cc} in the path. The test fails if one fails. This
4420 macro was created for @sc{gnu} Make to choose the default C compilation
4421 rule.
4422 @end defmac
4423
4424 @defmac AC_PROG_CC_STDC
4425 @maindex PROG_CC_STDC
4426 @ovindex CC
4427 If the C compiler is not in @sc{ansi} C mode by default, try to add an
4428 option to output variable @code{CC} to make it so. This macro tries
4429 various options that select @sc{ansi} C on some system or another. It
4430 considers the compiler to be in @sc{ansi} C mode if it handles function
4431 prototypes correctly.
4432
4433 If you use this macro, you should check after calling it whether the C
4434 compiler has been set to accept @sc{ansi} C; if not, the shell variable
4435 @code{ac_cv_prog_cc_stdc} is set to @samp{no}. If you wrote your source
4436 code in @sc{ansi} C, you can make an un-@sc{ansi}fied copy of it by
4437 using the program @code{ansi2knr}, which comes with Automake.
4438 @end defmac
4439
4440
4441 @defmac AC_PROG_CPP
4442 @maindex PROG_CPP
4443 @ovindex CPP
4444 Set output variable @code{CPP} to a command that runs the
4445 C preprocessor. If @samp{$CC -E} doesn't work, @file{/lib/cpp} is used.
4446 It is only portable to run @code{CPP} on files with a @file{.c}
4447 extension.
4448
4449 If the current language is C (@pxref{Language Choice}), many of the
4450 specific test macros use the value of @code{CPP} indirectly by calling
4451 @code{AC_TRY_CPP}, @code{AC_CHECK_HEADER}, @code{AC_EGREP_HEADER}, or
4452 @code{AC_EGREP_CPP}.
4453
4454 Some preprocessors don't indicate missing include files by the error
4455 status. For such preprocessors an internal variable is set that causes
4456 other macros to check the standard error from the preprocessor and
4457 consider the test failed if any warnings have been reported.
4458 @end defmac
4459
4460
4461 The following macros check for C compiler or machine architecture
4462 features. To check for characteristics not listed here, use
4463 @code{AC_TRY_COMPILE} (@pxref{Examining Syntax}) or @code{AC_TRY_RUN}
4464 (@pxref{Run Time})
4465
4466 @defmac AC_C_BIGENDIAN
4467 @maindex C_BIGENDIAN
4468 @cvindex WORDS_BIGENDIAN
4469 @cindex Endianness
4470 If words are stored with the most significant byte first (like Motorola
4471 and SPARC, but not Intel and VAX, CPUs), define @code{WORDS_BIGENDIAN}.
4472 @end defmac
4473
4474
4475 @defmac AC_C_CONST
4476 @maindex C_CONST
4477 @cvindex const
4478 If the C compiler does not fully support the @sc{ansi} C qualifier
4479 @code{const}, define @code{const} to be empty. Some C compilers that do
4480 not define @code{__STDC__} do support @code{const}; some compilers that
4481 define @code{__STDC__} do not completely support @code{const}. Programs
4482 can simply use @code{const} as if every C compiler supported it; for
4483 those that don't, the @file{Makefile} or configuration header file will
4484 define it as empty.
4485
4486 Occasionally installers use a C++ compiler to compile C code, typically
4487 because they lack a C compiler. This causes problems with @code{const},
4488 because C and C++ treat @code{const} differently. For example:
4489
4490 @example
4491 const int foo;
4492 @end example
4493
4494 @noindent
4495 is valid in C but not in C++. These differences unfortunately cannot be
4496 papered over by defining @code{const} to be empty.
4497
4498 If @code{autoconf} detects this situation, it leaves @code{const} alone,
4499 as this generally yields better results in practice. However, using a
4500 C++ compiler to compile C code is not recommended or supported, and
4501 installers who run into trouble in this area should get a C compiler
4502 like GCC to compile their C code.
4503 @end defmac
4504
4505 @defmac AC_C_VOLATILE
4506 @maindex C_VOLATILE
4507 @cvindex volatile
4508 If the C compiler does not understand the keyword @code{volatile},
4509 define @code{volatile} to be empty. Programs can simply use
4510 @code{volatile} as if every C compiler supported it; for those that do
4511 not, the @file{Makefile} or configuration header will define it as
4512 empty.
4513
4514 If the correctness of your program depends on the semantics of
4515 @code{volatile}, simply defining it to be empty does, in a sense, break
4516 your code. However, given that the compiler does not support
4517 @code{volatile}, you are at its mercy anyway. At least your
4518 program will compile, when it wouldn't before.
4519
4520 In general, the @code{volatile} keyword is a feature of @sc{ansi} C, so
4521 you might expect that @code{volatile} is available only when
4522 @code{__STDC__} is defined. However, Ultrix 4.3's native compiler does
4523 support volatile, but does not defined @code{__STDC__}.
4524 @end defmac
4525
4526 @defmac AC_C_INLINE
4527 @maindex C_INLINE
4528 @cvindex inline
4529 If the C compiler supports the keyword @code{inline}, do nothing.
4530 Otherwise define @code{inline} to @code{__inline__} or @code{__inline}
4531 if it accepts one of those, otherwise define @code{inline} to be empty.
4532 @end defmac
4533
4534 @defmac AC_C_CHAR_UNSIGNED
4535 @maindex C_CHAR_UNSIGNED
4536 @cvindex __CHAR_UNSIGNED__
4537 If the C type @code{char} is unsigned, define @code{__CHAR_UNSIGNED__},
4538 unless the C compiler predefines it.
4539 @end defmac
4540
4541 @defmac AC_C_LONG_DOUBLE
4542 @maindex C_LONG_DOUBLE
4543 @cvindex HAVE_LONG_DOUBLE
4544 If the C compiler supports the @code{long double} type, define
4545 @code{HAVE_LONG_DOUBLE}. Some C compilers that do not define
4546 @code{__STDC__} do support the @code{long double} type; some compilers
4547 that define @code{__STDC__} do not support @code{long double}.
4548 @end defmac
4549
4550 @defmac AC_C_STRINGIZE
4551 @maindex C_STRINGIZE
4552 @cvindex HAVE_STRINGIZE
4553 If the C preprocessor supports the stringizing operator, define
4554 @code{HAVE_STRINGIZE}. The stringizing operator is @samp{#} and is
4555 found in macros such as this:
4556
4557 @example
4558 #define x(y) #y
4559 @end example
4560 @end defmac
4561
4562 @defmac AC_C_PROTOTYPES
4563 @maindex C_PROTOTYPES
4564 @cvindex PROTOTYPES
4565 @cvindex PARAMS
4566 Check to see if function prototypes are understood by the compiler. If
4567 so, define @samp{PROTOTYPES}. In the case the compiler does not handle
4568 prototypes, you should use @code{ansi2knr}, which comes with the
4569 Automake distribution, to unprotoize function definitions. For
4570 function prototypes, you should first define @code{PARAMS}:
4571
4572 @example
4573 #ifndef PARAMS
4574 # if PROTOTYPES
4575 # define PARAMS(protos) protos
4576 # else /* no PROTOTYPES */
4577 # define PARAMS(protos) ()
4578 # endif /* no PROTOTYPES */
4579 #endif
4580 @end example
4581
4582 @noindent
4583 then use it this way:
4584
4585 @example
4586 size_t my_strlen PARAMS ((const char *));
4587 @end example
4588 @end defmac
4589
4590 @defmac AC_PROG_GCC_TRADITIONAL
4591 @maindex PROG_GCC_TRADITIONAL
4592 @ovindex CC
4593 Add @option{-traditional} to output variable @code{CC} if using the
4594 @sc{gnu} C compiler and @code{ioctl} does not work properly without
4595 @option{-traditional}. That usually happens when the fixed header files
4596 have not been installed on an old system. Since recent versions of the
4597 @sc{gnu} C compiler fix the header files automatically when installed,
4598 this is becoming a less prevalent problem.
4599 @end defmac
4600
4601
4602 @node C++ Compiler, Fortran 77 Compiler, C Compiler, Compilers and Preprocessors
4603 @subsection C++ Compiler Characteristics
4604
4605
4606 @defmac AC_PROG_CXX (@ovar{compiler-search-list})
4607 @maindex PROG_CXX
4608 @ovindex CXX
4609 @ovindex CXXFLAGS
4610 Determine a C++ compiler to use. Check if the environment variable
4611 @code{CXX} or @code{CCC} (in that order) is set; if so, then set output
4612 variable @code{CXX} to its value.
4613
4614 Otherwise, if the macro is invoked without an argument, then search for
4615 a C++ compiler under the likely names (first @code{g++} and @code{c++}
4616 then other names). If none of those checks succeed, then as a last
4617 resort set @code{CXX} to @code{g++}.
4618
4619 This macro may, however, be invoked with an optional first argument
4620 which, if specified, must be a space separated list of C++ compilers to
4621 search for. This just gives the user an opportunity to specify an
4622 alternative search list for the C++ compiler. For example, if you
4623 didn't like the default order, then you could invoke @code{AC_PROG_CXX}
4624 like this:
4625
4626 @example
4627 AC_PROG_CXX(cl KCC CC cxx cc++ xlC aCC c++ g++ egcs gcc)
4628 @end example
4629
4630 If using the @sc{gnu} C++ compiler, set shell variable @code{GXX} to
4631 @samp{yes}. If output variable @code{CXXFLAGS} was not already set, set
4632 it to @option{-g -O2} for the @sc{gnu} C++ compiler (@option{-O2} on
4633 systems where G++ does not accept @option{-g}), or @option{-g} for other
4634 compilers.
4635 @end defmac
4636
4637 @defmac AC_PROG_CXXCPP
4638 @maindex PROG_CXXCPP
4639 @ovindex CXXCPP
4640 Set output variable @code{CXXCPP} to a command that runs the C++
4641 preprocessor. If @samp{$CXX -E} doesn't work, @file{/lib/cpp} is used.
4642 It is only portable to run @code{CXXCPP} on files with a @file{.c},
4643 @file{.C}, or @file{.cc} extension.
4644
4645 If the current language is C++ (@pxref{Language Choice}), many of the
4646 specific test macros use the value of @code{CXXCPP} indirectly by
4647 calling @code{AC_TRY_CPP}, @code{AC_CHECK_HEADER},
4648 @code{AC_EGREP_HEADER}, or @code{AC_EGREP_CPP}.
4649
4650 Some preprocessors don't indicate missing include files by the error
4651 status. For such preprocessors an internal variable is set that causes
4652 other macros to check the standard error from the preprocessor and
4653 consider the test failed if any warnings have been reported. However,
4654 it is not known whether such broken preprocessors exist for C++.
4655 @end defmac
4656
4657
4658
4659 @node Fortran 77 Compiler, , C++ Compiler, Compilers and Preprocessors
4660 @subsection Fortran 77 Compiler Characteristics
4661
4662 @defmac AC_PROG_F77 (@ovar{compiler-search-list})
4663 @maindex PROG_FORTRAN
4664 @ovindex F77
4665 @ovindex FFLAGS
4666 Determine a Fortran 77 compiler to use. If @code{F77} is not already
4667 set in the environment, then check for @code{g77} and @code{f77}, and
4668 then some other names. Set the output variable @code{F77} to the name
4669 of the compiler found.
4670
4671 This macro may, however, be invoked with an optional first argument
4672 which, if specified, must be a space separated list of Fortran 77
4673 compilers to search for. This just gives the user an opportunity to
4674 specify an alternative search list for the Fortran 77 compiler. For
4675 example, if you didn't like the default order, then you could invoke
4676 @code{AC_PROG_F77} like this:
4677
4678 @example
4679 AC_PROG_F77(fl32 f77 fort77 xlf cf77 g77 f90 xlf90)
4680 @end example
4681
4682 If using @code{g77} (the @sc{gnu} Fortran 77 compiler), then
4683 @code{AC_PROG_F77} will set the shell variable @code{G77} to @samp{yes}.
4684 If the output variable @code{FFLAGS} was not already set in the
4685 environment, then set it to @option{-g -02} for @code{g77} (or @option{-O2}
4686 where @code{g77} does not accept @option{-g}). Otherwise, set
4687 @code{FFLAGS} to @option{-g} for all other Fortran 77 compilers.
4688 @end defmac
4689
4690 @defmac AC_PROG_F77_C_O
4691 @maindex PROG_F77_C_O
4692 @cvindex F77_NO_MINUS_C_MINUS_O
4693 Test if the Fortran 77 compiler accepts the options @option{-c} and
4694 @option{-o} simultaneously, and define @code{F77_NO_MINUS_C_MINUS_O} if it
4695 does not.
4696 @end defmac
4697
4698
4699 The following macros check for Fortran 77 compiler characteristics. To
4700 check for characteristics not listed here, use @code{AC_TRY_COMPILE}
4701 (@pxref{Examining Syntax}) or @code{AC_TRY_RUN} (@pxref{Run Time}),
4702 making sure to first set the current language to Fortran 77
4703 @code{AC_LANG(Fortran 77)} (@pxref{Language Choice}).
4704
4705
4706 @defmac AC_F77_LIBRARY_LDFLAGS
4707 @maindex F77_LIBRARY_LDFLAGS
4708 @ovindex FLIBS
4709 Determine the linker flags (e.g. @option{-L} and @option{-l}) for the
4710 @dfn{Fortran 77 intrinsic and run-time libraries} that are required to
4711 successfully link a Fortran 77 program or shared library. The output
4712 variable @code{FLIBS} is set to these flags.
4713
4714 This macro is intended to be used in those situations when it is
4715 necessary to mix, e.g. C++ and Fortran 77 source code into a single
4716 program or shared library (@pxref{Mixing Fortran 77 With C and C++,,,
4717 automake, GNU Automake}).
4718
4719 For example, if object files from a C++ and Fortran 77 compiler must be
4720 linked together, then the C++ compiler/linker must be used for linking
4721 (since special C++-ish things need to happen at link time like calling
4722 global constructors, instantiating templates, enabling exception
4723 support, etc.).
4724
4725 However, the Fortran 77 intrinsic and run-time libraries must be linked
4726 in as well, but the C++ compiler/linker doesn't know by default how to
4727 add these Fortran 77 libraries. Hence, the macro
4728 @code{AC_F77_LIBRARY_LDFLAGS} was created to determine these Fortran 77
4729 libraries.
4730
4731 The macro @code{AC_F77_DUMMY_MAIN} or @code{AC_F77_MAIN} will probably
4732 also be necessary to link C/C++ with Fortran; see below.
4733 @end defmac
4734
4735
4736 @defmac AC_F77_DUMMY_MAIN (@ovar{action-if-found}, @ovar{action-if-not-found})
4737 @maindex F77_DUMMY_MAIN
4738 @cvindex F77_DUMMY_MAIN
4739 With many compilers, the Fortran libraries detected by
4740 @code{AC_F77_LIBRARY_LDFLAGS} provide their own @code{main} entry
4741 function that initializes things like Fortran I/O, and which then calls
4742 a user-provided entry function named e.g. @code{MAIN__} to run the
4743 user's program. The @code{AC_F77_DUMMY_MAIN} or @code{AC_F77_MAIN}
4744 macro figures out how to deal with this interaction.
4745
4746 When using Fortran for purely numerical functions (no I/O, etcetera),
4747 users often prefer to provide their own @code{main} and skip the Fortran
4748 library initializations. In this case, however, one may still need to
4749 provide a dummy @code{MAIN__} routine in order to prevent linking errors
4750 on some systems. @code{AC_F77_DUMMY_MAIN} detects whether any such
4751 routine is @emph{required} for linking, and what its name is; the shell
4752 variable @code{F77_DUMMY_MAIN} holds this name, @code{unknown} when no
4753 solution was found, and @code{none} when no such dummy main is needed.
4754
4755 By default, @var{action-if-found} defines @code{F77_DUMMY_MAIN} to the
4756 name of this routine (e.g. @code{MAIN__}) @emph{if} it is required.
4757 @ovar{action-if-not-found} defaults to exiting with an error.
4758
4759 In order to link with Fortran routines, the user's C/C++ program should
4760 then include the following code to define the dummy main if it is
4761 needed:
4762
4763 @example
4764 #ifdef F77_DUMMY_MAIN
4765 # ifdef __cplusplus
4766 extern "C"
4767 # endif
4768 int F77_DUMMY_MAIN() @{ return 1; @}
4769 #endif
4770 @end example
4771
4772 Note that @code{AC_F77_DUMMY_MAIN} is called automatically from
4773 @code{AC_F77_WRAPPERS}; there is generally no need to call it explicitly
4774 unless one wants to change the default actions.
4775 @end defmac
4776
4777 @defmac AC_F77_MAIN
4778 @maindex F77_MAIN
4779 @cvindex F77_MAIN
4780 As discussed above for @code{AC_F77_DUMMY_MAIN}, many Fortran libraries
4781 allow you to provide an entry point called e.g. @code{MAIN__} instead of
4782 the usual @code{main}, which is then called by a @code{main} function in
4783 the Fortran libraries that initializes things like Fortran I/O. The
4784 @code{AC_F77_MAIN} macro detects whether it is @emph{possible} to
4785 utilize such an alternate main function, and defines @code{F77_MAIN} to
4786 the name of the function. (If no alternate main function name is found,
4787 @code{F77_MAIN} is simply defined to @code{main}.)
4788
4789 Thus, when calling Fortran routines from C that perform things like I/O,
4790 one should use this macro and name the "main" function @code{F77_MAIN}
4791 instead of @code{main}.
4792 @end defmac
4793
4794 @defmac AC_F77_WRAPPERS
4795 @maindex F77_WRAPPERS
4796 @cvindex F77_FUNC
4797 @cvindex F77_FUNC_
4798 Defines C macros @code{F77_FUNC(name,NAME)} and
4799 @code{F77_FUNC_(name,NAME)} to properly mangle the names of C/C++
4800 identifiers, and identifiers with underscores, respectively, so that
4801 they match the name-mangling scheme used by the Fortran 77 compiler.
4802
4803 Fortran 77 is case-insensitive, and in order to achieve this the Fortran
4804 77 compiler converts all identifiers into a canonical case and format.
4805 To call a Fortran 77 subroutine from C or to write a C function that is
4806 callable from Fortran 77, the C program must explicitly use identifiers
4807 in the format expected by the Fortran 77 compiler. In order to do this,
4808 one simply wraps all C identifiers in one of the macros provided by
4809 @code{AC_F77_WRAPPERS}. For example, suppose you have the following
4810 Fortran 77 subroutine:
4811
4812 @example
4813 subroutine foobar(x,y)
4814 double precision x, y
4815 y = 3.14159 * x
4816 return
4817 end
4818 @end example
4819
4820 You would then declare its prototype in C or C++ as:
4821
4822 @example
4823 #define FOOBAR_F77 F77_FUNC(foobar,FOOBAR)
4824 #ifdef __cplusplus
4825 extern "C" /* prevent C++ name mangling */
4826 #endif
4827 void FOOBAR_F77(double *x, double *y);
4828 @end example
4829
4830 Note that we pass both the lowercase and uppercase versions of the
4831 function name to @code{F77_FUNC} so that it can select the right one.
4832 Note also that all parameters to Fortran 77 routines are passed as
4833 pointers (@pxref{Mixing Fortran 77 With C and C++,,, automake, GNU
4834 Automake}).
4835
4836 Although Autoconf tries to be intelligent about detecting the
4837 name-mangling scheme of the Fortran 77 compiler, there may be Fortran 77
4838 compilers that it doesn't support yet. In this case, the above code
4839 will generate a compile-time error, but some other behavior
4840 (e.g. disabling Fortran-related features) can be induced by checking
4841 whether the @code{F77_FUNC} macro is defined.
4842
4843 Now, to call that routine from a C program, we would do something like:
4844
4845 @example
4846 @{
4847 double x = 2.7183, y;
4848 FOOBAR_F77(&x, &y);
4849 @}
4850 @end example
4851
4852 If the Fortran 77 identifier contains an underscore
4853 (e.g. @code{foo_bar}), you should use @code{F77_FUNC_} instead of
4854 @code{F77_FUNC} (with the same arguments). This is because some Fortran
4855 77 compilers mangle names differently if they contain an underscore.
4856 @end defmac
4857
4858 @defmac AC_F77_FUNC (@var{name}, @ovar{shellvar})
4859 @maindex F77_FUNC
4860 Given an identifier @var{name}, set the shell variable @var{shellvar} to
4861 hold the mangled version @var{name} according to the rules of the
4862 Fortran 77 linker (see also @code{AC_F77_WRAPPERS}). @var{shellvar} is
4863 optional; if it is not supplied, the shell variable will be simply
4864 @var{name}. The purpose of this macro is to give the caller a way to
4865 access the name-mangling information other than through the C
4866 preprocessor as above; for example, to call Fortran routines from some
4867 language other than C/C++.
4868 @end defmac
4869
4870 @node System Services, UNIX Variants, Compilers and Preprocessors, Existing Tests
4871 @section System Services
4872
4873 The following macros check for operating system services or capabilities.
4874
4875 @defmac AC_PATH_X
4876 @maindex PATH_X
4877 Try to locate the X Window System include files and libraries. If the
4878 user gave the command line options @option{--x-includes=@var{dir}} and
4879 @option{--x-libraries=@var{dir}}, use those directories. If either or
4880 both were not given, get the missing values by running @code{xmkmf} on a
4881 trivial @file{Imakefile} and examining the @file{Makefile} that it
4882 produces. If that fails (such as if @code{xmkmf} is not present), look
4883 for them in several directories where they often reside. If either
4884 method is successful, set the shell variables @code{x_includes} and
4885 @code{x_libraries} to their locations, unless they are in directories
4886 the compiler searches by default.
4887
4888 If both methods fail, or the user gave the command line option
4889 @option{--without-x}, set the shell variable @code{no_x} to @samp{yes};
4890 otherwise set it to the empty string.
4891 @end defmac
4892
4893 @defmac AC_PATH_XTRA
4894 @maindex PATH_XTRA
4895 @ovindex X_CFLAGS
4896 @ovindex X_LIBS
4897 @ovindex X_EXTRA_LIBS
4898 @ovindex X_PRE_LIBS
4899 @cvindex X_DISPLAY_MISSING
4900 An enhanced version of @code{AC_PATH_X}. It adds the C compiler flags
4901 that X needs to output variable @code{X_CFLAGS}, and the X linker flags
4902 to @code{X_LIBS}. Define @code{X_DISPLAY_MISSING} if X is not
4903 available.
4904
4905 This macro also checks for special libraries that some systems need in
4906 order to compile X programs. It adds any that the system needs to
4907 output variable @code{X_EXTRA_LIBS}. And it checks for special X11R6
4908 libraries that need to be linked with before @option{-lX11}, and adds
4909 any found to the output variable @code{X_PRE_LIBS}.
4910
4911 @c This is an incomplete kludge. Make a real way to do it.
4912 @c If you need to check for other X functions or libraries yourself, then
4913 @c after calling this macro, add the contents of @code{X_EXTRA_LIBS} to
4914 @c @code{LIBS} temporarily, like this: (FIXME - add example)
4915 @end defmac
4916
4917 @defmac AC_SYS_INTERPRETER
4918 @maindex SYS_INTERPRETER
4919 Check whether the system supports starting scripts with a line of the
4920 form @samp{#! /bin/csh} to select the interpreter to use for the script.
4921 After running this macro, shell code in @code{configure.ac} can check
4922 the shell variable @code{interpval}; it will be set to @samp{yes}
4923 if the system supports @samp{#!}, @samp{no} if not.
4924 @end defmac
4925
4926 @defmac AC_SYS_LARGEFILE
4927 @maindex SYS_LARGEFILE
4928 @cvindex _FILE_OFFSET_BITS
4929 @cvindex _LARGE_FILES
4930 @ovindex CC
4931 Arrange for
4932 @href{http://www.sas.com/standards/large.file/x_open.20Mar96.html,
4933 large-file support}. On some hosts, one must use special compiler
4934 options to build programs that can access large files. Append any such
4935 options to the output variable @code{CC}. Define
4936 @code{_FILE_OFFSET_BITS} and @code{_LARGE_FILES} if necessary.
4937
4938 Large-file support can be disabled by configuring with the
4939 @option{--disable-largefile} option.
4940
4941 If you use this macro, check that your program works even when
4942 @code{off_t} is longer than @code{long}, since this is common when
4943 large-file support is enabled. For example, it is not correct to print
4944 an arbitrary @code{off_t} value @code{X} with @code{printf ("%ld",
4945 (long) X)}.
4946 @end defmac
4947
4948 @defmac AC_SYS_LONG_FILE_NAMES
4949 @maindex SYS_LONG_FILE_NAMES
4950 @cvindex HAVE_LONG_FILE_NAMES
4951 If the system supports file names longer than 14 characters, define
4952 @code{HAVE_LONG_FILE_NAMES}.
4953 @end defmac
4954
4955 @defmac AC_SYS_POSIX_TERMIOS
4956 @maindex SYS_POSIX_TERMIOS
4957 @cindex POSIX termios headers
4958 @cindex termios POSIX headers
4959 Check to see if POSIX termios headers and functions are available on the
4960 system. If so, set the shell variable @code{am_cv_sys_posix_termios} to
4961 @samp{yes}. If not, set the variable to @samp{no}.
4962 @end defmac
4963
4964 @node UNIX Variants, , System Services, Existing Tests
4965 @section UNIX Variants
4966
4967 The following macros check for certain operating systems that need
4968 special treatment for some programs, due to exceptional oddities in
4969 their header files or libraries. These macros are warts; they will be
4970 replaced by a more systematic approach, based on the functions they make
4971 available or the environments they provide.
4972
4973 @defmac AC_AIX
4974 @maindex AIX
4975 @cvindex _ALL_SOURCE
4976 If on AIX, define @code{_ALL_SOURCE}. Allows the use of some @sc{bsd}
4977 functions. Should be called before any macros that run the C compiler.
4978 @end defmac
4979
4980 @defmac AC_ISC_POSIX
4981 @maindex ISC_POSIX
4982 @cvindex _POSIX_SOURCE
4983 @ovindex CC
4984 If on a POSIXized ISC @sc{unix}, define @code{_POSIX_SOURCE} and add
4985 @option{-posix} (for the @sc{gnu} C compiler) or @option{-Xp} (for other C
4986 compilers) to output variable @code{CC}. This allows the use of
4987 @sc{posix} facilities. Must be called after @code{AC_PROG_CC} and
4988 before any other macros that run the C compiler.
4989 @end defmac
4990
4991 @defmac AC_MINIX
4992 @maindex MINIX
4993 @cvindex _MINIX
4994 @cvindex _POSIX_SOURCE
4995 @cvindex _POSIX_1_SOURCE
4996 If on Minix, define @code{_MINIX} and @code{_POSIX_SOURCE} and define
4997 @code{_POSIX_1_SOURCE} to be 2. This allows the use of @sc{posix}
4998 facilities. Should be called before any macros that run the C compiler.
4999 @end defmac
5000
5001
5002
5003
5004 @c ========================================================= Writing Tests
5005
5006 @node Writing Tests, Results, Existing Tests, Top
5007 @chapter Writing Tests
5008
5009 If the existing feature tests don't do something you need, you have to
5010 write new ones. These macros are the building blocks. They provide
5011 ways for other macros to check whether various kinds of features are
5012 available and report the results.
5013
5014 This chapter contains some suggestions and some of the reasons why the
5015 existing tests are written the way they are. You can also learn a lot
5016 about how to write Autoconf tests by looking at the existing ones. If
5017 something goes wrong in one or more of the Autoconf tests, this
5018 information can help you understand the assumptions behind them, which
5019 might help you figure out how to best solve the problem.
5020
5021 These macros check the output of the C compiler system. They do
5022 not cache the results of their tests for future use (@pxref{Caching
5023 Results}), because they don't know enough about the information they are
5024 checking for to generate a cache variable name. They also do not print
5025 any messages, for the same reason. The checks for particular kinds of C
5026 features call these macros and do cache their results and print messages
5027 about what they're checking for.
5028
5029 When you write a feature test that could be applicable to more than one
5030 software package, the best thing to do is encapsulate it in a new macro.
5031 @xref{Writing Autoconf Macros}, for how to do that.
5032
5033 @menu
5034 * Examining Declarations:: Detecting header files and declarations
5035 * Examining Syntax:: Detecting language syntax features
5036 * Examining Libraries:: Detecting functions and global variables
5037 * Run Time:: Testing for run-time features
5038 * Systemology:: A zoology of operating systems
5039 * Multiple Cases:: Tests for several possible values
5040 * Language Choice:: Selecting which language to use for testing
5041 @end menu
5042
5043 @node Examining Declarations, Examining Syntax, Writing Tests, Writing Tests
5044 @section Examining Declarations
5045
5046 The macro @code{AC_TRY_CPP} is used to check whether particular header
5047 files exist. You can check for one at a time, or more than one if you
5048 need several header files to all exist for some purpose.
5049
5050 @defmac AC_TRY_CPP (@var{includes}, @ovar{action-if-true}, @ovar{action-if-false})
5051 @maindex TRY_CPP
5052 @var{includes} is C or C++ @code{#include} statements and declarations,
5053 on which shell variable, back quote, and backslash substitutions are
5054 performed. (Actually, it can be any C program, but other statements are
5055 probably not useful.) If the preprocessor produces no error messages
5056 while processing it, run shell commands @var{action-if-true}. Otherwise
5057 run shell commands @var{action-if-false}.
5058
5059 This macro uses @code{CPPFLAGS}, but not @code{CFLAGS}, because
5060 @option{-g}, @option{-O}, etc. are not valid options to many C
5061 preprocessors.
5062 @end defmac
5063
5064 Here is how to find out whether a header file contains a particular
5065 declaration, such as a typedef, a structure, a structure member, or a
5066 function. Use @code{AC_EGREP_HEADER} instead of running @code{grep}
5067 directly on the header file; on some systems the symbol might be defined
5068 in another header file that the file you are checking @samp{#include}s.
5069
5070 @defmac AC_EGREP_HEADER (@var{pattern}, @var{header-file}, @var{action-if-found}, @ovar{action-if-not-found})
5071 @maindex EGREP_HEADER
5072 If the output of running the preprocessor on the system header file
5073 @var{header-file} matches the @code{egrep} regular expression
5074 @var{pattern}, execute shell commands @var{action-if-found}, otherwise
5075 execute @var{action-if-not-found}.
5076 @end defmac
5077
5078 To check for C preprocessor symbols, either defined by header files or
5079 predefined by the C preprocessor, use @code{AC_EGREP_CPP}. Here is an
5080 example of the latter:
5081
5082 @example
5083 AC_EGREP_CPP(yes,
5084 [#ifdef _AIX
5085 yes
5086 #endif
5087 ], is_aix=yes, is_aix=no)
5088 @end example
5089
5090 @defmac AC_EGREP_CPP (@var{pattern}, @var{program}, @ovar{action-if-found}, @ovar{action-if-not-found})
5091 @maindex EGREP_CPP
5092 @var{program} is the text of a C or C++ program, on which shell
5093 variable, back quote, and backslash substitutions are performed. If the
5094 output of running the preprocessor on @var{program} matches the
5095 @code{egrep} regular expression @var{pattern}, execute shell commands
5096 @var{action-if-found}, otherwise execute @var{action-if-not-found}.
5097
5098 This macro calls @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP} (depending
5099 on which language is current, @pxref{Language Choice}), if it hasn't
5100 been called already.
5101 @end defmac
5102
5103 @node Examining Syntax, Examining Libraries, Examining Declarations, Writing Tests
5104 @section Examining Syntax
5105
5106 To check for a syntax feature of the C, C++ or Fortran 77 compiler, such
5107 as whether it recognizes a certain keyword, use @code{AC_TRY_COMPILE} to
5108 try to compile a small program that uses that feature. You can also use
5109 it to check for structures and structure members that are not present on
5110 all systems.
5111
5112 @defmac AC_TRY_COMPILE (@var{includes}, @var{function-body}, @ovar{action-if-found}, @ovar{action-if-not-found})
5113 @maindex TRY_COMPILE
5114 Create a C, C++ or Fortran 77 test program (depending on which language
5115 is current, @pxref{Language Choice}), to see whether a function whose
5116 body consists of @var{function-body} can be compiled.
5117
5118 For C and C++, @var{includes} is any @code{#include} statements needed
5119 by the code in @var{function-body} (@var{includes} will be ignored if
5120 the currently selected language is Fortran 77). This macro also uses
5121 @code{CFLAGS} or @code{CXXFLAGS} if either C or C++ is the currently
5122 selected language, as well as @code{CPPFLAGS}, when compiling. If
5123 Fortran 77 is the currently selected language then @code{FFLAGS} will be
5124 used when compiling.
5125
5126 If the file compiles successfully, run shell commands
5127 @var{action-if-found}, otherwise run @var{action-if-not-found}.
5128
5129 This macro does not try to link; use @code{AC_TRY_LINK} if you need to
5130 do that (@pxref{Examining Libraries}).
5131 @end defmac
5132
5133 @node Examining Libraries, Run Time, Examining Syntax, Writing Tests
5134 @section Examining Libraries
5135
5136 To check for a library, a function, or a global variable, Autoconf
5137 @code{configure} scripts try to compile and link a small program that
5138 uses it. This is unlike Metaconfig, which by default uses @code{nm}
5139 or @code{ar} on the C library to try to figure out which functions are
5140 available. Trying to link with the function is usually a more reliable
5141 approach because it avoids dealing with the variations in the options
5142 and output formats of @code{nm} and @code{ar} and in the location of the
5143 standard libraries. It also allows configuring for cross-compilation or
5144 checking a function's runtime behavior if needed. On the other hand, it
5145 can be slower than scanning the libraries once.
5146
5147 A few systems have linkers that do not return a failure exit status when
5148 there are unresolved functions in the link. This bug makes the
5149 configuration scripts produced by Autoconf unusable on those systems.
5150 However, some of them can be given options that make the exit status
5151 correct. This is a problem that Autoconf does not currently handle
5152 automatically. If users encounter this problem, they might be able to
5153 solve it by setting @code{LDFLAGS} in the environment to pass whatever
5154 options the linker needs (for example, @option{-Wl,-dn} on @sc{mips
5155 risc/os}).
5156
5157 @code{AC_TRY_LINK} is used to compile test programs to test for
5158 functions and global variables. It is also used by @code{AC_CHECK_LIB}
5159 to check for libraries (@pxref{Libraries}), by adding the library being
5160 checked for to @code{LIBS} temporarily and trying to link a small
5161 program.
5162
5163 @defmac AC_TRY_LINK (@var{includes}, @var{function-body}, @ovar{action-if-found}, @ovar{action-if-not-found})
5164 @maindex TRY_LINK
5165 Depending on the current language (@pxref{Language Choice}), create a
5166 test program to see whether a function whose body consists of
5167 @var{function-body} can be compiled and linked.
5168
5169 For C and C++, @var{includes} is any @code{#include} statements needed
5170 by the code in @var{function-body} (@var{includes} will be ignored if
5171 the currently selected language is Fortran 77). This macro also uses
5172 @code{CFLAGS} or @code{CXXFLAGS} if either C or C++ is the currently
5173 selected language, as well as @code{CPPFLAGS}, when compiling. If
5174 Fortran 77 is the currently selected language then @code{FFLAGS} will be
5175 used when compiling. However, both @code{LDFLAGS} and @code{LIBS} will
5176 be used during linking in all cases.
5177
5178 If the file compiles and links successfully, run shell commands
5179 @var{action-if-found}, otherwise run @var{action-if-not-found}.
5180 @end defmac
5181
5182 @defmac AC_TRY_LINK_FUNC (@var{function}, @ovar{action-if-found}, @ovar{action-if-not-found})
5183 @maindex TRY_LINK_FUNC
5184 Depending on the current language (@pxref{Language Choice}), create a
5185 test program to see whether a program whose body consists of
5186 a prototype of and a call to @var{function} can be compiled and linked.
5187
5188 If the file compiles and links successfully, run shell commands
5189 @var{action-if-found}, otherwise run @var{action-if-not-found}.
5190 @end defmac
5191
5192
5193
5194 @node Run Time, Systemology, Examining Libraries, Writing Tests
5195 @section Checking Run Time Behavior
5196
5197 Sometimes you need to find out how a system performs at run time, such
5198 as whether a given function has a certain capability or bug. If you
5199 can, make such checks when your program runs instead of when it is
5200 configured. You can check for things like the machine's endianness when
5201 your program initializes itself.
5202
5203 If you really need to test for a run-time behavior while configuring,
5204 you can write a test program to determine the result, and compile and
5205 run it using @code{AC_TRY_RUN}. Avoid running test programs if
5206 possible, because this prevents people from configuring your package for
5207 cross-compiling.
5208
5209 @menu
5210 * Test Programs:: Running test programs
5211 * Guidelines:: General rules for writing test programs
5212 * Test Functions:: Avoiding pitfalls in test programs
5213 @end menu
5214
5215 @node Test Programs, Guidelines, Run Time, Run Time
5216 @subsection Running Test Programs
5217
5218 Use the following macro if you need to test run-time behavior of the
5219 system while configuring.
5220
5221 @defmac AC_TRY_RUN (@var{program}, @ovar{action-if-true}, @ovar{action-if-false}, @ovar{action-if-cross-compiling})
5222 @maindex TRY_RUN
5223 @var{program} is the text of a C program, on which shell variable and
5224 back quote substitutions are performed. If it compiles and links
5225 successfully and returns an exit status of 0 when executed, run shell
5226 commands @var{action-if-true}. Otherwise, run shell commands
5227 @var{action-if-false}; the exit status of the program is available in
5228 the shell variable @samp{$?}. This macro uses @code{CFLAGS} or
5229 @code{CXXFLAGS}, @code{CPPFLAGS}, @code{LDFLAGS}, and @code{LIBS} when
5230 compiling.
5231
5232 If the C compiler being used does not produce executables that run on
5233 the system where @code{configure} is being run, then the test program is
5234 not run. If the optional shell commands @var{action-if-cross-compiling}
5235 are given, they are run instead. Otherwise, @code{configure} prints
5236 an error message and exits.
5237 @end defmac
5238
5239 Try to provide a pessimistic default value to use when cross-compiling
5240 makes run-time tests impossible. You do this by passing the optional
5241 last argument to @code{AC_TRY_RUN}. @code{autoconf} prints a warning
5242 message when creating @code{configure} each time it encounters a call to
5243 @code{AC_TRY_RUN} with no @var{action-if-cross-compiling} argument
5244 given. You may ignore the warning, though users will not be able to
5245 configure your package for cross-compiling. A few of the macros
5246 distributed with Autoconf produce this warning message.
5247
5248 To configure for cross-compiling you can also choose a value for those
5249 parameters based on the canonical system name (@pxref{Manual
5250 Configuration}). Alternatively, set up a test results cache file with
5251 the correct values for the host system (@pxref{Caching Results}).
5252
5253 To provide a default for calls of @code{AC_TRY_RUN} that are embedded in
5254 other macros, including a few of the ones that come with Autoconf, you
5255 can call @code{AC_PROG_CC} before running them. Then, if the shell
5256 variable @code{cross_compiling} is set to @samp{yes}, use an alternate
5257 method to get the results instead of calling the macros.
5258
5259
5260 @node Guidelines, Test Functions, Test Programs, Run Time
5261 @subsection Guidelines for Test Programs
5262
5263 Test programs should not write anything to the standard output. They
5264 should return 0 if the test succeeds, nonzero otherwise, so that success
5265 can be distinguished easily from a core dump or other failure;
5266 segmentation violations and other failures produce a nonzero exit
5267 status. Test programs should @code{exit}, not @code{return}, from
5268 @code{main}, because on some systems (old Suns, at least) the argument
5269 to @code{return} in @code{main} is ignored.
5270
5271 Test programs can use @code{#if} or @code{#ifdef} to check the values of
5272 preprocessor macros defined by tests that have already run. For
5273 example, if you call @code{AC_HEADER_STDC}, then later on in
5274 @file{configure.ac} you can have a test program that includes an
5275 @sc{ansi} C header file conditionally:
5276
5277 @example
5278 @group
5279 #if STDC_HEADERS
5280 # include <stdlib.h>
5281 #endif
5282 @end group
5283 @end example
5284
5285 If a test program needs to use or create a data file, give it a name
5286 that starts with @file{conftest}, such as @file{conftest.data}. The
5287 @code{configure} script cleans up by running @samp{rm -rf conftest*}
5288 after running test programs and if the script is interrupted.
5289
5290 @node Test Functions, , Guidelines, Run Time
5291 @subsection Test Functions
5292
5293 Function declarations in test programs should have a prototype
5294 conditionalized for C++. In practice, though, test programs rarely need
5295 functions that take arguments.
5296
5297 @example
5298 #ifdef __cplusplus
5299 foo (int i)
5300 #else
5301 foo (i) int i;
5302 #endif
5303 @end example
5304
5305 Functions that test programs declare should also be conditionalized for
5306 C++, which requires @samp{extern "C"} prototypes. Make sure to not
5307 include any header files containing clashing prototypes.
5308
5309 @example
5310 #ifdef __cplusplus
5311 extern "C" void *malloc (size_t);
5312 #else
5313 char *malloc ();
5314 #endif
5315 @end example
5316
5317 If a test program calls a function with invalid parameters (just to see
5318 whether it exists), organize the program to ensure that it never invokes
5319 that function. You can do this by calling it in another function that is
5320 never invoked. You can't do it by putting it after a call to
5321 @code{exit}, because GCC version 2 knows that @code{exit} never returns
5322 and optimizes out any code that follows it in the same block.
5323
5324 If you include any header files, make sure to call the functions
5325 relevant to them with the correct number of arguments, even if they are
5326 just 0, to avoid compilation errors due to prototypes. GCC version 2
5327 has internal prototypes for several functions that it automatically
5328 inlines; for example, @code{memcpy}. To avoid errors when checking for
5329 them, either pass them the correct number of arguments or redeclare them
5330 with a different return type (such as @code{char}).
5331
5332 @node Systemology, Multiple Cases, Run Time, Writing Tests
5333 @section Systemology
5334
5335 This section aims at presenting some systems and pointers to
5336 documentation. It may help you addressing particular problems reported
5337 by users.
5338
5339 @table @asis
5340 @item @sc{qnx 4.25}
5341 @cindex @sc{qnx 4.25}
5342 @c FIXME: Please, if you feel like writing something more precise,
5343 @c it'd be great. In particular, I can't understand the difference with
5344 @c QNX Neutrino.
5345 @sc{qnx} is a realtime operating system running on Intel architecture
5346 meant to be scalable from the small embedded systems to hundred
5347 processor super-computer. It claims to be @sc{posix} certified. More
5348 information is available on the @href{www.qnx.com, @sc{qnx} home page},
5349 including the @href{http://support.qnx.com/support/docs/qnx4/, @sc{qnx}
5350 man pages}.
5351 @end table
5352
5353
5354 @node Multiple Cases, Language Choice, Systemology, Writing Tests
5355 @section Multiple Cases
5356
5357 Some operations are accomplished in several possible ways, depending on
5358 the @sc{unix} variant. Checking for them essentially requires a ``case
5359 statement''. Autoconf does not directly provide one; however, it is
5360 easy to simulate by using a shell variable to keep track of whether a
5361 way to perform the operation has been found yet.
5362
5363 Here is an example that uses the shell variable @code{fstype} to keep
5364 track of whether the remaining cases need to be checked.
5365
5366 @example
5367 @group
5368 AC_MSG_CHECKING([how to get file system type])
5369 fstype=no
5370 # The order of these tests is important.
5371 AC_TRY_CPP([#include <sys/statvfs.h>
5372 #include <sys/fstyp.h>],
5373 [AC_DEFINE(FSTYPE_STATVFS) fstype=SVR4])
5374 if test $fstype = no; then
5375 AC_TRY_CPP([#include <sys/statfs.h>
5376 #include <sys/fstyp.h>],
5377 [AC_DEFINE(FSTYPE_USG_STATFS) fstype=SVR3])
5378 fi
5379 if test $fstype = no; then
5380 AC_TRY_CPP([#include <sys/statfs.h>
5381 #include <sys/vmount.h>],
5382 [AC_DEFINE(FSTYPE_AIX_STATFS) fstype=AIX])
5383 fi
5384 # (more cases omitted here)
5385 AC_MSG_RESULT([$fstype])
5386 @end group
5387 @end example
5388
5389 @node Language Choice, , Multiple Cases, Writing Tests
5390 @section Language Choice
5391 @cindex Language
5392
5393 Autoconf-generated @code{configure} scripts check for the C compiler and
5394 its features by default. Packages that use other programming languages
5395 (maybe more than one, e.g. C and C++) need to test features of the
5396 compilers for the respective languages. The following macros determine
5397 which programming language is used in the subsequent tests in
5398 @file{configure.ac}.
5399
5400 @defmac AC_LANG (@var{language})
5401 Do compilation tests using the compiler, preprocessor and file
5402 extensions for the specified @var{language}.
5403
5404 Supported languages are:
5405
5406 @table @samp
5407 @item C
5408 Do compilation tests using @code{CC} and @code{CPP} and use extension
5409 @file{.c} for test programs.
5410
5411 @item C++
5412 Do compilation tests using @code{CXX} and @code{CXXCPP} and use
5413 extension @file{.C} for test programs.
5414
5415 @item Fortran 77
5416 Do compilation tests using @code{F77} and use extension @file{.f} for
5417 test programs.
5418 @end table
5419 @end defmac
5420
5421 @defmac AC_LANG_PUSH (@var{language})
5422 @maindex LANG_PUSH
5423 Remember the current language (as set by @code{AC_LANG}) on a stack, and
5424 then select the @var{language}. Use this macro and @code{AC_LANG_POP}
5425 in macros that need to temporarily switch to a particular language.
5426 @end defmac
5427
5428 @defmac AC_LANG_POP (@ovar{language})
5429 @maindex LANG_POP
5430 Select the language that is saved on the top of the stack, as set by
5431 @code{AC_LANG_PUSH}, and remove it from the stack.
5432
5433 If given, @var{language} specifies the language we just @emph{quit}. It
5434 is a good idea to specify it when it's known (which should be the
5435 case@dots{}), since Autoconf will detect inconsistencies.
5436
5437 @example
5438 AC_LANG_PUSH(Fortran 77)
5439 # Perform some tests on Fortran 77.
5440 # ...
5441 AC_LANG_POP(Fortran 77)
5442 @end example
5443 @end defmac
5444
5445 @defmac AC_REQUIRE_CPP
5446 @maindex REQUIRE_CPP
5447 Ensure that whichever preprocessor would currently be used for tests has
5448 been found. Calls @code{AC_REQUIRE} (@pxref{Prerequisite Macros}) with an
5449 argument of either @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP},
5450 depending on which language is current.
5451 @end defmac
5452
5453
5454
5455 @c ====================================================== Results of Tests.
5456
5457 @node Results, Programming in M4, Writing Tests, Top
5458 @chapter Results of Tests
5459
5460 Once @code{configure} has determined whether a feature exists, what can
5461 it do to record that information? There are four sorts of things it can
5462 do: define a C preprocessor symbol, set a variable in the output files,
5463 save the result in a cache file for future @code{configure} runs, and
5464 print a message letting the user know the result of the test.
5465
5466 @menu
5467 * Defining Symbols:: Defining C preprocessor symbols
5468 * Setting Output Variables:: Replacing variables in output files
5469 * Caching Results:: Speeding up subsequent @code{configure} runs
5470 * Printing Messages:: Notifying @code{configure} users
5471 @end menu
5472
5473 @node Defining Symbols, Setting Output Variables, Results, Results
5474 @section Defining C Preprocessor Symbols
5475
5476 A common action to take in response to a feature test is to define a C
5477 preprocessor symbol indicating the results of the test. That is done by
5478 calling @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}.
5479
5480 By default, @code{AC_OUTPUT} places the symbols defined by these macros
5481 into the output variable @code{DEFS}, which contains an option
5482 @option{-D@var{symbol}=@var{value}} for each symbol defined. Unlike in
5483 Autoconf version 1, there is no variable @code{DEFS} defined while
5484 @code{configure} is running. To check whether Autoconf macros have
5485 already defined a certain C preprocessor symbol, test the value of the
5486 appropriate cache variable, as in this example:
5487
5488 @example
5489 AC_CHECK_FUNC(vprintf, [AC_DEFINE(HAVE_VPRINTF)])
5490 if test "$ac_cv_func_vprintf" != yes; then
5491 AC_CHECK_FUNC(_doprnt, [AC_DEFINE(HAVE_DOPRNT)])
5492 fi
5493 @end example
5494
5495 If @code{AC_CONFIG_HEADERS} has been called, then instead of creating
5496 @code{DEFS}, @code{AC_OUTPUT} creates a header file by substituting the
5497 correct values into @code{#define} statements in a template file.
5498 @xref{Configuration Headers}, for more information about this kind of
5499 output.
5500
5501 @defmac AC_DEFINE (@var{variable}, @ovar{value}, @ovar{description})
5502 @maindex DEFINE
5503 Define C preprocessor variable @var{variable}. If @var{value} is given,
5504 set @var{variable} to that value (verbatim), otherwise set it to 1.
5505 @var{value} should not contain literal newlines, and if you are not
5506 using @code{AC_CONFIG_HEADERS} it should not contain any @samp{#}
5507 characters, as @code{make} tends to eat them. To use a shell variable
5508 (which you need to do in order to define a value containing the M4 quote
5509 characters @samp{[} or @samp{]}), use @code{AC_DEFINE_UNQUOTED} instead.
5510 @var{description} is only useful if you are using
5511 @code{AC_CONFIG_HEADERS}. In this case, @var{description} is put into
5512 the generated @file{config.h.in} as the comment before the macro define.
5513 The following example defines the C preprocessor variable
5514 @code{EQUATION} to be the string constant @samp{"$a > $b"}:
5515
5516 @example
5517 AC_DEFINE(EQUATION, "$a > $b")
5518 @end example
5519 @end defmac
5520
5521 @defmac AC_DEFINE_UNQUOTED (@var{variable}, @ovar{value}, @ovar{description})
5522 @maindex DEFINE_UNQUOTED
5523 Like @code{AC_DEFINE}, but three shell expansions are
5524 performed---once---on @var{variable} and @var{value}: variable expansion
5525 (@samp{$}), command substitution (@samp{`}), and backslash escaping
5526 (@samp{\}). Single and double quote characters in the value have no
5527 special meaning. Use this macro instead of @code{AC_DEFINE} when
5528 @var{variable} or @var{value} is a shell variable. Examples:
5529
5530 @example
5531 AC_DEFINE_UNQUOTED(config_machfile, "$machfile")
5532 AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups)
5533 AC_DEFINE_UNQUOTED($ac_tr_hdr)
5534 @end example
5535 @end defmac
5536
5537 Due to the syntactical bizarreness of the Bourne shell, do not use
5538 semicolons to separate @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}
5539 calls from other macro calls or shell code; that can cause syntax errors
5540 in the resulting @code{configure} script. Use either spaces or
5541 newlines. That is, do this:
5542
5543 @example
5544 AC_CHECK_HEADER(elf.h, [AC_DEFINE(SVR4) LIBS="$LIBS -lelf"])
5545 @end example
5546
5547 @noindent
5548 or this:
5549
5550 @example
5551 AC_CHECK_HEADER(elf.h,
5552 [AC_DEFINE(SVR4)
5553 LIBS="$LIBS -lelf"])
5554 @end example
5555
5556 @noindent
5557 instead of this:
5558
5559 @example
5560 AC_CHECK_HEADER(elf.h, [AC_DEFINE(SVR4); LIBS="$LIBS -lelf"])
5561 @end example
5562
5563 @node Setting Output Variables, Caching Results, Defining Symbols, Results
5564 @section Setting Output Variables
5565
5566 Another way to record the results of tests is to set @dfn{output
5567 variables}, which are shell variables whose values are substituted into
5568 files that @code{configure} outputs. The two macros below create new
5569 output variables. @xref{Preset Output Variables}, for a list of output
5570 variables that are always available.
5571
5572 @defmac AC_SUBST (@var{variable}, @ovar{value})
5573 @maindex SUBST
5574 Create an output variable from a shell variable. Make @code{AC_OUTPUT}
5575 substitute the variable @var{variable} into output files (typically one
5576 or more @file{Makefile}s). This means that @code{AC_OUTPUT} will
5577 replace instances of @samp{@@@var{variable}@@} in input files with the
5578 value that the shell variable @var{variable} has when @code{AC_OUTPUT}
5579 is called. This value of @var{variable} should not contain literal
5580 newlines.
5581
5582 If @var{value} is given, in addition assign it to @samp{variable}.
5583 @end defmac
5584
5585 @defmac AC_SUBST_FILE (@var{variable})
5586 @maindex SUBST_FILE
5587 Another way to create an output variable from a shell variable. Make
5588 @code{AC_OUTPUT} insert (without substitutions) the contents of the file
5589 named by shell variable @var{variable} into output files. This means
5590 that @code{AC_OUTPUT} will replace instances of
5591 @samp{@@@var{variable}@@} in output files (such as @file{Makefile.in})
5592 with the contents of the file that the shell variable @var{variable}
5593 names when @code{AC_OUTPUT} is called. Set the variable to
5594 @file{/dev/null} for cases that do not have a file to insert.
5595
5596 This macro is useful for inserting @file{Makefile} fragments containing
5597 special dependencies or other @code{make} directives for particular host
5598 or target types into @file{Makefile}s. For example, @file{configure.ac}
5599 could contain:
5600
5601 @example
5602 AC_SUBST_FILE(host_frag)
5603 host_frag=$srcdir/conf/sun4.mh
5604 @end example
5605
5606 @noindent
5607 and then a @file{Makefile.in} could contain:
5608
5609 @example
5610 @@host_frag@@
5611 @end example
5612 @end defmac
5613
5614 @cindex Previous Variable
5615 @cindex Variable, Precious
5616 Running @command{configure} in different environments can be extremely
5617 dangerous. If for instance the user runs @samp{CC=bizarre-cc
5618 ./configure}, then the cache, @file{config.h} and many other output
5619 files will depend upon @command{bizarre-cc} being the C compiler. If
5620 for some reason the user runs @command{/configure} again, or if it is
5621 run via @samp{./config.status --recheck}, (@xref{Automatic Remaking},
5622 and @pxref{config.status Invocation}), then the configuration can be
5623 inconsistent, composed of results depending upon two different
5624 compilers.
5625
5626 Such variables are named @dfn{precious variables}, and can be declared
5627 as such by @code{AC_ARG_VAR}.
5628
5629 @defmac AC_ARG_VAR (@var{variable}, @var{description})
5630 @maindex ARG_VAR
5631 Declare @var{variable} is a precious variable, and include its
5632 @var{description} in the variable section of @samp{./configure --help}.
5633
5634 Being precious means that
5635 @itemize @minus
5636 @item
5637 @var{variable} is @code{AC_SUBST}'d.
5638
5639 @item
5640 @var{variable} is kept in the cache including if it was not specified on
5641 the @samp{./configure} command line. Indeed, while @command{configure}
5642 can notice the definition of @code{CC} in @samp{./configure
5643 CC=bizarre-cc}, it is impossible to notice it in @samp{CC=bizarre-cc
5644 ./configure}, which, unfortunately, is what most users do.
5645
5646 @item
5647 @var{variable} is checked for consistency between two
5648 @command{configure} runs. For instance:
5649
5650 @example
5651 $ ./configure --silent --config-cache
5652 $ CC=cc ./configure --silent --config-cache
5653 configure: error: `CC' was not set in the previous run
5654 configure: error: changes in the environment can compromise \
5655 the build
5656 configure: error: run `make distclean' and/or \
5657 `rm config.cache' and start over
5658 @end example
5659
5660 @noindent
5661 and similarly if the variable is unset, or if its content is changed.
5662
5663
5664 @item
5665 @var{variable} is kept during automatic reconfiguration
5666 (@pxref{config.status Invocation}) as if it had been passed as a command
5667 line argument, including when no cache is used:
5668
5669 @example
5670 $ CC=/usr/bin/cc ./configure undeclared_var=raboof --silent
5671 $ ./config.status --recheck
5672 running /bin/sh ./configure undeclared_var=raboof --silent \
5673 CC=/usr/bin/cc --no-create --no-recursion
5674 @end example
5675 @end itemize
5676 @end defmac
5677
5678
5679 @node Caching Results, Printing Messages, Setting Output Variables, Results
5680 @section Caching Results
5681 @cindex Cache
5682
5683 To avoid checking for the same features repeatedly in various
5684 @code{configure} scripts (or in repeated runs of one script),
5685 @code{configure} can optionally save the results of many checks in a
5686 @dfn{cache file} (@pxref{Cache Files}). If a @code{configure} script
5687 runs with caching enabled and finds a cache file, it reads the results
5688 of previous runs from the cache and avoids rerunning those checks. As a
5689 result, @code{configure} can then run much faster than if it had to
5690 perform all of the checks every time.
5691
5692 @defmac AC_CACHE_VAL (@var{cache-id}, @var{commands-to-set-it})
5693 @maindex CACHE_VAL
5694 Ensure that the results of the check identified by @var{cache-id} are
5695 available. If the results of the check were in the cache file that was
5696 read, and @code{configure} was not given the @option{--quiet} or
5697 @option{--silent} option, print a message saying that the result was
5698 cached; otherwise, run the shell commands @var{commands-to-set-it}. If
5699 the shell commands are run to determine the value, the value will be
5700 saved in the cache file just before @code{configure} creates its output
5701 files. @xref{Cache Variable Names}, for how to choose the name of the
5702 @var{cache-id} variable.
5703
5704 The @var{commands-to-set-it} @emph{must have no side effects} except for
5705 setting the variable @var{cache-id}, see below.
5706 @end defmac
5707
5708 @defmac AC_CACHE_CHECK (@var{message}, @var{cache-id}, @var{commands-to-set-it})
5709 @maindex CACHE_CHECK
5710 A wrapper for @code{AC_CACHE_VAL} that takes care of printing the
5711 messages. This macro provides a convenient shorthand for the most
5712 common way to use these macros. It calls @code{AC_MSG_CHECKING} for
5713 @var{message}, then @code{AC_CACHE_VAL} with the @var{cache-id} and
5714 @var{commands} arguments, and @code{AC_MSG_RESULT} with @var{cache-id}.
5715
5716 The @var{commands-to-set-it} @emph{must have no side effects} except for
5717 setting the variable @var{cache-id}, see below.
5718 @end defmac
5719
5720 It is very common to find buggy macros using @code{AC_CACHE_VAL} or
5721 @code{AC_CACHE_CHECK}, because people are tempted to call
5722 @code{AC_DEFINE} in the @var{commands-to-set-it}. Instead, the code that
5723 @emph{follows} the call to @code{AC_CACHE_VAL} should call
5724 @code{AC_DEFINE}, by examining the value of the cache variable. For
5725 instance, the following macro is broken:
5726
5727 @example
5728 @group
5729 AC_DEFUN([AC_SHELL_TRUE],
5730 [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
5731 [ac_cv_shell_true_works=no
5732 true && ac_cv_shell_true_works=yes
5733 if test $ac_cv_shell_true_works = yes; then
5734 AC_DEFINE([TRUE_WORKS], 1
5735 [Define if `true(1)' works properly.])
5736 fi])
5737 ])
5738 @end group
5739 @end example
5740
5741 @noindent
5742 This fails if the cache is enabled: the second time this macro is run,
5743 @code{TRUE_WORKS} @emph{will not be defined}. The proper implementation
5744 is:
5745
5746 @example
5747 @group
5748 AC_DEFUN([AC_SHELL_TRUE],
5749 [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
5750 [ac_cv_shell_true_works=no
5751 true && ac_cv_shell_true_works=yes])
5752 if test $ac_cv_shell_true_works = yes; then
5753 AC_DEFINE([TRUE_WORKS], 1
5754 [Define if `true(1)' works properly.])
5755 fi
5756 ])
5757 @end group
5758 @end example
5759
5760 Also, @var{commands-to-set-it} should not print any messages, for
5761 example with @code{AC_MSG_CHECKING}; do that before calling
5762 @code{AC_CACHE_VAL}, so the messages are printed regardless of whether
5763 the results of the check are retrieved from the cache or determined by
5764 running the shell commands.
5765
5766 @menu
5767 * Cache Variable Names:: Shell variables used in caches
5768 * Cache Files:: Files @code{configure} uses for caching
5769 * Cache Checkpointing:: Loading and saving the cache file
5770 @end menu
5771
5772 @node Cache Variable Names, Cache Files, Caching Results, Caching Results
5773 @subsection Cache Variable Names
5774 @cindex Cache variable
5775
5776 The names of cache variables should have the following format:
5777
5778 @example
5779 @var{package-prefix}_cv_@var{value-type}_@var{specific-value}_@ovar{additional-options}
5780 @end example
5781
5782 @noindent
5783 for example, @samp{ac_cv_header_stat_broken} or
5784 @samp{ac_cv_prog_gcc_traditional}. The parts of the variable name are:
5785
5786 @table @asis
5787 @item @var{package-prefix}
5788 An abbreviation for your package or organization; the same prefix you
5789 begin local Autoconf macros with, except lowercase by convention.
5790 For cache values used by the distributed Autoconf macros, this value is
5791 @samp{ac}.
5792
5793 @item @code{_cv_}
5794 Indicates that this shell variable is a cache value. This string
5795 @emph{must} be present in the variable name, including the leading
5796 underscore.
5797
5798 @item @var{value-type}
5799 A convention for classifying cache values, to produce a rational naming
5800 system. The values used in Autoconf are listed in @ref{Macro Names}.
5801
5802 @item @var{specific-value}
5803 Which member of the class of cache values this test applies to.
5804 For example, which function (@samp{alloca}), program (@samp{gcc}), or
5805 output variable (@samp{INSTALL}).
5806
5807 @item @var{additional-options}
5808 Any particular behavior of the specific member that this test applies to.
5809 For example, @samp{broken} or @samp{set}. This part of the name may
5810 be omitted if it does not apply.
5811 @end table
5812
5813 The values assigned to cache variables may not contain newlines.
5814 Usually, their values will be boolean (@samp{yes} or @samp{no}) or the
5815 names of files or functions; so this is not an important restriction.
5816
5817 @node Cache Files, Cache Checkpointing, Cache Variable Names, Caching Results
5818 @subsection Cache Files
5819
5820 A cache file is a shell script that caches the results of configure
5821 tests run on one system so they can be shared between configure scripts
5822 and configure runs. It is not useful on other systems. If its contents
5823 are invalid for some reason, the user may delete or edit it.
5824
5825 By default, @code{configure} uses no cache file (technically, it uses
5826 @option{--cache-file=/dev/null}), to avoid problems caused by accidental
5827 use of stale cache files.
5828
5829 To enable caching, @code{configure} accepts @option{--config-cache} (or
5830 @option{-C}) to cache results in the file @file{config.cache}.
5831 Alternatively, @option{--cache-file=@var{file}} specifies that
5832 @var{file} be the cache file. The cache file is created if it does not
5833 exist already. When @code{configure} calls @code{configure} scripts in
5834 subdirectories, it uses the @option{--cache-file} argument so that they
5835 share the same cache. @xref{Subdirectories}, for information on
5836 configuring subdirectories with the @code{AC_CONFIG_SUBDIRS} macro.
5837
5838 @file{config.status} only pays attention to the cache file if it is
5839 given the @option{--recheck} option, which makes it rerun
5840 @code{configure}.
5841
5842 It is wrong to try to distribute cache files for particular system types.
5843 There is too much room for error in doing that, and too much
5844 administrative overhead in maintaining them. For any features that
5845 can't be guessed automatically, use the standard method of the canonical
5846 system type and linking files (@pxref{Manual Configuration}).
5847
5848 The site initialization script can specify a site-wide cache file to
5849 use, instead of the usual per-program cache. In this case, the cache
5850 file will gradually accumulate information whenever someone runs a new
5851 @code{configure} script. (Running @code{configure} merges the new cache
5852 results with the existing cache file.) This may cause problems,
5853 however, if the system configuration (e.g. the installed libraries or
5854 compilers) changes and the stale cache file is not deleted.
5855
5856 @node Cache Checkpointing, , Cache Files, Caching Results
5857 @subsection Cache Checkpointing
5858
5859 If your configure script, or a macro called from configure.ac, happens
5860 to abort the configure process, it may be useful to checkpoint the cache
5861 a few times at key points using @code{AC_CACHE_SAVE}. Doing so will
5862 reduce the amount of time it takes to re-run the configure script with
5863 (hopefully) the error that caused the previous abort corrected.
5864
5865 @c FIXME: Do we really want to document this guy?
5866 @defmac AC_CACHE_LOAD
5867 @maindex CACHE_LOAD
5868 Loads values from existing cache file, or creates a new cache file if a
5869 cache file is not found. Called automatically from @code{AC_INIT}.
5870 @end defmac
5871
5872 @defmac AC_CACHE_SAVE
5873 @maindex CACHE_SAVE
5874 Flushes all cached values to the cache file. Called automatically from
5875 @code{AC_OUTPUT}, but it can be quite useful to call
5876 @code{AC_CACHE_SAVE} at key points in configure.ac.
5877 @end defmac
5878
5879 For instance:
5880
5881 @example
5882 @r{ @dots{} AC_INIT, etc. @dots{}}
5883 @group
5884 # Checks for programs.
5885 AC_PROG_CC
5886 AC_PROG_GCC_TRADITIONAL
5887 @r{ @dots{} more program checks @dots{}}
5888 AC_CACHE_SAVE
5889 @end group
5890
5891 @group
5892 # Checks for libraries.
5893 AC_CHECK_LIB(nsl, gethostbyname)
5894 AC_CHECK_LIB(socket, connect)
5895 @r{ @dots{} more lib checks @dots{}}
5896 AC_CACHE_SAVE
5897 @end group
5898
5899 @group
5900 # Might abort...
5901 AM_PATH_GTK(1.0.2,, (exit 1); exit)
5902 AM_PATH_GTKMM(0.9.5,, (exit 1); exit)
5903 @end group
5904 @r{ @dots{} AC_OUTPUT, etc. @dots{}}
5905 @end example
5906
5907 @node Printing Messages, , Caching Results, Results
5908 @section Printing Messages
5909 @cindex Messages, from @code{configure}
5910
5911 @code{configure} scripts need to give users running them several kinds
5912 of information. The following macros print messages in ways appropriate
5913 for each kind. The arguments to all of them get enclosed in shell
5914 double quotes, so the shell performs variable and back-quote
5915 substitution on them.
5916
5917 These macros are all wrappers around the @code{echo} shell command.
5918 @code{configure} scripts should rarely need to run @code{echo} directly
5919 to print messages for the user. Using these macros makes it easy to
5920 change how and when each kind of message is printed; such changes need
5921 only be made to the macro definitions and all of the callers will change
5922 automatically.
5923
5924 To diagnose static issues, i.e., when @code{autoconf} is run, see
5925 @ref{Reporting Messages}.
5926
5927 @defmac AC_MSG_CHECKING (@var{feature-description})
5928 @maindex MSG_CHECKING
5929 Notify the user that @code{configure} is checking for a particular
5930 feature. This macro prints a message that starts with @samp{checking }
5931 and ends with @samp{...} and no newline. It must be followed by a call
5932 to @code{AC_MSG_RESULT} to print the result of the check and the
5933 newline. The @var{feature-description} should be something like
5934 @samp{whether the Fortran compiler accepts C++ comments} or @samp{for
5935 c89}.
5936
5937 This macro prints nothing if @code{configure} is run with the
5938 @option{--quiet} or @option{--silent} option.
5939 @end defmac
5940
5941 @defmac AC_MSG_RESULT (@var{result-description})
5942 @maindex MSG_RESULT
5943 Notify the user of the results of a check. @var{result-description} is
5944 almost always the value of the cache variable for the check, typically
5945 @samp{yes}, @samp{no}, or a file name. This macro should follow a call
5946 to @code{AC_MSG_CHECKING}, and the @var{result-description} should be
5947 the completion of the message printed by the call to
5948 @code{AC_MSG_CHECKING}.
5949
5950 This macro prints nothing if @code{configure} is run with the
5951 @option{--quiet} or @option{--silent} option.
5952 @end defmac
5953
5954 @defmac AC_MSG_NOTICE (@var{message})
5955 @maindex MSG_NOTICE
5956 Deliver the @var{message} to the user. It is useful mainly to print a
5957 general description of the overall purpose of a group of feature checks,
5958 e.g.,
5959
5960 @example
5961 AC_MSG_NOTICE([checking if stack overflow is detectable])
5962 @end example
5963
5964 This macro prints nothing if @code{configure} is run with the
5965 @option{--quiet} or @option{--silent} option.
5966 @end defmac
5967
5968 @defmac AC_MSG_ERROR (@var{error-description}, @ovar{exit-status})
5969 @maindex MSG_ERROR
5970 Notify the user of an error that prevents @code{configure} from
5971 completing. This macro prints an error message to the standard error
5972 output and exits @code{configure} with @var{exit-status} (1 by default).
5973 @var{error-description} should be something like @samp{invalid value
5974 $HOME for \$HOME}.
5975
5976 The @var{error-description} should start with a lower-case letter, and
5977 ``cannot'' is preferred to ``can't''.
5978 @end defmac
5979
5980 @defmac AC_MSG_WARN (@var{problem-description})
5981 @maindex MSG_WARN
5982 Notify the @code{configure} user of a possible problem. This macro
5983 prints the message to the standard error output; @code{configure}
5984 continues running afterward, so macros that call @code{AC_MSG_WARN} should
5985 provide a default (back-up) behavior for the situations they warn about.
5986 @var{problem-description} should be something like @samp{ln -s seems to
5987 make hard links}.
5988 @end defmac
5989
5990
5991
5992 @c ====================================================== Programming in M4.
5993
5994 @node Programming in M4, Writing Autoconf Macros, Results, Top
5995 @chapter Programming in M4
5996
5997 Autoconf is written on top of two layers: @dfn{M4sugar}, which provides
5998 convenient macros for pure M4 programming, and @dfn{M4sh}, which
5999 provides macros dedicated to shell script generation.
6000
6001 As of this version of Autoconf, these two layers are still experimental,
6002 and their interface might change in the future. As a matter of fact,
6003 @emph{anything that is not documented must not be used}.
6004
6005 @menu
6006 * M4 Quotation:: Protecting macros from unwanted expansion
6007 * Programming in M4sugar:: Convenient pure M4 macros
6008 @end menu
6009
6010 @node M4 Quotation, Programming in M4sugar, Programming in M4, Programming in M4
6011 @section M4 Quotation
6012 @cindex quotation
6013
6014 @c FIXME: Grmph, yet another quoting myth: quotation has *never*
6015 @c prevented `expansion' of $1. Unless it refers to the expansion
6016 @c of the value of $1? Anyway, we need a rewrite here@dots{}
6017
6018 The most common brokenness of existing macros is an improper quotation.
6019 This section, which users of Autoconf can skip, but which macro writers
6020 @emph{must} read, first justifies the quotation scheme that was chosen
6021 for Autoconf and then ends with a rule of thumb. Understanding the
6022 former helps one to follow the latter.
6023
6024 @menu
6025 * Active Characters:: Characters that change the behavior of m4
6026 * One Macro Call:: Quotation and one macro call
6027 * Quotation and Nested Macros:: Macros calling macros
6028 * Quadrigraphs:: Another way to escape special characters
6029 * Quotation Rule Of Thumb:: One parenthesis, one quote
6030 @end menu
6031
6032 @node Active Characters, One Macro Call, M4 Quotation, M4 Quotation
6033 @subsection Active Characters
6034
6035 To fully understand where proper quotation is important, you first need
6036 to know what are the special characters in Autoconf: @samp{#} introduces
6037 a comment inside which no macro expansion is performed, @samp{,}
6038 separates arguments, @samp{[} and @samp{]} are the quotes themselves,
6039 and finally @samp{(} and @samp{)} (which @code{m4} tries to match by
6040 pairs).
6041
6042 In order to understand the delicate case of macro calls, we first have
6043 to present some obvious failures. Below they are ``obvious-ified'',
6044 although you find them in real life, they are usually in disguise.
6045
6046 Comments, introduced by a hash and running up to the newline, are opaque
6047 tokens to the top level: active characters are turned off, and there is
6048 no macro expansion:
6049
6050 @example
6051 # define([def], ine)
6052 @result{}# define([def], ine)
6053 @end example
6054
6055 Each time there can be a macro expansion, there is a quotation
6056 expansion; i.e., one level of quotes is stripped:
6057
6058 @example
6059 int tab[10];
6060 @result{}int tab10;
6061 [int tab[10];]
6062 @result{}int tab[10];
6063 @end example
6064
6065 Without this in mind, the reader will try hopelessly to use her macro
6066 @code{array}:
6067
6068 @example
6069 define([array], [int tab[10];])
6070 array
6071 @result{}int tab10;
6072 [array]
6073 @result{}array
6074 @end example
6075
6076 @noindent
6077 How can you correctly output the intended results@footnote{Using
6078 @code{defn}.}?
6079
6080
6081 @node One Macro Call, Quotation and Nested Macros, Active Characters, M4 Quotation
6082 @subsection One Macro Call
6083
6084 Let's proceed on the interaction between active characters and macros
6085 with this small macro, which just returns its first argument:
6086
6087 @example
6088 define([car], [$1])
6089 @end example
6090
6091 @noindent
6092 The two pairs of quotes above are not part of the arguments of
6093 @code{define}; rather, they are understood by the top level when it
6094 tries to find the arguments of @code{define}. Therefore, it is
6095 equivalent to write:
6096
6097 @example
6098 define(car, $1)
6099 @end example
6100
6101 @noindent
6102 But, while it is acceptable for a @file{configure.ac} to avoid unneeded
6103 quotes, it is bad practice for Autoconf macros which must both be more
6104 robust and also advocate perfect style.
6105
6106 At the top level, there are only two possible quotings: either you
6107 quote or you don't:
6108
6109 @example
6110 car(foo, bar, baz)
6111 @result{}foo
6112 [car(foo, bar, baz)]
6113 @result{}car(foo, bar, baz)
6114 @end example
6115
6116 Let's pay attention to the special characters:
6117
6118 @example
6119 car(#)
6120 @error{}EOF in argument list
6121 @end example
6122
6123 The closing parenthesis is hidden in the comment; with a hypothetical
6124 quoting, the top level understood it this way:
6125
6126 @example
6127 car([#)]
6128 @end example
6129
6130 @noindent
6131 Proper quotation, of course, fixes the problem:
6132
6133 @example
6134 car([#])
6135 @result{}#
6136 @end example
6137
6138 The reader will easily understand the following examples:
6139
6140 @example
6141 car(foo, bar)
6142 @result{}foo
6143 car([foo, bar])
6144 @result{}foo, bar
6145 car((foo, bar))
6146 @result{}(foo, bar)
6147 car([(foo], [bar)])
6148 @result{}(foo
6149 car([], [])
6150 @result{}
6151 car([[]], [[]])
6152 @result{}[]
6153 @end example
6154
6155 With this in mind, we can explore the cases where macros invoke
6156 macros@dots{}
6157
6158
6159 @node Quotation and Nested Macros, Quadrigraphs, One Macro Call, M4 Quotation
6160 @subsection Quotation and Nested Macros
6161
6162 The examples below use the following macros:
6163
6164 @example
6165 define([car], [$1])
6166 define([active], [ACT, IVE])
6167 define([array], [int tab[10]])
6168 @end example
6169
6170 Each additional embedded macro call introduces other possible
6171 interesting quotations:
6172
6173 @example
6174 car(active)
6175 @result{}ACT
6176 car([active])
6177 @result{}ACT, IVE
6178 car([[active]])
6179 @result{}active
6180 @end example
6181
6182 In the first case, the top level looks for the arguments of @code{car},
6183 and finds @samp{active}. Because @code{m4} evaluates its arguments
6184 before applying the macro, @samp{active} is expanded, which results in:
6185
6186 @example
6187 car(ACT, IVE)
6188 @result{}ACT
6189 @end example
6190
6191 @noindent
6192 In the second case, the top level gives @samp{active} as first and only
6193 argument of @code{car}, which results in:
6194
6195 @example
6196 active
6197 @result{}ACT, IVE
6198 @end example
6199
6200 @noindent
6201 i.e., the argument is evaluated @emph{after} the macro that invokes it.
6202 In the third case, @code{car} receives @samp{[active]}, which results in:
6203
6204 @example
6205 [active]
6206 @result{}active
6207 @end example
6208
6209 @noindent
6210 exactly as we already saw above.
6211
6212 The example above, applied to a more realistic example, gives:
6213
6214 @example
6215 car(int tab[10];)
6216 @result{}int tab10;
6217 car([int tab[10];])
6218 @result{}int tab10;
6219 car([[int tab[10];]])
6220 @result{}int tab[10];
6221 @end example
6222
6223 @noindent
6224 Huh? The first case is easily understood, but why is the second wrong,
6225 and the third right? To understand that, you must know that after
6226 @code{m4} expands a macro, the resulting text is immediately subjected
6227 to macro expansion and quote removal. This means that the quote removal
6228 occurs twice---first before the argument is passed to the @code{car}
6229 macro, and second after the @code{car} macro expands to the first
6230 argument.
6231
6232 As the author of the Autoconf macro @code{car}, you then consider it to
6233 be incorrect that your users have to double-quote the arguments of
6234 @code{car}, so you ``fix'' your macro. Let's call it @code{qar} for
6235 quoted car:
6236
6237 @example
6238 define([qar], [[$1]])
6239 @end example
6240
6241 @noindent
6242 and check that @code{qar} is properly fixed:
6243
6244 @example
6245 qar([int tab[10];])
6246 @result{}int tab[10];
6247 @end example
6248
6249 @noindent
6250 Ahhh! That's much better.
6251
6252 But note what you've done: now that the arguments are literal strings,
6253 if the user wants to use the results of expansions as arguments, she has
6254 to use an @emph{unquoted} macro call:
6255
6256 @example
6257 qar(active)
6258 @result{}ACT
6259 @end example
6260
6261 @noindent
6262 where she wanted to reproduce what she used to do with @code{car}:
6263
6264 @example
6265 car([active])
6266 @result{}ACT, IVE
6267 @end example
6268
6269 @noindent
6270 Worse yet: she wants to use a macro that produces a set of @code{cpp}
6271 macros:
6272
6273 @example
6274 define([my_includes], [#include <stdio.h>])
6275 car([my_includes])
6276 @result{}#include <stdio.h>
6277 qar(my_includes)
6278 @error{}EOF in argument list
6279 @end example
6280
6281 This macro, @code{qar}, because it double quotes its arguments, forces
6282 its users to leave their macro calls unquoted, which is dangerous.
6283 Commas and other active symbols are interpreted by @code{m4} before
6284 they are given to the macro, often not in the way the users expect.
6285 Also, because @code{qar} behaves differently from the other macros,
6286 it's an exception that should be avoided in Autoconf.
6287
6288
6289 @node Quadrigraphs, Quotation Rule Of Thumb, Quotation and Nested Macros, M4 Quotation
6290 @subsection Quadrigraphs
6291 @cindex quadrigraphs
6292 @cindex @samp{@@<:@@}
6293 @cindex @samp{@@:>@@}
6294 @cindex @samp{@@S|@@}
6295 @cindex @samp{@@%:@@}
6296
6297 When writing an autoconf macro you may occasionally need to generate
6298 special characters that are difficult to express with the standard
6299 autoconf quoting rules. For example, you may need to output the regular
6300 expression @samp{[^[]}, which matches any character other than @samp{[}.
6301 This expression contains unbalanced brackets so it cannot be put easily
6302 into an M4 macro.
6303
6304 You can work around this problem by using one of the following
6305 @dfn{quadrigraphs}:
6306
6307 @table @samp
6308 @item @@<:@@
6309 @samp{[}
6310 @item @@:>@@
6311 @samp{]}
6312 @item @@S|@@
6313 @samp{$}
6314 @item @@%:@@
6315 @samp{#}
6316 @end table
6317
6318 Quadrigraphs are replaced at a late stage of the translation process,
6319 after @command{m4} is run, so they do not get in the way of M4 quoting.
6320 For example, the string @samp{[^@@<:@@]}, if properly quoted, will
6321 appear as @samp{[^[]} in the @code{configure} script.
6322
6323
6324 @node Quotation Rule Of Thumb, , Quadrigraphs, M4 Quotation
6325 @subsection Quotation Rule Of Thumb
6326
6327 To conclude, the quotation rule of thumb is:
6328
6329 @center @emph{One pair of quotes per pair of parentheses.}
6330
6331 Never over-quote, never under-quote, in particular in the definition of
6332 macros. In the few places where the macros need to use brackets
6333 (usually in C program text or regular expressions), properly quote
6334 @emph{the arguments}!
6335
6336 It is common to read Autoconf programs with snippets like:
6337
6338 @example
6339 AC_TRY_LINK(
6340 changequote(<<, >>)dnl
6341 <<#include <time.h>
6342 #ifndef tzname /* For SGI. */
6343 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
6344 #endif>>,
6345 changequote([, ])dnl
6346 [atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)
6347 @end example
6348
6349 @noindent
6350 which is incredibly useless since @code{AC_TRY_LINK} is @emph{already}
6351 double quoting, so you just need:
6352
6353 @example
6354 AC_TRY_LINK(
6355 [#include <time.h>
6356 #ifndef tzname /* For SGI. */
6357 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
6358 #endif],
6359 [atoi (*tzname);],
6360 [ac_cv_var_tzname=yes],
6361 [ac_cv_var_tzname=no])
6362 @end example
6363
6364 @noindent
6365 The M4-fluent reader will note that these two examples are rigorously
6366 equivalent, since @code{m4} swallows both the @samp{changequote(<<, >>)}
6367 and @samp{<<} @samp{>>} when it @dfn{collects} the arguments: these
6368 quotes are not part of the arguments!
6369
6370 Simplified, the example above is just doing this:
6371
6372 @example
6373 changequote(<<, >>)dnl
6374 <<[]>>
6375 changequote([, ])dnl
6376 @end example
6377
6378 @noindent
6379 instead of simply:
6380
6381 @example
6382 [[]]
6383 @end example
6384
6385
6386 With macros that do not double quote their arguments (which is the
6387 rule), double-quote the (risky) literals:
6388
6389 @example
6390 AC_LINK_IFELSE([AC_LANG_PROGRAM(
6391 [[#include <time.h>
6392 #ifndef tzname /* For SGI. */
6393 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
6394 #endif]],
6395 [atoi (*tzname);])],
6396 [ac_cv_var_tzname=yes],
6397 [ac_cv_var_tzname=no])
6398 @end example
6399
6400 See @xref{Quadrigraphs}, for what to do if you run into a hopeless case
6401 where quoting does not suffice.
6402
6403 When you create a @code{configure} script using newly written macros,
6404 examine it carefully to check whether you need to add more quotes in
6405 your macros. If one or more words have disappeared in the @code{m4}
6406 output, you need more quotes. When in doubt, quote.
6407
6408 However, it's also possible to put on too many layers of quotes. If
6409 this happens, the resulting @code{configure} script will contain
6410 unexpanded macros. The @code{autoconf} program checks for this problem
6411 by doing @samp{grep AC_ configure}.
6412
6413
6414 @node Programming in M4sugar, , M4 Quotation, Programming in M4
6415 @section Programming in M4sugar
6416
6417 @cindex M4sugar
6418 M4 by itself provides only a small, but sufficient, set of all-purpose
6419 macros. M4sugar introduces additional generic macros. Its name was
6420 coined by Lars J. Aas: ``Readability And Greater Understanding Stands 4
6421 M4sugar''.
6422
6423 @menu
6424 * Redefined M4 Macros:: M4 builtins changed in M4sugar
6425 * Forbidden Patterns:: Catching unexpanded macros
6426 @end menu
6427
6428 @node Redefined M4 Macros, Forbidden Patterns, Programming in M4sugar, Programming in M4sugar
6429 @subsection Redefined M4 Macros
6430
6431 All the M4 native macros are moved in the @samp{m4_} pseudo-namespace,
6432 e.g., M4sugar renames @code{define} as @code{m4_define} etc. There is
6433 one exception: @code{dnl} kept its original name, and no @code{m4_dnl}
6434 is defined.
6435
6436 M4sugar redefines some M4 macros, and made them slightly incompatible
6437 with their native equivalent.
6438
6439 @defmac m4_defn (@var{macro})
6440 @msindex defn
6441 Contrary to the M4 builtin, this macro fails if @var{macro} is not
6442 defined. See @code{m4_undefine}.
6443 @end defmac
6444
6445 @defmac m4_undefine (@var{macro})
6446 @msindex undefine
6447 Contrary to the M4 builtin, this macro fails if @var{macro} is not
6448 defined. Use
6449
6450 @example
6451 m4_ifdef([@var{macro}], [m4_undefine([@var{macro}])])
6452 @end example
6453
6454 @noindent
6455 to recover the behavior of the builtin.
6456 @end defmac
6457
6458 @defmac m4_popdef (@var{macro})
6459 @msindex defn
6460 Contrary to the M4 builtin, this macro fails if @var{macro} is not
6461 defined. See @code{m4_undefine}.
6462 @end defmac
6463
6464 @node Forbidden Patterns, , Redefined M4 Macros, Programming in M4sugar
6465 @subsection Forbidden Patterns
6466
6467 M4sugar provides a means to define suspicious patterns, patterns
6468 describing tokens which should not be found in the output. For
6469 instance, if an Autoconf @file{configure} script includes tokens such as
6470 @samp{AC_DEFINE}, or @samp{dnl}, then most probably something went
6471 wrong (typically a macro was not evaluated because of over quotation).
6472
6473 M4sugar forbids all the tokens matching @samp{^m4_} and @samp{^dnl$}.
6474
6475 @defmac m4_pattern_forbid (@var{pattern})
6476 @msindex pattern_forbid
6477 Declare no token matching @var{pattern} must be found in the output.
6478 Comments are not checked; this can be a problem if, for instance, you
6479 have some macro left unexpanded after an @samp{#include}. No consensus
6480 is currently found in the Autoconf community, as some people consider it
6481 should be valid to name macros in comments (which doesn't makes sense to
6482 the author of this documentation, as @samp{#}-comments should document
6483 the output, not the input, documented vy @samp{dnl}-comments).
6484 @end defmac
6485
6486 Of course, you might encounter exceptions to these generic rules, for
6487 instance you might have to refer to @samp{$m4_flags}.
6488
6489 @defmac m4_pattern_allow (@var{pattern})
6490 @msindex pattern_allow
6491 Any token matching @var{pattern} is allowed, including if it matches an
6492 @code{m4_pattern_forbid} pattern.
6493 @end defmac
6494
6495 @c=================================================== Writing Autoconf Macros.
6496
6497 @node Writing Autoconf Macros, Portable Shell, Programming in M4, Top
6498 @chapter Writing Autoconf Macros
6499
6500 When you write a feature test that could be applicable to more than one
6501 software package, the best thing to do is encapsulate it in a new macro.
6502 Here are some instructions and guidelines for writing Autoconf macros.
6503
6504 @menu
6505 * Macro Definitions:: Basic format of an Autoconf macro
6506 * Macro Names:: What to call your new macros
6507 * Reporting Messages:: Notifying @code{autoconf} users
6508 * Dependencies Between Macros:: What to do when macros depend on other macros
6509 * Obsoleting Macros:: Warning about old ways of doing things
6510 * Coding Style:: Writing Autoconf macros @`a la Autoconf
6511 @end menu
6512
6513 @node Macro Definitions, Macro Names, Writing Autoconf Macros, Writing Autoconf Macros
6514 @section Macro Definitions
6515
6516 @maindex DEFUN
6517 Autoconf macros are defined using the @code{AC_DEFUN} macro, which is
6518 similar to the M4 builtin @code{define} macro. In addition to defining
6519 a macro, @code{AC_DEFUN} adds to it some code that is used to constrain
6520 the order in which macros are called (@pxref{Prerequisite Macros}).
6521
6522 An Autoconf macro definition looks like this:
6523
6524 @example
6525 AC_DEFUN(@var{macro-name}, @var{macro-body})
6526 @end example
6527
6528 You can refer to any arguments passed to the macro as @samp{$1},
6529 @samp{$2}, etc. @xref{Definitions,, How to define new macros, m4.info,
6530 GNU m4}, for more complete information on writing M4 macros.
6531
6532 Be sure to properly quote both the @var{macro-body} @emph{and} the
6533 @var{macro-name} to avoid any problems if the macro happens to have
6534 been previously defined.
6535
6536 Each macro should have a header comment that gives its prototype, and a
6537 brief description. When arguments have default values, display them in
6538 the prototype. For example:
6539
6540 @example
6541 # AC_MSG_ERROR(ERROR, [EXIT-STATUS = 1])
6542 # --------------------------------------
6543 define([AC_MSG_ERROR],
6544 [@{ _AC_ECHO([configure: error: $1], 2); exit m4_default([$2], 1); @}])
6545 @end example
6546
6547 Comments about the macro should be left in the header comment. Most
6548 other comments will make their way into @file{configure}, so just keep
6549 using @samp{#} to introduce comments.
6550
6551 @cindex @code{dnl}
6552 If you have some very special comments about pure M4 code, comments
6553 that make no sense in @file{configure} and in the header comment, then
6554 use the builtin @code{dnl}: it causes @code{m4} to discard the text
6555 through the next newline.
6556
6557 Keep in mind that @code{dnl} is rarely needed to introduce comments;
6558 @code{dnl} is more useful to get rid of the newlines following macros
6559 that produce no output, such as @code{AC_REQUIRE}.
6560
6561
6562 @node Macro Names, Reporting Messages, Macro Definitions, Writing Autoconf Macros
6563 @section Macro Names
6564
6565 All of the Autoconf macros have all-uppercase names starting with
6566 @samp{AC_} to prevent them from accidentally conflicting with other
6567 text. All shell variables that they use for internal purposes have
6568 mostly-lowercase names starting with @samp{ac_}. To ensure that your
6569 macros don't conflict with present or future Autoconf macros, you should
6570 prefix your own macro names and any shell variables they use with some
6571 other sequence. Possibilities include your initials, or an abbreviation
6572 for the name of your organization or software package.
6573
6574 Most of the Autoconf macros' names follow a structured naming convention
6575 that indicates the kind of feature check by the name. The macro names
6576 consist of several words, separated by underscores, going from most
6577 general to most specific. The names of their cache variables use the
6578 same convention (@pxref{Cache Variable Names}, for more information on
6579 them).
6580
6581 The first word of the name after @samp{AC_} usually tells the category
6582 of feature being tested. Here are the categories used in Autoconf for
6583 specific test macros, the kind of macro that you are more likely to
6584 write. They are also used for cache variables, in all-lowercase. Use
6585 them where applicable; where they're not, invent your own categories.
6586
6587 @table @code
6588 @item C
6589 C language builtin features.
6590 @item DECL
6591 Declarations of C variables in header files.
6592 @item FUNC
6593 Functions in libraries.
6594 @item GROUP
6595 @sc{unix} group owners of files.
6596 @item HEADER
6597 Header files.
6598 @item LIB
6599 C libraries.
6600 @item PATH
6601 The full path names to files, including programs.
6602 @item PROG
6603 The base names of programs.
6604 @item MEMBER
6605 Members of aggregates.
6606 @item SYS
6607 Operating system features.
6608 @item TYPE
6609 C builtin or declared types.
6610 @item VAR
6611 C variables in libraries.
6612 @end table
6613
6614 After the category comes the name of the particular feature being
6615 tested. Any further words in the macro name indicate particular aspects
6616 of the feature. For example, @code{AC_FUNC_UTIME_NULL} checks the
6617 behavior of the @code{utime} function when called with a @code{NULL}
6618 pointer.
6619
6620 An internal macro should have a name that starts with an underscore;
6621 Autoconf internals should therefore start with @samp{_AC_}.
6622 Additionally, a macro that is an internal subroutine of another macro
6623 should have a name that starts with an underscore and the name of that
6624 other macro, followed by one or more words saying what the internal
6625 macro does. For example, @code{AC_PATH_X} has internal macros
6626 @code{_AC_PATH_X_XMKMF} and @code{_AC_PATH_X_DIRECT}.
6627
6628 @node Reporting Messages, Dependencies Between Macros, Macro Names, Writing Autoconf Macros
6629 @section Reporting Messages
6630 @cindex Messages, from @code{autoconf}
6631
6632 When macros statically diagnose abnormal situations, benign or fatal,
6633 they should report them using these macros. For dynamic issues, i.e.,
6634 when @code{configure} is run, see @ref{Printing Messages}.
6635
6636 @defmac AC_DIAGNOSE (@var{category}, @var{message})
6637 @maindex DIAGNOSE
6638 Report @var{message} as a warning (or as an error if requested by the
6639 user) if it falls into the @var{category}. You are encouraged to use
6640 standard categories, which currently include:
6641
6642 @table @samp
6643 @item all
6644 messages that don't fall into one of the following category. Use of an
6645 empty @var{category} is equivalent.
6646
6647 @item cross
6648 related to cross compilation issues.
6649
6650 @item obsolete
6651 use of an obsolete construct.
6652
6653 @item syntax
6654 dubious syntactic constructs, incorrectly ordered macro calls.
6655 @end table
6656 @end defmac
6657
6658 @defmac AC_WARNING (@var{message})
6659 @maindex WARNING
6660 Equivalent to @samp{AC_DIAGNOSE([syntax], @var{message})}, but you are
6661 strongly encouraged to use a finer grained category.
6662 @end defmac
6663
6664 @defmac AC_FATAL (@var{message})
6665 @maindex FATAL
6666 Report a severe error @var{message}, and have @code{autoconf} die.
6667 @end defmac
6668
6669 When the user runs @samp{autoconf -W error}, warnings from
6670 @code{AC_DIAGNOSE} and @code{AC_WARNING} are reported as error, see
6671 @ref{autoconf Invocation}.
6672
6673 @node Dependencies Between Macros, Obsoleting Macros, Reporting Messages, Writing Autoconf Macros
6674 @section Dependencies Between Macros
6675
6676 Some Autoconf macros depend on other macros having been called first in
6677 order to work correctly. Autoconf provides a way to ensure that certain
6678 macros are called if needed and a way to warn the user if macros are
6679 called in an order that might cause incorrect operation.
6680
6681 @menu
6682 * Prerequisite Macros:: Ensuring required information
6683 * Suggested Ordering:: Warning about possible ordering problems
6684 @end menu
6685
6686 @node Prerequisite Macros, Suggested Ordering, Dependencies Between Macros, Dependencies Between Macros
6687 @subsection Prerequisite Macros
6688
6689 A macro that you write might need to use values that have previously
6690 been computed by other macros. For example, @code{AC_DECL_YYTEXT}
6691 examines the output of @code{flex} or @code{lex}, so it depends on
6692 @code{AC_PROG_LEX} having been called first to set the shell variable
6693 @code{LEX}.
6694
6695 Rather than forcing the user of the macros to keep track of the
6696 dependencies between them, you can use the @code{AC_REQUIRE} macro to do
6697 it automatically. @code{AC_REQUIRE} can ensure that a macro is only
6698 called if it is needed, and only called once.
6699
6700 @defmac AC_REQUIRE (@var{macro-name})
6701 @maindex REQUIRE
6702 If the M4 macro @var{macro-name} has not already been called, call it
6703 (without any arguments). Make sure to quote @var{macro-name} with
6704 square brackets. @var{macro-name} must have been defined using
6705 @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
6706 that it has been called.
6707
6708 @code{AC_REQUIRE} must be used inside an @code{AC_DEFUN}'d macro; it
6709 must not be called from the top level.
6710 @end defmac
6711
6712 @code{AC_REQUIRE} is often misunderstood. It really implements
6713 dependencies between macros in the sense that if one macro depends upon
6714 another, the latter will be expanded @emph{before} the body of the
6715 former. In particular, @samp{AC_REQUIRE(FOO)} is not replaced with the
6716 body of @code{FOO}. For instance, this definition of macros:
6717
6718 @example
6719 @group
6720 AC_DEFUN([TRAVOLTA],
6721 [test "$body_temparature_in_celsius" -gt "38" &&
6722 dance_floor=occupied])
6723 AC_DEFUN([NEWTON_JOHN],
6724 [test "$hair_style" = "curly" &&
6725 dance_floor=occupied])
6726 @end group
6727
6728 @group
6729 AC_DEFUN([RESERVE_DANCE_FLOOR],
6730 [if date | grep '^Sat.*pm' >/dev/null 2>&1; then
6731 AC_REQUIRE([TRAVOLTA])
6732 AC_REQUIRE([NEWTON_JOHN])
6733 fi])
6734 @end group
6735 @end example
6736
6737 @noindent
6738 with this @file{configure.ac}
6739
6740 @example
6741 AC_INIT
6742 RESERVE_DANCE_FLOOR
6743 if test "$dance_floor" = occupied; then
6744 AC_MSG_ERROR([cannot pick up here, let's move])
6745 fi
6746 @end example
6747
6748 @noindent
6749 will not leave you with a better chance to meet a kindred soul at
6750 other times than Saturday night since it expands into:
6751
6752 @example
6753 @group
6754 test "$body_temperature_in_Celsius" -gt "38" &&
6755 dance_floor=occupied
6756 test "$hair_style" = "curly" &&
6757 dance_floor=occupied
6758 fi
6759 if date | grep '^Sat.*pm' >/dev/null 2>&1; then
6760
6761
6762 fi
6763 @end group
6764 @end example
6765
6766 This behavior was chosen on purpose: (i) it prevents messages in
6767 required macros from interrupting the messages in the requiring macros;
6768 (ii) it avoids bad surprises when shell conditionals are used, as in:
6769
6770 @example
6771 @group
6772 if @dots{}; then
6773 AC_REQUIRE([SOME_CHECK])
6774 fi
6775 @dots{}
6776 SOME_CHECK
6777 @end group
6778 @end example
6779
6780
6781 You are encouraged to put all @code{AC_REQUIRE}s at the beginning of a
6782 macro. You can use @code{dnl} to avoid the empty lines they leave.
6783
6784 @node Suggested Ordering, , Prerequisite Macros, Dependencies Between Macros
6785 @subsection Suggested Ordering
6786
6787 Some macros should be run before another macro if both are called, but
6788 neither @emph{requires} that the other be called. For example, a macro
6789 that changes the behavior of the C compiler should be called before any
6790 macros that run the C compiler. Many of these dependencies are noted in
6791 the documentation.
6792
6793 Autoconf provides the @code{AC_BEFORE} macro to warn users when macros
6794 with this kind of dependency appear out of order in a
6795 @file{configure.ac} file. The warning occurs when creating
6796 @code{configure} from @file{configure.ac}, not when running
6797 @code{configure}.
6798
6799 For example, @code{AC_PROG_CPP} checks whether the C compiler
6800 can run the C preprocessor when given the @option{-E} option. It should
6801 therefore be called after any macros that change which C compiler is
6802 being used, such as @code{AC_PROG_CC}. So @code{AC_PROG_CC} contains:
6803
6804 @example
6805 AC_BEFORE([$0], [AC_PROG_CPP])dnl
6806 @end example
6807
6808 @noindent
6809 This warns the user if a call to @code{AC_PROG_CPP} has already occurred
6810 when @code{AC_PROG_CC} is called.
6811
6812 @defmac AC_BEFORE (@var{this-macro-name}, @var{called-macro-name})
6813 @maindex BEFORE
6814 Make @code{m4} print a warning message to the standard error output if
6815 @var{called-macro-name} has already been called. @var{this-macro-name}
6816 should be the name of the macro that is calling @code{AC_BEFORE}. The
6817 macro @var{called-macro-name} must have been defined using
6818 @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
6819 that it has been called.
6820 @end defmac
6821
6822 @node Obsoleting Macros, Coding Style, Dependencies Between Macros, Writing Autoconf Macros
6823 @section Obsoleting Macros
6824
6825 Configuration and portability technology has evolved over the years.
6826 Often better ways of solving a particular problem are developed, or
6827 ad-hoc approaches are systematized. This process has occurred in many
6828 parts of Autoconf. One result is that some of the macros are now
6829 considered @dfn{obsolete}; they still work, but are no longer considered
6830 the best thing to do, hence they should be replaced with more modern
6831 macros. Ideally, @code{autoupdate} should substitute the old macro calls
6832 with their modern implementation.
6833
6834 Autoconf provides a simple means to obsolete a macro.
6835
6836 @defmac AU_DEFUN (@var{old-macro}, @var{implementation}, @ovar{message})
6837 @maindex DEFUN
6838 @maindex AU_DEFUN
6839 Define @var{old-macro} as @var{implementation}. The only difference
6840 with @code{AC_DEFUN} is that the user will be warned that
6841 @var{old-macro} is now obsolete.
6842
6843 If she then uses @code{autoupdate}, the call to @var{old-macro} will be
6844 replaced by the modern @var{implementation}. The additional
6845 @var{message} is then printed.
6846 @end defmac
6847
6848 @node Coding Style, , Obsoleting Macros, Writing Autoconf Macros
6849 @section Coding Style
6850
6851 The Autoconf macros follow a strict coding style. You are encouraged to
6852 follow this style, especially if you intend to distribute your macro,
6853 either by contributing it to Autoconf itself, or via other means.
6854
6855 The first requirement is to pay great attention to the quotation, for
6856 more details, see @ref{Autoconf Language}, and @ref{M4 Quotation}.
6857
6858 Do not try to invent new interfaces. It is likely that there is a macro
6859 in Autoconf that resembles the macro you are defining: try to stick to
6860 this existing interface (order of arguments, default values, etc.). We
6861 @emph{are} conscious that some of these interfaces are not perfect;
6862 nevertheless, when harmless, homogeneity should be preferred over
6863 creativity.
6864
6865 Be careful about clashes both between M4 symbols and between shell
6866 variables.
6867
6868 If you stick to the suggested M4 naming scheme (@pxref{Macro Names}),
6869 you are unlikely to generate conflicts. Nevertheless, when you need to
6870 set a special value, @emph{avoid using a regular macro name}; rather,
6871 use an ``impossible'' name. For instance, up to version 2.13, the macro
6872 @code{AC_SUBST} used to remember what @var{symbol}s were already defined
6873 by setting @code{AC_SUBST_@var{symbol}}, which is a regular macro name.
6874 But since there is a macro named @code{AC_SUBST_FILE}, it was just
6875 impossible to @samp{AC_SUBST(FILE)}! In this case,
6876 @code{AC_SUBST(@var{symbol})} or @code{_AC_SUBST(@var{symbol})} should
6877 have been used (yes, with the parentheses)@dots{}or better yet, high-level
6878 macros such as @code{AC_EXPAND_ONCE}.
6879
6880 No Autoconf macro should ever enter the user-variable name space; i.e.,
6881 except for the variables that are the actual result of running the
6882 macro, all shell variables should start with @code{ac_}. In
6883 addition, small macros or any macro that is likely to be embedded in
6884 other macros should be careful not to use obvious names.
6885
6886 @cindex @code{dnl}
6887 Do not use @code{dnl} to introduce comments: most of the comments you
6888 are likely to write are either header comments which are not output
6889 anyway, or comments that should make their way into @file{configure}.
6890 There are exceptional cases where you do want to comment special M4
6891 constructs, in which case @code{dnl} is right, but keep in mind that it
6892 is unlikely.
6893
6894 M4 ignores the leading spaces before each argument, use this feature to
6895 indent in such a way that arguments are (more or less) aligned with the
6896 opening parenthesis of the macro being called. For instance, instead of
6897
6898 @example
6899 AC_CACHE_CHECK(for EMX OS/2 environment,
6900 ac_cv_emxos2,
6901 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __EMX__;])],
6902 [ac_cv_emxos2=yes], [ac_cv_emxos2=no])])
6903 @end example
6904
6905 @noindent
6906 write
6907
6908 @example
6909 AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
6910 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
6911 [ac_cv_emxos2=yes],
6912 [ac_cv_emxos2=no])])
6913 @end example
6914
6915 @noindent
6916 or even
6917
6918 @example
6919 AC_CACHE_CHECK([for EMX OS/2 environment],
6920 [ac_cv_emxos2],
6921 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
6922 [return __EMX__;])],
6923 [ac_cv_emxos2=yes],
6924 [ac_cv_emxos2=no])])
6925 @end example
6926
6927 When using @code{AC_TRY_RUN} or any macro that cannot work when
6928 cross-compiling, provide a pessimistic value (typically @samp{no}).
6929
6930 Feel free to use various tricks to prevent auxiliary tools, such as
6931 syntax-highlighting editors, from behaving improperly. For instance,
6932 instead of:
6933
6934 @example
6935 patsubst([$1], [$"])
6936 @end example
6937
6938 @noindent
6939 use
6940
6941 @example
6942 patsubst([$1], [$""])
6943 @end example
6944
6945 @noindent
6946 so that Emacsen do not open a endless ``string'' at the first quote.
6947 For the same reasons, avoid:
6948
6949 @example
6950 test $[#] != 0
6951 @end example
6952
6953 @noindent
6954 and use:
6955
6956 @example
6957 test $[@@%:@@] != 0
6958 @end example
6959
6960 @noindent
6961 Otherwise, the closing bracket would be hidden inside a @samp{#}-comment,
6962 breaking the bracket-matching highlighting from Emacsen. Note the
6963 preferred style to escape from M4: @samp{$[1]}, @samp{$[@@]}, etc. Do
6964 not escape when it is unneeded. Common examples of useless quotation
6965 are @samp{[$]$1} (write @samp{$$1}), @samp{[$]var} (use @samp{$var}),
6966 etc. If you add portability issues to the picture, you'll prefer
6967 @samp{$@{1+"$[@@]"@}} to @samp{"[$]@@"}, and you'll prefer do something
6968 better than hacking Autoconf @code{:-)}.
6969
6970 When using @command{sed}, don't use @option{-e} except for indenting
6971 purpose. With the @code{s} command, the preferred separator is @samp{/}
6972 unless @samp{/} itself is used in the command, in which case you should
6973 use @samp{,}.
6974
6975 @xref{Macro Definitions}, for details on how to define a macro. If a
6976 macro doesn't use @code{AC_REQUIRE} and it is expected to never be the
6977 object of an @code{AC_REQUIRE} directive, then use @code{define}. In
6978 case of doubt, use @code{AC_DEFUN}. All the @code{AC_REQUIRE}
6979 statements should be at the beginning of the macro, @code{dnl}'ed.
6980
6981 You should not rely on the number of arguments: instead of checking
6982 whether an argument is missing, test that it is not empty. It provides
6983 both a simpler and a more predictable interface to the user, and saves
6984 room for further arguments.
6985
6986 Unless the macro is short, try to leave the closing @samp{])} at the
6987 beginning of a line, followed by a comment that repeats the name of the
6988 macro being defined. This introduces an additional newline in
6989 @code{configure}; normally, that is not a problem, but if you want to
6990 remove it you can use @samp{[]dnl} on the last line. You can similarly
6991 use @samp{[]dnl} after a macro call to remove its newline. @samp{[]dnl}
6992 is recommended instead of @samp{dnl} to ensure that M4 does not
6993 interpret the @samp{dnl} as being attached to the preceding text or
6994 macro output. For example, instead of:
6995
6996 @example
6997 AC_DEFUN([AC_PATH_X],
6998 [AC_MSG_CHECKING([for X])
6999 AC_REQUIRE_CPP()
7000 @r{# @dots{}omitted@dots{}}
7001 AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
7002 fi])
7003 @end example
7004
7005 @noindent
7006 you would write:
7007
7008 @example
7009 AC_DEFUN([AC_PATH_X],
7010 [AC_REQUIRE_CPP()[]dnl
7011 AC_MSG_CHECKING([for X])
7012 @r{# @dots{}omitted@dots{}}
7013 AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
7014 fi[]dnl
7015 ])# AC_PATH_X
7016 @end example
7017
7018 If the macro is long, try to split it into logical chunks. Typically,
7019 macros that check for a bug in a function and prepare its
7020 @code{AC_LIBOBJ} replacement should have an auxiliary macro to perform
7021 this setup. Do not hesitate to introduce auxiliary macros to factor
7022 your code.
7023
7024 In order to highlight the recommended coding style, here is a macro
7025 written the old way:
7026
7027 @example
7028 dnl Check for EMX on OS/2.
7029 dnl _AC_EMXOS2
7030 AC_DEFUN(_AC_EMXOS2,
7031 [AC_CACHE_CHECK(for EMX OS/2 environment, ac_cv_emxos2,
7032 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return __EMX__;)],
7033 ac_cv_emxos2=yes, ac_cv_emxos2=no)])
7034 test "$ac_cv_emxos2" = yes && EMXOS2=yes])
7035 @end example
7036
7037 @noindent
7038 and the new way:
7039
7040 @example
7041 # _AC_EMXOS2
7042 # ----------
7043 # Check for EMX on OS/2.
7044 define([_AC_EMXOS2],
7045 [AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
7046 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
7047 [ac_cv_emxos2=yes],
7048 [ac_cv_emxos2=no])])
7049 test "$ac_cv_emxos2" = yes && EMXOS2=yes[]dnl
7050 ])# _AC_EMXOS2
7051 @end example
7052
7053
7054
7055
7056 @c ============================================= Portable Shell Programming
7057
7058 @node Portable Shell, Manual Configuration, Writing Autoconf Macros, Top
7059 @chapter Portable Shell Programming
7060
7061 When writing your own checks, there are some shell-script programming
7062 techniques you should avoid in order to make your code portable. The
7063 Bourne shell and upward-compatible shells like the Korn shell and Bash
7064 have evolved over the years, but to prevent trouble, do not take
7065 advantage of features that were added after @sc{unix} version 7, circa
7066 1977. You should not use shell functions, aliases, negated character
7067 classes, or other features that are not found in all Bourne-compatible
7068 shells; restrict yourself to the lowest common denominator. Even
7069 @code{unset} is not supported by all shells! Also, include a space
7070 after the exclamation point in interpreter specifications, like this:
7071
7072 @example
7073 #! /usr/bin/perl
7074 @end example
7075
7076 @noindent
7077 If you omit the space before the path, then 4.2@sc{bsd} based systems
7078 (such as Sequent DYNIX) will ignore the line, because they interpret
7079 @samp{#! /} as a 4-byte magic number.
7080
7081 The set of external programs you should run in a @code{configure} script
7082 is fairly small. @xref{Utilities in Makefiles,, Utilities in
7083 Makefiles, standards, GNU Coding Standards}, for the list. This
7084 restriction allows users to start out with a fairly small set of
7085 programs and build the rest, avoiding too many interdependencies between
7086 packages.
7087
7088 Some of these external utilities have a portable subset of features; see
7089 @ref{Limitations of Usual Tools}.
7090
7091 @menu
7092 * Shellology:: A zoology of shells
7093 * Here-Documents:: Quirks and tricks
7094 * File Descriptors:: FDs and redirections
7095 * File System Conventions:: File- and pathnames
7096 * Shell Substitutions:: Variable and command expansions
7097 * Assignments:: Varying side effects of assignments
7098 * Special Shell Variables:: Variables you should not change
7099 * Limitations of Builtins:: Portable use of not so portable /bin/sh
7100 * Limitations of Usual Tools:: Portable use of portable tools
7101 * Limitations of Make:: Portable Makefiles
7102 @end menu
7103
7104 @node Shellology, Here-Documents, Portable Shell, Portable Shell
7105 @section Shellology
7106
7107 There are several families of shells, most prominently the Bourne
7108 family and the C shell family which are deeply incompatible. If you
7109 want to write portable shell scripts, avoid members of the C shell
7110 family.
7111
7112 Below we describe some of the members of the Bourne shell family.
7113
7114 @table @asis
7115 @item Ash
7116 @cindex Ash
7117 @command{ash} is often used on @sc{gnu}/Linux and @sc{bsd} systems as a
7118 light-weight Bourne-compatible shell. Ash 0.2 has some bugs that are
7119 fixed in the 0.3.x series, but portable shell scripts should workaround
7120 them, since version 0.2 is still shipped with many @sc{gnu}/Linux
7121 distributions.
7122
7123 To be compatible with Ash 0.2:
7124
7125 @itemize @minus
7126 @item
7127 don't use @samp{$?} after expanding empty or unset variables:
7128
7129 @example
7130 foo=
7131 false
7132 $foo
7133 echo "Don't use it: $?"
7134 @end example
7135
7136 @item
7137 don't use command substitution within variable expansion:
7138
7139 @example
7140 cat $@{FOO=`bar`@}
7141 @end example
7142
7143 @item
7144 beware that single builtin substitutions are not performed by a sub
7145 shell, hence their effect applies to the current shell! @xref{Shell
7146 Substitutions}, item ``Command Substitution''.
7147 @end itemize
7148
7149 @item Bash
7150 @cindex Bash
7151 To detect whether you are running @command{bash}, test if
7152 @code{BASH_VERSION} is set. To disable its extensions and require
7153 @sc{posix} compatibility, run @samp{set -o posix}. @xref{Bash POSIX
7154 Mode,, Bash @sc{posix} Mode, bash, The GNU Bash Reference Manual}, for
7155 details.
7156
7157 @item @command{/usr/xpg4/bin/sh} on Solaris
7158 @cindex @command{/usr/xpg4/bin/sh} on Solaris
7159 The @sc{posix}-compliant Bourne shell on a Solaris system is
7160 @command{/usr/xpg4/bin/sh} and is part of an extra optional package.
7161 There is no extra charge for this package, but it is also not part of a
7162 minimal OS install and therefore some folks may not have it.
7163
7164 @item Zsh
7165 @cindex Zsh
7166 To detect whether you are running @command{zsh}, test if
7167 @code{ZSH_VERSION} is set. By default @command{zsh} is @emph{not}
7168 compatible with the Bourne shell: you have to run @samp{emulate sh} and
7169 set @code{NULLCMD} to @samp{:}. @xref{Compatibility,, Compatibility,
7170 zsh, The Z Shell Manual}, for details.
7171
7172 Zsh 3.0.8 is the native @command{/bin/sh} on Mac OS X 10.0.3.
7173 @end table
7174
7175 The following discussion between Russ Allbery and Robert Lipe is worth
7176 reading:
7177
7178 @noindent
7179 Russ Allbery:
7180
7181 @quotation
7182 The @sc{gnu} assumption that @command{/bin/sh} is the one and only shell
7183 leads to a permanent deadlock. Vendors don't want to break user's
7184 existent shell scripts, and there are some corner cases in the Bourne
7185 shell that are not completely compatible with a @sc{posix} shell. Thus,
7186 vendors who have taken this route will @emph{never} (OK@dots{}``never say
7187 never'') replace the Bourne shell (as @command{/bin/sh}) with a
7188 @sc{posix} shell.
7189 @end quotation
7190
7191 @noindent
7192 Robert Lipe:
7193
7194 @quotation
7195 This is exactly the problem. While most (at least most System V's) do
7196 have a bourne shell that accepts shell functions most vendor
7197 @command{/bin/sh} programs are not the @sc{posix} shell.
7198
7199 So while most modern systems do have a shell _somewhere_ that meets the
7200 @sc{posix} standard, the challenge is to find it.
7201 @end quotation
7202
7203 @node Here-Documents, File Descriptors, Shellology, Portable Shell
7204 @section Here-Documents
7205
7206 Don't rely on @samp{\} being preserved just because it has no special
7207 meaning together with the next symbol. in the native @command{/bin/sh}
7208 on OpenBSD 2.7 @samp{\"} expands to @samp{"} in here-documents with
7209 unquoted delimiter. As a general rule, if @samp{\\} expands to @samp{\}
7210 use @samp{\\} to get @samp{\}.
7211
7212 With OpenBSD 2.7's @command{/bin/sh}
7213
7214 @example
7215 @group
7216 $ cat <<EOF
7217 > \" \\
7218 > EOF
7219 " \
7220 @end group
7221 @end example
7222
7223 @noindent
7224 and with Bash:
7225
7226 @example
7227 @group
7228 bash-2.04$ cat <<EOF
7229 > \" \\
7230 > EOF
7231 \" \
7232 @end group
7233 @end example
7234
7235
7236 Many older shells (including the Bourne shell) implement here-documents
7237 inefficiently. Users can generally speed things up by using a faster
7238 shell, e.g., by using the command @samp{bash ./configure} rather than
7239 plain @samp{./configure}.
7240
7241 Some shells can be extremely inefficient when there are a lot of
7242 here-documents inside a single statement. For instance if your
7243 @file{configure.ac} includes something like:
7244
7245 @example
7246 @group
7247 if <cross_compiling>; then
7248 assume this and that
7249 else
7250 check this
7251 check that
7252 check something else
7253 @dots{}
7254 on and on forever
7255 @dots{}
7256 fi
7257 @end group
7258 @end example
7259
7260 A shell parses the whole @code{if}/@code{fi} construct, creating
7261 temporary files for each here document in it. Some shells create links
7262 for such here-documents on every @code{fork}, so that the clean-up code
7263 they had installed correctly removes them. It is creating the links
7264 that the shell can take forever.
7265
7266 Moving the tests out of the @code{if}/@code{fi}, or creating multiple
7267 @code{if}/@code{fi} constructs, would improve the performance
7268 significantly. Anyway, this kind of construct is not exactly the
7269 typical use of Autoconf. In fact, it's even not recommended, because M4
7270 macros can't look into shell conditionals, so we may fail to expand a
7271 macro when it was expanded before in a conditional path, and the
7272 condition turned out to be false at run-time, and we end up not
7273 executing the macro at all.
7274
7275 @node File Descriptors, File System Conventions, Here-Documents, Portable Shell
7276 @section File Descriptors
7277
7278 Some file descriptors shall not be used, since some systems, admittedly
7279 arcane, use them for special purpose:
7280
7281 @table @asis
7282 @item 3
7283 some systems may open it to @samp{/dev/tty}.
7284
7285 @item 4
7286 used on the Kubota Titan.
7287 @end table
7288
7289 Don't redirect several times the same file descriptor, as you are doomed
7290 to failure under Ultrix.
7291
7292 @example
7293 ULTRIX V4.4 (Rev. 69) System #31: Thu Aug 10 19:42:23 GMT 1995
7294 UWS V4.4 (Rev. 11)
7295 $ eval 'echo matter >fullness' >void
7296 illegal io
7297 $ eval '(echo matter >fullness)' >void
7298 illegal io
7299 $ (eval '(echo matter >fullness)') >void
7300 Ambiguous output redirect.
7301 @end example
7302
7303 @noindent
7304 In each case the expected result is of course @file{fullness} containing
7305 @samp{matter} and @file{void} being empty.
7306
7307 Don't try to redirect the standard error of a command substitution: it
7308 must be done @emph{inside} the command substitution: when running
7309 @samp{: `cd /zorglub` 2>/dev/null} expect the error message to
7310 escape, while @samp{: `cd /zorglub 2>/dev/null`} works properly.
7311
7312 It is worth noting that Zsh (but not Ash nor Bash) makes it possible
7313 in assignments though: @samp{foo=`cd /zorglub` 2>/dev/null}.
7314
7315 Most shells, if not all (including Bash, Zsh, Ash), output traces on
7316 stderr, even for sub-shells. This might result in undesired content
7317 if you meant to capture the standard-error output of the inner command:
7318
7319 @example
7320 $ ash -x -c '(eval "echo foo >&2") 2>stderr'
7321 $ cat stderr
7322 + eval echo foo >&2
7323 + echo foo
7324 foo
7325 $ bash -x -c '(eval "echo foo >&2") 2>stderr'
7326 $ cat stderr
7327 + eval 'echo foo >&2'
7328 ++ echo foo
7329 foo
7330 $ zsh -x -c '(eval "echo foo >&2") 2>stderr'
7331 @i{# Traces on startup files deleted here.}
7332 $ cat stderr
7333 +zsh:1> eval echo foo >&2
7334 +zsh:1> echo foo
7335 foo
7336 @end example
7337
7338 @noindent
7339 You'll appreciate the various levels of detail@dots{}
7340
7341 One workaround is to grep out uninteresting lines, hoping not to remove
7342 good ones@dots{}
7343
7344 @node File System Conventions, Shell Substitutions, File Descriptors, Portable Shell
7345 @section File System Conventions
7346
7347 While @command{autoconf} and friends will usually be run on some Unix
7348 variety, it can and will be used on other systems, most notably @sc{dos}
7349 variants. This impacts several assumptions regarding file and
7350 path names.
7351
7352 @noindent
7353 For example, the following code:
7354
7355 @example
7356 case $foo_dir in
7357 /*) # Absolute
7358 ;;
7359 *)
7360 foo_dir=$dots$foo_dir ;;
7361 esac
7362 @end example
7363
7364 @noindent
7365 will fail to properly detect absolute paths on those systems, because
7366 they can use a drivespec, and will usually use a backslash as directory
7367 separator. The canonical way to check for absolute paths is:
7368
7369 @example
7370 case $foo_dir in
7371 [\\/]* | ?:[\\/]* ) # Absolute
7372 ;;
7373 *)
7374 foo_dir=$dots$foo_dir ;;
7375 esac
7376 @end example
7377
7378 @noindent
7379 Make sure you quote the brackets if appropriate and keep the backslash as
7380 first character (@pxref{Limitations of Builtins}).
7381
7382 Also, because the colon is used as part of a drivespec, these systems don't
7383 use it as path separator. When creating or accessing paths, use
7384 @code{$ac_path_separator} instead (or the @code{PATH_SEPARATOR} output
7385 variable). @command{autoconf} sets this to the appropriate value (@samp{:}
7386 or @samp{;}) when it starts up.
7387
7388 File names need extra care as well. While @sc{dos}-based environments
7389 that are Unixy enough to run @command{autoconf} (such as DJGPP) will
7390 usually be able to handle long file names properly, there are still
7391 limitations that can seriously break packages. Several of these issues
7392 can be easily detected by the
7393 @href{ftp://ftp.gnu.org/gnu/non-gnu/doschk/doschk-1.1.tar.gz, doschk}
7394 package.
7395
7396 A short overview follows; problems are marked with @sc{sfn}/@sc{lfn} to
7397 indicate where they apply: @sc{sfn} means the issues are only relevant to
7398 plain @sc{dos}, not to @sc{dos} boxes under Windows, while @sc{lfn}
7399 identifies problems that exist even under Windows.
7400
7401 @table @asis
7402 @item No multiple dots (@sc{sfn})
7403 @sc{dos} cannot handle multiple dots in filenames. This is an especially
7404 important thing to remember when building a portable configure script,
7405 as @command{autoconf} uses a .in suffix for template files.
7406
7407 This is perfectly OK on Unices:
7408
7409 @example
7410 AC_CONFIG_HEADER(config.h)
7411 AC_CONFIG_FILES([source.c foo.bar])
7412 AC_OUTPUT
7413 @end example
7414
7415 @noindent
7416 but it causes problems on @sc{dos}, as it requires @samp{config.h.in},
7417 @samp{source.c.in} and @samp{foo.bar.in}. To make your package more portable
7418 to @sc{dos}-based environments, you should use this instead:
7419
7420 @example
7421 AC_CONFIG_HEADER(config.h:config.hin)
7422 AC_CONFIG_FILES([source.c:source.cin foo.bar:foobar.in])
7423 AC_OUTPUT
7424 @end example
7425
7426 @item No leading dot (@sc{sfn})
7427 @sc{dos} cannot handle filenames that start with a dot. This is usually
7428 not a very important issue for @command{autoconf}.
7429
7430 @item Case insensitivity (@sc{lfn})
7431 @sc{dos} is case insensitive, so you cannot, for example, have both a
7432 file called @samp{INSTALL} and a directory called @samp{install}. This
7433 also affects @command{make}; if there's a file called @samp{INSTALL} in
7434 the directory, @command{make install} will do nothing (unless the
7435 @samp{install} target is marked as PHONY).
7436
7437 @item The 8+3 limit (@sc{sfn})
7438 Because the @sc{dos} file system only stores the first 8 characters of
7439 the filename and the first 3 of the extension, those must be unique.
7440 That means that @file{foobar-part1.c}, @file{foobar-part2.c} and
7441 @file{foobar-prettybird.c} all resolve to the same filename
7442 (@file{FOOBAR-P.C}). The same goes for @file{foo.bar} and
7443 @file{foo.bartender}.
7444
7445 Note: This is not usually a problem under Windows, as it uses numeric
7446 tails in the short version of filenames to make them unique. However, a
7447 registry setting can turn this behaviour off. While this makes it
7448 possible to share file trees containing long file names between @sc{sfn}
7449 and @sc{lfn} environments, it also means the above problem applies there
7450 as well.
7451
7452 @item Invalid characters
7453 Some characters are invalid in @sc{dos} filenames, and should therefore
7454 be avoided. In a @sc{lfn} environment, these are @samp{/}, @samp{\},
7455 @samp{?}, @samp{*}, @samp{:}, @samp{<}, @samp{>}, @samp{|} and @samp{"}.
7456 In a @sc{sfn} environment, other characters are also invalid. These
7457 include @samp{+}, @samp{,}, @samp{[} and @samp{]}.
7458 @end table
7459
7460 @node Shell Substitutions, Assignments, File System Conventions, Portable Shell
7461 @section Shell Substitutions
7462
7463 Contrary to a persistent urban legend, the Bourne shell does not
7464 systematically split variables and backquoted expressions, in particular
7465 on the right-hand side of assignments and in the argument of @code{case}.
7466 For instance, the following code:
7467
7468 @example
7469 case "$given_srcdir" in
7470 .) top_srcdir="`echo "$dots" | sed 's,/$,,'`"
7471 *) top_srcdir="$dots$given_srcdir" ;;
7472 esac
7473 @end example
7474
7475 @noindent
7476 is more readable when written as:
7477
7478 @example
7479 case $given_srcdir in
7480 .) top_srcdir=`echo "$dots" | sed 's,/$,,'`
7481 *) top_srcdir=$dots$given_srcdir ;;
7482 esac
7483 @end example
7484
7485 @noindent
7486 and in fact it is even @emph{more} portable: in the first case of the
7487 first attempt, the computation of @code{top_srcdir} is not portable,
7488 since not all shells properly understand @code{"`@dots{}"@dots{}"@dots{}`"}.
7489 Worse yet, not all shells understand @code{"`@dots{}\"@dots{}\"@dots{}`"}
7490 the same way. There is just no portable way to use double-quoted
7491 strings inside double-quoted backquoted expressions (pfew!).
7492
7493 @table @code
7494 @item $@@
7495 @cindex @samp{"$@@"}
7496 One of the most famous shell-portability issues is related to
7497 @samp{"$@@"}: when there are no positional arguments, it is supposed to
7498 be equivalent to nothing. But some shells, for instance under Digital
7499 Unix 4.0 and 5.0, will then replace it with an empty argument. To be
7500 portable, use @samp{$@{1+"$@@"@}}.
7501
7502 @item $@{@var{var}:-@var{value}@}
7503 @cindex $@{@var{var}:-@var{value}@}
7504 Old @sc{bsd} shells, including the Ultrix @code{sh}, don't accept the
7505 colon for any shell substitution, and complain and die.
7506
7507 @item $@{@var{var}=@var{literal}@}
7508 @cindex $@{@var{var}=@var{literal}@}
7509 Be sure to quote:
7510
7511 @example
7512 : $@{var='Some words'@}
7513 @end example
7514
7515 @noindent
7516 otherwise some shells, such as on Digital Unix V 5.0, will die because
7517 of a ``bad substitution''.
7518
7519 Solaris' @command{/bin/sh} has a frightening bug in its interpretation
7520 of this. Imagine you need set a variable to a string containing
7521 @samp{@}}. This @samp{@}} character confuses Solaris' @command{/bin/sh}
7522 when the affected variable was already set. This bug can be exercised
7523 by running:
7524
7525 @example
7526 $ unset foo
7527 $ foo=$@{foo='@}'@}
7528 $ echo $foo
7529 @}
7530 $ foo=$@{foo='@}' # no error; this hints to what the bug is
7531 $ echo $foo
7532 @}
7533 $ foo=$@{foo='@}'@}
7534 $ echo $foo
7535 @}@}
7536 ^ ugh!
7537 @end example
7538
7539 It seems that @samp{@}} is interpreted as matching @samp{$@{}, even
7540 though it is enclosed in single quotes. The problem doesn't happen
7541 using double quotes.
7542
7543 @item $@{@var{var}=@var{expanded-value}@}
7544 @cindex $@{@var{var}=@var{expanded-value}@}
7545 On Ultrix,
7546 running
7547
7548 @example
7549 default="yu,yaa"
7550 : $@{var="$default"@}
7551 @end example
7552
7553 @noindent
7554 will set @var{var} to @samp{M-yM-uM-,M-yM-aM-a}, i.e., the 8th bit of
7555 each char will be set. You won't observe the phenomenon using a simple
7556 @samp{echo $var} since apparently the shell resets the 8th bit when it
7557 expands $var. Here are two means to make this shell confess its sins:
7558
7559 @example
7560 $ cat -v <<EOF
7561 $var
7562 EOF
7563 @end example
7564
7565 @noindent
7566 and
7567
7568 @example
7569 $ set | grep '^var=' | cat -v
7570 @end example
7571
7572 One classic incarnation of this bug is:
7573
7574 @example
7575 default="a b c"
7576 : $@{list="$default"@}
7577 for c in $list; do
7578 echo $c
7579 done
7580 @end example
7581
7582 @noindent
7583 You'll get @samp{a b c} on a single line. Why? Because there are no
7584 spaces in @samp{$list}: there are @samp{M- }, i.e., spaces with the 8th
7585 bit set, hence no IFS splitting is performed!!!
7586
7587 One piece of good news is that Ultrix works fine with @samp{:
7588 $@{list=$default@}}; i.e., if you @emph{don't} quote. The bad news is
7589 then that @sc{qnx} 4.25 then sets @var{list} to the @emph{last} item of
7590 @var{default}!
7591
7592 The portable way out consists in using a double assignment, to switch
7593 the 8th bit twice on Ultrix:
7594
7595 @example
7596 list=$@{list="$default"@}
7597 @end example
7598
7599 @noindent
7600 @dots{}but beware of the @samp{@}} bug from Solaris (see above). For safety,
7601 use:
7602
7603 @example
7604 test "$@{var+set@}" = set || var=@var{@{value@}}
7605 @end example
7606
7607
7608 @item `@var{commands}`
7609 @cindex `@var{commands}`
7610 @cindex Command Substitution
7611 While in general it makes no sense, do not substitute a single builtin
7612 with side effects as Ash 0.2, trying to optimize, does not fork a
7613 sub-shell to perform the command.
7614
7615 For instance, if you wanted to check that @command{cd} is silent, do not
7616 use @samp{test -z "`cd /`"} because the following can happen:
7617
7618 @example
7619 $ pwd
7620 /tmp
7621 $ test -n "`cd /`" && pwd
7622 /
7623 @end example
7624
7625 @noindent
7626 The result of @samp{foo=`exit 1`} is left as an exercise to the reader.
7627
7628
7629 @item $(@var{commands})
7630 @cindex $(@var{commands})
7631 This construct is meant to replace @samp{`@var{commands}`}; they can be
7632 nested while this is impossible to do portably with back quotes.
7633 Unfortunately it is not yet widely supported. Most notably, even recent
7634 releases of Solaris don't support it:
7635
7636 @example
7637 $ showrev -c /bin/sh | grep version
7638 Command version: SunOS 5.8 Generic 109324-02 February 2001
7639 $ echo $(echo blah)
7640 syntax error: `(' unexpected
7641 @end example
7642
7643 @noindent
7644 nor does @sc{irix} 6.5's Bourne shell:
7645 @example
7646 $ uname -a
7647 IRIX firebird-image 6.5 07151432 IP22
7648 $ echo $(echo blah)
7649 $(echo blah)
7650 @end example
7651 @end table
7652
7653
7654 @node Assignments, Special Shell Variables, Shell Substitutions, Portable Shell
7655 @section Assignments
7656
7657 When setting several variables in a row, be aware that the order of the
7658 evaluation is undefined. For instance @samp{foo=1 foo=2; echo $foo}
7659 gives @samp{1} with sh on Solaris, but @samp{2} with Bash. You must use
7660 @samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}.
7661
7662 Don't rely on the exit status of an assignment: Ash 0.2 does not change
7663 the status and propagates that of the last statement:
7664
7665 @example
7666 $ false || foo=bar; echo $?
7667 1
7668 $ false || foo=`:`; echo $?
7669 0
7670 @end example
7671
7672 @noindent
7673 and to make things even worse, @sc{qnx 4.25} just sets the exit status
7674 to 0 in any case:
7675
7676 @example
7677 $ foo=`exit 1`; echo $?
7678 0
7679 @end example
7680
7681 To assign default values, follow this algorithm:
7682
7683 @enumerate
7684 @item
7685 If the default value is a literal and does not contain any closing
7686 brace, use:
7687
7688 @example
7689 : $@{var='my literal'@}
7690 @end example
7691
7692 @item
7693 If the default value contains no closing brace, has to be expanded, and
7694 the variable being initialized will never be IFS-split (i.e., it's not a
7695 list), then use:
7696
7697 @example
7698 : $@{var="$default"@}
7699 @end example
7700
7701 @item
7702 If the default value contains no closing brace, has to be expanded, and
7703 the variable being initialized will be IFS-split (i.e., it's a list),
7704 then use:
7705
7706 @example
7707 var=$@{var="$default"@}
7708 @end example
7709
7710 @item
7711 If the default value contains a closing brace, then use:
7712
7713 @example
7714 test "$@{var+set@}" = set || var='$@{indirection@}'
7715 @end example
7716 @end enumerate
7717
7718 In most cases @samp{var=$@{var="$default"@}} is fine, but in case of
7719 doubt, just use the latter. @xref{Shell Substitutions}, items
7720 @samp{$@{@var{var}:-@var{value}@}} and @samp{$@{@var{var}=@var{value}@}}
7721 for the rationale.
7722
7723
7724 @node Special Shell Variables, Limitations of Builtins, Assignments, Portable Shell
7725 @section Special Shell Variables
7726
7727 Some shell variables should not be used, since they can have a deep
7728 influence on the behavior of the shell. In order to recover a sane
7729 behavior from the shell, some variables should be unset, but
7730 @command{unset} is not portable (@pxref{Limitations of Builtins}) and a
7731 fallback value is needed. We list these values below.
7732
7733 @c Alphabetical order, case insensitive, `A' before `a'.
7734 @table @code
7735 @item CDPATH
7736 @evindex CDPATH
7737 When this variable is set @code{cd} is verbose, so idioms such as
7738 @samp{abs=`cd $rel && pwd`} break because @code{abs} receives the path
7739 twice.
7740
7741 @c FIXME: Which shells? How do they behave?
7742 Setting @code{CDPATH} to the empty value is not enough for most shells.
7743 A simple colon is enough except for @code{zsh}, which prefers a leading
7744 dot:
7745
7746 @example
7747 zsh-3.1.6 % mkdir foo && (CDPATH=: cd foo)
7748 /tmp/foo
7749 zsh-3.1.6 % (CDPATH=:. cd foo)
7750 /tmp/foo
7751 zsh-3.1.6 % (CDPATH=.: cd foo)
7752 zsh-3.1.6 %
7753 @end example
7754
7755 @noindent
7756 (of course we could just @code{unset} @code{CDPATH}, since it also
7757 behaves properly if set to the empty string).
7758
7759 Life wouldn't be so much fun if @command{bash} and @command{zsh} had the
7760 same behavior:
7761
7762 @example
7763 bash-2.02 % (CDPATH=:. cd foo)
7764 bash-2.02 % (CDPATH=.: cd foo)
7765 /tmp/foo
7766 @end example
7767
7768 Therefore, a portable solution to neutralize @samp{CDPATH} is
7769
7770 @example
7771 CDPATH=$@{ZSH_VERSION+.@}:
7772 @end example
7773
7774 @noindent
7775 Note that since @command{zsh} supports @command{unset}, you may unset
7776 @samp{CDPATH} using @samp{:} as a fallback, see
7777 @ref{Limitations of Builtins}.
7778
7779 @item IFS
7780 @evindex IFS
7781 Don't set the first character of @code{IFS} to backslash. Indeed,
7782 Bourne shells use the first character (backslash) when joining the
7783 components in @samp{"$@@"} and some shells then re-interpret (!) the
7784 backslash escapes, so you can end up with backspace and other strange
7785 characters.
7786
7787 @item LANG
7788 @itemx LC_ALL
7789 @itemx LC_TIME
7790 @itemx LC_CTYPE
7791 @itemx LANGUAGE
7792 @itemx LC_COLLATE
7793 @itemx LC_NUMERIC
7794 @itemx LC_MESSAGES
7795 @evindex LANG
7796 @evindex LC_ALL
7797 @evindex LC_TIME
7798 @evindex LC_CTYPE
7799 @evindex LANGUAGE
7800 @evindex LC_COLLATE
7801 @evindex LC_NUMERIC
7802 @evindex LC_MESSAGES
7803
7804 These must not be set unconditionally because not all systems understand
7805 e.g. @samp{LANG=C} (notably SCO). Fixing @env{LC_MESSAGES} prevents
7806 Solaris @command{sh} from translating var values in @code{set}! Non-C
7807 @env{LC_CTYPE} values break the ctype check. Fixing @env{LC_COLLATE}
7808 makes scripts more portable in some cases. For example, it causes the
7809 regular expression @samp{[a-z]} to match only lower-case letters on
7810 @sc{ascii} platforms. However, @samp{[a-z]} does not work in general
7811 even when @env{LC_COLLATE} is fixed; for example, it does not work for
7812 @sc{ebcdic} platforms. For maximum portability, you should use regular
7813 expressions like @samp{[abcdefghijklmnopqrstuvwxyz]} that list
7814 characters explicitly instead of relying on ranges.
7815
7816 @emph{If} one of these variables is set, you should try to unset it,
7817 using @samp{C} as a fall back value. see @ref{Limitations of Builtins},
7818 builtin @command{unset}, for more details.
7819
7820 @item NULLCMD
7821 @evindex NULLCMD
7822 When executing the command @samp{>foo}, @command{zsh} executes
7823 @samp{$NULLCMD >foo}. The Bourne shell considers @code{NULLCMD} is
7824 @samp{:}, while @command{zsh}, even in Bourne shell compatibility mode,
7825 sets @code{NULLCMD} to @samp{cat}. If you forgot to set @code{NULLCMD},
7826 your script might be suspended waiting for data on its standard input.
7827
7828 @item status
7829 @evindex status
7830 This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6),
7831 hence read-only. Do not use it.
7832
7833 @item PATH_SEPARATOR
7834 @evindex PATH_SEPARATOR
7835 On DJGPP systems, the @code{PATH_SEPARATOR} variable can be set to
7836 either @samp{:} or @samp{;} to control the path separator @command{bash}
7837 uses to set up certain environment variables (such as
7838 @code{PATH}). Since this only works inside bash, you want autoconf to
7839 detect the regular @sc{dos} path separator @samp{;}, so it can be safely
7840 substituted in files that may not support @samp{;} as path separator. So
7841 either unset this variable or set it to @samp{;}.
7842
7843 @item RANDOM
7844 @evindex RANDOM
7845 Many shells provide @code{RANDOM}, a variable that returns a different
7846 integer when used. Most of the time, its value does not change when it
7847 is not used, but on @sc{irix 6.5} the value changes all the time. This
7848 can be observed by using @command{set}.
7849 @end table
7850
7851
7852 @node Limitations of Builtins, Limitations of Usual Tools, Special Shell Variables, Portable Shell
7853 @section Limitations of Shell Builtins
7854
7855 No, no, we are serious: some shells do have limitations! :)
7856
7857 You should always keep in mind that any built-in or command may support
7858 options, and therefore have a very different behavior with arguments
7859 starting with a dash. For instance, the innocent @samp{echo "$word"}
7860 can give unexpected results when @code{word} starts with a dash. It is
7861 often possible to avoid this problem using @samp{echo "x$word"}, taking
7862 the @samp{x} into account later in the pipe.
7863
7864 @table @asis
7865 @item @command{!}
7866 @cindex @command{!}
7867 You can't use @command{!}, you'll have to rewrite your code.
7868
7869
7870 @item @command{break}
7871 @c ------------------
7872 @cindex @command{break}
7873 The use of @samp{break 2}, etcetera, is safe.
7874
7875
7876 @item @command{case}
7877 @c -----------------
7878 @cindex @command{case}
7879 You don't need to quote the argument; no splitting is performed.
7880
7881 You don't need the final @samp{;;}, but you should use it.
7882
7883 Because of a bug in its @code{fnmatch}, @command{bash} fails to properly
7884 handle backslashes in character classes:
7885
7886 @example
7887 bash-2.02$ case /tmp in [/\\]*) echo OK;; esac
7888 bash-2.02$
7889 @end example
7890
7891 @noindent
7892 This is extremely unfortunate, since you are likely to use this code to
7893 handle @sc{unix} or @sc{ms-dos} absolute paths. To work around this
7894 bug, always put the backslash first:
7895
7896 @example
7897 bash-2.02$ case '\TMP' in [\\/]*) echo OK;; esac
7898 OK
7899 bash-2.02$ case /tmp in [\\/]*) echo OK;; esac
7900 OK
7901 @end example
7902
7903
7904 @item @command{echo}
7905 @c -----------------
7906 @cindex @command{echo}
7907 The simple @code{echo} is probably the most surprising source of
7908 portability troubles. It is not possible to use @samp{echo} portably
7909 unless both options and escape sequences are omitted. New applications
7910 which are not aiming at portability should use @samp{printf} instead of
7911 @samp{echo}.
7912
7913 Don't expect any option. @xref{Preset Output Variables}, @code{ECHO_N}
7914 etc. for a means to simulate @option{-c}.
7915
7916 Do not use backslashes in the arguments, as there is no consensus on
7917 their handling. On @samp{echo '\n' | wc -l}, the @command{sh} of
7918 Digital Unix 4.0, @sc{mips risc/os} 4.52, answer 2, but the Solaris'
7919 @command{sh}, Bash and Zsh (in @command{sh} emulation mode) report 1.
7920 Please note that the problem is truly @command{echo}: all the shells
7921 understand @samp{'\n'} as the string composed of a backslash and an
7922 @samp{n}.
7923
7924 Because of these problems, do not pass a string containing arbitrary
7925 characters to @command{echo}. For example, @samp{echo "$foo"} is safe
7926 if you know that @var{foo}'s value cannot contain backslashes and cannot
7927 start with @samp{-}, but otherwise you should use a here-document like
7928 this:
7929
7930 @example
7931 cat <<EOF
7932 $foo
7933 EOF
7934 @end example
7935
7936
7937 @item @command{exit}
7938 @c -----------------
7939 @cindex @command{exit}
7940 The default value of @command{exit} is supposed to be @code{$?};
7941 unfortunately, some shells, such as the DJGPP port of Bash 2.04, just
7942 perform @samp{exit 0}.
7943
7944 @example
7945 bash-2.04$ foo=`exit 1` || echo fail
7946 fail
7947 bash-2.04$ foo=`(exit 1)` || echo fail
7948 fail
7949 bash-2.04$ foo=`(exit 1); exit` || echo fail
7950 bash-2.04$
7951 @end example
7952
7953 Using @samp{exit $?} restores the expected behavior.
7954
7955 Some shell scripts, such as those generated by @command{autoconf}, use a
7956 trap to clean up before exiting. If the last shell command exited with
7957 nonzero status, the trap also exits with nonzero status so that the
7958 invoker can tell that an error occurred.
7959
7960 Unfortunately, in some shells, such as Solaris 8 @command{sh}, an exit
7961 trap ignores the @code{exit} command's status. In these shells, a trap
7962 cannot determine whether it was invoked by plain @code{exit} or by
7963 @code{exit 1}. Instead of calling @code{exit} directly, use the
7964 @code{AC_MSG_ERROR} macro that has a workaround for this problem.
7965
7966
7967 @item @command{export}
7968 @c -------------------
7969 @cindex @command{export}
7970 The builtin @command{export} dubs @dfn{environment variable} a shell
7971 variable. Each update of exported variables corresponds to an update of
7972 the environment variables. Conversely, each environment variable
7973 received by the shell when it is launched should be imported as a shell
7974 variable marked as exported.
7975
7976 Alas, many shells, such as Solaris 2.5, IRIX 6.3, IRIX 5.2, AIX 4.1.5
7977 and DU 4.0, forget to @command{export} the environment variables they
7978 receive. As a result, two variables are coexisting: the environment
7979 variable and the shell variable. The following code demonstrates this
7980 failure:
7981
7982 @example
7983 #! /bin/sh
7984 echo $FOO
7985 FOO=bar
7986 echo $FOO
7987 exec /bin/sh $0
7988 @end example
7989
7990 @noindent
7991 when run with @samp{FOO=foo} in the environment, these shells will print
7992 alternately @samp{foo} and @samp{bar}, although it should only print
7993 @samp{foo} and then a sequence of @samp{bar}s.
7994
7995 Therefore you should @command{export} again each environment variable
7996 that you update.
7997
7998
7999 @item @command{false}
8000 @c ------------------
8001 @cindex @command{false}
8002 Don't expect @command{false} to exit with status 1: in the native Bourne
8003 shell of Solaris 8, it exits with status 255.
8004
8005
8006 @item @command{for}
8007 @c ----------------
8008 @cindex @command{for}
8009 To loop over positional arguments, use:
8010
8011 @example
8012 for arg
8013 do
8014 echo "$arg"
8015 done
8016 @end example
8017
8018 @noindent
8019 You may @emph{not} leave the @code{do} on the same line as @code{for},
8020 since some shells improperly grok:
8021
8022 @example
8023 for arg; do
8024 echo "$arg"
8025 done
8026 @end example
8027
8028 If you want to explicitly refer to the positional arguments, given the
8029 @samp{$@@} bug (@pxref{Shell Substitutions}), use:
8030
8031 @example
8032 for arg in $@{1+"$@@"@}; do
8033 echo "$arg"
8034 done
8035 @end example
8036
8037 @item @command{if}
8038 @c ---------------
8039 @cindex @command{if}
8040 Using @samp{!} is not portable. Instead of:
8041
8042 @example
8043 if ! cmp -s file file.new; then
8044 mv file.new file
8045 fi
8046 @end example
8047
8048 @noindent
8049 use:
8050
8051 @example
8052 if cmp -s file file.new; then :; else
8053 mv file.new file
8054 fi
8055 @end example
8056
8057 There are shells that do not reset the exit status from an @command{if}:
8058
8059 @example
8060 $ if (exit 42); then true; fi; echo $?
8061 42
8062 @end example
8063
8064 @noindent
8065 whereas a proper shell should have printed @samp{0}. This is especially
8066 bad in Makefiles since it produces false failures. This is why properly
8067 written Makefiles, such as Automake's, have such hairy constructs:
8068
8069 @example
8070 if test -f "$file"; then
8071 install "$file" "$dest"
8072 else
8073 :
8074 fi
8075 @end example
8076
8077
8078 @item @command{set}
8079 @c ----------------
8080 @cindex @command{set}
8081 This builtin faces the usual problem with arguments starting with a
8082 dash. Modern shells such as Bash or Zsh understand @option{--} to specify
8083 the end of the options (any argument after @option{--} is a parameters,
8084 even @samp{-x} for instance), but most shells simply stop the option
8085 processing as soon as a non-option argument is found. Therefore, use
8086 @samp{dummy} or simply @samp{x} to end the option processing, and use
8087 @command{shift} to pop it out:
8088
8089 @example
8090 set x $my_list; shift
8091 @end example
8092
8093 @item @command{shift}
8094 @c ------------------
8095 @cindex @command{shift}
8096 Not only is @command{shift}ing a bad idea when there is nothing left to
8097 shift, but in addition it is not portable: the shell of @sc{mips
8098 risc/os} 4.52 refuses to do it.
8099
8100 @item @command{test}
8101 @c -----------------
8102 @cindex @command{test}
8103 The @code{test} program is the way to perform many file and string
8104 tests. It is often invoked by the alternate name @samp{[}, but using
8105 that name in Autoconf code is asking for trouble since it is an M4 quote
8106 character.
8107
8108 If you need to make multiple checks using @code{test}, combine them with
8109 the shell operators @samp{&&} and @samp{||} instead of using the
8110 @code{test} operators @option{-a} and @option{-o}. On System V, the
8111 precedence of @option{-a} and @option{-o} is wrong relative to the unary
8112 operators; consequently, @sc{posix} does not specify them, so using them
8113 is nonportable. If you combine @samp{&&} and @samp{||} in the same
8114 statement, keep in mind that they have equal precedence.
8115
8116 You may use @samp{!} with @command{test}, but not with @command{if}:
8117 @samp{test ! -r foo || exit 1}.
8118
8119 @item @command{test} (files)
8120 @c -------------------------
8121 To enable @code{configure} scripts to support cross-compilation, they
8122 shouldn't do anything that tests features of the build system instead of
8123 the host system. But occasionally you may find it necessary to check
8124 whether some arbitrary file exists. To do so, use @samp{test -f} or
8125 @samp{test -r}. Do not use @samp{test -x}, because @sc{4.3bsd} does not
8126 have it. Do not use @samp{test -e} either, because Solaris 2.5 does not
8127 have it.
8128
8129 @item @command{test} (strings)
8130 @c ---------------------------
8131 Avoid @samp{test "@var{string}"}, in particular if @var{string} might
8132 start with a dash, since @code{test} might interpret its argument as an
8133 option (e.g., @samp{@var{string} = "-n"}).
8134
8135 Contrary to a common belief, @samp{test -n @var{string}} and @samp{test
8136 -z @var{string}} @strong{are} portable, nevertheless many shells (such
8137 as Solaris 2.5, AIX 3.2, UNICOS 10.0.0.6, Digital Unix 4 etc.) have
8138 bizarre precedence and may be confused if @var{string} looks like an
8139 operator:
8140
8141 @example
8142 $ test -n =
8143 test: argument expected
8144 @end example
8145
8146 If there are risks, use @samp{test "x@var{string}" = x} or @samp{test
8147 "x@var{string}" != x} instead.
8148
8149 It is frequent to find variations of the following idiom:
8150
8151 @example
8152 test -n "`echo $ac_feature | sed 's/[-a-zA-Z0-9_]//g'`" &&
8153 @var{action}
8154 @end example
8155
8156 @noindent
8157 to take an action when a token matches a given pattern. Such constructs
8158 should always be avoided by using:
8159
8160 @example
8161 echo "$ac_feature" | grep '[^-a-zA-Z0-9_]' >/dev/null 2>&1 &&
8162 @var{action}
8163 @end example
8164
8165 @noindent
8166 Use @code{case} where possible since it is faster, being a shell builtin:
8167
8168
8169 @example
8170 case $ac_feature in
8171 *[!-a-zA-Z0-9_]*) @var{action};;
8172 esac
8173 @end example
8174
8175 Alas, negated character classes are probably not portable, although no
8176 shell is known to not support the @sc{posix.2} syntax @samp{[!@dots{}]}
8177 (when in interactive mode, @command{zsh} is confused by the
8178 @samp{[!@dots{}]} syntax and looks for an event in its history because of
8179 @samp{!}). Many shells do not support the alternative syntax
8180 @samp{[^@dots{}]} (Solaris, Digital Unix, etc.).
8181
8182 One solution can be:
8183
8184 @example
8185 expr "$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null &&
8186 @var{action}
8187 @end example
8188
8189 @noindent
8190 or better yet
8191
8192 @example
8193 expr "x$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null &&
8194 @var{action}
8195 @end example
8196
8197 @samp{expr "X@var{foo}" : "X@var{bar}"} is more robust than @samp{echo
8198 "X@var{foo}" | grep "^X@var{bar}"}, because it avoids problems when
8199 @samp{@var{foo}} contains backslashes.
8200
8201
8202 @item @command{trap}
8203 @c -----------------
8204 @cindex @command{trap}
8205 It is safe to trap at least the signals 1, 2, 13 and 15. You can also
8206 trap 0, i.e., have the @command{trap} run when the script ends (either via an
8207 explicit @command{exit}, or the end of the script).
8208
8209 Although @sc{posix} is not absolutely clear on this point, it is widely
8210 admitted that when entering the trap @samp{$?} should be set to the exit
8211 status of the last command run before the trap. The ambiguity can be
8212 summarized as: ``when the trap is launched by an @command{exit}, what is
8213 the @emph{last} command run: that before @command{exit}, or
8214 @command{exit} itself?''
8215
8216 Bash considers @command{exit} to be the last command, while Zsh and
8217 Solaris 8 @command{sh} consider that when the trap is run it is
8218 @emph{still} in the @command{exit}, hence it is the previous exit status
8219 that the trap receives:
8220
8221 @example
8222 $ cat trap.sh
8223 trap 'echo $?' 0
8224 (exit 42); exit 0
8225 $ zsh trap.sh
8226 42
8227 $ bash trap.sh
8228 0
8229 @end example
8230
8231 The portable solution is then simple: when you want to @samp{exit 42},
8232 run @samp{(exit 42); exit 42}, the first @command{exit} being used to
8233 set the exit status to 42 for Zsh, and the second to trigger the trap
8234 and pass 42 as exit status for Bash.
8235
8236 The shell in FreeBSD 4.0 has the following bug: @samp{$?} is reset to 0
8237 by empty lines if the code is inside @command{trap}.
8238
8239 @example
8240 $ trap 'false
8241
8242 echo $?' 0
8243 $ exit
8244 0
8245 @end example
8246
8247 @noindent
8248 Fortunately, this bug only affects @command{trap}.
8249
8250 @item @command{true}
8251 @c -----------------
8252 @cindex @command{true}
8253 @cindex @command{:}
8254 Don't worry: as far as we know @command{true} is portable.
8255 Nevertheless, it's not always a builtin (e.g., Bash 1.x), and the
8256 portable shell community tends to prefer using @command{:}. This has a
8257 funny side effect: when asked whether @command{false} is more portable
8258 than @command{true} Alexandre Oliva answered:
8259
8260 @quotation
8261 In a sense, yes, because if it doesn't exist, the shell will produce an
8262 exit status of failure, which is correct for @command{false}, but not
8263 for @command{true}.
8264 @end quotation
8265
8266
8267 @item @command{unset}
8268 @c ------------------
8269 @cindex @command{unset}
8270 You cannot assume the support of @command{unset}, nevertheless, because
8271 it is extremely useful to disable embarrassing variables such as
8272 @code{CDPATH} or @code{LANG}, you can test for its existence and use
8273 it @emph{provided} you give a neutralizing value when @command{unset} is
8274 not supported:
8275
8276 @example
8277 if (unset FOO) >/dev/null 2>&1; then
8278 unset=unset
8279 else
8280 unset=false
8281 fi
8282 $unset CDPATH || CDPATH=:
8283 @end example
8284
8285 @xref{Special Shell Variables}, for some neutralizing values. Also, see
8286 @ref{Limitations of Builtins}, documentation of @command{export}, for
8287 the case of environment variables.
8288 @end table
8289
8290 @node Limitations of Usual Tools, Limitations of Make, Limitations of Builtins, Portable Shell
8291 @section Limitations of Usual Tools
8292
8293 The small set of tools you can expect to find on any machine can still
8294 include some limitations you should be aware of.
8295
8296 @table @asis
8297 @item @command{awk}
8298 @c ----------------
8299 @cindex @command{awk}
8300 Don't leave white spaces before the parentheses in user functions calls,
8301 @sc{gnu} awk will reject it:
8302
8303 @example
8304 $ gawk 'function die () @{ print "Aaaaarg!" @}
8305 BEGIN @{ die () @}'
8306 gawk: cmd. line:2: BEGIN @{ die () @}
8307 gawk: cmd. line:2: ^ parse error
8308 $ gawk 'function die () @{ print "Aaaaarg!" @}
8309 BEGIN @{ die() @}'
8310 Aaaaarg!
8311 @end example
8312
8313 If you want your program to be deterministic, don't depend on @code{for}
8314 on arrays:
8315
8316 @example
8317 $ cat for.awk
8318 END @{
8319 arr["foo"] = 1
8320 arr["bar"] = 1
8321 for (i in arr)
8322 print i
8323 @}
8324 $ gawk -f for.awk </dev/null
8325 foo
8326 bar
8327 $ nawk -f for.awk </dev/null
8328 bar
8329 foo
8330 @end example
8331
8332 Some AWK, such as HPUX 11.0's native one, have regex engines fragile to
8333 inner anchors:
8334
8335 @example
8336 $ echo xfoo | $AWK '/foo|^bar/ @{ print @}'
8337 $ echo bar | $AWK '/foo|^bar/ @{ print @}'
8338 bar
8339 $ echo xfoo | $AWK '/^bar|foo/ @{ print @}'
8340 xfoo
8341 $ echo bar | $AWK '/^bar|foo/ @{ print @}'
8342 bar
8343 @end example
8344
8345 @noindent
8346 Either do not depend on such patterns (i.e., use @samp{/^(.*foo|bar)/},
8347 or use a simple test to reject such AWK.
8348
8349
8350 @item @command{cat}
8351 @c ----------------
8352 @cindex @command{cat}
8353 Don't rely on any option. The option @option{-v}, which displays
8354 non-printing characters, @emph{seems} portable, though.
8355
8356
8357 @item @command{cc}
8358 @c ---------------
8359 When a compilation such as @samp{cc foo.c -o foo} fails, some compilers
8360 (such as @sc{cds} on Reliant @sc{unix}) leave a @file{foo.o}.
8361
8362
8363 @item @command{cmp}
8364 @c ----------------
8365 @cindex @command{cmp}
8366 @command{cmp} performs a raw data comparison of two files, while
8367 @command{diff} compares two text files. Therefore, if you might compare
8368 DOS files, even if only checking whether two files are different, use
8369 @command{diff} to avoid spurious differences due to differences of
8370 newline encoding.
8371
8372
8373 @item @command{cp}
8374 @c ---------------
8375 @cindex @command{cp}
8376 @c This is thanks to Ian.
8377 SunOS @command{cp} does not support @option{-f}, although its
8378 @command{mv} does. It's possible to deduce why @command{mv} and
8379 @command{cp} are different with respect to @option{-f}. @command{mv}
8380 prompts by default before overwriting a read-only file. @command{cp}
8381 does not. Therefore, @command{mv} requires a @option{-f} option, but
8382 @command{cp} does not. @command{mv} and @command{cp} behave differently
8383 with respect to read-only files because the simplest form of
8384 @command{cp} cannot overwrite a read-only file, but the simplest form of
8385 @command{mv} can. This is because @command{cp} opens the target for
8386 write access, whereas @command{mv} simply calls @code{link} (or, in
8387 newer systems, @code{rename}).
8388 @c Ian said: ``I don't think -p or -r are portable''!!! How can you live
8389 @c without -r???
8390
8391
8392 @item @command{diff}
8393 @c -----------------
8394 @cindex @command{diff}
8395 Option @option{-u} is nonportable.
8396
8397 Some implementations, such as Tru64's, fail when comparing to
8398 @file{/dev/null}. Use an empty file instead.
8399
8400 @item @command{dirname}
8401 @c --------------------
8402 @cindex @command{dirname}
8403 Not all hosts have @command{dirname}, but it is reasonably easy to
8404 emulate, e.g.:
8405
8406 @example
8407 dir=`expr "x$file" : 'x\(.*\)/[^/]*' \|
8408 '.' : '.'
8409 @end example
8410
8411 @noindent
8412 But there are a few subtilities, e.g., under UN*X, should @samp{//1}
8413 give @samp{/}? Paul Eggert answers:
8414
8415 @quotation
8416 No, under some older flavors of Unix, leading @samp{//} is a special
8417 path name: it refers to a ``super-root'' and is used to access other
8418 machines' files. Leading @samp{///}, @samp{////}, etc. are equivalent
8419 to @samp{/}; but leading @samp{//} is special. I think this tradition
8420 started with Apollo Domain/OS, an OS that is still in use on some older
8421 hosts.
8422
8423 POSIX.2 allows but does not require the special treatment for @samp{//}.
8424 It says that the behavior of dirname on path names of the form
8425 @samp{//([^/]+/*)?} is implementation defined. In these cases, GNU
8426 @command{dirname} returns @samp{/}, but it's more portable to return
8427 @samp{//} as this works even on those older flavors of Unix.
8428
8429 I have heard rumors that this special treatment of @samp{//} may be
8430 dropped in future versions of POSIX, but for now it's still the
8431 standard.
8432 @end quotation
8433
8434
8435 @item @command{egrep}
8436 @c ------------------
8437 @cindex @command{egrep}
8438 The empty alternative is not portable, use @samp{?} instead. For
8439 instance with Digital Unix v5.0:
8440
8441 @example
8442 > printf "foo\n|foo\n" | egrep '^(|foo|bar)$'
8443 |foo
8444 > printf "bar\nbar|\n" | egrep '^(foo|bar|)$'
8445 bar|
8446 > printf "foo\nfoo|\n|bar\nbar\n" | egrep '^(foo||bar)$'
8447 foo
8448 |bar
8449 @end example
8450
8451 @command{egrep} also suffers the limitations of @command{grep}.
8452
8453
8454 @item @command{expr}
8455 @c -----------------
8456 @cindex @command{expr}
8457 No @command{expr} keyword starts with @samp{x}, so use @samp{expr
8458 x"@var{word}" : 'x@var{regex}'} to keep @command{expr} from
8459 misinterpreting @var{word}.
8460
8461 Don't use @code{length}, @code{substr}, @code{match} and @code{index}.
8462
8463 @item @command{expr} (@samp{|})
8464 @cindex @command{expr} (@samp{|})
8465 You can use @samp{|}. Although @sc{posix} does require that @samp{expr
8466 ''} return the empty string, it does not specify the result when you
8467 @samp{|} together the empty string (or zero) with the empty string. For
8468 example:
8469
8470 @example
8471 expr '' \| ''
8472 @end example
8473
8474 @sc{gnu}/Linux and @sc{posix.2-1992} return the empty string for this
8475 case, but traditional Unix returns @samp{0} (Solaris is one such
8476 example). In the latest @sc{posix} draft, the specification has been
8477 changed to match traditional Unix's behavior (which is bizarre, but it's
8478 too late to fix this). Please note that the same problem does arise
8479 when the empty string results from a computation, as in:
8480
8481 @example
8482 expr bar : foo \| foo : bar
8483 @end example
8484
8485 @noindent
8486 Avoid this portability problem by avoiding the empty string.
8487
8488
8489 @item @command{expr} (@samp{:})
8490 @c ----------------------------
8491 @cindex @command{expr}
8492 Don't use @samp{\?}, @samp{\+} and @samp{\|} in patterns, they are
8493 not supported on Solaris.
8494
8495 The @sc{posix.2-1992} standard is ambiguous as to whether @samp{expr a :
8496 b} (and @samp{expr 'a' : '\(b\)'}) output @samp{0} or the empty string.
8497 In practice, it outputs the empty string on most platforms, but portable
8498 scripts should not assume this. For instance, the @sc{qnx} 4.25 native
8499 @command{expr} returns @samp{0}.
8500
8501 You may believe that one means to get a uniform behavior would be to use
8502 the empty string as a default value:
8503
8504 @example
8505 expr a : b \| ''
8506 @end example
8507
8508 @noindent
8509 unfortunately this behaves exactly as the original expression, see the
8510 @samp{@command{expr} (@samp{:})} entry for more information.
8511
8512 Older @command{expr} implementations (e.g. SunOS 4 @command{expr} and
8513 Solaris 8 @command{/usr/ucb/expr}) have a silly length limit that causes
8514 @command{expr} to fail if the matched substring is longer than 120
8515 bytes. In this case, you might want to fall back on @samp{echo|sed} if
8516 @command{expr} fails.
8517
8518 Don't leave, there is some more!
8519
8520 The @sc{qnx} 4.25 @command{expr}, in addition of preferring @samp{0} to
8521 the empty string, has a funny behavior in its exit status: it's always 1
8522 when parentheses are used!
8523
8524 @example
8525 $ val=`expr 'a' : 'a'`; echo "$?: $val"
8526 0: 1
8527 $ val=`expr 'a' : 'b'`; echo "$?: $val"
8528 1: 0
8529
8530 $ val=`expr 'a' : '\(a\)'`; echo "?: $val"
8531 1: a
8532 $ val=`expr 'a' : '\(b\)'`; echo "?: $val"
8533 1: 0
8534 @end example
8535
8536 @noindent
8537 In practice this can be a big problem if you are ready to catch failures
8538 of @command{expr} programs with some other method (such as using
8539 @command{sed}), since you may get twice the result. For instance
8540
8541 @example
8542 $ expr 'a' : '\(a\)' || echo 'a' | sed 's/^\(a\)$/\1/'
8543 @end example
8544
8545 @noindent
8546 will output @samp{a} on most hosts, but @samp{aa} on @sc{qnx} 4.25. A
8547 simple work around consists in testing @command{expr} and use a variable
8548 set to @command{expr} or to @command{false} according to the result.
8549
8550
8551 @item @command{find}
8552 @c -----------------
8553 The option @option{-maxdepth} seems to be GNU specific. Tru64 v5.1,
8554 NetBSD 1.5 and Solaris 2.5 @command{find} commands do not understand it.
8555
8556
8557 @item @command{grep}
8558 @c -----------------
8559 @cindex @command{grep}
8560 Don't use @samp{grep -s} to suppress output, because @samp{grep -s} on
8561 System V does not suppress output, only error messages. Instead,
8562 redirect the standard output and standard error (in case the file
8563 doesn't exist) of @code{grep} to @file{/dev/null}. Check the exit
8564 status of @code{grep} to determine whether it found a match.
8565
8566 Don't use multiple regexps with @option{-e}, as some @code{grep} will only
8567 honor the last pattern (eg., IRIX 6.5 and Solaris 2.5.1). Anyway,
8568 Stardent Vistra SVR4 @code{grep} lacks @option{-e}@dots{} Instead, use
8569 alternation and @code{egrep}.
8570
8571
8572 @item @command{ln}
8573 @c ---------------
8574 @cindex @command{ln}
8575 @cindex Symbolic links
8576 Don't rely on @command{ln} having a @option{-f} option. Symbolic links
8577 are not available on old systems, use @samp{ln} as a fall back.
8578
8579 For versions of the DJGPP before 2.04, @command{ln} emulates soft links
8580 for executables by generating a stub that in turn calls the real
8581 program. This feature also works with nonexistent files like in the
8582 Unix spec. So @samp{ln -s file link} will generate @file{link.exe},
8583 which will attempt to call @file{file.exe} if run. But this feature only
8584 works for executables, so @samp{cp -p} is used instead for these
8585 systems. DJGPP versions 2.04 and later have full symlink support.
8586
8587
8588 @item @command{mv}
8589 @c ---------------
8590 @cindex @command{mv}
8591 The only portable options are @option{-f} and @option{-i}.
8592
8593 Moving individual files between file systems is portable (it was in V6),
8594 but it is not always atomic: when doing @samp{mv new existing}, there's
8595 a critical section where neither the old nor the new version of
8596 @file{existing} actually exists.
8597
8598 Moving directories across mount points is not portable, use @command{cp}
8599 and @command{rm}.
8600
8601
8602 @item @command{sed}
8603 @c ----------------
8604 @cindex @command{sed}
8605 Patterns should not include the separator (unless escaped), even as part
8606 of a character class. In conformance with @sc{posix}, the Cray
8607 @command{sed} will reject @samp{s/[^/]*$//}: use @samp{s,[^/]*$,,}.
8608
8609 Sed scripts should not use branch labels longer than 8 characters and
8610 should not contain comments.
8611
8612 Don't include extra @samp{;}, as some @command{sed}, such as NetBSD
8613 1.4.2's, try to interpret the second as a command:
8614
8615 @example
8616 $ echo a | sed 's/x/x/;;s/x/x/'
8617 sed: 1: "s/x/x/;;s/x/x/": invalid command code ;
8618 @end example
8619
8620 Input should have reasonably long lines, since some @command{sed} have
8621 an input buffer limited to 4000 bytes.
8622
8623 Alternation, @samp{\|}, is common but not portable.
8624 @c FIXME: I know Solaris is guilty, but I don't remember how.
8625 Anchors (@samp{^} and @samp{$}) inside groups are not portable.
8626
8627 Nested groups are extremely portable, but there is at least one
8628 @command{sed} (System V/68 Base Operating System R3V7.1) that does not
8629 support it.
8630
8631 Of course the option @option{-e} is portable, but it is not needed. No
8632 valid Sed program can start with a dash, so it does not help
8633 disambiguating. Its sole usefulness is helping enforcing indenting as
8634 in:
8635
8636 @example
8637 sed -e @var{instruction-1} \
8638 -e @var{instruction-2}
8639 @end example
8640
8641 @noindent
8642 as opposed to
8643
8644 @example
8645 sed @var{instruction-1};@var{instruction-2}
8646 @end example
8647
8648 Contrary to yet another urban legend, you may portably use @samp{&} in
8649 the replacement part of the @code{s} command to mean ``what was
8650 matched''.
8651
8652
8653 @item @command{sed} (@samp{t})
8654 @c ---------------------------
8655 @cindex @command{sed} (@samp{t})
8656 Some old systems have @command{sed} that ``forget'' to reset their
8657 @samp{t} flag when starting a new cycle. For instance on @sc{mips
8658 risc/os}, and on @sc{irix} 5.3, if you run the following @command{sed}
8659 script (the line numbers are not actual part of the texts):
8660
8661 @example
8662 s/keep me/kept/g # a
8663 t end # b
8664 s/.*/deleted/g # c
8665 : end # d
8666 @end example
8667
8668 @noindent
8669 on
8670
8671 @example
8672 delete me # 1
8673 delete me # 2
8674 keep me # 3
8675 delete me # 4
8676 @end example
8677
8678 @noindent
8679 you get
8680
8681 @example
8682 deleted
8683 delete me
8684 kept
8685 deleted
8686 @end example
8687
8688 @noindent
8689 instead of
8690
8691 @example
8692 deleted
8693 deleted
8694 kept
8695 deleted
8696 @end example
8697
8698 Why? When processing 1, a matches, therefore sets the t flag, b jumps to
8699 d, and the output is produced. When processing line 2, the t flag is
8700 still set (this is the bug). Line a fails to match, but @command{sed}
8701 is not supposed to clear the t flag when a substitution fails. Line b
8702 sees that the flag is set, therefore it clears it, and jumps to d, hence
8703 you get @samp{delete me} instead of @samp{deleted}. When processing 3 t
8704 is clear, a matches, so the flag is set, hence b clears the flags and
8705 jumps. Finally, since the flag is clear, 4 is processed properly.
8706
8707 There are two things one should remind about @samp{t} in @command{sed}.
8708 Firstly, always remember that @samp{t} jumps if @emph{some} substitution
8709 succeeded, not only the immediately preceding substitution, therefore,
8710 always use a fake @samp{t clear; : clear} to reset the t flag where
8711 indeed.
8712
8713 Secondly, you cannot rely on @command{sed} to clear the flag at each new
8714 cycle.
8715
8716 One portable implementation of the script above is:
8717
8718 @example
8719 t clear
8720 : clear
8721 s/keep me/kept/g
8722 t end
8723 s/.*/deleted/g
8724 : end
8725 @end example
8726
8727 @item @command{touch}
8728 @c ------------------
8729 @cindex @command{touch}
8730 On some old @sc{bsd} systems, @command{touch} or any command that
8731 results in an empty file does not update the timestamps, so use a
8732 command like @code{echo} as a workaround.
8733
8734 GNU @command{touch} 3.16r (and presumably all before that) fails to work
8735 on SunOS 4.1.3 when the empty file is on an @sc{nfs}-mounted 4.2 volume.
8736
8737 @end table
8738
8739
8740 @node Limitations of Make, , Limitations of Usual Tools, Portable Shell
8741 @section Limitations of Make
8742
8743 Make itself suffers a great number of limitations, only a few of which
8744 being listed here. First of all, remember that since commands are
8745 executed by the shell, all its weaknesses are inherited@dots{}
8746
8747 @table @asis
8748 @item Leading underscore in macro names
8749 Some Make don't support leading underscores in macro names, such as on
8750 NEWS-OS 4.2R.
8751
8752 @example
8753 $ cat Makefile
8754 _am_include = #
8755 _am_quote =
8756 all:; @@echo this is test
8757
8758 % make
8759 Make: Must be a separator on rules line 2. Stop.
8760
8761 $ cat Makefile2
8762 am_include = #
8763 am_quote =
8764 all:; @@echo this is test
8765
8766 $ make -f Makefile2
8767 this is test
8768 @end example
8769
8770 @item @code{VPATH}
8771 @cindex @code{VPATH}
8772 Don't use it! For instance any assignment to @code{VPATH} causes Sun
8773 @command{make} to only execute the first set of double-colon rules.
8774 @end table
8775
8776
8777
8778
8779 @c ================================================== Manual Configuration
8780
8781 @node Manual Configuration, Site Configuration, Portable Shell, Top
8782 @chapter Manual Configuration
8783
8784 A few kinds of features can't be guessed automatically by running test
8785 programs. For example, the details of the object-file format, or
8786 special options that need to be passed to the compiler or linker. You
8787 can check for such features using ad-hoc means, such as having
8788 @code{configure} check the output of the @code{uname} program, or
8789 looking for libraries that are unique to particular systems. However,
8790 Autoconf provides a uniform method for handling unguessable features.
8791
8792 @menu
8793 * Specifying Names:: Specifying the system type
8794 * Canonicalizing:: Getting the canonical system type
8795 * Using System Type:: What to do with the system type
8796 @end menu
8797
8798 @node Specifying Names, Canonicalizing, Manual Configuration, Manual Configuration
8799 @section Specifying the System Type
8800
8801 Like other @sc{gnu} @code{configure} scripts, Autoconf-generated
8802 @code{configure} scripts can make decisions based on a canonical name
8803 for the system type, which has the form:
8804 @samp{@var{cpu}-@var{vendor}-@var{os}}, where @var{os} can be
8805 @samp{@var{system}} or @samp{@var{kernel}-@var{system}}
8806
8807 @code{configure} can usually guess the canonical name for the type of
8808 system it's running on. To do so it runs a script called
8809 @code{config.guess}, which infers the name using the @code{uname}
8810 command or symbols predefined by the C preprocessor.
8811
8812 Alternately, the user can specify the system type with command line
8813 arguments to @code{configure}. Doing so is necessary when
8814 cross-compiling. In the most complex case of cross-compiling, three
8815 system types are involved. The options to specify them are@footnote{For
8816 backward compatibility, @code{configure} will accept a system type as an
8817 option by itself. Such an option will override the defaults for build,
8818 host and target system types. The following configure statement will
8819 configure a cross toolchain that will run on NetBSD/alpha but generate
8820 code for GNU Hurd/sparc, which is also the build platform.
8821
8822 @example
8823 ./configure --host=alpha-netbsd sparc-gnu
8824 @end example
8825 }:
8826
8827 @table @option
8828 @item --build=@var{build-type}
8829 the type of system on which the package is being configured and
8830 compiled.
8831
8832 @item --host=@var{host-type}
8833 @ovindex cross_compiling
8834 the type of system on which the package will run.
8835
8836 @item --target=@var{target-type}
8837 the type of system for which any compiler tools in the package will
8838 produce code (rarely needed). By default, it is the same as host.
8839 @end table
8840
8841 They all default to the result of running @code{config.guess}, unless
8842 you specify either @option{--build} or @option{--host}. In this case, the
8843 default becomes the system type you specified. If you specify both, and
8844 they're different, @code{configure} will enter cross compilation mode,
8845 so it won't run any tests that require execution.
8846
8847 Hint: if you mean to override the result of @code{config.guess}, prefer
8848 @option{--build} over @option{--host}. In the future, @option{--host} will
8849 not override the name of the build system type. Also, if you specify
8850 @option{--host}, but not @option{--build}, when @code{configure} performs
8851 the first compiler test it will try to run an executable produced by the
8852 compiler. If the execution fails, it will enter cross-compilation mode.
8853 Note, however, that it won't guess the build-system type, since this may
8854 require running test programs. Moreover, by the time the compiler test
8855 is performed, it may be too late to modify the build-system type: other
8856 tests may have already been performed. Therefore, whenever you specify
8857 @code{--host}, be sure to specify @code{--build} too.
8858
8859 @example
8860 ./configure --build=i686-pc-linux-gnu --host=m68k-coff
8861 @end example
8862
8863 @noindent
8864 will enter cross-compilation mode, but @code{configure} will fail if it
8865 can't run the code generated by the specified compiler if you configure
8866 as follows:
8867
8868 @example
8869 ./configure CC=m68k-coff-gcc
8870 @end example
8871
8872 @code{configure} recognizes short aliases for many system types; for
8873 example, @samp{decstation} can be used instead of
8874 @samp{mips-dec-ultrix4.2}. @code{configure} runs a script called
8875 @code{config.sub} to canonicalize system type aliases.
8876
8877
8878
8879 @node Canonicalizing, Using System Type, Specifying Names, Manual Configuration
8880 @section Getting the Canonical System Type
8881
8882 The following macros make the system type available to @code{configure}
8883 scripts.
8884
8885 @ovindex build_alias
8886 @ovindex host_alias
8887 @ovindex target_alias
8888
8889 The variables @samp{build_alias}, @samp{host_alias}, and
8890 @samp{target_alias} are always exactly the arguments of @option{--build},
8891 @option{--host}, and @option{--target}; in particular, they are left empty
8892 if the user did not use them, even if the corresponding
8893 @code{AC_CANONICAL} macro was run. Any configure script may use these
8894 variables anywhere. These are the variables that should be used when in
8895 interaction with the user.
8896
8897 If you need to recognize some special environments based on their system
8898 type, run the following macros to get canonical system names. These
8899 variables are not set before the macro call.
8900
8901 If you use these macros, you must distribute @code{config.guess} and
8902 @code{config.sub} along with your source code. @xref{Output}, for
8903 information about the @code{AC_CONFIG_AUX_DIR} macro which you can use
8904 to control in which directory @code{configure} looks for those scripts.
8905
8906
8907 @defmac AC_CANONICAL_BUILD
8908 @maindex CANONICAL_BUILD
8909 @ovindex build
8910 @ovindex build_cpu
8911 @ovindex build_vendor
8912 @ovindex build_os
8913 Compute the canonical build-system type variable, @code{build}, and its
8914 three individual parts @code{build_cpu}, @code{build_vendor}, and
8915 @code{build_os}.
8916
8917 If @option{--build} was specified, then @code{build} is the
8918 canonicalization of @code{build_alias} by @command{config.sub},
8919 otherwise it is determined by the shell script @code{config.guess}.
8920 @end defmac
8921
8922 @defmac AC_CANONICAL_HOST
8923 @maindex CANONICAL_HOST
8924 @ovindex host
8925 @ovindex host_cpu
8926 @ovindex host_vendor
8927 @ovindex host_os
8928 Compute the canonical host-system type variable, @code{host}, and its
8929 three individual parts @code{host_cpu}, @code{host_vendor}, and
8930 @code{host_os}.
8931
8932 If @option{--host} was specified, then @code{host} is the
8933 canonicalization of @code{host_alias} by @command{config.sub},
8934 otherwise it defaults to @code{build}.
8935
8936 For temporary backward-compatibility, when @option{--host} is specified
8937 by @option{--build} isn't, the build system will be assumed to be the
8938 same as @option{--host}, and @samp{build_alias} will be set to that
8939 value. Eventually, this historically incorrect behavior will go away.
8940
8941 @end defmac
8942
8943 @defmac AC_CANONICAL_TARGET
8944 @maindex CANONICAL_TARGET
8945 @ovindex target
8946 @ovindex target_cpu
8947 @ovindex target_vendor
8948 @ovindex target_os
8949 Compute the canonical target-system type variable, @code{target}, and its
8950 three individual parts @code{target_cpu}, @code{target_vendor}, and
8951 @code{target_os}.
8952
8953 If @option{--target} was specified, then @code{target} is the
8954 canonicalization of @code{target_alias} by @command{config.sub},
8955 otherwise it defaults to @code{host}.
8956 @end defmac
8957
8958
8959 @node Using System Type, , Canonicalizing, Manual Configuration
8960 @section Using the System Type
8961
8962 How do you use a canonical system type? Usually, you use it in one or
8963 more @code{case} statements in @file{configure.ac} to select
8964 system-specific C files. Then, using @code{AC_CONFIG_LINKS}, link those
8965 files which have names based on the system name, to generic names, such
8966 as @file{host.h} or @file{target.c} (@pxref{Configuration Links}). The
8967 @code{case} statement patterns can use shell wild cards to group several
8968 cases together, like in this fragment:
8969
8970 @example
8971 case "$target" in
8972 i386-*-mach* | i386-*-gnu*)
8973 obj_format=aout emulation=mach bfd_gas=yes ;;
8974 i960-*-bout) obj_format=bout ;;
8975 esac
8976 @end example
8977
8978 @noindent
8979 and in @file{configure.ac}, use:
8980
8981 @example
8982 AC_CONFIG_LINKS(host.h:config/$machine.h
8983 object.h:config/$obj_format.h)
8984 @end example
8985
8986 You can also use the host system type to find cross-compilation tools.
8987 @xref{Generic Programs}, for information about the @code{AC_CHECK_TOOL}
8988 macro which does that.
8989
8990
8991 @c ===================================================== Site Configuration.
8992
8993 @node Site Configuration, Running configure scripts, Manual Configuration, Top
8994 @chapter Site Configuration
8995
8996 @code{configure} scripts support several kinds of local configuration
8997 decisions. There are ways for users to specify where external software
8998 packages are, include or exclude optional features, install programs
8999 under modified names, and set default values for @code{configure}
9000 options.
9001
9002 @menu
9003 * External Software:: Working with other optional software
9004 * Package Options:: Selecting optional features
9005 * Pretty Help Strings:: Formatting help string
9006 * Site Details:: Configuring site details
9007 * Transforming Names:: Changing program names when installing
9008 * Site Defaults:: Giving @code{configure} local defaults
9009 @end menu
9010
9011 @node External Software, Package Options, Site Configuration, Site Configuration
9012 @section Working With External Software
9013
9014 Some packages require, or can optionally use, other software packages
9015 that are already installed. The user can give @code{configure}
9016 command line options to specify which such external software to use.
9017 The options have one of these forms:
9018
9019 @example
9020 --with-@var{package}=@ovar{arg}
9021 --without-@var{package}
9022 @end example
9023
9024 For example, @option{--with-gnu-ld} means work with the @sc{gnu} linker
9025 instead of some other linker. @option{--with-x} means work with The X
9026 Window System.
9027
9028 The user can give an argument by following the package name with
9029 @samp{=} and the argument. Giving an argument of @samp{no} is for
9030 packages that are used by default; it says to @emph{not} use the
9031 package. An argument that is neither @samp{yes} nor @samp{no} could
9032 include a name or number of a version of the other package, to specify
9033 more precisely which other package this program is supposed to work
9034 with. If no argument is given, it defaults to @samp{yes}.
9035 @option{--without-@var{package}} is equivalent to
9036 @option{--with-@var{package}=no}.
9037
9038 @code{configure} scripts do not complain about
9039 @option{--with-@var{package}} options that they do not support. This
9040 behavior permits configuring a source tree containing multiple packages
9041 with a top-level @code{configure} script when the packages support
9042 different options, without spurious error messages about options that
9043 some of the packages support. An unfortunate side effect is that option
9044 spelling errors are not diagnosed. No better approach to this problem
9045 has been suggested so far.
9046
9047 For each external software package that may be used, @file{configure.ac}
9048 should call @code{AC_ARG_WITH} to detect whether the @code{configure}
9049 user asked to use it. Whether each package is used or not by default,
9050 and which arguments are valid, is up to you.
9051
9052 @defmac AC_ARG_WITH (@var{package}, @var{help-string}, @ovar{action-if-given}, @ovar{action-if-not-given})
9053 @maindex ARG_WITH
9054 If the user gave @code{configure} the option @option{--with-@var{package}}
9055 or @option{--without-@var{package}}, run shell commands
9056 @var{action-if-given}. If neither option was given, run shell commands
9057 @var{action-if-not-given}. The name @var{package} indicates another
9058 software package that this program should work with. It should consist
9059 only of alphanumeric characters and dashes.
9060
9061 The option's argument is available to the shell commands
9062 @var{action-if-given} in the shell variable @code{withval}, which is
9063 actually just the value of the shell variable @code{with_@var{package}},
9064 with any @option{-} characters changed into @samp{_}. You may use that
9065 variable instead, if you wish.
9066
9067 The argument @var{help-string} is a description of the option that
9068 looks like this:
9069 @example
9070 --with-readline support fancy command line editing
9071 @end example
9072
9073 @noindent
9074 @var{help-string} may be more than one line long, if more detail is
9075 needed. Just make sure the columns line up in @samp{configure --help}.
9076 Avoid tabs in the help string. You'll need to enclose it in @samp{[}
9077 and @samp{]} in order to produce the leading spaces.
9078
9079 You should format your @var{help-string} with the macro
9080 @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
9081 @end defmac
9082
9083 @defmac AC_WITH (@var{package}, @var{action-if-given}, @ovar{action-if-not-given})
9084 @maindex WITH
9085 This is an obsolete version of @code{AC_ARG_WITH} that does not
9086 support providing a help string.
9087 @end defmac
9088
9089 @node Package Options, Pretty Help Strings, External Software, Site Configuration
9090 @section Choosing Package Options
9091
9092 If a software package has optional compile-time features, the user can
9093 give @code{configure} command line options to specify whether to
9094 compile them. The options have one of these forms:
9095
9096 @example
9097 --enable-@var{feature}=@ovar{arg}
9098 --disable-@var{feature}
9099 @end example
9100
9101 These options allow users to choose which optional features to build and
9102 install. @option{--enable-@var{feature}} options should never make a
9103 feature behave differently or cause one feature to replace another.
9104 They should only cause parts of the program to be built rather than left
9105 out.
9106
9107 The user can give an argument by following the feature name with
9108 @samp{=} and the argument. Giving an argument of @samp{no} requests
9109 that the feature @emph{not} be made available. A feature with an
9110 argument looks like @option{--enable-debug=stabs}. If no argument is
9111 given, it defaults to @samp{yes}. @option{--disable-@var{feature}} is
9112 equivalent to @option{--enable-@var{feature}=no}.
9113
9114 @code{configure} scripts do not complain about
9115 @option{--enable-@var{feature}} options that they do not support.
9116 This behavior permits configuring a source tree containing multiple
9117 packages with a top-level @code{configure} script when the packages
9118 support different options, without spurious error messages about options
9119 that some of the packages support.
9120 An unfortunate side effect is that option spelling errors are not diagnosed.
9121 No better approach to this problem has been suggested so far.
9122
9123 For each optional feature, @file{configure.ac} should call
9124 @code{AC_ARG_ENABLE} to detect whether the @code{configure} user asked
9125 to include it. Whether each feature is included or not by default, and
9126 which arguments are valid, is up to you.
9127
9128 @defmac AC_ARG_ENABLE (@var{feature}, @var{help-string}, @ovar{action-if-given}, @ovar{action-if-not-given})
9129 @maindex ARG_ENABLE
9130 If the user gave @code{configure} the option
9131 @option{--enable-@var{feature}} or @option{--disable-@var{feature}}, run
9132 shell commands @var{action-if-given}. If neither option was given, run
9133 shell commands @var{action-if-not-given}. The name @var{feature}
9134 indicates an optional user-level facility. It should consist only of
9135 alphanumeric characters and dashes.
9136
9137 The option's argument is available to the shell commands
9138 @var{action-if-given} in the shell variable @code{enableval}, which is
9139 actually just the value of the shell variable
9140 @code{enable_@var{feature}}, with any @option{-} characters changed into
9141 @samp{_}. You may use that variable instead, if you wish. The
9142 @var{help-string} argument is like that of @code{AC_ARG_WITH}
9143 (@pxref{External Software}).
9144
9145 You should format your @var{help-string} with the macro
9146 @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
9147 @end defmac
9148
9149 @defmac AC_ENABLE (@var{feature}, @var{action-if-given}, @ovar{action-if-not-given})
9150 @maindex ENABLE
9151 This is an obsolete version of @code{AC_ARG_ENABLE} that does not
9152 support providing a help string.
9153 @end defmac
9154
9155
9156 @node Pretty Help Strings, Site Details, Package Options, Site Configuration
9157 @section Making Your Help Strings Look Pretty
9158
9159 Properly formatting the @samp{help strings} which are used in
9160 @code{AC_ARG_WITH} (@pxref{External Software}) and @code{AC_ARG_ENABLE}
9161 (@pxref{Package Options}) can be challenging. Specifically, you want
9162 your own @samp{help strings} to line up in the appropriate columns of
9163 @samp{configure --help} just like the standard Autoconf @samp{help
9164 strings} do. This is the purpose of the @code{AS_HELP_STRING} macro.
9165
9166 @defmac AS_HELP_STRING (@var{left-hand-side}, @var{right-hand-side})
9167 @maindex HELP_STRING
9168
9169 Expands into an help string that looks pretty when the user executes
9170 @samp{configure --help}. It is typically used in @code{AC_ARG_WITH}
9171 (@pxref{External Software}) or @code{AC_ARG_ENABLE} (@pxref{Package
9172 Options}). The following example will make this clearer.
9173
9174 @example
9175 AC_DEFUN(TEST_MACRO,
9176 [AC_ARG_WITH(foo,
9177 AS_HELP_STRING([--with-foo],
9178 [use foo (default is NO)]),
9179 ac_cv_use_foo=$withval, ac_cv_use_foo=no),
9180 AC_CACHE_CHECK(whether to use foo,
9181 ac_cv_use_foo, ac_cv_use_foo=no)])
9182 @end example
9183
9184 Please note that the call to @code{AS_HELP_STRING} is @strong{unquoted}.
9185 Then the last few lines of @samp{configure --help} will appear like
9186 this:
9187
9188 @example
9189 --enable and --with options recognized:
9190 --with-foo use foo (default is NO)
9191 @end example
9192
9193 The @code{AS_HELP_STRING} macro is particularly helpful when the
9194 @var{left-hand-side} and/or @var{right-hand-side} are composed of macro
9195 arguments, as shown in the following example.
9196
9197 @example
9198 AC_DEFUN(MY_ARG_WITH,
9199 [AC_ARG_WITH([$1],
9200 AS_HELP_STRING([--with-$1], [use $1 (default is $2)]),
9201 ac_cv_use_$1=$withval, ac_cv_use_$1=no),
9202 AC_CACHE_CHECK(whether to use $1, ac_cv_use_$1, ac_cv_use_$1=$2)])
9203 @end example
9204 @end defmac
9205
9206
9207 @node Site Details, Transforming Names, Pretty Help Strings, Site Configuration
9208 @section Configuring Site Details
9209
9210 Some software packages require complex site-specific information. Some
9211 examples are host names to use for certain services, company names, and
9212 email addresses to contact. Since some configuration scripts generated
9213 by Metaconfig ask for such information interactively, people sometimes
9214 wonder how to get that information in Autoconf-generated configuration
9215 scripts, which aren't interactive.
9216
9217 Such site configuration information should be put in a file that is
9218 edited @emph{only by users}, not by programs. The location of the file
9219 can either be based on the @code{prefix} variable, or be a standard
9220 location such as the user's home directory. It could even be specified
9221 by an environment variable. The programs should examine that file at
9222 run time, rather than at compile time. Run time configuration is more
9223 convenient for users and makes the configuration process simpler than
9224 getting the information while configuring. @xref{Directory Variables,,
9225 Variables for Installation Directories, standards, GNU Coding
9226 Standards}, for more information on where to put data files.
9227
9228 @node Transforming Names, Site Defaults, Site Details, Site Configuration
9229 @section Transforming Program Names When Installing
9230
9231 Autoconf supports changing the names of programs when installing them.
9232 In order to use these transformations, @file{configure.ac} must call the
9233 macro @code{AC_ARG_PROGRAM}.
9234
9235 @defmac AC_ARG_PROGRAM
9236 @maindex ARG_PROGRAM
9237 @ovindex program_transform_name
9238 Place in output variable @code{program_transform_name} a sequence of
9239 @code{sed} commands for changing the names of installed programs.
9240
9241 If any of the options described below are given to @code{configure},
9242 program names are transformed accordingly. Otherwise, if
9243 @code{AC_CANONICAL_TARGET} has been called and a @option{--target} value
9244 is given that differs from the host type (specified with @option{--host}),
9245 the target type followed by a dash is used as a prefix. Otherwise, no
9246 program name transformation is done.
9247 @end defmac
9248
9249 @menu
9250 * Transformation Options:: @code{configure} options to transform names
9251 * Transformation Examples:: Sample uses of transforming names
9252 * Transformation Rules:: @file{Makefile} uses of transforming names
9253 @end menu
9254
9255 @node Transformation Options, Transformation Examples, Transforming Names, Transforming Names
9256 @subsection Transformation Options
9257
9258 You can specify name transformations by giving @code{configure} these
9259 command line options:
9260
9261 @table @option
9262 @item --program-prefix=@var{prefix}
9263 prepend @var{prefix} to the names;
9264
9265 @item --program-suffix=@var{suffix}
9266 append @var{suffix} to the names;
9267
9268 @item --program-transform-name=@var{expression}
9269 perform @code{sed} substitution @var{expression} on the names.
9270 @end table
9271
9272 @node Transformation Examples, Transformation Rules, Transformation Options, Transforming Names
9273 @subsection Transformation Examples
9274
9275 These transformations are useful with programs that can be part of a
9276 cross-compilation development environment. For example, a
9277 cross-assembler running on a Sun 4 configured with
9278 @option{--target=i960-vxworks} is normally installed as
9279 @file{i960-vxworks-as}, rather than @file{as}, which could be confused
9280 with a native Sun 4 assembler.
9281
9282 You can force a program name to begin with @file{g}, if you don't want
9283 @sc{gnu} programs installed on your system to shadow other programs with
9284 the same name. For example, if you configure @sc{gnu} @code{diff} with
9285 @option{--program-prefix=g}, then when you run @samp{make install} it is
9286 installed as @file{/usr/local/bin/gdiff}.
9287
9288 As a more sophisticated example, you could use
9289
9290 @example
9291 --program-transform-name='s/^/g/; s/^gg/g/; s/^gless/less/'
9292 @end example
9293 @noindent
9294
9295 to prepend @samp{g} to most of the program names in a source tree,
9296 excepting those like @code{gdb} that already have one and those like
9297 @code{less} and @code{lesskey} that aren't @sc{gnu} programs. (That is
9298 assuming that you have a source tree containing those programs that is
9299 set up to use this feature.)
9300
9301 One way to install multiple versions of some programs simultaneously is
9302 to append a version number to the name of one or both. For example, if
9303 you want to keep Autoconf version 1 around for awhile, you can configure
9304 Autoconf version 2 using @option{--program-suffix=2} to install the
9305 programs as @file{/usr/local/bin/autoconf2},
9306 @file{/usr/local/bin/autoheader2}, etc. Nevertheless, pay attention
9307 that only the binaries are renamed, therefore you'd have problems with
9308 the library files which might overlap.
9309
9310 @node Transformation Rules, , Transformation Examples, Transforming Names
9311 @subsection Transformation Rules
9312
9313 Here is how to use the variable @code{program_transform_name} in a
9314 @file{Makefile.in}:
9315
9316 @example
9317 transform = @@program_transform_name@@
9318 install: all
9319 $(INSTALL_PROGRAM) myprog $(bindir)/`echo myprog | \
9320 sed '$(transform)'`
9321
9322 uninstall:
9323 rm -f $(bindir)/`echo myprog | sed '$(transform)'`
9324 @end example
9325
9326 @noindent
9327 If you have more than one program to install, you can do it in a loop:
9328
9329 @example
9330 PROGRAMS = cp ls rm
9331 install:
9332 for p in $(PROGRAMS); do \
9333 $(INSTALL_PROGRAM) $$p $(bindir)/`echo $$p | \
9334 sed '$(transform)'`; \
9335 done
9336
9337 uninstall:
9338 for p in $(PROGRAMS); do \
9339 rm -f $(bindir)/`echo $$p | sed '$(transform)'`; \
9340 done
9341 @end example
9342
9343 It is guaranteed that @code{program_transform_name} is never empty, and
9344 that there are no useless separators. Therefore you may safely embed
9345 @code{program_transform_name} within a sed program using @samp{;}:
9346
9347 @example
9348 transform = @@program_transform_name@@
9349 transform_exe = s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/
9350 @end example
9351
9352 Whether to do the transformations on documentation files (Texinfo or
9353 @code{man}) is a tricky question; there seems to be no perfect answer,
9354 due to the several reasons for name transforming. Documentation is not
9355 usually particular to a specific architecture, and Texinfo files do not
9356 conflict with system documentation. But they might conflict with
9357 earlier versions of the same files, and @code{man} pages sometimes do
9358 conflict with system documentation. As a compromise, it is probably
9359 best to do name transformations on @code{man} pages but not on Texinfo
9360 manuals.
9361
9362 @node Site Defaults, , Transforming Names, Site Configuration
9363 @section Setting Site Defaults
9364
9365 Autoconf-generated @code{configure} scripts allow your site to provide
9366 default values for some configuration values. You do this by creating
9367 site- and system-wide initialization files.
9368
9369 @evindex CONFIG_SITE
9370 If the environment variable @code{CONFIG_SITE} is set, @code{configure}
9371 uses its value as the name of a shell script to read. Otherwise, it
9372 reads the shell script @file{@var{prefix}/share/config.site} if it exists,
9373 then @file{@var{prefix}/etc/config.site} if it exists. Thus,
9374 settings in machine-specific files override those in machine-independent
9375 ones in case of conflict.
9376
9377 Site files can be arbitrary shell scripts, but only certain kinds of
9378 code are really appropriate to be in them. Because @code{configure}
9379 reads any cache file after it has read any site files, a site file can
9380 define a default cache file to be shared between all Autoconf-generated
9381 @code{configure} scripts run on that system (@pxref{Cache Files}). If
9382 you set a default cache file in a site file, it is a good idea to also
9383 set the output variable @code{CC} in that site file, because the cache
9384 file is only valid for a particular compiler, but many systems have
9385 several available.
9386
9387 You can examine or override the value set by a command line option to
9388 @code{configure} in a site file; options set shell variables that have
9389 the same names as the options, with any dashes turned into underscores.
9390 The exceptions are that @option{--without-} and @option{--disable-} options
9391 are like giving the corresponding @option{--with-} or @option{--enable-}
9392 option and the value @samp{no}. Thus, @option{--cache-file=localcache}
9393 sets the variable @code{cache_file} to the value @samp{localcache};
9394 @option{--enable-warnings=no} or @option{--disable-warnings} sets the variable
9395 @code{enable_warnings} to the value @samp{no}; @option{--prefix=/usr} sets the
9396 variable @code{prefix} to the value @samp{/usr}; etc.
9397
9398 Site files are also good places to set default values for other output
9399 variables, such as @code{CFLAGS}, if you need to give them non-default
9400 values: anything you would normally do, repetitively, on the command
9401 line. If you use non-default values for @var{prefix} or
9402 @var{exec_prefix} (wherever you locate the site file), you can set them
9403 in the site file if you specify it with the @code{CONFIG_SITE}
9404 environment variable.
9405
9406 You can set some cache values in the site file itself. Doing this is
9407 useful if you are cross-compiling, so it is impossible to check features
9408 that require running a test program. You could ``prime the cache'' by
9409 setting those values correctly for that system in
9410 @file{@var{prefix}/etc/config.site}. To find out the names of the cache
9411 variables you need to set, look for shell variables with @samp{_cv_} in
9412 their names in the affected @code{configure} scripts, or in the Autoconf
9413 M4 source code for those macros.
9414
9415 The cache file is careful to not override any variables set in the site
9416 files. Similarly, you should not override command-line options in the
9417 site files. Your code should check that variables such as @code{prefix}
9418 and @code{cache_file} have their default values (as set near the top of
9419 @code{configure}) before changing them.
9420
9421 Here is a sample file @file{/usr/share/local/gnu/share/config.site}. The
9422 command @samp{configure --prefix=/usr/share/local/gnu} would read this
9423 file (if @code{CONFIG_SITE} is not set to a different file).
9424
9425 @example
9426 # config.site for configure
9427 #
9428 # Change some defaults.
9429 test "$prefix" = NONE && prefix=/usr/share/local/gnu
9430 test "$exec_prefix" = NONE && exec_prefix=/usr/local/gnu
9431 test "$sharedstatedir" = '$prefix/com' && sharedstatedir=/var
9432 test "$localstatedir" = '$prefix/var' && localstatedir=/var
9433
9434 # Give Autoconf 2.x generated configure scripts a shared default
9435 # cache file for feature test results, architecture-specific.
9436 if test "$cache_file" = /dev/null; then
9437 cache_file="$prefix/var/config.cache"
9438 # A cache file is only valid for one C compiler.
9439 CC=gcc
9440 fi
9441 @end example
9442
9443
9444 @c ============================================== Running configure Scripts.
9445
9446 @node Running configure scripts, config.status Invocation, Site Configuration, Top
9447 @chapter Running @code{configure} Scripts
9448 @cindex @code{configure}
9449
9450 Below are instructions on how to configure a package that uses a
9451 @code{configure} script, suitable for inclusion as an @file{INSTALL}
9452 file in the package. A plain-text version of @file{INSTALL} which you
9453 may use comes with Autoconf.
9454
9455 @menu
9456 * Basic Installation:: Instructions for typical cases
9457 * Compilers and Options:: Selecting compilers and optimization
9458 * Multiple Architectures:: Compiling for multiple architectures at once
9459 * Installation Names:: Installing in different directories
9460 * Optional Features:: Selecting optional features
9461 * System Type:: Specifying the system type
9462 * Sharing Defaults:: Setting site-wide defaults for @code{configure}
9463 * Environment Variables:: Defining environment variables.
9464 * configure Invocation:: Changing how @code{configure} runs
9465 @end menu
9466
9467 @include install.texi
9468
9469
9470 @c ============================================== Recreating a Configuration
9471
9472 @node config.status Invocation, Obsolete Constructs, Running configure scripts, Top
9473 @chapter Recreating a Configuration
9474 @cindex @code{config.status}
9475
9476 The @code{configure} script creates a file named @file{config.status},
9477 which actually configures, @dfn{instantiates}, the template files. It
9478 also records the configuration options that were specified when the
9479 package was last configured in case reconfiguring is needed.
9480
9481 Synopsis:
9482 @example
9483 ./config.status @var{option}@dots{} [@var{file}@dots{}]
9484 @end example
9485
9486 It configures the @var{files}, if none are specified, all the templates
9487 are instantiated. The files must be specified without their
9488 dependencies, as in
9489
9490 @example
9491 ./config.status foobar
9492 @end example
9493
9494 @noindent
9495 not
9496
9497 @example
9498 ./config.status foobar:foo.in:bar.in
9499 @end example
9500
9501 The supported @var{option}s are:
9502
9503 @table @option
9504 @item --help
9505 @itemx -h
9506 Print a summary of the command line options, the list of the template
9507 files and exit.
9508
9509 @item --version
9510 @itemx -V
9511 Print the version number of Autoconf and exit.
9512
9513 @item --debug
9514 @itemx -d
9515 Don't remove the temporary files.
9516
9517 @item --file=@var{file}[:@var{template}]
9518 Require that @var{file} be instantiated as if
9519 @samp{AC_CONFIG_FILES(@var{file}:@var{template})} was used. Both
9520 @var{file} and @var{template} may be @samp{-} in which case the standard
9521 output and/or standard input, respectively, is used. If a
9522 @var{template} filename is relative, it is first looked for in the build
9523 tree, and then in the source tree. @xref{Configuration Actions}, for
9524 more details.
9525
9526 This option and the following ones provide one way for separately
9527 distributed packages to share the values computed by @code{configure}.
9528 Doing so can be useful if some of the packages need a superset of the
9529 features that one of them, perhaps a common library, does. These
9530 options allow a @file{config.status} file to create files other than the
9531 ones that its @file{configure.ac} specifies, so it can be used for a
9532 different package.
9533
9534 @item --header=@var{file}[:@var{template}]
9535 Same as @option{--file} above, but with @samp{AC_CONFIG_HEADERS}.
9536
9537 @item --recheck
9538 Ask @file{config.status} to update itself and exit (no instantiation).
9539 This option is useful if you change @code{configure}, so that the
9540 results of some tests might be different from the previous run. The
9541 @option{--recheck} option re-runs @code{configure} with the same arguments
9542 you used before, plus the @option{--no-create} option, which prevents
9543 @code{configure} from running @file{config.status} and creating
9544 @file{Makefile} and other files, and the @option{--no-recursion} option,
9545 which prevents @code{configure} from running other @code{configure}
9546 scripts in subdirectories. (This is so other @file{Makefile} rules can
9547 run @file{config.status} when it changes; @pxref{Automatic Remaking},
9548 for an example).
9549 @end table
9550
9551 @file{config.status} checks several optional environment variables that
9552 can alter its behavior:
9553
9554 @defvar CONFIG_SHELL
9555 @evindex CONFIG_SHELL
9556 The shell with which to run @code{configure} for the @option{--recheck}
9557 option. It must be Bourne-compatible. The default is @file{/bin/sh}.
9558 @end defvar
9559
9560 @defvar CONFIG_STATUS
9561 @evindex CONFIG_STATUS
9562 The file name to use for the shell script that records the
9563 configuration. The default is @file{./config.status}. This variable is
9564 useful when one package uses parts of another and the @code{configure}
9565 scripts shouldn't be merged because they are maintained separately.
9566 @end defvar
9567
9568 You can use @file{./config.status} in your Makefiles. For example, in
9569 the dependencies given above (@pxref{Automatic Remaking}),
9570 @file{config.status} is run twice when @file{configure.ac} has changed.
9571 If that bothers you, you can make each run only regenerate the files for
9572 that rule:
9573 @example
9574 @group
9575 config.h: stamp-h
9576 stamp-h: config.h.in config.status
9577 ./config.status config.h
9578 echo > stamp-h
9579
9580 Makefile: Makefile.in config.status
9581 ./config.status Makefile
9582 @end group
9583 @end example
9584
9585 The calling convention of @file{config.status} has changed, see
9586 @ref{Obsolete config.status Use}, for details.
9587
9588
9589 @c =================================================== Obsolete Constructs
9590
9591 @node Obsolete Constructs, Questions, config.status Invocation, Top
9592 @chapter Obsolete Constructs
9593
9594 Autoconf changes, and throughout the years some constructs are obsoleted.
9595 Most of the changes involve the macros, but the tools themselves, or
9596 even some concepts, are now considered obsolete.
9597
9598 You may completely skip this chapter if you are new to Autoconf, its
9599 intention is mainly to help maintainers updating their packages by
9600 understanding how to move to more modern constructs.
9601
9602 @menu
9603 * Obsolete config.status Use:: Different calling convention
9604 * acconfig.h:: Additional entries in @file{config.h.in}
9605 * autoupdate Invocation:: Automatic update of @file{configure.ac}
9606 * Obsolete Macros:: Backward compatibility macros
9607 * Autoconf 1:: Tips for upgrading your files
9608 * Autoconf 2.13:: Some fresher tips
9609 @end menu
9610
9611 @node Obsolete config.status Use, acconfig.h, Obsolete Constructs, Obsolete Constructs
9612 @section Obsolete @file{config.status} Invocation
9613
9614 @file{config.status} now supports arguments to specify the files to
9615 instantiate, see @ref{config.status Invocation}, for more details.
9616 Before, environment variables had to be used.
9617
9618 @defvar CONFIG_COMMANDS
9619 @evindex CONFIG_COMMANDS
9620 The tags of the commands to execute. The default is the arguments given
9621 to @code{AC_OUTPUT} and @code{AC_CONFIG_COMMANDS} in
9622 @file{configure.ac}.
9623 @end defvar
9624
9625 @defvar CONFIG_FILES
9626 @evindex CONFIG_FILES
9627 The files in which to perform @samp{@@@var{variable}@@} substitutions.
9628 The default is the arguments given to @code{AC_OUTPUT} and
9629 @code{AC_CONFIG_FILES} in @file{configure.ac}.
9630 @end defvar
9631
9632 @defvar CONFIG_HEADERS
9633 @evindex CONFIG_HEADERS
9634 The files in which to substitute C @code{#define} statements. The
9635 default is the arguments given to @code{AC_CONFIG_HEADERS}; if that
9636 macro was not called, @file{config.status} ignores this variable.
9637 @end defvar
9638
9639 @defvar CONFIG_LINKS
9640 @evindex CONFIG_LINKS
9641 The symbolic links to establish. The default is the arguments given to
9642 @code{AC_CONFIG_LINKS}; if that macro was not called,
9643 @file{config.status} ignores this variable.
9644 @end defvar
9645
9646 In @ref{config.status Invocation}, using this old interface, the example
9647 would be:
9648
9649 @example
9650 @group
9651 config.h: stamp-h
9652 stamp-h: config.h.in config.status
9653 CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_FILES= \
9654 CONFIG_HEADERS=config.h ./config.status
9655 echo > stamp-h
9656
9657 Makefile: Makefile.in config.status
9658 CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_HEADERS= \
9659 CONFIG_FILES=Makefile ./config.status
9660 @end group
9661 @end example
9662
9663 @noindent
9664 (If @file{configure.ac} does not call @code{AC_CONFIG_HEADERS}, there is
9665 no need to set @code{CONFIG_HEADERS} in the @code{make} rules, equally
9666 for @code{CONFIG_COMMANDS} etc.)
9667
9668
9669 @node acconfig.h, autoupdate Invocation, Obsolete config.status Use, Obsolete Constructs
9670 @section @file{acconfig.h}
9671
9672 @cindex @file{acconfig.h}
9673 @cindex @file{config.h.top}
9674 @cindex @file{config.h.bot}
9675
9676 In order to produce @file{config.h.in}, @command{autoheader} needs to
9677 build or to find templates for each symbol. Modern releases of Autoconf
9678 use @code{AH_VERBATIM} and @code{AH_TEMPLATE} (@pxref{Autoheader
9679 Macros}), but in older releases a file, @file{acconfig.h}, contained the
9680 list of needed templates. @code{autoheader} copies comments and
9681 @code{#define} and @code{#undef} statements from @file{acconfig.h} in
9682 the current directory, if present. This file used to be mandatory if
9683 you @code{AC_DEFINE} any additional symbols.
9684
9685 Modern releases of Autoconf also provide @code{AH_TOP} and
9686 @code{AH_BOTTOM} if you need to prepend/append some information to
9687 @file{config.h.in}. Ancient versions of Autoconf had a similar feature:
9688 if @file{./acconfig.h} contains the string @samp{@@TOP@@},
9689 @code{autoheader} copies the lines before the line containing
9690 @samp{@@TOP@@} into the top of the file that it generates. Similarly,
9691 if @file{./acconfig.h} contains the string @samp{@@BOTTOM@@},
9692 @code{autoheader} copies the lines after that line to the end of the
9693 file it generates. Either or both of those strings may be omitted. An
9694 even older alternate way to produce the same effect in jurasik versions
9695 of Autoconf is to create the files @file{@var{file}.top} (typically
9696 @file{config.h.top}) and/or @file{@var{file}.bot} in the current
9697 directory. If they exist, @code{autoheader} copies them to the
9698 beginning and end, respectively, of its output.
9699
9700 In former versions of Autoconf, the files used in preparing a software
9701 package for distribution were:
9702 @example
9703 @group
9704 configure.ac --. .------> autoconf* -----> configure
9705 +---+
9706 [aclocal.m4] --+ `---.
9707 [acsite.m4] ---' |
9708 +--> [autoheader*] -> [config.h.in]
9709 [acconfig.h] ----. |
9710 +-----'
9711 [config.h.top] --+
9712 [config.h.bot] --'
9713 @end group
9714 @end example
9715
9716 Use only the @code{AH_} macros, @file{configure.ac} should be
9717 self-contained, and should not depend upon @file{acconfig.h} etc.
9718
9719
9720 @node autoupdate Invocation, Obsolete Macros, acconfig.h, Obsolete Constructs
9721 @section Using @code{autoupdate} to Modernize @file{configure.ac}
9722 @cindex @code{autoupdate}
9723
9724 The @code{autoupdate} program updates a @file{configure.ac} file that
9725 calls Autoconf macros by their old names to use the current macro names.
9726 In version 2 of Autoconf, most of the macros were renamed to use a more
9727 uniform and descriptive naming scheme. @xref{Macro Names}, for a
9728 description of the new scheme. Although the old names still work
9729 (@pxref{Obsolete Macros}, for a list of the old macros and the corresponding
9730 new names), you can make your @file{configure.ac} files more readable
9731 and make it easier to use the current Autoconf documentation if you
9732 update them to use the new macro names.
9733
9734 @evindex SIMPLE_BACKUP_SUFFIX
9735 If given no arguments, @code{autoupdate} updates @file{configure.ac},
9736 backing up the original version with the suffix @file{~} (or the value
9737 of the environment variable @code{SIMPLE_BACKUP_SUFFIX}, if that is
9738 set). If you give @code{autoupdate} an argument, it reads that file
9739 instead of @file{configure.ac} and writes the updated file to the
9740 standard output.
9741
9742 @noindent
9743 @code{autoupdate} accepts the following options:
9744
9745 @table @option
9746 @item --help
9747 @itemx -h
9748 Print a summary of the command line options and exit.
9749
9750 @item --version
9751 @itemx -V
9752 Print the version number of Autoconf and exit.
9753
9754 @item --verbose
9755 @itemx -v
9756 Report processing steps.
9757
9758 @item --debug
9759 @itemx -d
9760 Don't remove the temporary files.
9761
9762 @item --autoconf-dir=@var{dir}
9763 @itemx -A @var{dir}
9764 @evindex AC_MACRODIR
9765 Override the location where the installed Autoconf data files are looked
9766 for. You can also set the @code{AC_MACRODIR} environment variable to a
9767 directory; this option overrides the environment variable.
9768
9769 This option is rarely needed and dangerous; it is only used when one
9770 plays with different versions of Autoconf simultaneously.
9771
9772 @item --localdir=@var{dir}
9773 @itemx -l @var{dir}
9774 Look for the package file @file{aclocal.m4} in directory @var{dir}
9775 instead of in the current directory.
9776 @end table
9777
9778 @node Obsolete Macros, Autoconf 1, autoupdate Invocation, Obsolete Constructs
9779 @section Obsolete Macros
9780
9781 Several macros are obsoleted in Autoconf, for various reasons (typically
9782 they failed to quote properly, couldn't be extended for more recent
9783 issues etc.). They are still supported, but deprecated: their use
9784 should be avoided.
9785
9786 During the jump from Autoconf version 1 to version 2, most of the
9787 macros were renamed to use a more uniform and descriptive naming scheme,
9788 but their signature did not change. @xref{Macro Names}, for a
9789 description of the new naming scheme. Below, there is just the mapping
9790 from old names to new names for these macros, the reader is invited to
9791 refer to the definition of the new macro for the signature and the
9792 description.
9793
9794 @defmac AC_ALLOCA
9795 @maindex ALLOCA
9796 @code{AC_FUNC_ALLOCA}
9797 @end defmac
9798
9799 @defmac AC_ARG_ARRAY
9800 @maindex ARG_ARRAY
9801 removed because of limited usefulness
9802 @end defmac
9803
9804 @defmac AC_C_CROSS
9805 @maindex C_CROSS
9806 This macro is obsolete; it does nothing.
9807 @end defmac
9808
9809 @defmac AC_CANONICAL_SYSTEM
9810 @maindex CANONICAL_SYSTEM
9811 Determine the system type and set output variables to the names of the
9812 canonical system types. @xref{Canonicalizing}, for details about the
9813 variables this macro sets.
9814
9815 The user is encouraged to use either @code{AC_CANONICAL_BUILD}, or
9816 @code{AC_CANONICAL_HOST}, or @code{AC_CANONICAL_TARGET}, depending on
9817 the needs. Using @code{AC_CANONICAL_TARGET} is enough to run the two
9818 other macros.
9819 @end defmac
9820
9821 @defmac AC_CHAR_UNSIGNED
9822 @maindex CHAR_UNSIGNED
9823 @code{AC_C_CHAR_UNSIGNED}
9824 @end defmac
9825
9826 @defmac AC_CHECK_TYPE (@var{type}, @var{default})
9827 @maindex CHECK_TYPE
9828 Autoconf, up to 2.13, used to provide this version of
9829 @code{AC_CHECK_TYPE}, deprecated because of its flaws. Firstly, although
9830 it is a member of the @code{CHECK} clan, singular sub-family, it does
9831 more than just checking. Second, missing types are not
9832 @code{typedef}'d, they are @code{#define}'d, which can lead to
9833 incompatible code in the case of pointer types.
9834
9835 This use of @code{AC_CHECK_TYPE} is obsolete and discouraged, see
9836 @ref{Generic Types}, for the description of the current macro.
9837
9838 If the type @var{type} is not defined, define it to be the C (or C++)
9839 builtin type @var{default}; e.g., @samp{short} or @samp{unsigned}.
9840
9841 This macro is equivalent to:
9842
9843 @example
9844 AC_CHECK_TYPE([@var{type}],
9845 [AC_DEFINE([@var{type}], [@var{default}],
9846 [Define to `@var{default}' if <sys/types.h>
9847 does not define.])])
9848 @end example
9849
9850 In order to keep backward compatibility, the two versions of
9851 @code{AC_CHECK_TYPE} are implemented, selected by a simple heuristics:
9852
9853 @enumerate
9854 @item
9855 If there are three or four arguments, the modern version is used.
9856
9857 @item
9858 If the second argument appears to be a C or C++ type, then the
9859 obsolete version is used. This happens if the argument is a C or C++
9860 @emph{builtin} type or a C identifier ending in @samp{_t}, optionally
9861 followed by one of @samp{[(* } and then by a string of zero or more
9862 characters taken from the set @samp{[]()* _a-zA-Z0-9}.
9863
9864 @item
9865 If the second argument is spelled with the alphabet of valid C and C++
9866 types, the user is warned and the modern version is used.
9867
9868 @item
9869 Otherwise, the modern version is used.
9870 @end enumerate
9871
9872 @noindent
9873 You are encouraged either to use a valid builtin type, or to use the
9874 equivalent modern code (see above), or better yet, to use
9875 @code{AC_CHECK_TYPES} together with
9876
9877 @example
9878 #if !HAVE_LOFF_T
9879 typedef loff_t off_t;
9880 #endif
9881 @end example
9882 @end defmac
9883 @c end of AC_CHECK_TYPE
9884
9885 @defmac AC_CHECKING (@var{feature-description})
9886 @maindex CHECKING
9887 Same as @samp{AC_MSG_NOTICE([checking @var{feature-description}@dots{}]}.
9888 @end defmac
9889
9890 @defmac AC_COMPILE_CHECK (@var{echo-text}, @var{includes}, @var{function-body}, @var{action-if-found}, @ovar{action-if-not-found})
9891 @maindex COMPILE_CHECK
9892 This is an obsolete version of @code{AC_TRY_LINK} (@pxref{Examining
9893 Libraries}), with the addition that it prints @samp{checking for
9894 @var{echo-text}} to the standard output first, if @var{echo-text} is
9895 non-empty. Use @code{AC_MSG_CHECKING} and @code{AC_MSG_RESULT} instead
9896 to print messages (@pxref{Printing Messages}).
9897 @end defmac
9898
9899 @defmac AC_CONST
9900 @maindex CONST
9901 @code{AC_C_CONST}
9902 @end defmac
9903
9904 @defmac AC_CROSS_CHECK
9905 @maindex CROSS_CHECK
9906 Same as @code{AC_C_CROSS}, which is obsolete too, and does nothing
9907 @code{:-)}.
9908 @end defmac
9909
9910 @defmac AC_CYGWIN
9911 @maindex CYGWIN
9912 Check for the Cygwin environment in which case the shell variable
9913 @code{CYGWIN} is set to @samp{yes}. Don't use this macro, the dignified
9914 means to check the nature of the host is using
9915 @code{AC_CANONICAL_HOST}. As a matter of fact this macro is defined as:
9916
9917 @example
9918 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
9919 case $host_os in
9920 *cygwin* ) CYGWIN=yes;;
9921 * ) CYGWIN=no;;
9922 esac
9923 @end example
9924
9925 Beware that the variable @code{CYGWIN} has a very special meaning when
9926 running CygWin32, and should not be changed. That's yet another reason
9927 not to use this macro.
9928 @end defmac
9929
9930 @defmac AC_DECL_YYTEXT
9931 @maindex DECL_YYTEXT
9932 Does nothing, now integrated in @code{AC_PROG_LEX}.
9933 @end defmac
9934
9935 @defmac AC_DIR_HEADER
9936 @maindex DIR_HEADER
9937 @cvindex DIRENT
9938 @cvindex SYSNDIR
9939 @cvindex SYSDIR
9940 @cvindex NDIR
9941 Like calling @code{AC_FUNC_CLOSEDIR_VOID} and@code{AC_HEADER_DIRENT},
9942 but defines a different set of C preprocessor macros to indicate which
9943 header file is found:
9944
9945 @multitable {@file{sys/ndir.h}} {Old Symbol} {@code{HAVE_SYS_NDIR_H}}
9946 @item Header @tab Old Symbol @tab New Symbol
9947 @item @file{dirent.h} @tab @code{DIRENT} @tab @code{HAVE_DIRENT_H}
9948 @item @file{sys/ndir.h} @tab @code{SYSNDIR} @tab @code{HAVE_SYS_NDIR_H}
9949 @item @file{sys/dir.h} @tab @code{SYSDIR} @tab @code{HAVE_SYS_DIR_H}
9950 @item @file{ndir.h} @tab @code{NDIR} @tab @code{HAVE_NDIR_H}
9951 @end multitable
9952 @end defmac
9953
9954 @defmac AC_DYNIX_SEQ
9955 @maindex DYNIX_SEQ
9956 If on Dynix/PTX (Sequent @sc{unix}), add @option{-lseq} to output variable
9957 @code{LIBS}. This macro used to be defined as
9958
9959 @example
9960 AC_CHECK_LIB(seq, getmntent, LIBS="-lseq $LIBS")
9961 @end example
9962
9963 @noindent
9964 now it is just @code{AC_FUNC_GETMNTENT}.
9965 @end defmac
9966
9967 @defmac AC_EXEEXT
9968 @maindex EXEEXT
9969 @ovindex EXEEXT
9970 Defined the output variable @code{EXEEXT} based on the output of the
9971 compiler, which is now done automatically. Typically set to empty
9972 string if Unix and @samp{.exe} if Win32 or OS/2.
9973 @end defmac
9974
9975 @defmac AC_EMXOS2
9976 @maindex EMXOS2
9977 Similar to @code{AC_CYGWIN} but checks for the EMX environment on OS/2
9978 and sets @code{EMXOS2}.
9979 @end defmac
9980
9981 @defmac AC_ERROR
9982 @maindex ERROR
9983 @code{AC_MSG_ERROR}
9984 @end defmac
9985
9986 @defmac AC_FIND_X
9987 @maindex FIND_X
9988 @code{AC_PATH_X}
9989 @end defmac
9990
9991 @defmac AC_FIND_XTRA
9992 @maindex FIND_XTRA
9993 @code{AC_PATH_XTRA}
9994 @end defmac
9995
9996 @defmac AC_FUNC_CHECK
9997 @maindex FUNC_CHECK
9998 @code{AC_CHECK_FUNC}
9999 @end defmac
10000
10001 @defmac AC_FUNC_WAIT3
10002 @maindex FUNC_WAIT3
10003 @cvindex HAVE_WAIT3
10004 If @code{wait3} is found and fills in the contents of its third argument
10005 (a @samp{struct rusage *}), which HP-UX does not do, define
10006 @code{HAVE_WAIT3}.
10007
10008 These days portable programs should use @code{waitpid}, not
10009 @code{wait3}, as @code{wait3} is being removed from the Open Group
10010 standards, and will not appear in the next revision of POSIX.
10011 @end defmac
10012
10013 @defmac AC_GCC_TRADITIONAL
10014 @maindex GCC_TRADITIONAL
10015 @code{AC_PROG_GCC_TRADITIONAL}
10016 @end defmac
10017
10018 @defmac AC_GETGROUPS_T
10019 @maindex GETGROUPS_T
10020 @code{AC_TYPE_GETGROUPS}
10021 @end defmac
10022
10023 @defmac AC_GETLOADAVG
10024 @maindex GETLOADAVG
10025 @code{AC_FUNC_GETLOADAVG}
10026 @end defmac
10027
10028 @defmac AC_HAVE_FUNCS
10029 @maindex HAVE_FUNCS
10030 @code{AC_CHECK_FUNCS}
10031 @end defmac
10032
10033 @defmac AC_HAVE_HEADERS
10034 @maindex HAVE_HEADERS
10035 @code{AC_CHECK_HEADERS}
10036 @end defmac
10037
10038 @defmac AC_HAVE_LIBRARY (@var{library}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
10039 @maindex HAVE_LIBRARY
10040 This macro is equivalent to calling @code{AC_CHECK_LIB} with a
10041 @var{function} argument of @code{main}. In addition, @var{library} can
10042 be written as any of @samp{foo}, @option{-lfoo}, or @samp{libfoo.a}. In
10043 all of those cases, the compiler is passed @option{-lfoo}. However,
10044 @var{library} cannot be a shell variable; it must be a literal name.
10045 @end defmac
10046
10047 @defmac AC_HAVE_POUNDBANG
10048 @maindex HAVE_POUNDBANG
10049 @code{AC_SYS_INTERPRETER} (different calling convention)
10050 @end defmac
10051
10052 @defmac AC_HEADER_CHECK
10053 @maindex HEADER_CHECK
10054 @code{AC_CHECK_HEADER}
10055 @end defmac
10056
10057 @defmac AC_HEADER_EGREP
10058 @maindex HEADER_EGREP
10059 @code{AC_EGREP_HEADER}
10060 @end defmac
10061
10062 @defmac AC_HELP_STRING
10063 @maindex HELP_STRING
10064 @code{AS_HELP_STRING}
10065 @end defmac
10066
10067 @defmac AC_INIT (@var{unique-file-in-source-dir})
10068 @maindex INIT
10069 Formerly @code{AC_INIT} used to have a single argument, and was
10070 equivalent to:
10071
10072 @example
10073 AC_INIT
10074 AC_CONFIG_SRCDIR(@var{unique-file-in-source-dir})
10075 @end example
10076 @end defmac
10077
10078 @defmac AC_INLINE
10079 @maindex INLINE
10080 @code{AC_C_INLINE}
10081 @end defmac
10082
10083 @defmac AC_INT_16_BITS
10084 @maindex INT_16_BITS
10085 @cvindex INT_16_BITS
10086 If the C type @code{int} is 16 bits wide, define @code{INT_16_BITS}.
10087 Use @samp{AC_CHECK_SIZEOF(int)} instead.
10088 @end defmac
10089
10090 @defmac AC_IRIX_SUN
10091 @maindex IRIX_SUN
10092 If on IRIX (Silicon Graphics @sc{unix}), add @option{-lsun} to output
10093 @code{LIBS}. If you were using it to get @code{getmntent}, use
10094 @code{AC_FUNC_GETMNTENT} instead. If you used it for the NIS versions
10095 of the password and group functions, use @samp{AC_CHECK_LIB(sun,
10096 getpwnam)}. Up to Autoconf 2.13, it used to be
10097
10098 @example
10099 AC_CHECK_LIB(sun, getmntent, LIBS="-lsun $LIBS")
10100 @end example
10101
10102 @noindent
10103 now it is defined as
10104
10105 @example
10106 AC_FUNC_GETMNTENT
10107 AC_CHECK_LIB(sun, getpwnam)
10108 @end example
10109 @end defmac
10110
10111 @defmac AC_LANG_C
10112 @maindex LANG_C
10113 Same as @samp{AC_LANG(C)}.
10114 @end defmac
10115
10116 @defmac AC_LANG_CPLUSPLUS
10117 @maindex LANG_CPLUSPLUS
10118 Same as @samp{AC_LANG(C++)}.
10119 @end defmac
10120
10121 @defmac AC_LANG_FORTRAN77
10122 @maindex LANG_FORTRAN77
10123 Same as @samp{AC_LANG(Fortran 77)}.
10124 @end defmac
10125
10126 @defmac AC_LANG_RESTORE
10127 @maindex LANG_RESTORE
10128 Select the @var{language} that is saved on the top of the stack, as set
10129 by @code{AC_LANG_SAVE}, remove it from the stack, and call
10130 @code{AC_LANG(@var{language})}.
10131 @end defmac
10132
10133 @defmac AC_LANG_SAVE
10134 @maindex LANG_SAVE
10135 Remember the current language (as set by @code{AC_LANG}) on a stack.
10136 The current language does not change. @code{AC_LANG_PUSH} is preferred.
10137 @end defmac
10138
10139 @defmac AC_LINK_FILES (@var{source}@dots{}, @var{dest}@dots{})
10140 @maindex LINK_FILES
10141 This is an obsolete version of @code{AC_CONFIG_LINKS}. An updated
10142 version of:
10143
10144 @example
10145 AC_LINK_FILES(config/$machine.h config/$obj_format.h,
10146 host.h object.h)
10147 @end example
10148
10149 @noindent
10150 is:
10151
10152 @example
10153 AC_CONFIG_LINKS(host.h:config/$machine.h
10154 object.h:config/$obj_format.h)
10155 @end example
10156 @end defmac
10157
10158 @defmac AC_LN_S
10159 @maindex LN_S
10160 @code{AC_PROG_LN_S}
10161 @end defmac
10162
10163 @defmac AC_LONG_64_BITS
10164 @maindex LONG_64_BITS
10165 @cvindex LONG_64_BITS
10166 Define @code{LONG_64_BITS} if the C type @code{long int} is 64 bits wide.
10167 Use the generic macro @samp{AC_CHECK_SIZEOF([long int])} instead.
10168 @end defmac
10169
10170 @defmac AC_LONG_DOUBLE
10171 @maindex LONG_DOUBLE
10172 @code{AC_C_LONG_DOUBLE}
10173 @end defmac
10174
10175 @defmac AC_LONG_FILE_NAMES
10176 @maindex LONG_FILE_NAMES
10177 @code{AC_SYS_LONG_FILE_NAMES}
10178 @end defmac
10179
10180 @defmac AC_MAJOR_HEADER
10181 @maindex MAJOR_HEADER
10182 @code{AC_HEADER_MAJOR}
10183 @end defmac
10184
10185 @defmac AC_MEMORY_H
10186 @maindex MEMORY_H
10187 @cvindex NEED_MEMORY_H
10188 Used to define @code{NEED_MEMORY_H} if the @code{mem} functions were
10189 defined in @file{memory.h}. Today it is equivalent to
10190 @samp{AC_CHECK_HEADERS(memory.h)}. Adjust your code to depend upon
10191 @code{HAVE_MEMORY_H}, not @code{NEED_MEMORY_H}, see @xref{Standard
10192 Symbols}.
10193 @end defmac
10194
10195 @defmac AC_MINGW32
10196 @maindex MINGW32
10197 Similar to @code{AC_CYGWIN} but checks for the MingW32 compiler
10198 environment and sets @code{MINGW32}.
10199 @end defmac
10200
10201 @defmac AC_MINUS_C_MINUS_O
10202 @maindex MINUS_C_MINUS_O
10203 @code{AC_PROG_CC_C_O}
10204 @end defmac
10205
10206 @defmac AC_MMAP
10207 @maindex MMAP
10208 @code{AC_FUNC_MMAP}
10209 @end defmac
10210
10211 @defmac AC_MODE_T
10212 @maindex MODE_T
10213 @code{AC_TYPE_MODE_T}
10214 @end defmac
10215
10216 @defmac AC_OBJEXT
10217 @maindex OBJEXT
10218 @ovindex OBJEXT
10219 Defined the output variable @code{OBJEXT} based on the output of the
10220 compiler, after .c files have been excluded. Typically set to @samp{o}
10221 if Unix, @samp{obj} if Win32. Now the compiler checking macros handle
10222 this automatically.
10223 @end defmac
10224
10225 @defmac AC_OBSOLETE (@var{this-macro-name}, @ovar{suggestion})
10226 @maindex OBSOLETE
10227 Make @code{m4} print a message to the standard error output warning that
10228 @var{this-macro-name} is obsolete, and giving the file and line number
10229 where it was called. @var{this-macro-name} should be the name of the
10230 macro that is calling @code{AC_OBSOLETE}. If @var{suggestion} is given,
10231 it is printed at the end of the warning message; for example, it can be
10232 a suggestion for what to use instead of @var{this-macro-name}.
10233
10234 For instance
10235
10236 @example
10237 AC_OBSOLETE([$0], [; use AC_CHECK_HEADERS(unistd.h) instead])dnl
10238 @end example
10239
10240 You are encouraged to use @code{AU_DEFUN} instead, since it gives better
10241 services to the user.
10242 @end defmac
10243
10244 @defmac AC_OFF_T
10245 @maindex OFF_T
10246 @code{AC_TYPE_OFF_T}
10247 @end defmac
10248
10249 @defmac AC_OUTPUT (@ovar{file}@dots{}, @ovar{extra-cmds}, @ovar{init-cmds}, @ovar{save-defs})
10250 @maindex OUTPUT
10251 The use of @code{AC_OUTPUT} with argument is deprecated, this obsoleted
10252 interface is equivalent to:
10253
10254 @example
10255 @group
10256 AC_CONFIG_FILES(@var{file}@dots{})
10257 AC_CONFIG_COMMANDS([default],
10258 @var{extra-cmds}, @var{init-cmds})
10259 AC_SETUP_DEFS(@var{save-defs})
10260 AC_OUTPUT
10261 @end group
10262 @end example
10263
10264 If you specify @var{save-defs}, autoconf will save the @samp{#define}s in a
10265 different form, for use in the files specified in @code{AC_CONFIG_HEADERS}.
10266 In this case, autoconf substitutes the C-style @samp{#define}s where it finds
10267 @samp{@@DEFS@@}.
10268 This runs faster, and is simpler to maintain
10269 than building a file of @samp{#undef}s,
10270 since autoconf will automatically generate a @samp{#define} for each
10271 @code{AC_DEFINE} that you execute in the @code{configure} script.
10272 The value for @var{save-defs} should be
10273 either @code{cat}, or @code{sort};
10274 this value is used to filter the list of @samp{#define}s before editing.
10275 Sorted lists are easier to read,
10276 but you may wish to see the definitions in the order that they were
10277 processed.
10278 @end defmac
10279
10280 @defmac AC_OUTPUT_COMMANDS (@var{extra-cmds}, @ovar{init-cmds})
10281 @maindex OUTPUT_COMMANDS
10282 Specify additional shell commands to run at the end of
10283 @file{config.status}, and shell commands to initialize any variables
10284 from @code{configure}. This macro may be called multiple times. It is
10285 obsolete, replaced by @code{AC_CONFIG_COMMANDS}.
10286
10287 Here is an unrealistic example:
10288
10289 @example
10290 fubar=27
10291 AC_OUTPUT_COMMANDS([echo this is extra $fubar, and so on.],
10292 fubar=$fubar)
10293 AC_OUTPUT_COMMANDS([echo this is another, extra, bit],
10294 [echo init bit])
10295 @end example
10296
10297 Aside from the fact that @code{AC_CONFIG_COMMANDS} requires an
10298 additional key, an important difference is that
10299 @code{AC_OUTPUT_COMMANDS} is quoting its arguments twice, while
10300 @code{AC_CONFIG_COMMANDS}. This means that @code{AC_CONFIG_COMMANDS}
10301 can safely be given macro calls as arguments:
10302
10303 @example
10304 AC_CONFIG_COMMANDS(foo, [my_FOO()])
10305 @end example
10306
10307 @noindent
10308 conversely, where one level of quoting was enough for literal strings
10309 with @code{AC_OUTPUT_COMMANDS}, you need two with
10310 @code{AC_CONFIG_COMMANDS}. The following lines are equivalent:
10311
10312 @example
10313 @group
10314 AC_OUTPUT_COMMANDS([echo "Square brackets: []"])
10315 AC_CONFIG_COMMANDS(default, [[echo "Square brackets: []"]])
10316 @end group
10317 @end example
10318 @end defmac
10319
10320 @defmac AC_PID_T
10321 @maindex PID_T
10322 @code{AC_TYPE_PID_T}
10323 @end defmac
10324
10325 @defmac AC_PREFIX
10326 @maindex PREFIX
10327 @code{AC_PREFIX_PROGRAM}
10328 @end defmac
10329
10330 @defmac AC_PROGRAMS_CHECK
10331 @maindex PROGRAMS_CHECK
10332 @code{AC_CHECK_PROGS}
10333 @end defmac
10334
10335 @defmac AC_PROGRAMS_PATH
10336 @maindex PROGRAMS_PATH
10337 @code{AC_PATH_PROGS}
10338 @end defmac
10339
10340 @defmac AC_PROGRAM_CHECK
10341 @maindex PROGRAM_CHECK
10342 @code{AC_CHECK_PROG}
10343 @end defmac
10344
10345 @defmac AC_PROGRAM_EGREP
10346 @maindex PROGRAM_EGREP
10347 @code{AC_EGREP_CPP}
10348 @end defmac
10349
10350 @defmac AC_PROGRAM_PATH
10351 @maindex PROGRAM_PATH
10352 @code{AC_PATH_PROG}
10353 @end defmac
10354
10355 @defmac AC_REMOTE_TAPE
10356 @maindex REMOTE_TAPE
10357 removed because of limited usefulness
10358 @end defmac
10359
10360 @defmac AC_RESTARTABLE_SYSCALLS
10361 @maindex RESTARTABLE_SYSCALLS
10362 @code{AC_SYS_RESTARTABLE_SYSCALLS}
10363 @end defmac
10364
10365 @defmac AC_RETSIGTYPE
10366 @maindex RETSIGTYPE
10367 @code{AC_TYPE_SIGNAL}
10368 @end defmac
10369
10370 @defmac AC_RSH
10371 @maindex RSH
10372 Removed because of limited usefulness.
10373 @end defmac
10374
10375 @defmac AC_SCO_INTL
10376 @maindex SCO_INTL
10377 @ovindex LIBS
10378 If on SCO UNIX, add @option{-lintl} to output variable @code{LIBS}. This
10379 macro used to
10380
10381 @example
10382 AC_CHECK_LIB(intl, strftime, LIBS="-lintl $LIBS")
10383 @end example
10384
10385 @noindent
10386 now it just calls @code{AC_FUNC_STRFTIME} instead.
10387 @end defmac
10388
10389 @defmac AC_SETVBUF_REVERSED
10390 @maindex SETVBUF_REVERSED
10391 @code{AC_FUNC_SETVBUF_REVERSED}
10392 @end defmac
10393
10394 @defmac AC_SET_MAKE
10395 @maindex SET_MAKE
10396 @code{AC_PROG_MAKE_SET}
10397 @end defmac
10398
10399 @defmac AC_SIZEOF_TYPE
10400 @maindex SIZEOF_TYPE
10401 @code{AC_CHECK_SIZEOF}
10402 @end defmac
10403
10404 @defmac AC_SIZE_T
10405 @maindex SIZE_T
10406 @code{AC_TYPE_SIZE_T}
10407 @end defmac
10408
10409 @defmac AC_STAT_MACROS_BROKEN
10410 @maindex STAT_MACROS_BROKEN
10411 @code{AC_HEADER_STAT}
10412 @end defmac
10413
10414 @defmac AC_STDC_HEADERS
10415 @maindex STDC_HEADERS
10416 @code{AC_HEADER_STDC}
10417 @end defmac
10418
10419 @defmac AC_STRCOLL
10420 @maindex STRCOLL
10421 @code{AC_FUNC_STRCOLL}
10422 @end defmac
10423
10424 @defmac AC_ST_BLKSIZE
10425 @maindex ST_BLKSIZE
10426 @code{AC_STRUCT_ST_BLKSIZE}
10427 @end defmac
10428
10429 @defmac AC_ST_BLOCKS
10430 @maindex ST_BLOCKS
10431 @code{AC_STRUCT_ST_BLOCKS}
10432 @end defmac
10433
10434 @defmac AC_ST_RDEV
10435 @maindex ST_RDEV
10436 @code{AC_STRUCT_ST_RDEV}
10437 @end defmac
10438
10439 @defmac AC_SYS_RESTARTABLE_SYSCALLS
10440 @maindex SYS_RESTARTABLE_SYSCALLS
10441 @cvindex HAVE_RESTARTABLE_SYSCALLS
10442 If the system automatically restarts a system call that is interrupted
10443 by a signal, define @code{HAVE_RESTARTABLE_SYSCALLS}. This macro does
10444 not check if system calls are restarted in general--it tests whether a
10445 signal handler installed with @code{signal} (but not @code{sigaction})
10446 causes system calls to be restarted. It does not test if system calls
10447 can be restarted when interrupted by signals that have no handler.
10448
10449 These days portable programs should use @code{sigaction} with
10450 @code{SA_RESTART} if they want restartable system calls. They should
10451 not rely on @code{HAVE_RESTARTABLE_SYSCALLS}, since nowadays whether a
10452 system call is restartable is a dynamic issue, not a configuration-time
10453 issue.
10454 @end defmac
10455
10456 @defmac AC_SYS_SIGLIST_DECLARED
10457 @maindex SYS_SIGLIST_DECLARED
10458 @code{AC_DECL_SYS_SIGLIST}
10459 @end defmac
10460
10461 @defmac AC_TEST_CPP
10462 @maindex TEST_CPP
10463 @code{AC_TRY_CPP}
10464 @end defmac
10465
10466 @defmac AC_TEST_PROGRAM
10467 @maindex TEST_PROGRAM
10468 @code{AC_TRY_RUN}
10469 @end defmac
10470
10471 @defmac AC_TIMEZONE
10472 @maindex TIMEZONE
10473 @code{AC_STRUCT_TIMEZONE}
10474 @end defmac
10475
10476 @defmac AC_TIME_WITH_SYS_TIME
10477 @maindex TIME_WITH_SYS_TIME
10478 @code{AC_HEADER_TIME}
10479 @end defmac
10480
10481 @defmac AC_UID_T
10482 @maindex UID_T
10483 @code{AC_TYPE_UID_T}
10484 @end defmac
10485
10486 @defmac AC_UNISTD_H
10487 @maindex UNISTD_H
10488 Same as @samp{AC_CHECK_HEADERS(unistd.h)}.
10489 @end defmac
10490
10491 @defmac AC_USG
10492 @maindex USG
10493 @cvindex USG
10494 Define @code{USG} if the @sc{bsd} string functions are defined in
10495 @file{strings.h}. You should no longer depend upon @code{USG}, but on
10496 @code{HAVE_STRING_H}, see @xref{Standard Symbols}.
10497 @end defmac
10498
10499 @defmac AC_UTIME_NULL
10500 @maindex UTIME_NULL
10501 @code{AC_FUNC_UTIME_NULL}
10502 @end defmac
10503
10504 @defmac AC_VALIDATE_CACHED_SYSTEM_TUPLE (@ovar{cmd})
10505 @maindex VALIDATE_CACHED_SYSTEM_TUPLE
10506 If the cache file is inconsistent with the current host, target and
10507 build system types, it used to execute @var{cmd} or print a default
10508 error message.
10509
10510 This is now handled by default.
10511 @end defmac
10512
10513 @defmac AC_VERBOSE (@var{result-description})
10514 @maindex VERBOSE
10515 @code{AC_MSG_RESULT}.
10516 @end defmac
10517
10518 @defmac AC_VFORK
10519 @maindex VFORK
10520 @code{AC_FUNC_VFORK}
10521 @end defmac
10522
10523 @defmac AC_VPRINTF
10524 @maindex VPRINTF
10525 @code{AC_FUNC_VPRINTF}
10526 @end defmac
10527
10528 @defmac AC_WAIT3
10529 @maindex WAIT3
10530 @code{AC_FUNC_WAIT3}
10531 @end defmac
10532
10533 @defmac AC_WARN
10534 @maindex WARN
10535 @code{AC_MSG_WARN}
10536 @end defmac
10537
10538 @defmac AC_WORDS_BIGENDIAN
10539 @maindex WORDS_BIGENDIAN
10540 @code{AC_C_BIGENDIAN}
10541 @end defmac
10542
10543 @defmac AC_XENIX_DIR
10544 @maindex XENIX_DIR
10545 @ovindex LIBS
10546 This macro used to add @option{-lx} to output variable @code{LIBS} if on
10547 Xenix. Also, if @file{dirent.h} is being checked for, added
10548 @option{-ldir} to @code{LIBS}. Now it is merely an alias of
10549 @code{AC_HEADER_DIRENT} instead, plus some code to detect whether
10550 running @sc{xenix} on which you should not depend:
10551
10552 @example
10553 AC_MSG_CHECKING([for Xenix])
10554 AC_EGREP_CPP(yes,
10555 [#if defined M_XENIX && !defined M_UNIX
10556 yes
10557 #endif],
10558 [AC_MSG_RESULT([yes]); XENIX=yes],
10559 [AC_MSG_RESULT([no]); XENIX=])
10560 @end example
10561 @end defmac
10562
10563 @defmac AC_YYTEXT_POINTER
10564 @maindex YYTEXT_POINTER
10565 @code{AC_DECL_YYTEXT}
10566 @end defmac
10567
10568 @node Autoconf 1, Autoconf 2.13, Obsolete Macros, Obsolete Constructs
10569 @section Upgrading From Version 1
10570
10571 Autoconf version 2 is mostly backward compatible with version 1.
10572 However, it introduces better ways to do some things, and doesn't
10573 support some of the ugly things in version 1. So, depending on how
10574 sophisticated your @file{configure.ac} files are, you might have to do
10575 some manual work in order to upgrade to version 2. This chapter points
10576 out some problems to watch for when upgrading. Also, perhaps your
10577 @code{configure} scripts could benefit from some of the new features in
10578 version 2; the changes are summarized in the file @file{NEWS} in the
10579 Autoconf distribution.
10580
10581 @menu
10582 * Changed File Names:: Files you might rename
10583 * Changed Makefiles:: New things to put in @file{Makefile.in}
10584 * Changed Macros:: Macro calls you might replace
10585 * Changed Results:: Changes in how to check test results
10586 * Changed Macro Writing:: Better ways to write your own macros
10587 @end menu
10588
10589 @node Changed File Names, Changed Makefiles, Autoconf 1, Autoconf 1
10590 @subsection Changed File Names
10591
10592 If you have an @file{aclocal.m4} installed with Autoconf (as opposed to
10593 in a particular package's source directory), you must rename it to
10594 @file{acsite.m4}. @xref{autoconf Invocation}.
10595
10596 If you distribute @file{install.sh} with your package, rename it to
10597 @file{install-sh} so @code{make} builtin rules won't inadvertently
10598 create a file called @file{install} from it. @code{AC_PROG_INSTALL}
10599 looks for the script under both names, but it is best to use the new name.
10600
10601 If you were using @file{config.h.top}, @file{config.h.bot}, or
10602 @file{acconfig.h}, you still can, but you will have less clutter if you
10603 use the @code{AH_} macros. @xref{Autoheader Macros}.
10604
10605 @node Changed Makefiles, Changed Macros, Changed File Names, Autoconf 1
10606 @subsection Changed Makefiles
10607
10608 Add @samp{@@CFLAGS@@}, @samp{@@CPPFLAGS@@}, and @samp{@@LDFLAGS@@} in
10609 your @file{Makefile.in} files, so they can take advantage of the values
10610 of those variables in the environment when @code{configure} is run.
10611 Doing this isn't necessary, but it's a convenience for users.
10612
10613 Also add @samp{@@configure_input@@} in a comment to each input file for
10614 @code{AC_OUTPUT}, so that the output files will contain a comment saying
10615 they were produced by @code{configure}. Automatically selecting the
10616 right comment syntax for all the kinds of files that people call
10617 @code{AC_OUTPUT} on became too much work.
10618
10619 Add @file{config.log} and @file{config.cache} to the list of files you
10620 remove in @code{distclean} targets.
10621
10622 If you have the following in @file{Makefile.in}:
10623
10624 @example
10625 prefix = /usr/local
10626 exec_prefix = $(prefix)
10627 @end example
10628
10629 @noindent
10630 you must change it to:
10631
10632 @example
10633 prefix = @@prefix@@
10634 exec_prefix = @@exec_prefix@@
10635 @end example
10636
10637 @noindent
10638 The old behavior of replacing those variables without @samp{@@}
10639 characters around them has been removed.
10640
10641 @node Changed Macros, Changed Results, Changed Makefiles, Autoconf 1
10642 @subsection Changed Macros
10643
10644 Many of the macros were renamed in Autoconf version 2. You can still
10645 use the old names, but the new ones are clearer, and it's easier to find
10646 the documentation for them. @xref{Obsolete Macros}, for a table showing the
10647 new names for the old macros. Use the @code{autoupdate} program to
10648 convert your @file{configure.ac} to using the new macro names.
10649 @xref{autoupdate Invocation}.
10650
10651 Some macros have been superseded by similar ones that do the job better,
10652 but are not call-compatible. If you get warnings about calling obsolete
10653 macros while running @code{autoconf}, you may safely ignore them, but
10654 your @code{configure} script will generally work better if you follow
10655 the advice it prints about what to replace the obsolete macros with. In
10656 particular, the mechanism for reporting the results of tests has
10657 changed. If you were using @code{echo} or @code{AC_VERBOSE} (perhaps
10658 via @code{AC_COMPILE_CHECK}), your @code{configure} script's output will
10659 look better if you switch to @code{AC_MSG_CHECKING} and
10660 @code{AC_MSG_RESULT}. @xref{Printing Messages}. Those macros work best
10661 in conjunction with cache variables. @xref{Caching Results}.
10662
10663
10664
10665 @node Changed Results, Changed Macro Writing, Changed Macros, Autoconf 1
10666 @subsection Changed Results
10667
10668 If you were checking the results of previous tests by examining the
10669 shell variable @code{DEFS}, you need to switch to checking the values of
10670 the cache variables for those tests. @code{DEFS} no longer exists while
10671 @code{configure} is running; it is only created when generating output
10672 files. This difference from version 1 is because properly quoting the
10673 contents of that variable turned out to be too cumbersome and
10674 inefficient to do every time @code{AC_DEFINE} is called. @xref{Cache
10675 Variable Names}.
10676
10677 For example, here is a @file{configure.ac} fragment written for Autoconf
10678 version 1:
10679
10680 @example
10681 AC_HAVE_FUNCS(syslog)
10682 case "$DEFS" in
10683 *-DHAVE_SYSLOG*) ;;
10684 *) # syslog is not in the default libraries. See if it's in some other.
10685 saved_LIBS="$LIBS"
10686 for lib in bsd socket inet; do
10687 AC_CHECKING(for syslog in -l$lib)
10688 LIBS="$saved_LIBS -l$lib"
10689 AC_HAVE_FUNCS(syslog)
10690 case "$DEFS" in
10691 *-DHAVE_SYSLOG*) break ;;
10692 *) ;;
10693 esac
10694 LIBS="$saved_LIBS"
10695 done ;;
10696 esac
10697 @end example
10698
10699 Here is a way to write it for version 2:
10700
10701 @example
10702 AC_CHECK_FUNCS(syslog)
10703 if test $ac_cv_func_syslog = no; then
10704 # syslog is not in the default libraries. See if it's in some other.
10705 for lib in bsd socket inet; do
10706 AC_CHECK_LIB($lib, syslog, [AC_DEFINE(HAVE_SYSLOG)
10707 LIBS="$LIBS -l$lib"; break])
10708 done
10709 fi
10710 @end example
10711
10712 If you were working around bugs in @code{AC_DEFINE_UNQUOTED} by adding
10713 backslashes before quotes, you need to remove them. It now works
10714 predictably, and does not treat quotes (except back quotes) specially.
10715 @xref{Setting Output Variables}.
10716
10717 All of the boolean shell variables set by Autoconf macros now use
10718 @samp{yes} for the true value. Most of them use @samp{no} for false,
10719 though for backward compatibility some use the empty string instead. If
10720 you were relying on a shell variable being set to something like 1 or
10721 @samp{t} for true, you need to change your tests.
10722
10723 @node Changed Macro Writing, , Changed Results, Autoconf 1
10724 @subsection Changed Macro Writing
10725
10726 When defining your own macros, you should now use @code{AC_DEFUN}
10727 instead of @code{define}. @code{AC_DEFUN} automatically calls
10728 @code{AC_PROVIDE} and ensures that macros called via @code{AC_REQUIRE}
10729 do not interrupt other macros, to prevent nested @samp{checking@dots{}}
10730 messages on the screen. There's no actual harm in continuing to use the
10731 older way, but it's less convenient and attractive. @xref{Macro
10732 Definitions}.
10733
10734 You probably looked at the macros that came with Autoconf as a guide for
10735 how to do things. It would be a good idea to take a look at the new
10736 versions of them, as the style is somewhat improved and they take
10737 advantage of some new features.
10738
10739 If you were doing tricky things with undocumented Autoconf internals
10740 (macros, variables, diversions), check whether you need to change
10741 anything to account for changes that have been made. Perhaps you can
10742 even use an officially supported technique in version 2 instead of
10743 kludging. Or perhaps not.
10744
10745 To speed up your locally written feature tests, add caching to them.
10746 See whether any of your tests are of general enough usefulness to
10747 encapsulate into macros that you can share.
10748
10749
10750 @node Autoconf 2.13, , Autoconf 1, Obsolete Constructs
10751 @section Upgrading From Version 2.13
10752
10753 The introduction of the previous section (@pxref{Autoconf 1}) perfectly
10754 suits this section...
10755
10756 @quotation
10757 Autoconf version 2.50 is mostly backward compatible with version 2.13.
10758 However, it introduces better ways to do some things, and doesn't
10759 support some of the ugly things in version 2.13. So, depending on how
10760 sophisticated your @file{configure.ac} files are, you might have to do
10761 some manual work in order to upgrade to version 2.50. This chapter
10762 points out some problems to watch for when upgrading. Also, perhaps
10763 your @code{configure} scripts could benefit from some of the new
10764 features in version 2.50; the changes are summarized in the file
10765 @file{NEWS} in the Autoconf distribution.
10766 @end quotation
10767
10768 @menu
10769 * Changed Quotation:: Broken code which used to work
10770 * New Macros:: Interaction with foreign macros
10771 @end menu
10772
10773 @node Changed Quotation, New Macros, Autoconf 2.13, Autoconf 2.13
10774 @subsection Changed Quotation
10775
10776 The most important changes are invisible to you: the implementation of
10777 most macros have completely changed. This allowed more factorization of
10778 the code, better error messages, a higher uniformity of the user's
10779 interface etc. Unfortunately, as a side effect, some construct which
10780 used to (miraculously) work might break starting with Autoconf 2.50.
10781 The most common culprit is bad quotation.
10782
10783 For instance, in the following example, the message is not properly
10784 quoted:
10785
10786 @example
10787 AC_INIT
10788 AC_CHECK_HEADERS(foo.h,,
10789 AC_MSG_ERROR(cannot find foo.h, bailing out))
10790 AC_OUTPUT
10791 @end example
10792
10793 @noindent
10794 Autoconf 2.13 simply ignores it:
10795
10796 @example
10797 $ autoconf-2.13; ./configure --silent
10798 creating cache ./config.cache
10799 configure: error: cannot find foo.h
10800 $
10801 @end example
10802
10803 @noindent
10804 while Autoconf 2.50 will produce a broken @file{configure}:
10805
10806 @example
10807 $ autoconf-2.50; ./configure --silent
10808 configure: error: cannot find foo.h
10809 ./configure: exit: bad non-numeric arg `bailing'
10810 ./configure: exit: bad non-numeric arg `bailing'
10811 $
10812 @end example
10813
10814 The message needs to be quoted, and the @code{AC_MSG_ERROR} invocation
10815 too!
10816
10817 @example
10818 AC_INIT
10819 AC_CHECK_HEADERS(foo.h,,
10820 [AC_MSG_ERROR([cannot find foo.h, bailing out])])
10821 AC_OUTPUT
10822 @end example
10823
10824 Many many (and many more) Autoconf macros were lacking proper quotation,
10825 including no less than... @code{AC_DEFUN} itself!
10826
10827 @example
10828 $ cat configure.in
10829 AC_DEFUN([AC_PROG_INSTALL],
10830 [# My own much better version
10831 ])
10832 AC_INIT
10833 AC_PROG_INSTALL
10834 AC_OUTPUT
10835 $ autoconf-2.13
10836 autoconf: Undefined macros:
10837 ***BUG in Autoconf--please report*** AC_FD_MSG
10838 ***BUG in Autoconf--please report*** AC_EPI
10839 configure.in:1:AC_DEFUN([AC_PROG_INSTALL],
10840 configure.in:5:AC_PROG_INSTALL
10841 $ autoconf-2.50
10842 $
10843 @end example
10844
10845
10846 @node New Macros, , Changed Quotation, Autoconf 2.13
10847 @subsection New Macros
10848
10849 @cindex @code{undefined macro: _m4_divert_diversion}
10850
10851 Because Autoconf has been dormant for years, Automake provided
10852 Autoconf-like macros for a while. Autoconf 2.50 now provides better
10853 versions of these macros, integrated in the @code{AC_} namespace,
10854 instead of @code{AM_}. But in order to ease the upgrading via
10855 @command{autoupdate}, bindings to such @code{AM_} macros are provided.
10856
10857 Unfortunately Automake did not quote the name of these macros!
10858 Therefore, when @command{m4} find in @file{aclocal.m4} something like
10859 @samp{AC_DEFUN(AM_TYPE_PTRDIFF_T, ...)}, @code{AM_TYPE_PTRDIFF_T} is
10860 expanded, replaced with its Autoconf definition.
10861
10862 Fortunately Autoconf catches pre-@code{AC_INIT} expansions, and will
10863 complain, in its own words:
10864
10865 @example
10866 $ cat configure.in
10867 AC_INIT
10868 AM_TYPE_PTRDIFF_T
10869 $ aclocal-1.4
10870 $ autoconf
10871 ./aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversion
10872 actypes.m4:289: AM_TYPE_PTRDIFF_T is expanded from...
10873 ./aclocal.m4:17: the top level
10874 $
10875 @end example
10876
10877 Future versions of Automake will simply no longer define most of these
10878 macros, and will properly quote the names of the remaining macros.
10879 But you don't have to wait for it to happen to do the right thing right
10880 now: do not depend upon macros from Automake as it is simply not its job
10881 to provide macros (but the one it requires by itself):
10882
10883 @example
10884 $ cat configure.in
10885 AC_INIT
10886 AM_TYPE_PTRDIFF_T
10887 $ rm aclocal.m4
10888 $ autoupdate
10889 autoupdate: `configure.in' is updated
10890 $ cat configure.in
10891 AC_INIT
10892 AC_CHECK_TYPES([ptrdiff_t])
10893 $ aclocal-1.4
10894 $ autoconf
10895 $
10896 @end example
10897
10898 @c ================================================ Questions About Autoconf.
10899
10900 @node Questions, History, Obsolete Constructs, Top
10901 @chapter Questions About Autoconf
10902
10903 Several questions about Autoconf come up occasionally. Here some of them
10904 are addressed.
10905
10906 @menu
10907 * Distributing:: Distributing @code{configure} scripts
10908 * Why GNU m4:: Why not use the standard M4?
10909 * Bootstrapping:: Autoconf and GNU M4 require each other?
10910 * Why Not Imake:: Why GNU uses @code{configure} instead of Imake
10911 @end menu
10912
10913 @node Distributing, Why GNU m4, Questions, Questions
10914 @section Distributing @code{configure} Scripts
10915
10916 @display
10917 What are the restrictions on distributing @code{configure}
10918 scripts that Autoconf generates? How does that affect my
10919 programs that use them?
10920 @end display
10921
10922 There are no restrictions on how the configuration scripts that Autoconf
10923 produces may be distributed or used. In Autoconf version 1, they were
10924 covered by the @sc{gnu} General Public License. We still encourage
10925 software authors to distribute their work under terms like those of the
10926 GPL, but doing so is not required to use Autoconf.
10927
10928 Of the other files that might be used with @code{configure},
10929 @file{config.h.in} is under whatever copyright you use for your
10930 @file{configure.ac}. @file{config.sub} and @file{config.guess} have an
10931 exception to the GPL when they are used with an Autoconf-generated
10932 @code{configure} script, which permits you to distribute them under the
10933 same terms as the rest of your package. @file{install-sh} is from the X
10934 Consortium and is not copyrighted.
10935
10936 @node Why GNU m4, Bootstrapping, Distributing, Questions
10937 @section Why Require GNU M4?
10938
10939 @display
10940 Why does Autoconf require @sc{gnu} M4?
10941 @end display
10942
10943 Many M4 implementations have hard-coded limitations on the size and
10944 number of macros that Autoconf exceeds. They also lack several
10945 builtin macros that it would be difficult to get along without in a
10946 sophisticated application like Autoconf, including:
10947
10948 @example
10949 builtin
10950 indir
10951 patsubst
10952 __file__
10953 __line__
10954 @end example
10955
10956 Autoconf requires version 1.4 or above of @sc{gnu} M4 because it uses
10957 frozen state files.
10958
10959 Since only software maintainers need to use Autoconf, and since @sc{gnu}
10960 M4 is simple to configure and install, it seems reasonable to require
10961 @sc{gnu} M4 to be installed also. Many maintainers of @sc{gnu} and
10962 other free software already have most of the @sc{gnu} utilities
10963 installed, since they prefer them.
10964
10965 @node Bootstrapping, Why Not Imake, Why GNU m4, Questions
10966 @section How Can I Bootstrap?
10967
10968 @display
10969 If Autoconf requires @sc{gnu} M4 and @sc{gnu} M4 has an Autoconf
10970 @code{configure} script, how do I bootstrap? It seems like a chicken
10971 and egg problem!
10972 @end display
10973
10974 This is a misunderstanding. Although @sc{gnu} M4 does come with a
10975 @code{configure} script produced by Autoconf, Autoconf is not required
10976 in order to run the script and install @sc{gnu} M4. Autoconf is only
10977 required if you want to change the M4 @code{configure} script, which few
10978 people have to do (mainly its maintainer).
10979
10980 @node Why Not Imake, , Bootstrapping, Questions
10981 @section Why Not Imake?
10982
10983 @display
10984 Why not use Imake instead of @code{configure} scripts?
10985 @end display
10986
10987 Several people have written addressing this question, so I include
10988 adaptations of their explanations here.
10989
10990 The following answer is based on one written by Richard Pixley:
10991
10992 @quotation
10993 Autoconf generated scripts frequently work on machines that it has
10994 never been set up to handle before. That is, it does a good job of
10995 inferring a configuration for a new system. Imake cannot do this.
10996
10997 Imake uses a common database of host specific data. For X11, this makes
10998 sense because the distribution is made as a collection of tools, by one
10999 central authority who has control over the database.
11000
11001 @sc{gnu} tools are not released this way. Each @sc{gnu} tool has a
11002 maintainer; these maintainers are scattered across the world. Using a
11003 common database would be a maintenance nightmare. Autoconf may appear
11004 to be this kind of database, but in fact it is not. Instead of listing
11005 host dependencies, it lists program requirements.
11006
11007 If you view the @sc{gnu} suite as a collection of native tools, then the
11008 problems are similar. But the @sc{gnu} development tools can be
11009 configured as cross tools in almost any host+target permutation. All of
11010 these configurations can be installed concurrently. They can even be
11011 configured to share host independent files across hosts. Imake doesn't
11012 address these issues.
11013
11014 Imake templates are a form of standardization. The @sc{gnu} coding
11015 standards address the same issues without necessarily imposing the same
11016 restrictions.
11017 @end quotation
11018
11019
11020 Here is some further explanation, written by Per Bothner:
11021
11022 @quotation
11023 One of the advantages of Imake is that it easy to generate large
11024 Makefiles using @code{cpp}'s @samp{#include} and macro mechanisms.
11025 However, @code{cpp} is not programmable: it has limited conditional
11026 facilities, and no looping. And @code{cpp} cannot inspect its
11027 environment.
11028
11029 All of these problems are solved by using @code{sh} instead of
11030 @code{cpp}. The shell is fully programmable, has macro substitution,
11031 can execute (or source) other shell scripts, and can inspect its
11032 environment.
11033 @end quotation
11034
11035
11036 Paul Eggert elaborates more:
11037
11038 @quotation
11039 With Autoconf, installers need not assume that Imake itself is already
11040 installed and working well. This may not seem like much of an advantage
11041 to people who are accustomed to Imake. But on many hosts Imake is not
11042 installed or the default installation is not working well, and requiring
11043 Imake to install a package hinders the acceptance of that package on
11044 those hosts. For example, the Imake template and configuration files
11045 might not be installed properly on a host, or the Imake build procedure
11046 might wrongly assume that all source files are in one big directory
11047 tree, or the Imake configuration might assume one compiler whereas the
11048 package or the installer needs to use another, or there might be a
11049 version mismatch between the Imake expected by the package and the Imake
11050 supported by the host. These problems are much rarer with Autoconf,
11051 where each package comes with its own independent configuration
11052 processor.
11053
11054 Also, Imake often suffers from unexpected interactions between
11055 @code{make} and the installer's C preprocessor. The fundamental problem
11056 here is that the C preprocessor was designed to preprocess C programs,
11057 not @file{Makefile}s. This is much less of a problem with Autoconf,
11058 which uses the general-purpose preprocessor @code{m4}, and where the
11059 package's author (rather than the installer) does the preprocessing in a
11060 standard way.
11061 @end quotation
11062
11063
11064 Finally, Mark Eichin notes:
11065
11066 @quotation
11067 Imake isn't all that extensible, either. In order to add new features to
11068 Imake, you need to provide your own project template, and duplicate most
11069 of the features of the existing one. This means that for a sophisticated
11070 project, using the vendor-provided Imake templates fails to provide any
11071 leverage---since they don't cover anything that your own project needs
11072 (unless it is an X11 program).
11073
11074 On the other side, though:
11075
11076 The one advantage that Imake has over @code{configure}:
11077 @file{Imakefile}s tend to be much shorter (likewise, less redundant)
11078 than @file{Makefile.in}s. There is a fix to this, however---at least
11079 for the Kerberos V5 tree, we've modified things to call in common
11080 @file{post.in} and @file{pre.in} @file{Makefile} fragments for the
11081 entire tree. This means that a lot of common things don't have to be
11082 duplicated, even though they normally are in @code{configure} setups.
11083 @end quotation
11084
11085
11086
11087
11088 @c ===================================================== History of Autoconf.
11089
11090 @node History, Environment Variable Index, Questions, Top
11091 @chapter History of Autoconf
11092
11093 You may be wondering, Why was Autoconf originally written? How did it
11094 get into its present form? (Why does it look like gorilla spit?) If
11095 you're not wondering, then this chapter contains no information useful
11096 to you, and you might as well skip it. If you @emph{are} wondering,
11097 then let there be light@dots{}
11098
11099 @menu
11100 * Genesis:: Prehistory and naming of @code{configure}
11101 * Exodus:: The plagues of M4 and Perl
11102 * Leviticus:: The priestly code of portability arrives
11103 * Numbers:: Growth and contributors
11104 * Deuteronomy:: Approaching the promises of easy configuration
11105 @end menu
11106
11107 @node Genesis, Exodus, History, History
11108 @section Genesis
11109
11110 In June 1991 I was maintaining many of the @sc{gnu} utilities for the
11111 Free Software Foundation. As they were ported to more platforms and
11112 more programs were added, the number of @option{-D} options that users
11113 had to select in the @file{Makefile} (around 20) became burdensome.
11114 Especially for me---I had to test each new release on a bunch of
11115 different systems. So I wrote a little shell script to guess some of
11116 the correct settings for the fileutils package, and released it as part
11117 of fileutils 2.0. That @code{configure} script worked well enough that
11118 the next month I adapted it (by hand) to create similar @code{configure}
11119 scripts for several other @sc{gnu} utilities packages. Brian Berliner
11120 also adapted one of my scripts for his @sc{cvs} revision control system.
11121
11122 Later that summer, I learned that Richard Stallman and Richard Pixley
11123 were developing similar scripts to use in the @sc{gnu} compiler tools;
11124 so I adapted my @code{configure} scripts to support their evolving
11125 interface: using the file name @file{Makefile.in} as the templates;
11126 adding @samp{+srcdir}, the first option (of many); and creating
11127 @file{config.status} files.
11128
11129 @node Exodus, Leviticus, Genesis, History
11130 @section Exodus
11131
11132 As I got feedback from users, I incorporated many improvements, using
11133 Emacs to search and replace, cut and paste, similar changes in each of
11134 the scripts. As I adapted more @sc{gnu} utilities packages to use
11135 @code{configure} scripts, updating them all by hand became impractical.
11136 Rich Murphey, the maintainer of the @sc{gnu} graphics utilities, sent me
11137 mail saying that the @code{configure} scripts were great, and asking if
11138 I had a tool for generating them that I could send him. No, I thought,
11139 but I should! So I started to work out how to generate them. And the
11140 journey from the slavery of hand-written @code{configure} scripts to the
11141 abundance and ease of Autoconf began.
11142
11143 Cygnus @code{configure}, which was being developed at around that time,
11144 is table driven; it is meant to deal mainly with a discrete number of
11145 system types with a small number of mainly unguessable features (such as
11146 details of the object file format). The automatic configuration system
11147 that Brian Fox had developed for Bash takes a similar approach. For
11148 general use, it seems to me a hopeless cause to try to maintain an
11149 up-to-date database of which features each variant of each operating
11150 system has. It's easier and more reliable to check for most features on
11151 the fly---especially on hybrid systems that people have hacked on
11152 locally or that have patches from vendors installed.
11153
11154 I considered using an architecture similar to that of Cygnus
11155 @code{configure}, where there is a single @code{configure} script that
11156 reads pieces of @file{configure.in} when run. But I didn't want to have
11157 to distribute all of the feature tests with every package, so I settled
11158 on having a different @code{configure} made from each
11159 @file{configure.in} by a preprocessor. That approach also offered more
11160 control and flexibility.
11161
11162 I looked briefly into using the Metaconfig package, by Larry Wall,
11163 Harlan Stenn, and Raphael Manfredi, but I decided not to for several
11164 reasons. The @code{Configure} scripts it produces are interactive,
11165 which I find quite inconvenient; I didn't like the ways it checked for
11166 some features (such as library functions); I didn't know that it was
11167 still being maintained, and the @code{Configure} scripts I had
11168 seen didn't work on many modern systems (such as System V R4 and NeXT);
11169 it wasn't very flexible in what it could do in response to a feature's
11170 presence or absence; I found it confusing to learn; and it was too big
11171 and complex for my needs (I didn't realize then how much Autoconf would
11172 eventually have to grow).
11173
11174 I considered using Perl to generate my style of @code{configure}
11175 scripts, but decided that M4 was better suited to the job of simple
11176 textual substitutions: it gets in the way less, because output is
11177 implicit. Plus, everyone already has it. (Initially I didn't rely on
11178 the @sc{gnu} extensions to M4.) Also, some of my friends at the
11179 University of Maryland had recently been putting M4 front ends on
11180 several programs, including @code{tvtwm}, and I was interested in trying
11181 out a new language.
11182
11183 @node Leviticus, Numbers, Exodus, History
11184 @section Leviticus
11185
11186 Since my @code{configure} scripts determine the system's capabilities
11187 automatically, with no interactive user intervention, I decided to call
11188 the program that generates them Autoconfig. But with a version number
11189 tacked on, that name would be too long for old @sc{unix} file systems,
11190 so I shortened it to Autoconf.
11191
11192 In the fall of 1991 I called together a group of fellow questers after
11193 the Holy Grail of portability (er, that is, alpha testers) to give me
11194 feedback as I encapsulated pieces of my handwritten scripts in M4 macros
11195 and continued to add features and improve the techniques used in the
11196 checks. Prominent among the testers were Fran@,cois Pinard, who came up
11197 with the idea of making an @file{autoconf} shell script to run @code{m4}
11198 and check for unresolved macro calls; Richard Pixley, who suggested
11199 running the compiler instead of searching the file system to find
11200 include files and symbols, for more accurate results; Karl Berry, who
11201 got Autoconf to configure @TeX{} and added the macro index to the
11202 documentation; and Ian Lance Taylor, who added support for creating a C
11203 header file as an alternative to putting @option{-D} options in a
11204 @file{Makefile}, so he could use Autoconf for his @sc{uucp} package.
11205 The alpha testers cheerfully adjusted their files again and again as the
11206 names and calling conventions of the Autoconf macros changed from
11207 release to release. They all contributed many specific checks, great
11208 ideas, and bug fixes.
11209
11210 @node Numbers, Deuteronomy, Leviticus, History
11211 @section Numbers
11212
11213 In July 1992, after months of alpha testing, I released Autoconf 1.0,
11214 and converted many @sc{gnu} packages to use it. I was surprised by how
11215 positive the reaction to it was. More people started using it than I
11216 could keep track of, including people working on software that wasn't
11217 part of the @sc{gnu} Project (such as TCL, FSP, and Kerberos V5).
11218 Autoconf continued to improve rapidly, as many people using the
11219 @code{configure} scripts reported problems they encountered.
11220
11221 Autoconf turned out to be a good torture test for M4 implementations.
11222 @sc{unix} @code{m4} started to dump core because of the length of the
11223 macros that Autoconf defined, and several bugs showed up in @sc{gnu}
11224 @code{m4} as well. Eventually, we realized that we needed to use some
11225 features that only @sc{gnu} M4 has. 4.3@sc{bsd} @code{m4}, in
11226 particular, has an impoverished set of builtin macros; the System V
11227 version is better, but still doesn't provide everything we need.
11228
11229 More development occurred as people put Autoconf under more stresses
11230 (and to uses I hadn't anticipated). Karl Berry added checks for X11.
11231 david zuhn contributed C++ support. Fran@,cois Pinard made it diagnose
11232 invalid arguments. Jim Blandy bravely coerced it into configuring
11233 @sc{gnu} Emacs, laying the groundwork for several later improvements.
11234 Roland McGrath got it to configure the @sc{gnu} C Library, wrote the
11235 @code{autoheader} script to automate the creation of C header file
11236 templates, and added a @option{--verbose} option to @code{configure}.
11237 Noah Friedman added the @option{--autoconf-dir} option and
11238 @code{AC_MACRODIR} environment variable. (He also coined the term
11239 @dfn{autoconfiscate} to mean ``adapt a software package to use
11240 Autoconf''.) Roland and Noah improved the quoting protection in
11241 @code{AC_DEFINE} and fixed many bugs, especially when I got sick of
11242 dealing with portability problems from February through June, 1993.
11243
11244 @node Deuteronomy, , Numbers, History
11245 @section Deuteronomy
11246
11247 A long wish list for major features had accumulated, and the effect of
11248 several years of patching by various people had left some residual
11249 cruft. In April 1994, while working for Cygnus Support, I began a major
11250 revision of Autoconf. I added most of the features of the Cygnus
11251 @code{configure} that Autoconf had lacked, largely by adapting the
11252 relevant parts of Cygnus @code{configure} with the help of david zuhn
11253 and Ken Raeburn. These features include support for using
11254 @file{config.sub}, @file{config.guess}, @option{--host}, and
11255 @option{--target}; making links to files; and running @code{configure}
11256 scripts in subdirectories. Adding these features enabled Ken to convert
11257 @sc{gnu} @code{as}, and Rob Savoye to convert DejaGNU, to using
11258 Autoconf.
11259
11260 I added more features in response to other peoples' requests. Many
11261 people had asked for @code{configure} scripts to share the results of
11262 the checks between runs, because (particularly when configuring a large
11263 source tree, like Cygnus does) they were frustratingly slow. Mike
11264 Haertel suggested adding site-specific initialization scripts. People
11265 distributing software that had to unpack on MS-DOS asked for a way to
11266 override the @file{.in} extension on the file names, which produced file
11267 names like @file{config.h.in} containing two dots. Jim Avera did an
11268 extensive examination of the problems with quoting in @code{AC_DEFINE}
11269 and @code{AC_SUBST}; his insights led to significant improvements.
11270 Richard Stallman asked that compiler output be sent to @file{config.log}
11271 instead of @file{/dev/null}, to help people debug the Emacs
11272 @code{configure} script.
11273
11274 I made some other changes because of my dissatisfaction with the quality
11275 of the program. I made the messages showing results of the checks less
11276 ambiguous, always printing a result. I regularized the names of the
11277 macros and cleaned up coding style inconsistencies. I added some
11278 auxiliary utilities that I had developed to help convert source code
11279 packages to use Autoconf. With the help of Fran@,cois Pinard, I made
11280 the macros not interrupt each others' messages. (That feature revealed
11281 some performance bottlenecks in @sc{gnu} @code{m4}, which he hastily
11282 corrected!) I reorganized the documentation around problems people want
11283 to solve. And I began a test suite, because experience had shown that
11284 Autoconf has a pronounced tendency to regress when we change it.
11285
11286 Again, several alpha testers gave invaluable feedback, especially
11287 Fran@,cois Pinard, Jim Meyering, Karl Berry, Rob Savoye, Ken Raeburn,
11288 and Mark Eichin.
11289
11290 Finally, version 2.0 was ready. And there was much rejoicing. (And I
11291 have free time again. I think. Yeah, right.)
11292
11293
11294 @c ========================================================== Appendices
11295
11296 @node Environment Variable Index, Output Variable Index, History, Top
11297 @unnumbered Environment Variable Index
11298
11299 This is an alphabetical list of the environment variables that Autoconf
11300 checks.
11301
11302 @printindex ev
11303
11304 @node Output Variable Index, Preprocessor Symbol Index, Environment Variable Index, Top
11305 @unnumbered Output Variable Index
11306
11307 This is an alphabetical list of the variables that Autoconf can
11308 substitute into files that it creates, typically one or more
11309 @file{Makefile}s. @xref{Setting Output Variables}, for more information
11310 on how this is done.
11311
11312 @printindex ov
11313
11314 @node Preprocessor Symbol Index, Autoconf Macro Index, Output Variable Index, Top
11315 @unnumbered Preprocessor Symbol Index
11316
11317 This is an alphabetical list of the C preprocessor symbols that the
11318 Autoconf macros define. To work with Autoconf, C source code needs to
11319 use these names in @code{#if} directives.
11320
11321 @printindex cv
11322
11323 @node Autoconf Macro Index, M4 Macro Index, Preprocessor Symbol Index, Top
11324 @unnumbered Autoconf Macro Index
11325
11326 This is an alphabetical list of the Autoconf macros. To make the list
11327 easier to use, the macros are listed without their preceding @samp{AC_}.
11328
11329 @printindex ma
11330
11331 @node M4 Macro Index, Concept Index, Autoconf Macro Index, Top
11332 @unnumbered M4 Macro Index
11333
11334 This is an alphabetical list of the M4, M4sugar, and M4sh macros. To
11335 make the list easier to use, the macros are listed without their
11336 preceding @samp{m4_} or @samp{AS_}.
11337
11338 @printindex ms
11339
11340 @node Concept Index, , M4 Macro Index, Top
11341 @unnumbered Concept Index
11342
11343 This is an alphabetical list of the files, tools, and concepts
11344 introduced in this document.
11345
11346 @printindex cp
11347
11348 @contents
11349 @bye
11350
11351 @c Local Variables:
11352 @c ispell-local-dictionary: "american"
11353 @c End: