Debian Codegraph @

doc/autoconf.info

raw
1 This is autoconf.info, produced by makeinfo version 7.2 from
2 autoconf.texi.
3
4 This manual (17 March 2026) is for GNU Autoconf (version 2.73), a
5 package for creating scripts to configure source code packages using
6 templates and an M4 macro package.
7
8 Copyright © 1992–1996, 1998–2017, 2020–2026 Free Software Foundation,
9 Inc.
10
11 Permission is granted to copy, distribute and/or modify this
12 document under the terms of the GNU Free Documentation License,
13 Version 1.3 or any later version published by the Free Software
14 Foundation; with no Invariant Sections, no Front-Cover texts, and
15 no Back-Cover Texts. A copy of the license is included in the
16 section entitled “GNU Free Documentation License.”
17 INFO-DIR-SECTION Software development
18 START-INFO-DIR-ENTRY
19 * Autoconf: (autoconf). Create source code configuration scripts.
20 END-INFO-DIR-ENTRY
21
22 INFO-DIR-SECTION Individual utilities
23 START-INFO-DIR-ENTRY
24 * autoscan: (autoconf)autoscan Invocation.
25 Semi-automatic ‘configure.ac’ writing
26 * ifnames: (autoconf)ifnames Invocation. Listing conditionals in source.
27 * autoconf-invocation: (autoconf)autoconf Invocation.
28 How to create configuration scripts
29 * autoreconf: (autoconf)autoreconf Invocation.
30 Remaking multiple ‘configure’ scripts
31 * autoheader: (autoconf)autoheader Invocation.
32 How to create configuration templates
33 * autom4te: (autoconf)autom4te Invocation.
34 The Autoconf executables backbone
35 * configure: (autoconf)configure Invocation. Configuring a package.
36 * autoupdate: (autoconf)autoupdate Invocation.
37 Automatic update of ‘configure.ac’
38 * config.status: (autoconf)config.status Invocation. Recreating configurations.
39 * testsuite: (autoconf)testsuite Invocation. Running an Autotest test suite.
40 END-INFO-DIR-ENTRY
41
42 
43 File: autoconf.info, Node: Top, Next: Introduction, Up: (dir)
44
45 Autoconf
46 ********
47
48 This manual (17 March 2026) is for GNU Autoconf (version 2.73), a
49 package for creating scripts to configure source code packages using
50 templates and an M4 macro package.
51
52 Copyright © 1992–1996, 1998–2017, 2020–2026 Free Software Foundation,
53 Inc.
54
55 Permission is granted to copy, distribute and/or modify this
56 document under the terms of the GNU Free Documentation License,
57 Version 1.3 or any later version published by the Free Software
58 Foundation; with no Invariant Sections, no Front-Cover texts, and
59 no Back-Cover Texts. A copy of the license is included in the
60 section entitled “GNU Free Documentation License.”
61
62 * Menu:
63
64 * Introduction:: Autoconf’s purpose, strengths, and weaknesses
65 * The GNU Build System:: A set of tools for portable software packages
66 * Making configure Scripts:: How to organize and produce Autoconf scripts
67 * Setup:: Initialization and output
68 * Existing Tests:: Macros that check for particular features
69 * Writing Tests:: How to write new feature checks
70 * Results:: What to do with results from feature checks
71 * Programming in M4:: Layers on top of which Autoconf is written
72 * Programming in M4sh:: Shell portability layer
73 * Writing Autoconf Macros:: Adding new macros to Autoconf
74 * Portable Shell:: Shell script portability pitfalls
75 * Portable Make:: Makefile portability pitfalls
76 * Portable C and C++:: C and C++ portability pitfalls
77 * Manual Configuration:: Selecting features that can’t be guessed
78 * Site Configuration:: Local defaults for ‘configure’
79 * Running configure Scripts:: How to use the Autoconf output
80 * config.status Invocation:: Recreating a configuration
81 * Obsolete Constructs:: Kept for backward compatibility
82 * Using Autotest:: Creating portable test suites
83 * FAQ:: Frequent Autoconf Questions, with answers
84 * History:: History of Autoconf
85 * GNU Free Documentation License:: License for copying this manual
86 * Indices:: Indices of symbols, concepts, etc.
87
88 — The Detailed Node Listing —
89
90 The GNU Build System
91
92 * Automake:: Escaping makefile hell
93 * Gnulib:: The GNU portability library
94 * Libtool:: Building libraries portably
95 * Pointers:: More info on the GNU build system
96
97 Making ‘configure’ Scripts
98
99 * Writing Autoconf Input:: What to put in an Autoconf input file
100 * autoscan Invocation:: Semi-automatic ‘configure.ac’ writing
101 * ifnames Invocation:: Listing the conditionals in source code
102 * autoconf Invocation:: How to create configuration scripts
103 * autoreconf Invocation:: Remaking multiple ‘configure’ scripts
104
105 Writing ‘configure.ac’
106
107 * Shell Script Compiler:: Autoconf as solution of a problem
108 * Autoconf Language:: Programming in Autoconf
109 * Autoconf Input Layout:: Standard organization of ‘configure.ac’
110
111 Initialization and Output Files
112
113 * Initializing configure:: Option processing etc.
114 * Versioning:: Dealing with Autoconf versions
115 * Notices:: Copyright, version numbers in ‘configure’
116 * Input:: Where Autoconf should find files
117 * Output:: Outputting results from the configuration
118 * Configuration Actions:: Preparing the output based on results
119 * Configuration Files:: Creating output files
120 * Makefile Substitutions:: Using output variables in makefiles
121 * Configuration Headers:: Creating a configuration header file
122 * Configuration Commands:: Running arbitrary instantiation commands
123 * Configuration Links:: Links depending on the configuration
124 * Subdirectories:: Configuring independent packages together
125 * Default Prefix:: Changing the default installation prefix
126
127 Substitutions in Makefiles
128
129 * Preset Output Variables:: Output variables that are always set
130 * Installation Directory Variables:: Other preset output variables
131 * Changed Directory Variables:: Warnings about ‘datarootdir’
132 * Build Directories:: Supporting multiple concurrent compiles
133 * Automatic Remaking:: Makefile rules for configuring
134
135 Configuration Header Files
136
137 * Header Templates:: Input for the configuration headers
138 * autoheader Invocation:: How to create configuration templates
139 * Autoheader Macros:: How to specify CPP templates
140
141 Existing Tests
142
143 * Common Behavior:: Macros’ standard schemes
144 * Alternative Programs:: Selecting between alternative programs
145 * Files:: Checking for the existence of files
146 * Libraries:: Library archives that might be missing
147 * Library Functions:: C library functions that might be missing
148 * Header Files:: Header files that might be missing
149 * Declarations:: Declarations that may be missing
150 * Structures:: Structures or members that might be missing
151 * Types:: Types that might be missing
152 * Compilers and Preprocessors:: Checking for compiling programs
153 * System Services:: Operating system services
154 * C and POSIX Variants:: Kludges for C and POSIX variants
155 * Erlang Libraries:: Checking for the existence of Erlang libraries
156
157 Common Behavior
158
159 * Standard Symbols:: Symbols defined by the macros
160 * Default Includes:: Includes used by the generic macros
161
162 Alternative Programs
163
164 * Particular Programs:: Special handling to find certain programs
165 * Generic Programs:: How to find other programs
166
167 Library Functions
168
169 * Function Portability:: Pitfalls with usual functions
170 * Particular Functions:: Special handling to find certain functions
171 * Generic Functions:: How to find other functions
172
173 Header Files
174
175 * Header Portability:: Collected knowledge on common headers
176 * Particular Headers:: Special handling to find certain headers
177 * Generic Headers:: How to find other headers
178
179 Declarations
180
181 * Particular Declarations:: Macros to check for certain declarations
182 * Generic Declarations:: How to find other declarations
183
184 Structures
185
186 * Particular Structures:: Macros to check for certain structure members
187 * Generic Structures:: How to find other structure members
188
189 Types
190
191 * Particular Types:: Special handling to find certain types
192 * Generic Types:: How to find other types
193
194 Compilers and Preprocessors
195
196 * Specific Compiler Characteristics:: Some portability issues
197 * Generic Compiler Characteristics:: Language independent tests and features
198 * C Compiler:: Checking its characteristics
199 * C++ Compiler:: Likewise
200 * Objective C Compiler:: Likewise
201 * Objective C++ Compiler:: Likewise
202 * Erlang Compiler and Interpreter:: Likewise
203 * Fortran Compiler:: Likewise
204 * Go Compiler:: Likewise
205 * Algol 68 Compiler:: Likewise
206
207 Writing Tests
208
209 * Language Choice:: Selecting which language to use for testing
210 * Writing Test Programs:: Forging source files for compilers
211 * Running the Preprocessor:: Detecting preprocessor symbols
212 * Running the Compiler:: Detecting language or header features
213 * Running the Linker:: Detecting library features
214 * Runtime:: Testing for runtime features
215 * Multiple Cases:: Tests for several possible values
216
217 Writing Test Programs
218
219 * Guidelines:: General rules for writing test programs
220 * Test Functions:: Avoiding pitfalls in test programs
221 * Generating Sources:: Source program boilerplate
222
223 Results of Tests
224
225 * Defining Symbols:: Defining C preprocessor symbols
226 * Setting Output Variables:: Replacing variables in output files
227 * Special Chars in Variables:: Characters to beware of in variables
228 * Caching Results:: Speeding up subsequent ‘configure’ runs
229 * Printing Messages:: Notifying ‘configure’ users
230
231 Caching Results
232
233 * Cache Variable Names:: Shell variables used in caches
234 * Cache Files:: Files ‘configure’ uses for caching
235 * Cache Checkpointing:: Loading and saving the cache file
236
237 Programming in M4
238
239 * M4 Quotation:: Protecting macros from unwanted expansion
240 * Using autom4te:: The Autoconf executables backbone
241 * Programming in M4sugar:: Convenient pure M4 macros
242 * Debugging via autom4te:: Figuring out what M4 was doing
243
244 M4 Quotation
245
246 * Active Characters:: Characters that change the behavior of M4
247 * One Macro Call:: Quotation and one macro call
248 * Quoting and Parameters:: M4 vs. shell parameters
249 * Quotation and Nested Macros:: Macros calling macros
250 * Changequote is Evil:: Worse than INTERCAL: M4 + changequote
251 * Quadrigraphs:: Another way to escape special characters
252 * Balancing Parentheses:: Dealing with unbalanced parentheses
253 * Quotation Rule Of Thumb:: One parenthesis, one quote
254
255 Using ‘autom4te’
256
257 * autom4te Invocation:: A GNU M4 wrapper
258 * Customizing autom4te:: Customizing the Autoconf package
259
260 Programming in M4sugar
261
262 * Redefined M4 Macros:: M4 builtins changed in M4sugar
263 * Diagnostic Macros:: Diagnostic messages from M4sugar
264 * Diversion support:: Diversions in M4sugar
265 * Conditional constructs:: Conditions in M4
266 * Looping constructs:: Iteration in M4
267 * Evaluation Macros:: More quotation and evaluation control
268 * Text processing Macros:: String manipulation in M4
269 * Number processing Macros:: Arithmetic computation in M4
270 * Set manipulation Macros:: Set manipulation in M4
271 * Forbidden Patterns:: Catching unexpanded macros
272
273 Programming in M4sh
274
275 * Common Shell Constructs:: Portability layer for common shell constructs
276 * Polymorphic Variables:: Support for indirect variable names
277 * Initialization Macros:: Macros to establish a sane shell environment
278 * File Descriptor Macros:: File descriptor macros for input and output
279
280 Writing Autoconf Macros
281
282 * Macro Definitions:: Basic format of an Autoconf macro
283 * Macro Names:: What to call your new macros
284 * Dependencies Between Macros:: What to do when macros depend on other macros
285 * Obsoleting Macros:: Warning about old ways of doing things
286 * Coding Style:: Writing Autoconf macros à la Autoconf
287
288 Dependencies Between Macros
289
290 * Prerequisite Macros:: Ensuring required information
291 * Suggested Ordering:: Warning about possible ordering problems
292 * One-Shot Macros:: Ensuring a macro is called only once
293
294 Portable Shell Programming
295
296 * Systemology:: A zoology of operating systems
297 * Shellology:: A zoology of shells
298 * Invoking the Shell:: Invoking the shell as a command
299 * Here-Documents:: Quirks and tricks
300 * File Descriptors:: FDs and redirections
301 * Signal Handling:: Shells, signals, and headaches
302 * File System Conventions:: File names
303 * Shell Pattern Matching:: Pattern matching
304 * Shell Substitutions:: Variable and command expansions
305 * Assignments:: Varying side effects of assignments
306 * Parentheses:: Parentheses in shell scripts
307 * Special Shell Variables:: Variables you should not change
308 * Shell Functions:: What to look out for if you use them
309 * Limitations of Builtins:: Portable use of not so portable /bin/sh
310 * Limitations of Usual Tools:: Portable use of portable tools
311
312 Portable Make Programming
313
314 * $< in Ordinary Make Rules:: $< in ordinary rules
315 * Failure in Make Rules:: Failing portably in rules
316 * Command Line Prefixes:: What’s at the start of makefile command lines
317 * Special Chars in Names:: Special characters in macro names
318 * Backslash-Newline-Empty:: Empty lines after backslash-newline
319 * Backslash-Newline Comments:: Spanning comments across line boundaries
320 * Macros and Submakes:: ‘make macro=value’ and submakes
321 * The Make Macro MAKEFLAGS:: ‘$(MAKEFLAGS)’ portability issues
322 * The Make Macro SHELL:: ‘$(SHELL)’ portability issues
323 * Parallel Make:: Parallel ‘make’ quirks
324 * Comments in Make Rules:: Other problems with Make comments
325 * Newlines in Make Rules:: Using literal newlines in rules
326 * Comments in Make Macros:: Other problems with Make comments in macros
327 * Trailing whitespace in Make Macros:: Macro substitution problems
328 * Command-line Macros and whitespace:: Whitespace trimming of values
329 * obj/ and Make:: Don’t name a subdirectory ‘obj’
330 * make -k Status:: Exit status of ‘make -k’
331 * VPATH and Make:: ‘VPATH’ woes
332 * Single Suffix Rules:: Single suffix rules and separated dependencies
333 * Timestamps and Make:: Sub-second timestamp resolution
334
335 ‘VPATH’ and Make
336
337 * Variables listed in VPATH:: ‘VPATH’ must be literal on ancient hosts
338 * VPATH and Double-colon:: Problems with ‘::’ on ancient hosts
339 * $< in Explicit Rules:: ‘$<’ does not work in ordinary rules
340 * Automatic Rule Rewriting:: ‘VPATH’ goes wild on Solaris
341 * Make Target Lookup:: More details about ‘VPATH’ lookup
342
343 Portable C and C++ Programming
344
345 * Varieties of Unportability:: How to make your programs unportable
346 * Integer Overflow:: When integers get too large
347 * Preprocessor Arithmetic:: ‘#if’ expression problems
348 * Null Pointers:: Properties of null pointers
349 * Buffer Overruns:: Subscript errors and the like
350 * Volatile Objects:: ‘volatile’ and signals
351 * Floating Point Portability:: Portable floating-point arithmetic
352 * Exiting Portably:: Exiting and the exit status
353
354 Integer Overflow
355
356 * Integer Overflow Basics:: Why integer overflow is a problem
357 * Signed Overflow Examples:: Examples of code assuming wraparound
358 * Optimization and Wraparound:: Optimizations that break uses of wraparound
359 * Signed Overflow Advice:: Practical advice for signed overflow issues
360 * Signed Integer Division:: ‘INT_MIN / -1’ and ‘INT_MIN % -1’
361
362 Manual Configuration
363
364 * Specifying Target Triplets:: Specifying target triplets
365 * Canonicalizing:: Getting the canonical system type
366 * Using System Type:: What to do with the system type
367
368 Site Configuration
369
370 * Help Formatting:: Customizing ‘configure --help’
371 * External Software:: Working with other optional software
372 * Package Options:: Selecting optional features
373 * Pretty Help Strings:: Formatting help string
374 * Option Checking:: Controlling checking of ‘configure’ options
375 * Site Details:: Configuring site details
376 * Transforming Names:: Changing program names when installing
377 * Site Defaults:: Giving ‘configure’ local defaults
378
379 Transforming Program Names When Installing
380
381 * Transformation Options:: ‘configure’ options to transform names
382 * Transformation Examples:: Sample uses of transforming names
383 * Transformation Rules:: Makefile uses of transforming names
384
385 Running ‘configure’ Scripts
386
387 * Basic Installation:: Instructions for typical cases
388 * Installation Prerequisites:: What you need to install
389 * Compilers and Options:: Selecting compilers and optimization
390 * Multiple Architectures:: Compiling for multiple architectures at once
391 * Installation Names:: Installing in different directories
392 * Optional Features:: Selecting optional features
393 * System Types:: Specifying a system type
394 * Sharing Defaults:: Setting site-wide defaults for ‘configure’
395 * Defining Variables:: Specifying the compiler etc.
396 * configure Invocation:: Changing how ‘configure’ runs
397
398 Obsolete Constructs
399
400 * Obsolete config.status Use:: Obsolete convention for ‘config.status’
401 * acconfig Header:: Additional entries in ‘config.h.in’
402 * autoupdate Invocation:: Automatic update of ‘configure.ac’
403 * Obsolete Macros:: Backward compatibility macros
404 * Autoconf 1:: Tips for upgrading your files
405 * Autoconf 2.13:: Some fresher tips
406
407 Upgrading From Version 1
408
409 * Changed File Names:: Files you might rename
410 * Changed Makefiles:: New things to put in ‘Makefile.in’
411 * Changed Macros:: Macro calls you might replace
412 * Changed Results:: Changes in how to check test results
413 * Changed Macro Writing:: Better ways to write your own macros
414
415 Upgrading From Version 2.13
416
417 * Changed Quotation:: Broken code which used to work
418 * New Macros:: Interaction with foreign macros
419 * Hosts and Cross-Compilation:: Bugward compatibility kludges
420 * AC_LIBOBJ vs LIBOBJS:: LIBOBJS is a forbidden token
421 * AC_ACT_IFELSE vs AC_TRY_ACT:: A more generic scheme for testing sources
422
423 Generating Test Suites with Autotest
424
425 * Using an Autotest Test Suite:: Autotest and the user
426 * Writing Testsuites:: Autotest macros
427 * testsuite Invocation:: Running ‘testsuite’ scripts
428 * Making testsuite Scripts:: Using autom4te to create ‘testsuite’
429
430 Using an Autotest Test Suite
431
432 * testsuite Scripts:: The concepts of Autotest
433 * Autotest Logs:: Their contents
434
435 Frequent Autoconf Questions, with answers
436
437 * Distributing:: Distributing ‘configure’ scripts
438 * Why GNU M4:: Why not use the standard M4?
439 * Bootstrapping:: Autoconf and GNU M4 require each other?
440 * Why Not Imake:: Why GNU uses ‘configure’ instead of Imake
441 * Defining Directories:: Passing ‘datadir’ to program
442 * Autom4te Cache:: What is it? Can I remove it?
443 * Present But Cannot Be Compiled:: Compiler and Preprocessor Disagree
444 * Expanded Before Required:: Expanded Before Required
445 * Debugging:: Debugging ‘configure’ scripts
446
447 History of Autoconf
448
449 * Genesis:: Prehistory and naming of ‘configure’
450 * Exodus:: The plagues of M4 and Perl
451 * Leviticus:: The priestly code of portability arrives
452 * Numbers:: Growth and contributors
453 * Deuteronomy:: Approaching the promises of easy configuration
454
455 Indices
456
457 * Environment Variable Index:: Index of environment variables used
458 * Output Variable Index:: Index of variables set in output files
459 * Preprocessor Symbol Index:: Index of C preprocessor symbols defined
460 * Cache Variable Index:: Index of documented cache variables
461 * Autoconf Macro Index:: Index of Autoconf macros
462 * M4 Macro Index:: Index of M4, M4sugar, and M4sh macros
463 * Autotest Macro Index:: Index of Autotest macros
464 * Program & Function Index:: Index of those with portability problems
465 * Concept Index:: General index
466
467 
468 File: autoconf.info, Node: Introduction, Next: The GNU Build System, Prev: Top, Up: Top
469
470 1 Introduction
471 **************
472
473 A physicist, an engineer, and a computer scientist were discussing the
474 nature of God. “Surely a Physicist,” said the physicist, “because
475 early in the Creation, God made Light; and you know, Maxwell’s
476 equations, the dual nature of electromagnetic waves, the relativistic
477 consequences...” “An Engineer!,” said the engineer, “because
478 before making Light, God split the Chaos into Land and Water; it takes
479 a hell of an engineer to handle that big amount of mud, and orderly
480 separation of solids from liquids...” The computer scientist
481 shouted: “And the Chaos, where do you think it was coming from, hmm?”
482
483 —Anonymous
484
485 Autoconf is a tool for producing shell scripts that automatically
486 configure software source code packages to adapt to many kinds of
487 POSIX-like systems. The configuration scripts produced by Autoconf are
488 independent of Autoconf when they are run, so their users do not need to
489 have Autoconf.
490
491 The configuration scripts produced by Autoconf require no manual user
492 intervention when run; they do not normally even need an argument
493 specifying the system type. Instead, they individually test for the
494 presence of each feature that the software package they are for might
495 need. (Before each check, they print a one-line message stating what
496 they are checking for, so the user doesn’t get too bored while waiting
497 for the script to finish.) As a result, they deal well with systems
498 that are hybrids or customized from the more common POSIX variants.
499 There is no need to maintain files that list the features supported by
500 each release of each variant of POSIX.
501
502 For each software package that Autoconf is used with, it creates a
503 configuration script from a template file that lists the system features
504 that the package needs or can use. After the shell code to recognize
505 and respond to a system feature has been written, Autoconf allows it to
506 be shared by many software packages that can use (or need) that feature.
507 If it later turns out that the shell code needs adjustment for some
508 reason, it needs to be changed in only one place; all of the
509 configuration scripts can be regenerated automatically to take advantage
510 of the updated code.
511
512 Those who do not understand Autoconf are condemned to reinvent it,
513 poorly. The primary goal of Autoconf is making the _user’s_ life
514 easier; making the _maintainer’s_ life easier is only a secondary goal.
515 Put another way, the primary goal is not to make the generation of
516 ‘configure’ automatic for package maintainers (although patches along
517 that front are welcome, since package maintainers form the user base of
518 Autoconf); rather, the goal is to make ‘configure’ painless, portable,
519 and predictable for the end user of each “autoconfiscated” package. And
520 to this degree, Autoconf is highly successful at its goal—most
521 complaints to the Autoconf list are about difficulties in writing
522 Autoconf input, and not in the behavior of the resulting ‘configure’.
523 Even packages that don’t use Autoconf will generally provide a
524 ‘configure’ script, and the most common complaint about these
525 alternative home-grown scripts is that they fail to meet one or more of
526 the GNU Coding Standards (*note (standards)Configuration::) that users
527 have come to expect from Autoconf-generated ‘configure’ scripts.
528
529 The Metaconfig package is similar in purpose to Autoconf, but the
530 scripts it produces require manual user intervention, which is quite
531 inconvenient when configuring large source trees. Unlike Metaconfig
532 scripts, Autoconf scripts can support cross-compiling, if some care is
533 taken in writing them.
534
535 Autoconf does not solve all problems related to making portable
536 software packages—for a more complete solution, it should be used in
537 concert with other GNU build tools like Automake and Libtool. These
538 other tools take on jobs like the creation of a portable, recursive
539 makefile with all of the standard targets, linking of shared libraries,
540 and so on. *Note The GNU Build System::, for more information.
541
542 Autoconf imposes some restrictions on the names of macros used with
543 ‘#if’ in C programs (*note Preprocessor Symbol Index::).
544
545 Autoconf requires GNU M4 version 1.4.8 or later in order to generate
546 the scripts. It uses features that some versions of M4, including GNU
547 M4 1.3, do not have. Autoconf works better with GNU M4 version 1.4.16
548 or later, though this is not required.
549
550 *Note Autoconf 1::, for information about upgrading from version 1.
551 *Note History::, for the story of Autoconf’s development. *Note FAQ::,
552 for answers to some common questions about Autoconf.
553
554 See the Autoconf web page (https://www.gnu.org/software/autoconf/)
555 for up-to-date information, details on the mailing lists, pointers to a
556 list of known bugs, etc.
557
558 Mail suggestions to the Autoconf mailing list <[email protected]>.
559 Past suggestions are archived
560 (https://lists.gnu.org/archive/html/autoconf/).
561
562 Mail bug reports to the Autoconf Bugs mailing list
563 <[email protected]>. Past bug reports are archived
564 (https://lists.gnu.org/archive/html/bug-autoconf/).
565
566 If possible, first check that your bug is not already solved in
567 current development versions, and that it has not been reported yet. Be
568 sure to include all the needed information and a short ‘configure.ac’
569 that demonstrates the problem.
570
571 Autoconf’s development tree is accessible via ‘git’; see the Autoconf
572 Summary (https://savannah.gnu.org/projects/autoconf/) for details, or
573 view the actual repository
574 (https://git.savannah.gnu.org/cgit/autoconf.git). Patches relative to
575 the current ‘git’ version can be sent for review to the Autoconf Patches
576 mailing list <[email protected]>, with discussion on prior
577 patches archived (https://lists.gnu.org/archive/html/autoconf-patches/);
578 and all commits are posted in the read-only Autoconf Commit mailing list
579 <[email protected]>, which is also archived
580 (https://lists.gnu.org/archive/html/autoconf-commit/).
581
582 Because of its mission, the Autoconf package itself includes only a
583 set of often-used macros that have already demonstrated their
584 usefulness. Nevertheless, if you wish to share your macros, or find
585 existing ones, see the Autoconf Macro Archive
586 (https://www.gnu.org/software/autoconf-archive/), which is kindly run by
587 Peter Simons <[email protected]>.
588
589 
590 File: autoconf.info, Node: The GNU Build System, Next: Making configure Scripts, Prev: Introduction, Up: Top
591
592 2 The GNU Build System
593 **********************
594
595 Autoconf solves an important problem—reliable discovery of
596 system-specific build and runtime information—but this is only one piece
597 of the puzzle for the development of portable software. To this end,
598 the GNU project has developed a suite of integrated utilities to finish
599 the job Autoconf started: the GNU build system, whose most important
600 components are Autoconf, Automake, and Libtool. In this chapter, we
601 introduce you to those tools, point you to sources of more information,
602 and try to convince you to use the entire GNU build system for your
603 software.
604
605 * Menu:
606
607 * Automake:: Escaping makefile hell
608 * Gnulib:: The GNU portability library
609 * Libtool:: Building libraries portably
610 * Pointers:: More info on the GNU build system
611
612 
613 File: autoconf.info, Node: Automake, Next: Gnulib, Up: The GNU Build System
614
615 2.1 Automake
616 ============
617
618 The ubiquity of ‘make’ means that a makefile is almost the only viable
619 way to distribute automatic build rules for software, but one quickly
620 runs into its numerous limitations. Its lack of support for automatic
621 dependency tracking, recursive builds in subdirectories, reliable
622 timestamps (e.g., for network file systems), and so on, mean that
623 developers must painfully (and often incorrectly) reinvent the wheel for
624 each project. Portability is non-trivial, thanks to the quirks of
625 ‘make’ on many systems. On top of all this is the manual labor required
626 to implement the many standard targets that users have come to expect
627 (‘make install’, ‘make distclean’, ‘make uninstall’, etc.). Since you
628 are, of course, using Autoconf, you also have to insert repetitive code
629 in your ‘Makefile.in’ to recognize ‘@CC@’, ‘@CFLAGS@’, and other
630 substitutions provided by ‘configure’. Into this mess steps “Automake”.
631
632 Automake allows you to specify your build needs in a ‘Makefile.am’
633 file with a vastly simpler and more powerful syntax than that of a plain
634 makefile, and then generates a portable ‘Makefile.in’ for use with
635 Autoconf. For example, the ‘Makefile.am’ to build and install a simple
636 “Hello world” program might look like:
637
638 bin_PROGRAMS = hello
639 hello_SOURCES = hello.c
640
641 The resulting ‘Makefile.in’ (~400 lines) automatically supports all the
642 standard targets, the substitutions provided by Autoconf, automatic
643 dependency tracking, ‘VPATH’ building, and so on. ‘make’ builds the
644 ‘hello’ program, and ‘make install’ installs it in ‘/usr/local/bin’ (or
645 whatever prefix was given to ‘configure’, if not ‘/usr/local’).
646
647 The benefits of Automake increase for larger packages (especially
648 ones with subdirectories), but even for small programs the added
649 convenience and portability can be substantial. And that’s not all...
650
651 
652 File: autoconf.info, Node: Gnulib, Next: Libtool, Prev: Automake, Up: The GNU Build System
653
654 2.2 Gnulib
655 ==========
656
657 GNU software has a well-deserved reputation for running on many
658 different types of systems. While our primary goal is to write software
659 for the GNU system, many users and developers have been introduced to us
660 through the systems that they were already using.
661
662 Gnulib is a central location for common GNU code, intended to be
663 shared among free software packages. Its components are typically
664 shared at the source level, rather than being a library that gets built,
665 installed, and linked against. The idea is to copy files from Gnulib
666 into your own source tree. There is no distribution tarball; developers
667 should just grab source modules from the repository. The source files
668 are available online, under various licenses, mostly GNU GPL or GNU
669 LGPL.
670
671 Gnulib modules typically contain C source code along with Autoconf
672 macros used to configure the source code. For example, the Gnulib
673 ‘stdckdint’ module implements a ‘stdckdint.h’ header that nearly
674 conforms to C23, even on older hosts that lack ‘stdckdint.h’. This
675 module contains a source file for the replacement header, along with an
676 Autoconf macro that arranges to use the replacement header on older
677 systems.
678
679 For more information, consult the Gnulib website,
680 <https://www.gnu.org/software/gnulib/>.
681
682 
683 File: autoconf.info, Node: Libtool, Next: Pointers, Prev: Gnulib, Up: The GNU Build System
684
685 2.3 Libtool
686 ===========
687
688 Often, one wants to build not only programs, but libraries, so that
689 other programs can benefit from the fruits of your labor. Ideally, one
690 would like to produce _shared_ (dynamically linked) libraries, which can
691 be used by multiple programs without duplication on disk or in memory
692 and can be updated independently of the linked programs. Producing
693 shared libraries portably, however, is the stuff of nightmares—each
694 system has its own incompatible tools, compiler flags, and magic
695 incantations. Fortunately, GNU provides a solution: “Libtool”.
696
697 Libtool handles all the requirements of building shared libraries for
698 you, and at this time seems to be the _only_ way to do so with any
699 portability. It also handles many other headaches, such as: the
700 interaction of Make rules with the variable suffixes of shared
701 libraries, linking reliably with shared libraries before they are
702 installed by the superuser, and supplying a consistent versioning system
703 (so that different versions of a library can be installed or upgraded
704 without breaking binary compatibility). Although Libtool, like
705 Autoconf, can be used without Automake, it is most simply utilized in
706 conjunction with Automake—there, Libtool is used automatically whenever
707 shared libraries are needed, and you need not know its syntax.
708
709 
710 File: autoconf.info, Node: Pointers, Prev: Libtool, Up: The GNU Build System
711
712 2.4 Pointers
713 ============
714
715 Developers who are used to the simplicity of ‘make’ for small projects
716 on a single system might be daunted at the prospect of learning to use
717 Automake and Autoconf. As your software is distributed to more and more
718 users, however, you otherwise quickly find yourself putting lots of
719 effort into reinventing the services that the GNU build tools provide,
720 and making the same mistakes that they once made and overcame.
721 (Besides, since you’re already learning Autoconf, Automake is a piece of
722 cake.)
723
724 There are a number of places that you can go to for more information
725 on the GNU build tools.
726
727 − Web
728
729 The project home pages for Autoconf
730 (https://www.gnu.org/software/autoconf/), Automake
731 (https://www.gnu.org/software/automake/), Gnulib
732 (https://www.gnu.org/software/gnulib/), and Libtool
733 (https://www.gnu.org/software/libtool/).
734
735 − Automake Manual
736
737 *Note Automake: (automake)Top, for more information on Automake.
738
739 − Books
740
741 The book ‘GNU Autoconf, Automake and Libtool’(1) describes the
742 complete GNU build environment. You can also find the entire book
743 on-line (https://www.sourceware.org/autobook/).
744
745 ---------- Footnotes ----------
746
747 (1) ‘GNU Autoconf, Automake and Libtool’, by G. V. Vaughan, B.
748 Elliston, T. Tromey, and I. L. Taylor. SAMS (originally New Riders),
749 2000, ISBN 1578701902.
750
751 
752 File: autoconf.info, Node: Making configure Scripts, Next: Setup, Prev: The GNU Build System, Up: Top
753
754 3 Making ‘configure’ Scripts
755 ****************************
756
757 The configuration scripts that Autoconf produces are by convention
758 called ‘configure’. When run, ‘configure’ creates several files,
759 replacing configuration parameters in them with appropriate values. The
760 files that ‘configure’ creates are:
761
762 − one or more ‘Makefile’ files, usually one in each subdirectory of
763 the package (*note Makefile Substitutions::);
764
765 − optionally, a C header file, the name of which is configurable,
766 containing ‘#define’ directives (*note Configuration Headers::);
767
768 − a shell script called ‘config.status’ that, when run, recreates the
769 files listed above (*note config.status Invocation::);
770
771 − an optional shell script normally called ‘config.cache’ (created
772 when using ‘configure --config-cache’) that saves the results of
773 running many of the tests (*note Cache Files::);
774
775 − a file called ‘config.log’ containing any messages produced by
776 compilers, to help debugging if ‘configure’ makes a mistake.
777
778 To create a ‘configure’ script with Autoconf, you need to write an
779 Autoconf input file ‘configure.ac’ and run ‘autoconf’ on it. If you
780 write your own feature tests to supplement those that come with
781 Autoconf, you might also write files called ‘aclocal.m4’ and
782 ‘acsite.m4’. If you use a C header file to contain ‘#define’
783 directives, you might also run ‘autoheader’, and you can distribute the
784 generated file ‘config.h.in’ with the package.
785
786 Here is a diagram showing how the files that can be used in
787 configuration are produced. Programs that are executed are suffixed by
788 ‘*’. Optional files are enclosed in square brackets (‘[]’). ‘autoconf’
789 and ‘autoheader’ also read the installed Autoconf macro files (by
790 reading ‘autoconf.m4’).
791
792 Files used in preparing a software package for distribution, when using
793 just Autoconf:
794 your source files --> [autoscan*] --> [configure.scan] --> configure.ac
795
796 configure.ac --.
797 | .------> autoconf* -----> configure
798 [aclocal.m4] --+---+
799 | `-----> [autoheader*] --> [config.h.in]
800 [acsite.m4] ---'
801
802 Makefile.in
803
804 Additionally, if you use Automake, the following additional productions
805 come into play:
806
807 [acinclude.m4] --.
808 |
809 [local macros] --+--> aclocal* --> aclocal.m4
810 |
811 configure.ac ----'
812
813 configure.ac --.
814 +--> automake* --> Makefile.in
815 Makefile.am ---'
816
817 Files used in configuring a software package:
818 .-------------> [config.cache]
819 configure* ------------+-------------> config.log
820 |
821 [config.h.in] -. v .-> [config.h] -.
822 +--> config.status* -+ +--> make*
823 Makefile.in ---' `-> Makefile ---'
824
825 * Menu:
826
827 * Writing Autoconf Input:: What to put in an Autoconf input file
828 * autoscan Invocation:: Semi-automatic ‘configure.ac’ writing
829 * ifnames Invocation:: Listing the conditionals in source code
830 * autoconf Invocation:: How to create configuration scripts
831 * autoreconf Invocation:: Remaking multiple ‘configure’ scripts
832
833 
834 File: autoconf.info, Node: Writing Autoconf Input, Next: autoscan Invocation, Up: Making configure Scripts
835
836 3.1 Writing ‘configure.ac’
837 ==========================
838
839 To produce a ‘configure’ script for a software package, create a file
840 called ‘configure.ac’ that contains invocations of the Autoconf macros
841 that test the system features your package needs or can use. Autoconf
842 macros already exist to check for many features; see *note Existing
843 Tests::, for their descriptions. For most other features, you can use
844 Autoconf template macros to produce custom checks; see *note Writing
845 Tests::, for information about them. For especially tricky or
846 specialized features, ‘configure.ac’ might need to contain some
847 hand-crafted shell commands; see *note Portable Shell Programming:
848 Portable Shell. The ‘autoscan’ program can give you a good start in
849 writing ‘configure.ac’ (*note autoscan Invocation::, for more
850 information).
851
852 Previous versions of Autoconf promoted the name ‘configure.in’, which
853 is somewhat ambiguous (the tool needed to process this file is not
854 described by its extension), and introduces a slight confusion with
855 ‘config.h.in’ and so on (for which ‘.in’ means “to be processed by
856 ‘configure’”). Using ‘configure.ac’ is now preferred, while the use of
857 ‘configure.in’ will cause warnings from ‘autoconf’.
858
859 * Menu:
860
861 * Shell Script Compiler:: Autoconf as solution of a problem
862 * Autoconf Language:: Programming in Autoconf
863 * Autoconf Input Layout:: Standard organization of ‘configure.ac’
864
865 
866 File: autoconf.info, Node: Shell Script Compiler, Next: Autoconf Language, Up: Writing Autoconf Input
867
868 3.1.1 A Shell Script Compiler
869 -----------------------------
870
871 Just as for any other computer language, in order to properly program
872 ‘configure.ac’ in Autoconf you must understand _what_ problem the
873 language tries to address and _how_ it does so.
874
875 The problem Autoconf addresses is that the world is a mess. After
876 all, you are using Autoconf in order to have your package compile easily
877 on all sorts of different systems, some of them being extremely hostile.
878 Autoconf itself bears the price for these differences: ‘configure’ must
879 run on all those systems, and thus ‘configure’ must limit itself to
880 their lowest common denominator of features.
881
882 Naturally, you might then think of shell scripts; who needs
883 ‘autoconf’? A set of properly written shell functions is enough to make
884 it easy to write ‘configure’ scripts by hand. Sigh! Unfortunately,
885 even in 2008, where shells without any function support are far and few
886 between, there are pitfalls to avoid when making use of them. Also,
887 finding a Bourne shell that accepts shell functions is not trivial, even
888 though there is almost always one on interesting porting targets.
889
890 So, what is really needed is some kind of compiler, ‘autoconf’, that
891 takes an Autoconf program, ‘configure.ac’, and transforms it into a
892 portable shell script, ‘configure’.
893
894 How does ‘autoconf’ perform this task?
895
896 There are two obvious possibilities: creating a brand new language or
897 extending an existing one. The former option is attractive: all sorts
898 of optimizations could easily be implemented in the compiler and many
899 rigorous checks could be performed on the Autoconf program (e.g.,
900 rejecting any non-portable construct). Alternatively, you can extend an
901 existing language, such as the ‘sh’ (Bourne shell) language.
902
903 Autoconf does the latter: it is a layer on top of ‘sh’. It was
904 therefore most convenient to implement ‘autoconf’ as a macro expander: a
905 program that repeatedly performs “macro expansions” on text input,
906 replacing macro calls with macro bodies and producing a pure ‘sh’ script
907 in the end. Instead of implementing a dedicated Autoconf macro
908 expander, it is natural to use an existing general-purpose macro
909 language, such as M4, and implement the extensions as a set of M4
910 macros.
911
912 
913 File: autoconf.info, Node: Autoconf Language, Next: Autoconf Input Layout, Prev: Shell Script Compiler, Up: Writing Autoconf Input
914
915 3.1.2 The Autoconf Language
916 ---------------------------
917
918 The Autoconf language differs from many other computer languages because
919 it treats actual code the same as plain text. Whereas in C, for
920 instance, data and instructions have different syntactic status, in
921 Autoconf their status is rigorously the same. Therefore, we need a
922 means to distinguish literal strings from text to be expanded:
923 quotation.
924
925 When calling macros that take arguments, there must not be any white
926 space between the macro name and the open parenthesis.
927
928 AC_INIT ([oops], [1.0]) # incorrect
929 AC_INIT([hello], [1.0]) # good
930
931 Arguments should be enclosed within the quote characters ‘[’ and ‘]’,
932 and be separated by commas. Any leading blanks or newlines in arguments
933 are ignored, unless they are quoted. You should always quote an
934 argument that might contain a macro name, comma, parenthesis, or a
935 leading blank or newline. This rule applies recursively for every macro
936 call, including macros called from other macros. For more details on
937 quoting rules, see *note Programming in M4::.
938
939 For instance:
940
941 AC_CHECK_HEADER([stdio.h],
942 [AC_DEFINE([HAVE_STDIO_H], [1],
943 [Define to 1 if you have <stdio.h>.])],
944 [AC_MSG_ERROR([sorry, can't do anything for you])])
945
946 is quoted properly. You may safely simplify its quotation to:
947
948 AC_CHECK_HEADER([stdio.h],
949 [AC_DEFINE([HAVE_STDIO_H], 1,
950 [Define to 1 if you have <stdio.h>.])],
951 [AC_MSG_ERROR([sorry, can't do anything for you])])
952
953 because ‘1’ cannot contain a macro call. Here, the argument of
954 ‘AC_MSG_ERROR’ must be quoted; otherwise, its comma would be interpreted
955 as an argument separator. Also, the second and third arguments of
956 ‘AC_CHECK_HEADER’ must be quoted, since they contain macro calls. The
957 three arguments ‘HAVE_STDIO_H’, ‘stdio.h’, and ‘Define to 1 if you have
958 <stdio.h>.’ do not need quoting, but if you unwisely defined a macro
959 with a name like ‘Define’ or ‘stdio’ then they would need quoting.
960 Cautious Autoconf users would keep the quotes, but many Autoconf users
961 find such precautions annoying, and would rewrite the example as
962 follows:
963
964 AC_CHECK_HEADER(stdio.h,
965 [AC_DEFINE(HAVE_STDIO_H, 1,
966 [Define to 1 if you have <stdio.h>.])],
967 [AC_MSG_ERROR([sorry, can't do anything for you])])
968
969 This is safe, so long as you adopt good naming conventions and do not
970 define macros with names like ‘HAVE_STDIO_H’, ‘stdio’, or ‘h’. Though
971 it is also safe here to omit the quotes around ‘Define to 1 if you have
972 <stdio.h>.’ this is not recommended, as message strings are more likely
973 to inadvertently contain commas.
974
975 The following example is wrong and dangerous, as it is underquoted:
976
977 AC_CHECK_HEADER(stdio.h,
978 AC_DEFINE(HAVE_STDIO_H, 1,
979 Define to 1 if you have <stdio.h>.),
980 AC_MSG_ERROR([sorry, can't do anything for you]))
981
982 In other cases, you may want to use text that also resembles a macro
983 call. You must quote that text (whether just the potential problem, or
984 the entire line) even when it is not passed as a macro argument; and you
985 may also have to use ‘m4_pattern_allow’ (*note Forbidden Patterns::), to
986 declare your intention that the resulting configure file will have a
987 literal that resembles what would otherwise be reserved for a macro
988 name. For example:
989
990 dnl Simulate a possible future autoconf macro
991 m4_define([AC_DC], [oops])
992 dnl Underquoted:
993 echo "Hard rock was here! --AC_DC"
994 dnl Correctly quoted:
995 m4_pattern_allow([AC_DC])
996 echo "Hard rock was here! --[AC_DC]"
997 [echo "Hard rock was here! --AC_DC"]
998
999 which results in this text in ‘configure’:
1000
1001 echo "Hard rock was here! --oops"
1002 echo "Hard rock was here! --AC_DC"
1003 echo "Hard rock was here! --AC_DC"
1004
1005 When you use the same text in a macro argument, you must therefore have
1006 an extra quotation level (since one is stripped away by the macro
1007 substitution). In general, then, it is a good idea to _use double
1008 quoting for all literal string arguments_, either around just the
1009 problematic portions, or over the entire argument:
1010
1011 m4_pattern_allow([AC_DC])
1012 AC_MSG_WARN([[AC_DC] stinks --Iron Maiden])
1013 AC_MSG_WARN([[AC_DC stinks --Iron Maiden]])
1014
1015 It is also possible to avoid the problematic patterns in the first
1016 place, by the use of additional escaping (either a quadrigraph, or
1017 creative shell constructs), in which case it is no longer necessary to
1018 use ‘m4_pattern_allow’:
1019
1020 echo "Hard rock was here! --AC""_DC"
1021 AC_MSG_WARN([[AC@&t@_DC stinks --Iron Maiden]])
1022
1023 You are now able to understand one of the constructs of Autoconf that
1024 has been continually misunderstood... The rule of thumb is that
1025 _whenever you expect macro expansion, expect quote expansion_; i.e.,
1026 expect one level of quotes to be lost. For instance:
1027
1028 AC_COMPILE_IFELSE(AC_LANG_SOURCE([char b[10];]), [],
1029 [AC_MSG_ERROR([you lose])])
1030
1031 is incorrect: here, the first argument of ‘AC_LANG_SOURCE’ is ‘char
1032 b[10];’ and is expanded once, which results in ‘char b10;’; and the
1033 ‘AC_LANG_SOURCE’ is also expanded prior to being passed to
1034 ‘AC_COMPILE_IFELSE’. (There was an idiom common in Autoconf’s past to
1035 address this issue via the M4 ‘changequote’ primitive, but do not use
1036 it!) Let’s take a closer look: the author meant the first argument to
1037 be understood as a literal, and therefore it must be quoted twice;
1038 likewise, the intermediate ‘AC_LANG_SOURCE’ macro should be quoted once
1039 so that it is only expanded after the rest of the body of
1040 ‘AC_COMPILE_IFELSE’ is in place:
1041
1042 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char b[10];]])], [],
1043 [AC_MSG_ERROR([you lose])])
1044
1045 Voilà, you actually produce ‘char b[10];’ this time!
1046
1047 On the other hand, descriptions (e.g., the last parameter of
1048 ‘AC_DEFINE’ or ‘AS_HELP_STRING’) are not literals—they are subject to
1049 line breaking, for example—and should not be double quoted. Even if
1050 these descriptions are short and are not actually broken, double quoting
1051 them yields weird results.
1052
1053 Some macros take optional arguments, which this documentation
1054 represents as [ARG] (not to be confused with the quote characters). You
1055 may just leave them empty, or use ‘[]’ to make the emptiness of the
1056 argument explicit, or you may simply omit the trailing commas. The
1057 three lines below are equivalent:
1058
1059 AC_CHECK_HEADERS([stdio.h], [], [], [])
1060 AC_CHECK_HEADERS([stdio.h],,,)
1061 AC_CHECK_HEADERS([stdio.h])
1062
1063 It is best to put each macro call on its own line in ‘configure.ac’.
1064 Most of the macros don’t add extra newlines; they rely on the newline
1065 after the macro call to terminate the commands. This approach makes the
1066 generated ‘configure’ script a little easier to read by not inserting
1067 lots of blank lines. It is generally safe to set shell variables on the
1068 same line as a macro call, because the shell allows assignments without
1069 intervening newlines.
1070
1071 You can include comments in ‘configure.ac’ files by starting them
1072 with the ‘#’. For example, it is helpful to begin ‘configure.ac’ files
1073 with a line like this:
1074
1075 # Process this file with autoconf to produce a configure script.
1076
1077 
1078 File: autoconf.info, Node: Autoconf Input Layout, Prev: Autoconf Language, Up: Writing Autoconf Input
1079
1080 3.1.3 Standard ‘configure.ac’ Layout
1081 ------------------------------------
1082
1083 The order in which ‘configure.ac’ calls the Autoconf macros is not
1084 important, with a few exceptions. Every ‘configure.ac’ must contain a
1085 call to ‘AC_INIT’ before the checks, and a call to ‘AC_OUTPUT’ at the
1086 end (*note Output::). Additionally, some macros rely on other macros
1087 having been called first, because they check previously set values of
1088 some variables to decide what to do. These macros are noted in the
1089 individual descriptions (*note Existing Tests::), and they also warn you
1090 when ‘configure’ is created if they are called out of order.
1091
1092 To encourage consistency, here is a suggested order for calling the
1093 Autoconf macros. Generally speaking, the things near the end of this
1094 list are those that could depend on things earlier in it. For example,
1095 library functions could be affected by types and libraries.
1096
1097 Autoconf requirements
1098 ‘AC_INIT(PACKAGE, VERSION, BUG-REPORT-ADDRESS)’
1099 information on the package
1100 checks for programs
1101 checks for libraries
1102 checks for header files
1103 checks for types
1104 checks for structures
1105 checks for compiler characteristics
1106 checks for library functions
1107 checks for system services
1108 ‘AC_CONFIG_FILES([FILE...])’
1109 ‘AC_OUTPUT’
1110
1111 
1112 File: autoconf.info, Node: autoscan Invocation, Next: ifnames Invocation, Prev: Writing Autoconf Input, Up: Making configure Scripts
1113
1114 3.2 Using ‘autoscan’ to Create ‘configure.ac’
1115 =============================================
1116
1117 The ‘autoscan’ program can help you create and/or maintain a
1118 ‘configure.ac’ file for a software package. ‘autoscan’ examines source
1119 files in the directory tree rooted at a directory given as a command
1120 line argument, or the current directory if none is given. It searches
1121 the source files for common portability problems and creates a file
1122 ‘configure.scan’ which is a preliminary ‘configure.ac’ for that package,
1123 and checks a possibly existing ‘configure.ac’ for completeness.
1124
1125 When using ‘autoscan’ to create a ‘configure.ac’, you should manually
1126 examine ‘configure.scan’ before renaming it to ‘configure.ac’; it
1127 probably needs some adjustments. Occasionally, ‘autoscan’ outputs a
1128 macro in the wrong order relative to another macro, so that ‘autoconf’
1129 produces a warning; you need to move such macros manually. Also, if you
1130 want the package to use a configuration header file, you must add a call
1131 to ‘AC_CONFIG_HEADERS’ (*note Configuration Headers::). You might also
1132 have to change or add some ‘#if’ directives to your program in order to
1133 make it work with Autoconf (*note ifnames Invocation::, for information
1134 about a program that can help with that job).
1135
1136 When using ‘autoscan’ to maintain a ‘configure.ac’, simply consider
1137 adding its suggestions. The file ‘autoscan.log’ contains detailed
1138 information on why a macro is requested.
1139
1140 ‘autoscan’ uses several data files (installed along with Autoconf) to
1141 determine which macros to output when it finds particular symbols in a
1142 package’s source files. These data files all have the same format: each
1143 line consists of a symbol, one or more blanks, and the Autoconf macro to
1144 output if that symbol is encountered. Lines starting with ‘#’ are
1145 comments.
1146
1147 ‘autoscan’ accepts the following options:
1148
1149 ‘--help’
1150 ‘-h’
1151 Print a summary of the command line options and exit.
1152
1153 ‘--version’
1154 ‘-V’
1155 Print the version number of Autoconf and exit.
1156
1157 ‘--verbose’
1158 ‘-v’
1159 Print the names of the files it examines and the potentially
1160 interesting symbols it finds in them. This output can be
1161 voluminous.
1162
1163 ‘--debug’
1164 ‘-d’
1165 Don’t remove temporary files.
1166
1167 ‘--include=DIR’
1168 ‘-I DIR’
1169 Append DIR to the include path. Multiple invocations accumulate.
1170
1171 ‘--prepend-include=DIR’
1172 ‘-B DIR’
1173 Prepend DIR to the include path. Multiple invocations accumulate.
1174
1175 
1176 File: autoconf.info, Node: ifnames Invocation, Next: autoconf Invocation, Prev: autoscan Invocation, Up: Making configure Scripts
1177
1178 3.3 Using ‘ifnames’ to List Conditionals
1179 ========================================
1180
1181 ‘ifnames’ can help you write ‘configure.ac’ for a software package. It
1182 prints the identifiers that the package already uses in C preprocessor
1183 conditionals. If a package has already been set up to have some
1184 portability, ‘ifnames’ can thus help you figure out what its ‘configure’
1185 needs to check for. It may help fill in some gaps in a ‘configure.ac’
1186 generated by ‘autoscan’ (*note autoscan Invocation::).
1187
1188 ‘ifnames’ scans all of the C source files named on the command line
1189 (or the standard input, if none are given) and writes to the standard
1190 output a sorted list of all the identifiers that appear in those files
1191 in ‘#if’, ‘#ifdef’, ‘#ifndef’, ‘#elif’, ‘#elifdef’, or ‘#elifndef’
1192 directives. It prints each identifier on a line, followed by a
1193 space-separated list of the files in which that identifier occurs.
1194
1195 ‘ifnames’ accepts the following options:
1196
1197 ‘--help’
1198 ‘-h’
1199 Print a summary of the command line options and exit.
1200
1201 ‘--version’
1202 ‘-V’
1203 Print the version number of Autoconf and exit.
1204
1205 
1206 File: autoconf.info, Node: autoconf Invocation, Next: autoreconf Invocation, Prev: ifnames Invocation, Up: Making configure Scripts
1207
1208 3.4 Using ‘autoconf’ to Create ‘configure’
1209 ==========================================
1210
1211 To create ‘configure’ from ‘configure.ac’, run the ‘autoconf’ program
1212 with no arguments. ‘autoconf’ processes ‘configure.ac’ with the M4
1213 macro processor, using the Autoconf macros. If you give ‘autoconf’ an
1214 argument, it reads that file instead of ‘configure.ac’ and writes the
1215 configuration script to the standard output instead of to ‘configure’.
1216 If you give ‘autoconf’ the argument ‘-’, it reads from the standard
1217 input instead of ‘configure.ac’ and writes the configuration script to
1218 the standard output.
1219
1220 The Autoconf macros are defined in several files. Some of the files
1221 are distributed with Autoconf; ‘autoconf’ reads them first. Then it
1222 looks for the optional file ‘acsite.m4’ in the directory that contains
1223 the distributed Autoconf macro files, and for the optional file
1224 ‘aclocal.m4’ in the current directory. Those files can contain your
1225 site’s or the package’s own Autoconf macro definitions (*note Writing
1226 Autoconf Macros::, for more information). If a macro is defined in more
1227 than one of the files that ‘autoconf’ reads, the last definition it
1228 reads overrides the earlier ones.
1229
1230 ‘autoconf’ accepts the following options:
1231
1232 ‘--help’
1233 ‘-h’
1234 Print a summary of the command line options and exit.
1235
1236 ‘--version’
1237 ‘-V’
1238 Print the version number of Autoconf and exit.
1239
1240 ‘--verbose’
1241 ‘-v’
1242 Report processing steps.
1243
1244 ‘--debug’
1245 ‘-d’
1246 Don’t remove the temporary files.
1247
1248 ‘--force’
1249 ‘-f’
1250 Remake ‘configure’ even if newer than its input files.
1251
1252 ‘--include=DIR’
1253 ‘-I DIR’
1254 Append DIR to the include path. Multiple invocations accumulate.
1255
1256 ‘--prepend-include=DIR’
1257 ‘-B DIR’
1258 Prepend DIR to the include path. Multiple invocations accumulate.
1259
1260 ‘--output=FILE’
1261 ‘-o FILE’
1262 Save output (script or trace) to FILE. The file ‘-’ stands for the
1263 standard output.
1264
1265 ‘--warnings=CATEGORY[,CATEGORY...]’
1266 ‘-WCATEGORY[,CATEGORY...]’
1267 Enable or disable warnings related to each CATEGORY. *Note
1268 m4_warn::, for a comprehensive list of categories. Special values
1269 include:
1270
1271 ‘all’
1272 Enable all categories of warnings.
1273
1274 ‘none’
1275 Disable all categories of warnings.
1276
1277 ‘error’
1278 Treat all warnings as errors.
1279
1280 ‘no-CATEGORY’
1281 Disable warnings falling into CATEGORY.
1282
1283 The environment variable ‘WARNINGS’ may also be set to a
1284 comma-separated list of warning categories to enable or disable.
1285 It is interpreted exactly the same way as the argument of
1286 ‘--warnings’, but unknown categories are silently ignored. The
1287 command line takes precedence; for instance, if ‘WARNINGS’ is set
1288 to ‘obsolete’, but ‘-Wnone’ is given on the command line, no
1289 warnings will be issued.
1290
1291 Some categories of warnings are on by default. Again, for details
1292 see *note m4_warn::.
1293
1294 ‘--trace=MACRO[:FORMAT]’
1295 ‘-t MACRO[:FORMAT]’
1296 Do not create the ‘configure’ script, but list the calls to MACRO
1297 according to the FORMAT. Multiple ‘--trace’ arguments can be used
1298 to list several macros. Multiple ‘--trace’ arguments for a single
1299 macro are not cumulative; instead, you should just make FORMAT as
1300 long as needed.
1301
1302 The FORMAT is a regular string, with newlines if desired, and
1303 several special escape codes. It defaults to ‘$f:$l:$n:$%’; see
1304 *note autom4te Invocation::, for details on the FORMAT.
1305
1306 ‘--initialization’
1307 ‘-i’
1308 By default, ‘--trace’ does not trace the initialization of the
1309 Autoconf macros (typically the ‘AC_DEFUN’ definitions). This
1310 results in a noticeable speedup, but can be disabled by this
1311 option.
1312
1313 It is often necessary to check the content of a ‘configure.ac’ file,
1314 but parsing it yourself is extremely fragile and error-prone. It is
1315 suggested that you rely upon ‘--trace’ to scan ‘configure.ac’. For
1316 instance, to find the list of variables that are substituted, use:
1317
1318 $ autoconf -t AC_SUBST
1319 configure.ac:28:AC_SUBST:SHELL
1320 configure.ac:28:AC_SUBST:PATH_SEPARATOR
1321 More traces deleted
1322
1323 The example below highlights the difference between ‘$@’, ‘$*’, and
1324 ‘$%’.
1325
1326 $ cat configure.ac
1327 AC_DEFINE(This, is, [an
1328 [example]])
1329 $ autoconf -t 'AC_DEFINE:@: $@
1330 *: $*
1331 %: $%'
1332 @: [This],[is],[an
1333 [example]]
1334 *: This,is,an
1335 [example]
1336 %: This:is:an [example]
1337
1338 The FORMAT gives you a lot of freedom:
1339
1340 $ autoconf -t 'AC_SUBST:$$ac_subst{"$1"} = "$f:$l";'
1341 $ac_subst{"SHELL"} = "configure.ac:28";
1342 $ac_subst{"PATH_SEPARATOR"} = "configure.ac:28";
1343 More traces deleted
1344
1345 A long SEPARATOR can be used to improve the readability of complex
1346 structures, and to ease their parsing (for instance when no single
1347 character is suitable as a separator):
1348
1349 $ autoconf -t 'AM_MISSING_PROG:${|:::::|}*'
1350 ACLOCAL|:::::|aclocal|:::::|$missing_dir
1351 AUTOCONF|:::::|autoconf|:::::|$missing_dir
1352 AUTOMAKE|:::::|automake|:::::|$missing_dir
1353 More traces deleted
1354
1355 
1356 File: autoconf.info, Node: autoreconf Invocation, Prev: autoconf Invocation, Up: Making configure Scripts
1357
1358 3.5 Using ‘autoreconf’ to Update ‘configure’ Scripts
1359 ====================================================
1360
1361 Installing the various components of the GNU Build System can be
1362 tedious: running ‘autopoint’ for Gettext, ‘automake’ for ‘Makefile.in’
1363 etc. in each directory. It may be needed either because some tools such
1364 as ‘automake’ have been updated on your system, or because some of the
1365 sources such as ‘configure.ac’ have been updated, or finally, simply in
1366 order to install the GNU Build System in a fresh tree.
1367
1368 ‘autoreconf’ runs ‘autoconf’, ‘autoheader’, ‘aclocal’, ‘automake’,
1369 ‘libtoolize’, ‘intltoolize’, ‘gtkdocize’, and ‘autopoint’ (when
1370 appropriate) repeatedly to update the GNU Build System in the specified
1371 directories and their subdirectories (*note Subdirectories::). By
1372 default, it only remakes those files that are older than their sources.
1373
1374 If you install a new version of some tool, you can make ‘autoreconf’
1375 remake _all_ of the files by giving it the ‘--force’ option.
1376
1377 The environment variables ‘AUTOM4TE’, ‘AUTOCONF’, ‘AUTOHEADER’,
1378 ‘AUTOMAKE’, ‘ACLOCAL’, ‘AUTOPOINT’, ‘LIBTOOLIZE’, ‘INTLTOOLIZE’,
1379 ‘GTKDOCIZE’, ‘M4’, and ‘MAKE’ may be used to override the invocation of
1380 the respective tools.
1381
1382 Except for ‘AUTOM4TE’ and ‘M4’, setting any of these enviroment
1383 variables to ‘true’, ‘false’, ‘:’, or the empty string has the same
1384 effect as passing ‘--exclude=CMD’ on the command line, where CMD is the
1385 lowercased version of the command’s name; see the description of the
1386 ‘--exclude’ option, below.
1387
1388 *Note Automatic Remaking::, for Make rules to automatically rebuild
1389 ‘configure’ scripts when their source files change. That method handles
1390 the timestamps of configuration header templates properly, but does not
1391 pass ‘--autoconf-dir=DIR’ or ‘--localdir=DIR’.
1392
1393 Gettext supplies the ‘autopoint’ command to add translation
1394 infrastructure to a source package. If you use ‘autopoint’, your
1395 ‘configure.ac’ should invoke ‘AM_GNU_GETTEXT’ and one of
1396 ‘AM_GNU_GETTEXT_VERSION(GETTEXT-VERSION)’ or
1397 ‘AM_GNU_GETTEXT_REQUIRE_VERSION(MIN-GETTEXT-VERSION)’. *Note Invoking
1398 the ‘autopoint’ Program: (gettext)autopoint Invocation, for further
1399 details.
1400
1401 ‘autoreconf’ accepts the following options:
1402
1403 ‘--help’
1404 ‘-h’
1405 Print a summary of the command line options and exit.
1406
1407 ‘--version’
1408 ‘-V’
1409 Print the version number of Autoconf and exit.
1410
1411 ‘--verbose’
1412 ‘-v’
1413 Print the name of each directory ‘autoreconf’ examines and the
1414 commands it runs. If given two or more times, pass ‘--verbose’ to
1415 subordinate tools that support it.
1416
1417 ‘--debug’
1418 ‘-d’
1419 Don’t remove the temporary files.
1420
1421 ‘--force’
1422 ‘-f’
1423 Consider all generated and standard auxiliary files to be obsolete.
1424 This remakes even ‘configure’ scripts and configuration headers
1425 that are newer than their input files (‘configure.ac’ and, if
1426 present, ‘aclocal.m4’).
1427
1428 If deemed appropriate, this option triggers calls to ‘automake
1429 --force-missing’. Passing both ‘--force’ and ‘--install’ to
1430 ‘autoreconf’ will in turn undo any customizations to standard
1431 files. Note that the macro ‘AM_INIT_AUTOMAKE’ has some options
1432 which change the set of files considered to be standard.
1433
1434 ‘--replace-handwritten’
1435 ‘-R’
1436 Replace files that _could_ be generated but appear to have been
1437 written by hand. Currently this only affects the treatment of the
1438 primary configuration header template (usually ‘config.h.in’; *note
1439 Header Templates::). In the future it may also affect ‘aclocal.m4’
1440 and others.
1441
1442 ‘--install’
1443 ‘-i’
1444 Install any missing standard auxiliary files in the package. By
1445 default, files are copied; this can be changed with ‘--symlink’.
1446
1447 If deemed appropriate, this option triggers calls to ‘automake
1448 --add-missing’, ‘libtoolize’, ‘autopoint’, etc.
1449
1450 ‘--no-recursive’
1451 Do not rebuild files in subdirectories to configure (see *note
1452 Subdirectories::, macro ‘AC_CONFIG_SUBDIRS’).
1453
1454 ‘--symlink’
1455 ‘-s’
1456 When used with ‘--install’, install symbolic links to the missing
1457 auxiliary files instead of copying them.
1458
1459 ‘--make’
1460 ‘-m’
1461 When the directories were configured, update the configuration by
1462 running ‘./config.status --recheck && ./config.status’, and then
1463 run ‘make’.
1464
1465 ‘--exclude=CMD[,CMD...]’
1466 ‘-x CMD[,CMD...]’
1467 Do not run any CMD in the list, even if it seems to be needed. CMD
1468 can be ‘autoconf’, ‘autoheader’, ‘automake’, ‘aclocal’,
1469 ‘autopoint’, ‘libtoolize’, ‘intltoolize’, ‘gtkdocize’, or ‘make’.
1470
1471 ‘--exclude make’ has priority over ‘--make’.
1472
1473 ‘--include=DIR’
1474 ‘-I DIR’
1475 Append DIR to the include path. Multiple invocations accumulate.
1476 Passed on to ‘aclocal’, ‘autoconf’ and ‘autoheader’ internally.
1477
1478 ‘--prepend-include=DIR’
1479 ‘-B DIR’
1480 Prepend DIR to the include path. Multiple invocations accumulate.
1481 Passed on to ‘autoconf’ and ‘autoheader’ internally.
1482
1483 ‘--warnings=CATEGORY[,CATEGORY...]’
1484 ‘-WCATEGORY[,CATEGORY...]’
1485 Enable or disable warnings related to each CATEGORY. *Note
1486 m4_warn::, for a comprehensive list of categories. Special values
1487 include:
1488
1489 ‘all’
1490 Enable all categories of warnings.
1491
1492 ‘none’
1493 Disable all categories of warnings.
1494
1495 ‘error’
1496 Treat all warnings as errors.
1497
1498 ‘no-CATEGORY’
1499 Disable warnings falling into CATEGORY.
1500
1501 The environment variable ‘WARNINGS’ may also be set to a
1502 comma-separated list of warning categories to enable or disable.
1503 It is interpreted exactly the same way as the argument of
1504 ‘--warnings’, but unknown categories are silently ignored. The
1505 command line takes precedence; for instance, if ‘WARNINGS’ is set
1506 to ‘obsolete’, but ‘-Wnone’ is given on the command line, no
1507 warnings will be issued.
1508
1509 Some categories of warnings are on by default. Again, for details
1510 see *note m4_warn::.
1511
1512 If you want ‘autoreconf’ to pass flags that are not listed here on to
1513 ‘aclocal’, set ‘ACLOCAL_AMFLAGS’ in your ‘Makefile.am’. Due to a
1514 limitation in the Autoconf implementation these flags currently must be
1515 set on a single line in ‘Makefile.am’, without any backslash-newlines or
1516 makefile comments. Also, be aware that future Automake releases might
1517 start flagging ‘ACLOCAL_AMFLAGS’ as obsolescent, or even remove support
1518 for it.
1519
1520 
1521 File: autoconf.info, Node: Setup, Next: Existing Tests, Prev: Making configure Scripts, Up: Top
1522
1523 4 Initialization and Output Files
1524 *********************************
1525
1526 Autoconf-generated ‘configure’ scripts need some information about how
1527 to initialize, such as how to find the package’s source files and about
1528 the output files to produce. The following sections describe the
1529 initialization and the creation of output files.
1530
1531 * Menu:
1532
1533 * Initializing configure:: Option processing etc.
1534 * Versioning:: Dealing with Autoconf versions
1535 * Notices:: Copyright, version numbers in ‘configure’
1536 * Input:: Where Autoconf should find files
1537 * Output:: Outputting results from the configuration
1538 * Configuration Actions:: Preparing the output based on results
1539 * Configuration Files:: Creating output files
1540 * Makefile Substitutions:: Using output variables in makefiles
1541 * Configuration Headers:: Creating a configuration header file
1542 * Configuration Commands:: Running arbitrary instantiation commands
1543 * Configuration Links:: Links depending on the configuration
1544 * Subdirectories:: Configuring independent packages together
1545 * Default Prefix:: Changing the default installation prefix
1546
1547 
1548 File: autoconf.info, Node: Initializing configure, Next: Versioning, Up: Setup
1549
1550 4.1 Initializing ‘configure’
1551 ============================
1552
1553 Every ‘configure’ script must call ‘AC_INIT’ before doing anything else
1554 that produces output. Calls to silent macros, such as ‘AC_DEFUN’, may
1555 also occur prior to ‘AC_INIT’, although these are generally used via
1556 ‘aclocal.m4’, since that is implicitly included before the start of
1557 ‘configure.ac’. The only other required macro is ‘AC_OUTPUT’ (*note
1558 Output::).
1559
1560 — Macro: AC_INIT(PACKAGE, VERSION, [BUG-REPORT], [TARNAME], [URL])
1561 Process any command-line arguments and perform initialization and
1562 verification.
1563
1564 Set the name of the PACKAGE and its VERSION. These are typically
1565 used in ‘--version’ support, including that of ‘configure’. The
1566 optional argument BUG-REPORT should be the email to which users
1567 should send bug reports. The package TARNAME differs from PACKAGE:
1568 the latter designates the full package name (e.g., ‘GNU Autoconf’),
1569 while the former is meant for distribution tar ball names (e.g.,
1570 ‘autoconf’). It defaults to PACKAGE with ‘GNU ’ stripped,
1571 lower-cased, and all characters other than alphanumerics and
1572 underscores are changed to ‘-’. If provided, URL should be the
1573 home page for the package.
1574
1575 Leading and trailing whitespace is stripped from all the arguments
1576 to ‘AC_INIT’, and interior whitespace is collapsed to a single
1577 space. This means that, for instance, if you want to put several
1578 email addresses in BUG-REPORT, you can put each one on its own
1579 line:
1580
1581 # We keep having problems with the mail hosting for
1582 # gnomovision.example, so give people an alternative.
1583 AC_INIT([Gnomovision], [17.0.1], [
1584 [email protected]
1585 or [email protected]
1586 ])
1587
1588 The arguments to ‘AC_INIT’ may be computed by M4, when ‘autoconf’
1589 is run. For instance, if you want to include the package’s version
1590 number in the TARNAME, but you don’t want to repeat it, you can use
1591 a helper macro:
1592
1593 m4_define([gnomo_VERSION], [17.0.1])
1594 AC_INIT([Gnomovision],
1595 m4_defn([gnomo_VERSION]),
1596 [[email protected]],
1597 [gnomo-]m4_defn([gnomo_VERSION]))
1598
1599 This uses ‘m4_defn’ to produce the expansion of ‘gnomo_VERSION’ _as
1600 a quoted string_, so that if there happen to be any more M4 macro
1601 names in ‘gnomo_VERSION’, they will not be expanded. *Note
1602 Renaming Macros: (m4)Defn.
1603
1604 Continuing this example, if you don’t want to embed the version
1605 number in ‘configure.ac’ at all, you can use ‘m4_esyscmd’ to look
1606 it up somewhere else when ‘autoconf’ is run:
1607
1608 m4_define([gnomo_VERSION],
1609 m4_esyscmd([build-aux/git-version-gen .tarball-version]))
1610 AC_INIT([Gnomovision],
1611 m4_defn([gnomo_VERSION]),
1612 [[email protected]],
1613 [gnomo-]m4_defn([gnomo_VERSION]))
1614
1615 This uses the utility script ‘git-version-gen’ to look up the
1616 package’s version in its version control metadata. This script is
1617 part of Gnulib (*note Gnulib::).
1618
1619 The arguments to ‘AC_INIT’ are written into ‘configure’ in several
1620 different places. Therefore, we strongly recommend that you write
1621 any M4 logic in ‘AC_INIT’ arguments to be evaluated _before_
1622 ‘AC_INIT’ itself is evaluated. For instance, in the above example,
1623 the second argument to ‘m4_define’ is _not_ quoted, so the
1624 ‘m4_esyscmd’ is evaluated only once, and ‘gnomo_VERSION’ is defined
1625 to the output of the command. If the second argument to
1626 ‘m4_define’ were quoted, ‘m4_esyscmd’ would be evaluated each time
1627 the VERSION or TARNAME arguments were written to ‘configure’, and
1628 the command would be run repeatedly.
1629
1630 In some of the places where the arguments to ‘AC_INIT’ are used,
1631 within ‘configure’, shell evaluation cannot happen. Therefore, the
1632 arguments to ‘AC_INIT’ may _not_ be computed when ‘configure’ is
1633 run. If they contain any construct that isn’t always treated as
1634 literal by the shell (e.g. variable expansions), ‘autoconf’ will
1635 issue an error.
1636
1637 The TARNAME argument is used to construct filenames. It should not
1638 contain wildcard characters, white space, or anything else that
1639 could be troublesome as part of a file or directory name.
1640
1641 Some of M4’s active characters (notably parentheses, square
1642 brackets, ‘,’ and ‘#’) commonly appear in URLs and lists of email
1643 addresses. If any of these characters appear in an argument to
1644 AC_INIT, that argument will probably need to be double-quoted to
1645 avoid errors and mistranscriptions. *Note M4 Quotation::.
1646
1647 The following M4 macros (e.g., ‘AC_PACKAGE_NAME’), output variables
1648 (e.g., ‘PACKAGE_NAME’), and preprocessor symbols (e.g.,
1649 ‘PACKAGE_NAME’), are defined by ‘AC_INIT’:
1650
1651 ‘AC_PACKAGE_NAME’, ‘PACKAGE_NAME’
1652 Exactly PACKAGE.
1653
1654 ‘AC_PACKAGE_TARNAME’, ‘PACKAGE_TARNAME’
1655 Exactly TARNAME, possibly generated from PACKAGE.
1656
1657 ‘AC_PACKAGE_VERSION’, ‘PACKAGE_VERSION’
1658 Exactly VERSION.
1659
1660 ‘AC_PACKAGE_STRING’, ‘PACKAGE_STRING’
1661 Exactly ‘PACKAGE VERSION’.
1662
1663 ‘AC_PACKAGE_BUGREPORT’, ‘PACKAGE_BUGREPORT’
1664 Exactly BUG-REPORT, if one was provided. Typically an email
1665 address, or URL to a bug management web page.
1666
1667 ‘AC_PACKAGE_URL’, ‘PACKAGE_URL’
1668 Exactly URL, if one was provided. If URL was empty, but
1669 PACKAGE begins with ‘GNU ’, then this defaults to
1670 ‘https://www.gnu.org/software/TARNAME/’, otherwise, no URL is
1671 assumed.
1672
1673 If your ‘configure’ script does its own option processing, it should
1674 inspect ‘$@’ or ‘$*’ immediately after calling ‘AC_INIT’, because other
1675 Autoconf macros liberally use the ‘set’ command to process strings, and
1676 this has the side effect of updating ‘$@’ and ‘$*’. However, we suggest
1677 that you use standard macros like ‘AC_ARG_ENABLE’ instead of attempting
1678 to implement your own option processing. *Note Site Configuration::.
1679
1680 
1681 File: autoconf.info, Node: Versioning, Next: Notices, Prev: Initializing configure, Up: Setup
1682
1683 4.2 Dealing with Autoconf versions
1684 ==================================
1685
1686 The following optional macros can be used to help choose the minimum
1687 version of Autoconf that can successfully compile a given
1688 ‘configure.ac’.
1689
1690 — Macro: AC_PREREQ(VERSION)
1691 Ensure that a recent enough version of Autoconf is being used. If
1692 the version of Autoconf being used to create ‘configure’ is earlier
1693 than VERSION, print an error message to the standard error output
1694 and exit with failure (exit status is 63). For example:
1695
1696 AC_PREREQ([2.73])
1697
1698 This macro may be used before ‘AC_INIT’.
1699
1700 — Macro: AC_AUTOCONF_VERSION
1701 This macro was introduced in Autoconf 2.62. It identifies the
1702 version of Autoconf that is currently parsing the input file, in a
1703 format suitable for ‘m4_version_compare’ (*note
1704 m4_version_compare::); in other words, for this release of
1705 Autoconf, its value is ‘2.73’. One potential use of this macro is
1706 for writing conditional fallbacks based on when a feature was added
1707 to Autoconf, rather than using ‘AC_PREREQ’ to require the newer
1708 version of Autoconf. However, remember that the Autoconf
1709 philosophy favors feature checks over version checks.
1710
1711 You should not expand this macro directly; use
1712 ‘m4_defn([AC_AUTOCONF_VERSION])’ instead. This is because some
1713 users might have a beta version of Autoconf installed, with
1714 arbitrary letters included in its version string. This means it is
1715 possible for the version string to contain the name of a defined
1716 macro, such that expanding ‘AC_AUTOCONF_VERSION’ would trigger the
1717 expansion of that macro during rescanning, and change the version
1718 string to be different than what you intended to check.
1719
1720 
1721 File: autoconf.info, Node: Notices, Next: Input, Prev: Versioning, Up: Setup
1722
1723 4.3 Notices in ‘configure’
1724 ==========================
1725
1726 The following macros manage version numbers for ‘configure’ scripts.
1727 Using them is optional.
1728
1729 — Macro: AC_COPYRIGHT(COPYRIGHT-NOTICE)
1730 State that, in addition to the Free Software Foundation’s copyright
1731 on the Autoconf macros, parts of your ‘configure’ are covered by
1732 the COPYRIGHT-NOTICE.
1733
1734 The COPYRIGHT-NOTICE shows up in both the head of ‘configure’ and
1735 in ‘configure --version’.
1736
1737 — Macro: AC_REVISION(REVISION-INFO)
1738 Copy revision stamp REVISION-INFO into the ‘configure’ script, with
1739 any dollar signs or double-quotes removed. This macro lets you put
1740 a revision stamp from ‘configure.ac’ into ‘configure’ that the
1741 traditional version control systems RCS and CVS can update, without
1742 these systems changing it again when you check in the resulting
1743 ‘configure’. That way, you can determine easily which revision of
1744 ‘configure.ac’ a particular ‘configure’ corresponds to.
1745
1746 For example, this line in ‘configure.ac’:
1747
1748 AC_REVISION([$Revision: 1.30 $])
1749
1750 produces this in ‘configure’:
1751
1752 #!/bin/sh
1753 # From configure.ac Revision: 1.30
1754
1755 
1756 File: autoconf.info, Node: Input, Next: Output, Prev: Notices, Up: Setup
1757
1758 4.4 Configure Input: Source Code, Macros, and Auxiliary Files
1759 =============================================================
1760
1761 The following macros help you manage the contents of your source tree.
1762
1763 — Macro: AC_CONFIG_SRCDIR(UNIQUE-FILE-IN-SOURCE-DIR)
1764 Distinguish this package’s source directory from other source
1765 directories that might happen to exist in the file system.
1766 UNIQUE-FILE-IN-SOURCE-DIR should name a file that is unique to this
1767 package. ‘configure’ will verify that this file exists in
1768 ‘SRCDIR’, before it runs any other checks.
1769
1770 Use of this macro is strongly recommended. It protects against
1771 people accidentally specifying the wrong directory with ‘--srcdir’.
1772 *Note configure Invocation::, for more information.
1773
1774 Packages that use ‘aclocal’ to generate ‘aclocal.m4’ should declare
1775 where local macros can be found using ‘AC_CONFIG_MACRO_DIRS’.
1776
1777 — Macro: AC_CONFIG_MACRO_DIRS(DIR1 [DIR2 ... DIRN])
1778 — Macro: AC_CONFIG_MACRO_DIR(DIR)
1779 Specify the given directories as the location of additional local
1780 Autoconf macros. These macros are intended for use by commands
1781 like ‘autoreconf’ or ‘aclocal’ that trace macro calls; they should
1782 be called directly from ‘configure.ac’ so that tools that install
1783 macros for ‘aclocal’ can find the macros’ declarations. Tools that
1784 want to learn which directories have been selected should trace
1785 ‘AC_CONFIG_MACRO_DIR_TRACE’, which will be called once per
1786 directory.
1787
1788 AC_CONFIG_MACRO_DIRS is the preferred form, and can be called
1789 multiple times and with multiple arguments; in such cases,
1790 directories in earlier calls are expected to be searched before
1791 directories in later calls, and directories appearing in the same
1792 call are expected to be searched in the order in which they appear
1793 in the call. For historical reasons, the macro AC_CONFIG_MACRO_DIR
1794 can also be used once, if it appears first, for tools such as older
1795 ‘libtool’ that weren’t prepared to handle multiple directories.
1796 For example, a usage like
1797
1798 AC_CONFIG_MACRO_DIR([dir1])
1799 AC_CONFIG_MACRO_DIRS([dir2])
1800 AC_CONFIG_MACRO_DIRS([dir3 dir4])
1801
1802 will cause the trace of AC_CONFIG_MACRO_DIR_TRACE to appear four
1803 times, and should cause the directories to be searched in this
1804 order: ‘dir1 dir2 dir3 dir4’.
1805
1806 Note that if you use ‘aclocal’ from an Automake release prior to
1807 1.13 to generate ‘aclocal.m4’, you must also set ‘ACLOCAL_AMFLAGS =
1808 -I DIR1 [-I DIR2 ... -I DIRN]’ in your top-level ‘Makefile.am’.
1809 Due to a limitation in the Autoconf implementation of ‘autoreconf’,
1810 these include directives currently must be set on a single line in
1811 ‘Makefile.am’, without any backslash-newlines or makefile comments.
1812
1813 Some Autoconf macros require auxiliary scripts. ‘AC_PROG_INSTALL’
1814 (*note Particular Programs::) requires a fallback implementation of
1815 ‘install’ called ‘install-sh’, and the ‘AC_CANONICAL’ macros (*note
1816 Manual Configuration::) require the system-identification scripts
1817 ‘config.sub’ and ‘config.guess’. Third-party tools, such as Automake
1818 and Libtool, may require additional auxiliary scripts.
1819
1820 By default, ‘configure’ looks for these scripts next to itself, in
1821 ‘SRCDIR’. For convenience when working with subdirectories with their
1822 own configure scripts (*note Subdirectories::), if the scripts are not
1823 in ‘SRCDIR’ it will also look in ‘SRCDIR/..’ and ‘SRCDIR/../..’. All of
1824 the scripts must be found in the same directory.
1825
1826 If these default locations are not adequate, or simply to reduce
1827 clutter at the top level of the source tree, packages can use
1828 ‘AC_CONFIG_AUX_DIR’ to declare where to look for auxiliary scripts.
1829
1830 — Macro: AC_CONFIG_AUX_DIR(DIR)
1831 Look for auxiliary scripts in DIR. Normally, DIR should be a
1832 relative path, which is taken as relative to ‘SRCDIR’. If DIR is
1833 an absolute path or contains shell variables, however, it is used
1834 as-is.
1835
1836 When the goal of using ‘AC_CONFIG_AUX_DIR’ is to reduce clutter at
1837 the top level of the source tree, the conventional name for DIR is
1838 ‘build-aux’. If you need portability to DOS variants, do not name
1839 the auxiliary directory ‘aux’. *Note File System Conventions::.
1840
1841 — Macro: AC_REQUIRE_AUX_FILE(FILE)
1842 Declare that FILE is an auxiliary script needed by this configure
1843 script, and set the shell variable ‘ac_aux_dir’ to the directory
1844 where it can be found. The value of ‘ac_aux_dir’ is guaranteed to
1845 end with a ‘/’.
1846
1847 Macros that need auxiliary scripts must use this macro to register
1848 each script they need.
1849
1850 ‘configure’ checks for all the auxiliary scripts it needs on startup,
1851 and exits with an error if any are missing.
1852
1853 ‘autoreconf’ also detects missing auxiliary scripts. When used with
1854 the ‘--install’ option, ‘autoreconf’ will try to add missing scripts to
1855 the directory specified by ‘AC_CONFIG_AUX_DIR’, or to the top level of
1856 the source tree if ‘AC_CONFIG_AUX_DIR’ was not used. It can always do
1857 this for the scripts needed by Autoconf core macros: ‘install-sh’,
1858 ‘config.sub’, and ‘config.guess’. Many other commonly-needed scripts
1859 are installed by the third-party tools that ‘autoreconf’ knows how to
1860 run, such as ‘missing’ for Automake and ‘ltmain.sh’ for Libtool.
1861
1862 If you are using Automake, auxiliary scripts will automatically be
1863 included in the tarball created by ‘make dist’. If you are not using
1864 Automake you will need to arrange for auxiliary scripts to be included
1865 in tarballs yourself. Auxiliary scripts should normally _not_ be
1866 checked into a version control system, for the same reasons that
1867 ‘configure’ shouldn’t be.
1868
1869 The scripts needed by Autoconf core macros can be found in
1870 ‘$(datadir)/autoconf/build-aux’ of the Autoconf installation (*note
1871 Installation Directory Variables::). ‘install-sh’ can be downloaded
1872 from
1873 <https://git.savannah.gnu.org/cgit/automake.git/plain/lib/install-sh>.
1874 ‘config.sub’ and ‘config.guess’ can be downloaded from
1875 <https://git.savannah.gnu.org/cgit/config.git/tree/>.
1876
1877 
1878 File: autoconf.info, Node: Output, Next: Configuration Actions, Prev: Input, Up: Setup
1879
1880 4.5 Outputting Files
1881 ====================
1882
1883 Every Autoconf script, e.g., ‘configure.ac’, should finish by calling
1884 ‘AC_OUTPUT’. That is the macro that generates and runs ‘config.status’,
1885 which in turn creates the makefiles and any other files resulting from
1886 configuration. This is the only required macro besides ‘AC_INIT’ (*note
1887 Input::).
1888
1889 — Macro: AC_OUTPUT
1890 Generate ‘config.status’ and launch it. Call this macro once, at
1891 the end of ‘configure.ac’.
1892
1893 ‘config.status’ performs all the configuration actions: all the
1894 output files (see *note Configuration Files::, macro
1895 ‘AC_CONFIG_FILES’), header files (see *note Configuration
1896 Headers::, macro ‘AC_CONFIG_HEADERS’), commands (see *note
1897 Configuration Commands::, macro ‘AC_CONFIG_COMMANDS’), links (see
1898 *note Configuration Links::, macro ‘AC_CONFIG_LINKS’),
1899 subdirectories to configure (see *note Subdirectories::, macro
1900 ‘AC_CONFIG_SUBDIRS’) are honored.
1901
1902 The location of your ‘AC_OUTPUT’ invocation is the exact point
1903 where configuration actions are taken: any code afterwards is
1904 executed by ‘configure’ once ‘config.status’ was run. If you want
1905 to bind actions to ‘config.status’ itself (independently of whether
1906 ‘configure’ is being run), see *note Running Arbitrary
1907 Configuration Commands: Configuration Commands.
1908
1909 Historically, the usage of ‘AC_OUTPUT’ was somewhat different. *Note
1910 Obsolete Macros::, for a description of the arguments that ‘AC_OUTPUT’
1911 used to support.
1912
1913 If you run ‘make’ in subdirectories, you should run it using the
1914 ‘make’ variable ‘MAKE’. Most versions of ‘make’ set ‘MAKE’ to the name
1915 of the ‘make’ program plus any options it was given. (But many do not
1916 include in it the values of any variables set on the command line, so
1917 those are not passed on automatically.) Some old versions of ‘make’ do
1918 not set this variable. The following macro allows you to use it even
1919 with those versions.
1920
1921 — Macro: AC_PROG_MAKE_SET
1922 If the Make command, ‘$MAKE’ if set or else ‘make’, predefines
1923 ‘$(MAKE)’, define output variable ‘SET_MAKE’ to be empty.
1924 Otherwise, define ‘SET_MAKE’ to a macro definition that sets
1925 ‘$(MAKE)’, such as ‘MAKE=make’. Calls ‘AC_SUBST’ for ‘SET_MAKE’.
1926
1927 If you use this macro, place a line like this in each ‘Makefile.in’
1928 that runs ‘MAKE’ on other directories:
1929
1930 @SET_MAKE@
1931
1932 
1933 File: autoconf.info, Node: Configuration Actions, Next: Configuration Files, Prev: Output, Up: Setup
1934
1935 4.6 Performing Configuration Actions
1936 ====================================
1937
1938 ‘configure’ is designed so that it appears to do everything itself, but
1939 there is actually a hidden slave: ‘config.status’. ‘configure’ is in
1940 charge of examining your system, but it is ‘config.status’ that actually
1941 takes the proper actions based on the results of ‘configure’. The most
1942 typical task of ‘config.status’ is to _instantiate_ files.
1943
1944 This section describes the common behavior of the four standard
1945 instantiating macros: ‘AC_CONFIG_FILES’, ‘AC_CONFIG_HEADERS’,
1946 ‘AC_CONFIG_COMMANDS’ and ‘AC_CONFIG_LINKS’. They all have this
1947 prototype:
1948
1949 AC_CONFIG_ITEMS(TAG..., [COMMANDS], [INIT-CMDS])
1950
1951 where the arguments are:
1952
1953 TAG...
1954 A blank-or-newline-separated list of tags, which are typically the
1955 names of the files to instantiate.
1956
1957 You are encouraged to use literals as TAGS. In particular, you
1958 should avoid
1959
1960 AS_IF([...], [my_foos="$my_foos fooo"])
1961 AS_IF([...], [my_foos="$my_foos foooo"])
1962 AC_CONFIG_ITEMS([$my_foos])
1963
1964 and use this instead:
1965
1966 AS_IF([...], [AC_CONFIG_ITEMS([fooo])])
1967 AS_IF([...], [AC_CONFIG_ITEMS([foooo])])
1968
1969 The macros ‘AC_CONFIG_FILES’ and ‘AC_CONFIG_HEADERS’ use special
1970 TAG values: they may have the form ‘OUTPUT’ or ‘OUTPUT:INPUTS’.
1971 The file OUTPUT is instantiated from its templates, INPUTS
1972 (defaulting to ‘OUTPUT.in’).
1973
1974 ‘AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk])’, for
1975 example, asks for the creation of the file ‘Makefile’ that contains
1976 the expansion of the output variables in the concatenation of
1977 ‘boiler/top.mk’ and ‘boiler/bot.mk’.
1978
1979 The special value ‘-’ might be used to denote the standard output
1980 when used in OUTPUT, or the standard input when used in the INPUTS.
1981 You most probably don’t need to use this in ‘configure.ac’, but it
1982 is convenient when using the command line interface of
1983 ‘./config.status’, see *note config.status Invocation::, for more
1984 details.
1985
1986 The INPUTS may be absolute or relative file names. In the latter
1987 case they are first looked for in the build tree, and then in the
1988 source tree. Input files should be text files, and a line length
1989 below 2000 bytes should be safe.
1990
1991 COMMANDS
1992 Shell commands output literally into ‘config.status’, and
1993 associated with a tag that the user can use to tell ‘config.status’
1994 which commands to run. The commands are run each time a TAG
1995 request is given to ‘config.status’, typically each time the file
1996 ‘TAG’ is created.
1997
1998 The variables set during the execution of ‘configure’ are _not_
1999 available here: you first need to set them via the INIT-CMDS.
2000 Nonetheless the following variables are pre-computed:
2001
2002 ‘srcdir’
2003 The name of the top source directory, assuming that the
2004 working directory is the top build directory. This is what
2005 ‘configure’’s ‘--srcdir’ option sets.
2006
2007 ‘ac_top_srcdir’
2008 The name of the top source directory, assuming that the
2009 working directory is the current build directory.
2010
2011 ‘ac_top_build_prefix’
2012 The name of the top build directory, assuming that the working
2013 directory is the current build directory. It can be empty, or
2014 else ends with a slash, so that you may concatenate it.
2015
2016 ‘ac_srcdir’
2017 The name of the corresponding source directory, assuming that
2018 the working directory is the current build directory.
2019
2020 ‘tmp’
2021 The name of a temporary directory within the build tree, which
2022 you can use if you need to create additional temporary files.
2023 The directory is cleaned up when ‘config.status’ is done or
2024 interrupted. Please use package-specific file name prefixes
2025 to avoid clashing with files that ‘config.status’ may use
2026 internally.
2027
2028 The “current” directory refers to the directory (or
2029 pseudo-directory) containing the input part of TAGS. For instance,
2030 running
2031
2032 AC_CONFIG_COMMANDS([deep/dir/out:in/in.in], [...], [...])
2033
2034 with ‘--srcdir=../package’ produces the following values:
2035
2036 # Argument of --srcdir
2037 srcdir='../package'
2038 # Reversing deep/dir
2039 ac_top_build_prefix='../../'
2040 # Concatenation of $ac_top_build_prefix and srcdir
2041 ac_top_srcdir='../../../package'
2042 # Concatenation of $ac_top_srcdir and deep/dir
2043 ac_srcdir='../../../package/deep/dir'
2044
2045 independently of ‘in/in.in’.
2046
2047 INIT-CMDS
2048 Shell commands output _unquoted_ near the beginning of
2049 ‘config.status’, and executed each time ‘config.status’ runs
2050 (regardless of the tag). Because they are unquoted, for example,
2051 ‘$var’ is output as the value of ‘var’. INIT-CMDS is typically
2052 used by ‘configure’ to give ‘config.status’ some variables it needs
2053 to run the COMMANDS.
2054
2055 You should be extremely cautious in your variable names: all the
2056 INIT-CMDS share the same name space and may overwrite each other in
2057 unpredictable ways. Sorry...
2058
2059 All these macros can be called multiple times, with different TAG
2060 values, of course!
2061
2062 
2063 File: autoconf.info, Node: Configuration Files, Next: Makefile Substitutions, Prev: Configuration Actions, Up: Setup
2064
2065 4.7 Creating Configuration Files
2066 ================================
2067
2068 Be sure to read the previous section, *note Configuration Actions::.
2069
2070 — Macro: AC_CONFIG_FILES(FILE..., [CMDS], [INIT-CMDS])
2071 Make ‘AC_OUTPUT’ create each ‘FILE’ by copying an input file (by
2072 default ‘FILE.in’), substituting the output variable values. This
2073 macro is one of the instantiating macros; see *note Configuration
2074 Actions::. *Note Makefile Substitutions::, for more information on
2075 using output variables. *Note Setting Output Variables::, for more
2076 information on creating them. This macro creates the directory
2077 that the file is in if it doesn’t exist. Usually, makefiles are
2078 created this way, but other files, such as ‘.gdbinit’, can be
2079 specified as well.
2080
2081 Typical calls to ‘AC_CONFIG_FILES’ look like this:
2082
2083 AC_CONFIG_FILES([Makefile src/Makefile man/Makefile X/Imakefile])
2084 AC_CONFIG_FILES([autoconf], [chmod +x autoconf])
2085
2086 You can override an input file name by appending to FILE a
2087 colon-separated list of input files. Examples:
2088
2089 AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk]
2090 [lib/Makefile:boiler/lib.mk])
2091
2092 Doing this allows you to keep your file names acceptable to DOS
2093 variants, or to prepend and/or append boilerplate to the file.
2094
2095 The FILE names should not contain shell metacharacters. *Note
2096 Special Chars in Variables::.
2097
2098 
2099 File: autoconf.info, Node: Makefile Substitutions, Next: Configuration Headers, Prev: Configuration Files, Up: Setup
2100
2101 4.8 Substitutions in Makefiles
2102 ==============================
2103
2104 Each subdirectory in a distribution that contains something to be
2105 compiled or installed should come with a file ‘Makefile.in’, from which
2106 ‘configure’ creates a file ‘Makefile’ in that directory. To create
2107 ‘Makefile’, ‘configure’ performs a simple variable substitution,
2108 replacing occurrences of ‘@VARIABLE@’ in ‘Makefile.in’ with the value
2109 that ‘configure’ has determined for that variable. Variables that are
2110 substituted into output files in this way are called “output variables”.
2111 They are ordinary shell variables that are set in ‘configure’. To make
2112 ‘configure’ substitute a particular variable into the output files, the
2113 macro ‘AC_SUBST’ must be called with that variable name as an argument.
2114 Any occurrences of ‘@VARIABLE@’ for other variables are left unchanged.
2115 *Note Setting Output Variables::, for more information on creating
2116 output variables with ‘AC_SUBST’.
2117
2118 A software package that uses a ‘configure’ script should be
2119 distributed with a file ‘Makefile.in’, but no makefile; that way, the
2120 user has to properly configure the package for the local system before
2121 compiling it.
2122
2123 *Note Makefile Conventions: (standards)Makefile Conventions, for more
2124 information on what to put in makefiles.
2125
2126 * Menu:
2127
2128 * Preset Output Variables:: Output variables that are always set
2129 * Installation Directory Variables:: Other preset output variables
2130 * Changed Directory Variables:: Warnings about ‘datarootdir’
2131 * Build Directories:: Supporting multiple concurrent compiles
2132 * Automatic Remaking:: Makefile rules for configuring
2133
2134 
2135 File: autoconf.info, Node: Preset Output Variables, Next: Installation Directory Variables, Up: Makefile Substitutions
2136
2137 4.8.1 Preset Output Variables
2138 -----------------------------
2139
2140 Some output variables are preset by the Autoconf macros. Some of the
2141 Autoconf macros set additional output variables, which are mentioned in
2142 the descriptions for those macros. *Note Output Variable Index::, for a
2143 complete list of output variables. *Note Installation Directory
2144 Variables::, for the list of the preset ones related to installation
2145 directories. Below are listed the other preset ones, many of which are
2146 precious variables (*note Setting Output Variables::, ‘AC_ARG_VAR’).
2147
2148 The preset variables which are available during ‘config.status’
2149 (*note Configuration Actions::) may also be used during ‘configure’
2150 tests. For example, it is permissible to reference ‘$srcdir’ when
2151 constructing a list of directories to pass via the ‘-I’ option during a
2152 compiler feature check. When used in this manner, coupled with the fact
2153 that ‘configure’ is always run from the top build directory, it is
2154 sufficient to use just ‘$srcdir’ instead of ‘$top_srcdir’.
2155
2156 — Variable: CFLAGS
2157 Debugging and optimization options for the C compiler. If it is
2158 not set in the environment when ‘configure’ runs, the default value
2159 is set when you call ‘AC_PROG_CC’ (or empty if you don’t).
2160 ‘configure’ uses this variable when compiling or linking programs
2161 to test for C features.
2162
2163 If a compiler option affects only the behavior of the preprocessor
2164 (e.g., ‘-DNAME’), it should be put into ‘CPPFLAGS’ instead. If it
2165 affects only the linker (e.g., ‘-LDIRECTORY’), it should be put
2166 into ‘LDFLAGS’ instead. If it affects only the compiler proper,
2167 ‘CFLAGS’ is the natural home for it. If an option affects multiple
2168 phases of the compiler, though, matters get tricky:
2169
2170 • If an option selects a 32-bit or 64-bit build on a bi-arch
2171 system, it must be put direcly into ‘CC’, e.g., ‘CC='gcc
2172 -m64'’. This is necessary for ‘config.guess’ to work right.
2173 • Otherwise one approach is to put the option into ‘CC’.
2174 Another is to put it into both ‘CPPFLAGS’ and ‘LDFLAGS’, but
2175 not into ‘CFLAGS’.
2176
2177 However, remember that some ‘Makefile’ variables are reserved by
2178 the GNU Coding Standards for the use of the “user”—the person
2179 building the package. For instance, ‘CFLAGS’ is one such variable.
2180
2181 Sometimes package developers are tempted to set user variables such
2182 as ‘CFLAGS’ because it appears to make their job easier. However,
2183 the package itself should never set a user variable, particularly
2184 not to include switches that are required for proper compilation of
2185 the package. Since these variables are documented as being for the
2186 package builder, that person rightfully expects to be able to
2187 override any of these variables at build time. If the package
2188 developer needs to add switches without interfering with the user,
2189 the proper way to do that is to introduce an additional variable.
2190 Automake makes this easy by introducing ‘AM_CFLAGS’ (*note
2191 (automake)Flag Variables Ordering::), but the concept is the same
2192 even if Automake is not used.
2193
2194 — Variable: configure_input
2195 A comment saying that the file was generated automatically by
2196 ‘configure’ and giving the name of the input file. ‘AC_OUTPUT’
2197 adds a comment line containing this variable to the top of every
2198 makefile it creates. For other files, you should reference this
2199 variable in a comment at the top of each input file. For example,
2200 an input shell script should begin like this:
2201
2202 #!/bin/sh
2203 # @configure_input@
2204
2205 The presence of that line also reminds people editing the file that
2206 it needs to be processed by ‘configure’ in order to be used.
2207
2208 — Variable: CPPFLAGS
2209 Preprocessor options for the C, C++, Objective C, and Objective C++
2210 preprocessors and compilers. If it is not set in the environment
2211 when ‘configure’ runs, the default value is empty. ‘configure’
2212 uses this variable when preprocessing or compiling programs to test
2213 for C, C++, Objective C, and Objective C++ features.
2214
2215 This variable’s contents should contain options like ‘-I’, ‘-D’,
2216 and ‘-U’ that affect only the behavior of the preprocessor. Please
2217 see the explanation of ‘CFLAGS’ for what you can do if an option
2218 affects other phases of the compiler as well.
2219
2220 Currently, ‘configure’ always links as part of a single invocation
2221 of the compiler that also preprocesses and compiles, so it uses
2222 this variable also when linking programs. However, it is unwise to
2223 depend on this behavior because the GNU Coding Standards do not
2224 require it and many packages do not use ‘CPPFLAGS’ when linking
2225 programs.
2226
2227 *Note Special Chars in Variables::, for limitations that ‘CPPFLAGS’
2228 might run into.
2229
2230 — Variable: CXXFLAGS
2231 Debugging and optimization options for the C++ compiler. It acts
2232 like ‘CFLAGS’, but for C++ instead of C.
2233
2234 — Variable: DEFS
2235 ‘-D’ options to pass to the C compiler. If ‘AC_CONFIG_HEADERS’ is
2236 called, ‘configure’ replaces ‘@DEFS@’ with ‘-DHAVE_CONFIG_H’
2237 instead (*note Configuration Headers::). This variable is not
2238 defined while ‘configure’ is performing its tests, only when
2239 creating the output files. *Note Setting Output Variables::, for
2240 how to check the results of previous tests.
2241
2242 — Variable: ECHO_C
2243 — Variable: ECHO_N
2244 — Variable: ECHO_T
2245 These obsolescent variables let you suppress the trailing newline
2246 from ‘echo’ for question-answer message pairs. Nowadays it is
2247 better to use ‘AS_ECHO_N’.
2248
2249 — Variable: ERLCFLAGS
2250 Debugging and optimization options for the Erlang compiler. If it
2251 is not set in the environment when ‘configure’ runs, the default
2252 value is empty. ‘configure’ uses this variable when compiling
2253 programs to test for Erlang features.
2254
2255 — Variable: FCFLAGS
2256 Debugging and optimization options for the Fortran compiler. If it
2257 is not set in the environment when ‘configure’ runs, the default
2258 value is set when you call ‘AC_PROG_FC’ (or empty if you don’t).
2259 ‘configure’ uses this variable when compiling or linking programs
2260 to test for Fortran features.
2261
2262 — Variable: FFLAGS
2263 Debugging and optimization options for the Fortran 77 compiler. If
2264 it is not set in the environment when ‘configure’ runs, the default
2265 value is set when you call ‘AC_PROG_F77’ (or empty if you don’t).
2266 ‘configure’ uses this variable when compiling or linking programs
2267 to test for Fortran 77 features.
2268
2269 — Variable: LDFLAGS
2270 Options for the linker. If it is not set in the environment when
2271 ‘configure’ runs, the default value is empty. ‘configure’ uses
2272 this variable when linking programs to test for features in C, C++,
2273 Objective C, Objective C++, Fortran, Go, and Algol 68.
2274
2275 This variable’s contents should contain options like ‘-s’ and ‘-L’
2276 that affect only the behavior of the linker. Please see the
2277 explanation of ‘CFLAGS’ for what you can do if an option also
2278 affects other phases of the compiler.
2279
2280 Don’t use this variable to pass library names (‘-l’) to the linker;
2281 use ‘LIBS’ instead.
2282
2283 — Variable: LIBS
2284 ‘-l’ options to pass to the linker. The default value is empty,
2285 but some Autoconf macros may prepend extra libraries to this
2286 variable if those libraries are found and provide necessary
2287 functions, see *note Libraries::. ‘configure’ uses this variable
2288 when linking programs to test for C, C++, Objective C, Objective
2289 C++, Fortran, and Go features.
2290
2291 — Variable: OBJCFLAGS
2292 Debugging and optimization options for the Objective C compiler.
2293 It acts like ‘CFLAGS’, but for Objective C instead of C.
2294
2295 — Variable: OBJCXXFLAGS
2296 Debugging and optimization options for the Objective C++ compiler.
2297 It acts like ‘CXXFLAGS’, but for Objective C++ instead of C++.
2298
2299 — Variable: GOFLAGS
2300 Debugging and optimization options for the Go compiler. It acts
2301 like ‘CFLAGS’, but for Go instead of C.
2302
2303 — Variable: A68FLAGS
2304 Debugging and optimization options for the Algol 68 compiler. It
2305 acts like ‘CFLAGS’, but for Algol 68 instead of C.
2306
2307 — Variable: builddir
2308 Rigorously equal to ‘.’. Added for symmetry only.
2309
2310 — Variable: abs_builddir
2311 Absolute name of ‘builddir’.
2312
2313 — Variable: top_builddir
2314 The relative name of the top level of the current build tree. In
2315 the top-level directory, this is the same as ‘builddir’.
2316
2317 — Variable: top_build_prefix
2318 The relative name of the top level of the current build tree with
2319 final slash if nonempty. This is the same as ‘top_builddir’,
2320 except that it contains zero or more runs of ‘../’, so it should
2321 not be appended with a slash for concatenation. This helps for
2322 ‘make’ implementations that otherwise do not treat ‘./file’ and
2323 ‘file’ as equal in the top-level build directory.
2324
2325 — Variable: abs_top_builddir
2326 Absolute name of ‘top_builddir’.
2327
2328 — Variable: srcdir
2329 The name of the directory that contains the source code for that
2330 makefile.
2331
2332 — Variable: abs_srcdir
2333 Absolute name of ‘srcdir’.
2334
2335 — Variable: top_srcdir
2336 The name of the top-level source code directory for the package.
2337 In the top-level directory, this is the same as ‘srcdir’.
2338
2339 — Variable: abs_top_srcdir
2340 Absolute name of ‘top_srcdir’.
2341
2342 
2343 File: autoconf.info, Node: Installation Directory Variables, Next: Changed Directory Variables, Prev: Preset Output Variables, Up: Makefile Substitutions
2344
2345 4.8.2 Installation Directory Variables
2346 --------------------------------------
2347
2348 The following variables specify the directories for package
2349 installation, see *note Variables for Installation Directories:
2350 (standards)Directory Variables, for more information. Each variable
2351 corresponds to an argument of ‘configure’; trailing slashes are stripped
2352 so that expressions such as ‘${prefix}/lib’ expand with only one slash
2353 between directory names. See the end of this section for details on
2354 when and how to use these variables.
2355
2356 — Variable: bindir
2357 The directory for installing executables that users run.
2358
2359 — Variable: datadir
2360 The directory for installing idiosyncratic read-only
2361 architecture-independent data.
2362
2363 — Variable: datarootdir
2364 The root of the directory tree for read-only
2365 architecture-independent data files.
2366
2367 — Variable: docdir
2368 The directory for installing documentation files (other than Info
2369 and man).
2370
2371 — Variable: dvidir
2372 The directory for installing documentation files in DVI format.
2373
2374 — Variable: exec_prefix
2375 The installation prefix for architecture-dependent files. By
2376 default it’s the same as ‘prefix’. You should avoid installing
2377 anything directly to ‘exec_prefix’. However, the default value for
2378 directories containing architecture-dependent files should be
2379 relative to ‘exec_prefix’.
2380
2381 — Variable: htmldir
2382 The directory for installing HTML documentation.
2383
2384 — Variable: includedir
2385 The directory for installing C header files.
2386
2387 — Variable: infodir
2388 The directory for installing documentation in Info format.
2389
2390 — Variable: libdir
2391 The directory for installing object code libraries.
2392
2393 — Variable: libexecdir
2394 The directory for installing executables that other programs run.
2395
2396 — Variable: localedir
2397 The directory for installing locale-dependent but
2398 architecture-independent data, such as message catalogs. This
2399 directory usually has a subdirectory per locale.
2400
2401 — Variable: localstatedir
2402 The directory for installing modifiable single-machine data.
2403 Content in this directory typically survives a reboot.
2404
2405 — Variable: runstatedir
2406 The directory for installing temporary modifiable single-machine
2407 data. Content in this directory survives as long as the process is
2408 running (such as pid files), as contrasted with ‘/tmp’ that may be
2409 periodically cleaned. Conversely, this directory is typically
2410 cleaned on a reboot. By default, this is a subdirectory of
2411 ‘localstatedir’.
2412
2413 — Variable: mandir
2414 The top-level directory for installing documentation in man format.
2415
2416 — Variable: oldincludedir
2417 The directory for installing C header files for non-GCC compilers.
2418
2419 — Variable: pdfdir
2420 The directory for installing PDF documentation.
2421
2422 — Variable: prefix
2423 The common installation prefix for all files. If ‘exec_prefix’ is
2424 defined to a different value, ‘prefix’ is used only for
2425 architecture-independent files.
2426
2427 — Variable: psdir
2428 The directory for installing PostScript documentation.
2429
2430 — Variable: sbindir
2431 The directory for installing executables that system administrators
2432 run.
2433
2434 — Variable: sharedstatedir
2435 The directory for installing modifiable architecture-independent
2436 data.
2437
2438 — Variable: sysconfdir
2439 The directory for installing read-only single-machine data.
2440
2441 Most of these variables have values that rely on ‘prefix’ or
2442 ‘exec_prefix’. It is deliberate that the directory output variables
2443 keep them unexpanded: typically ‘@datarootdir@’ is replaced by
2444 ‘${prefix}/share’, not ‘/usr/local/share’, and ‘@datadir@’ is replaced
2445 by ‘${datarootdir}’.
2446
2447 This behavior is mandated by the GNU Coding Standards, so that when
2448 the user runs:
2449
2450 ‘make’
2451 she can still specify a different prefix from the one specified to
2452 ‘configure’, in which case, if needed, the package should hard code
2453 dependencies corresponding to the make-specified prefix.
2454
2455 ‘make install’
2456 she can specify a different installation location, in which case
2457 the package _must_ still depend on the location which was compiled
2458 in (i.e., never recompile when ‘make install’ is run). This is an
2459 extremely important feature, as many people may decide to install
2460 all the files of a package grouped together, and then install links
2461 from the final locations to there.
2462
2463 In order to support these features, it is essential that
2464 ‘datarootdir’ remains defined as ‘${prefix}/share’, so that its value
2465 can be expanded based on the current value of ‘prefix’.
2466
2467 A corollary is that you should not use these variables except in
2468 makefiles. For instance, instead of trying to evaluate ‘datadir’ in
2469 ‘configure’ and hard-coding it in makefiles using e.g.,
2470 ‘AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])’, you
2471 should add ‘-DDATADIR='$(datadir)'’ to your makefile’s definition of
2472 ‘CPPFLAGS’ (‘AM_CPPFLAGS’ if you are also using Automake).
2473
2474 Similarly, you should not rely on ‘AC_CONFIG_FILES’ to replace
2475 ‘bindir’ and friends in your shell scripts and other files; instead, let
2476 ‘make’ manage their replacement. For instance Autoconf ships templates
2477 of its shell scripts ending with ‘.in’, and uses a makefile snippet
2478 similar to the following to build scripts like ‘autoheader’ and
2479 ‘autom4te’:
2480
2481 edit = sed \
2482 -e 's|@bindir[@]|$(bindir)|g' \
2483 -e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
2484 -e 's|@prefix[@]|$(prefix)|g'
2485
2486 autoheader autom4te: Makefile
2487 rm -f $@ [email protected]
2488 srcdir=''; \
2489 test -f ./[email protected] || srcdir=$(srcdir)/; \
2490 $(edit) $${srcdir}[email protected] >[email protected]
2491 chmod +x [email protected]
2492 chmod a-w [email protected]
2493 mv [email protected] $@
2494
2495 autoheader: $(srcdir)/autoheader.in
2496 autom4te: $(srcdir)/autom4te.in
2497
2498 Some details are noteworthy:
2499
2500 ‘@bindir[@]’
2501 The brackets prevent ‘configure’ from replacing ‘@bindir@’ in the
2502 Sed expression itself. Brackets are preferable to a backslash
2503 here, since POSIX says ‘\@’ is not portable.
2504
2505 ‘$(bindir)’
2506 Don’t use ‘@bindir@’! Use the matching makefile variable instead.
2507
2508 ‘$(pkgdatadir)’
2509 The example takes advantage of the variable ‘$(pkgdatadir)’
2510 provided by Automake; it is equivalent to ‘$(datadir)/$(PACKAGE)’.
2511
2512 ‘/’
2513 Don’t use ‘/’ in the Sed expressions that replace file names since
2514 most likely the variables you use, such as ‘$(bindir)’, contain
2515 ‘/’. Use a shell metacharacter instead, such as ‘|’.
2516
2517 special characters
2518 File names, file name components, and the value of ‘VPATH’ should
2519 not contain shell metacharacters or white space. *Note Special
2520 Chars in Variables::.
2521
2522 dependency on ‘Makefile’
2523 Since ‘edit’ uses values that depend on the configuration specific
2524 values (‘prefix’, etc.) and not only on ‘VERSION’ and so forth, the
2525 output depends on ‘Makefile’, not ‘configure.ac’.
2526
2527 ‘$@’
2528 The main rule is generic, and uses ‘$@’ extensively to avoid the
2529 need for multiple copies of the rule.
2530
2531 Separated dependencies and single suffix rules
2532 You can’t use them! The above snippet cannot be (portably)
2533 rewritten as:
2534
2535 autoconf autoheader: Makefile
2536 .in:
2537 rm -f $@ [email protected]
2538 $(edit) $< >[email protected]
2539 chmod +x [email protected]
2540 mv [email protected] $@
2541
2542 *Note Single Suffix Rules::, for details.
2543
2544 ‘$(srcdir)’
2545 Be sure to specify the name of the source directory, otherwise the
2546 package won’t support separated builds.
2547
2548 For the more specific installation of Erlang libraries, the following
2549 variables are defined:
2550
2551 — Variable: ERLANG_INSTALL_LIB_DIR
2552 The common parent directory of Erlang library installation
2553 directories. This variable is set by calling the
2554 ‘AC_ERLANG_SUBST_INSTALL_LIB_DIR’ macro in ‘configure.ac’.
2555
2556 — Variable: ERLANG_INSTALL_LIB_DIR_LIBRARY
2557 The installation directory for Erlang library LIBRARY. This
2558 variable is set by using the ‘AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR’
2559 macro in ‘configure.ac’.
2560
2561 *Note Erlang Libraries::, for details.
2562
2563 
2564 File: autoconf.info, Node: Changed Directory Variables, Next: Build Directories, Prev: Installation Directory Variables, Up: Makefile Substitutions
2565
2566 4.8.3 Changed Directory Variables
2567 ---------------------------------
2568
2569 In Autoconf 2.60, the set of directory variables has changed, and the
2570 defaults of some variables have been adjusted (*note Installation
2571 Directory Variables::) to changes in the GNU Coding Standards. Notably,
2572 ‘datadir’, ‘infodir’, and ‘mandir’ are now expressed in terms of
2573 ‘datarootdir’. If you are upgrading from an earlier Autoconf version,
2574 you may need to adjust your files to ensure that the directory variables
2575 are substituted correctly (*note Defining Directories::), and that a
2576 definition of ‘datarootdir’ is in place. For example, in a
2577 ‘Makefile.in’, adding
2578
2579 datarootdir = @datarootdir@
2580
2581 is usually sufficient. If you use Automake to create ‘Makefile.in’, it
2582 will add this for you.
2583
2584 To help with the transition, Autoconf warns about files that seem to
2585 use ‘datarootdir’ without defining it. In some cases, it then expands
2586 the value of ‘$datarootdir’ in substitutions of the directory variables.
2587 The following example shows such a warning:
2588
2589 $ cat configure.ac
2590 AC_INIT
2591 AC_CONFIG_FILES([Makefile])
2592 AC_OUTPUT
2593 $ cat Makefile.in
2594 prefix = @prefix@
2595 datadir = @datadir@
2596 $ autoconf
2597 $ configure
2598 configure: creating ./config.status
2599 config.status: creating Makefile
2600 config.status: WARNING:
2601 Makefile.in seems to ignore the --datarootdir setting
2602 $ cat Makefile
2603 prefix = /usr/local
2604 datadir = ${prefix}/share
2605
2606 Usually one can easily change the file to accommodate both older and
2607 newer Autoconf releases:
2608
2609 $ cat Makefile.in
2610 prefix = @prefix@
2611 datarootdir = @datarootdir@
2612 datadir = @datadir@
2613 $ configure
2614 configure: creating ./config.status
2615 config.status: creating Makefile
2616 $ cat Makefile
2617 prefix = /usr/local
2618 datarootdir = ${prefix}/share
2619 datadir = ${datarootdir}
2620
2621 In some cases, however, the checks may not be able to detect that a
2622 suitable initialization of ‘datarootdir’ is in place, or they may fail
2623 to detect that such an initialization is necessary in the output file.
2624 If, after auditing your package, there are still spurious ‘configure’
2625 warnings about ‘datarootdir’, you may add the line
2626
2627 AC_DEFUN([AC_DATAROOTDIR_CHECKED])
2628
2629 to your ‘configure.ac’ to disable the warnings. This is an exception to
2630 the usual rule that you should not define a macro whose name begins with
2631 ‘AC_’ (*note Macro Names::).
2632
2633 
2634 File: autoconf.info, Node: Build Directories, Next: Automatic Remaking, Prev: Changed Directory Variables, Up: Makefile Substitutions
2635
2636 4.8.4 Build Directories
2637 -----------------------
2638
2639 You can support compiling a software package for several architectures
2640 simultaneously from the same copy of the source code. The object files
2641 for each architecture are kept in their own directory.
2642
2643 To support doing this, ‘make’ uses the ‘VPATH’ variable to find the
2644 files that are in the source directory. GNU Make can do this. Most
2645 other recent ‘make’ programs can do this as well, though they may have
2646 difficulties and it is often simpler to recommend GNU ‘make’ (*note
2647 VPATH and Make::). Older ‘make’ programs do not support ‘VPATH’; when
2648 using them, the source code must be in the same directory as the object
2649 files.
2650
2651 If you are using GNU Automake, the remaining details in this section
2652 are already covered for you, based on the contents of your
2653 ‘Makefile.am’. But if you are using Autoconf in isolation, then
2654 supporting ‘VPATH’ requires the following in your ‘Makefile.in’:
2655
2656 srcdir = @srcdir@
2657 VPATH = @srcdir@
2658
2659 Do not set ‘VPATH’ to the value of another variable (*note Variables
2660 listed in VPATH::.
2661
2662 ‘configure’ substitutes the correct value for ‘srcdir’ when it
2663 produces ‘Makefile’.
2664
2665 Do not use the ‘make’ variable ‘$<’, which expands to the file name
2666 of the file in the source directory (found with ‘VPATH’), except in
2667 implicit rules. (An implicit rule is one such as ‘.c.o’, which tells
2668 how to create a ‘.o’ file from a ‘.c’ file.) Some versions of ‘make’ do
2669 not set ‘$<’ in explicit rules; they expand it to an empty value.
2670
2671 Instead, Make command lines should always refer to source files by
2672 prefixing them with ‘$(srcdir)/’. It’s safer to quote the source
2673 directory name, in case it contains characters that are special to the
2674 shell. Because ‘$(srcdir)’ is expanded by Make, single-quoting works
2675 and is safer than double-quoting. For example:
2676
2677 time.info: time.texinfo
2678 $(MAKEINFO) '$(srcdir)/time.texinfo'
2679
2680 
2681 File: autoconf.info, Node: Automatic Remaking, Prev: Build Directories, Up: Makefile Substitutions
2682
2683 4.8.5 Automatic Remaking
2684 ------------------------
2685
2686 You can put rules like the following in the top-level ‘Makefile.in’ for
2687 a package to automatically update the configuration information when you
2688 change the configuration files. This example includes all of the
2689 optional files, such as ‘aclocal.m4’ and those related to configuration
2690 header files. Omit from the ‘Makefile.in’ rules for any of these files
2691 that your package does not use.
2692
2693 The ‘$(srcdir)/’ prefix is included because of limitations in the
2694 ‘VPATH’ mechanism.
2695
2696 The ‘stamp-’ files are necessary because the timestamps of
2697 ‘config.h.in’ and ‘config.h’ are not changed if remaking them does not
2698 change their contents. This feature avoids unnecessary recompilation.
2699 You should include the file ‘stamp-h.in’ in your package’s distribution,
2700 so that ‘make’ considers ‘config.h.in’ up to date. Don’t use ‘touch’
2701 (*note Limitations of Usual Tools: touch.); instead, use ‘echo’ (using
2702 ‘date’ would cause needless output differences).
2703
2704 $(srcdir)/configure: configure.ac aclocal.m4
2705 cd '$(srcdir)' && autoconf
2706
2707 # autoheader might not change config.h.in, so touch a stamp file.
2708 $(srcdir)/config.h.in: stamp-h.in ;
2709 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
2710 cd '$(srcdir)' && autoheader
2711 echo timestamp > '$(srcdir)/stamp-h.in'
2712
2713 config.h: stamp-h ;
2714 stamp-h: config.h.in config.status
2715 ./config.status
2716
2717 Makefile: Makefile.in config.status
2718 ./config.status
2719
2720 config.status: configure
2721 ./config.status --recheck
2722
2723 (Be careful if you copy these lines directly into your makefile, as you
2724 need to convert the indented lines to start with the tab character.)
2725
2726 In addition, you should use
2727
2728 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
2729
2730 so ‘config.status’ ensures that ‘config.h’ is considered up to date.
2731 *Note Output::, for more information about ‘AC_OUTPUT’.
2732
2733 *Note config.status Invocation::, for more examples of handling
2734 configuration-related dependencies.
2735
2736 
2737 File: autoconf.info, Node: Configuration Headers, Next: Configuration Commands, Prev: Makefile Substitutions, Up: Setup
2738
2739 4.9 Configuration Header Files
2740 ==============================
2741
2742 When a package contains more than a few tests that define C preprocessor
2743 symbols, the command lines to pass ‘-D’ options to the compiler can get
2744 quite long. This causes two problems. One is that the ‘make’ output is
2745 hard to visually scan for errors. More seriously, the command lines can
2746 exceed the length limits of some operating systems. As an alternative
2747 to passing ‘-D’ options to the compiler, ‘configure’ scripts can create
2748 a C header file containing ‘#define’ directives. The
2749 ‘AC_CONFIG_HEADERS’ macro selects this kind of output. Though it can be
2750 called anywhere between ‘AC_INIT’ and ‘AC_OUTPUT’, it is customary to
2751 call it right after ‘AC_INIT’.
2752
2753 The package should ‘#include’ the configuration header file before
2754 any other header files, to prevent inconsistencies in declarations (for
2755 example, if it redefines ‘const’, or if it defines a macro like
2756 ‘_FILE_OFFSET_BITS’ that affects the behavior of system headers). Note
2757 that it is okay to only include ‘config.h’ from ‘.c’ files; the
2758 project’s ‘.h’ files can rely on ‘config.h’ already being included first
2759 by the corresponding ‘.c’ file.
2760
2761 To provide for VPATH builds, remember to pass the C compiler a ‘-I.’
2762 option (or ‘-I..’; whichever directory contains ‘config.h’). Even if
2763 you use ‘#include "config.h"’, the preprocessor searches only the
2764 directory of the currently read file, i.e., the source directory, not
2765 the build directory.
2766
2767 With the appropriate ‘-I’ option, you can use ‘#include <config.h>’.
2768 Actually, it’s a good habit to use it, because in the rare case when the
2769 source directory contains another ‘config.h’, the build directory should
2770 be searched first.
2771
2772 — Macro: AC_CONFIG_HEADERS(HEADER ..., [CMDS], [INIT-CMDS])
2773 This macro is one of the instantiating macros; see *note
2774 Configuration Actions::. Make ‘AC_OUTPUT’ create the file(s) in
2775 the blank-or-newline-separated list HEADER containing C
2776 preprocessor ‘#define’ statements, and replace ‘@DEFS@’ in
2777 generated files with ‘-DHAVE_CONFIG_H’ instead of the value of
2778 ‘DEFS’. The usual name for HEADER is ‘config.h’; HEADER should not
2779 contain shell metacharacters. *Note Special Chars in Variables::.
2780
2781 If HEADER already exists and its contents are identical to what
2782 ‘AC_OUTPUT’ would put in it, it is left alone. Doing this allows
2783 making some changes in the configuration without needlessly causing
2784 object files that depend on the header file to be recompiled.
2785
2786 Usually the input file is named ‘HEADER.in’; however, you can
2787 override the input file name by appending to HEADER a
2788 colon-separated list of input files. For example, you might need
2789 to make the input file name acceptable to DOS variants:
2790
2791 AC_CONFIG_HEADERS([config.h:config.hin])
2792
2793 — Macro: AH_HEADER
2794 This macro is defined as the name of the first declared config
2795 header and undefined if no config headers have been declared up to
2796 this point. A third-party macro may, for example, require use of a
2797 config header without invoking AC_CONFIG_HEADERS twice, like this:
2798
2799 AC_CONFIG_COMMANDS_PRE(
2800 [m4_ifndef([AH_HEADER], [AC_CONFIG_HEADERS([config.h])])])
2801
2802 *Note Configuration Actions::, for more details on HEADER.
2803
2804 * Menu:
2805
2806 * Header Templates:: Input for the configuration headers
2807 * autoheader Invocation:: How to create configuration templates
2808 * Autoheader Macros:: How to specify CPP templates
2809
2810 
2811 File: autoconf.info, Node: Header Templates, Next: autoheader Invocation, Up: Configuration Headers
2812
2813 4.9.1 Configuration Header Templates
2814 ------------------------------------
2815
2816 Your distribution should contain a template file that looks as you want
2817 the final header file to look, including comments, with ‘#undef’
2818 statements which are used as hooks. For example, suppose your
2819 ‘configure.ac’ makes these calls:
2820
2821 AC_CONFIG_HEADERS([conf.h])
2822 AC_CHECK_HEADERS([unistd.h])
2823
2824 Then you could have code like the following in ‘conf.h.in’. The
2825 ‘conf.h’ created by ‘configure’ defines ‘HAVE_UNISTD_H’ to 1, if and
2826 only if the system has ‘unistd.h’.
2827
2828 /* Define as 1 if you have unistd.h. */
2829 #undef HAVE_UNISTD_H
2830
2831 The format of the template file is stricter than what the C
2832 preprocessor is required to accept. A directive line should contain
2833 only whitespace, ‘#undef’, and ‘HAVE_UNISTD_H’. The use of ‘#define’
2834 instead of ‘#undef’, or of comments on the same line as ‘#undef’, is
2835 strongly discouraged. Each hook should only be listed once. Other
2836 preprocessor lines, such as ‘#ifdef’ or ‘#include’, are copied verbatim
2837 from the template into the generated header.
2838
2839 Since it is a tedious task to keep a template header up to date, you
2840 may use ‘autoheader’ to generate it, see *note autoheader Invocation::.
2841
2842 During the instantiation of the header, each ‘#undef’ line in the
2843 template file for each symbol defined by ‘AC_DEFINE’ is changed to an
2844 appropriate ‘#define’. If the corresponding ‘AC_DEFINE’ has not been
2845 executed during the ‘configure’ run, the ‘#undef’ line is commented out.
2846 (This is important, e.g., for ‘_POSIX_SOURCE’: on many systems, it can
2847 be implicitly defined by the compiler, and undefining it in the header
2848 would then break compilation of subsequent headers.)
2849
2850 Currently, _all_ remaining ‘#undef’ lines in the header template are
2851 commented out, whether or not there was a corresponding ‘AC_DEFINE’ for
2852 the macro name; but this behavior is not guaranteed for future releases
2853 of Autoconf.
2854
2855 Generally speaking, since you should not use ‘#define’, and you
2856 cannot guarantee whether a ‘#undef’ directive in the header template
2857 will be converted to a ‘#define’ or commented out in the generated
2858 header file, the template file cannot be used for conditional definition
2859 effects. Consequently, if you need to use the construct
2860
2861 #ifdef THIS
2862 # define THAT
2863 #endif
2864
2865 you must place it outside of the template. If you absolutely need to
2866 hook it to the config header itself, please put the directives to a
2867 separate file, and ‘#include’ that file from the config header template.
2868 If you are using ‘autoheader’, you would probably use ‘AH_BOTTOM’ to
2869 append the ‘#include’ directive.
2870
2871 
2872 File: autoconf.info, Node: autoheader Invocation, Next: Autoheader Macros, Prev: Header Templates, Up: Configuration Headers
2873
2874 4.9.2 Using ‘autoheader’ to Create ‘config.h.in’
2875 ------------------------------------------------
2876
2877 The ‘autoheader’ program can create a template file of C ‘#define’
2878 statements for ‘configure’ to use. It searches for the first invocation
2879 of ‘AC_CONFIG_HEADERS’ in ‘configure’ sources to determine the name of
2880 the template. (If the first call of ‘AC_CONFIG_HEADERS’ specifies more
2881 than one input file name, ‘autoheader’ uses the first one.)
2882
2883 It is recommended that only one input file is used. If you want to
2884 append a boilerplate code, it is preferable to use ‘AH_BOTTOM([#include
2885 <conf_post.h>])’. File ‘conf_post.h’ is not processed during the
2886 configuration then, which make things clearer. Analogically, ‘AH_TOP’
2887 can be used to prepend a boilerplate code.
2888
2889 In order to do its job, ‘autoheader’ needs you to document all of the
2890 symbols that you might use. Typically this is done via an ‘AC_DEFINE’
2891 or ‘AC_DEFINE_UNQUOTED’ call whose first argument is a literal symbol
2892 and whose third argument describes the symbol (*note Defining
2893 Symbols::). Alternatively, you can use ‘AH_TEMPLATE’ (*note Autoheader
2894 Macros::), or you can supply a suitable input file for a subsequent
2895 configuration header file. Symbols defined by Autoconf’s builtin tests
2896 are already documented properly; you need to document only those that
2897 you define yourself.
2898
2899 You might wonder why ‘autoheader’ is needed: after all, why would
2900 ‘configure’ need to “patch” a ‘config.h.in’ to produce a ‘config.h’
2901 instead of just creating ‘config.h’ from scratch? Well, when everything
2902 rocks, the answer is just that we are wasting our time maintaining
2903 ‘autoheader’: generating ‘config.h’ directly is all that is needed.
2904 When things go wrong, however, you’ll be thankful for the existence of
2905 ‘autoheader’.
2906
2907 The fact that the symbols are documented is important in order to
2908 _check_ that ‘config.h’ makes sense. The fact that there is a
2909 well-defined list of symbols that should be defined (or not) is also
2910 important for people who are porting packages to environments where
2911 ‘configure’ cannot be run: they just have to _fill in the blanks_.
2912
2913 But let’s come back to the point: the invocation of ‘autoheader’...
2914
2915 If you give ‘autoheader’ an argument, it uses that file instead of
2916 ‘configure.ac’ and writes the header file to the standard output instead
2917 of to ‘config.h.in’. If you give ‘autoheader’ an argument of ‘-’, it
2918 reads the standard input instead of ‘configure.ac’ and writes the header
2919 file to the standard output.
2920
2921 ‘autoheader’ accepts the following options:
2922
2923 ‘--help’
2924 ‘-h’
2925 Print a summary of the command line options and exit.
2926
2927 ‘--version’
2928 ‘-V’
2929 Print the version number of Autoconf and exit.
2930
2931 ‘--verbose’
2932 ‘-v’
2933 Report processing steps.
2934
2935 ‘--debug’
2936 ‘-d’
2937 Don’t remove the temporary files.
2938
2939 ‘--force’
2940 ‘-f’
2941 Remake the template file even if newer than its input files.
2942
2943 ‘--replace-handwritten’
2944 ‘-R’
2945 Remake the template file even if it appears not to have been
2946 generated by ‘autoheader’.
2947
2948 ‘--include=DIR’
2949 ‘-I DIR’
2950 Append DIR to the include path. Multiple invocations accumulate.
2951
2952 ‘--prepend-include=DIR’
2953 ‘-B DIR’
2954 Prepend DIR to the include path. Multiple invocations accumulate.
2955
2956 ‘--warnings=CATEGORY[,CATEGORY...]’
2957 ‘-WCATEGORY[,CATEGORY...]’
2958 Enable or disable warnings related to each CATEGORY. *Note
2959 m4_warn::, for a comprehensive list of categories. Special values
2960 include:
2961
2962 ‘all’
2963 Enable all categories of warnings.
2964
2965 ‘none’
2966 Disable all categories of warnings.
2967
2968 ‘error’
2969 Treat all warnings as errors.
2970
2971 ‘no-CATEGORY’
2972 Disable warnings falling into CATEGORY.
2973
2974 The environment variable ‘WARNINGS’ may also be set to a
2975 comma-separated list of warning categories to enable or disable.
2976 It is interpreted exactly the same way as the argument of
2977 ‘--warnings’, but unknown categories are silently ignored. The
2978 command line takes precedence; for instance, if ‘WARNINGS’ is set
2979 to ‘obsolete’, but ‘-Wnone’ is given on the command line, no
2980 warnings will be issued.
2981
2982 Some categories of warnings are on by default. Again, for details
2983 see *note m4_warn::.
2984
2985 
2986 File: autoconf.info, Node: Autoheader Macros, Prev: autoheader Invocation, Up: Configuration Headers
2987
2988 4.9.3 Autoheader Macros
2989 -----------------------
2990
2991 ‘autoheader’ scans ‘configure.ac’ and figures out which C preprocessor
2992 symbols it might define. It knows how to generate templates for symbols
2993 defined by ‘AC_CHECK_HEADERS’, ‘AC_CHECK_FUNCS’ etc., but if you
2994 ‘AC_DEFINE’ any additional symbol, you must define a template for it.
2995 If there are missing templates, ‘autoheader’ fails with an error
2996 message.
2997
2998 The template for a SYMBOL is created by ‘autoheader’ from the
2999 DESCRIPTION argument to an ‘AC_DEFINE’; see *note Defining Symbols::.
3000
3001 For special needs, you can use the following macros.
3002
3003 — Macro: AH_TEMPLATE(KEY, DESCRIPTION)
3004 Tell ‘autoheader’ to generate a template for KEY. This macro
3005 generates standard templates just like ‘AC_DEFINE’ when a
3006 DESCRIPTION is given.
3007
3008 For example:
3009
3010 AH_TEMPLATE([NULL_DEVICE],
3011 [Name of the file to open to get
3012 a null file, or a data sink.])
3013
3014 generates the following template, with the description properly
3015 justified.
3016
3017 /* Name of the file to open to get a null file, or a data sink. */
3018 #undef NULL_DEVICE
3019
3020 — Macro: AH_VERBATIM(KEY, TEMPLATE)
3021 Tell ‘autoheader’ to include the TEMPLATE as-is in the header
3022 template file. This TEMPLATE is associated with the KEY, which is
3023 used to sort all the different templates and guarantee their
3024 uniqueness. It should be a symbol that can be defined via
3025 ‘AC_DEFINE’.
3026
3027 — Macro: AH_TOP(TEXT)
3028 Include TEXT at the top of the header template file.
3029
3030 — Macro: AH_BOTTOM(TEXT)
3031 Include TEXT at the bottom of the header template file.
3032
3033 Please note that TEXT gets included “verbatim” to the template file,
3034 not to the resulting config header, so it can easily get mangled when
3035 the template is processed. There is rarely a need for something other
3036 than
3037
3038 AH_BOTTOM([#include <custom.h>])
3039
3040 
3041 File: autoconf.info, Node: Configuration Commands, Next: Configuration Links, Prev: Configuration Headers, Up: Setup
3042
3043 4.10 Running Arbitrary Configuration Commands
3044 =============================================
3045
3046 You can execute arbitrary commands before, during, and after
3047 ‘config.status’ is run. The three following macros accumulate the
3048 commands to run when they are called multiple times.
3049 ‘AC_CONFIG_COMMANDS’ replaces the obsolete macro ‘AC_OUTPUT_COMMANDS’;
3050 see *note Obsolete Macros::, for details.
3051
3052 — Macro: AC_CONFIG_COMMANDS(TAG..., [CMDS], [INIT-CMDS])
3053 Specify additional shell commands to run at the end of
3054 ‘config.status’, and shell commands to initialize any variables
3055 from ‘configure’. Associate the commands with TAG. Since
3056 typically the CMDS create a file, TAG should naturally be the name
3057 of that file. If needed, the directory hosting TAG is created.
3058 The TAG should not contain shell metacharacters. *Note Special
3059 Chars in Variables::. This macro is one of the instantiating
3060 macros; see *note Configuration Actions::.
3061
3062 Here is an unrealistic example:
3063 fubar=42
3064 AC_CONFIG_COMMANDS([fubar],
3065 [AS_ECHO(["this is extra $fubar, and so on."])],
3066 [fubar=$fubar])
3067
3068 Here is a better one:
3069 AC_CONFIG_COMMANDS([timestamp], [echo >timestamp])
3070
3071 The following two macros look similar, but in fact they are not of
3072 the same breed: they are executed directly by ‘configure’, so you cannot
3073 use ‘config.status’ to rerun them.
3074
3075 — Macro: AC_CONFIG_COMMANDS_PRE(CMDS)
3076 Execute the CMDS right before creating ‘config.status’.
3077
3078 This macro presents the last opportunity to call ‘AC_SUBST’,
3079 ‘AC_DEFINE’, or ‘AC_CONFIG_ITEMS’ macros.
3080
3081 — Macro: AC_CONFIG_COMMANDS_POST(CMDS)
3082 Execute the CMDS right after creating ‘config.status’.
3083
3084 
3085 File: autoconf.info, Node: Configuration Links, Next: Subdirectories, Prev: Configuration Commands, Up: Setup
3086
3087 4.11 Creating Configuration Links
3088 =================================
3089
3090 You may find it convenient to create links whose destinations depend
3091 upon results of tests. One can use ‘AC_CONFIG_COMMANDS’ but the
3092 creation of relative symbolic links can be delicate when the package is
3093 built in a directory different from the source directory.
3094
3095 — Macro: AC_CONFIG_LINKS(DEST:SOURCE..., [CMDS], [INIT-CMDS])
3096 Make ‘AC_OUTPUT’ link each of the existing files SOURCE to the
3097 corresponding link name DEST. Makes a symbolic link if possible,
3098 otherwise a hard link if possible, otherwise a copy. The DEST and
3099 SOURCE names should be relative to the top level source or build
3100 directory, and should not contain shell metacharacters. *Note
3101 Special Chars in Variables::.
3102
3103 This macro is one of the instantiating macros; see *note
3104 Configuration Actions::.
3105
3106 For example, this call:
3107
3108 AC_CONFIG_LINKS([host.h:config/$machine.h
3109 object.h:config/$obj_format.h])
3110
3111 creates in the current directory ‘host.h’ as a link to
3112 ‘SRCDIR/config/$machine.h’, and ‘object.h’ as a link to
3113 ‘SRCDIR/config/$obj_format.h’.
3114
3115 The tempting value ‘.’ for DEST is invalid: it makes it impossible
3116 for ‘config.status’ to guess the links to establish.
3117
3118 One can then run:
3119 ./config.status host.h object.h
3120 to create the links.
3121
3122 
3123 File: autoconf.info, Node: Subdirectories, Next: Default Prefix, Prev: Configuration Links, Up: Setup
3124
3125 4.12 Configuring Other Packages in Subdirectories
3126 =================================================
3127
3128 In most situations, calling ‘AC_OUTPUT’ is sufficient to produce
3129 makefiles in subdirectories. However, ‘configure’ scripts that control
3130 more than one independent package can use ‘AC_CONFIG_SUBDIRS’ to run
3131 ‘configure’ scripts for other packages in subdirectories.
3132
3133 — Macro: AC_CONFIG_SUBDIRS(DIR ...)
3134 Make ‘AC_OUTPUT’ run ‘configure’ in each subdirectory DIR in the
3135 given blank-or-newline-separated list. Each DIR should be a
3136 literal, i.e., please do not use:
3137
3138 if test "x$package_foo_enabled" = xyes; then
3139 my_subdirs="$my_subdirs foo"
3140 fi
3141 AC_CONFIG_SUBDIRS([$my_subdirs])
3142
3143 because this prevents ‘./configure --help=recursive’ from
3144 displaying the options of the package ‘foo’. Instead, you should
3145 write:
3146
3147 AS_IF([test "x$package_foo_enabled" = xyes],
3148 [AC_CONFIG_SUBDIRS([foo])])
3149
3150 If a given DIR is not found at ‘configure’ run time, a warning is
3151 reported; if the subdirectory is optional, write:
3152
3153 AS_IF([test -d "$srcdir/foo"],
3154 [AC_CONFIG_SUBDIRS([foo])])
3155
3156 These examples use ‘AS_IF’ instead of ordinary shell ‘if’ to avoid
3157 problems that Autoconf has with macro calls in shell conditionals
3158 outside macro definitions. *Note Common Shell Constructs::.
3159
3160 If a given DIR contains ‘configure.gnu’, it is run instead of
3161 ‘configure’. This is for packages that might use a non-Autoconf
3162 script ‘Configure’, which can’t be called through a wrapper
3163 ‘configure’ since it would be the same file on case-insensitive
3164 file systems.
3165
3166 The subdirectory ‘configure’ scripts are given the same command
3167 line options that were given to this ‘configure’ script, with minor
3168 changes if needed, which include:
3169
3170 − adjusting a relative name for the cache file;
3171
3172 − adjusting a relative name for the source directory;
3173
3174 − propagating the current value of ‘$prefix’, including if it
3175 was defaulted, and if the default values of the top level and
3176 of the subdirectory ‘configure’ differ.
3177
3178 This macro also sets the output variable ‘subdirs’ to the list of
3179 directories ‘DIR ...’. Make rules can use this variable to
3180 determine which subdirectories to recurse into.
3181
3182 This macro may be called multiple times.
3183
3184 
3185 File: autoconf.info, Node: Default Prefix, Prev: Subdirectories, Up: Setup
3186
3187 4.13 Default Prefix
3188 ===================
3189
3190 By default, ‘configure’ sets the prefix for files it installs to
3191 ‘/usr/local’. The user of ‘configure’ can select a different prefix
3192 using the ‘--prefix’ and ‘--exec-prefix’ options. There are two ways to
3193 change the default: when creating ‘configure’, and when running it.
3194
3195 Some software packages might want to install in a directory other
3196 than ‘/usr/local’ by default. To accomplish that, use the
3197 ‘AC_PREFIX_DEFAULT’ macro.
3198
3199 — Macro: AC_PREFIX_DEFAULT(PREFIX)
3200 Set the default installation prefix to PREFIX instead of
3201 ‘/usr/local’.
3202
3203 It may be convenient for users to have ‘configure’ guess the
3204 installation prefix from the location of a related program that they
3205 have already installed. If you wish to do that, you can call
3206 ‘AC_PREFIX_PROGRAM’.
3207
3208 — Macro: AC_PREFIX_PROGRAM(PROGRAM)
3209 If the user did not specify an installation prefix (using the
3210 ‘--prefix’ option), guess a value for it by looking for PROGRAM in
3211 ‘PATH’, the way the shell does. If PROGRAM is found, set the
3212 prefix to the parent of the directory containing PROGRAM, else
3213 default the prefix as described above (‘/usr/local’ or
3214 ‘AC_PREFIX_DEFAULT’). For example, if PROGRAM is ‘gcc’ and the
3215 ‘PATH’ contains ‘/usr/local/gnu/bin/gcc’, set the prefix to
3216 ‘/usr/local/gnu’.
3217
3218 
3219 File: autoconf.info, Node: Existing Tests, Next: Writing Tests, Prev: Setup, Up: Top
3220
3221 5 Existing Tests
3222 ****************
3223
3224 These macros test for particular system features that packages might
3225 need or want to use. If you need to test for a kind of feature that
3226 none of these macros check for, you can probably do it by calling
3227 primitive test macros with appropriate arguments (*note Writing
3228 Tests::).
3229
3230 These tests print messages telling the user which feature they’re
3231 checking for, and what they find. They cache their results for future
3232 ‘configure’ runs (*note Caching Results::).
3233
3234 Some of these macros set output variables. *Note Makefile
3235 Substitutions::, for how to get their values. The phrase “define NAME”
3236 is used below as a shorthand to mean “define the C preprocessor symbol
3237 NAME to the value 1”. *Note Defining Symbols::, for how to get those
3238 symbol definitions into your program.
3239
3240 * Menu:
3241
3242 * Common Behavior:: Macros’ standard schemes
3243 * Alternative Programs:: Selecting between alternative programs
3244 * Files:: Checking for the existence of files
3245 * Libraries:: Library archives that might be missing
3246 * Library Functions:: C library functions that might be missing
3247 * Header Files:: Header files that might be missing
3248 * Declarations:: Declarations that may be missing
3249 * Structures:: Structures or members that might be missing
3250 * Types:: Types that might be missing
3251 * Compilers and Preprocessors:: Checking for compiling programs
3252 * System Services:: Operating system services
3253 * C and POSIX Variants:: Kludges for C and POSIX variants
3254 * Erlang Libraries:: Checking for the existence of Erlang libraries
3255
3256 
3257 File: autoconf.info, Node: Common Behavior, Next: Alternative Programs, Up: Existing Tests
3258
3259 5.1 Common Behavior
3260 ===================
3261
3262 Much effort has been expended to make Autoconf easy to learn. The most
3263 obvious way to reach this goal is simply to enforce standard interfaces
3264 and behaviors, avoiding exceptions as much as possible. Because of
3265 history and inertia, unfortunately, there are still too many exceptions
3266 in Autoconf; nevertheless, this section describes some of the common
3267 rules.
3268
3269 * Menu:
3270
3271 * Standard Symbols:: Symbols defined by the macros
3272 * Default Includes:: Includes used by the generic macros
3273
3274 
3275 File: autoconf.info, Node: Standard Symbols, Next: Default Includes, Up: Common Behavior
3276
3277 5.1.1 Standard Symbols
3278 ----------------------
3279
3280 All the generic macros that ‘AC_DEFINE’ a symbol as a result of their
3281 test transform their ARGUMENT values to a standard alphabet. First,
3282 ARGUMENT is converted to upper case and any asterisks (‘*’) are each
3283 converted to ‘P’. Any remaining characters that are not alphanumeric
3284 are converted to underscores.
3285
3286 For instance,
3287
3288 AC_CHECK_TYPES([struct $Expensive*])
3289
3290 defines the symbol ‘HAVE_STRUCT__EXPENSIVEP’ if the check succeeds.
3291
3292 
3293 File: autoconf.info, Node: Default Includes, Prev: Standard Symbols, Up: Common Behavior
3294
3295 5.1.2 Default Includes
3296 ----------------------
3297
3298 Test programs frequently need to include headers that may or may not be
3299 available on the system whose features are being tested. Each test can
3300 use all the preprocessor macros that have been ‘AC_DEFINE’d by previous
3301 tests, so for example one may write
3302
3303 #include <time.h>
3304 #ifdef HAVE_SYS_TIME_H
3305 # include <sys/time.h>
3306 #endif
3307
3308 if ‘sys/time.h’ has already been tested for.
3309
3310 All hosted environments that are still of interest for portable code
3311 provide all of the headers specified in C89 (as amended in 1995):
3312 ‘assert.h’, ‘ctype.h’, ‘errno.h’, ‘float.h’, ‘iso646.h’, ‘limits.h’,
3313 ‘locale.h’, ‘math.h’, ‘setjmp.h’, ‘signal.h’, ‘stdarg.h’, ‘stddef.h’,
3314 ‘stdio.h’, ‘stdlib.h’, ‘string.h’, ‘time.h’, ‘wchar.h’, and ‘wctype.h’.
3315 Most programs can safely include these headers unconditionally. A
3316 program not intended to be portable to C89 can also safely include the
3317 C99-specified header ‘stdbool.h’. Other headers, including headers from
3318 C99 and later revisions of the C standard, might need to be tested for
3319 (*note Header Files::) or their bugs may need to be worked around (*note
3320 Gnulib::).
3321
3322 If your program needs to be portable to a _freestanding_ environment,
3323 such as an embedded OS that doesn’t provide all of the facilities of the
3324 C89 standard library, you may need to test for some of the above headers
3325 as well. Note that many Autoconf macros internally assume that the
3326 complete set of C89 headers are available.
3327
3328 Most generic macros use the following macro to provide a default set
3329 of includes:
3330
3331 — Macro: AC_INCLUDES_DEFAULT([INCLUDE-DIRECTIVES])
3332 Expand to INCLUDE-DIRECTIVES if present and nonempty, otherwise to:
3333
3334 #include <stddef.h>
3335 #ifdef HAVE_STDIO_H
3336 # include <stdio.h>
3337 #endif
3338 #ifdef HAVE_STDLIB_H
3339 # include <stdlib.h>
3340 #endif
3341 #ifdef HAVE_STRING_H
3342 # include <string.h>
3343 #endif
3344 #ifdef HAVE_INTTYPES_H
3345 # include <inttypes.h>
3346 #endif
3347 #ifdef HAVE_STDINT_H
3348 # include <stdint.h>
3349 #endif
3350 #ifdef HAVE_STRINGS_H
3351 # include <strings.h>
3352 #endif
3353 #ifdef HAVE_SYS_TYPES_H
3354 # include <sys/types.h>
3355 #endif
3356 #ifdef HAVE_SYS_STAT_H
3357 # include <sys/stat.h>
3358 #endif
3359 #ifdef HAVE_UNISTD_H
3360 # include <unistd.h>
3361 #endif
3362
3363 Using this macro without INCLUDE-DIRECTIVES has the side effect of
3364 checking for ‘stdio.h’, ‘stdlib.h’, ‘string.h’, ‘inttypes.h’,
3365 ‘stdint.h’, ‘strings.h’, ‘sys/types.h’, ‘sys/stat.h’, and
3366 ‘unistd.h’, as if by ‘AC_CHECK_HEADERS_ONCE’. For backward
3367 compatibility, the macro ‘STDC_HEADERS’ will be defined when both
3368 ‘stdlib.h’ and ‘string.h’ are available.
3369
3370 *Portability Note:* It is safe for most programs to assume the
3371 presence of all of the headers required by the original 1990 C
3372 standard. ‘AC_INCLUDES_DEFAULT’ checks for ‘stdio.h’, ‘stdlib.h’,
3373 and ‘string.h’, even though they are in that list, because they
3374 might not be available when compiling for a “freestanding
3375 environment” (in which most of the features of the C library are
3376 optional). You probably do not need to write ‘#ifdef HAVE_STDIO_H’
3377 in your own code.
3378
3379 ‘inttypes.h’ and ‘stdint.h’ were added to C in the 1999 revision of
3380 the standard, and ‘strings.h’, ‘sys/types.h’, ‘sys/stat.h’, and
3381 ‘unistd.h’ are POSIX extensions. You _should_ guard uses of these
3382 headers with appropriate conditionals.
3383
3384 — Macro: AC_CHECK_INCLUDES_DEFAULT
3385 Check for all the headers that ‘AC_INCLUDES_DEFAULT’ would check
3386 for as a side-effect, if this has not already happened.
3387
3388 This macro mainly exists so that ‘autoupdate’ can replace certain
3389 obsolete constructs with it. You should not need to use it
3390 yourself; in fact, it is likely to be safe to delete it from any
3391 script in which it appears. (‘autoupdate’ does not know whether
3392 preprocessor macros such as ‘HAVE_STDINT_H’ are used in the
3393 program, nor whether they would get defined as a side-effect of
3394 other checks.)
3395
3396 
3397 File: autoconf.info, Node: Alternative Programs, Next: Files, Prev: Common Behavior, Up: Existing Tests
3398
3399 5.2 Alternative Programs
3400 ========================
3401
3402 These macros check for the presence or behavior of particular programs.
3403 They are used to choose between several alternative programs and to
3404 decide what to do once one has been chosen. If there is no macro
3405 specifically defined to check for a program you need, and you don’t need
3406 to check for any special properties of it, then you can use one of the
3407 general program-check macros.
3408
3409 * Menu:
3410
3411 * Particular Programs:: Special handling to find certain programs
3412 * Generic Programs:: How to find other programs
3413
3414 
3415 File: autoconf.info, Node: Particular Programs, Next: Generic Programs, Up: Alternative Programs
3416
3417 5.2.1 Particular Program Checks
3418 -------------------------------
3419
3420 These macros check for particular programs—whether they exist, and in
3421 some cases whether they support certain features.
3422
3423 — Macro: AC_PROG_AR
3424 Set output variable ‘AR’ to ‘ar’ if ‘ar’ is found, and otherwise to
3425 ‘:’ (do nothing).
3426
3427 — Macro: AC_PROG_AWK
3428 Check for the commands ‘gawk’, ‘mawk’, ‘nawk’, ‘awk’, and ‘busybox
3429 awk’, in that order, and set output variable ‘AWK’ to the first one
3430 that is found. Try ‘gawk’ first because that is reported to be the
3431 best implementation. The result can be overridden by setting the
3432 variable ‘AWK’ or the cache variable ‘ac_cv_prog_AWK’.
3433
3434 Using this macro avoids some pitfalls of older systems that have
3435 both traditional ‘awk’ (*note Limitations of Usual Tools: awk.) and
3436 better alternatives like ‘gawk’. It also can help port to
3437 stripped-down systems that have only ‘busybox awk’, although these
3438 systems could well have problems with other build components that
3439 use plain ‘awk’.
3440
3441 — Macro: AC_PROG_GREP
3442 Look for the best available ‘grep’ or ‘ggrep’ that accepts the
3443 longest input lines possible, and that supports multiple ‘-e’
3444 options. Set the output variable ‘GREP’ to whatever is chosen.
3445 *Note Limitations of Usual Tools: grep, for more information about
3446 portability problems with the ‘grep’ command family. The result
3447 can be overridden by setting the ‘GREP’ variable and is cached in
3448 the ‘ac_cv_path_GREP’ variable.
3449
3450 — Macro: AC_PROG_EGREP
3451 Check whether ‘$GREP -E’ works, or else look for the best available
3452 ‘egrep’ or ‘gegrep’ that accepts the longest input lines possible.
3453 Set the output variable ‘EGREP’ to whatever is chosen. The result
3454 can be overridden by setting the ‘EGREP’ variable and is cached in
3455 the ‘ac_cv_path_EGREP’ variable.
3456
3457 — Macro: AC_PROG_FGREP
3458 Check whether ‘$GREP -F’ works, or else look for the best available
3459 ‘fgrep’ or ‘gfgrep’ that accepts the longest input lines possible.
3460 Set the output variable ‘FGREP’ to whatever is chosen. The result
3461 can be overridden by setting the ‘FGREP’ variable and is cached in
3462 the ‘ac_cv_path_FGREP’ variable.
3463
3464 — Macro: AC_PROG_INSTALL
3465 Set output variable ‘INSTALL’ to the name of a BSD-compatible
3466 ‘install’ program, if one is found in the current ‘PATH’.
3467 Otherwise, set ‘INSTALL’ to ‘DIR/install-sh -c’, checking the
3468 directories specified to ‘AC_CONFIG_AUX_DIR’ (or its default
3469 directories) to determine DIR (*note Output::). Also set the
3470 variables ‘INSTALL_PROGRAM’ and ‘INSTALL_SCRIPT’ to ‘${INSTALL}’
3471 and ‘INSTALL_DATA’ to ‘${INSTALL} -m 644’.
3472
3473 ‘@INSTALL@’ is special, as its value may vary for different
3474 configuration files.
3475
3476 This macro screens out various instances of ‘install’ known not to
3477 work. It prefers to find a C program rather than a shell script,
3478 for speed. Instead of ‘install-sh’, it can also use ‘install.sh’,
3479 but that name is obsolete because some ‘make’ programs have a rule
3480 that creates ‘install’ from it if there is no makefile. Further,
3481 this macro requires ‘install’ to be able to install multiple files
3482 into a target directory in a single invocation.
3483
3484 Autoconf comes with a copy of ‘install-sh’ that you can use. If
3485 you use ‘AC_PROG_INSTALL’, you must include ‘install-sh’ in your
3486 distribution; otherwise ‘autoreconf’ and ‘configure’ will produce
3487 an error message saying they can’t find it—even if the system
3488 you’re on has a good ‘install’ program. This check is a safety
3489 measure to prevent you from accidentally leaving that file out,
3490 which would prevent your package from installing on systems that
3491 don’t have a BSD-compatible ‘install’ program.
3492
3493 If you need to use your own installation program because it has
3494 features not found in standard ‘install’ programs, there is no
3495 reason to use ‘AC_PROG_INSTALL’; just put the file name of your
3496 program into your ‘Makefile.in’ files.
3497
3498 The result of the test can be overridden by setting the variable
3499 ‘INSTALL’ or the cache variable ‘ac_cv_path_install’.
3500
3501 — Macro: AC_PROG_MKDIR_P
3502 Set output variable ‘MKDIR_P’ to a program that ensures that for
3503 each argument, a directory named by this argument exists, creating
3504 it and its parent directories if needed, and without race
3505 conditions when two instances of the program attempt to make the
3506 same directory at nearly the same time.
3507
3508 This macro uses the equivalent of the ‘mkdir -p’ command. Ancient
3509 versions of ‘mkdir’ are vulnerable to race conditions, so if you
3510 want to support parallel installs from different packages into the
3511 same directory you should use a non-ancient ‘mkdir’.
3512
3513 This macro is related to the ‘AS_MKDIR_P’ macro (*note Programming
3514 in M4sh::), but it sets an output variable intended for use in
3515 other files, whereas ‘AS_MKDIR_P’ is intended for use in scripts
3516 like ‘configure’. Also, ‘AS_MKDIR_P’ does not accept options, but
3517 ‘MKDIR_P’ supports the ‘-m’ option, e.g., a makefile might invoke
3518 ‘$(MKDIR_P) -m 0 dir’ to create an inaccessible directory, and
3519 conversely a makefile should use ‘$(MKDIR_P) -- $(FOO)’ if FOO
3520 might yield a value that begins with ‘-’.
3521
3522 The result of the test can be overridden by setting the variable
3523 ‘MKDIR_P’ or the cache variable ‘ac_cv_path_mkdir’.
3524
3525 — Macro: AC_PROG_LEX(OPTIONS)
3526 Search for a lexical analyzer generator, preferring ‘flex’ to plain
3527 ‘lex’. Output variable ‘LEX’ is set to whichever program is
3528 available. If neither program is available, ‘LEX’ is set to ‘:’;
3529 for packages that ship the generated ‘file.yy.c’ alongside the
3530 source ‘file.l’, this default allows users without a lexer
3531 generator to still build the package even if the timestamp for
3532 ‘file.l’ is inadvertently changed.
3533
3534 The name of the program to use can be overridden by setting the
3535 output variable ‘LEX’ or the cache variable ‘ac_cv_prog_LEX’ when
3536 running ‘configure’.
3537
3538 If a lexical analyzer generator is found, this macro performs
3539 additional checks for common portability pitfalls. If these
3540 additional checks fail, ‘LEX’ is reset to ‘:’; otherwise the
3541 following additional macros and variables are provided.
3542
3543 Preprocessor macro ‘YYTEXT_POINTER’ is defined if the lexer
3544 skeleton, by default, declares ‘yytext’ as a ‘char *’ rather than a
3545 ‘char []’.
3546
3547 Output variable ‘LEX_OUTPUT_ROOT’ is set to the base of the file
3548 name that the lexer generates; this is usually either ‘lex.yy’ or
3549 ‘lexyy’.
3550
3551 If generated lexers need a library to work, output variable
3552 ‘LEXLIB’ is set to a link option for that library (e.g., ‘-ll’),
3553 otherwise it is set to empty.
3554
3555 The OPTIONS argument modifies the behavior of ‘AC_PROG_LEX’. It
3556 should be a whitespace-separated list of options. Currently there
3557 are only two options, and they are mutually exclusive:
3558
3559 ‘yywrap’
3560 Indicate that the library in ‘LEXLIB’ needs to define the
3561 function ‘yywrap’. If a library that defines this function
3562 cannot be found, ‘LEX’ will be reset to ‘:’.
3563
3564 ‘noyywrap’
3565 Indicate that the library in ‘LEXLIB’ does not need to define
3566 the function ‘yywrap’. ‘configure’ will not search for it at
3567 all.
3568
3569 Prior to Autoconf 2.70, ‘AC_PROG_LEX’ did not take any arguments,
3570 and its behavior was different from either of the above
3571 possibilities: it would search for a library that defines ‘yywrap’,
3572 and would set ‘LEXLIB’ to that library if it finds one. However,
3573 if a library that defines this function could not be found,
3574 ‘LEXLIB’ would be left empty and ‘LEX’ would _not_ be reset. This
3575 behavior was due to a bug, but several packages came to depend on
3576 it, so ‘AC_PROG_LEX’ still does this if neither the ‘yywrap’ nor
3577 the ‘noyywrap’ option is given.
3578
3579 Usage of ‘AC_PROG_LEX’ without choosing one of the ‘yywrap’ or
3580 ‘noyywrap’ options is deprecated. It is usually better to use
3581 ‘noyywrap’ and define the ‘yywrap’ function yourself, as this
3582 almost always renders the ‘LEXLIB’ unnecessary.
3583
3584 *Caution:* As a side-effect of the test, this macro may delete any
3585 file in the configure script’s current working directory named
3586 ‘lex.yy.c’ or ‘lexyy.c’.
3587
3588 *Caution:* Packages that ship a generated ‘lex.yy.c’ cannot assume
3589 that the definition of ‘YYTEXT_POINTER’ matches the code in that
3590 file. They also cannot assume that ‘LEXLIB’ provides the library
3591 routines required by the code in that file.
3592
3593 If you use Flex to generate ‘lex.yy.c’, you can work around these
3594 limitations by defining ‘yywrap’ and ‘main’ yourself (rendering
3595 ‘-lfl’ unnecessary), and by using either the ‘--array’ or
3596 ‘--pointer’ options to control how ‘yytext’ is declared. The code
3597 generated by Flex is also more portable than the code generated by
3598 historical versions of Lex.
3599
3600 If you have used Flex to generate ‘lex.yy.c’, and especially if
3601 your scanner depends on Flex features, we recommend you use this
3602 Autoconf snippet to prevent the scanner being regenerated with
3603 historical Lex:
3604
3605 AC_PROG_LEX
3606 AS_IF([test "x$LEX" != xflex],
3607 [LEX="$SHELL $missing_dir/missing flex"
3608 AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
3609 AC_SUBST([LEXLIB], [''])])
3610
3611 The shell script ‘missing’ can be found in the Automake
3612 distribution.
3613
3614 Remember that the user may have supplied an alternate location in
3615 ‘LEX’, so if Flex is required, it is better to check that the user
3616 provided something sufficient by parsing the output of ‘$LEX
3617 --version’ than by simply relying on ‘test "x$LEX" = xflex’.
3618
3619 — Macro: AC_PROG_LN_S
3620 If ‘ln -s’ works on the current file system (the operating system
3621 and file system support symbolic links), set the output variable
3622 ‘LN_S’ to ‘ln -s’; otherwise, if ‘ln’ works, set ‘LN_S’ to ‘ln’,
3623 and otherwise set it to ‘cp -pR’.
3624
3625 If you make a link in a directory other than the current directory,
3626 its meaning depends on whether ‘ln’ or ‘ln -s’ is used. To safely
3627 create links using ‘$(LN_S)’, either find out which form is used
3628 and adjust the arguments, or always invoke ‘ln’ in the directory
3629 where the link is to be created.
3630
3631 In other words, it does not work to do:
3632 $(LN_S) foo /x/bar
3633
3634 Instead, do:
3635
3636 (cd /x && $(LN_S) foo bar)
3637
3638 — Macro: AC_PROG_RANLIB
3639 Set output variable ‘RANLIB’ to ‘ranlib’ if ‘ranlib’ is found, and
3640 otherwise to ‘:’ (do nothing).
3641
3642 — Macro: AC_PROG_SED
3643 Set output variable ‘SED’ to a Sed implementation that conforms to
3644 POSIX and does not have arbitrary length limits. Report an error
3645 if no acceptable Sed is found. *Note Limitations of Usual Tools:
3646 sed.
3647
3648 The result of this test can be overridden by setting the ‘SED’
3649 variable and is cached in the ‘ac_cv_path_SED’ variable.
3650
3651 — Macro: AC_PROG_YACC
3652 If ‘bison’ is found, set output variable ‘YACC’ to ‘bison -y’.
3653 Otherwise, if ‘byacc’ is found, set ‘YACC’ to ‘byacc’. Otherwise
3654 set ‘YACC’ to ‘yacc’. The result of this test can be influenced by
3655 setting the variable ‘YACC’ or the cache variable
3656 ‘ac_cv_prog_YACC’.
3657
3658 
3659 File: autoconf.info, Node: Generic Programs, Prev: Particular Programs, Up: Alternative Programs
3660
3661 5.2.2 Generic Program and File Checks
3662 -------------------------------------
3663
3664 These macros are used to find programs not covered by the “particular”
3665 test macros. If you need to check the behavior of a program as well as
3666 find out whether it is present, you have to write your own test for it
3667 (*note Writing Tests::). By default, these macros use the environment
3668 variable ‘PATH’. If you need to check for a program that might not be
3669 in the user’s ‘PATH’, you can pass a modified path to use instead, like
3670 this:
3671
3672 AC_PATH_PROG([INETD], [inetd], [/usr/libexec/inetd],
3673 [$PATH$PATH_SEPARATOR/usr/libexec$PATH_SEPARATOR]dnl
3674 [/usr/sbin$PATH_SEPARATOR/usr/etc$PATH_SEPARATOR/etc])
3675
3676 You are strongly encouraged to declare the VARIABLE passed to
3677 ‘AC_CHECK_PROG’ etc. as precious. *Note Setting Output Variables::,
3678 ‘AC_ARG_VAR’, for more details.
3679
3680 — Macro: AC_CHECK_PROG(VARIABLE, PROG-TO-CHECK-FOR, VALUE-IF-FOUND,
3681 [VALUE-IF-NOT-FOUND], [PATH = $PATH], [REJECT])
3682 Check whether program PROG-TO-CHECK-FOR exists in PATH. If it is
3683 found, set VARIABLE to VALUE-IF-FOUND, otherwise to
3684 VALUE-IF-NOT-FOUND, if given. Always pass over REJECT (an absolute
3685 file name) even if it is the first found in the search path; in
3686 that case, set VARIABLE using the absolute file name of the
3687 PROG-TO-CHECK-FOR found that is not REJECT. If VARIABLE was
3688 already set, do nothing. Calls ‘AC_SUBST’ for VARIABLE. The
3689 result of this test can be overridden by setting the VARIABLE
3690 variable or the cache variable ‘ac_cv_prog_VARIABLE’.
3691
3692 — Macro: AC_CHECK_PROGS(VARIABLE, PROGS-TO-CHECK-FOR,
3693 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3694 Check for each program in the blank-separated list
3695 PROGS-TO-CHECK-FOR existing in the PATH. If one is found, set
3696 VARIABLE to the name of that program. Otherwise, continue checking
3697 the next program in the list. If none of the programs in the list
3698 are found, set VARIABLE to VALUE-IF-NOT-FOUND; if
3699 VALUE-IF-NOT-FOUND is not specified, the value of VARIABLE is not
3700 changed. Calls ‘AC_SUBST’ for VARIABLE. The result of this test
3701 can be overridden by setting the VARIABLE variable or the cache
3702 variable ‘ac_cv_prog_VARIABLE’.
3703
3704 — Macro: AC_CHECK_TARGET_TOOL(VARIABLE, PROG-TO-CHECK-FOR,
3705 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3706 Like ‘AC_CHECK_PROG’, but first looks for PROG-TO-CHECK-FOR with a
3707 prefix of the target type as determined by ‘AC_CANONICAL_TARGET’,
3708 followed by a dash (*note Canonicalizing::). If the tool cannot be
3709 found with a prefix, and if the build and target types are equal,
3710 then it is also searched for without a prefix.
3711
3712 As noted in *note Specifying Target Triplets::, the target is
3713 rarely specified, because most of the time it is the same as the
3714 host: it is the type of system for which any compiler tool in the
3715 package produces code. What this macro looks for is, for example,
3716 _a tool (assembler, linker, etc.) that the compiler driver (‘gcc’
3717 for the GNU C Compiler) uses to produce objects, archives or
3718 executables_.
3719
3720 — Macro: AC_CHECK_TOOL(VARIABLE, PROG-TO-CHECK-FOR,
3721 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3722 Like ‘AC_CHECK_PROG’, but first looks for PROG-TO-CHECK-FOR with a
3723 prefix of the host type as specified by ‘--host’, followed by a
3724 dash. For example, if the user runs ‘configure --build=x86_64-gnu
3725 --host=aarch64-linux-gnu’, then this call:
3726 AC_CHECK_TOOL([RANLIB], [ranlib], [:])
3727 sets ‘RANLIB’ to ‘aarch64-linux-gnu-ranlib’ if that program exists
3728 in PATH, or otherwise to ‘ranlib’ if that program exists in PATH,
3729 or to ‘:’ if neither program exists.
3730
3731 When cross-compiling, this macro will issue a warning if no program
3732 prefixed with the host type could be found. For more information,
3733 see *note Specifying Target Triplets::.
3734
3735 — Macro: AC_CHECK_TARGET_TOOLS(VARIABLE, PROGS-TO-CHECK-FOR,
3736 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3737 Like ‘AC_CHECK_TARGET_TOOL’, each of the tools in the list
3738 PROGS-TO-CHECK-FOR are checked with a prefix of the target type as
3739 determined by ‘AC_CANONICAL_TARGET’, followed by a dash (*note
3740 Canonicalizing::). If none of the tools can be found with a
3741 prefix, and if the build and target types are equal, then the first
3742 one without a prefix is used. If a tool is found, set VARIABLE to
3743 the name of that program. If none of the tools in the list are
3744 found, set VARIABLE to VALUE-IF-NOT-FOUND; if VALUE-IF-NOT-FOUND is
3745 not specified, the value of VARIABLE is not changed. Calls
3746 ‘AC_SUBST’ for VARIABLE.
3747
3748 — Macro: AC_CHECK_TOOLS(VARIABLE, PROGS-TO-CHECK-FOR,
3749 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3750 Like ‘AC_CHECK_TOOL’, each of the tools in the list
3751 PROGS-TO-CHECK-FOR are checked with a prefix of the host type as
3752 determined by ‘AC_CANONICAL_HOST’, followed by a dash (*note
3753 Canonicalizing::). If none of the tools can be found with a
3754 prefix, then the first one without a prefix is used. If a tool is
3755 found, set VARIABLE to the name of that program. If none of the
3756 tools in the list are found, set VARIABLE to VALUE-IF-NOT-FOUND; if
3757 VALUE-IF-NOT-FOUND is not specified, the value of VARIABLE is not
3758 changed. Calls ‘AC_SUBST’ for VARIABLE.
3759
3760 When cross-compiling, this macro will issue a warning if no program
3761 prefixed with the host type could be found. For more information,
3762 see *note Specifying Target Triplets::.
3763
3764 — Macro: AC_PATH_PROG(VARIABLE, PROG-TO-CHECK-FOR,
3765 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3766 Like ‘AC_CHECK_PROG’, but set VARIABLE to the absolute name of
3767 PROG-TO-CHECK-FOR if found. The result of this test can be
3768 overridden by setting the VARIABLE variable. A positive result of
3769 this test is cached in the ‘ac_cv_path_VARIABLE’ variable.
3770
3771 — Macro: AC_PATH_PROGS(VARIABLE, PROGS-TO-CHECK-FOR,
3772 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3773 Like ‘AC_CHECK_PROGS’, but if any of PROGS-TO-CHECK-FOR are found,
3774 set VARIABLE to the absolute name of the program found. The result
3775 of this test can be overridden by setting the VARIABLE variable. A
3776 positive result of this test is cached in the ‘ac_cv_path_VARIABLE’
3777 variable.
3778
3779 — Macro: AC_PATH_PROGS_FEATURE_CHECK(VARIABLE, PROGS-TO-CHECK-FOR,
3780 FEATURE-TEST, [ACTION-IF-NOT-FOUND], [PATH = $PATH])
3781 This macro was introduced in Autoconf 2.62. If VARIABLE is not
3782 empty, then set the cache variable ‘ac_cv_path_VARIABLE’ to its
3783 value. Otherwise, check for each program in the blank-separated
3784 list PROGS-TO-CHECK-FOR existing in PATH. For each program found,
3785 execute FEATURE-TEST with ‘ac_path_VARIABLE’ set to the absolute
3786 name of the candidate program. If no invocation of FEATURE-TEST
3787 sets the shell variable ‘ac_cv_path_VARIABLE’, then
3788 ACTION-IF-NOT-FOUND is executed. FEATURE-TEST will be run even
3789 when ‘ac_cv_path_VARIABLE’ is set, to provide the ability to choose
3790 a better candidate found later in PATH; to accept the current
3791 setting and bypass all further checks, FEATURE-TEST can execute
3792 ‘ac_path_VARIABLE_found=:’.
3793
3794 Note that this macro has some subtle differences from
3795 ‘AC_CHECK_PROGS’. It is designed to be run inside ‘AC_CACHE_VAL’,
3796 therefore, it should have no side effects. In particular, VARIABLE
3797 is not set to the final value of ‘ac_cv_path_VARIABLE’, nor is
3798 ‘AC_SUBST’ automatically run. Also, on failure, any action can be
3799 performed, whereas ‘AC_CHECK_PROGS’ only performs
3800 ‘VARIABLE=VALUE-IF-NOT-FOUND’.
3801
3802 Here is an example that searches for an implementation of ‘m4’ that
3803 supports the ‘indir’ builtin, even if it goes by the name ‘gm4’ or
3804 is not the first implementation on ‘PATH’.
3805
3806 AC_CACHE_CHECK([for m4 that supports indir], [ac_cv_path_M4],
3807 [AC_PATH_PROGS_FEATURE_CHECK([M4], [m4 gm4],
3808 [[m4out=`echo 'changequote([,])indir([divnum])' | $ac_path_M4`
3809 test "x$m4out" = x0 \
3810 && ac_cv_path_M4=$ac_path_M4 ac_path_M4_found=:]],
3811 [AC_MSG_ERROR([could not find m4 that supports indir])])])
3812 AC_SUBST([M4], [$ac_cv_path_M4])
3813
3814 — Macro: AC_PATH_TARGET_TOOL(VARIABLE, PROG-TO-CHECK-FOR,
3815 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3816 Like ‘AC_CHECK_TARGET_TOOL’, but set VARIABLE to the absolute name
3817 of the program if it is found.
3818
3819 — Macro: AC_PATH_TOOL(VARIABLE, PROG-TO-CHECK-FOR,
3820 [VALUE-IF-NOT-FOUND], [PATH = $PATH])
3821 Like ‘AC_CHECK_TOOL’, but set VARIABLE to the absolute name of the
3822 program if it is found.
3823
3824 When cross-compiling, this macro will issue a warning if no program
3825 prefixed with the host type could be found. For more information,
3826 see *note Specifying Target Triplets::.
3827
3828 
3829 File: autoconf.info, Node: Files, Next: Libraries, Prev: Alternative Programs, Up: Existing Tests
3830
3831 5.3 Files
3832 =========
3833
3834 You might also need to check for the existence of files. Before using
3835 these macros, ask yourself whether a runtime test might not be a better
3836 solution. Be aware that, like most Autoconf macros, they test a feature
3837 of the host machine, and therefore, they die when cross-compiling.
3838
3839 — Macro: AC_CHECK_FILE(FILE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
3840 Check whether file FILE exists on the native system. If it is
3841 found, execute ACTION-IF-FOUND, otherwise do ACTION-IF-NOT-FOUND,
3842 if given. Cache the result of this test in the ‘ac_cv_file_FILE’
3843 variable, with characters not suitable for a variable name mapped
3844 to underscores.
3845
3846 — Macro: AC_CHECK_FILES(FILES, [ACTION-IF-FOUND],
3847 [ACTION-IF-NOT-FOUND])
3848 For each file listed in FILES, execute ‘AC_CHECK_FILE’ and perform
3849 either ACTION-IF-FOUND or ACTION-IF-NOT-FOUND. Like
3850 ‘AC_CHECK_FILE’, this defines ‘HAVE_FILE’ (*note Standard
3851 Symbols::) for each file found and caches the results of each test
3852 in the ‘ac_cv_file_FILE’ variable, with characters not suitable for
3853 a variable name mapped to underscores.
3854
3855 
3856 File: autoconf.info, Node: Libraries, Next: Library Functions, Prev: Files, Up: Existing Tests
3857
3858 5.4 Library Files
3859 =================
3860
3861 The following macros check for the presence of certain C, C++, Fortran,
3862 or Go library archive files.
3863
3864 — Macro: AC_CHECK_LIB(LIBRARY, FUNCTION, [ACTION-IF-FOUND],
3865 [ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES])
3866 Test whether the library LIBRARY is available by trying to link a
3867 test program that calls function FUNCTION with the library.
3868 FUNCTION should be a function provided by the library. Use the
3869 base name of the library; e.g., to check for ‘-lmp’, use ‘mp’ as
3870 the LIBRARY argument.
3871
3872 ACTION-IF-FOUND is a list of shell commands to run if the link with
3873 the library succeeds; ACTION-IF-NOT-FOUND is a list of shell
3874 commands to run if the link fails. If ACTION-IF-FOUND is not
3875 specified, the default action prepends ‘-lLIBRARY’ to ‘LIBS’ and
3876 defines ‘HAVE_LIBLIBRARY’ (in all capitals). This macro is
3877 intended to support building ‘LIBS’ in a right-to-left
3878 (least-dependent to most-dependent) fashion such that library
3879 dependencies are satisfied as a natural side effect of consecutive
3880 tests. Linkers are sensitive to library ordering so the order in
3881 which ‘LIBS’ is generated is important to reliable detection of
3882 libraries.
3883
3884 If linking with LIBRARY results in unresolved symbols that would be
3885 resolved by linking with additional libraries, give those libraries
3886 as the OTHER-LIBRARIES argument, separated by spaces: e.g., ‘-lXt
3887 -lX11’. Otherwise, this macro may fail to detect that LIBRARY is
3888 present, because linking the test program can fail with unresolved
3889 symbols. The OTHER-LIBRARIES argument should be limited to cases
3890 where it is desirable to test for one library in the presence of
3891 another that is not already in ‘LIBS’.
3892
3893 ‘AC_CHECK_LIB’ requires some care in usage, and should be avoided
3894 in some common cases. Many standard functions like ‘gethostbyname’
3895 appear in the standard C library on some hosts, and in special
3896 libraries like ‘nsl’ on other hosts. On some hosts the special
3897 libraries contain variant implementations that you may not want to
3898 use. These days it is normally better to use
3899 ‘AC_SEARCH_LIBS([gethostbyname], [nsl])’ instead of
3900 ‘AC_CHECK_LIB([nsl], [gethostbyname])’.
3901
3902 The result of this test is cached in the
3903 ‘ac_cv_lib_LIBRARY_FUNCTION’ variable.
3904
3905 — Macro: AC_SEARCH_LIBS(FUNCTION, SEARCH-LIBS, [ACTION-IF-FOUND],
3906 [ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES])
3907 Search for a library defining FUNCTION if it’s not already
3908 available. This equates to calling
3909 ‘AC_LINK_IFELSE([AC_LANG_CALL([], [FUNCTION])])’ first with no
3910 libraries, then for each library listed in SEARCH-LIBS.
3911
3912 Prepend ‘-lLIBRARY’ to ‘LIBS’ for the first library found to
3913 contain FUNCTION, and run ACTION-IF-FOUND. If the function is not
3914 found, run ACTION-IF-NOT-FOUND.
3915
3916 If linking with LIBRARY results in unresolved symbols that would be
3917 resolved by linking with additional libraries, give those libraries
3918 as the OTHER-LIBRARIES argument, separated by spaces: e.g., ‘-lXt
3919 -lX11’. Otherwise, this macro fails to detect that FUNCTION is
3920 present, because linking the test program always fails with
3921 unresolved symbols.
3922
3923 The result of this test is cached in the ‘ac_cv_search_FUNCTION’
3924 variable as ‘none required’ if FUNCTION is already available, as
3925 ‘no’ if no library containing FUNCTION was found, otherwise as the
3926 ‘-lLIBRARY’ option that needs to be prepended to ‘LIBS’.
3927
3928 
3929 File: autoconf.info, Node: Library Functions, Next: Header Files, Prev: Libraries, Up: Existing Tests
3930
3931 5.5 Library Functions
3932 =====================
3933
3934 The following macros check for particular C library functions. If there
3935 is no macro specifically defined to check for a function you need, and
3936 you don’t need to check for any special properties of it, then you can
3937 use one of the general function-check macros.
3938
3939 * Menu:
3940
3941 * Function Portability:: Pitfalls with usual functions
3942 * Particular Functions:: Special handling to find certain functions
3943 * Generic Functions:: How to find other functions
3944
3945 
3946 File: autoconf.info, Node: Function Portability, Next: Particular Functions, Up: Library Functions
3947
3948 5.5.1 Portability of C Functions
3949 --------------------------------
3950
3951 Most usual functions can either be missing, or be buggy, or be limited
3952 on some architectures. This section tries to make an inventory of these
3953 portability issues. By definition, this list always requires additions.
3954 A much more complete list is maintained by the Gnulib project (*note
3955 Gnulib::), covering *note Current POSIX Functions: (gnulib)Function
3956 Substitutes, *note Legacy Functions: (gnulib)Legacy Function
3957 Substitutes, and *note Glibc Functions: (gnulib)Glibc Function
3958 Substitutes. Please help us keep the Gnulib list as complete as
3959 possible.
3960
3961 ‘exit’
3962 On ancient hosts, ‘exit’ returned ‘int’. This is because ‘exit’
3963 predates ‘void’, and there was a long tradition of it returning
3964 ‘int’.
3965
3966 On current hosts, the problem more likely is that ‘exit’ is not
3967 declared, due to C++ problems of some sort or another. For this
3968 reason we suggest that test programs not invoke ‘exit’, but return
3969 from ‘main’ instead.
3970
3971 ‘malloc’
3972 The C standard says a successful call ‘malloc (0)’ is
3973 implementation dependent. It can return either ‘NULL’ or a new
3974 non-null pointer. The latter is more common (e.g., the GNU C
3975 Library) but is by no means universal. ‘AC_FUNC_MALLOC’ can be
3976 used to insist on non-‘NULL’ (*note Particular Functions::).
3977
3978 ‘putenv’
3979 POSIX prefers ‘setenv’ to ‘putenv’; among other things, ‘putenv’ is
3980 not required of all POSIX implementations, but ‘setenv’ is.
3981
3982 POSIX specifies that ‘putenv’ puts the given string directly in
3983 ‘environ’, but some systems make a copy of it instead (e.g., glibc
3984 2.0, or BSD). And when a copy is made, ‘unsetenv’ might not free
3985 it, causing a memory leak (e.g., FreeBSD 4).
3986
3987 On some systems ‘putenv ("FOO")’ removes ‘FOO’ from the
3988 environment, but this is not standard usage and it dumps core on
3989 some systems (e.g., AIX).
3990
3991 On MinGW, a call ‘putenv ("FOO=")’ removes ‘FOO’ from the
3992 environment, rather than inserting it with an empty value.
3993
3994 ‘realloc’
3995 It is problematic to call ‘realloc’ with a zero size. The C
3996 standard says ‘realloc (NULL, 0)’ is equivalent to ‘malloc (0)’,
3997 which means one cannot portably tell whether the call has succeeded
3998 if it returns a null pointer. If ‘ptr’ is non-null, the C standard
3999 says ‘realloc (ptr, 0)’ has undefined behavior.
4000
4001 The ‘AC_FUNC_REALLOC’ macro avoids some of these portability
4002 issues. *Note Particular Functions::.
4003
4004 ‘signal’ handler
4005 In most cases, it is more robust to use ‘sigaction’ when it is
4006 available, rather than ‘signal’.
4007
4008 ‘snprintf’
4009 In C99 and later, if the output array isn’t big enough and if no
4010 other errors occur, ‘snprintf’ and ‘vsnprintf’ truncate the output
4011 and return the number of bytes that ought to have been produced.
4012 Some older systems, notably Microsoft Windows before Visual Studio
4013 2015 and Windows 10, do not null-terminate the output and return −1
4014 instead.
4015
4016 Portable code can check the return value of ‘snprintf (buf, sizeof
4017 buf, ...)’: if the value is negative or is not less than ‘sizeof
4018 buf’, an error occurred and the contents of ‘buf’ can be ignored.
4019 Alternatively, one of the Gnulib modules related to ‘snprintf’ can
4020 be used. *Note Gnulib::.
4021
4022 ‘strerror_r’
4023 POSIX specifies that ‘strerror_r’ returns an ‘int’, but many
4024 systems (e.g., the GNU C Library) provide a different version
4025 returning a ‘char *’. ‘AC_FUNC_STRERROR_R’ can detect which is in
4026 use (*note Particular Functions::).
4027
4028 ‘strnlen’
4029 Android 5.0’s strnlen was broken, because it assumed the addressed
4030 array always had at least the specified number of bytes. For
4031 example, ‘strnlen ("", SIZE_MAX)’ should return 0 but on Android
4032 5.0 it crashed.
4033
4034 AIX 4.3 provided a broken version which produces the following
4035 results:
4036
4037 strnlen ("foobar", 0) = 0
4038 strnlen ("foobar", 1) = 3
4039 strnlen ("foobar", 2) = 2
4040 strnlen ("foobar", 3) = 1
4041 strnlen ("foobar", 4) = 0
4042 strnlen ("foobar", 5) = 6
4043 strnlen ("foobar", 6) = 6
4044 strnlen ("foobar", 7) = 6
4045 strnlen ("foobar", 8) = 6
4046 strnlen ("foobar", 9) = 6
4047
4048 ‘sysconf’
4049 ‘_SC_PAGESIZE’ is standard, but some older systems (e.g., HP-UX 9)
4050 have ‘_SC_PAGE_SIZE’ instead. This can be tested with ‘#ifdef’.
4051
4052 ‘unlink’
4053 The POSIX spec says that ‘unlink’ causes the given file to be
4054 removed only after there are no more open file handles for it.
4055 Some non-POSIX hosts have trouble with this requirement, though,
4056 and some DOS variants even corrupt the file system.
4057
4058 ‘unsetenv’
4059 On MinGW, ‘unsetenv’ is not available, but a variable ‘FOO’ can be
4060 removed with a call ‘putenv ("FOO=")’, as described under ‘putenv’
4061 above.
4062
4063 ‘va_copy’
4064 C99 and later provide ‘va_copy’ for copying ‘va_list’ variables.
4065 It may be available in older environments too, though possibly as
4066 ‘__va_copy’ (e.g., ‘gcc’ in strict pre-C99 mode). These can be
4067 tested with ‘#ifdef’. A fallback to ‘memcpy (&dst, &src, sizeof
4068 (va_list))’ gives maximum portability.
4069
4070 ‘va_list’
4071 ‘va_list’ is not necessarily just a pointer. It can be a ‘struct’,
4072 which means ‘NULL’ is not portable. Or it can be an array, which
4073 means as a function parameter it can be effectively
4074 call-by-reference and library routines might modify the value back
4075 in the caller.
4076
4077 Signed ‘>>’
4078 Normally the C ‘>>’ right shift of a signed type replicates the
4079 high bit, giving a so-called “arithmetic” shift. But care should
4080 be taken since Standard C doesn’t require that behavior. On a few
4081 platforms (e.g., Cray C by default) zero bits are shifted in, the
4082 same as a shift of an unsigned type.
4083
4084 Integer ‘/’
4085 C divides signed integers by truncating their quotient toward zero,
4086 yielding the same result as Fortran. However, before C99 the
4087 standard allowed C implementations to take the floor or ceiling of
4088 the quotient in some cases. Hardly any implementations took
4089 advantage of this freedom, though, and it’s probably not worth
4090 worrying about this issue nowadays.
4091
4092 
4093 File: autoconf.info, Node: Particular Functions, Next: Generic Functions, Prev: Function Portability, Up: Library Functions
4094
4095 5.5.2 Particular Function Checks
4096 --------------------------------
4097
4098 These macros check for particular C functions—whether they exist, and in
4099 some cases how they respond when given certain arguments.
4100
4101 — Macro: AC_FUNC_ALLOCA
4102 Check for the ‘alloca’ function. Define ‘HAVE_ALLOCA_H’ if
4103 ‘alloca.h’ defines a working ‘alloca’. If not, look for a builtin
4104 alternative. If either method succeeds, define ‘HAVE_ALLOCA’.
4105 Otherwise, set the output variable ‘ALLOCA’ to
4106 ‘${LIBOBJDIR}alloca.o’ and define ‘C_ALLOCA’ (so programs can
4107 periodically call ‘alloca (0)’ to garbage collect). This variable
4108 is separate from ‘LIBOBJS’ so multiple programs can share the value
4109 of ‘ALLOCA’ without needing to create an actual library, in case
4110 only some of them use the code in ‘LIBOBJS’. The ‘${LIBOBJDIR}’
4111 prefix serves the same purpose as in ‘LIBOBJS’ (*note AC_LIBOBJ vs
4112 LIBOBJS::).
4113
4114 Source files that use ‘alloca’ should start with a piece of code
4115 like the following, to declare it properly.
4116
4117 #include <stdlib.h>
4118 #include <stddef.h>
4119 #ifdef HAVE_ALLOCA_H
4120 # include <alloca.h>
4121 #elif !defined alloca
4122 # ifdef __GNUC__
4123 # define alloca __builtin_alloca
4124 # elif defined _MSC_VER
4125 # include <malloc.h>
4126 # define alloca _alloca
4127 # elif !defined HAVE_ALLOCA
4128 # ifdef __cplusplus
4129 extern "C"
4130 # endif
4131 void *alloca (size_t);
4132 # endif
4133 #endif
4134
4135 If you don’t want to maintain this piece of code in your package
4136 manually, you can instead use the Gnulib module ‘alloca-opt’ or
4137 ‘alloca’. *Note Gnulib::.
4138
4139 — Macro: AC_FUNC_CHOWN
4140 If the ‘chown’ function is available and works (in particular, it
4141 should accept ‘-1’ for ‘uid’ and ‘gid’), define ‘HAVE_CHOWN’. The
4142 result of this macro is cached in the ‘ac_cv_func_chown_works’
4143 variable.
4144
4145 If you want a workaround, that is, a ‘chown’ function that is
4146 available and works, you can use the Gnulib module ‘chown’. *Note
4147 Gnulib::.
4148
4149 — Macro: AC_FUNC_CLOSEDIR_VOID
4150 If the ‘closedir’ function does not return a meaningful value,
4151 define ‘CLOSEDIR_VOID’. Otherwise, callers ought to check its
4152 return value for an error indicator.
4153
4154 Currently this test is implemented by running a test program. When
4155 cross compiling the pessimistic assumption that ‘closedir’ does not
4156 return a meaningful value is made.
4157
4158 The result of this macro is cached in the
4159 ‘ac_cv_func_closedir_void’ variable.
4160
4161 This macro is obsolescent, as ‘closedir’ returns a meaningful value
4162 on current systems. New programs need not use this macro.
4163
4164 — Macro: AC_FUNC_ERROR_AT_LINE
4165 If the ‘error_at_line’ function is not found, require an
4166 ‘AC_LIBOBJ’ replacement of ‘error’.
4167
4168 The result of this macro is cached in the ‘ac_cv_lib_error_at_line’
4169 variable.
4170
4171 The ‘AC_FUNC_ERROR_AT_LINE’ macro is obsolescent. New programs
4172 should use Gnulib’s ‘error’ module. *Note Gnulib::.
4173
4174 — Macro: AC_FUNC_FNMATCH
4175 If the ‘fnmatch’ function conforms to POSIX, define ‘HAVE_FNMATCH’.
4176
4177 Unlike the other specific ‘AC_FUNC’ macros, ‘AC_FUNC_FNMATCH’ does
4178 not replace a broken/missing ‘fnmatch’. This is for historical
4179 reasons. See ‘AC_REPLACE_FNMATCH’ below.
4180
4181 The result of this macro is cached in the
4182 ‘ac_cv_func_fnmatch_works’ variable.
4183
4184 This macro is obsolescent. New programs should use Gnulib’s
4185 ‘fnmatch-posix’ module. *Note Gnulib::.
4186
4187 — Macro: AC_FUNC_FNMATCH_GNU
4188 Behave like ‘AC_REPLACE_FNMATCH’ (_replace_) but also test whether
4189 ‘fnmatch’ supports GNU extensions. Detect common implementation
4190 bugs, for example, the bugs in the GNU C Library 2.1.
4191
4192 The result of this macro is cached in the ‘ac_cv_func_fnmatch_gnu’
4193 variable.
4194
4195 This macro is obsolescent. New programs should use Gnulib’s
4196 ‘fnmatch-gnu’ module. *Note Gnulib::.
4197
4198 — Macro: AC_FUNC_FORK
4199 This macro checks for the ‘fork’ and ‘vfork’ functions. If a
4200 working ‘fork’ is found, define ‘HAVE_WORKING_FORK’. This macro
4201 checks whether ‘fork’ is just a stub by trying to run it.
4202
4203 If ‘vfork.h’ is found, define ‘HAVE_VFORK_H’. If a working ‘vfork’
4204 is found, define ‘HAVE_WORKING_VFORK’. Otherwise, define ‘vfork’
4205 to be ‘fork’ for backward compatibility with previous versions of
4206 ‘autoconf’. This macro checks for several known errors in
4207 implementations of ‘vfork’ and considers the system to not have a
4208 working ‘vfork’ if it detects any of them.
4209
4210 Since this macro defines ‘vfork’ only for backward compatibility
4211 with previous versions of ‘autoconf’ you’re encouraged to define it
4212 yourself in new code:
4213 #ifndef HAVE_WORKING_VFORK
4214 # define vfork fork
4215 #endif
4216
4217 The results of this macro are cached in the ‘ac_cv_func_fork_works’
4218 and ‘ac_cv_func_vfork_works’ variables. In order to override the
4219 test, you also need to set the ‘ac_cv_func_fork’ and
4220 ‘ac_cv_func_vfork’ variables.
4221
4222 — Macro: AC_FUNC_FSEEKO
4223 If the ‘fseeko’ and ‘ftello’ functions are available, define
4224 ‘HAVE_FSEEKO’. Define ‘_LARGEFILE_SOURCE’ if necessary to make the
4225 prototype visible.
4226
4227 Configure scripts that use ‘AC_FUNC_FSEEKO’ should normally also
4228 use ‘AC_SYS_LARGEFILE’ to ensure that ‘off_t’ can represent all
4229 supported file sizes. *Note AC_SYS_LARGEFILE::.
4230
4231 The Gnulib module ‘fseeko’ invokes ‘AC_FUNC_FSEEKO’ and also
4232 contains workarounds for other portability problems of ‘fseeko’.
4233 *Note Gnulib::.
4234
4235 — Macro: AC_FUNC_GETGROUPS
4236 Perform all the checks performed by ‘AC_TYPE_GETGROUPS’ (*note
4237 AC_TYPE_GETGROUPS::). Then, if the ‘getgroups’ function is
4238 available and known to work correctly, define ‘HAVE_GETGROUPS’.
4239 Set the output variable ‘GETGROUPS_LIB’ to any libraries needed to
4240 get that function.
4241
4242 This macro relies on a list of systems with known, serious bugs in
4243 ‘getgroups’. If this list mis-identifies your system’s ‘getgroups’
4244 as buggy, or as not buggy, you can override it by setting the cache
4245 variable ‘ac_cv_func_getgroups_works’ in a ‘config.site’ file
4246 (*note Site Defaults::). Please also report the error to the
4247 Autoconf Bugs mailing list <[email protected]>.
4248
4249 The Gnulib module ‘getgroups’ provides workarounds for additional,
4250 less severe portability problems with this function.
4251
4252 — Macro: AC_FUNC_GETLOADAVG
4253 Check how to get the system load averages. To perform its tests
4254 properly, this macro needs the file ‘getloadavg.c’; therefore, be
4255 sure to set the ‘AC_LIBOBJ’ replacement directory properly (see
4256 *note Generic Functions::, ‘AC_CONFIG_LIBOBJ_DIR’).
4257
4258 If the system has the ‘getloadavg’ function, define
4259 ‘HAVE_GETLOADAVG’, and set ‘GETLOADAVG_LIBS’ to any libraries
4260 necessary to get that function. Also add ‘GETLOADAVG_LIBS’ to
4261 ‘LIBS’. Otherwise, require an ‘AC_LIBOBJ’ replacement for
4262 ‘getloadavg’ and possibly define several other C preprocessor
4263 macros and output variables:
4264
4265 1. Define ‘C_GETLOADAVG’.
4266
4267 2. Define ‘SVR4’, ‘DGUX’, ‘UMAX’, or ‘UMAX4_3’ if on those
4268 systems.
4269
4270 3. If ‘nlist.h’ is found, define ‘HAVE_NLIST_H’.
4271
4272 4. If ‘struct nlist’ has an ‘n_un.n_name’ member, define
4273 ‘HAVE_STRUCT_NLIST_N_UN_N_NAME’. The obsolete symbol
4274 ‘NLIST_NAME_UNION’ is still defined, but do not depend upon
4275 it.
4276
4277 5. Programs may need to be installed set-group-ID (or
4278 set-user-ID) for ‘getloadavg’ to work. In this case, define
4279 ‘GETLOADAVG_PRIVILEGED’, set the output variable ‘NEED_SETGID’
4280 to ‘true’ (and otherwise to ‘false’), and set ‘KMEM_GROUP’ to
4281 the name of the group that should own the installed program.
4282
4283 The ‘AC_FUNC_GETLOADAVG’ macro is obsolescent. New programs should
4284 use Gnulib’s ‘getloadavg’ module. *Note Gnulib::.
4285
4286 — Macro: AC_FUNC_GETMNTENT
4287 Check for ‘getmntent’ in the standard C library, and then in the
4288 ‘sun’, ‘seq’, and ‘gen’ libraries. Then, if ‘getmntent’ is
4289 available, define ‘HAVE_GETMNTENT’ and set ‘ac_cv_func_getmntent’
4290 to ‘yes’. Otherwise set ‘ac_cv_func_getmntent’ to ‘no’.
4291
4292 The result of this macro can be overridden by setting the cache
4293 variable ‘ac_cv_search_getmntent’.
4294
4295 The ‘AC_FUNC_GETMNTENT’ macro is obsolescent. New programs should
4296 use Gnulib’s ‘mountlist’ module. *Note Gnulib::.
4297
4298 — Macro: AC_FUNC_GETPGRP
4299 Define ‘GETPGRP_VOID’ if it is an error to pass 0 to ‘getpgrp’;
4300 this is the POSIX behavior. On older BSD systems, you must pass 0
4301 to ‘getpgrp’, as it takes an argument and behaves like POSIX’s
4302 ‘getpgid’.
4303
4304 #ifdef GETPGRP_VOID
4305 pid = getpgrp ();
4306 #else
4307 pid = getpgrp (0);
4308 #endif
4309
4310 This macro does not check whether ‘getpgrp’ exists at all; if you
4311 need to work in that situation, first call ‘AC_CHECK_FUNC’ for
4312 ‘getpgrp’.
4313
4314 The result of this macro is cached in the ‘ac_cv_func_getpgrp_void’
4315 variable.
4316
4317 This macro is obsolescent, as current systems have a ‘getpgrp’
4318 whose signature conforms to POSIX. New programs need not use this
4319 macro.
4320
4321 — Macro: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
4322 If ‘link’ is a symbolic link, then ‘lstat’ should treat ‘link/’ the
4323 same as ‘link/.’. However, many older ‘lstat’ implementations
4324 incorrectly ignore trailing slashes.
4325
4326 It is safe to assume that if ‘lstat’ incorrectly ignores trailing
4327 slashes, then other symbolic-link-aware functions like ‘unlink’
4328 also incorrectly ignore trailing slashes.
4329
4330 If ‘lstat’ behaves properly, define
4331 ‘LSTAT_FOLLOWS_SLASHED_SYMLINK’, otherwise require an ‘AC_LIBOBJ’
4332 replacement of ‘lstat’.
4333
4334 The result of this macro is cached in the
4335 ‘ac_cv_func_lstat_dereferences_slashed_symlink’ variable.
4336
4337 The ‘AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK’ macro is obsolescent.
4338 New programs should use Gnulib’s ‘lstat’ module. *Note Gnulib::.
4339
4340 — Macro: AC_FUNC_MALLOC
4341 If the ‘malloc’ function is compatible with the GNU C library
4342 ‘malloc’ (i.e., ‘malloc (0)’ returns a valid pointer), define
4343 ‘HAVE_MALLOC’ to 1. Otherwise define ‘HAVE_MALLOC’ to 0, ask for
4344 an ‘AC_LIBOBJ’ replacement for ‘malloc’, and define ‘malloc’ to
4345 ‘rpl_malloc’ so that the native ‘malloc’ is not used in the main
4346 project.
4347
4348 Typically, the replacement file ‘malloc.c’ should look like (note
4349 the ‘#undef malloc’):
4350
4351 #include <config.h>
4352 #undef malloc
4353
4354 #include <stdlib.h>
4355
4356 /* Allocate an N-byte block of memory from the heap.
4357 If N is zero, allocate a 1-byte block. */
4358
4359 void *
4360 rpl_malloc (size_t n)
4361 {
4362 if (n == 0)
4363 n = 1;
4364 return malloc (n);
4365 }
4366
4367 The result of this macro is cached in the
4368 ‘ac_cv_func_malloc_0_nonnull’ variable. The result might contain
4369 spaces, e.g., ‘guessing yes’.
4370
4371 If you don’t want to maintain a ‘malloc.c’ file in your package
4372 manually, you can instead use the Gnulib module ‘malloc-gnu’.
4373
4374 — Macro: AC_FUNC_MBRTOWC
4375 Define ‘HAVE_MBRTOWC’ to 1 if the function ‘mbrtowc’ and the type
4376 ‘mbstate_t’ are properly declared.
4377
4378 The result of this macro is cached in the ‘ac_cv_func_mbrtowc’
4379 variable.
4380
4381 The Gnulib module ‘mbrtowc’ not only ensures that the function is
4382 declared, but also works around other portability problems of this
4383 function.
4384
4385 — Macro: AC_FUNC_MEMCMP
4386 If the ‘memcmp’ function is not available or does not work, require
4387 an ‘AC_LIBOBJ’ replacement for ‘memcmp’.
4388
4389 The result of this macro is cached in the
4390 ‘ac_cv_func_memcmp_working’ variable.
4391
4392 This macro is obsolescent, as current systems have a working
4393 ‘memcmp’. New programs need not use this macro.
4394
4395 — Macro: AC_FUNC_MKTIME
4396 If the ‘mktime’ function is not available, or does not work
4397 correctly, require an ‘AC_LIBOBJ’ replacement for ‘mktime’. For
4398 the purposes of this test, ‘mktime’ should conform to the POSIX
4399 standard and should be the inverse of ‘localtime’.
4400
4401 The result of this macro is cached in the
4402 ‘ac_cv_func_working_mktime’ variable.
4403
4404 The ‘AC_FUNC_MKTIME’ macro is obsolescent. New programs should use
4405 Gnulib’s ‘mktime’ module. *Note Gnulib::.
4406
4407 — Macro: AC_FUNC_MMAP
4408 If the ‘mmap’ function exists and works correctly, define
4409 ‘HAVE_MMAP’. This checks only private fixed mapping of
4410 already-mapped memory.
4411
4412 The result of this macro is cached in the
4413 ‘ac_cv_func_mmap_fixed_mapped’ variable.
4414
4415 Note: This macro asks for more than what an average program needs
4416 from ‘mmap’. In particular, the use of ‘MAP_FIXED’ fails on HP-UX
4417 11, whereas ‘mmap’ otherwise works fine on this platform.
4418
4419 — Macro: AC_FUNC_OBSTACK
4420 If the obstacks are found, define ‘HAVE_OBSTACK’, else require an
4421 ‘AC_LIBOBJ’ replacement for ‘obstack’.
4422
4423 The result of this macro is cached in the ‘ac_cv_func_obstack’
4424 variable.
4425
4426 The ‘AC_FUNC_OBSTACK’ macro is obsolescent. New programs should
4427 use Gnulib’s ‘obstack’ module. *Note Gnulib::.
4428
4429 — Macro: AC_FUNC_REALLOC
4430 If a successful call to ‘realloc (NULL, 0)’ returns a non-null
4431 pointer, define ‘HAVE_REALLOC’ to 1. Otherwise define
4432 ‘HAVE_REALLOC’ to 0, ask for an ‘AC_LIBOBJ’ replacement for
4433 ‘realloc’, and define ‘realloc’ to ‘rpl_realloc’ so that the native
4434 ‘realloc’ is not used in the main project. See ‘AC_FUNC_MALLOC’
4435 for details.
4436
4437 The result of this macro is cached in the
4438 ‘ac_cv_func_realloc_0_nonnull’ variable. The result might contain
4439 spaces, e.g., ‘guessing yes’.
4440
4441 This macro does not check compatibility with glibc ‘realloc (P, 0)’
4442 when P is non-null, as glibc 1–2.1 behaves differently from glibc
4443 2.1.1–2.40 (at least), and the C standard says behavior is
4444 undefined.
4445
4446 — Macro: AC_FUNC_SELECT_ARGTYPES
4447 Determines the correct type to be passed for each of the ‘select’
4448 function’s arguments, and defines those types in
4449 ‘SELECT_TYPE_ARG1’, ‘SELECT_TYPE_ARG234’, and ‘SELECT_TYPE_ARG5’
4450 respectively. ‘SELECT_TYPE_ARG1’ defaults to ‘int’,
4451 ‘SELECT_TYPE_ARG234’ defaults to ‘int *’, and ‘SELECT_TYPE_ARG5’
4452 defaults to ‘struct timeval *’.
4453
4454 This macro is obsolescent, as current systems have a ‘select’ whose
4455 signature conforms to POSIX. New programs need not use this macro.
4456
4457 — Macro: AC_FUNC_SETPGRP
4458 If ‘setpgrp’ takes no argument (the POSIX version), define
4459 ‘SETPGRP_VOID’. Otherwise, it is the BSD version, which takes two
4460 process IDs as arguments. This macro does not check whether
4461 ‘setpgrp’ exists at all; if you need to work in that situation,
4462 first call ‘AC_CHECK_FUNC’ for ‘setpgrp’. This macro also does not
4463 check for the Solaris variant of ‘setpgrp’, which returns a ‘pid_t’
4464 instead of an ‘int’; portable code should only use the return value
4465 by comparing it against ‘-1’ to check for errors.
4466
4467 The result of this macro is cached in the ‘ac_cv_func_setpgrp_void’
4468 variable.
4469
4470 This macro is obsolescent, as all forms of ‘setpgrp’ are also
4471 obsolescent. New programs should use the POSIX function ‘setpgid’,
4472 which takes two process IDs as arguments (like the BSD ‘setpgrp’).
4473
4474 — Macro: AC_FUNC_STAT
4475 — Macro: AC_FUNC_LSTAT
4476 Determine whether ‘stat’ or ‘lstat’ have the bug that it succeeds
4477 when given the zero-length file name as argument.
4478
4479 If it does, then define ‘HAVE_STAT_EMPTY_STRING_BUG’ (or
4480 ‘HAVE_LSTAT_EMPTY_STRING_BUG’) and ask for an ‘AC_LIBOBJ’
4481 replacement of it.
4482
4483 The results of these macros are cached in the
4484 ‘ac_cv_func_stat_empty_string_bug’ and the
4485 ‘ac_cv_func_lstat_empty_string_bug’ variables, respectively.
4486
4487 These macros are obsolescent, as no current systems have the bug.
4488 New programs need not use these macros.
4489
4490 — Macro: AC_FUNC_STRCOLL
4491 If the ‘strcoll’ function exists and works correctly, define
4492 ‘HAVE_STRCOLL’. This does a bit more than
4493 ‘AC_CHECK_FUNCS(strcoll)’, because some systems have incorrect
4494 definitions of ‘strcoll’ that should not be used. But it does not
4495 check against a known bug of this function on Solaris 10.
4496
4497 The result of this macro is cached in the
4498 ‘ac_cv_func_strcoll_works’ variable.
4499
4500 — Macro: AC_FUNC_STRERROR_R
4501 If ‘strerror_r’ is available, define ‘HAVE_STRERROR_R’, and if it
4502 is declared, define ‘HAVE_DECL_STRERROR_R’. If it returns a ‘char
4503 *’ message, define ‘STRERROR_R_CHAR_P’; otherwise it returns an
4504 ‘int’ error number. The Thread-Safe Functions option of POSIX
4505 requires ‘strerror_r’ to return ‘int’, but many systems (including,
4506 for example, the GNU C Library) return a ‘char *’ value that is not
4507 necessarily equal to the buffer argument.
4508
4509 The result of this macro is cached in the
4510 ‘ac_cv_func_strerror_r_char_p’ variable.
4511
4512 The Gnulib module ‘strerror_r’ not only ensures that the function
4513 has the return type specified by POSIX, but also works around other
4514 portability problems of this function.
4515
4516 — Macro: AC_FUNC_STRFTIME
4517 Check for ‘strftime’ in the ‘intl’ library. Then, if ‘strftime’ is
4518 available, define ‘HAVE_STRFTIME’.
4519
4520 This macro is obsolescent, as no current systems require the ‘intl’
4521 library for ‘strftime’. New programs need not use this macro.
4522
4523 — Macro: AC_FUNC_STRTOD
4524 If the ‘strtod’ function does not exist or doesn’t work correctly,
4525 ask for an ‘AC_LIBOBJ’ replacement of ‘strtod’. In this case,
4526 because ‘strtod.c’ is likely to need ‘pow’, set the output variable
4527 ‘POW_LIB’ to the extra library needed.
4528
4529 This macro caches its result in the ‘ac_cv_func_strtod’ variable
4530 and depends upon the result in the ‘ac_cv_func_pow’ variable.
4531
4532 The ‘AC_FUNC_STRTOD’ macro is obsolescent. New programs should use
4533 Gnulib’s ‘strtod’ module. *Note Gnulib::.
4534
4535 — Macro: AC_FUNC_STRTOLD
4536 If the ‘strtold’ function exists and conforms to C99 or later,
4537 define ‘HAVE_STRTOLD’.
4538
4539 This macro caches its result in the ‘ac_cv_func_strtold’ variable.
4540
4541 The Gnulib module ‘strtold’ not only ensures that the function
4542 exists, but also works around other portability problems of this
4543 function.
4544
4545 — Macro: AC_FUNC_STRNLEN
4546 If the ‘strnlen’ function is not available, or is buggy (like the
4547 one from Android 5.0 or AIX 4.3), require an ‘AC_LIBOBJ’
4548 replacement for it.
4549
4550 This macro caches its result in the ‘ac_cv_func_strnlen_working’
4551 variable.
4552
4553 The ‘AC_FUNC_STRNLEN’ macro is obsolescent. New programs should
4554 use Gnulib’s ‘strnlen’ module. *Note Gnulib::.
4555
4556 — Macro: AC_FUNC_UTIME_NULL
4557 If ‘utime (FILE, NULL)’ sets FILE’s timestamp to the present,
4558 define ‘HAVE_UTIME_NULL’.
4559
4560 This macro caches its result in the ‘ac_cv_func_utime_null’
4561 variable.
4562
4563 This macro is obsolescent, as all current systems have a ‘utime’
4564 that behaves this way. New programs need not use this macro.
4565
4566 — Macro: AC_FUNC_VPRINTF
4567 If ‘vprintf’ is found, define ‘HAVE_VPRINTF’. Otherwise, if
4568 ‘_doprnt’ is found, define ‘HAVE_DOPRNT’. (If ‘vprintf’ is
4569 available, you may assume that ‘vfprintf’ and ‘vsprintf’ are also
4570 available.)
4571
4572 This macro is obsolescent, as all current systems have ‘vprintf’.
4573 New programs need not use this macro.
4574
4575 — Macro: AC_REPLACE_FNMATCH
4576 If the ‘fnmatch’ function does not conform to POSIX (see
4577 ‘AC_FUNC_FNMATCH’), ask for its ‘AC_LIBOBJ’ replacement.
4578
4579 The files ‘fnmatch.c’, ‘fnmatch_loop.c’, and ‘fnmatch_.h’ in the
4580 ‘AC_LIBOBJ’ replacement directory are assumed to contain a copy of
4581 the source code of GNU ‘fnmatch’. If necessary, this source code
4582 is compiled as an ‘AC_LIBOBJ’ replacement, and the ‘fnmatch_.h’
4583 file is linked to ‘fnmatch.h’ so that it can be included in place
4584 of the system ‘<fnmatch.h>’.
4585
4586 This macro caches its result in the ‘ac_cv_func_fnmatch_works’
4587 variable.
4588
4589 This macro is obsolescent, as it assumes the use of particular
4590 source files. New programs should use Gnulib’s ‘fnmatch-posix’
4591 module, which provides this macro along with the source files.
4592 *Note Gnulib::.
4593
4594 
4595 File: autoconf.info, Node: Generic Functions, Prev: Particular Functions, Up: Library Functions
4596
4597 5.5.3 Generic Function Checks
4598 -----------------------------
4599
4600 These macros are used to find functions not covered by the “particular”
4601 test macros. If the functions might be in libraries other than the
4602 default C library, first call ‘AC_CHECK_LIB’ for those libraries. If
4603 you need to check the behavior of a function as well as find out whether
4604 it is present, you have to write your own test for it (*note Writing
4605 Tests::).
4606
4607 — Macro: AC_CHECK_FUNC(FUNCTION, [ACTION-IF-FOUND],
4608 [ACTION-IF-NOT-FOUND])
4609 If C function FUNCTION is available, run shell commands
4610 ACTION-IF-FOUND, otherwise ACTION-IF-NOT-FOUND. If you just want
4611 to define a symbol if the function is available, consider using
4612 ‘AC_CHECK_FUNCS’ instead. This macro checks for functions with C
4613 linkage even when ‘AC_LANG(C++)’ has been called, since C is more
4614 standardized than C++. (*note Language Choice::, for more
4615 information about selecting the language for checks.)
4616
4617 This macro caches its result in the ‘ac_cv_func_FUNCTION’ variable.
4618
4619 — Macro: AC_CHECK_FUNCS(FUNCTION..., [ACTION-IF-FOUND],
4620 [ACTION-IF-NOT-FOUND])
4621 For each FUNCTION enumerated in the blank-or-newline-separated
4622 argument list, define ‘HAVE_FUNCTION’ (in all capitals) if it is
4623 available. If ACTION-IF-FOUND is given, it is additional shell
4624 code to execute when one of the functions is found. You can give
4625 it a value of ‘break’ to break out of the loop on the first match.
4626 If ACTION-IF-NOT-FOUND is given, it is executed when one of the
4627 functions is not found.
4628
4629 Results are cached for each FUNCTION as in ‘AC_CHECK_FUNC’.
4630
4631 — Macro: AC_CHECK_FUNCS_ONCE(FUNCTION...)
4632 For each FUNCTION enumerated in the blank-or-newline-separated
4633 argument list, define ‘HAVE_FUNCTION’ (in all capitals) if it is
4634 available. This is a once-only variant of ‘AC_CHECK_FUNCS’. It
4635 generates the checking code at most once, so that ‘configure’ is
4636 smaller and faster; but the checks cannot be conditionalized and
4637 are always done once, early during the ‘configure’ run.
4638
4639
4640 Autoconf follows a philosophy that was formed over the years by those
4641 who have struggled for portability: isolate the portability issues in
4642 specific files, and then program as if you were in a POSIX environment.
4643 Some functions may be missing or unfixable, and your package must be
4644 ready to replace them.
4645
4646 Suitable replacements for many such problem functions are available
4647 from Gnulib (*note Gnulib::).
4648
4649 — Macro: AC_LIBOBJ(FUNCTION)
4650 Specify that ‘FUNCTION.c’ must be included in the executables to
4651 replace a missing or broken implementation of FUNCTION.
4652
4653 Technically, it adds ‘FUNCTION.$ac_objext’ to the output variable
4654 ‘LIBOBJS’ if it is not already in, and calls ‘AC_LIBSOURCE’ for
4655 ‘FUNCTION.c’. You should not directly change ‘LIBOBJS’, since this
4656 is not traceable.
4657
4658 — Macro: AC_LIBSOURCE(FILE)
4659 Specify that FILE might be needed to compile the project. If you
4660 need to know what files might be needed by a ‘configure.ac’, you
4661 should trace ‘AC_LIBSOURCE’. FILE must be a literal.
4662
4663 This macro is called automatically from ‘AC_LIBOBJ’, but you must
4664 call it explicitly if you pass a shell variable to ‘AC_LIBOBJ’. In
4665 that case, since shell variables cannot be traced statically, you
4666 must pass to ‘AC_LIBSOURCE’ any possible files that the shell
4667 variable might cause ‘AC_LIBOBJ’ to need. For example, if you want
4668 to pass a variable ‘$foo_or_bar’ to ‘AC_LIBOBJ’ that holds either
4669 ‘"foo"’ or ‘"bar"’, you should do:
4670
4671 AC_LIBSOURCE([foo.c])
4672 AC_LIBSOURCE([bar.c])
4673 AC_LIBOBJ([$foo_or_bar])
4674
4675 There is usually a way to avoid this, however, and you are
4676 encouraged to simply call ‘AC_LIBOBJ’ with literal arguments.
4677
4678 Note that this macro replaces the obsolete ‘AC_LIBOBJ_DECL’, with
4679 slightly different semantics: the old macro took the function name,
4680 e.g., ‘foo’, as its argument rather than the file name.
4681
4682 — Macro: AC_LIBSOURCES(FILES)
4683 Like ‘AC_LIBSOURCE’, but accepts one or more FILES in a
4684 comma-separated M4 list. Thus, the above example might be
4685 rewritten:
4686
4687 AC_LIBSOURCES([foo.c, bar.c])
4688 AC_LIBOBJ([$foo_or_bar])
4689
4690 — Macro: AC_CONFIG_LIBOBJ_DIR(DIRECTORY)
4691 Specify that ‘AC_LIBOBJ’ replacement files are to be found in
4692 DIRECTORY, a name relative to the top level of the source tree.
4693 The replacement directory defaults to ‘.’, the top level directory,
4694 and the most typical value is ‘lib’, corresponding to
4695 ‘AC_CONFIG_LIBOBJ_DIR([lib])’.
4696
4697 ‘configure’ might need to know the replacement directory for the
4698 following reasons: (i) some checks use the replacement files, (ii)
4699 some macros bypass broken system headers by installing links to the
4700 replacement headers (iii) when used in conjunction with Automake,
4701 within each makefile, DIRECTORY is used as a relative path from
4702 ‘$(top_srcdir)’ to each object named in ‘LIBOBJS’ and ‘LTLIBOBJS’,
4703 etc.
4704
4705
4706 It is common to merely check for the existence of a function, and ask
4707 for its ‘AC_LIBOBJ’ replacement if missing. The following macro is a
4708 convenient shorthand.
4709
4710 — Macro: AC_REPLACE_FUNCS(FUNCTION...)
4711 Like ‘AC_CHECK_FUNCS’, but uses ‘AC_LIBOBJ(FUNCTION)’ as
4712 ACTION-IF-NOT-FOUND. You can declare your replacement function by
4713 enclosing the prototype in ‘#ifndef HAVE_FUNCTION’. If the system
4714 has the function, it probably declares it in a header file you
4715 should be including, so you shouldn’t redeclare it lest your
4716 declaration conflict.
4717
4718 
4719 File: autoconf.info, Node: Header Files, Next: Declarations, Prev: Library Functions, Up: Existing Tests
4720
4721 5.6 Header Files
4722 ================
4723
4724 The following macros check for the presence of certain C header files.
4725 If there is no macro specifically defined to check for a header file you
4726 need, and you don’t need to check for any special properties of it, then
4727 you can use one of the general header-file check macros.
4728
4729 * Menu:
4730
4731 * Header Portability:: Collected knowledge on common headers
4732 * Particular Headers:: Special handling to find certain headers
4733 * Generic Headers:: How to find other headers
4734
4735 
4736 File: autoconf.info, Node: Header Portability, Next: Particular Headers, Up: Header Files
4737
4738 5.6.1 Portability of Headers
4739 ----------------------------
4740
4741 This section documents some collected knowledge about common headers,
4742 and the problems they cause. By definition, this list always requires
4743 additions. A much more complete list is maintained by the Gnulib
4744 project (*note Gnulib::), covering *note POSIX Headers: (gnulib)Header
4745 File Substitutes. and *note Glibc Headers: (gnulib)Glibc Header File
4746 Substitutes. Please help us keep the Gnulib list as complete as
4747 possible.
4748
4749 When we say that a header “may require” some set of other headers, we
4750 mean that it may be necessary for you to manually include those other
4751 headers first, or the contents of the header under test will fail to
4752 compile. When checking for these headers, you must provide the
4753 potentially-required headers in the INCLUDES argument to
4754 ‘AC_CHECK_HEADER’ or ‘AC_CHECK_HEADERS’, or the check will fail
4755 spuriously. ‘AC_INCLUDES_DEFAULT’ (*note Default Includes::) arranges
4756 to include a number of common requirements and should normally come
4757 first in your INCLUDES. For example, ‘net/if.h’ may require
4758 ‘sys/types.h’, ‘sys/socket.h’, or both, and ‘AC_INCLUDES_DEFAULT’
4759 handles ‘sys/types.h’ but not ‘sys/socket.h’, so you should check for it
4760 like this:
4761
4762 AC_CHECK_HEADERS([sys/socket.h])
4763 AC_CHECK_HEADERS([net/if.h], [], [],
4764 [AC_INCLUDES_DEFAULT[
4765 #ifdef HAVE_SYS_SOCKET_H
4766 # include <sys/socket.h>
4767 #endif
4768 ]])
4769
4770 Note that the example mixes single quoting (for‘AC_INCLUDES_DEFAULT’,
4771 so that it gets expanded) and double quoting (to ensure that each
4772 preprocessor ‘#’ gets treated as a literal string rather than a
4773 comment).
4774
4775 ‘limits.h’
4776 In C99 and later, ‘limits.h’ defines ‘LLONG_MIN’, ‘LLONG_MAX’, and
4777 ‘ULLONG_MAX’, but many almost-C99 environments (e.g., default GCC
4778 4.0.2 + glibc 2.4) do not define them.
4779
4780 ‘memory.h’
4781 This header file is obsolete; use ‘string.h’ instead.
4782
4783 ‘strings.h’
4784 On some systems, this is the only header that declares
4785 ‘strcasecmp’, ‘strncasecmp’, and ‘ffs’.
4786
4787 This header may or may not include ‘string.h’ for you. However, on
4788 all recent systems it is safe to include both ‘string.h’ and
4789 ‘strings.h’, in either order, in the same source file.
4790
4791 ‘inttypes.h’ vs. ‘stdint.h’
4792 C99 specifies that ‘inttypes.h’ includes ‘stdint.h’, so there’s no
4793 need to include ‘stdint.h’ separately in a standard environment.
4794 However, some implementations have ‘stdint.h’ but not ‘inttypes.h’
4795 (e.g. MSVC 2012). Therefore, it is necessary to check for each
4796 and include each only if available.
4797
4798 ‘linux/irda.h’
4799 This header may require ‘linux/types.h’ and/or ‘sys/socket.h’.
4800
4801 ‘linux/random.h’
4802 This header may require ‘linux/types.h’.
4803
4804 ‘net/if.h’
4805 This header may require ‘sys/types.h’ and/or ‘sys/socket.h’.
4806
4807 ‘netinet/if_ether.h’
4808 This header may require some combination of ‘sys/types.h’,
4809 ‘sys/socket.h’, ‘netinet/in.h’, and ‘net/if.h’.
4810
4811 ‘sys/mount.h’
4812 This header may require ‘sys/params.h’.
4813
4814 ‘sys/ptem.h’
4815 This header may require ‘sys/stream.h’.
4816
4817 ‘sys/socket.h’
4818 This header may require ‘sys/types.h’.
4819
4820 ‘sys/ucred.h’
4821 This header may require ‘sys/types.h’.
4822
4823 ‘X11/extensions/scrnsaver.h’
4824 Using XFree86, this header requires ‘X11/Xlib.h’, which is probably
4825 so required that you might not even consider looking for it.
4826
4827 
4828 File: autoconf.info, Node: Particular Headers, Next: Generic Headers, Prev: Header Portability, Up: Header Files
4829
4830 5.6.2 Particular Header Checks
4831 ------------------------------
4832
4833 These macros check for particular system header files—whether they
4834 exist, and in some cases whether they declare certain symbols.
4835
4836 — Macro: AC_CHECK_HEADER_STDBOOL
4837 Check whether ‘stdbool.h’ exists and conforms to C99 or later, and
4838 cache the result in the ‘ac_cv_header_stdbool_h’ variable. If the
4839 type ‘_Bool’ is defined, define ‘HAVE__BOOL’ to 1.
4840
4841 This macro is obsolescent, as all current C compilers have
4842 ‘stdbool.h’, a header that is itself obsolescent as of C23.
4843
4844 This macro is intended for use by Gnulib (*note Gnulib::) and other
4845 packages that supply a substitute ‘stdbool.h’ on platforms lacking
4846 a conforming one. The ‘AC_HEADER_STDBOOL’ macro is better for code
4847 that explicitly checks for ‘stdbool.h’.
4848
4849 — Macro: AC_HEADER_ASSERT
4850 Check whether to enable assertions in the style of ‘assert.h’.
4851 Assertions are enabled by default, but the user can override this
4852 by invoking ‘configure’ with the ‘--disable-assert’ option.
4853
4854 — Macro: AC_HEADER_DIRENT
4855 Check for the following header files. For the first one that is
4856 found and defines ‘DIR’, define the listed C preprocessor macro:
4857
4858 ‘dirent.h’ ‘HAVE_DIRENT_H’
4859 ‘sys/ndir.h’ ‘HAVE_SYS_NDIR_H’
4860 ‘sys/dir.h’ ‘HAVE_SYS_DIR_H’
4861 ‘ndir.h’ ‘HAVE_NDIR_H’
4862
4863 The directory-library declarations in your source code should look
4864 something like the following:
4865
4866 #include <sys/types.h>
4867 #ifdef HAVE_DIRENT_H
4868 # include <dirent.h>
4869 # define NAMLEN(dirent) strlen ((dirent)->d_name)
4870 #else
4871 # define dirent direct
4872 # define NAMLEN(dirent) ((dirent)->d_namlen)
4873 # ifdef HAVE_SYS_NDIR_H
4874 # include <sys/ndir.h>
4875 # endif
4876 # ifdef HAVE_SYS_DIR_H
4877 # include <sys/dir.h>
4878 # endif
4879 # ifdef HAVE_NDIR_H
4880 # include <ndir.h>
4881 # endif
4882 #endif
4883
4884 Using the above declarations, the program would declare variables
4885 to be of type ‘struct dirent’, not ‘struct direct’, and would
4886 access the length of a directory entry name by passing a pointer to
4887 a ‘struct dirent’ to the ‘NAMLEN’ macro.
4888
4889 This macro also checks for the obsolete ‘dir’ and ‘x’ libraries.
4890
4891 This macro is obsolescent, as all current systems with directory
4892 libraries have ‘<dirent.h>’. New programs need not use this macro.
4893
4894 Also see ‘AC_STRUCT_DIRENT_D_INO’ and ‘AC_STRUCT_DIRENT_D_TYPE’
4895 (*note Particular Structures::).
4896
4897 — Macro: AC_HEADER_MAJOR
4898 Detect the headers required to use ‘makedev’, ‘major’, and ‘minor’.
4899 These functions may be defined by ‘sys/mkdev.h’, ‘sys/sysmacros.h’,
4900 or ‘sys/types.h’.
4901
4902 ‘AC_HEADER_MAJOR’ defines ‘MAJOR_IN_MKDEV’ if they are in
4903 ‘sys/mkdev.h’, or ‘MAJOR_IN_SYSMACROS’ if they are in
4904 ‘sys/sysmacros.h’. If neither macro is defined, they are either in
4905 ‘sys/types.h’ or unavailable.
4906
4907 To properly use these functions, your code should contain something
4908 like:
4909
4910 #include <sys/types.h>
4911 #ifdef MAJOR_IN_MKDEV
4912 # include <sys/mkdev.h>
4913 #elif defined MAJOR_IN_SYSMACROS
4914 # include <sys/sysmacros.h>
4915 #endif
4916
4917 Note: Configure scripts built with Autoconf 2.69 or earlier will
4918 not detect a problem if ‘sys/types.h’ contains definitions of
4919 ‘major’, ‘minor’, and/or ‘makedev’ that trigger compiler warnings
4920 upon use. This is known to occur with GNU libc 2.25, where those
4921 definitions are being deprecated to reduce namespace pollution. If
4922 it is not practical to use Autoconf 2.70 to regenerate the
4923 configure script of affected software, you can work around the
4924 problem by setting ‘ac_cv_header_sys_types_h_makedev=no’, as an
4925 argument to ‘configure’ or as part of a ‘config.site’ site default
4926 file (*note Site Defaults::).
4927
4928 — Macro: AC_HEADER_RESOLV
4929 Checks for header ‘resolv.h’, checking for prerequisites first. To
4930 properly use ‘resolv.h’, your code should contain something like
4931 the following:
4932
4933 #ifdef HAVE_SYS_TYPES_H
4934 # include <sys/types.h>
4935 #endif
4936 #ifdef HAVE_NETINET_IN_H
4937 # include <netinet/in.h> /* inet_ functions / structs */
4938 #endif
4939 #ifdef HAVE_ARPA_NAMESER_H
4940 # include <arpa/nameser.h> /* DNS HEADER struct */
4941 #endif
4942 #ifdef HAVE_NETDB_H
4943 # include <netdb.h>
4944 #endif
4945 #include <resolv.h>
4946
4947 — Macro: AC_HEADER_STAT
4948 If the macros ‘S_ISDIR’, ‘S_ISREG’, etc. defined in ‘sys/stat.h’ do
4949 not work properly (returning false positives), define
4950 ‘STAT_MACROS_BROKEN’. This is the case on Tektronix UTekV, Amdahl
4951 UTS and Motorola System V/88.
4952
4953 This macro is obsolescent, as no current systems have the bug. New
4954 programs need not use this macro.
4955
4956 — Macro: AC_HEADER_STDBOOL
4957 If ‘stdbool.h’ exists and conforms to C99 or later, define
4958 ‘HAVE_STDBOOL_H’ to 1; if the type ‘_Bool’ is defined, define
4959 ‘HAVE__BOOL’ to 1.
4960
4961 This macro is obsolescent, as all current C compilers have
4962 ‘stdbool.h’, a header that is itself obsolescent as of C23.
4963 Nowadays programs that need ‘bool’, ‘true’ and ‘false’ can include
4964 ‘stdbool.h’ unconditionally, without using ‘AC_HEADER_STDBOOL’, and
4965 if such a program needs to be portable only to C23 or later it need
4966 not even include ‘stdbool.h’.
4967
4968 This macro caches its result in the ‘ac_cv_header_stdbool_h’
4969 variable.
4970
4971 This macro differs from ‘AC_CHECK_HEADER_STDBOOL’ only in that it
4972 defines ‘HAVE_STDBOOL_H’ whereas ‘AC_CHECK_HEADER_STDBOOL’ does
4973 not.
4974
4975 — Macro: AC_HEADER_STDC
4976
4977 This macro is obsolescent. Its sole effect is to make sure that
4978 all the headers that are included by ‘AC_INCLUDES_DEFAULT’ (*note
4979 Default Includes::), but not part of C89, have been checked for.
4980
4981 All hosted environments that are still of interest for portable
4982 code provide all of the headers specified in C89 (as amended in
4983 1995).
4984
4985 — Macro: AC_HEADER_SYS_WAIT
4986 If ‘sys/wait.h’ exists and is compatible with POSIX, define
4987 ‘HAVE_SYS_WAIT_H’. Incompatibility can occur if ‘sys/wait.h’ does
4988 not exist, or if it uses the old BSD ‘union wait’ instead of ‘int’
4989 to store a status value. If ‘sys/wait.h’ is not POSIX compatible,
4990 then instead of including it, define the POSIX macros with their
4991 usual interpretations. Here is an example:
4992
4993 #include <sys/types.h>
4994 #ifdef HAVE_SYS_WAIT_H
4995 # include <sys/wait.h>
4996 #endif
4997 #ifndef WEXITSTATUS
4998 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
4999 #endif
5000 #ifndef WIFEXITED
5001 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
5002 #endif
5003
5004 This macro caches its result in the ‘ac_cv_header_sys_wait_h’
5005 variable.
5006
5007 This macro is obsolescent, as current systems are compatible with
5008 POSIX. New programs need not use this macro.
5009
5010 ‘_POSIX_VERSION’ is defined when ‘unistd.h’ is included on POSIX
5011 systems. If there is no ‘unistd.h’, it is definitely not a POSIX
5012 system. However, some non-POSIX systems do have ‘unistd.h’.
5013
5014 The way to check whether the system says it supports POSIX is:
5015
5016 #ifdef HAVE_UNISTD_H
5017 # include <sys/types.h>
5018 # include <unistd.h>
5019 #endif
5020
5021 #ifdef _POSIX_VERSION
5022 /* Code for POSIX systems. */
5023 #endif
5024
5025 — Macro: AC_HEADER_TIOCGWINSZ
5026 If the use of ‘TIOCGWINSZ’ requires ‘<sys/ioctl.h>’, then define
5027 ‘GWINSZ_IN_SYS_IOCTL’. Otherwise ‘TIOCGWINSZ’ can be found in
5028 ‘<termios.h>’.
5029
5030 Use:
5031
5032 #ifdef HAVE_TERMIOS_H
5033 # include <termios.h>
5034 #endif
5035
5036 #ifdef GWINSZ_IN_SYS_IOCTL
5037 # include <sys/ioctl.h>
5038 #endif
5039
5040 
5041 File: autoconf.info, Node: Generic Headers, Prev: Particular Headers, Up: Header Files
5042
5043 5.6.3 Generic Header Checks
5044 ---------------------------
5045
5046 These macros are used to find system header files not covered by the
5047 “particular” test macros. If you need to check the contents of a header
5048 as well as find out whether it is present, you have to write your own
5049 test for it (*note Writing Tests::).
5050
5051 — Macro: AC_CHECK_HEADER(HEADER-FILE, [ACTION-IF-FOUND],
5052 [ACTION-IF-NOT-FOUND], [INCLUDES])
5053 If the system header file HEADER-FILE is compilable, execute shell
5054 commands ACTION-IF-FOUND, otherwise execute ACTION-IF-NOT-FOUND.
5055 If you just want to define a symbol if the header file is
5056 available, consider using ‘AC_CHECK_HEADERS’ instead.
5057
5058 INCLUDES should be the appropriate “prerequisite” code, i.e.
5059 whatever might be required to appear above ‘#include <HEADER-FILE>’
5060 for it to compile without error. This can be anything, but will
5061 normally be additional ‘#include’ directives. If INCLUDES is
5062 omitted or empty, ‘configure’ will use the contents of the macro
5063 ‘AC_INCLUDES_DEFAULT’. *Note Default Includes::.
5064
5065 This macro used to check only for the _presence_ of a header, not
5066 whether its contents were acceptable to the compiler. Some older
5067 ‘configure’ scripts rely on this behavior, so it is still available
5068 by specifying ‘-’ as INCLUDES. This mechanism is deprecated as of
5069 Autoconf 2.70; situations where a preprocessor-only check is
5070 required should use ‘AC_PREPROC_IFELSE’. *Note Running the
5071 Preprocessor::.
5072
5073 This macro caches its result in the ‘ac_cv_header_HEADER-FILE’
5074 variable, with characters not suitable for a variable name mapped
5075 to underscores.
5076
5077 — Macro: AC_CHECK_HEADERS(HEADER-FILE..., [ACTION-IF-FOUND],
5078 [ACTION-IF-NOT-FOUND], [INCLUDES])
5079 For each given system header file HEADER-FILE in the
5080 blank-separated argument list that exists, define
5081 ‘HAVE_HEADER-FILE’ (in all capitals). If ACTION-IF-FOUND is given,
5082 it is additional shell code to execute when one of the header files
5083 is found. You can give it a value of ‘break’ to break out of the
5084 loop on the first match. If ACTION-IF-NOT-FOUND is given, it is
5085 executed when one of the header files is not found.
5086
5087 INCLUDES is interpreted as in ‘AC_CHECK_HEADER’, in order to choose
5088 the set of preprocessor directives supplied before the header under
5089 test.
5090
5091 This macro caches its result in the ‘ac_cv_header_HEADER-FILE’
5092 variable, with characters not suitable for a variable name mapped
5093 to underscores.
5094
5095 — Macro: AC_CHECK_HEADERS_ONCE(HEADER-FILE...)
5096 For each given system header file HEADER-FILE in the
5097 blank-separated argument list that exists, define
5098 ‘HAVE_HEADER-FILE’ (in all capitals).
5099
5100 If you do not need the full power of ‘AC_CHECK_HEADERS’, this
5101 variant generates smaller, faster ‘configure’ files. All headers
5102 passed to ‘AC_CHECK_HEADERS_ONCE’ are checked for in one pass,
5103 early during the ‘configure’ run. The checks cannot be
5104 conditionalized, you cannot specify an ACTION-IF-FOUND or
5105 ACTION-IF-NOT-FOUND, and ‘AC_INCLUDES_DEFAULT’ is always used for
5106 the prerequisites.
5107
5108 In previous versions of Autoconf, these macros merely checked whether
5109 the header was accepted by the preprocessor. This was changed because
5110 the old test was inappropriate for typical uses. Headers are typically
5111 used to compile, not merely to preprocess, and the old behavior
5112 sometimes accepted headers that clashed at compile-time (*note Present
5113 But Cannot Be Compiled::). If for some reason it is inappropriate to
5114 check whether a header is compilable, you should use ‘AC_PREPROC_IFELSE’
5115 (*note Running the Preprocessor::) instead of these macros.
5116
5117 Requiring each header to compile improves the robustness of the test,
5118 but it also requires you to make sure that the INCLUDES are correct.
5119 Most system headers nowadays make sure to ‘#include’ whatever they
5120 require, or else have their dependencies satisfied by
5121 ‘AC_INCLUDES_DEFAULT’ (*note Default Includes::), but *note Header
5122 Portability::, for known exceptions. In general, if you are looking for
5123 ‘bar.h’, which requires that ‘foo.h’ be included first if it exists, you
5124 should do something like this:
5125
5126 AC_CHECK_HEADERS([foo.h])
5127 AC_CHECK_HEADERS([bar.h], [], [],
5128 [#ifdef HAVE_FOO_H
5129 # include <foo.h>
5130 #endif
5131 ])
5132
5133 
5134 File: autoconf.info, Node: Declarations, Next: Structures, Prev: Header Files, Up: Existing Tests
5135
5136 5.7 Declarations
5137 ================
5138
5139 The following macros check for the declaration of variables and
5140 functions. If there is no macro specifically defined to check for a
5141 symbol you need, then you can use the general macros (*note Generic
5142 Declarations::) or, for more complex tests, you may use
5143 ‘AC_COMPILE_IFELSE’ (*note Running the Compiler::).
5144
5145 * Menu:
5146
5147 * Particular Declarations:: Macros to check for certain declarations
5148 * Generic Declarations:: How to find other declarations
5149
5150 
5151 File: autoconf.info, Node: Particular Declarations, Next: Generic Declarations, Up: Declarations
5152
5153 5.7.1 Particular Declaration Checks
5154 -----------------------------------
5155
5156 There are no specific macros for declarations.
5157
5158 
5159 File: autoconf.info, Node: Generic Declarations, Prev: Particular Declarations, Up: Declarations
5160
5161 5.7.2 Generic Declaration Checks
5162 --------------------------------
5163
5164 These macros are used to find declarations not covered by the
5165 “particular” test macros.
5166
5167 — Macro: AC_CHECK_DECL(SYMBOL, [ACTION-IF-FOUND],
5168 [ACTION-IF-NOT-FOUND], [INCLUDES = AC_INCLUDES_DEFAULT])
5169 If SYMBOL (a function, variable, or constant) is not declared in
5170 INCLUDES and a declaration is needed, run the shell commands
5171 ACTION-IF-NOT-FOUND, otherwise ACTION-IF-FOUND. INCLUDES is a
5172 series of include directives, defaulting to ‘AC_INCLUDES_DEFAULT’
5173 (*note Default Includes::), which are used prior to the declaration
5174 under test.
5175
5176 This macro actually tests whether SYMBOL is defined as a macro or
5177 can be used as an r-value, not whether it is really declared,
5178 because it is much safer to avoid introducing extra declarations
5179 when they are not needed. In order to facilitate use of C++ and
5180 overloaded function declarations, it is possible to specify
5181 function argument types in parentheses for types which can be
5182 zero-initialized:
5183
5184 AC_CHECK_DECL([basename(char *)])
5185
5186 This macro caches its result in the ‘ac_cv_have_decl_SYMBOL’
5187 variable, with characters not suitable for a variable name mapped
5188 to underscores.
5189
5190 — Macro: AC_CHECK_DECLS(SYMBOLS, [ACTION-IF-FOUND],
5191 [ACTION-IF-NOT-FOUND], [INCLUDES = AC_INCLUDES_DEFAULT])
5192 For each of the SYMBOLS (_comma_-separated list with optional
5193 function argument types for C++ overloads), define
5194 ‘HAVE_DECL_SYMBOL’ (in all capitals) to ‘1’ if SYMBOL is declared,
5195 otherwise to ‘0’. If ACTION-IF-NOT-FOUND is given, it is
5196 additional shell code to execute when one of the function
5197 declarations is needed, otherwise ACTION-IF-FOUND is executed.
5198
5199 INCLUDES is a series of include directives, defaulting to
5200 ‘AC_INCLUDES_DEFAULT’ (*note Default Includes::), which are used
5201 prior to the declarations under test.
5202
5203 This macro uses an M4 list as first argument:
5204 AC_CHECK_DECLS([strdup])
5205 AC_CHECK_DECLS([strlen])
5206 AC_CHECK_DECLS([malloc, realloc, calloc, free])
5207 AC_CHECK_DECLS([j0], [], [], [[#include <math.h>]])
5208 AC_CHECK_DECLS([[basename(char *)], [dirname(char *)]])
5209
5210 Unlike the other ‘AC_CHECK_*S’ macros, when a SYMBOL is not
5211 declared, ‘HAVE_DECL_SYMBOL’ is defined to ‘0’ instead of leaving
5212 ‘HAVE_DECL_SYMBOL’ undeclared. When you are _sure_ that the check
5213 was performed, use ‘HAVE_DECL_SYMBOL’ in ‘#if’:
5214
5215 #if !HAVE_DECL_SYMBOL
5216 extern char *symbol;
5217 #endif
5218
5219 If the test may have not been performed, however, because it is
5220 safer _not_ to declare a symbol than to use a declaration that
5221 conflicts with the system’s one, you should use:
5222
5223 #if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
5224 void *malloc (size_t *s);
5225 #endif
5226
5227 You fall into the second category only in extreme situations:
5228 either your files may be used without being configured, or they are
5229 used during the configuration. In most cases the traditional
5230 approach is enough.
5231
5232 This macro caches its results in ‘ac_cv_have_decl_SYMBOL’
5233 variables, with characters not suitable for a variable name mapped
5234 to underscores.
5235
5236 — Macro: AC_CHECK_DECLS_ONCE(SYMBOLS)
5237 For each of the SYMBOLS (_comma_-separated list), define
5238 ‘HAVE_DECL_SYMBOL’ (in all capitals) to ‘1’ if SYMBOL is declared
5239 in the default include files, otherwise to ‘0’. This is a
5240 once-only variant of ‘AC_CHECK_DECLS’. It generates the checking
5241 code at most once, so that ‘configure’ is smaller and faster; but
5242 the checks cannot be conditionalized and are always done once,
5243 early during the ‘configure’ run.
5244
5245 
5246 File: autoconf.info, Node: Structures, Next: Types, Prev: Declarations, Up: Existing Tests
5247
5248 5.8 Structures
5249 ==============
5250
5251 The following macros check for the presence of certain members in C
5252 structures. If there is no macro specifically defined to check for a
5253 member you need, then you can use the general structure-member macros
5254 (*note Generic Structures::) or, for more complex tests, you may use
5255 ‘AC_COMPILE_IFELSE’ (*note Running the Compiler::).
5256
5257 * Menu:
5258
5259 * Particular Structures:: Macros to check for certain structure members
5260 * Generic Structures:: How to find other structure members
5261
5262 
5263 File: autoconf.info, Node: Particular Structures, Next: Generic Structures, Up: Structures
5264
5265 5.8.1 Particular Structure Checks
5266 ---------------------------------
5267
5268 The following macros check for certain structures or structure members.
5269
5270 — Macro: AC_STRUCT_DIRENT_D_INO
5271 Perform all the actions of ‘AC_HEADER_DIRENT’ (*note Particular
5272 Headers::). Then, if ‘struct dirent’ contains a ‘d_ino’ member,
5273 define ‘HAVE_STRUCT_DIRENT_D_INO’.
5274
5275 ‘HAVE_STRUCT_DIRENT_D_INO’ indicates only the presence of ‘d_ino’,
5276 not whether its contents are always reliable. Traditionally, a
5277 zero ‘d_ino’ indicated a deleted directory entry, though current
5278 systems hide this detail from the user and never return zero
5279 ‘d_ino’ values. Many current systems report an incorrect ‘d_ino’
5280 for a directory entry that is a mount point.
5281
5282 — Macro: AC_STRUCT_DIRENT_D_TYPE
5283 Perform all the actions of ‘AC_HEADER_DIRENT’ (*note Particular
5284 Headers::). Then, if ‘struct dirent’ contains a ‘d_type’ member,
5285 define ‘HAVE_STRUCT_DIRENT_D_TYPE’.
5286
5287 — Macro: AC_STRUCT_ST_BLOCKS
5288 If ‘struct stat’ contains an ‘st_blocks’ member, define
5289 ‘HAVE_STRUCT_STAT_ST_BLOCKS’. Otherwise, require an ‘AC_LIBOBJ’
5290 replacement of ‘fileblocks’. The former name, ‘HAVE_ST_BLOCKS’ is
5291 to be avoided, as its support will cease in the future.
5292
5293 This macro caches its result in the
5294 ‘ac_cv_member_struct_stat_st_blocks’ variable.
5295
5296 — Macro: AC_STRUCT_TM
5297 If ‘time.h’ does not define ‘struct tm’, define ‘TM_IN_SYS_TIME’,
5298 which means that including ‘sys/time.h’ had better define ‘struct
5299 tm’.
5300
5301 This macro is obsolescent, as ‘time.h’ defines ‘struct tm’ in
5302 current systems. New programs need not use this macro.
5303
5304 — Macro: AC_STRUCT_TIMEZONE
5305 Figure out how to get the current timezone. If ‘struct tm’ has a
5306 ‘tm_zone’ member, define ‘HAVE_STRUCT_TM_TM_ZONE’ (and the
5307 obsoleted ‘HAVE_TM_ZONE’). Otherwise, if the external array
5308 ‘tzname’ is found, define ‘HAVE_TZNAME’; if it is declared, define
5309 ‘HAVE_DECL_TZNAME’.
5310
5311 
5312 File: autoconf.info, Node: Generic Structures, Prev: Particular Structures, Up: Structures
5313
5314 5.8.2 Generic Structure Checks
5315 ------------------------------
5316
5317 These macros are used to find structure members not covered by the
5318 “particular” test macros.
5319
5320 — Macro: AC_CHECK_MEMBER(AGGREGATE.MEMBER, [ACTION-IF-FOUND],
5321 [ACTION-IF-NOT-FOUND], [INCLUDES = AC_INCLUDES_DEFAULT])
5322 Check whether MEMBER is a member of the aggregate AGGREGATE. If no
5323 INCLUDES are specified, the default includes are used (*note
5324 Default Includes::).
5325
5326 AC_CHECK_MEMBER([struct passwd.pw_gecos], [],
5327 [AC_MSG_ERROR([we need 'passwd.pw_gecos'])],
5328 [[#include <pwd.h>]])
5329
5330 You can use this macro for submembers:
5331
5332 AC_CHECK_MEMBER(struct top.middle.bot)
5333
5334 This macro caches its result in the ‘ac_cv_member_AGGREGATE_MEMBER’
5335 variable, with characters not suitable for a variable name mapped
5336 to underscores.
5337
5338 — Macro: AC_CHECK_MEMBERS(MEMBERS, [ACTION-IF-FOUND],
5339 [ACTION-IF-NOT-FOUND], [INCLUDES = AC_INCLUDES_DEFAULT])
5340 Check for the existence of each ‘AGGREGATE.MEMBER’ of MEMBERS using
5341 the previous macro. When MEMBER belongs to AGGREGATE, define
5342 ‘HAVE_AGGREGATE_MEMBER’ (in all capitals, with spaces and dots
5343 replaced by underscores). If ACTION-IF-FOUND is given, it is
5344 executed for each of the found members. If ACTION-IF-NOT-FOUND is
5345 given, it is executed for each of the members that could not be
5346 found.
5347
5348 INCLUDES is a series of include directives, defaulting to
5349 ‘AC_INCLUDES_DEFAULT’ (*note Default Includes::), which are used
5350 prior to the members under test.
5351
5352 This macro uses M4 lists:
5353 AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize])
5354
5355 
5356 File: autoconf.info, Node: Types, Next: Compilers and Preprocessors, Prev: Structures, Up: Existing Tests
5357
5358 5.9 Types
5359 =========
5360
5361 The following macros check for C types, either builtin or typedefs. If
5362 there is no macro specifically defined to check for a type you need, and
5363 you don’t need to check for any special properties of it, then you can
5364 use a general type-check macro.
5365
5366 * Menu:
5367
5368 * Particular Types:: Special handling to find certain types
5369 * Generic Types:: How to find other types
5370
5371 
5372 File: autoconf.info, Node: Particular Types, Next: Generic Types, Up: Types
5373
5374 5.9.1 Particular Type Checks
5375 ----------------------------
5376
5377 These macros check for particular C types in ‘sys/types.h’, ‘stdlib.h’,
5378 ‘stdint.h’, ‘inttypes.h’ and others, if they exist.
5379
5380 The Gnulib ‘stdint’ module is an alternate way to define many of
5381 these symbols; it is useful if you prefer your code to assume a
5382 C99-or-better environment. *Note Gnulib::.
5383
5384 — Macro: AC_TYPE_GETGROUPS
5385 Define ‘GETGROUPS_T’ to be whichever of ‘gid_t’ or ‘int’ is the
5386 base type of the array argument to ‘getgroups’.
5387
5388 This macro caches the base type in the ‘ac_cv_type_getgroups’
5389 variable.
5390
5391 — Macro: AC_TYPE_INT8_T
5392 If ‘stdint.h’ or ‘inttypes.h’ does not define the type ‘int8_t’,
5393 define ‘int8_t’ to a signed integer type that is exactly 8 bits
5394 wide and that uses two’s complement representation, if such a type
5395 exists. If you are worried about porting to hosts that lack such a
5396 type, you can use the results of this macro as follows:
5397
5398 #if HAVE_STDINT_H
5399 # include <stdint.h>
5400 #endif
5401 #if defined INT8_MAX || defined int8_t
5402 _code using int8_t_
5403 #else
5404 _complicated alternative using >8-bit 'signed char'_
5405 #endif
5406
5407 This macro caches the type in the ‘ac_cv_c_int8_t’ variable.
5408
5409 — Macro: AC_TYPE_INT16_T
5410 This is like ‘AC_TYPE_INT8_T’, except for 16-bit integers.
5411
5412 — Macro: AC_TYPE_INT32_T
5413 This is like ‘AC_TYPE_INT8_T’, except for 32-bit integers.
5414
5415 — Macro: AC_TYPE_INT64_T
5416 This is like ‘AC_TYPE_INT8_T’, except for 64-bit integers.
5417
5418 — Macro: AC_TYPE_INTMAX_T
5419 If ‘stdint.h’ or ‘inttypes.h’ defines the type ‘intmax_t’, define
5420 ‘HAVE_INTMAX_T’. Otherwise, define ‘intmax_t’ to the widest signed
5421 integer type.
5422
5423 — Macro: AC_TYPE_INTPTR_T
5424 If ‘stdint.h’ or ‘inttypes.h’ defines the type ‘intptr_t’, define
5425 ‘HAVE_INTPTR_T’. Otherwise, define ‘intptr_t’ to a signed integer
5426 type wide enough to hold a pointer, if such a type exists.
5427
5428 — Macro: AC_TYPE_LONG_DOUBLE
5429 If the C compiler supports a working ‘long double’ type, define
5430 ‘HAVE_LONG_DOUBLE’. The ‘long double’ type might have the same
5431 range and precision as ‘double’.
5432
5433 This macro caches its result in the ‘ac_cv_type_long_double’
5434 variable.
5435
5436 This macro is obsolescent, as current C compilers support ‘long
5437 double’. New programs need not use this macro.
5438
5439 — Macro: AC_TYPE_LONG_DOUBLE_WIDER
5440 If the C compiler supports a working ‘long double’ type with more
5441 range or precision than the ‘double’ type, define
5442 ‘HAVE_LONG_DOUBLE_WIDER’.
5443
5444 This macro caches its result in the ‘ac_cv_type_long_double_wider’
5445 variable.
5446
5447 — Macro: AC_TYPE_LONG_LONG_INT
5448 If the C compiler supports a working ‘long long int’ type, define
5449 ‘HAVE_LONG_LONG_INT’. However, this test does not test ‘long long
5450 int’ values in preprocessor ‘#if’ expressions, because too many
5451 compilers mishandle such expressions. *Note Preprocessor
5452 Arithmetic::.
5453
5454 This macro caches its result in the ‘ac_cv_type_long_long_int’
5455 variable.
5456
5457 — Macro: AC_TYPE_MBSTATE_T
5458 Define ‘HAVE_MBSTATE_T’ if ‘<wchar.h>’ declares the ‘mbstate_t’
5459 type. Also, define ‘mbstate_t’ to be a type if ‘<wchar.h>’ does
5460 not declare it.
5461
5462 This macro caches its result in the ‘ac_cv_type_mbstate_t’
5463 variable.
5464
5465 — Macro: AC_TYPE_MODE_T
5466 Define ‘mode_t’ to a suitable type, if standard headers do not
5467 define it.
5468
5469 This macro caches its result in the ‘ac_cv_type_mode_t’ variable.
5470
5471 — Macro: AC_TYPE_OFF_T
5472 Define ‘off_t’ to a suitable type, if standard headers do not
5473 define it.
5474
5475 This macro caches its result in the ‘ac_cv_type_off_t’ variable.
5476
5477 — Macro: AC_TYPE_PID_T
5478 Define ‘pid_t’ to a suitable type, if standard headers do not
5479 define it.
5480
5481 This macro caches its result in the ‘ac_cv_type_pid_t’ variable.
5482
5483 — Macro: AC_TYPE_SIZE_T
5484 Define ‘size_t’ to a suitable type, if standard headers do not
5485 define it.
5486
5487 This macro caches its result in the ‘ac_cv_type_size_t’ variable.
5488
5489 — Macro: AC_TYPE_SSIZE_T
5490 Define ‘ssize_t’ to a suitable type, if standard headers do not
5491 define it.
5492
5493 This macro caches its result in the ‘ac_cv_type_ssize_t’ variable.
5494
5495 — Macro: AC_TYPE_UID_T
5496 Define ‘uid_t’ and ‘gid_t’ to suitable types, if standard headers
5497 do not define them.
5498
5499 This macro caches its result in the ‘ac_cv_type_uid_t’ variable.
5500
5501 — Macro: AC_TYPE_UINT8_T
5502 If ‘stdint.h’ or ‘inttypes.h’ does not define the type ‘uint8_t’,
5503 define ‘uint8_t’ to an unsigned integer type that is exactly 8 bits
5504 wide, if such a type exists. This is like ‘AC_TYPE_INT8_T’, except
5505 for unsigned integers.
5506
5507 — Macro: AC_TYPE_UINT16_T
5508 This is like ‘AC_TYPE_UINT8_T’, except for 16-bit integers.
5509
5510 — Macro: AC_TYPE_UINT32_T
5511 This is like ‘AC_TYPE_UINT8_T’, except for 32-bit integers.
5512
5513 — Macro: AC_TYPE_UINT64_T
5514 This is like ‘AC_TYPE_UINT8_T’, except for 64-bit integers.
5515
5516 — Macro: AC_TYPE_UINTMAX_T
5517 If ‘stdint.h’ or ‘inttypes.h’ defines the type ‘uintmax_t’, define
5518 ‘HAVE_UINTMAX_T’. Otherwise, define ‘uintmax_t’ to the widest
5519 unsigned integer type.
5520
5521 — Macro: AC_TYPE_UINTPTR_T
5522 If ‘stdint.h’ or ‘inttypes.h’ defines the type ‘uintptr_t’, define
5523 ‘HAVE_UINTPTR_T’. Otherwise, define ‘uintptr_t’ to an unsigned
5524 integer type wide enough to hold a pointer, if such a type exists.
5525
5526 — Macro: AC_TYPE_UNSIGNED_LONG_LONG_INT
5527 If the C compiler supports a working ‘unsigned long long int’ type,
5528 define ‘HAVE_UNSIGNED_LONG_LONG_INT’. However, this test does not
5529 test ‘unsigned long long int’ values in preprocessor ‘#if’
5530 expressions, because too many compilers mishandle such expressions.
5531 *Note Preprocessor Arithmetic::.
5532
5533 This macro caches its result in the
5534 ‘ac_cv_type_unsigned_long_long_int’ variable.
5535
5536 
5537 File: autoconf.info, Node: Generic Types, Prev: Particular Types, Up: Types
5538
5539 5.9.2 Generic Type Checks
5540 -------------------------
5541
5542 These macros are used to check for types not covered by the “particular”
5543 test macros.
5544
5545 — Macro: AC_CHECK_TYPE(TYPE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
5546 [INCLUDES = AC_INCLUDES_DEFAULT])
5547 Check whether TYPE is defined. It may be a compiler builtin type
5548 or defined by the INCLUDES. INCLUDES is a series of include
5549 directives, defaulting to ‘AC_INCLUDES_DEFAULT’ (*note Default
5550 Includes::), which are used prior to the type under test.
5551
5552 In C, TYPE must be a type-name, so that the expression ‘sizeof
5553 (TYPE)’ is valid (but ‘sizeof ((TYPE))’ is not). The same test is
5554 applied when compiling for C++, which means that in C++ TYPE should
5555 be a type-id and should not be an anonymous ‘struct’ or ‘union’.
5556
5557 This macro caches its result in the ‘ac_cv_type_TYPE’ variable,
5558 with ‘*’ mapped to ‘p’ and other characters not suitable for a
5559 variable name mapped to underscores.
5560
5561 — Macro: AC_CHECK_TYPES(TYPES, [ACTION-IF-FOUND],
5562 [ACTION-IF-NOT-FOUND], [INCLUDES = AC_INCLUDES_DEFAULT])
5563 For each TYPE of the TYPES that is defined, define ‘HAVE_TYPE’ (in
5564 all capitals). Each TYPE must follow the rules of ‘AC_CHECK_TYPE’.
5565 If no INCLUDES are specified, the default includes are used (*note
5566 Default Includes::). If ACTION-IF-FOUND is given, it is additional
5567 shell code to execute when one of the types is found. If
5568 ACTION-IF-NOT-FOUND is given, it is executed when one of the types
5569 is not found.
5570
5571 This macro uses M4 lists:
5572 AC_CHECK_TYPES([ptrdiff_t])
5573 AC_CHECK_TYPES([unsigned long long int, uintmax_t])
5574 AC_CHECK_TYPES([float_t], [], [], [[#include <math.h>]])
5575
5576 Autoconf, up to 2.13, used to provide to another version of
5577 ‘AC_CHECK_TYPE’, broken by design. In order to keep backward
5578 compatibility, a simple heuristic, quite safe but not totally, is
5579 implemented. In case of doubt, read the documentation of the former
5580 ‘AC_CHECK_TYPE’, see *note Obsolete Macros::.
5581
5582 
5583 File: autoconf.info, Node: Compilers and Preprocessors, Next: System Services, Prev: Types, Up: Existing Tests
5584
5585 5.10 Compilers and Preprocessors
5586 ================================
5587
5588 All the tests for compilers (‘AC_PROG_CC’, ‘AC_PROG_CXX’, ‘AC_PROG_F77’)
5589 define the output variable ‘EXEEXT’ based on the output of the compiler,
5590 typically to the empty string if POSIX and ‘.exe’ if a DOS variant.
5591
5592 They also define the output variable ‘OBJEXT’ based on the output of
5593 the compiler, after ‘.c’ files have been excluded, typically to ‘o’ if
5594 POSIX, ‘obj’ if a DOS variant.
5595
5596 If the compiler being used does not produce executables, the tests
5597 fail. If the executables can’t be run, and cross-compilation is not
5598 enabled, they fail too. *Note Manual Configuration::, for more on
5599 support for cross compiling.
5600
5601 * Menu:
5602
5603 * Specific Compiler Characteristics:: Some portability issues
5604 * Generic Compiler Characteristics:: Language independent tests and features
5605 * C Compiler:: Checking its characteristics
5606 * C++ Compiler:: Likewise
5607 * Objective C Compiler:: Likewise
5608 * Objective C++ Compiler:: Likewise
5609 * Erlang Compiler and Interpreter:: Likewise
5610 * Fortran Compiler:: Likewise
5611 * Go Compiler:: Likewise
5612 * Algol 68 Compiler:: Likewise
5613
5614 
5615 File: autoconf.info, Node: Specific Compiler Characteristics, Next: Generic Compiler Characteristics, Up: Compilers and Preprocessors
5616
5617 5.10.1 Specific Compiler Characteristics
5618 ----------------------------------------
5619
5620 Some compilers exhibit different behaviors.
5621
5622 Static/Dynamic Expressions
5623 Autoconf relies on a trick to extract one bit of information from
5624 the C compiler: using negative array sizes. For instance the
5625 following excerpt of a C source demonstrates how to test whether
5626 ‘int’ objects are 4 bytes wide:
5627
5628 static int test_array[sizeof (int) == 4 ? 1 : -1];
5629
5630 To our knowledge, there is a single compiler that does not support
5631 this trick: the HP C compilers (the real ones, not only the
5632 “bundled”) on HP-UX 11.00. They incorrectly reject the above
5633 program with the diagnostic “Variable-length arrays cannot have
5634 static storage.” This bug comes from HP compilers’ mishandling of
5635 ‘sizeof (int)’, not from the ‘? 1 : -1’, and Autoconf works around
5636 this problem by casting ‘sizeof (int)’ to ‘long int’ before
5637 comparing it.
5638
5639 
5640 File: autoconf.info, Node: Generic Compiler Characteristics, Next: C Compiler, Prev: Specific Compiler Characteristics, Up: Compilers and Preprocessors
5641
5642 5.10.2 Generic Compiler Characteristics
5643 ---------------------------------------
5644
5645 — Macro: AC_CHECK_SIZEOF(TYPE-OR-EXPR, [UNUSED], [INCLUDES =
5646 AC_INCLUDES_DEFAULT])
5647 Define ‘SIZEOF_TYPE-OR-EXPR’ (*note Standard Symbols::) to be the
5648 size in bytes of TYPE-OR-EXPR, which may be either a type or an
5649 expression returning a value that has a size. If the expression
5650 ‘sizeof (TYPE-OR-EXPR)’ is invalid, the result is 0. INCLUDES is a
5651 series of include directives, defaulting to ‘AC_INCLUDES_DEFAULT’
5652 (*note Default Includes::), which are used prior to the expression
5653 under test.
5654
5655 This macro now works even when cross-compiling. The UNUSED
5656 argument was used when cross-compiling.
5657
5658 For example, the call
5659
5660 AC_CHECK_SIZEOF([int *])
5661
5662 defines ‘SIZEOF_INT_P’ to be 8 on x86-64 systems.
5663
5664 This macro caches its result in the ‘ac_cv_sizeof_TYPE-OR-EXPR’
5665 variable, with ‘*’ mapped to ‘p’ and other characters not suitable
5666 for a variable name mapped to underscores.
5667
5668 — Macro: AC_CHECK_ALIGNOF(TYPE, [INCLUDES = AC_INCLUDES_DEFAULT])
5669 Define ‘ALIGNOF_TYPE’ (*note Standard Symbols::) to be the
5670 alignment in bytes of TYPE. ‘TYPE y;’ must be valid as a structure
5671 member declaration. If ‘type’ is unknown, the result is 0. If no
5672 INCLUDES are specified, the default includes are used (*note
5673 Default Includes::).
5674
5675 This macro caches its result in the ‘ac_cv_alignof_TYPE-OR-EXPR’
5676 variable, with ‘*’ mapped to ‘p’ and other characters not suitable
5677 for a variable name mapped to underscores.
5678
5679 — Macro: AC_COMPUTE_INT(VAR, EXPRESSION, [INCLUDES =
5680 AC_INCLUDES_DEFAULT], [ACTION-IF-FAILS])
5681 Store into the shell variable VAR the value of the integer
5682 EXPRESSION. The value should fit in an initializer in a C variable
5683 of type ‘signed long’. To support cross compilation, it should be
5684 possible to evaluate the expression at compile-time. If no
5685 INCLUDES are specified, the default includes are used (*note
5686 Default Includes::).
5687
5688 Execute ACTION-IF-FAILS if the value cannot be determined
5689 correctly.
5690
5691 — Macro: AC_LANG_WERROR
5692 Normally Autoconf ignores warnings generated by the compiler,
5693 linker, and preprocessor. If this macro is used, warnings count as
5694 fatal errors for the current language. This macro is useful when
5695 the results of configuration are used where warnings are
5696 unacceptable; for instance, if parts of a program are built with
5697 the GCC ‘-Werror’ option. If the whole program is built using
5698 ‘-Werror’ it is often simpler to put ‘-Werror’ in the compiler
5699 flags (‘CFLAGS’, etc.).
5700
5701 — Macro: AC_OPENMP
5702 OpenMP (https://www.openmp.org/) specifies extensions of C, C++,
5703 and Fortran that simplify optimization of shared memory
5704 parallelism, which is a common problem on multi-core CPUs.
5705
5706 If the current language is C, the macro ‘AC_OPENMP’ sets the
5707 variable ‘OPENMP_CFLAGS’ to the C compiler flags needed for
5708 supporting OpenMP. ‘OPENMP_CFLAGS’ is set to empty if the compiler
5709 already supports OpenMP, if it has no way to activate OpenMP
5710 support, or if the user rejects OpenMP support by invoking
5711 ‘configure’ with the ‘--disable-openmp’ option.
5712
5713 ‘OPENMP_CFLAGS’ needs to be used when compiling programs, when
5714 preprocessing program source, and when linking programs. Therefore
5715 you need to add ‘$(OPENMP_CFLAGS)’ to the ‘CFLAGS’ of C programs
5716 that use OpenMP. If you preprocess OpenMP-specific C code, you
5717 also need to add ‘$(OPENMP_CFLAGS)’ to ‘CPPFLAGS’. The presence of
5718 OpenMP support is revealed at compile time by the preprocessor
5719 macro ‘_OPENMP’.
5720
5721 Linking a program with ‘OPENMP_CFLAGS’ typically adds one more
5722 shared library to the program’s dependencies, so its use is
5723 recommended only on programs that actually require OpenMP.
5724
5725 If the current language is C++, ‘AC_OPENMP’ sets the variable
5726 ‘OPENMP_CXXFLAGS’, suitably for the C++ compiler. The same remarks
5727 hold as for C.
5728
5729 If the current language is Fortran 77 or Fortran, ‘AC_OPENMP’ sets
5730 the variable ‘OPENMP_FFLAGS’ or ‘OPENMP_FCFLAGS’, respectively.
5731 Similar remarks as for C hold, except that ‘CPPFLAGS’ is not used
5732 for Fortran, and no preprocessor macro signals OpenMP support.
5733
5734 For portability, it is best to avoid spaces between ‘#’ and ‘pragma
5735 omp’. That is, write ‘#pragma omp’, not ‘# pragma omp’. The Sun
5736 WorkShop 6.2 C compiler chokes on the latter.
5737
5738 This macro caches its result in the ‘ac_cv_prog_c_openmp’,
5739 ‘ac_cv_prog_cxx_openmp’, ‘ac_cv_prog_f77_openmp’, or
5740 ‘ac_cv_prog_fc_openmp’ variable, depending on the current language.
5741
5742 *Caution:* Some of the compiler options that ‘AC_OPENMP’ tests,
5743 mean “enable OpenMP” to one compiler, but “write output to a file
5744 named ‘mp’ or ‘penmp’” to other compilers. We cannot guarantee
5745 that the implementation of ‘AC_OPENMP’ will not overwrite an
5746 existing file with either of these names.
5747
5748 Therefore, as a defensive measure, a ‘configure’ script that uses
5749 ‘AC_OPENMP’ will issue an error and stop (before doing any of the
5750 operations that might overwrite these files) upon encountering
5751 either of these files in its working directory. ‘autoconf’ will
5752 also issue an error if it finds either of these files in the same
5753 directory as a ‘configure.ac’ that uses ‘AC_OPENMP’.
5754
5755 If you have files with either of these names at the top level of
5756 your source tree, and you need to use ‘AC_OPENMP’, we recommend you
5757 either change their names or move them into a subdirectory.
5758
5759 
5760 File: autoconf.info, Node: C Compiler, Next: C++ Compiler, Prev: Generic Compiler Characteristics, Up: Compilers and Preprocessors
5761
5762 5.10.3 C Compiler Characteristics
5763 ---------------------------------
5764
5765 The following macros provide ways to find and exercise a C Compiler.
5766 There are a few constructs that ought to be avoided, but do not deserve
5767 being checked for, since they can easily be worked around.
5768
5769 Don’t use lines containing solitary backslashes
5770 They tickle a bug in the HP-UX C compiler (checked on HP-UX 10.20,
5771 11.00, and 11i). When given the following source:
5772
5773 #ifdef __STDC__
5774 /\
5775 * A comment with backslash-newlines in it. %{ %} *\
5776 \
5777 /
5778 char str[] = "\\
5779 " A string with backslash-newlines in it %{ %} \\
5780 "";
5781 char apostrophe = '\\
5782 \
5783 '\
5784 ';
5785 #endif
5786
5787 the compiler incorrectly fails with the diagnostics
5788 “Non-terminating comment at end of file” and “Missing ‘#endif’ at
5789 end of file.” Removing the lines with solitary backslashes solves
5790 the problem.
5791
5792 Don’t compile several files at once if output matters to you
5793 Some compilers, such as HP’s, report names of files being compiled
5794 when given more than one file operand. For instance:
5795
5796 $ cc a.c b.c
5797 a.c:
5798 b.c:
5799
5800 This can cause problems if you observe the output of the compiler
5801 to detect failures. Invoking ‘cc -c a.c && cc -c b.c && cc -o c
5802 a.o b.o’ solves the issue.
5803
5804 Don’t rely on correct ‘#line’ support
5805 On Solaris, ‘c89’ (at least through Oracle Developer Studio 12.6)
5806 diagnoses ‘#line’ directives whose line numbers are greater than
5807 32767. Nothing in POSIX makes this invalid. That is why Autoconf
5808 stopped issuing ‘#line’ directives.
5809
5810 — Macro: AC_PROG_CC([COMPILER-SEARCH-LIST])
5811 Determine a C compiler to use.
5812
5813 If the environment variable ‘CC’ is set, its value will be taken as
5814 the name of the C compiler to use. Otherwise, search for a C
5815 compiler under a series of likely names, trying ‘gcc’ and ‘cc’
5816 first. Regardless, the output variable ‘CC’ is set to the chosen
5817 compiler.
5818
5819 If the optional first argument to the macro is used, it must be a
5820 whitespace-separated list of potential names for a C compiler,
5821 which overrides the built-in list.
5822
5823 If no C compiler can be found, ‘configure’ will error out.
5824
5825 If the selected C compiler is found to be GNU C (regardless of its
5826 name), the shell variable ‘GCC’ will be set to ‘yes’. If the shell
5827 variable ‘CFLAGS’ was not already set, it is set to ‘-g -O2’ for
5828 the GNU C compiler (‘-O2’ on systems where GCC does not accept
5829 ‘-g’), or ‘-g’ for other compilers. ‘CFLAGS’ is then made an
5830 output variable. You can override the default for ‘CFLAGS’ by
5831 inserting a shell default assignment between ‘AC_INIT’ and
5832 ‘AC_PROG_CC’:
5833
5834 : ${CFLAGS="OPTIONS"}
5835
5836 where OPTIONS are the appropriate set of options to use by default.
5837 (It is important to use this construct rather than a normal
5838 assignment, so that ‘CFLAGS’ can still be overridden by the person
5839 building the package. *Note Preset Output Variables::.)
5840
5841 If necessary, options are added to ‘CC’ to enable support for ISO
5842 Standard C features with extensions, preferring the newest edition
5843 of the C standard for which detection is supported. Currently the
5844 newest edition Autoconf knows how to detect support for is C23.
5845 After calling this macro you can check whether the C compiler has
5846 been set to accept standard C by inspecting the shell variable
5847 ‘ac_prog_cc_stdc’. Its value is ‘c23’, ‘c11’, ‘c99’, or ‘c89’,
5848 respectively, if the C compiler has been set to use the 2023, 2011,
5849 1999, or 1990 edition of the C standard, and ‘no’ if the compiler
5850 does not support compiling standard C at all. (There is no special
5851 value for the 2017 edition of the C standard, as it is a minor
5852 revision that does not introduce new language features.)
5853
5854 The tests for standard conformance are not comprehensive. They
5855 test the value of ‘__STDC_VERSION__’, and a representative sample
5856 of the language features added in each version of the C standard.
5857 They do not examine ‘__STDC__’ because some compilers by default
5858 leave it undefined. They do not test for variable-length arrays, a
5859 C99 feature that was made optional in C11; if you need to use this
5860 feature when available, use ‘AC_C_VARARRAYS’. They do not test the
5861 C standard library, because the C compiler might be generating code
5862 for a “freestanding environment” (in which most of the standard
5863 library is optional). If you need to know whether a particular C
5864 standard header exists, use ‘AC_CHECK_HEADER’.
5865
5866 None of the options that may be added to ‘CC’ by this macro enable
5867 _strict_ conformance to the C standard. In particular,
5868 system-specific extensions are not disabled. (For example, for GNU
5869 C, the ‘-std=gnuNN’ options may be used, but not the ‘-std=cNN’
5870 options.)
5871
5872 Many Autoconf macros use a compiler, and thus call
5873 ‘AC_REQUIRE([AC_PROG_CC])’ to ensure that the compiler has been
5874 determined before the body of the outermost ‘AC_DEFUN’ macro.
5875 Although ‘AC_PROG_CC’ is safe to directly expand multiple times, it
5876 performs certain checks (such as the proper value of ‘EXEEXT’) only
5877 on the first invocation. Therefore, care must be used when
5878 invoking this macro from within another macro rather than at the
5879 top level (*note Expanded Before Required::).
5880
5881 — Macro: AC_PROG_CC_C_O
5882 If the C compiler does not accept the ‘-c’ and ‘-o’ options
5883 simultaneously, define ‘NO_MINUS_C_MINUS_O’. This macro actually
5884 tests both the compiler found by ‘AC_PROG_CC’, and, if different,
5885 the first ‘cc’ in the path. The test fails if one fails. This
5886 macro was created for GNU Make to choose the default C compilation
5887 rule.
5888
5889 For the compiler COMPILER, this macro caches its result in the
5890 ‘ac_cv_prog_cc_COMPILER_c_o’ variable.
5891
5892 — Macro: AC_PROG_CPP
5893 Set output variable ‘CPP’ to a command that runs the C
5894 preprocessor. If ‘$CC -E’ doesn’t work, tries ‘cpp’ and
5895 ‘/lib/cpp’, in that order.
5896
5897 It is only portable to run ‘CPP’ on files with a ‘.c’ extension.
5898
5899 Some preprocessors don’t indicate missing include files by the
5900 error status. For such preprocessors an internal variable is set
5901 that causes other macros to check the standard error from the
5902 preprocessor and consider the test failed if any warnings have been
5903 reported. For most preprocessors, though, warnings do not cause
5904 include-file tests to fail unless ‘AC_PROG_CPP_WERROR’ is also
5905 specified.
5906
5907 — Macro: AC_PROG_CPP_WERROR
5908 This acts like ‘AC_PROG_CPP’, except it treats warnings from the
5909 preprocessor as errors even if the preprocessor exit status
5910 indicates success. This is useful for avoiding headers that
5911 generate mandatory warnings, such as deprecation notices.
5912
5913 The following macros check for C compiler or machine architecture
5914 features. To check for characteristics not listed here, use
5915 ‘AC_COMPILE_IFELSE’ (*note Running the Compiler::) or ‘AC_RUN_IFELSE’
5916 (*note Runtime::).
5917
5918 — Macro: AC_C_BACKSLASH_A
5919 Define ‘HAVE_C_BACKSLASH_A’ to 1 if the C compiler understands
5920 ‘\a’.
5921
5922 This macro is obsolescent, as current C compilers understand ‘\a’.
5923 New programs need not use this macro.
5924
5925 — Macro: AC_C_BIGENDIAN([ACTION-IF-TRUE], [ACTION-IF-FALSE],
5926 [ACTION-IF-UNKNOWN], [ACTION-IF-UNIVERSAL])
5927 If words are stored with the most significant byte first (like
5928 Motorola and SPARC CPUs), execute ACTION-IF-TRUE. If words are
5929 stored with the least significant byte first (like Intel and VAX
5930 CPUs), execute ACTION-IF-FALSE.
5931
5932 This macro runs a test-case if endianness cannot be determined from
5933 the system header files. When cross-compiling, the test-case is
5934 not run but grep’ed for some magic values. ACTION-IF-UNKNOWN is
5935 executed if the latter case fails to determine the byte sex of the
5936 host system.
5937
5938 In some cases a single run of a compiler can generate code for
5939 multiple architectures. This can happen, for example, when
5940 generating Mac OS X universal binary files, which work on both
5941 PowerPC and Intel architectures. In this case, the different
5942 variants might be for architectures with differing endianness. If
5943 ‘configure’ detects this, it executes ACTION-IF-UNIVERSAL instead
5944 of ACTION-IF-UNKNOWN.
5945
5946 The default for ACTION-IF-TRUE is to define ‘WORDS_BIGENDIAN’. The
5947 default for ACTION-IF-FALSE is to do nothing. The default for
5948 ACTION-IF-UNKNOWN is to abort configure and tell the installer how
5949 to bypass this test. And finally, the default for
5950 ACTION-IF-UNIVERSAL is to ensure that ‘WORDS_BIGENDIAN’ is defined
5951 if and only if a universal build is detected and the current code
5952 is big-endian; this default works only if ‘autoheader’ is used
5953 (*note autoheader Invocation::).
5954
5955 If you use this macro without specifying ACTION-IF-UNIVERSAL, you
5956 should also use ‘AC_CONFIG_HEADERS’; otherwise ‘WORDS_BIGENDIAN’
5957 may be set incorrectly for Mac OS X universal binary files.
5958
5959 — Macro: AC_C_CONST
5960 If the C compiler does not fully support the ‘const’ keyword,
5961 define ‘const’ to be empty. Some C compilers that do not define
5962 ‘__STDC__’ do support ‘const’; some compilers that define
5963 ‘__STDC__’ do not completely support ‘const’. Programs can simply
5964 use ‘const’ as if every C compiler supported it; for those that
5965 don’t, the makefile or configuration header file defines it as
5966 empty.
5967
5968 Occasionally installers use a C++ compiler to compile C code,
5969 typically because they lack a C compiler. This causes problems
5970 with ‘const’, because C and C++ treat ‘const’ differently. For
5971 example:
5972
5973 const int foo;
5974
5975 is valid in C but not in C++. These differences unfortunately
5976 cannot be papered over by defining ‘const’ to be empty.
5977
5978 If ‘autoconf’ detects this situation, it leaves ‘const’ alone, as
5979 this generally yields better results in practice. However, using a
5980 C++ compiler to compile C code is not recommended or supported, and
5981 installers who run into trouble in this area should get a C
5982 compiler like GCC to compile their C code.
5983
5984 This macro caches its result in the ‘ac_cv_c_const’ variable.
5985
5986 This macro is obsolescent, as current C compilers support ‘const’.
5987 New programs need not use this macro.
5988
5989 — Macro: AC_C__GENERIC
5990 If the C compiler supports C11-style generic selection using the
5991 ‘_Generic’ keyword, define ‘HAVE_C__GENERIC’.
5992
5993 — Macro: AC_C_RESTRICT
5994 If the C compiler recognizes a variant spelling for the ‘restrict’
5995 keyword (‘__restrict’, ‘__restrict__’, or ‘_Restrict’), then define
5996 ‘restrict’ to that; this is more likely to do the right thing with
5997 compilers that support language variants where plain ‘restrict’ is
5998 not a keyword. Otherwise, if the C compiler recognizes the
5999 ‘restrict’ keyword, don’t do anything. Otherwise, define
6000 ‘restrict’ to be empty. Thus, programs may simply use ‘restrict’
6001 as if every C compiler supported it; for those that do not, the
6002 makefile or configuration header defines it away.
6003
6004 Although support in C++ for the ‘restrict’ keyword is not required,
6005 several C++ compilers do accept the keyword. This macro works for
6006 them, too.
6007
6008 This macro caches ‘no’ in the ‘ac_cv_c_restrict’ variable if
6009 ‘restrict’ is not supported, and a supported spelling otherwise.
6010
6011 — Macro: AC_C_VOLATILE
6012 If the C compiler does not understand the keyword ‘volatile’,
6013 define ‘volatile’ to be empty. Programs can simply use ‘volatile’
6014 as if every C compiler supported it; for those that do not, the
6015 makefile or configuration header defines it as empty.
6016
6017 If the correctness of your program depends on the semantics of
6018 ‘volatile’, simply defining it to be empty does, in a sense, break
6019 your code. However, given that the compiler does not support
6020 ‘volatile’, you are at its mercy anyway. At least your program
6021 compiles, when it wouldn’t before. *Note Volatile Objects::, for
6022 more about ‘volatile’.
6023
6024 This macro is obsolescent, as current C compilers support
6025 ‘volatile’. New programs need not use this macro.
6026
6027 — Macro: AC_C_INLINE
6028 If the C compiler supports the keyword ‘inline’, do nothing.
6029 Otherwise define ‘inline’ to ‘__inline__’ or ‘__inline’ if it
6030 accepts one of those, otherwise define ‘inline’ to be empty.
6031
6032 — Macro: AC_C_CHAR_UNSIGNED
6033 If the C type ‘char’ is unsigned, define ‘__CHAR_UNSIGNED__’,
6034 unless the C compiler predefines it.
6035
6036 These days, using this macro is not necessary. The same
6037 information can be determined by this portable alternative, thus
6038 avoiding the use of preprocessor macros in the namespace reserved
6039 for the implementation.
6040
6041 #include <limits.h>
6042 #if CHAR_MIN == 0
6043 # define CHAR_UNSIGNED 1
6044 #endif
6045
6046 — Macro: AC_C_STRINGIZE
6047 If the C preprocessor supports the stringizing operator, define
6048 ‘HAVE_STRINGIZE’. The stringizing operator is ‘#’ and is found in
6049 macros such as this:
6050
6051 #define x(y) #y
6052
6053 This macro is obsolescent, as current C compilers support the
6054 stringizing operator. New programs need not use this macro.
6055
6056 — Macro: AC_C_FLEXIBLE_ARRAY_MEMBER
6057 If the C compiler supports flexible array members, define
6058 ‘FLEXIBLE_ARRAY_MEMBER’ to nothing; otherwise define it to 1. That
6059 way, a declaration like this:
6060
6061 struct s
6062 {
6063 size_t n_vals;
6064 double val[FLEXIBLE_ARRAY_MEMBER];
6065 };
6066
6067 will let applications use the “struct hack” even with compilers
6068 that do not support flexible array members. To allocate and use
6069 such an object, you can use code like this:
6070
6071 size_t i;
6072 size_t n = compute_value_count ();
6073 struct s *p =
6074 malloc (offsetof (struct s, val)
6075 + n * sizeof (double));
6076 p->n_vals = n;
6077 for (i = 0; i < n; i++)
6078 p->val[i] = compute_value (i);
6079
6080 — Macro: AC_C_VARARRAYS
6081 If the C compiler does not support variable-length arrays, define
6082 the macro ‘__STDC_NO_VLA__’ to be 1 if it is not already defined.
6083 A variable-length array is an array of automatic storage duration
6084 whose length is determined at run time, when the array is declared.
6085 For backward compatibility this macro also defines
6086 ‘HAVE_C_VARARRAYS’ if the C compiler supports variable-length
6087 arrays, but this usage is obsolescent and new programs should use
6088 ‘__STDC_NO_VLA__’.
6089
6090 — Macro: AC_C_TYPEOF
6091 If the C compiler supports GNU C’s ‘typeof’ syntax either directly
6092 or through a different spelling of the keyword (e.g.,
6093 ‘__typeof__’), define ‘HAVE_TYPEOF’. If the support is available
6094 only through a different spelling, define ‘typeof’ to that
6095 spelling.
6096
6097 — Macro: AC_C_PROTOTYPES
6098 If function prototypes are understood by the compiler (as
6099 determined by ‘AC_PROG_CC’), define ‘PROTOTYPES’ and
6100 ‘__PROTOTYPES’. Defining ‘__PROTOTYPES’ is for the benefit of
6101 header files that cannot use macros that infringe on user name
6102 space.
6103
6104 This macro is obsolescent, as current C compilers support
6105 prototypes. New programs need not use this macro.
6106
6107 
6108 File: autoconf.info, Node: C++ Compiler, Next: Objective C Compiler, Prev: C Compiler, Up: Compilers and Preprocessors
6109
6110 5.10.4 C++ Compiler Characteristics
6111 -----------------------------------
6112
6113 — Macro: AC_PROG_CXX([COMPILER-SEARCH-LIST])
6114 Determine a C++ compiler to use.
6115
6116 If either the environment variable ‘CXX’ or the environment
6117 variable ‘CCC’ is set, its value will be taken as the name of a C++
6118 compiler. If both are set, ‘CXX’ is preferred. If neither are
6119 set, search for a C++ compiler under a series of likely names,
6120 trying ‘g++’ and ‘c++’ first. Regardless, the output variable
6121 ‘CXX’ is set to the chosen compiler.
6122
6123 If the optional first argument to the macro is used, it must be a
6124 whitespace-separated list of potential names for a C++ compiler,
6125 which overrides the built-in list.
6126
6127 If no C++ compiler can be found, as a last resort ‘CXX’ is set to
6128 ‘g++’ (and subsequent tests will probably fail).
6129
6130 If the selected C++ compiler is found to be GNU C++ (regardless of
6131 its name), the shell variable ‘GXX’ will be set to ‘yes’. If the
6132 shell variable ‘CXXFLAGS’ was not already set, it is set to ‘-g
6133 -O2’ for the GNU C++ compiler (‘-O2’ on systems where G++ does not
6134 accept ‘-g’), or ‘-g’ for other compilers. ‘CXXFLAGS’ is then made
6135 an output variable. You can override the default for ‘CXXFLAGS’ by
6136 inserting a shell default assignment between ‘AC_INIT’ and
6137 ‘AC_PROG_CXX’:
6138
6139 : ${CXXFLAGS="OPTIONS"}
6140
6141 where OPTIONS are the appropriate set of options to use by default.
6142 (It is important to use this construct rather than a normal
6143 assignment, so that ‘CXXFLAGS’ can still be overridden by the
6144 person building the package. *Note Preset Output Variables::.)
6145
6146 — Macro: AC_PROG_CXXCPP
6147 Set output variable ‘CXXCPP’ to a command that runs the C++
6148 preprocessor. If ‘$CXX -E’ doesn’t work, tries ‘cpp’ and
6149 ‘/lib/cpp’, in that order. Because of this fallback, ‘CXXCPP’ may
6150 or may not set C++-specific predefined macros (such as
6151 ‘__cplusplus’).
6152
6153 It is portable to run ‘CXXCPP’ only on files with a ‘.c’, ‘.C’,
6154 ‘.cc’, or ‘.cpp’ extension.
6155
6156 Some preprocessors don’t indicate missing include files by the
6157 error status. For such preprocessors an internal variable is set
6158 that causes other macros to check the standard error from the
6159 preprocessor and consider the test failed if any warnings have been
6160 reported. However, it is not known whether such broken
6161 preprocessors exist for C++.
6162
6163 — Macro: AC_PROG_CXX_C_O
6164 Test whether the C++ compiler accepts the options ‘-c’ and ‘-o’
6165 simultaneously, and define ‘CXX_NO_MINUS_C_MINUS_O’, if it does
6166 not.
6167
6168 
6169 File: autoconf.info, Node: Objective C Compiler, Next: Objective C++ Compiler, Prev: C++ Compiler, Up: Compilers and Preprocessors
6170
6171 5.10.5 Objective C Compiler Characteristics
6172 -------------------------------------------
6173
6174 — Macro: AC_PROG_OBJC([COMPILER-SEARCH-LIST])
6175 Determine an Objective C compiler to use. If ‘OBJC’ is not already
6176 set in the environment, check for Objective C compilers. Set
6177 output variable ‘OBJC’ to the name of the compiler found.
6178
6179 This macro may, however, be invoked with an optional first argument
6180 which, if specified, must be a blank-separated list of Objective C
6181 compilers to search for. This just gives the user an opportunity
6182 to specify an alternative search list for the Objective C compiler.
6183 For example, if you didn’t like the default order, then you could
6184 invoke ‘AC_PROG_OBJC’ like this:
6185
6186 AC_PROG_OBJC([gcc objcc objc])
6187
6188 If using a compiler that supports GNU Objective C, set shell
6189 variable ‘GOBJC’ to ‘yes’. If output variable ‘OBJCFLAGS’ was not
6190 already set, set it to ‘-g -O2’ for a GNU Objective C compiler
6191 (‘-O2’ on systems where the compiler does not accept ‘-g’), or ‘-g’
6192 for other compilers.
6193
6194 — Macro: AC_PROG_OBJCPP
6195 Set output variable ‘OBJCPP’ to a command that runs the Objective C
6196 preprocessor. If ‘$OBJC -E’ doesn’t work, tries ‘cpp’ and
6197 ‘/lib/cpp’, in that order. Because of this fallback, ‘CXXCPP’ may
6198 or may not set Objective-C-specific predefined macros (such as
6199 ‘__OBJC__’).
6200
6201 
6202 File: autoconf.info, Node: Objective C++ Compiler, Next: Erlang Compiler and Interpreter, Prev: Objective C Compiler, Up: Compilers and Preprocessors
6203
6204 5.10.6 Objective C++ Compiler Characteristics
6205 ---------------------------------------------
6206
6207 — Macro: AC_PROG_OBJCXX([COMPILER-SEARCH-LIST])
6208 Determine an Objective C++ compiler to use. If ‘OBJCXX’ is not
6209 already set in the environment, check for Objective C++ compilers.
6210 Set output variable ‘OBJCXX’ to the name of the compiler found.
6211
6212 This macro may, however, be invoked with an optional first argument
6213 which, if specified, must be a blank-separated list of Objective
6214 C++ compilers to search for. This just gives the user an
6215 opportunity to specify an alternative search list for the Objective
6216 C++ compiler. For example, if you didn’t like the default order,
6217 then you could invoke ‘AC_PROG_OBJCXX’ like this:
6218
6219 AC_PROG_OBJCXX([gcc g++ objcc++ objcxx])
6220
6221 If using a compiler that supports GNU Objective C++, set shell
6222 variable ‘GOBJCXX’ to ‘yes’. If output variable ‘OBJCXXFLAGS’ was
6223 not already set, set it to ‘-g -O2’ for a GNU Objective C++
6224 compiler (‘-O2’ on systems where the compiler does not accept
6225 ‘-g’), or ‘-g’ for other compilers.
6226
6227 — Macro: AC_PROG_OBJCXXCPP
6228 Set output variable ‘OBJCXXCPP’ to a command that runs the
6229 Objective C++ preprocessor. If ‘$OBJCXX -E’ doesn’t work, tries
6230 ‘cpp’ and ‘/lib/cpp’, in that order. Because of this fallback,
6231 ‘CXXCPP’ may or may not set Objective-C++-specific predefined
6232 macros (such as ‘__cplusplus’ and ‘__OBJC__’).
6233
6234 
6235 File: autoconf.info, Node: Erlang Compiler and Interpreter, Next: Fortran Compiler, Prev: Objective C++ Compiler, Up: Compilers and Preprocessors
6236
6237 5.10.7 Erlang Compiler and Interpreter Characteristics
6238 ------------------------------------------------------
6239
6240 Autoconf defines the following macros for determining paths to the
6241 essential Erlang/OTP programs:
6242
6243 — Macro: AC_ERLANG_PATH_ERLC([VALUE-IF-NOT-FOUND], [PATH = $PATH])
6244 Determine an Erlang compiler to use. If ‘ERLC’ is not already set
6245 in the environment, check for ‘erlc’. Set output variable ‘ERLC’
6246 to the complete path of the compiler command found. In addition,
6247 if ‘ERLCFLAGS’ is not set in the environment, set it to an empty
6248 value.
6249
6250 The two optional arguments have the same meaning as the two last
6251 arguments of macro ‘AC_PATH_PROG’ for looking for the ‘erlc’
6252 program. For example, to look for ‘erlc’ only in the
6253 ‘/usr/lib/erlang/bin’ directory:
6254
6255 AC_ERLANG_PATH_ERLC([not found], [/usr/lib/erlang/bin])
6256
6257 — Macro: AC_ERLANG_NEED_ERLC([PATH = $PATH])
6258 A simplified variant of the ‘AC_ERLANG_PATH_ERLC’ macro, that
6259 prints an error message and exits the ‘configure’ script if the
6260 ‘erlc’ program is not found.
6261
6262 — Macro: AC_ERLANG_PATH_ERL([VALUE-IF-NOT-FOUND], [PATH = $PATH])
6263 Determine an Erlang interpreter to use. If ‘ERL’ is not already
6264 set in the environment, check for ‘erl’. Set output variable ‘ERL’
6265 to the complete path of the interpreter command found.
6266
6267 The two optional arguments have the same meaning as the two last
6268 arguments of macro ‘AC_PATH_PROG’ for looking for the ‘erl’
6269 program. For example, to look for ‘erl’ only in the
6270 ‘/usr/lib/erlang/bin’ directory:
6271
6272 AC_ERLANG_PATH_ERL([not found], [/usr/lib/erlang/bin])
6273
6274 — Macro: AC_ERLANG_NEED_ERL([PATH = $PATH])
6275 A simplified variant of the ‘AC_ERLANG_PATH_ERL’ macro, that prints
6276 an error message and exits the ‘configure’ script if the ‘erl’
6277 program is not found.
6278
6279 
6280 File: autoconf.info, Node: Fortran Compiler, Next: Go Compiler, Prev: Erlang Compiler and Interpreter, Up: Compilers and Preprocessors
6281
6282 5.10.8 Fortran Compiler Characteristics
6283 ---------------------------------------
6284
6285 The Autoconf Fortran support is divided into two categories: legacy
6286 Fortran 77 macros (‘F77’), and modern Fortran macros (‘FC’). The former
6287 are intended for traditional Fortran 77 code, and have output variables
6288 like ‘F77’, ‘FFLAGS’, and ‘FLIBS’. The latter are for newer programs
6289 that can (or must) compile under the newer Fortran standards, and have
6290 output variables like ‘FC’, ‘FCFLAGS’, and ‘FCLIBS’.
6291
6292 Except for the macros ‘AC_FC_SRCEXT’, ‘AC_FC_FREEFORM’,
6293 ‘AC_FC_FIXEDFORM’, and ‘AC_FC_LINE_LENGTH’ (see below), the ‘FC’ and
6294 ‘F77’ macros behave almost identically, and so they are documented
6295 together in this section.
6296
6297 — Macro: AC_PROG_F77([COMPILER-SEARCH-LIST])
6298 Determine a Fortran 77 compiler to use. If ‘F77’ is not already
6299 set in the environment, then check for ‘g77’ and ‘f77’, and then
6300 some other names. Set the output variable ‘F77’ to the name of the
6301 compiler found.
6302
6303 This macro may, however, be invoked with an optional first argument
6304 which, if specified, must be a blank-separated list of Fortran 77
6305 compilers to search for. This just gives the user an opportunity
6306 to specify an alternative search list for the Fortran 77 compiler.
6307 For example, if you didn’t like the default order, then you could
6308 invoke ‘AC_PROG_F77’ like this:
6309
6310 AC_PROG_F77([fl32 f77 fort77 xlf g77 f90 xlf90])
6311
6312 If using a compiler that supports GNU Fortran 77, set the shell
6313 variable ‘G77’ to ‘yes’. If the output variable ‘FFLAGS’ was not
6314 already set in the environment, set it to ‘-g -02’ for ‘g77’ (or
6315 ‘-O2’ where the GNU Fortran 77 compiler does not accept ‘-g’), or
6316 ‘-g’ for other compilers.
6317
6318 The result of the GNU test is cached in the
6319 ‘ac_cv_f77_compiler_gnu’ variable, acceptance of ‘-g’ in the
6320 ‘ac_cv_prog_f77_g’ variable.
6321
6322 — Macro: AC_PROG_FC([COMPILER-SEARCH-LIST], [DIALECT])
6323 Determine a Fortran compiler to use. If ‘FC’ is not already set in
6324 the environment, then ‘dialect’ is a hint to indicate what Fortran
6325 dialect to search for; the default is to search for the newest
6326 available dialect. Set the output variable ‘FC’ to the name of the
6327 compiler found.
6328
6329 By default, newer dialects are preferred over older dialects, but
6330 if ‘dialect’ is specified then older dialects are preferred
6331 starting with the specified dialect. ‘dialect’ can currently be
6332 one of Fortran 77, Fortran 90, or Fortran 95. However, this is
6333 only a hint of which compiler _name_ to prefer (e.g., ‘f90’ or
6334 ‘f95’), and no attempt is made to guarantee that a particular
6335 language standard is actually supported. Thus, it is preferable
6336 that you avoid the ‘dialect’ option, and use AC_PROG_FC only for
6337 code compatible with the latest Fortran standard.
6338
6339 This macro may, alternatively, be invoked with an optional first
6340 argument which, if specified, must be a blank-separated list of
6341 Fortran compilers to search for, just as in ‘AC_PROG_F77’.
6342
6343 If using a compiler that supports GNU Fortran, set the shell
6344 variable ‘GFC’ to ‘yes’. If the output variable ‘FCFLAGS’ was not
6345 already set in the environment, then set it to ‘-g -02’ for a GNU
6346 Fortran compiler (or ‘-O2’ where the compiler does not accept
6347 ‘-g’), or ‘-g’ for other compilers.
6348
6349 The result of the GNU test is cached in the ‘ac_cv_fc_compiler_gnu’
6350 variable, acceptance of ‘-g’ in the ‘ac_cv_prog_fc_g’ variable.
6351
6352 — Macro: AC_PROG_F77_C_O
6353 — Macro: AC_PROG_FC_C_O
6354 Test whether the Fortran compiler accepts the options ‘-c’ and ‘-o’
6355 simultaneously, and define ‘F77_NO_MINUS_C_MINUS_O’ or
6356 ‘FC_NO_MINUS_C_MINUS_O’, respectively, if it does not.
6357
6358 The result of the test is cached in the ‘ac_cv_prog_f77_c_o’ or
6359 ‘ac_cv_prog_fc_c_o’ variable, respectively.
6360
6361 The following macros check for Fortran compiler characteristics. To
6362 check for characteristics not listed here, use ‘AC_COMPILE_IFELSE’
6363 (*note Running the Compiler::) or ‘AC_RUN_IFELSE’ (*note Runtime::),
6364 making sure to first set the current language to Fortran 77 or Fortran
6365 via ‘AC_LANG([Fortran 77])’ or ‘AC_LANG(Fortran)’ (*note Language
6366 Choice::).
6367
6368 — Macro: AC_F77_LIBRARY_LDFLAGS
6369 — Macro: AC_FC_LIBRARY_LDFLAGS
6370 Determine the linker flags (e.g., ‘-L’ and ‘-l’) for the “Fortran
6371 intrinsic and runtime libraries” that are required to successfully
6372 link a Fortran program or shared library. The output variable
6373 ‘FLIBS’ or ‘FCLIBS’ is set to these flags (which should be included
6374 after ‘LIBS’ when linking).
6375
6376 This macro is intended to be used in those situations when it is
6377 necessary to mix, e.g., C++ and Fortran source code in a single
6378 program or shared library (*note (automake)Mixing Fortran 77 With C
6379 and C++::).
6380
6381 For example, if object files from a C++ and Fortran compiler must
6382 be linked together, then the C++ compiler/linker must be used for
6383 linking (since special C++-ish things need to happen at link time
6384 like calling global constructors, instantiating templates, enabling
6385 exception support, etc.).
6386
6387 However, the Fortran intrinsic and runtime libraries must be linked
6388 in as well, but the C++ compiler/linker doesn’t know by default how
6389 to add these Fortran 77 libraries. Hence, this macro was created
6390 to determine these Fortran libraries.
6391
6392 The macros ‘AC_F77_DUMMY_MAIN’ and ‘AC_FC_DUMMY_MAIN’ or
6393 ‘AC_F77_MAIN’ and ‘AC_FC_MAIN’ are probably also necessary to link
6394 C/C++ with Fortran; see below. Further, it is highly recommended
6395 that you use ‘AC_CONFIG_HEADERS’ (*note Configuration Headers::)
6396 because the complex defines that the function wrapper macros create
6397 may not work with C/C++ compiler drivers.
6398
6399 These macros internally compute the flag needed to verbose linking
6400 output and cache it in ‘ac_cv_prog_f77_v’ or ‘ac_cv_prog_fc_v’
6401 variables, respectively. The computed linker flags are cached in
6402 ‘ac_cv_f77_libs’ or ‘ac_cv_fc_libs’, respectively.
6403
6404 — Macro: AC_F77_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND =
6405 AC_MSG_FAILURE])
6406 — Macro: AC_FC_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND =
6407 AC_MSG_FAILURE])
6408 With many compilers, the Fortran libraries detected by
6409 ‘AC_F77_LIBRARY_LDFLAGS’ or ‘AC_FC_LIBRARY_LDFLAGS’ provide their
6410 own ‘main’ entry function that initializes things like Fortran I/O,
6411 and which then calls a user-provided entry function named (say)
6412 ‘MAIN__’ to run the user’s program. The ‘AC_F77_DUMMY_MAIN’ and
6413 ‘AC_FC_DUMMY_MAIN’ or ‘AC_F77_MAIN’ and ‘AC_FC_MAIN’ macros figure
6414 out how to deal with this interaction.
6415
6416 When using Fortran for purely numerical functions (no I/O, etc.)
6417 often one prefers to provide one’s own ‘main’ and skip the Fortran
6418 library initializations. In this case, however, one may still need
6419 to provide a dummy ‘MAIN__’ routine in order to prevent linking
6420 errors on some systems. ‘AC_F77_DUMMY_MAIN’ or ‘AC_FC_DUMMY_MAIN’
6421 detects whether any such routine is _required_ for linking, and
6422 what its name is; the shell variable ‘F77_DUMMY_MAIN’ or
6423 ‘FC_DUMMY_MAIN’ holds this name, ‘unknown’ when no solution was
6424 found, and ‘none’ when no such dummy main is needed.
6425
6426 By default, ACTION-IF-FOUND defines ‘F77_DUMMY_MAIN’ or
6427 ‘FC_DUMMY_MAIN’ to the name of this routine (e.g., ‘MAIN__’) _if_
6428 it is required. ACTION-IF-NOT-FOUND defaults to exiting with an
6429 error.
6430
6431 In order to link with Fortran routines, the user’s C/C++ program
6432 should then include the following code to define the dummy main if
6433 it is needed:
6434
6435 #ifdef F77_DUMMY_MAIN
6436 # ifdef __cplusplus
6437 extern "C"
6438 # endif
6439 int F77_DUMMY_MAIN (void) { return 1; }
6440 #endif
6441
6442 (Replace ‘F77’ with ‘FC’ for Fortran instead of Fortran 77.)
6443
6444 Note that this macro is called automatically from ‘AC_F77_WRAPPERS’
6445 or ‘AC_FC_WRAPPERS’; there is generally no need to call it
6446 explicitly unless one wants to change the default actions.
6447
6448 The result of this macro is cached in the ‘ac_cv_f77_dummy_main’ or
6449 ‘ac_cv_fc_dummy_main’ variable, respectively.
6450
6451 — Macro: AC_F77_MAIN
6452 — Macro: AC_FC_MAIN
6453 As discussed above, many Fortran libraries allow you to provide an
6454 entry point called (say) ‘MAIN__’ instead of the usual ‘main’,
6455 which is then called by a ‘main’ function in the Fortran libraries
6456 that initializes things like Fortran I/O. The ‘AC_F77_MAIN’ and
6457 ‘AC_FC_MAIN’ macros detect whether it is _possible_ to utilize such
6458 an alternate main function, and defines ‘F77_MAIN’ and ‘FC_MAIN’ to
6459 the name of the function. (If no alternate main function name is
6460 found, ‘F77_MAIN’ and ‘FC_MAIN’ are simply defined to ‘main’.)
6461
6462 Thus, when calling Fortran routines from C that perform things like
6463 I/O, one should use this macro and declare the "main" function like
6464 so:
6465
6466 #ifdef __cplusplus
6467 extern "C"
6468 #endif
6469 int F77_MAIN (int argc, char *argv[]);
6470
6471 (Again, replace ‘F77’ with ‘FC’ for Fortran instead of Fortran 77.)
6472
6473 The result of this macro is cached in the ‘ac_cv_f77_main’ or
6474 ‘ac_cv_fc_main’ variable, respectively.
6475
6476 — Macro: AC_F77_WRAPPERS
6477 — Macro: AC_FC_WRAPPERS
6478 Defines C macros ‘F77_FUNC (name, NAME)’, ‘FC_FUNC (name, NAME)’,
6479 ‘F77_FUNC_(name, NAME)’, and ‘FC_FUNC_(name, NAME)’ to properly
6480 mangle the names of C/C++ identifiers, and identifiers with
6481 underscores, respectively, so that they match the name-mangling
6482 scheme used by the Fortran compiler.
6483
6484 Fortran is case-insensitive, and in order to achieve this the
6485 Fortran compiler converts all identifiers into a canonical case and
6486 format. To call a Fortran subroutine from C or to write a C
6487 function that is callable from Fortran, the C program must
6488 explicitly use identifiers in the format expected by the Fortran
6489 compiler. In order to do this, one simply wraps all C identifiers
6490 in one of the macros provided by ‘AC_F77_WRAPPERS’ or
6491 ‘AC_FC_WRAPPERS’. For example, suppose you have the following
6492 Fortran 77 subroutine:
6493
6494 subroutine foobar (x, y)
6495 double precision x, y
6496 y = 3.14159 * x
6497 return
6498 end
6499
6500 You would then declare its prototype in C or C++ as:
6501
6502 #define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)
6503 #ifdef __cplusplus
6504 extern "C" /* prevent C++ name mangling */
6505 #endif
6506 void FOOBAR_F77 (double *x, double *y);
6507
6508 Note that we pass both the lowercase and uppercase versions of the
6509 function name to ‘F77_FUNC’ so that it can select the right one.
6510 Note also that all parameters to Fortran 77 routines are passed as
6511 pointers (*note (automake)Mixing Fortran 77 With C and C++::).
6512
6513 (Replace ‘F77’ with ‘FC’ for Fortran instead of Fortran 77.)
6514
6515 Although Autoconf tries to be intelligent about detecting the
6516 name-mangling scheme of the Fortran compiler, there may be Fortran
6517 compilers that it doesn’t support yet. In this case, the above
6518 code generates a compile-time error, but some other behavior (e.g.,
6519 disabling Fortran-related features) can be induced by checking
6520 whether ‘F77_FUNC’ or ‘FC_FUNC’ is defined.
6521
6522 Now, to call that routine from a C program, we would do something
6523 like:
6524
6525 {
6526 double x = 2.7183, y;
6527 FOOBAR_F77 (&x, &y);
6528 }
6529
6530 If the Fortran identifier contains an underscore (e.g., ‘foo_bar’),
6531 you should use ‘F77_FUNC_’ or ‘FC_FUNC_’ instead of ‘F77_FUNC’ or
6532 ‘FC_FUNC’ (with the same arguments). This is because some Fortran
6533 compilers mangle names differently if they contain an underscore.
6534
6535 The name mangling scheme is encoded in the ‘ac_cv_f77_mangling’ or
6536 ‘ac_cv_fc_mangling’ cache variable, respectively, and also used for
6537 the ‘AC_F77_FUNC’ and ‘AC_FC_FUNC’ macros described below.
6538
6539 — Macro: AC_F77_FUNC(NAME, [SHELLVAR])
6540 — Macro: AC_FC_FUNC(NAME, [SHELLVAR])
6541 Given an identifier NAME, set the shell variable SHELLVAR to hold
6542 the mangled version NAME according to the rules of the Fortran
6543 linker (see also ‘AC_F77_WRAPPERS’ or ‘AC_FC_WRAPPERS’). SHELLVAR
6544 is optional; if it is not supplied, the shell variable is simply
6545 NAME. The purpose of this macro is to give the caller a way to
6546 access the name-mangling information other than through the C
6547 preprocessor as above, for example, to call Fortran routines from
6548 some language other than C/C++.
6549
6550 — Macro: AC_FC_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6551 AC_MSG_FAILURE])
6552 — Macro: AC_FC_PP_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6553 AC_MSG_FAILURE])
6554 By default, the ‘FC’ macros perform their tests using a ‘.f’
6555 extension for source-code files. Some compilers, however, only
6556 enable newer language features for appropriately named files, e.g.,
6557 Fortran 90 features only for ‘.f90’ files, or preprocessing only
6558 with ‘.F’ files or maybe other upper-case extensions. On the other
6559 hand, some other compilers expect all source files to end in ‘.f’
6560 and require special flags to support other file name extensions.
6561 The ‘AC_FC_SRCEXT’ and ‘AC_FC_PP_SRCEXT’ macros deal with these
6562 issues.
6563
6564 The ‘AC_FC_SRCEXT’ macro tries to get the ‘FC’ compiler to accept
6565 files ending with the extension ‘.EXT’ (i.e., EXT does _not_
6566 contain the dot). If any special compiler flags are needed for
6567 this, it stores them in the output variable ‘FCFLAGS_EXT’. This
6568 extension and these flags are then used for all subsequent ‘FC’
6569 tests (until ‘AC_FC_SRCEXT’ or ‘AC_FC_PP_SRCEXT’ is called another
6570 time).
6571
6572 For example, you would use ‘AC_FC_SRCEXT(f90)’ to employ the ‘.f90’
6573 extension in future tests, and it would set the ‘FCFLAGS_f90’
6574 output variable with any extra flags that are needed to compile
6575 such files.
6576
6577 Similarly, the ‘AC_FC_PP_SRCEXT’ macro tries to get the ‘FC’
6578 compiler to preprocess and compile files with the extension ‘.EXT’.
6579 When both ‘fpp’ and ‘cpp’ style preprocessing are provided, the
6580 former is preferred, as the latter may treat continuation lines,
6581 ‘//’ tokens, and white space differently from what some Fortran
6582 dialects expect. Conversely, if you do not want files to be
6583 preprocessed, use only lower-case characters in the file name
6584 extension. Like with ‘AC_FC_SRCEXT(f90)’, any needed flags are
6585 stored in the ‘FCFLAGS_EXT’ variable.
6586
6587 The ‘FCFLAGS_EXT’ flags can _not_ be simply absorbed into
6588 ‘FCFLAGS’, for two reasons based on the limitations of some
6589 compilers. First, only one ‘FCFLAGS_EXT’ can be used at a time, so
6590 files with different extensions must be compiled separately.
6591 Second, ‘FCFLAGS_EXT’ must appear _immediately_ before the
6592 source-code file name when compiling. So, continuing the example
6593 above, you might compile a ‘foo.f90’ file in your makefile with the
6594 command:
6595
6596 foo.o: foo.f90
6597 $(FC) -c $(FCFLAGS) $(FCFLAGS_f90) '$(srcdir)/foo.f90'
6598
6599 If ‘AC_FC_SRCEXT’ or ‘AC_FC_PP_SRCEXT’ succeeds in compiling files
6600 with the EXT extension, it calls ACTION-IF-SUCCESS (defaults to
6601 nothing). If it fails, and cannot find a way to make the ‘FC’
6602 compiler accept such files, it calls ACTION-IF-FAILURE (defaults to
6603 exiting with an error message).
6604
6605 The ‘AC_FC_SRCEXT’ and ‘AC_FC_PP_SRCEXT’ macros cache their results
6606 in ‘ac_cv_fc_srcext_EXT’ and ‘ac_cv_fc_pp_srcext_EXT’ variables,
6607 respectively.
6608
6609 — Macro: AC_FC_PP_DEFINE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6610 AC_MSG_FAILURE])
6611
6612 Find a flag to specify defines for preprocessed Fortran. Not all
6613 Fortran compilers use ‘-D’. Substitute ‘FC_DEFINE’ with the result
6614 and call ACTION-IF-SUCCESS (defaults to nothing) if successful, and
6615 ACTION-IF-FAILURE (defaults to failing with an error message) if
6616 not.
6617
6618 This macro calls ‘AC_FC_PP_SRCEXT([F])’ in order to learn how to
6619 preprocess a ‘conftest.F’ file, but restores a previously used
6620 Fortran source file extension afterwards again.
6621
6622 The result of this test is cached in the ‘ac_cv_fc_pp_define’
6623 variable.
6624
6625 — Macro: AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6626 AC_MSG_FAILURE])
6627
6628 Try to ensure that the Fortran compiler (‘$FC’) allows free-format
6629 source code (as opposed to the older fixed-format style from
6630 Fortran 77). If necessary, it may add some additional flags to
6631 ‘FCFLAGS’.
6632
6633 This macro is most important if you are using the default ‘.f’
6634 extension, since many compilers interpret this extension as
6635 indicating fixed-format source unless an additional flag is
6636 supplied. If you specify a different extension with
6637 ‘AC_FC_SRCEXT’, such as ‘.f90’, then ‘AC_FC_FREEFORM’ ordinarily
6638 succeeds without modifying ‘FCFLAGS’. For extensions which the
6639 compiler does not know about, the flag set by the ‘AC_FC_SRCEXT’
6640 macro might let the compiler assume Fortran 77 by default, however.
6641
6642 If ‘AC_FC_FREEFORM’ succeeds in compiling free-form source, it
6643 calls ACTION-IF-SUCCESS (defaults to nothing). If it fails, it
6644 calls ACTION-IF-FAILURE (defaults to exiting with an error
6645 message).
6646
6647 The result of this test, or ‘none’ or ‘unknown’, is cached in the
6648 ‘ac_cv_fc_freeform’ variable.
6649
6650 — Macro: AC_FC_FIXEDFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6651 AC_MSG_FAILURE])
6652
6653 Try to ensure that the Fortran compiler (‘$FC’) allows the old
6654 fixed-format source code (as opposed to free-format style). If
6655 necessary, it may add some additional flags to ‘FCFLAGS’.
6656
6657 This macro is needed for some compilers alias names like ‘xlf95’
6658 which assume free-form source code by default, and in case you want
6659 to use fixed-form source with an extension like ‘.f90’ which many
6660 compilers interpret as free-form by default. If you specify a
6661 different extension with ‘AC_FC_SRCEXT’, such as ‘.f’, then
6662 ‘AC_FC_FIXEDFORM’ ordinarily succeeds without modifying ‘FCFLAGS’.
6663
6664 If ‘AC_FC_FIXEDFORM’ succeeds in compiling fixed-form source, it
6665 calls ACTION-IF-SUCCESS (defaults to nothing). If it fails, it
6666 calls ACTION-IF-FAILURE (defaults to exiting with an error
6667 message).
6668
6669 The result of this test, or ‘none’ or ‘unknown’, is cached in the
6670 ‘ac_cv_fc_fixedform’ variable.
6671
6672 — Macro: AC_FC_LINE_LENGTH([LENGTH], [ACTION-IF-SUCCESS],
6673 [ACTION-IF-FAILURE = AC_MSG_FAILURE])
6674
6675 Try to ensure that the Fortran compiler (‘$FC’) accepts long source
6676 code lines. The LENGTH argument may be given as 80, 132, or
6677 unlimited, and defaults to 132. Note that line lengths above 250
6678 columns are not portable, and some compilers do not accept more
6679 than 132 columns at least for fixed format source. If necessary,
6680 it may add some additional flags to ‘FCFLAGS’.
6681
6682 If ‘AC_FC_LINE_LENGTH’ succeeds in compiling fixed-form source, it
6683 calls ACTION-IF-SUCCESS (defaults to nothing). If it fails, it
6684 calls ACTION-IF-FAILURE (defaults to exiting with an error
6685 message).
6686
6687 The result of this test, or ‘none’ or ‘unknown’, is cached in the
6688 ‘ac_cv_fc_line_length’ variable.
6689
6690 — Macro: AC_FC_CHECK_BOUNDS([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6691 AC_MSG_FAILURE])
6692
6693 The ‘AC_FC_CHECK_BOUNDS’ macro tries to enable array bounds
6694 checking in the Fortran compiler. If successful, the
6695 ACTION-IF-SUCCESS is called and any needed flags are added to
6696 ‘FCFLAGS’. Otherwise, ACTION-IF-FAILURE is called, which defaults
6697 to failing with an error message. The macro currently requires
6698 Fortran 90 or a newer dialect.
6699
6700 The result of the macro is cached in the ‘ac_cv_fc_check_bounds’
6701 variable.
6702
6703 — Macro: AC_F77_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6704 AC_MSG_FAILURE])
6705 — Macro: AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6706 AC_MSG_FAILURE])
6707
6708 Try to disallow implicit declarations in the Fortran compiler. If
6709 successful, ACTION-IF-SUCCESS is called and any needed flags are
6710 added to ‘FFLAGS’ or ‘FCFLAGS’, respectively. Otherwise,
6711 ACTION-IF-FAILURE is called, which defaults to failing with an
6712 error message.
6713
6714 The result of these macros are cached in the
6715 ‘ac_cv_f77_implicit_none’ and ‘ac_cv_fc_implicit_none’ variables,
6716 respectively.
6717
6718 — Macro: AC_FC_MODULE_EXTENSION
6719
6720 Find the Fortran 90 module file name extension. Most Fortran 90
6721 compilers store module information in files separate from the
6722 object files. The module files are usually named after the name of
6723 the module rather than the source file name, with characters
6724 possibly turned to upper case, plus an extension, often ‘.mod’.
6725
6726 Not all compilers use module files at all, or by default. The Cray
6727 Fortran compiler requires ‘-e m’ in order to store and search
6728 module information in ‘.mod’ files rather than in object files.
6729 Likewise, the Fujitsu Fortran compilers uses the ‘-Am’ option to
6730 indicate how module information is stored.
6731
6732 The ‘AC_FC_MODULE_EXTENSION’ macro computes the module extension
6733 without the leading dot, and stores that in the ‘FC_MODEXT’
6734 variable. If the compiler does not produce module files, or the
6735 extension cannot be determined, ‘FC_MODEXT’ is empty. Typically,
6736 the result of this macro may be used in cleanup ‘make’ rules as
6737 follows:
6738
6739 clean-modules:
6740 -test -z "$(FC_MODEXT)" || rm -f *.$(FC_MODEXT)
6741
6742 The extension, or ‘unknown’, is cached in the ‘ac_cv_fc_module_ext’
6743 variable.
6744
6745 — Macro: AC_FC_MODULE_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6746 AC_MSG_FAILURE])
6747
6748 Find the compiler flag to include Fortran 90 module information
6749 from another directory, and store that in the ‘FC_MODINC’ variable.
6750 Call ACTION-IF-SUCCESS (defaults to nothing) if successful, and set
6751 ‘FC_MODINC’ to empty and call ACTION-IF-FAILURE (defaults to
6752 exiting with an error message) if not.
6753
6754 Most Fortran 90 compilers provide a way to specify module
6755 directories. Some have separate flags for the directory to write
6756 module files to, and directories to search them in, whereas others
6757 only allow writing to the current directory or to the first
6758 directory specified in the include path. Further, with some
6759 compilers, the module search path and the preprocessor search path
6760 can only be modified with the same flag. Thus, for portability,
6761 write module files to the current directory only and list that as
6762 first directory in the search path.
6763
6764 There may be no whitespace between ‘FC_MODINC’ and the following
6765 directory name, but ‘FC_MODINC’ may contain trailing white space.
6766 For example, if you use Automake and would like to search ‘../lib’
6767 for module files, you can use the following:
6768
6769 AM_FCFLAGS = $(FC_MODINC). $(FC_MODINC)../lib
6770
6771 Inside ‘configure’ tests, you can use:
6772
6773 if test -n "$FC_MODINC"; then
6774 FCFLAGS="$FCFLAGS $FC_MODINC. $FC_MODINC../lib"
6775 fi
6776
6777 The flag is cached in the ‘ac_cv_fc_module_flag’ variable. The
6778 substituted value of ‘FC_MODINC’ may refer to the ‘ac_empty’ dummy
6779 placeholder empty variable, to avoid losing the significant
6780 trailing whitespace in a ‘Makefile’.
6781
6782 — Macro: AC_FC_MODULE_OUTPUT_FLAG([ACTION-IF-SUCCESS],
6783 [ACTION-IF-FAILURE = AC_MSG_FAILURE])
6784
6785 Find the compiler flag to write Fortran 90 module information to
6786 another directory, and store that in the ‘FC_MODOUT’ variable.
6787 Call ACTION-IF-SUCCESS (defaults to nothing) if successful, and set
6788 ‘FC_MODOUT’ to empty and call ACTION-IF-FAILURE (defaults to
6789 exiting with an error message) if not.
6790
6791 Not all Fortran 90 compilers write module files, and of those that
6792 do, not all allow writing to a directory other than the current
6793 one, nor do all have separate flags for writing and reading; see
6794 the description of ‘AC_FC_MODULE_FLAG’ above. If you need to be
6795 able to write to another directory, for maximum portability use
6796 ‘FC_MODOUT’ before any ‘FC_MODINC’ and include both the current
6797 directory and the one you write to in the search path:
6798
6799 AM_FCFLAGS = $(FC_MODOUT)../mod $(FC_MODINC)../mod $(FC_MODINC). ...
6800
6801 The flag is cached in the ‘ac_cv_fc_module_output_flag’ variable.
6802 The substituted value of ‘FC_MODOUT’ may refer to the ‘ac_empty’
6803 dummy placeholder empty variable, to avoid losing the significant
6804 trailing whitespace in a ‘Makefile’.
6805
6806 — Macro: AC_F77_CRAY_POINTERS([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6807 AC_MSG_FAILURE])
6808 — Macro: AC_FC_CRAY_POINTERS([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE =
6809 AC_MSG_FAILURE])
6810
6811 Try to ensure that the Fortran compiler (‘$F77’ or ‘$FC’) accepts
6812 Cray pointers. If successful, the ACTION-IF-SUCCESS is called and
6813 any needed flags are added to ‘FFLAGS’ or ‘FCFLAGS’. Otherwise,
6814 ACTION-IF-FAILURE is called, which defaults to failing with an
6815 error message.
6816
6817 Cray pointers are a non-standard extension supported by many
6818 Fortran compilers which allow an integer to be declared as C-like
6819 pointer to a target variable.
6820
6821 The result of this test, or ‘none’ or ‘unknown’, is cached in the
6822 ‘ac_cv_f77_cray_ptr’ or ‘ac_cv_fc_cray_ptr’ variable.
6823
6824 
6825 File: autoconf.info, Node: Go Compiler, Next: Algol 68 Compiler, Prev: Fortran Compiler, Up: Compilers and Preprocessors
6826
6827 5.10.9 Go Compiler Characteristics
6828 ----------------------------------
6829
6830 Autoconf provides basic support for the Go programming language when
6831 using the ‘gccgo’ compiler (there is currently no support for the ‘6g’
6832 and ‘8g’ compilers).
6833
6834 — Macro: AC_PROG_GO([COMPILER-SEARCH-LIST])
6835 Find the Go compiler to use. Check whether the environment
6836 variable ‘GOC’ is set; if so, then set output variable ‘GOC’ to its
6837 value.
6838
6839 Otherwise, if the macro is invoked without an argument, then search
6840 for a Go compiler named ‘gccgo’. If it is not found, then as a
6841 last resort set ‘GOC’ to ‘gccgo’.
6842
6843 This macro may be invoked with an optional first argument which, if
6844 specified, must be a blank-separated list of Go compilers to search
6845 for.
6846
6847 If output variable ‘GOFLAGS’ was not already set, set it to ‘-g
6848 -O2’. If your package does not like this default, ‘GOFLAGS’ may be
6849 set before ‘AC_PROG_GO’.
6850
6851 
6852 File: autoconf.info, Node: Algol 68 Compiler, Prev: Go Compiler, Up: Compilers and Preprocessors
6853
6854 5.10.10 Algol 68 Compiler
6855 -------------------------
6856
6857 Autoconf provides basic support for the Algol 68 programming language
6858 when using the ‘ga68’ compiler.
6859
6860 Note that the GCC Algol 68 front-end is not yet integrated in the
6861 main compiler, so it is developed and distributed off-tree. See
6862 <https://gcc.gnu.org/wiki/Algol68FrontEnd>. Additional information
6863 about the Algol 68 programming language, and how it is being evolved by
6864 the GNU Algol 68 Working Group can be found at
6865 <https://algol68-lang.org>.
6866
6867 — Macro: AC_PROG_A68([COMPILER-SEARCH-LIST])
6868 Find the Algol 68 compiler to use. Check whether the environment
6869 variable ‘A68’ is set; if so, then set output variable ‘A68’ to its
6870 value.
6871
6872 Otherwise, if the macro is invoked without an argument, then search
6873 for an Algol 68 compiler named ‘ga68’. If it is not found, then as
6874 a last resort set ‘A68’ to ‘ga68’.
6875
6876 This macro may be invoked with an optional first argument which, if
6877 specified, must be a blank-separated list of Algol 68 compilers to
6878 search for.
6879
6880 If output variable ‘A68FLAGS’ was not already set, set it to ‘-g
6881 -O2’. If your package does not like this default, ‘A68FLAGS’ may
6882 be set before ‘AC_PROG_A68’.
6883
6884 
6885 File: autoconf.info, Node: System Services, Next: C and POSIX Variants, Prev: Compilers and Preprocessors, Up: Existing Tests
6886
6887 5.11 System Services
6888 ====================
6889
6890 The following macros check for operating system services or
6891 capabilities.
6892
6893 — Macro: AC_PATH_X
6894 Try to locate the X Window System include files and libraries. If
6895 the user gave the command line options ‘--x-includes=DIR’ and
6896 ‘--x-libraries=DIR’, use those directories.
6897
6898 If either or both were not given, get the missing values by running
6899 ‘xmkmf’ (or an executable pointed to by the ‘XMKMF’ environment
6900 variable) on a trivial ‘Imakefile’ and examining the makefile that
6901 it produces. Setting ‘XMKMF’ to ‘false’ disables this method.
6902
6903 If this method fails to find the X Window System, ‘configure’ looks
6904 for the files in several directories where they often reside. If
6905 either method is successful, set the shell variables ‘x_includes’
6906 and ‘x_libraries’ to their locations, unless they are in
6907 directories the compiler searches by default.
6908
6909 If both methods fail, or the user gave the command line option
6910 ‘--without-x’, set the shell variable ‘no_x’ to ‘yes’; otherwise
6911 set it to the empty string.
6912
6913 — Macro: AC_PATH_XTRA
6914 An enhanced version of ‘AC_PATH_X’. It adds the C compiler flags
6915 that X needs to output variable ‘X_CFLAGS’, and the X linker flags
6916 to ‘X_LIBS’. Define ‘X_DISPLAY_MISSING’ if X is not available.
6917
6918 This macro also checks for special libraries that some systems need
6919 in order to compile X programs. It adds any that the system needs
6920 to output variable ‘X_EXTRA_LIBS’. And it checks for special X11R6
6921 libraries that need to be linked with before ‘-lX11’, and adds any
6922 found to the output variable ‘X_PRE_LIBS’.
6923
6924 — Macro: AC_SYS_INTERPRETER
6925 Check whether the system supports starting scripts with a line of
6926 the form ‘#!/bin/sh’ to select the interpreter to use for the
6927 script. After running this macro, shell code in ‘configure.ac’ can
6928 check the shell variable ‘interpval’; it is set to ‘yes’ if the
6929 system supports ‘#!’, ‘no’ if not.
6930
6931 — Macro: AC_SYS_LARGEFILE
6932 If the default ‘off_t’ type is a 32-bit integer, and therefore
6933 cannot be used with files 2 GiB or larger, make a wider ‘off_t’
6934 available if the system supports it. Similarly, widen other types
6935 related to sizes of files and file systems if possible. These
6936 types may include ‘blkcnt_t’, ‘dev_t’, ‘ino_t’, ‘fsblkcnt_t’,
6937 ‘fsfilcnt_t’, and ‘rlim_t’.
6938
6939 Also, arrange for a ‘configure’ option ‘--enable-year2038’ to
6940 request widening the type ‘time_t’ as needed to represent file wand
6941 other timestamps after mid-January 2038. This widening is possible
6942 only on 32-bit GNU/Linux x86 and ARM systems with glibc 2.34 or
6943 later. If year-2038 support is requested but ‘configure’ fails to
6944 find a way to widen ‘time_t’ and inspection of the system suggests
6945 that this feature is available somehow, ‘configure’ will error out.
6946 If you want the default to be ‘--enable-year2038’, you can use
6947 ‘AC_SYS_YEAR2038’ or ‘AC_SYS_YEAR2038_RECOMMENDED’ instead of
6948 ‘AC_SYS_LARGEFILE’. In other words, older packages that have long
6949 used ‘AC_SYS_LARGEFILE’ can have year-2038 support on 32-bit
6950 GNU/Linux x86 and ARM systems either by regenerating ‘configure’
6951 with current Autoconf and configuring with ‘--enable-year2038’, or
6952 by using ‘AC_SYS_YEAR2038’ or ‘AC_SYS_YEAR2038_RECOMMENDED’ and
6953 configuring without ‘--disable-year2038’. A future version of
6954 Autoconf might change the ‘AC_SYS_LARGEFILE’ default to
6955 ‘--enable-year2038’; if and when that happens, ‘AC_SYS_LARGEFILE’
6956 and ‘AC_SYS_YEAR2038’ will become equivalent. *Note
6957 AC_SYS_YEAR2038::.
6958
6959 Set the shell variable ‘ac_have_largefile’ to ‘yes’ or ‘no’
6960 depending on whether a wide ‘off_t’ is available, regardless of
6961 whether arrangements were necessary. Similarly, set the shell
6962 variable ‘ac_have_year2038’ to ‘yes’ or ‘no’ depending on whether a
6963 wide-enough ‘time_t’ is available.
6964
6965 Define preprocessor macros if necessary to make types wider; for
6966 example, on GNU/Linux systems the macros ‘_FILE_OFFSET_BITS’ and
6967 ‘_TIME_BITS’ can be defined. Some of these macros work only if
6968 defined before the first system header is included; therefore, when
6969 using this macro in concert with ‘AC_CONFIG_HEADERS’, make sure
6970 that ‘config.h’ is included before any system headers.
6971
6972 Large-file support can be disabled by configuring with the
6973 ‘--disable-largefile’ option, and year-2038 support can be enabled
6974 and disabled via the ‘--enable-year2038’ and ‘--disable-year2038’
6975 options. These options have no effect on systems where types are
6976 wide enough by default. Large-file support is required for
6977 year-2038 support: if you configure with ‘--disable-largefile’ on a
6978 platform with 32-bit ‘time_t’, then year-2038 support is not
6979 available.
6980
6981 Disabling large-file or year-2038 support can have surprising
6982 effects, such as causing functions like ‘readdir’ and ‘stat’ to
6983 fail even on a small file because its inode number or timestamp is
6984 out of range.
6985
6986 Regardless of whether you use this macro, portable programs should
6987 not assume that any of the types listed above fit into a ‘long
6988 int’. For example, it is not portable to print an arbitrary
6989 ‘off_t’ or ‘time_t’ value ‘X’ with ‘printf ("%ld", (long int) X)’.
6990
6991 The standard C library functions ‘fseek’ and ‘ftell’ do not use
6992 ‘off_t’. If you need to use either of these functions, you should
6993 use ‘AC_FUNC_FSEEKO’ as well as ‘AC_SYS_LARGEFILE’, and then use
6994 their POSIX replacements ‘fseeko’ and ‘ftello’. *Note
6995 AC_FUNC_FSEEKO::.
6996
6997 When using ‘AC_SYS_LARGEFILE’ in different packages that are linked
6998 together and that have interfaces that depend on the width of
6999 ‘off_t’, ‘time_t’ or related types, the simplest thing is to
7000 configure all components the same way. For example, if an
7001 application uses ‘AC_SYS_LARGEFILE’ and is configured with
7002 ‘--enable-year2038’, libraries it links to with an ‘off_t’- or
7003 ‘time_t’-dependent interface should be configured equivalently.
7004 Alternatively, you can modify libraries to support both 32- and
7005 64-bit interfaces though this is more work and few libraries other
7006 than the C library itself are modified in this way.
7007
7008 Applications and libraries should be configured compatibly. If
7009 ‘off_t’, ‘time_t’ or related types appear in a library’s public
7010 interface, enabling or disabling the library’s large-file or
7011 year-2038 support may break binary compatibility with applications
7012 or with other libraries. Similarly, if an application links to a
7013 such a library, enabling or disabling the application’s large-file
7014 support may break binary compatibility with that library.
7015
7016 — Macro: AC_SYS_LONG_FILE_NAMES
7017 If the system supports file names longer than 14 characters, define
7018 ‘HAVE_LONG_FILE_NAMES’.
7019
7020 — Macro: AC_SYS_POSIX_TERMIOS
7021 Check to see if the POSIX termios headers and functions are
7022 available on the system. If so, set the shell variable
7023 ‘ac_cv_sys_posix_termios’ to ‘yes’. If not, set the variable to
7024 ‘no’.
7025
7026 — Macro: AC_SYS_YEAR2038
7027 This is like ‘AC_SYS_LARGEFILE’ except it defaults to enabling
7028 instead of disabling year-2038 support. Year-2038 support for
7029 applications and libraries should be configured compatibly. *Note
7030 AC_SYS_LARGEFILE::.
7031
7032 — Macro: AC_SYS_YEAR2038_RECOMMENDED
7033 This macro has the same effect as ‘AC_SYS_YEAR2038’, but also
7034 declares that the program being configured should support
7035 timestamps after mid-January 2038. If a large ‘time_t’ is
7036 unavailable, ‘configure’ will error out unless the
7037 ‘--disable-year2038’ option is specified.
7038
7039 Year-2038 support for applications and libraries should be
7040 configured compatibly. *Note AC_SYS_YEAR2038::.
7041
7042 
7043 File: autoconf.info, Node: C and POSIX Variants, Next: Erlang Libraries, Prev: System Services, Up: Existing Tests
7044
7045 5.12 C and POSIX Variants
7046 =========================
7047
7048 The following macro makes it possible to use C language and library
7049 extensions defined by the C standards committee, features of POSIX that
7050 are extensions to C, and platform extensions not defined by POSIX.
7051
7052 — Macro: AC_USE_SYSTEM_EXTENSIONS
7053 If possible, enable extensions to C or POSIX on hosts that normally
7054 disable the extensions, typically due to standards-conformance
7055 namespace issues. This should be called before any macros that run
7056 the C compiler. Also, when using this macro in concert with
7057 ‘AC_CONFIG_HEADERS’, be sure that ‘config.h’ is included before any
7058 system header.
7059
7060 Define the following preprocessor macros unconditionally:
7061
7062 ‘_ALL_SOURCE’
7063 Enable extensions on AIX and z/OS.
7064 ‘_COSMO_SOURCE’
7065 Enable extensions on Cosmopolitan Libc.
7066 ‘_DARWIN_C_SOURCE’
7067 Enable extensions on macOS.
7068 ‘_GNU_SOURCE’
7069 Enable extensions on GNU systems.
7070 ‘_NETBSD_SOURCE’
7071 Enable general extensions on NetBSD. Enable NetBSD
7072 compatibility extensions on Minix.
7073 ‘_OPENBSD_SOURCE’
7074 Enable OpenBSD compatibility extensions on NetBSD. Oddly
7075 enough, this does nothing on OpenBSD.
7076 ‘_POSIX_PTHREAD_SEMANTICS’
7077 Enable POSIX-compatible threading on Solaris.
7078 ‘__STDC_WANT_IEC_60559_ATTRIBS_EXT__’
7079 Enable extensions specified by ISO/IEC TS 18661-5:2014.
7080 ‘__STDC_WANT_IEC_60559_BFP_EXT__’
7081 Enable extensions specified by ISO/IEC TS 18661-1:2014.
7082 ‘__STDC_WANT_IEC_60559_DFP_EXT__’
7083 Enable extensions specified by ISO/IEC TS 18661-2:2015.
7084 ‘__STDC_WANT_IEC_60559_EXT__’
7085 Enable extensions specified by C23 Annex F.
7086 ‘__STDC_WANT_IEC_60559_FUNCS_EXT__’
7087 Enable extensions specified by ISO/IEC TS 18661-4:2015.
7088 ‘__STDC_WANT_IEC_60559_TYPES_EXT__’
7089 Enable extensions specified by C23 Annex H and by ISO/IEC TS
7090 18661-3:2015.
7091 ‘__STDC_WANT_LIB_EXT2__’
7092 Enable extensions specified by ISO/IEC TR 24731-2:2010.
7093 ‘__STDC_WANT_MATH_SPEC_FUNCS__’
7094 Enable extensions specified by ISO/IEC 24747:2009.
7095 ‘_TANDEM_SOURCE’
7096 Enable extensions on HP NonStop systems.
7097
7098 The following preprocessor macros are defined only when necessary;
7099 they enable access to extensions on some operating systems but
7100 _disable_ extensions on other operating systems.
7101
7102 ‘__EXTENSIONS__’
7103 Enable general extensions on Solaris. This macro is defined
7104 only if the headers included by ‘AC_INCLUDES_DEFAULT’ (*note
7105 Default Includes::) work correctly with it defined.
7106
7107 ‘_MINIX’
7108 ‘_POSIX_SOURCE’
7109 ‘_POSIX_1_SOURCE’
7110 Defined only on MINIX. ‘_POSIX_SOURCE’ and ‘_POSIX_1_SOURCE’
7111 are needed to enable a number of POSIX features on this OS.
7112 ‘_MINIX’ does not affect the system headers’ behavior; future
7113 versions of Autoconf may stop defining it. Programs that need
7114 to recognize Minix should use ‘AC_CANONICAL_HOST’.
7115
7116 ‘_XOPEN_SOURCE’
7117 Defined (with value 500) only if needed to make ‘wchar.h’
7118 declare ‘mbstate_t’. This is known to be necessary on some
7119 versions of HP-UX.
7120
7121 The C preprocessor macro ‘__STDC_WANT_DEC_FP__’ is not defined.
7122 ISO/IEC TR 24732:2009 was superseded by ISO/IEC TS 18661-2:2015.
7123
7124 The C preprocessor macro ‘__STDC_WANT_LIB_EXT1__’ is not defined,
7125 as the C standard’s Annex K is problematic. See: O’Donell C, Sebor
7126 M. Field Experience With Annex K—Bounds Checking Interfaces
7127 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm).
7128
7129 The Autoconf macro ‘AC_USE_SYSTEM_EXTENSIONS’ was introduced in
7130 Autoconf 2.60.
7131
7132 
7133 File: autoconf.info, Node: Erlang Libraries, Prev: C and POSIX Variants, Up: Existing Tests
7134
7135 5.13 Erlang Libraries
7136 =====================
7137
7138 The following macros check for an installation of Erlang/OTP, and for
7139 the presence of certain Erlang libraries. All those macros require the
7140 configuration of an Erlang interpreter and an Erlang compiler (*note
7141 Erlang Compiler and Interpreter::).
7142
7143 — Macro: AC_ERLANG_SUBST_ERTS_VER
7144 Set the output variable ‘ERLANG_ERTS_VER’ to the version of the
7145 Erlang runtime system (as returned by Erlang’s
7146 ‘erlang:system_info(version)’ function). The result of this test
7147 is cached if caching is enabled when running ‘configure’. The
7148 ‘ERLANG_ERTS_VER’ variable is not intended to be used for testing
7149 for features of specific ERTS versions, but to be used for
7150 substituting the ERTS version in Erlang/OTP release resource files
7151 (‘.rel’ files), as shown below.
7152
7153 — Macro: AC_ERLANG_SUBST_ROOT_DIR
7154 Set the output variable ‘ERLANG_ROOT_DIR’ to the path to the base
7155 directory in which Erlang/OTP is installed (as returned by Erlang’s
7156 ‘code:root_dir/0’ function). The result of this test is cached if
7157 caching is enabled when running ‘configure’.
7158
7159 — Macro: AC_ERLANG_SUBST_LIB_DIR
7160 Set the output variable ‘ERLANG_LIB_DIR’ to the path of the library
7161 directory of Erlang/OTP (as returned by Erlang’s ‘code:lib_dir/0’
7162 function), which subdirectories each contain an installed
7163 Erlang/OTP library. The result of this test is cached if caching
7164 is enabled when running ‘configure’.
7165
7166 — Macro: AC_ERLANG_CHECK_LIB(LIBRARY, [ACTION-IF-FOUND],
7167 [ACTION-IF-NOT-FOUND])
7168 Test whether the Erlang/OTP library LIBRARY is installed by calling
7169 Erlang’s ‘code:lib_dir/1’ function. The result of this test is
7170 cached if caching is enabled when running ‘configure’.
7171 ACTION-IF-FOUND is a list of shell commands to run if the library
7172 is installed; ACTION-IF-NOT-FOUND is a list of shell commands to
7173 run if it is not. Additionally, if the library is installed, the
7174 output variable ‘ERLANG_LIB_DIR_LIBRARY’ is set to the path to the
7175 library installation directory, and the output variable
7176 ‘ERLANG_LIB_VER_LIBRARY’ is set to the version number that is part
7177 of the subdirectory name, if it is in the standard form
7178 (‘LIBRARY-VERSION’). If the directory name does not have a version
7179 part, ‘ERLANG_LIB_VER_LIBRARY’ is set to the empty string. If the
7180 library is not installed, ‘ERLANG_LIB_DIR_LIBRARY’ and
7181 ‘ERLANG_LIB_VER_LIBRARY’ are set to ‘"not found"’. For example, to
7182 check if library ‘stdlib’ is installed:
7183
7184 AC_ERLANG_CHECK_LIB([stdlib],
7185 [AS_ECHO(["stdlib version \"$ERLANG_LIB_VER_stdlib\""])
7186 AS_ECHO(["is installed in \"$ERLANG_LIB_DIR_stdlib\""])],
7187 [AC_MSG_ERROR([stdlib was not found!])])
7188
7189 The ‘ERLANG_LIB_VER_LIBRARY’ variables (set by
7190 ‘AC_ERLANG_CHECK_LIB’) and the ‘ERLANG_ERTS_VER’ variable (set by
7191 ‘AC_ERLANG_SUBST_ERTS_VER’) are not intended to be used for testing
7192 for features of specific versions of libraries or of the Erlang
7193 runtime system. Those variables are intended to be substituted in
7194 Erlang release resource files (‘.rel’ files). For instance, to
7195 generate a ‘example.rel’ file for an application depending on the
7196 ‘stdlib’ library, ‘configure.ac’ could contain:
7197
7198 AC_ERLANG_SUBST_ERTS_VER
7199 AC_ERLANG_CHECK_LIB([stdlib],
7200 [],
7201 [AC_MSG_ERROR([stdlib was not found!])])
7202 AC_CONFIG_FILES([example.rel])
7203
7204 The ‘example.rel.in’ file used to generate ‘example.rel’ should
7205 contain:
7206
7207 {release,
7208 {"@PACKAGE@", "@VERSION@"},
7209 {erts, "@ERLANG_ERTS_VER@"},
7210 [{stdlib, "@ERLANG_LIB_VER_stdlib@"},
7211 {@PACKAGE@, "@VERSION@"}]}.
7212
7213 In addition to the above macros, which test installed Erlang
7214 libraries, the following macros determine the paths to the directories
7215 into which newly built Erlang libraries are to be installed:
7216
7217 — Macro: AC_ERLANG_SUBST_INSTALL_LIB_DIR
7218
7219 Set the ‘ERLANG_INSTALL_LIB_DIR’ output variable to the directory
7220 into which every built Erlang library should be installed in a
7221 separate subdirectory. If this variable is not set in the
7222 environment when ‘configure’ runs, its default value is
7223 ‘${libdir}/erlang/lib’.
7224
7225 — Macro: AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(LIBRARY, VERSION)
7226
7227 Set the ‘ERLANG_INSTALL_LIB_DIR_LIBRARY’ output variable to the
7228 directory into which the built Erlang library LIBRARY version
7229 VERSION should be installed. If this variable is not set in the
7230 environment when ‘configure’ runs, its default value is
7231 ‘$ERLANG_INSTALL_LIB_DIR/LIBRARY-VERSION’, the value of the
7232 ‘ERLANG_INSTALL_LIB_DIR’ variable being set by the
7233 ‘AC_ERLANG_SUBST_INSTALL_LIB_DIR’ macro.
7234
7235 
7236 File: autoconf.info, Node: Writing Tests, Next: Results, Prev: Existing Tests, Up: Top
7237
7238 6 Writing Tests
7239 ***************
7240
7241 If the existing feature tests don’t do something you need, you have to
7242 write new ones. These macros are the building blocks. They provide
7243 ways for other macros to check whether various kinds of features are
7244 available and report the results.
7245
7246 This chapter contains some suggestions and some of the reasons why
7247 the existing tests are written the way they are. You can also learn a
7248 lot about how to write Autoconf tests by looking at the existing ones.
7249 If something goes wrong in one or more of the Autoconf tests, this
7250 information can help you understand the assumptions behind them, which
7251 might help you figure out how to best solve the problem.
7252
7253 These macros check the output of the compiler system of the current
7254 language (*note Language Choice::). They do not cache the results of
7255 their tests for future use (*note Caching Results::), because they don’t
7256 know enough about the information they are checking for to generate a
7257 cache variable name. They also do not print any messages, for the same
7258 reason. The checks for particular kinds of features call these macros
7259 and do cache their results and print messages about what they’re
7260 checking for.
7261
7262 When you write a feature test that could be applicable to more than
7263 one software package, the best thing to do is encapsulate it in a new
7264 macro. *Note Writing Autoconf Macros::, for how to do that.
7265
7266 * Menu:
7267
7268 * Language Choice:: Selecting which language to use for testing
7269 * Writing Test Programs:: Forging source files for compilers
7270 * Running the Preprocessor:: Detecting preprocessor symbols
7271 * Running the Compiler:: Detecting language or header features
7272 * Running the Linker:: Detecting library features
7273 * Runtime:: Testing for runtime features
7274 * Multiple Cases:: Tests for several possible values
7275
7276 
7277 File: autoconf.info, Node: Language Choice, Next: Writing Test Programs, Up: Writing Tests
7278
7279 6.1 Language Choice
7280 ===================
7281
7282 Autoconf-generated ‘configure’ scripts check for the C compiler and its
7283 features by default. Packages that use other programming languages
7284 (maybe more than one, e.g., C and C++) need to test features of the
7285 compilers for the respective languages. The following macros determine
7286 which programming language is used in the subsequent tests in
7287 ‘configure.ac’.
7288
7289 — Macro: AC_LANG(LANGUAGE)
7290 Do compilation tests using the compiler, preprocessor, and file
7291 extensions for the specified LANGUAGE.
7292
7293 Supported languages are:
7294
7295 ‘C’
7296 Do compilation tests using ‘CC’ and ‘CPP’ and use extension
7297 ‘.c’ for test programs. Use compilation flags: ‘CPPFLAGS’
7298 with ‘CPP’, and both ‘CPPFLAGS’ and ‘CFLAGS’ with ‘CC’.
7299
7300 ‘C++’
7301 Do compilation tests using ‘CXX’ and ‘CXXCPP’ and use
7302 extension ‘.C’ for test programs. Use compilation flags:
7303 ‘CPPFLAGS’ with ‘CXXCPP’, and both ‘CPPFLAGS’ and ‘CXXFLAGS’
7304 with ‘CXX’.
7305
7306 ‘Fortran 77’
7307 Do compilation tests using ‘F77’ and use extension ‘.f’ for
7308 test programs. Use compilation flags: ‘FFLAGS’.
7309
7310 ‘Fortran’
7311 Do compilation tests using ‘FC’ and use extension ‘.f’ (or
7312 whatever has been set by ‘AC_FC_SRCEXT’) for test programs.
7313 Use compilation flags: ‘FCFLAGS’.
7314
7315 ‘Erlang’
7316 Compile and execute tests using ‘ERLC’ and ‘ERL’ and use
7317 extension ‘.erl’ for test Erlang modules. Use compilation
7318 flags: ‘ERLCFLAGS’.
7319
7320 ‘Objective C’
7321 Do compilation tests using ‘OBJC’ and ‘OBJCPP’ and use
7322 extension ‘.m’ for test programs. Use compilation flags:
7323 ‘CPPFLAGS’ with ‘OBJCPP’, and both ‘CPPFLAGS’ and ‘OBJCFLAGS’
7324 with ‘OBJC’.
7325
7326 ‘Objective C++’
7327 Do compilation tests using ‘OBJCXX’ and ‘OBJCXXCPP’ and use
7328 extension ‘.mm’ for test programs. Use compilation flags:
7329 ‘CPPFLAGS’ with ‘OBJCXXCPP’, and both ‘CPPFLAGS’ and
7330 ‘OBJCXXFLAGS’ with ‘OBJCXX’.
7331
7332 ‘Go’
7333 Do compilation tests using ‘GOC’ and use extension ‘.go’ for
7334 test programs. Use compilation flags ‘GOFLAGS’.
7335
7336 ‘Algol 68’
7337 Do compilation tests using ‘A68’ and use extension ‘.a68’ for
7338 test programs. Use compilation flags ‘A68FLAGS’.
7339
7340 — Macro: AC_LANG_PUSH(LANGUAGE)
7341 Remember the current language (as set by ‘AC_LANG’) on a stack, and
7342 then select the LANGUAGE. Use this macro and ‘AC_LANG_POP’ in
7343 macros that need to temporarily switch to a particular language.
7344
7345 — Macro: AC_LANG_POP([LANGUAGE])
7346 Select the language that is saved on the top of the stack, as set
7347 by ‘AC_LANG_PUSH’, and remove it from the stack.
7348
7349 If given, LANGUAGE specifies the language we just _quit_. It is a
7350 good idea to specify it when it’s known (which should be the
7351 case...), since Autoconf detects inconsistencies.
7352
7353 AC_LANG_PUSH([Fortran 77])
7354 # Perform some tests on Fortran 77.
7355 # ...
7356 AC_LANG_POP([Fortran 77])
7357
7358 — Macro: AC_LANG_ASSERT(LANGUAGE)
7359 Check statically that the current language is LANGUAGE. You should
7360 use this in your language specific macros to avoid that they be
7361 called with an inappropriate language.
7362
7363 This macro runs only at ‘autoconf’ time, and incurs no cost at
7364 ‘configure’ time. Sadly enough and because Autoconf is a two layer
7365 language (1), the macros ‘AC_LANG_PUSH’ and ‘AC_LANG_POP’ cannot be
7366 “optimizing”, therefore as much as possible you ought to avoid
7367 using them to wrap your code, rather, require from the user to run
7368 the macro with a correct current language, and check it with
7369 ‘AC_LANG_ASSERT’. And anyway, that may help the user understand
7370 she is running a Fortran macro while expecting a result about her
7371 Fortran 77 compiler...
7372
7373 — Macro: AC_REQUIRE_CPP
7374 Ensure that whichever preprocessor would currently be used for
7375 tests has been found. Calls ‘AC_REQUIRE’ (*note Prerequisite
7376 Macros::) with an argument of either ‘AC_PROG_CPP’ or
7377 ‘AC_PROG_CXXCPP’, depending on which language is current.
7378
7379 ---------- Footnotes ----------
7380
7381 (1) Because M4 is not aware of Sh code, especially conditionals, some
7382 optimizations that look nice statically may produce incorrect results at
7383 runtime.
7384
7385 
7386 File: autoconf.info, Node: Writing Test Programs, Next: Running the Preprocessor, Prev: Language Choice, Up: Writing Tests
7387
7388 6.2 Writing Test Programs
7389 =========================
7390
7391 Autoconf tests follow a common scheme: feed some program with some
7392 input, and most of the time, feed a compiler with some source file.
7393 This section is dedicated to these source samples.
7394
7395 * Menu:
7396
7397 * Guidelines:: General rules for writing test programs
7398 * Test Functions:: Avoiding pitfalls in test programs
7399 * Generating Sources:: Source program boilerplate
7400
7401 
7402 File: autoconf.info, Node: Guidelines, Next: Test Functions, Up: Writing Test Programs
7403
7404 6.2.1 Guidelines for Test Programs
7405 ----------------------------------
7406
7407 The most important rule to follow when writing testing samples is:
7408
7409 _Look for realism._
7410
7411 This motto means that testing samples must be written with the same
7412 strictness as real programs are written. In particular, you should
7413 avoid “shortcuts” and simplifications.
7414
7415 Don’t just play with the preprocessor if you want to prepare a
7416 compilation. For instance, using ‘cpp’ to check whether a header is
7417 functional might let your ‘configure’ accept a header which causes some
7418 _compiler_ error. Do not hesitate to check a header with other headers
7419 included before, especially required headers.
7420
7421 Make sure the symbols you use are properly defined, i.e., refrain
7422 from simply declaring a function yourself instead of including the
7423 proper header.
7424
7425 Test programs should not write to standard output. They should exit
7426 with status 0 if the test succeeds, and with status 1 otherwise, so that
7427 success can be distinguished easily from a core dump or other failure;
7428 segmentation violations and other failures produce a nonzero exit
7429 status. Unless you arrange for ‘exit’ to be declared, test programs
7430 should ‘return’, not ‘exit’, from ‘main’, because on many systems ‘exit’
7431 is not declared by default.
7432
7433 Test programs can use ‘#if’ or ‘#ifdef’ to check the values of
7434 preprocessor macros defined by tests that have already run. For
7435 example, if you call ‘AC_HEADER_STDBOOL’, then later on in
7436 ‘configure.ac’ you can have a test program that includes ‘stdbool.h’
7437 conditionally:
7438
7439 #ifdef HAVE_STDBOOL_H
7440 # include <stdbool.h>
7441 #endif
7442
7443 Both ‘#if HAVE_STDBOOL_H’ and ‘#ifdef HAVE_STDBOOL_H’ will work with
7444 any standard C compiler. Some developers prefer ‘#if’ because it is
7445 easier to read, while others prefer ‘#ifdef’ because it avoids
7446 diagnostics with picky compilers like GCC with the ‘-Wundef’ option.
7447
7448 If a test program needs to use or create a data file, give it a name
7449 that starts with ‘conftest’, such as ‘conftest.data’. The ‘configure’
7450 script cleans up by running ‘rm -f -r conftest*’ after running test
7451 programs and if the script is interrupted.
7452
7453 
7454 File: autoconf.info, Node: Test Functions, Next: Generating Sources, Prev: Guidelines, Up: Writing Test Programs
7455
7456 6.2.2 Test Functions
7457 --------------------
7458
7459 Functions in test code should use function prototypes, introduced in C89
7460 and required in C23.
7461
7462 Functions that test programs declare should also be conditionalized
7463 for C++, which requires ‘extern "C"’ prototypes. Make sure to not
7464 include any header files containing clashing prototypes.
7465
7466 #ifdef __cplusplus
7467 extern "C"
7468 #endif
7469 void *valloc (size_t);
7470
7471 If a test program calls a function with invalid parameters (just to
7472 see whether it exists), organize the program to ensure that it never
7473 invokes that function. You can do this by calling it in another
7474 function that is never invoked. You can’t do it by putting it after a
7475 call to ‘exit’, because GCC version 2 knows that ‘exit’ never returns
7476 and optimizes out any code that follows it in the same block.
7477
7478 If you include any header files, be sure to call the functions
7479 relevant to them with the correct number of arguments, even if they are
7480 just 0, to avoid compilation errors due to prototypes. GCC version 2
7481 has internal prototypes for several functions that it automatically
7482 inlines; for example, ‘memcpy’. To avoid errors when checking for them,
7483 either pass them the correct number of arguments or redeclare them with
7484 a different return type (such as ‘char’).
7485
7486 
7487 File: autoconf.info, Node: Generating Sources, Prev: Test Functions, Up: Writing Test Programs
7488
7489 6.2.3 Generating Sources
7490 ------------------------
7491
7492 Autoconf provides a set of macros that can be used to generate test
7493 source files. They are written to be language generic, i.e., they
7494 actually depend on the current language (*note Language Choice::) to
7495 “format” the output properly.
7496
7497 — Macro: AC_LANG_CONFTEST(SOURCE)
7498 Save the SOURCE text in the current test source file:
7499 ‘conftest.EXTENSION’ where the EXTENSION depends on the current
7500 language. As of Autoconf 2.63b, the source file also contains the
7501 results of all of the ‘AC_DEFINE’ performed so far.
7502
7503 Note that the SOURCE is evaluated exactly once, like regular
7504 Autoconf macro arguments, and therefore (i) you may pass a macro
7505 invocation, (ii) if not, be sure to double quote if needed.
7506
7507 The SOURCE text is expanded as an unquoted here-document, so ‘$’,
7508 ‘`’ and some ‘\’s should be backslash-escaped. *Note
7509 Here-Documents::.
7510
7511 This macro issues a warning during ‘autoconf’ processing if SOURCE
7512 does not include an expansion of the macro
7513 ‘AC_LANG_DEFINES_PROVIDED’ (note that both ‘AC_LANG_SOURCE’ and
7514 ‘AC_LANG_PROGRAM’ call this macro, and thus avoid the warning).
7515
7516 This macro is seldom called directly, but is used under the hood by
7517 more common macros such as ‘AC_COMPILE_IFELSE’ and ‘AC_RUN_IFELSE’.
7518
7519 — Macro: AC_LANG_DEFINES_PROVIDED
7520 This macro is called as a witness that the file
7521 ‘conftest.EXTENSION’ appropriate for the current language is
7522 complete, including all previously determined results from
7523 ‘AC_DEFINE’. This macro is seldom called directly, but exists if
7524 you have a compelling reason to write a conftest file without using
7525 ‘AC_LANG_SOURCE’, yet still want to avoid a syntax warning from
7526 ‘AC_LANG_CONFTEST’.
7527
7528 — Macro: AC_LANG_SOURCE(SOURCE)
7529 Expands into the SOURCE, with the definition of all the ‘AC_DEFINE’
7530 performed so far. This macro includes an expansion of
7531 ‘AC_LANG_DEFINES_PROVIDED’.
7532
7533 In many cases, you may find it more convenient to use the wrapper
7534 ‘AC_LANG_PROGRAM’.
7535
7536 For instance, executing (observe the double quotation!):
7537
7538 AC_INIT([Hello], [1.0], [[email protected]], [],
7539 [https://www.example.org/])
7540 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7541 [Greetings string.])
7542 AC_LANG([C])
7543 AC_LANG_CONFTEST(
7544 [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
7545 gcc -E -dD conftest.c
7546
7547 on a system with ‘gcc’ installed, results in:
7548
7549 ...
7550 # 1 "conftest.c"
7551
7552 #define PACKAGE_NAME "Hello"
7553 #define PACKAGE_TARNAME "hello"
7554 #define PACKAGE_VERSION "1.0"
7555 #define PACKAGE_STRING "Hello 1.0"
7556 #define PACKAGE_BUGREPORT "[email protected]"
7557 #define PACKAGE_URL "https://www.example.org/"
7558 #define HELLO_WORLD "Hello, World\n"
7559
7560 const char hw[] = "Hello, World\n";
7561
7562 When the test language is Fortran, Erlang, Go, or Algol 68, the
7563 ‘AC_DEFINE’ definitions are not automatically translated into constants
7564 in the source code by this macro.
7565
7566 — Macro: AC_LANG_PROGRAM([PROLOGUE], [BODY])
7567 Expands into a source file which consists of the PROLOGUE, and then
7568 BODY as body of the main function (e.g., ‘main’ in C). Since it
7569 uses ‘AC_LANG_SOURCE’, the features of the latter are available.
7570
7571 For instance:
7572
7573 AC_INIT([Hello], [1.0], [[email protected]], [],
7574 [https://www.example.org/])
7575 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7576 [Greetings string.])
7577 AC_LANG_CONFTEST(
7578 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
7579 [[fputs (hw, stdout);]])])
7580 gcc -E -dD conftest.c
7581
7582 on a system with ‘gcc’ installed, results in:
7583
7584 ...
7585 # 1 "conftest.c"
7586
7587 #define PACKAGE_NAME "Hello"
7588 #define PACKAGE_TARNAME "hello"
7589 #define PACKAGE_VERSION "1.0"
7590 #define PACKAGE_STRING "Hello 1.0"
7591 #define PACKAGE_BUGREPORT "[email protected]"
7592 #define PACKAGE_URL "https://www.example.org/"
7593 #define HELLO_WORLD "Hello, World\n"
7594
7595 const char hw[] = "Hello, World\n";
7596 int
7597 main (void)
7598 {
7599 fputs (hw, stdout);
7600 ;
7601 return 0;
7602 }
7603
7604 In Erlang tests, the created source file is that of an Erlang module
7605 called ‘conftest’ (‘conftest.erl’). This module defines and exports at
7606 least one ‘start/0’ function, which is called to perform the test. The
7607 PROLOGUE is optional code that is inserted between the module header and
7608 the ‘start/0’ function definition. BODY is the body of the ‘start/0’
7609 function without the final period (*note Runtime::, about constraints on
7610 this function’s behavior).
7611
7612 For instance:
7613
7614 AC_INIT([Hello], [1.0], [[email protected]])
7615 AC_LANG(Erlang)
7616 AC_LANG_CONFTEST(
7617 [AC_LANG_PROGRAM([[-define(HELLO_WORLD, "Hello, world!").]],
7618 [[io:format("~s~n", [?HELLO_WORLD])]])])
7619 cat conftest.erl
7620
7621 results in:
7622
7623 -module(conftest).
7624 -export([start/0]).
7625 -define(HELLO_WORLD, "Hello, world!").
7626 start() ->
7627 io:format("~s~n", [?HELLO_WORLD])
7628 .
7629
7630 — Macro: AC_LANG_CALL(PROLOGUE, FUNCTION)
7631 Expands into a source file which consists of the PROLOGUE, and then
7632 a call to the FUNCTION as body of the main function (e.g., ‘main’
7633 in C). Since it uses ‘AC_LANG_PROGRAM’, the feature of the latter
7634 are available.
7635
7636 This function will probably be replaced in the future by a version
7637 which would enable specifying the arguments. The use of this macro
7638 is not encouraged, as it violates strongly the typing system.
7639
7640 This macro cannot be used for Erlang tests.
7641
7642 — Macro: AC_LANG_FUNC_LINK_TRY(FUNCTION)
7643 Expands into a source file which uses the FUNCTION in the body of
7644 the main function (e.g., ‘main’ in C). Since it uses
7645 ‘AC_LANG_PROGRAM’, the features of the latter are available.
7646
7647 As ‘AC_LANG_CALL’, this macro is documented only for completeness.
7648 It is considered to be severely broken, and in the future will be
7649 removed in favor of actual function calls (with properly typed
7650 arguments).
7651
7652 This macro cannot be used for Erlang tests.
7653
7654 
7655 File: autoconf.info, Node: Running the Preprocessor, Next: Running the Compiler, Prev: Writing Test Programs, Up: Writing Tests
7656
7657 6.3 Running the Preprocessor
7658 ============================
7659
7660 Sometimes one might need to run the preprocessor on some source file.
7661 _Usually it is a bad idea_, as you typically need to _compile_ your
7662 project, not merely run the preprocessor on it; therefore you certainly
7663 want to run the compiler, not the preprocessor. Resist the temptation
7664 of following the easiest path.
7665
7666 Nevertheless, if you need to run the preprocessor, then use
7667 ‘AC_PREPROC_IFELSE’.
7668
7669 The macros described in this section cannot be used for tests in
7670 Erlang, Fortran, Go, or Algol 68 since those languages require no
7671 preprocessor.
7672
7673 — Macro: AC_PREPROC_IFELSE(INPUT, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
7674 Run the preprocessor of the current language (*note Language
7675 Choice::) on the INPUT, run the shell commands ACTION-IF-TRUE on
7676 success, ACTION-IF-FALSE otherwise.
7677
7678 If INPUT is nonempty use the equivalent of
7679 ‘AC_LANG_CONFTEST(INPUT)’ to generate the current test source file;
7680 otherwise reuse the already-existing test source file. The INPUT
7681 can be made by ‘AC_LANG_PROGRAM’ and friends. The INPUT text is
7682 expanded as an unquoted here-document, so ‘$’, ‘`’ and some ‘\’s
7683 should be backslash-escaped. *Note Here-Documents::.
7684
7685 This macro uses ‘CPPFLAGS’, but not ‘CFLAGS’, because ‘-g’, ‘-O’,
7686 etc. are not valid options to many C preprocessors.
7687
7688 It is customary to report unexpected failures with
7689 ‘AC_MSG_FAILURE’. If needed, ACTION-IF-TRUE can further access the
7690 preprocessed output in the file ‘conftest.i’.
7691
7692 For instance:
7693
7694 AC_INIT([Hello], [1.0], [[email protected]])
7695 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
7696 [Greetings string.])
7697 AC_PREPROC_IFELSE(
7698 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
7699 [[fputs (hw, stdout);]])],
7700 [AC_MSG_RESULT([OK])],
7701 [AC_MSG_FAILURE([unexpected preprocessor failure])])
7702
7703 might result in:
7704
7705 checking for gcc... gcc
7706 checking whether the C compiler works... yes
7707 checking for C compiler default output file name... a.out
7708 checking for suffix of executables...
7709 checking whether we are cross compiling... no
7710 checking for suffix of object files... o
7711 checking whether the compiler supports GNU C... yes
7712 checking whether gcc accepts -g... yes
7713 checking for gcc option to enable C23 features... -std=gnu23
7714 checking how to run the C preprocessor... gcc -std=gnu23 -E
7715 OK
7716
7717
7718 The macro ‘AC_TRY_CPP’ (*note Obsolete Macros::) used to play the
7719 role of ‘AC_PREPROC_IFELSE’, but double quotes its argument, making it
7720 impossible to use it to elaborate sources. You are encouraged to get
7721 rid of your old use of the macro ‘AC_TRY_CPP’ in favor of
7722 ‘AC_PREPROC_IFELSE’, but, in the first place, are you sure you need to
7723 run the _preprocessor_ and not the compiler?
7724
7725 — Macro: AC_EGREP_HEADER(PATTERN, HEADER-FILE, ACTION-IF-FOUND,
7726 [ACTION-IF-NOT-FOUND])
7727 PATTERN, after being expanded as if in a double-quoted shell
7728 string, is an extended regular expression. If the output of
7729 running the preprocessor on the system header file HEADER-FILE
7730 contains a line matching PATTERN, execute shell commands
7731 ACTION-IF-FOUND, otherwise execute ACTION-IF-NOT-FOUND.
7732
7733 See below for some problems involving this macro.
7734
7735 — Macro: AC_EGREP_CPP(PATTERN, PROGRAM, [ACTION-IF-FOUND],
7736 [ACTION-IF-NOT-FOUND])
7737 PATTERN, after being expanded as if in a double-quoted shell
7738 string, is an extended regular expression. PROGRAM is the text of
7739 a C or C++ program, which is expanded as an unquoted here-document
7740 (*note Here-Documents::). If the output of running the
7741 preprocessor on PROGRAM contains a line matching PATTERN, execute
7742 shell commands ACTION-IF-FOUND, otherwise execute
7743 ACTION-IF-NOT-FOUND.
7744
7745 See below for some problems involving this macro.
7746
7747 ‘AC_EGREP_CPP’ and ‘AC_EGREP_HEADER’ should be used with care, as
7748 preprocessors can insert line breaks between output tokens. For
7749 example, the preprocessor might transform this:
7750
7751 #define MAJOR 2
7752 #define MINOR 23
7753 Version MAJOR . MINOR
7754
7755 into this:
7756
7757 Version
7758 2
7759 .
7760 23
7761
7762 Because preprocessors are allowed to insert white space, change escapes
7763 in string constants, insert backlash-newline pairs, or do any of a
7764 number of things that do not change the meaning of the preprocessed
7765 program, it is better to rely on ‘AC_PREPROC_IFELSE’ than to resort to
7766 ‘AC_EGREP_CPP’ or ‘AC_EGREP_HEADER’.
7767
7768 For more information about what can appear in portable extended
7769 regular expressions, *note (grep)Problematic Expressions::.
7770
7771 
7772 File: autoconf.info, Node: Running the Compiler, Next: Running the Linker, Prev: Running the Preprocessor, Up: Writing Tests
7773
7774 6.4 Running the Compiler
7775 ========================
7776
7777 To check for a syntax feature of the current language’s (*note Language
7778 Choice::) compiler, such as whether it recognizes a certain keyword, or
7779 simply to try some library feature, use ‘AC_COMPILE_IFELSE’ to try to
7780 compile a small program that uses that feature.
7781
7782 — Macro: AC_COMPILE_IFELSE(INPUT, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
7783 Run the compiler and compilation flags of the current language
7784 (*note Language Choice::) on the INPUT, run the shell commands
7785 ACTION-IF-TRUE on success, ACTION-IF-FALSE otherwise.
7786
7787 If INPUT is nonempty use the equivalent of
7788 ‘AC_LANG_CONFTEST(INPUT)’ to generate the current test source file;
7789 otherwise reuse the already-existing test source file. The INPUT
7790 can be made by ‘AC_LANG_PROGRAM’ and friends. The INPUT text is
7791 expanded as an unquoted here-document, so ‘$’, ‘`’ and some ‘\’s
7792 should be backslash-escaped. *Note Here-Documents::.
7793
7794 It is customary to report unexpected failures with
7795 ‘AC_MSG_FAILURE’. This macro does not try to link; use
7796 ‘AC_LINK_IFELSE’ if you need to do that (*note Running the
7797 Linker::). If needed, ACTION-IF-TRUE can further access the
7798 just-compiled object file ‘conftest.$OBJEXT’.
7799
7800 This macro uses ‘AC_REQUIRE’ for the compiler associated with the
7801 current language, which means that if the compiler has not yet been
7802 determined, the compiler determination will be made prior to the
7803 body of the outermost ‘AC_DEFUN’ macro that triggered this macro to
7804 expand (*note Expanded Before Required::).
7805
7806 For tests in Erlang, the INPUT must be the source code of a module
7807 named ‘conftest’. ‘AC_COMPILE_IFELSE’ generates a ‘conftest.beam’ file
7808 that can be interpreted by the Erlang virtual machine (‘ERL’). It is
7809 recommended to use ‘AC_LANG_PROGRAM’ to specify the test program, to
7810 ensure that the Erlang module has the right name.
7811
7812 
7813 File: autoconf.info, Node: Running the Linker, Next: Runtime, Prev: Running the Compiler, Up: Writing Tests
7814
7815 6.5 Running the Linker
7816 ======================
7817
7818 To check for a library, a function, or a global variable, Autoconf
7819 ‘configure’ scripts try to compile and link a small program that uses
7820 it. This is unlike Metaconfig, which by default uses ‘nm’ or ‘ar’ on
7821 the C library to try to figure out which functions are available.
7822 Trying to link with the function is usually a more reliable approach
7823 because it avoids dealing with the variations in the options and output
7824 formats of ‘nm’ and ‘ar’ and in the location of the standard libraries.
7825 It also allows configuring for cross-compilation or checking a
7826 function’s runtime behavior if needed. On the other hand, it can be
7827 slower than scanning the libraries once, but accuracy is more important
7828 than speed.
7829
7830 ‘AC_LINK_IFELSE’ is used to compile test programs to test for
7831 functions and global variables. It is also used by ‘AC_CHECK_LIB’ to
7832 check for libraries (*note Libraries::), by adding the library being
7833 checked for to ‘LIBS’ temporarily and trying to link a small program.
7834
7835 — Macro: AC_LINK_IFELSE(INPUT, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
7836 Run the compiler (and compilation flags) and the linker of the
7837 current language (*note Language Choice::) on the INPUT, run the
7838 shell commands ACTION-IF-TRUE on success, ACTION-IF-FALSE
7839 otherwise. If needed, ACTION-IF-TRUE can further access the
7840 just-linked program file ‘conftest$EXEEXT’.
7841
7842 If INPUT is nonempty use the equivalent of
7843 ‘AC_LANG_CONFTEST(INPUT)’ to generate the current test source file;
7844 otherwise reuse the already-existing test source file. The INPUT
7845 can be made by ‘AC_LANG_PROGRAM’ and friends. The INPUT text is
7846 expanded as an unquoted here-document, so ‘$’, ‘`’ and some ‘\’s
7847 should be backslash-escaped. *Note Here-Documents::.
7848
7849 ‘LDFLAGS’ and ‘LIBS’ are used for linking, in addition to the
7850 current compilation flags.
7851
7852 It is customary to report unexpected failures with
7853 ‘AC_MSG_FAILURE’. This macro does not try to execute the program;
7854 use ‘AC_RUN_IFELSE’ if you need to do that (*note Runtime::).
7855
7856 The ‘AC_LINK_IFELSE’ macro cannot be used for Erlang tests, since
7857 Erlang programs are interpreted and do not require linking.
7858
7859 
7860 File: autoconf.info, Node: Runtime, Next: Multiple Cases, Prev: Running the Linker, Up: Writing Tests
7861
7862 6.6 Checking Runtime Behavior
7863 =============================
7864
7865 Sometimes you need to find out how a system performs at runtime, such as
7866 whether a given function has a certain capability or bug. If you can,
7867 make such checks when your program runs instead of when it is
7868 configured. You can check for things like the machine’s endianness when
7869 your program initializes itself.
7870
7871 If you really need to test for a runtime behavior while configuring,
7872 you can write a test program to determine the result, and compile and
7873 run it using ‘AC_RUN_IFELSE’. Avoid running test programs if possible,
7874 because this prevents people from configuring your package for
7875 cross-compiling.
7876
7877 — Macro: AC_RUN_IFELSE(INPUT, [ACTION-IF-TRUE], [ACTION-IF-FALSE],
7878 [ACTION-IF-CROSS-COMPILING = AC_MSG_FAILURE])
7879 Run the compiler (and compilation flags) and the linker of the
7880 current language (*note Language Choice::) on the INPUT, then
7881 execute the resulting program. If the program returns an exit
7882 status of 0 when executed, run shell commands ACTION-IF-TRUE.
7883 Otherwise, run shell commands ACTION-IF-FALSE.
7884
7885 If INPUT is nonempty use the equivalent of
7886 ‘AC_LANG_CONFTEST(INPUT)’ to generate the current test source file;
7887 otherwise reuse the already-existing test source file. The INPUT
7888 can be made by ‘AC_LANG_PROGRAM’ and friends. The INPUT text is
7889 expanded as an unquoted here-document, so ‘$’, ‘`’ and some ‘\’s
7890 should be backslash-escaped. *Note Here-Documents::.
7891
7892 ‘LDFLAGS’ and ‘LIBS’ are used for linking, in addition to the
7893 compilation flags of the current language (*note Language
7894 Choice::). Additionally, ACTION-IF-TRUE can run
7895 ‘./conftest$EXEEXT’ for further testing.
7896
7897 In the ACTION-IF-FALSE section, the failing exit status is
7898 available in the shell variable ‘$?’. This exit status might be
7899 that of a failed compilation, or it might be that of a failed
7900 program execution.
7901
7902 If cross-compilation mode is enabled (this is the case if either
7903 the compiler being used does not produce executables that run on
7904 the system where ‘configure’ is being run, or if the options
7905 ‘--build’ and ‘--host’ were both specified and their values are
7906 different), then the test program is not run. If the optional
7907 shell commands ACTION-IF-CROSS-COMPILING are given, those commands
7908 are run instead; typically these commands provide pessimistic
7909 defaults that allow cross-compilation to work even if the guess was
7910 wrong. If the fourth argument is empty or omitted, but
7911 cross-compilation is detected, then ‘configure’ prints an error
7912 message and exits. If you want your package to be useful in a
7913 cross-compilation scenario, you _should_ provide a non-empty
7914 ACTION-IF-CROSS-COMPILING clause, as well as wrap the
7915 ‘AC_RUN_IFELSE’ compilation inside an ‘AC_CACHE_CHECK’ (*note
7916 Caching Results::) which allows the user to override the
7917 pessimistic default if needed.
7918
7919 It is customary to report unexpected failures with
7920 ‘AC_MSG_FAILURE’.
7921
7922 ‘autoconf’ prints a warning message when creating ‘configure’ each
7923 time it encounters a call to ‘AC_RUN_IFELSE’ with no
7924 ACTION-IF-CROSS-COMPILING argument given. If you are not concerned
7925 about users configuring your package for cross-compilation, you may
7926 ignore the warning. A few of the macros distributed with Autoconf
7927 produce this warning message; but if this is a problem for you, please
7928 report it as a bug, along with an appropriate pessimistic guess to use
7929 instead.
7930
7931 To configure for cross-compiling you can also choose a value for
7932 those parameters based on the canonical system name (*note Manual
7933 Configuration::). Alternatively, set up a test results cache file with
7934 the correct values for the host system (*note Caching Results::).
7935
7936 To provide a default for calls of ‘AC_RUN_IFELSE’ that are embedded
7937 in other macros, including a few of the ones that come with Autoconf,
7938 you can test whether the shell variable ‘cross_compiling’ is set to
7939 ‘yes’, and then use an alternate method to get the results instead of
7940 calling the macros.
7941
7942 It is also permissible to temporarily assign to ‘cross_compiling’ in
7943 order to force tests to behave as though they are in a cross-compilation
7944 environment, particularly since this provides a way to test your
7945 ACTION-IF-CROSS-COMPILING even when you are not using a cross-compiler.
7946
7947 # We temporarily set cross-compile mode to force AC_COMPUTE_INT
7948 # to use the slow link-only method
7949 save_cross_compiling=$cross_compiling
7950 cross_compiling=yes
7951 AC_COMPUTE_INT([...])
7952 cross_compiling=$save_cross_compiling
7953
7954 A C or C++ runtime test should be portable. *Note Portable C and
7955 C++::.
7956
7957 Erlang tests must exit themselves the Erlang VM by calling the
7958 ‘halt/1’ function: the given status code is used to determine the
7959 success of the test (status is ‘0’) or its failure (status is different
7960 than ‘0’), as explained above. It must be noted that data output
7961 through the standard output (e.g., using ‘io:format/2’) may be truncated
7962 when halting the VM. Therefore, if a test must output configuration
7963 information, it is recommended to create and to output data into the
7964 temporary file named ‘conftest.out’, using the functions of module
7965 ‘file’. The ‘conftest.out’ file is automatically deleted by the
7966 ‘AC_RUN_IFELSE’ macro. For instance, a simplified implementation of
7967 Autoconf’s ‘AC_ERLANG_SUBST_LIB_DIR’ macro is:
7968
7969 AC_INIT([LibdirTest], [1.0], [[email protected]])
7970 AC_ERLANG_NEED_ERL
7971 AC_LANG(Erlang)
7972 AC_RUN_IFELSE(
7973 [AC_LANG_PROGRAM([], [dnl
7974 file:write_file("conftest.out", code:lib_dir()),
7975 halt(0)])],
7976 [AS_ECHO(["code:lib_dir() returned: `cat conftest.out`"])],
7977 [AC_MSG_FAILURE([test Erlang program execution failed])])
7978
7979 
7980 File: autoconf.info, Node: Multiple Cases, Prev: Runtime, Up: Writing Tests
7981
7982 6.7 Multiple Cases
7983 ==================
7984
7985 Some operations are accomplished in several possible ways, depending on
7986 the OS variant. Checking for them essentially requires a “case
7987 statement”. Autoconf does not directly provide one; however, it is easy
7988 to simulate by using a shell variable to keep track of whether a way to
7989 perform the operation has been found yet.
7990
7991 Here is an example that uses the shell variable ‘fstype’ to keep
7992 track of whether the remaining cases need to be checked. Note that
7993 since the value of ‘fstype’ is under our control, we don’t have to use
7994 the longer ‘test "x$fstype" = xno’.
7995
7996 AC_MSG_CHECKING([how to get file system type])
7997 fstype=no
7998 # The order of these tests is important.
7999 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statvfs.h>
8000 #include <sys/fstyp.h>
8001 ]])],
8002 [AC_DEFINE([FSTYPE_STATVFS], [1],
8003 [Define if statvfs exists.])
8004 fstype=SVR4])
8005 AS_IF([test $fstype = no],
8006 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
8007 #include <sys/fstyp.h>
8008 ]])],
8009 [AC_DEFINE([FSTYPE_USG_STATFS], [1],
8010 [Define if USG statfs.])
8011 fstype=SVR3])])
8012 AS_IF([test $fstype = no],
8013 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
8014 #include <sys/vmount.h>
8015 ]])],
8016 [AC_DEFINE([FSTYPE_AIX_STATFS], [1],
8017 [Define if AIX statfs.])
8018 fstype=AIX])])
8019 # (more cases omitted here)
8020 AC_MSG_RESULT([$fstype])
8021
8022 
8023 File: autoconf.info, Node: Results, Next: Programming in M4, Prev: Writing Tests, Up: Top
8024
8025 7 Results of Tests
8026 ******************
8027
8028 Once ‘configure’ has determined whether a feature exists, what can it do
8029 to record that information? There are four sorts of things it can do:
8030 define a C preprocessor symbol, set a variable in the output files, save
8031 the result in a cache file for future ‘configure’ runs, and print a
8032 message letting the user know the result of the test.
8033
8034 * Menu:
8035
8036 * Defining Symbols:: Defining C preprocessor symbols
8037 * Setting Output Variables:: Replacing variables in output files
8038 * Special Chars in Variables:: Characters to beware of in variables
8039 * Caching Results:: Speeding up subsequent ‘configure’ runs
8040 * Printing Messages:: Notifying ‘configure’ users
8041
8042 
8043 File: autoconf.info, Node: Defining Symbols, Next: Setting Output Variables, Up: Results
8044
8045 7.1 Defining C Preprocessor Symbols
8046 ===================================
8047
8048 A common action to take in response to a feature test is to define a C
8049 preprocessor symbol indicating the results of the test. That is done by
8050 calling ‘AC_DEFINE’ or ‘AC_DEFINE_UNQUOTED’.
8051
8052 By default, ‘AC_OUTPUT’ places the symbols defined by these macros
8053 into the output variable ‘DEFS’, which contains an option
8054 ‘-DSYMBOL=VALUE’ for each symbol defined. Unlike in Autoconf version 1,
8055 there is no variable ‘DEFS’ defined while ‘configure’ is running. To
8056 check whether Autoconf macros have already defined a certain C
8057 preprocessor symbol, test the value of the appropriate cache variable,
8058 as in this example:
8059
8060 AC_CHECK_FUNC([vprintf],
8061 [AC_DEFINE([HAVE_VPRINTF], [1],
8062 [Define if vprintf exists.])])
8063 AS_IF([test "x$ac_cv_func_vprintf" != xyes],
8064 [AC_CHECK_FUNC([_doprnt],
8065 [AC_DEFINE([HAVE_DOPRNT], [1],
8066 [Define if _doprnt exists.])])])
8067
8068 If ‘AC_CONFIG_HEADERS’ has been called, then instead of creating
8069 ‘DEFS’, ‘AC_OUTPUT’ creates a header file by substituting the correct
8070 values into ‘#define’ statements in a template file. *Note
8071 Configuration Headers::, for more information about this kind of output.
8072
8073 — Macro: AC_DEFINE(VARIABLE, VALUE, [DESCRIPTION])
8074 — Macro: AC_DEFINE(VARIABLE)
8075 Define VARIABLE to VALUE (verbatim), by defining a C preprocessor
8076 macro for VARIABLE. VARIABLE should be a C identifier, optionally
8077 suffixed by a parenthesized argument list to define a C
8078 preprocessor macro with arguments. The macro argument list, if
8079 present, should be a comma-separated list of C identifiers,
8080 possibly terminated by an ellipsis ‘...’ if C99-or-later syntax is
8081 employed. VARIABLE should not contain comments, white space,
8082 trigraphs, backslash-newlines, universal character names, or
8083 non-ASCII characters.
8084
8085 VALUE may contain backslash-escaped newlines, which will be
8086 preserved if you use ‘AC_CONFIG_HEADERS’ but flattened if passed
8087 via ‘@DEFS@’ (with no effect on the compilation, since the
8088 preprocessor sees only one line in the first place). VALUE should
8089 not contain raw newlines. If you are not using
8090 ‘AC_CONFIG_HEADERS’, VALUE should not contain any ‘#’ characters,
8091 as ‘make’ tends to eat them. To use a shell variable, use
8092 ‘AC_DEFINE_UNQUOTED’ instead.
8093
8094 DESCRIPTION is only useful if you are using ‘AC_CONFIG_HEADERS’.
8095 In this case, DESCRIPTION is put into the generated ‘config.h.in’
8096 as the comment before the macro define. The following example
8097 defines the C preprocessor variable ‘EQUATION’ to be the string
8098 constant ‘"$a > $b"’:
8099
8100 AC_DEFINE([EQUATION], ["$a > $b"],
8101 [Equation string.])
8102
8103 If neither VALUE nor DESCRIPTION are given, then VALUE defaults to
8104 1 instead of to the empty string. This is for backwards
8105 compatibility with older versions of Autoconf, but this usage is
8106 obsolescent and may be withdrawn in future versions of Autoconf.
8107
8108 If the VARIABLE is a literal string, it is passed to
8109 ‘m4_pattern_allow’ (*note Forbidden Patterns::).
8110
8111 If multiple ‘AC_DEFINE’ statements are executed for the same
8112 VARIABLE name (not counting any parenthesized argument list), the
8113 last one wins.
8114
8115 — Macro: AC_DEFINE_UNQUOTED(VARIABLE, VALUE, [DESCRIPTION])
8116 — Macro: AC_DEFINE_UNQUOTED(VARIABLE)
8117 Like ‘AC_DEFINE’, but three shell expansions are performed—once—on
8118 VARIABLE and VALUE: variable expansion (‘$’), command substitution
8119 (‘`’), and backslash escaping (‘\’), as if in an unquoted
8120 here-document. Single and double quote characters in the value
8121 have no special meaning. Use this macro instead of ‘AC_DEFINE’
8122 when VARIABLE or VALUE is a shell variable. Examples:
8123
8124 AC_DEFINE_UNQUOTED([config_machfile], ["$machfile"],
8125 [Configuration machine file.])
8126 AC_DEFINE_UNQUOTED([GETGROUPS_T], [$ac_cv_type_getgroups],
8127 [getgroups return type.])
8128 AC_DEFINE_UNQUOTED([$ac_tr_hdr], [1],
8129 [Translated header name.])
8130
8131 Due to a syntactical oddity of the Bourne shell, do not use
8132 semicolons to separate ‘AC_DEFINE’ or ‘AC_DEFINE_UNQUOTED’ calls from
8133 other macro calls or shell code; that can cause syntax errors in the
8134 resulting ‘configure’ script. Use either blanks or newlines. That is,
8135 do this:
8136
8137 AC_CHECK_HEADER([elf.h],
8138 [AC_DEFINE([SVR4], [1], [System V Release 4]) LIBS="-lelf $LIBS"])
8139
8140 or this:
8141
8142 AC_CHECK_HEADER([elf.h],
8143 [AC_DEFINE([SVR4], [1], [System V Release 4])
8144 LIBS="-lelf $LIBS"])
8145
8146 instead of this:
8147
8148 AC_CHECK_HEADER([elf.h],
8149 [AC_DEFINE([SVR4], [1], [System V Release 4]); LIBS="-lelf $LIBS"])
8150
8151 
8152 File: autoconf.info, Node: Setting Output Variables, Next: Special Chars in Variables, Prev: Defining Symbols, Up: Results
8153
8154 7.2 Setting Output Variables
8155 ============================
8156
8157 Another way to record the results of tests is to set “output variables”,
8158 which are shell variables whose values are substituted into files that
8159 ‘configure’ outputs. The two macros below create new output variables.
8160 *Note Preset Output Variables::, for a list of output variables that are
8161 always available.
8162
8163 — Macro: AC_SUBST(VARIABLE, [VALUE])
8164 Create an output variable from a shell variable. Make ‘AC_OUTPUT’
8165 substitute the variable VARIABLE into output files (typically one
8166 or more makefiles). This means that ‘AC_OUTPUT’ replaces instances
8167 of ‘@VARIABLE@’ in input files with the value that the shell
8168 variable VARIABLE has when ‘AC_OUTPUT’ is called. The value can
8169 contain any non-‘NUL’ character, including newline. If you are
8170 using Automake 1.11 or newer, for newlines in values you might want
8171 to consider using ‘AM_SUBST_NOTMAKE’ to prevent ‘automake’ from
8172 adding a line ‘VARIABLE = @VARIABLE@’ to the ‘Makefile.in’ files
8173 (*note Automake: (automake)Optional.).
8174
8175 Variable occurrences should not overlap: e.g., an input file should
8176 not contain ‘@VAR1@VAR2@’ if VAR1 and VAR2 are variable names. The
8177 substituted value is not rescanned for more output variables;
8178 occurrences of ‘@VARIABLE@’ in the value are inserted literally
8179 into the output file. (The algorithm uses the special marker
8180 ‘|#_!!_#|’ internally, so neither the substituted value nor the
8181 output file may contain ‘|#_!!_#|’.)
8182
8183 If VALUE is given, in addition assign it to VARIABLE.
8184
8185 The string VARIABLE is passed to ‘m4_pattern_allow’ (*note
8186 Forbidden Patterns::). VARIABLE is not further expanded, even if
8187 there is another macro by the same name.
8188
8189 — Macro: AC_SUBST_FILE(VARIABLE)
8190 Another way to create an output variable from a shell variable.
8191 Make ‘AC_OUTPUT’ insert (without substitutions) the contents of the
8192 file named by shell variable VARIABLE into output files. This
8193 means that ‘AC_OUTPUT’ replaces instances of ‘@VARIABLE@’ in output
8194 files (such as ‘Makefile.in’) with the contents of the file that
8195 the shell variable VARIABLE names when ‘AC_OUTPUT’ is called. Set
8196 the variable to ‘/dev/null’ for cases that do not have a file to
8197 insert. This substitution occurs only when the ‘@VARIABLE@’ is on
8198 a line by itself, optionally surrounded by spaces and tabs. The
8199 substitution replaces the whole line, including the spaces, tabs,
8200 and the terminating newline.
8201
8202 This macro is useful for inserting makefile fragments containing
8203 special dependencies or other ‘make’ directives for particular host
8204 or target types into makefiles. For example, ‘configure.ac’ could
8205 contain:
8206
8207 AC_SUBST_FILE([host_frag])
8208 host_frag=$srcdir/conf/sun4.mh
8209
8210 and then a ‘Makefile.in’ could contain:
8211
8212 @host_frag@
8213
8214 The string VARIABLE is passed to ‘m4_pattern_allow’ (*note
8215 Forbidden Patterns::).
8216
8217 Running ‘configure’ in varying environments can be extremely
8218 dangerous. If for instance the user runs ‘CC=bizarre-cc ./configure’,
8219 then the cache, ‘config.h’, and many other output files depend upon
8220 ‘bizarre-cc’ being the C compiler. If for some reason the user runs
8221 ‘./configure’ again, or if it is run via ‘./config.status --recheck’,
8222 (*Note Automatic Remaking::, and *note config.status Invocation::), then
8223 the configuration can be inconsistent, composed of results depending
8224 upon two different compilers.
8225
8226 Environment variables that affect this situation, such as ‘CC’ above,
8227 are called “precious variables”, and can be declared as such by
8228 ‘AC_ARG_VAR’.
8229
8230 — Macro: AC_ARG_VAR(VARIABLE, DESCRIPTION)
8231 Declare VARIABLE is a precious variable, and include its
8232 DESCRIPTION in the variable section of ‘./configure --help’.
8233
8234 Being precious means that
8235 − VARIABLE is substituted via ‘AC_SUBST’.
8236
8237 − The value of VARIABLE when ‘configure’ was launched is saved
8238 in the cache, including if it was not specified on the command
8239 line but via the environment. Indeed, while ‘configure’ can
8240 notice the definition of ‘CC’ in ‘./configure CC=bizarre-cc’,
8241 it is impossible to notice it in ‘CC=bizarre-cc ./configure’,
8242 which, unfortunately, is what most users do.
8243
8244 We emphasize that it is the _initial_ value of VARIABLE which
8245 is saved, not that found during the execution of ‘configure’.
8246 Indeed, specifying ‘./configure FOO=foo’ and letting
8247 ‘./configure’ guess that ‘FOO’ is ‘foo’ can be two different
8248 things.
8249
8250 − VARIABLE is checked for consistency between two ‘configure’
8251 runs. For instance:
8252
8253 $ ./configure --silent --config-cache
8254 $ CC=cc ./configure --silent --config-cache
8255 configure: error: 'CC' was not set in the previous run
8256 configure: error: changes in the environment can compromise \
8257 the build
8258 configure: error: run 'make distclean' and/or \
8259 'rm config.cache' and start over
8260
8261 and similarly if the variable is unset, or if its content is
8262 changed. If the content has white space changes only, then
8263 the error is degraded to a warning only, but the old value is
8264 reused.
8265
8266 − VARIABLE is kept during automatic reconfiguration (*note
8267 config.status Invocation::) as if it had been passed as a
8268 command line argument, including when no cache is used:
8269
8270 $ CC=/usr/bin/cc ./configure var=raboof --silent
8271 $ ./config.status --recheck
8272 running CONFIG_SHELL=/bin/sh /bin/sh ./configure var=raboof \
8273 CC=/usr/bin/cc --no-create --no-recursion
8274
8275 
8276 File: autoconf.info, Node: Special Chars in Variables, Next: Caching Results, Prev: Setting Output Variables, Up: Results
8277
8278 7.3 Special Characters in Output Variables
8279 ==========================================
8280
8281 Many output variables are intended to be evaluated both by ‘make’ and by
8282 the shell. Some characters are expanded differently in these two
8283 contexts, so to avoid confusion these variables’ values should not
8284 contain any of the following characters:
8285
8286 " # $ & ' ( ) * ; < > ? [ \ ^ ` |
8287
8288 Also, these variables’ values should neither contain newlines, nor
8289 start with ‘~’, nor contain white space or ‘:’ immediately followed by
8290 ‘~’. The values can contain nonempty sequences of white space
8291 characters like tabs and spaces, but each such sequence might
8292 arbitrarily be replaced by a single space during substitution.
8293
8294 These restrictions apply both to the values that ‘configure’
8295 computes, and to the values set directly by the user. For example, the
8296 following invocations of ‘configure’ are problematic, since they attempt
8297 to use special characters within ‘CPPFLAGS’ and white space within
8298 ‘$(srcdir)’:
8299
8300 CPPFLAGS='-DOUCH="&\"#$*?"' '../My Source/ouch-1.0/configure'
8301
8302 '../My Source/ouch-1.0/configure' CPPFLAGS='-DOUCH="&\"#$*?"'
8303
8304 
8305 File: autoconf.info, Node: Caching Results, Next: Printing Messages, Prev: Special Chars in Variables, Up: Results
8306
8307 7.4 Caching Results
8308 ===================
8309
8310 To avoid checking for the same features repeatedly in various
8311 ‘configure’ scripts (or in repeated runs of one script), ‘configure’ can
8312 optionally save the results of many checks in a “cache file” (*note
8313 Cache Files::). If a ‘configure’ script runs with caching enabled and
8314 finds a cache file, it reads the results of previous runs from the cache
8315 and avoids rerunning those checks. As a result, ‘configure’ can then
8316 run much faster than if it had to perform all of the checks every time.
8317
8318 — Macro: AC_CACHE_VAL(CACHE-ID, COMMANDS-TO-SET-IT)
8319 Ensure that the results of the check identified by CACHE-ID are
8320 available. If the results of the check were in the cache file that
8321 was read, and ‘configure’ was not given the ‘--quiet’ or ‘--silent’
8322 option, print a message saying that the result was cached;
8323 otherwise, run the shell commands COMMANDS-TO-SET-IT. If the shell
8324 commands are run to determine the value, the value is saved in the
8325 cache file just before ‘configure’ creates its output files. *Note
8326 Cache Variable Names::, for how to choose the name of the CACHE-ID
8327 variable.
8328
8329 The COMMANDS-TO-SET-IT _must have no side effects_ except for
8330 setting the variable CACHE-ID, see below.
8331
8332 — Macro: AC_CACHE_CHECK(MESSAGE, CACHE-ID, COMMANDS-TO-SET-IT)
8333 A wrapper for ‘AC_CACHE_VAL’ that takes care of printing the
8334 messages. This macro provides a convenient shorthand for the most
8335 common way to use these macros. It calls ‘AC_MSG_CHECKING’ for
8336 MESSAGE, then ‘AC_CACHE_VAL’ with the CACHE-ID and COMMANDS
8337 arguments, and ‘AC_MSG_RESULT’ with CACHE-ID.
8338
8339 The COMMANDS-TO-SET-IT _must have no side effects_ except for
8340 setting the variable CACHE-ID, see below.
8341
8342 It is common to find buggy macros using ‘AC_CACHE_VAL’ or
8343 ‘AC_CACHE_CHECK’, because people are tempted to call ‘AC_DEFINE’ in the
8344 COMMANDS-TO-SET-IT. Instead, the code that _follows_ the call to
8345 ‘AC_CACHE_VAL’ should call ‘AC_DEFINE’, by examining the value of the
8346 cache variable. For instance, the following macro is broken:
8347
8348 AC_DEFUN([AC_SHELL_TRUE],
8349 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
8350 [my_cv_shell_true_works=no
8351 (true) 2>/dev/null && my_cv_shell_true_works=yes
8352 if test "x$my_cv_shell_true_works" = xyes; then
8353 AC_DEFINE([TRUE_WORKS], [1],
8354 [Define if 'true(1)' works properly.])
8355 fi])
8356 ])
8357
8358 This fails if the cache is enabled: the second time this macro is run,
8359 ‘TRUE_WORKS’ _will not be defined_. The proper implementation is:
8360
8361 AC_DEFUN([AC_SHELL_TRUE],
8362 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
8363 [my_cv_shell_true_works=no
8364 (true) 2>/dev/null && my_cv_shell_true_works=yes])
8365 if test "x$my_cv_shell_true_works" = xyes; then
8366 AC_DEFINE([TRUE_WORKS], [1],
8367 [Define if 'true(1)' works properly.])
8368 fi
8369 ])
8370
8371 Also, COMMANDS-TO-SET-IT should not print any messages, for example
8372 with ‘AC_MSG_CHECKING’; do that before calling ‘AC_CACHE_VAL’, so the
8373 messages are printed regardless of whether the results of the check are
8374 retrieved from the cache or determined by running the shell commands.
8375
8376 * Menu:
8377
8378 * Cache Variable Names:: Shell variables used in caches
8379 * Cache Files:: Files ‘configure’ uses for caching
8380 * Cache Checkpointing:: Loading and saving the cache file
8381
8382 
8383 File: autoconf.info, Node: Cache Variable Names, Next: Cache Files, Up: Caching Results
8384
8385 7.4.1 Cache Variable Names
8386 --------------------------
8387
8388 The names of cache variables should have the following format:
8389
8390 PACKAGE-PREFIX_cv_VALUE-TYPE_SPECIFIC-VALUE_[ADDITIONAL-OPTIONS]
8391
8392 for example, ‘ac_cv_header_stat_broken’ or ‘ac_cv_prog_gcc_traditional’.
8393 The parts of the variable name are:
8394
8395 PACKAGE-PREFIX
8396 An abbreviation for your package or organization; the same prefix
8397 you begin local Autoconf macros with, except lowercase by
8398 convention. For cache values used by the distributed Autoconf
8399 macros, this value is ‘ac’.
8400
8401 ‘_cv_’
8402 Indicates that this shell variable is a cache value. This string
8403 _must_ be present in the variable name, including the leading
8404 underscore.
8405
8406 VALUE-TYPE
8407 A convention for classifying cache values, to produce a rational
8408 naming system. The values used in Autoconf are listed in *note
8409 Macro Names::.
8410
8411 SPECIFIC-VALUE
8412 Which member of the class of cache values this test applies to.
8413 For example, which function (‘alloca’), program (‘gcc’), or output
8414 variable (‘INSTALL’).
8415
8416 ADDITIONAL-OPTIONS
8417 Any particular behavior of the specific member that this test
8418 applies to. For example, ‘broken’ or ‘set’. This part of the name
8419 may be omitted if it does not apply.
8420
8421 The values assigned to cache variables may not contain newlines.
8422 Usually, their values are Boolean (‘yes’ or ‘no’) or the names of files
8423 or functions; so this is not an important restriction. *note Cache
8424 Variable Index:: for an index of cache variables with documented
8425 semantics.
8426
8427 
8428 File: autoconf.info, Node: Cache Files, Next: Cache Checkpointing, Prev: Cache Variable Names, Up: Caching Results
8429
8430 7.4.2 Cache Files
8431 -----------------
8432
8433 A cache file is a shell script that caches the results of configure
8434 tests run on one system so they can be shared between configure scripts
8435 and configure runs. It is not useful on other systems. If its contents
8436 are invalid for some reason, the user may delete or edit it, or override
8437 documented cache variables on the ‘configure’ command line.
8438
8439 By default, ‘configure’ uses no cache file, to avoid problems caused
8440 by accidental use of stale cache files.
8441
8442 To enable caching, ‘configure’ accepts ‘--config-cache’ (or ‘-C’) to
8443 cache results in the file ‘config.cache’. Alternatively,
8444 ‘--cache-file=FILE’ specifies that FILE be the cache file. The cache
8445 file is created if it does not exist already. When ‘configure’ calls
8446 ‘configure’ scripts in subdirectories, it uses the ‘--cache-file’
8447 argument so that they share the same cache. *Note Subdirectories::, for
8448 information on configuring subdirectories with the ‘AC_CONFIG_SUBDIRS’
8449 macro.
8450
8451 ‘config.status’ only pays attention to the cache file if it is given
8452 the ‘--recheck’ option, which makes it rerun ‘configure’.
8453
8454 It is wrong to try to distribute cache files for particular system
8455 types. There is too much room for error in doing that, and too much
8456 administrative overhead in maintaining them. For any features that
8457 can’t be guessed automatically, use the standard method of the canonical
8458 system type and linking files (*note Manual Configuration::).
8459
8460 The site initialization script can specify a site-wide cache file to
8461 use, instead of the usual per-program cache. In this case, the cache
8462 file gradually accumulates information whenever someone runs a new
8463 ‘configure’ script. (Running ‘configure’ merges the new cache results
8464 with the existing cache file.) This may cause problems, however, if the
8465 system configuration (e.g., the installed libraries or compilers)
8466 changes and the stale cache file is not deleted.
8467
8468 If ‘configure’ is interrupted at the right time when it updates a
8469 cache file outside of the build directory where the ‘configure’ script
8470 is run, it may leave behind a temporary file named after the cache file
8471 with digits following it. You may safely delete such a file.
8472
8473 
8474 File: autoconf.info, Node: Cache Checkpointing, Prev: Cache Files, Up: Caching Results
8475
8476 7.4.3 Cache Checkpointing
8477 -------------------------
8478
8479 If your configure script, or a macro called from ‘configure.ac’, happens
8480 to abort the configure process, it may be useful to checkpoint the cache
8481 a few times at key points using ‘AC_CACHE_SAVE’. Doing so reduces the
8482 amount of time it takes to rerun the configure script with (hopefully)
8483 the error that caused the previous abort corrected.
8484
8485 — Macro: AC_CACHE_LOAD
8486 Loads values from existing cache file, or creates a new cache file
8487 if a cache file is not found. Called automatically from ‘AC_INIT’.
8488
8489 — Macro: AC_CACHE_SAVE
8490 Flushes all cached values to the cache file. Called automatically
8491 from ‘AC_OUTPUT’, but it can be quite useful to call
8492 ‘AC_CACHE_SAVE’ at key points in ‘configure.ac’.
8493
8494 For instance:
8495
8496 ... AC_INIT, etc. ...
8497 # Checks for programs.
8498 AC_PROG_CC
8499 AC_PROG_AWK
8500 ... more program checks ...
8501 AC_CACHE_SAVE
8502
8503 # Checks for libraries.
8504 AC_CHECK_LIB([nsl], [gethostbyname])
8505 AC_CHECK_LIB([socket], [connect])
8506 ... more lib checks ...
8507 AC_CACHE_SAVE
8508
8509 # Might abort...
8510 AM_PATH_GTK([1.0.2], [], [AC_MSG_ERROR([GTK not in path])])
8511 AM_PATH_GTKMM([0.9.5], [], [AC_MSG_ERROR([GTK not in path])])
8512 ... AC_OUTPUT, etc. ...
8513
8514 
8515 File: autoconf.info, Node: Printing Messages, Prev: Caching Results, Up: Results
8516
8517 7.5 Printing Messages
8518 =====================
8519
8520 ‘configure’ scripts need to give users running them several kinds of
8521 information. The following macros print messages in ways appropriate
8522 for each kind. The arguments to all of them get enclosed in shell
8523 double quotes, so the shell performs variable and back-quote
8524 substitution on them.
8525
8526 These macros are all wrappers around the ‘printf’ shell command.
8527 They direct output to the appropriate file descriptor (*note File
8528 Descriptor Macros::). ‘configure’ scripts should rarely need to run
8529 ‘printf’ directly to print messages for the user. Using these macros
8530 makes it easy to change how and when each kind of message is printed;
8531 such changes need only be made to the macro definitions and all the
8532 callers change automatically.
8533
8534 To diagnose static issues, i.e., when ‘autoconf’ is run, see *note
8535 Diagnostic Macros::.
8536
8537 — Macro: AC_MSG_CHECKING(FEATURE-DESCRIPTION)
8538 Notify the user that ‘configure’ is checking for a particular
8539 feature. This macro prints a message that starts with ‘checking ’
8540 and ends with ‘...’ and no newline. It must be followed by a call
8541 to ‘AC_MSG_RESULT’ to print the result of the check and the
8542 newline. The FEATURE-DESCRIPTION should be something like ‘whether
8543 the Fortran compiler accepts C++ comments’ or ‘for _Alignof’.
8544
8545 This macro prints nothing if ‘configure’ is run with the ‘--quiet’
8546 or ‘--silent’ option.
8547
8548 — Macro: AC_MSG_RESULT(RESULT-DESCRIPTION)
8549 Notify the user of the results of a check. RESULT-DESCRIPTION is
8550 almost always the value of the cache variable for the check,
8551 typically ‘yes’, ‘no’, or a file name. This macro should follow a
8552 call to ‘AC_MSG_CHECKING’, and the RESULT-DESCRIPTION should be the
8553 completion of the message printed by the call to ‘AC_MSG_CHECKING’.
8554
8555 This macro prints nothing if ‘configure’ is run with the ‘--quiet’
8556 or ‘--silent’ option.
8557
8558 — Macro: AC_MSG_NOTICE(MESSAGE)
8559 Deliver the MESSAGE to the user. It is useful mainly to print a
8560 general description of the overall purpose of a group of feature
8561 checks, e.g.,
8562
8563 AC_MSG_NOTICE([checking if stack overflow is detectable])
8564
8565 This macro prints nothing if ‘configure’ is run with the ‘--quiet’
8566 or ‘--silent’ option.
8567
8568 — Macro: AC_MSG_ERROR(ERROR-DESCRIPTION, [EXIT-STATUS = $?/1])
8569 Notify the user of an error that prevents ‘configure’ from
8570 completing. This macro prints an error message to the standard
8571 error output and exits ‘configure’ with EXIT-STATUS (‘$?’ by
8572 default, except that ‘0’ is converted to ‘1’). ERROR-DESCRIPTION
8573 should be something like ‘invalid value $HOME for \$HOME’.
8574
8575 The ERROR-DESCRIPTION should start with a lower-case letter, and
8576 “cannot” is preferred to “can’t”.
8577
8578 — Macro: AC_MSG_FAILURE(ERROR-DESCRIPTION, [EXIT-STATUS])
8579 This ‘AC_MSG_ERROR’ wrapper notifies the user of an error that
8580 prevents ‘configure’ from completing _and_ that additional details
8581 are provided in ‘config.log’. This is typically used when abnormal
8582 results are found during a compilation.
8583
8584 — Macro: AC_MSG_WARN(PROBLEM-DESCRIPTION)
8585 Notify the ‘configure’ user of a possible problem. This macro
8586 prints the message to the standard error output; ‘configure’
8587 continues running afterward, so macros that call ‘AC_MSG_WARN’
8588 should provide a default (back-up) behavior for the situations they
8589 warn about. PROBLEM-DESCRIPTION should be something like ‘ln -s
8590 seems to make hard links’.
8591
8592 
8593 File: autoconf.info, Node: Programming in M4, Next: Programming in M4sh, Prev: Results, Up: Top
8594
8595 8 Programming in M4
8596 *******************
8597
8598 Autoconf is written on top of two layers: “M4sugar”, which provides
8599 convenient macros for pure M4 programming, and “M4sh”, which provides
8600 macros dedicated to shell script generation.
8601
8602 As of this version of Autoconf, these two layers still contain
8603 experimental macros, whose interface might change in the future. As a
8604 matter of fact, _anything that is not documented must not be used_.
8605
8606 * Menu:
8607
8608 * M4 Quotation:: Protecting macros from unwanted expansion
8609 * Using autom4te:: The Autoconf executables backbone
8610 * Programming in M4sugar:: Convenient pure M4 macros
8611 * Debugging via autom4te:: Figuring out what M4 was doing
8612
8613 
8614 File: autoconf.info, Node: M4 Quotation, Next: Using autom4te, Up: Programming in M4
8615
8616 8.1 M4 Quotation
8617 ================
8618
8619 The most common problem with existing macros is an improper quotation.
8620 This section, which users of Autoconf can skip, but which macro writers
8621 _must_ read, first justifies the quotation scheme that was chosen for
8622 Autoconf and then ends with a rule of thumb. Understanding the former
8623 helps one to follow the latter.
8624
8625 * Menu:
8626
8627 * Active Characters:: Characters that change the behavior of M4
8628 * One Macro Call:: Quotation and one macro call
8629 * Quoting and Parameters:: M4 vs. shell parameters
8630 * Quotation and Nested Macros:: Macros calling macros
8631 * Changequote is Evil:: Worse than INTERCAL: M4 + changequote
8632 * Quadrigraphs:: Another way to escape special characters
8633 * Balancing Parentheses:: Dealing with unbalanced parentheses
8634 * Quotation Rule Of Thumb:: One parenthesis, one quote
8635
8636 
8637 File: autoconf.info, Node: Active Characters, Next: One Macro Call, Up: M4 Quotation
8638
8639 8.1.1 Active Characters
8640 -----------------------
8641
8642 To fully understand where proper quotation is important, you first need
8643 to know what the special characters are in Autoconf: ‘#’ introduces a
8644 comment inside which no macro expansion is performed, ‘,’ separates
8645 arguments, ‘[’ and ‘]’ are the quotes themselves(1), ‘(’ and ‘)’ (which
8646 M4 tries to match by pairs), and finally ‘$’ inside a macro definition.
8647
8648 In order to understand the delicate case of macro calls, we first
8649 have to present some obvious failures. Below they are “obvious-ified”,
8650 but when you find them in real life, they are usually in disguise.
8651
8652 Comments, introduced by a hash and running up to the newline, are
8653 opaque tokens to the top level: active characters are turned off, and
8654 there is no macro expansion:
8655
8656 # define([def], ine)
8657 ⇒# define([def], ine)
8658
8659 Each time there can be a macro expansion, there is a quotation
8660 expansion, i.e., one level of quotes is stripped:
8661
8662 int tab[10];
8663 ⇒int tab10;
8664 [int tab[10];]
8665 ⇒int tab[10];
8666
8667 Without this in mind, the reader might try hopelessly to use her
8668 macro ‘array’:
8669
8670 define([array], [int tab[10];])
8671 array
8672 ⇒int tab10;
8673 [array]
8674 ⇒array
8675
8676 How can you correctly output the intended results(2)?
8677
8678 ---------- Footnotes ----------
8679
8680 (1) By itself, M4 uses ‘`’ and ‘'’; it is the M4sugar layer that sets
8681 up the preferred quotes of ‘[’ and ‘]’.
8682
8683 (2) Using ‘defn’.
8684
8685 
8686 File: autoconf.info, Node: One Macro Call, Next: Quoting and Parameters, Prev: Active Characters, Up: M4 Quotation
8687
8688 8.1.2 One Macro Call
8689 --------------------
8690
8691 Let’s proceed on the interaction between active characters and macros
8692 with this small macro, which just returns its first argument:
8693
8694 define([car], [$1])
8695
8696 The two pairs of quotes above are not part of the arguments of ‘define’;
8697 rather, they are understood by the top level when it tries to find the
8698 arguments of ‘define’. Therefore, assuming ‘car’ is not already
8699 defined, it is equivalent to write:
8700
8701 define(car, $1)
8702
8703 But, while it is acceptable for a ‘configure.ac’ to avoid unnecessary
8704 quotes, it is bad practice for Autoconf macros which must both be more
8705 robust and also advocate perfect style.
8706
8707 At the top level, there are only two possibilities: either you quote
8708 or you don’t:
8709
8710 car(foo, bar, baz)
8711 ⇒foo
8712 [car(foo, bar, baz)]
8713 ⇒car(foo, bar, baz)
8714
8715 Let’s pay attention to the special characters:
8716
8717 car(#)
8718 error→EOF in argument list
8719
8720 The closing parenthesis is hidden in the comment; with a hypothetical
8721 quoting, the top level understood it this way:
8722
8723 car([#)]
8724
8725 Proper quotation, of course, fixes the problem:
8726
8727 car([#])
8728 ⇒#
8729
8730 Here are more examples:
8731
8732 car(foo, bar)
8733 ⇒foo
8734 car([foo, bar])
8735 ⇒foo, bar
8736 car((foo, bar))
8737 ⇒(foo, bar)
8738 car([(foo], [bar)])
8739 ⇒(foo
8740 define([a], [b])
8741 ⇒
8742 car(a)
8743 ⇒b
8744 car([a])
8745 ⇒b
8746 car([[a]])
8747 ⇒a
8748 car([[[a]]])
8749 ⇒[a]
8750
8751 
8752 File: autoconf.info, Node: Quoting and Parameters, Next: Quotation and Nested Macros, Prev: One Macro Call, Up: M4 Quotation
8753
8754 8.1.3 Quoting and Parameters
8755 ----------------------------
8756
8757 When M4 encounters ‘$’ within a macro definition, followed immediately
8758 by a character it recognizes (‘0’...‘9’, ‘#’, ‘@’, or ‘*’), it will
8759 perform M4 parameter expansion. This happens regardless of how many
8760 layers of quotes the parameter expansion is nested within, or even if it
8761 occurs in text that will be rescanned as a comment.
8762
8763 define([none], [$1])
8764 ⇒
8765 define([one], [[$1]])
8766 ⇒
8767 define([two], [[[$1]]])
8768 ⇒
8769 define([comment], [# $1])
8770 ⇒
8771 define([active], [ACTIVE])
8772 ⇒
8773 none([active])
8774 ⇒ACTIVE
8775 one([active])
8776 ⇒active
8777 two([active])
8778 ⇒[active]
8779 comment([active])
8780 ⇒# active
8781
8782 On the other hand, since autoconf generates shell code, you often
8783 want to output shell variable expansion, rather than performing M4
8784 parameter expansion. To do this, you must use M4 quoting to separate
8785 the ‘$’ from the next character in the definition of your macro. If the
8786 macro definition occurs in single-quoted text, then insert another level
8787 of quoting; if the usage is already inside a double-quoted string, then
8788 split it into concatenated strings.
8789
8790 define([foo], [a single-quoted $[]1 definition])
8791 ⇒
8792 define([bar], [[a double-quoted $][1 definition]])
8793 ⇒
8794 foo
8795 ⇒a single-quoted $1 definition
8796 bar
8797 ⇒a double-quoted $1 definition
8798
8799 POSIX states that M4 implementations are free to provide
8800 implementation extensions when ‘${’ is encountered in a macro
8801 definition. Autoconf reserves the longer sequence ‘${{’ for use with
8802 planned extensions that will be available in the future GNU M4 2.0, but
8803 guarantees that all other instances of ‘${’ will be output literally.
8804 Therefore, this idiom can also be used to output shell code parameter
8805 references:
8806
8807 define([first], [${1}])first
8808 ⇒${1}
8809
8810 POSIX also states that ‘$11’ should expand to the first parameter
8811 concatenated with a literal ‘1’, although some versions of GNU M4 expand
8812 the eleventh parameter instead. For portability, you should only use
8813 single-digit M4 parameter expansion.
8814
8815 With this in mind, we can explore the cases where macros invoke
8816 macros...
8817
8818 
8819 File: autoconf.info, Node: Quotation and Nested Macros, Next: Changequote is Evil, Prev: Quoting and Parameters, Up: M4 Quotation
8820
8821 8.1.4 Quotation and Nested Macros
8822 ---------------------------------
8823
8824 The examples below use the following macros:
8825
8826 define([car], [$1])
8827 define([active], [ACT, IVE])
8828 define([array], [int tab[10]])
8829
8830 Each additional embedded macro call introduces other possible
8831 interesting quotations:
8832
8833 car(active)
8834 ⇒ACT
8835 car([active])
8836 ⇒ACT, IVE
8837 car([[active]])
8838 ⇒active
8839
8840 In the first case, the top level looks for the arguments of ‘car’,
8841 and finds ‘active’. Because M4 evaluates its arguments before applying
8842 the macro, ‘active’ is expanded, which results in:
8843
8844 car(ACT, IVE)
8845 ⇒ACT
8846
8847 In the second case, the top level gives ‘active’ as first and only
8848 argument of ‘car’, which results in:
8849
8850 active
8851 ⇒ACT, IVE
8852
8853 i.e., the argument is evaluated _after_ the macro that invokes it. In
8854 the third case, ‘car’ receives ‘[active]’, which results in:
8855
8856 [active]
8857 ⇒active
8858
8859 exactly as we already saw above.
8860
8861 The example above, applied to a more realistic example, gives:
8862
8863 car(int tab[10];)
8864 ⇒int tab10;
8865 car([int tab[10];])
8866 ⇒int tab10;
8867 car([[int tab[10];]])
8868 ⇒int tab[10];
8869
8870 Huh? The first case is easily understood, but why is the second wrong,
8871 and the third right? To understand that, you must know that after M4
8872 expands a macro, the resulting text is immediately subjected to macro
8873 expansion and quote removal. This means that the quote removal occurs
8874 twice—first before the argument is passed to the ‘car’ macro, and second
8875 after the ‘car’ macro expands to the first argument.
8876
8877 As the author of the Autoconf macro ‘car’, you then consider it to be
8878 incorrect that your users have to double-quote the arguments of ‘car’,
8879 so you “fix” your macro. Let’s call it ‘qar’ for quoted car:
8880
8881 define([qar], [[$1]])
8882
8883 and check that ‘qar’ is properly fixed:
8884
8885 qar([int tab[10];])
8886 ⇒int tab[10];
8887
8888 Ahhh! That’s much better.
8889
8890 But note what you’ve done: now that the result of ‘qar’ is always a
8891 literal string, the only time a user can use nested macros is if she
8892 relies on an _unquoted_ macro call:
8893
8894 qar(active)
8895 ⇒ACT
8896 qar([active])
8897 ⇒active
8898
8899 leaving no way for her to reproduce what she used to do with ‘car’:
8900
8901 car([active])
8902 ⇒ACT, IVE
8903
8904 Worse yet: she wants to use a macro that produces a set of ‘cpp’ macros:
8905
8906 define([my_includes], [#include <stdio.h>])
8907 car([my_includes])
8908 ⇒#include <stdio.h>
8909 qar(my_includes)
8910 error→EOF in argument list
8911
8912 This macro, ‘qar’, because it double quotes its arguments, forces its
8913 users to leave their macro calls unquoted, which is dangerous. Commas
8914 and other active symbols are interpreted by M4 before they are given to
8915 the macro, often not in the way the users expect. Also, because ‘qar’
8916 behaves differently from the other macros, it’s an exception that should
8917 be avoided in Autoconf.
8918
8919 
8920 File: autoconf.info, Node: Changequote is Evil, Next: Quadrigraphs, Prev: Quotation and Nested Macros, Up: M4 Quotation
8921
8922 8.1.5 ‘changequote’ is Evil
8923 ---------------------------
8924
8925 The temptation is often high to bypass proper quotation, in particular
8926 when it’s late at night. Then, many experienced Autoconf hackers
8927 finally surrender to the dark side of the force and use the ultimate
8928 weapon: ‘changequote’.
8929
8930 The M4 builtin ‘changequote’ belongs to a set of primitives that
8931 allow one to adjust the syntax of the language to adjust it to one’s
8932 needs. For instance, by default M4 uses ‘`’ and ‘'’ as quotes, but in
8933 the context of shell programming (and actually of most programming
8934 languages), that’s about the worst choice one can make: because of
8935 strings and back-quoted expressions in shell code (such as ‘'this'’ and
8936 ‘`that`’), and because of literal characters in usual programming
8937 languages (as in ‘'0'’), there are many unbalanced ‘`’ and ‘'’. Proper
8938 M4 quotation then becomes a nightmare, if not impossible. In order to
8939 make M4 useful in such a context, its designers have equipped it with
8940 ‘changequote’, which makes it possible to choose another pair of quotes.
8941 M4sugar, M4sh, Autoconf, and Autotest all have chosen to use ‘[’ and
8942 ‘]’. Not especially because they are unlikely characters, but _because
8943 they are characters unlikely to be unbalanced_.
8944
8945 There are other magic primitives, such as ‘changecom’ to specify what
8946 syntactic forms are comments (it is common to see ‘changecom(<!--, -->)’
8947 when M4 is used to produce HTML pages), ‘changeword’ and ‘changesyntax’
8948 to change other syntactic details (such as the character to denote the
8949 Nth argument, ‘$’ by default, the parentheses around arguments, etc.).
8950
8951 These primitives are really meant to make M4 more useful for specific
8952 domains: they should be considered like command line options:
8953 ‘--quotes’, ‘--comments’, ‘--words’, and ‘--syntax’. Nevertheless, they
8954 are implemented as M4 builtins, as it makes M4 libraries self contained
8955 (no need for additional options).
8956
8957 There lies the problem...
8958
8959
8960 The problem is that it is then tempting to use them in the middle of
8961 an M4 script, as opposed to its initialization. This, if not carefully
8962 thought out, can lead to disastrous effects: _you are changing the
8963 language in the middle of the execution_. Changing and restoring the
8964 syntax is often not enough: if you happened to invoke macros in between,
8965 these macros are lost, as the current syntax is probably not the one
8966 they were implemented with.
8967
8968 
8969 File: autoconf.info, Node: Quadrigraphs, Next: Balancing Parentheses, Prev: Changequote is Evil, Up: M4 Quotation
8970
8971 8.1.6 Quadrigraphs
8972 ------------------
8973
8974 When writing an Autoconf macro you may occasionally need to generate
8975 special characters that are difficult to express with the standard
8976 Autoconf quoting rules. For example, you may need to output the regular
8977 expression ‘[^[]’, which matches any character other than ‘[’. This
8978 expression contains unbalanced brackets so it cannot be put easily into
8979 an M4 macro.
8980
8981 Additionally, there are a few m4sugar macros (such as ‘m4_split’ and
8982 ‘m4_expand’) which internally use special markers in addition to the
8983 regular quoting characters. If the arguments to these macros contain
8984 the literal strings ‘-=<{(’ or ‘)}>=-’, the macros might behave
8985 incorrectly.
8986
8987 You can work around these problems by using one of the following
8988 “quadrigraphs”:
8989
8990 ‘@<:@’
8991 ‘[’
8992 ‘@:>@’
8993 ‘]’
8994 ‘@S|@’
8995 ‘$’
8996 ‘@%:@’
8997 ‘#’
8998 ‘@{:@’
8999 ‘(’
9000 ‘@:}@’
9001 ‘)’
9002 ‘@&t@’
9003 Expands to nothing.
9004
9005 Quadrigraphs are replaced at a late stage of the translation process,
9006 after ‘m4’ is run, so they do not get in the way of M4 quoting. For
9007 example, the string ‘^@<:@’, independently of its quotation, appears as
9008 ‘^[’ in the output.
9009
9010 The empty quadrigraph can be used:
9011
9012 − to mark trailing spaces explicitly
9013
9014 Trailing spaces are smashed by ‘autom4te’. This is a feature.
9015
9016 − to produce quadrigraphs and other strings reserved by m4sugar
9017
9018 For instance ‘@<@&t@:@’ produces ‘@<:@’. For a more contrived
9019 example:
9020
9021 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
9022 m4_split([a )}>=- b -=<{( c])
9023 ⇒[a], [], [B], [], [c]
9024 m4_split([a )}@&t@>=- b -=<@&t@{( c])
9025 ⇒[a], [)}>=-], [b], [-=<{(], [c]
9026
9027 − to escape _occurrences_ of forbidden patterns
9028
9029 For instance you might want to mention ‘AC_FOO’ in a comment, while
9030 still being sure that ‘autom4te’ still catches unexpanded ‘AC_*’.
9031 Then write ‘AC@&t@_FOO’.
9032
9033 The name ‘@&t@’ was suggested by Paul Eggert:
9034
9035 I should give some credit to the ‘@&t@’ pun. The ‘&’ is my own
9036 invention, but the ‘t’ came from the source code of the ALGOL68C
9037 compiler, written by Steve Bourne (of Bourne shell fame), and which
9038 used ‘mt’ to denote the empty string. In C, it would have looked
9039 like something like:
9040
9041 char const mt[] = "";
9042
9043 but of course the source code was written in Algol 68.
9044
9045 I don’t know where he got ‘mt’ from: it could have been his own
9046 invention, and I suppose it could have been a common pun around the
9047 Cambridge University computer lab at the time.
9048
9049 
9050 File: autoconf.info, Node: Balancing Parentheses, Next: Quotation Rule Of Thumb, Prev: Quadrigraphs, Up: M4 Quotation
9051
9052 8.1.7 Dealing with unbalanced parentheses
9053 -----------------------------------------
9054
9055 One of the pitfalls of portable shell programming is that if you intend
9056 your script to run with obsolescent shells, ‘case’ statements require
9057 unbalanced parentheses. *Note Limitations of Shell Builtins: case.
9058 With syntax highlighting editors, the presence of unbalanced ‘)’ can
9059 interfere with editors that perform syntax highlighting of macro
9060 contents based on finding the matching ‘(’. Another concern is how much
9061 editing must be done when transferring code snippets between shell
9062 scripts and macro definitions. But most importantly, the presence of
9063 unbalanced parentheses can introduce expansion bugs.
9064
9065 For an example, here is an underquoted attempt to use the macro
9066 ‘my_case’, which happens to expand to a portable ‘case’ statement:
9067
9068 AC_DEFUN([my_case],
9069 [case $file_name in
9070 *.c) file_type='C source code';;
9071 esac])
9072 AS_IF(:, my_case)
9073
9074 In the above example, the ‘AS_IF’ call under-quotes its arguments. As a
9075 result, the unbalanced ‘)’ generated by the premature expansion of
9076 ‘my_case’ results in expanding ‘AS_IF’ with a truncated parameter, and
9077 the expansion is syntactically invalid:
9078
9079 if :
9080 then :
9081 case $file_name in
9082 *.c
9083 fi file_type='C source code';;
9084 esac)
9085
9086 If nothing else, this should emphasize the importance of the quoting
9087 arguments to macro calls. On the other hand, there are several
9088 variations for defining ‘my_case’ to be more robust, even when used
9089 without proper quoting, each with some benefits and some drawbacks.
9090
9091 Use left parenthesis before pattern
9092 AC_DEFUN([my_case],
9093 [case $file_name in
9094 (*.c) file_type='C source code';;
9095 esac])
9096 This is simple and provides balanced parentheses. Although this is
9097 not portable to obsolescent shells (notably Solaris 10 ‘/bin/sh’),
9098 platforms with these shells invariably have a more-modern shell
9099 available somewhere so this approach typically suffices nowadays.
9100
9101 Creative literal shell comment
9102 AC_DEFUN([my_case],
9103 [case $file_name in #(
9104 *.c) file_type='C source code';;
9105 esac])
9106 This version provides balanced parentheses to several editors, and
9107 can be copied and pasted into a terminal as is. Unfortunately, it
9108 is still unbalanced as an Autoconf argument, since ‘#(’ is an M4
9109 comment that masks the normal properties of ‘(’.
9110
9111 Quadrigraph shell comment
9112 AC_DEFUN([my_case],
9113 [case $file_name in @%:@(
9114 *.c) file_type='C source code';;
9115 esac])
9116 This version provides balanced parentheses to even more editors,
9117 and can be used as a balanced Autoconf argument. Unfortunately, it
9118 requires some editing before it can be copied and pasted into a
9119 terminal, and the use of the quadrigraph ‘@%:@’ for ‘#’ reduces
9120 readability.
9121
9122 Quoting just the parenthesis
9123 AC_DEFUN([my_case],
9124 [case $file_name in
9125 *.c[)] file_type='C source code';;
9126 esac])
9127 This version quotes the ‘)’, so that it can be used as a balanced
9128 Autoconf argument. As written, this is not balanced to an editor,
9129 but it can be coupled with ‘[#(]’ to meet that need, too. However,
9130 it still requires some edits before it can be copied and pasted
9131 into a terminal.
9132
9133 Double-quoting the entire statement
9134 AC_DEFUN([my_case],
9135 [[case $file_name in #(
9136 *.c) file_type='C source code';;
9137 esac]])
9138 Since the entire macro is double-quoted, there is no problem with
9139 using this as an Autoconf argument; and since the double-quoting is
9140 over the entire statement, this code can be easily copied and
9141 pasted into a terminal. However, the double quoting prevents the
9142 expansion of any macros inside the case statement, which may cause
9143 its own set of problems.
9144
9145 Using ‘AS_CASE’
9146 AC_DEFUN([my_case],
9147 [AS_CASE([$file_name],
9148 [*.c], [file_type='C source code'])])
9149 This version avoids the balancing issue altogether, by relying on
9150 ‘AS_CASE’ (*note Common Shell Constructs::); it also allows for the
9151 expansion of ‘AC_REQUIRE’ to occur prior to the entire case
9152 statement, rather than within a branch of the case statement that
9153 might not be taken. However, the abstraction comes with a penalty
9154 that it is no longer a quick copy, paste, and edit to get back to
9155 shell code.
9156
9157 
9158 File: autoconf.info, Node: Quotation Rule Of Thumb, Prev: Balancing Parentheses, Up: M4 Quotation
9159
9160 8.1.8 Quotation Rule Of Thumb
9161 -----------------------------
9162
9163 To conclude, the quotation rule of thumb is:
9164
9165 _One pair of quotes per pair of parentheses._
9166
9167 Never over-quote, never under-quote, in particular in the definition
9168 of macros. In the few places where the macros need to use brackets
9169 (usually in C program text or regular expressions), properly quote _the
9170 arguments_!
9171
9172 It is common to read Autoconf programs with snippets like:
9173
9174 AC_TRY_LINK(
9175 changequote(<<, >>)dnl
9176 <<#include <time.h>
9177 #ifndef tzname /* For SGI. */
9178 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
9179 #endif>>,
9180 changequote([, ])dnl
9181 [atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)
9182
9183 which is incredibly useless since ‘AC_TRY_LINK’ is _already_ double
9184 quoting, so you just need:
9185
9186 AC_TRY_LINK(
9187 [#include <time.h>
9188 #ifndef tzname /* For SGI. */
9189 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
9190 #endif],
9191 [atoi (*tzname);],
9192 [ac_cv_var_tzname=yes],
9193 [ac_cv_var_tzname=no])
9194
9195 The M4-fluent reader might note that these two examples are rigorously
9196 equivalent, since M4 swallows both the ‘changequote(<<, >>)’ and ‘<<’
9197 ‘>>’ when it “collects” the arguments: these quotes are not part of the
9198 arguments!
9199
9200 Simplified, the example above is just doing this:
9201
9202 changequote(<<, >>)dnl
9203 <<[]>>
9204 changequote([, ])dnl
9205
9206 instead of simply:
9207
9208 [[]]
9209
9210 With macros that do not double quote their arguments (which is the
9211 rule), double-quote the (risky) literals:
9212
9213 AC_LINK_IFELSE([AC_LANG_PROGRAM(
9214 [[#include <time.h>
9215 #ifndef tzname /* For SGI. */
9216 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
9217 #endif]],
9218 [atoi (*tzname);])],
9219 [ac_cv_var_tzname=yes],
9220 [ac_cv_var_tzname=no])
9221
9222 Please note that the macro ‘AC_TRY_LINK’ is obsolete, so you really
9223 should be using ‘AC_LINK_IFELSE’ instead.
9224
9225 *Note Quadrigraphs::, for what to do if you run into a hopeless case
9226 where quoting does not suffice.
9227
9228 When you create a ‘configure’ script using newly written macros,
9229 examine it carefully to check whether you need to add more quotes in
9230 your macros. If one or more words have disappeared in the M4 output,
9231 you need more quotes. When in doubt, quote.
9232
9233 However, it’s also possible to put on too many layers of quotes. If
9234 this happens, the resulting ‘configure’ script may contain unexpanded
9235 macros. The ‘autoconf’ program checks for this problem by looking for
9236 the string ‘AC_’ in ‘configure’. However, this heuristic does not work
9237 in general: for example, it does not catch overquoting in ‘AC_DEFINE’
9238 descriptions.
9239
9240 
9241 File: autoconf.info, Node: Using autom4te, Next: Programming in M4sugar, Prev: M4 Quotation, Up: Programming in M4
9242
9243 8.2 Using ‘autom4te’
9244 ====================
9245
9246 The Autoconf suite, including M4sugar, M4sh, and Autotest, in addition
9247 to Autoconf per se, heavily rely on M4. All these different uses
9248 revealed common needs factored into a layer over M4: ‘autom4te’(1).
9249
9250 ‘autom4te’ is a preprocessor that is like ‘m4’. It supports M4
9251 extensions designed for use in tools like Autoconf.
9252
9253 * Menu:
9254
9255 * autom4te Invocation:: A GNU M4 wrapper
9256 * Customizing autom4te:: Customizing the Autoconf package
9257
9258 ---------- Footnotes ----------
9259
9260 (1) Yet another great name from Lars J. Aas.
9261
9262 
9263 File: autoconf.info, Node: autom4te Invocation, Next: Customizing autom4te, Up: Using autom4te
9264
9265 8.2.1 Invoking ‘autom4te’
9266 -------------------------
9267
9268 The command line arguments are modeled after M4’s:
9269
9270 autom4te OPTIONS FILES
9271
9272 where the FILES are directly passed to ‘m4’. By default, GNU M4 is
9273 found during configuration, but the environment variable ‘M4’ can be set
9274 to tell ‘autom4te’ where to look. In addition to the regular expansion,
9275 it handles the replacement of the quadrigraphs (*note Quadrigraphs::),
9276 and of ‘__oline__’, the current line in the output. It supports an
9277 extended syntax for the FILES:
9278
9279 ‘FILE.m4f’
9280 This file is an M4 frozen file. Note that _all the previous files
9281 are ignored_. See the ‘--melt’ option for the rationale.
9282
9283 ‘FILE?’
9284 If found in the library path, the FILE is included for expansion,
9285 otherwise it is ignored instead of triggering a failure.
9286
9287
9288 Of course, it supports the Autoconf common subset of options:
9289
9290 ‘--help’
9291 ‘-h’
9292 Print a summary of the command line options and exit.
9293
9294 ‘--version’
9295 ‘-V’
9296 Print the version number of Autoconf and exit.
9297
9298 ‘--verbose’
9299 ‘-v’
9300 Report processing steps.
9301
9302 ‘--debug’
9303 ‘-d’
9304 Don’t remove the temporary files and be even more verbose.
9305
9306 ‘--include=DIR’
9307 ‘-I DIR’
9308 Also look for input files in DIR. Multiple invocations accumulate.
9309
9310 ‘--output=FILE’
9311 ‘-o FILE’
9312 Save output (script or trace) to FILE. The file ‘-’ stands for the
9313 standard output.
9314
9315
9316 As an extension of ‘m4’, it includes the following options:
9317
9318 ‘--warnings=CATEGORY[,CATEGORY...]’
9319 ‘-WCATEGORY[,CATEGORY...]’
9320 Enable or disable warnings related to each CATEGORY. *Note
9321 m4_warn::, for a comprehensive list of categories. Special values
9322 include:
9323
9324 ‘all’
9325 Enable all categories of warnings.
9326
9327 ‘none’
9328 Disable all categories of warnings.
9329
9330 ‘error’
9331 Treat all warnings as errors.
9332
9333 ‘no-CATEGORY’
9334 Disable warnings falling into CATEGORY.
9335
9336 The environment variable ‘WARNINGS’ may also be set to a
9337 comma-separated list of warning categories to enable or disable.
9338 It is interpreted exactly the same way as the argument of
9339 ‘--warnings’, but unknown categories are silently ignored. The
9340 command line takes precedence; for instance, if ‘WARNINGS’ is set
9341 to ‘obsolete’, but ‘-Wnone’ is given on the command line, no
9342 warnings will be issued.
9343
9344 Some categories of warnings are on by default. Again, for details
9345 see *note m4_warn::.
9346
9347 ‘--melt’
9348 ‘-M’
9349 Do not use frozen files. Any argument ‘FILE.m4f’ is replaced by
9350 ‘FILE.m4’. This helps tracing the macros which are executed only
9351 when the files are frozen, typically ‘m4_define’. For instance,
9352 running:
9353
9354 autom4te --melt 1.m4 2.m4f 3.m4 4.m4f input.m4
9355
9356 is roughly equivalent to running:
9357
9358 m4 1.m4 2.m4 3.m4 4.m4 input.m4
9359
9360 while
9361
9362 autom4te 1.m4 2.m4f 3.m4 4.m4f input.m4
9363
9364 is equivalent to:
9365
9366 m4 --reload-state=4.m4f input.m4
9367
9368 ‘--freeze’
9369 ‘-F’
9370 Produce a frozen state file. ‘autom4te’ freezing is stricter than
9371 M4’s: it must produce no warnings, and no output other than empty
9372 lines (a line with white space is _not_ empty) and comments
9373 (starting with ‘#’). Unlike ‘m4’’s similarly-named option, this
9374 option takes no argument:
9375
9376 autom4te 1.m4 2.m4 3.m4 --freeze --output=3.m4f
9377
9378 corresponds to
9379
9380 m4 1.m4 2.m4 3.m4 --freeze-state=3.m4f
9381
9382 ‘--mode=OCTAL-MODE’
9383 ‘-m OCTAL-MODE’
9384 Set the mode of the non-traces output to OCTAL-MODE; by default
9385 ‘0666’.
9386
9387
9388 As another additional feature over ‘m4’, ‘autom4te’ caches its
9389 results. GNU M4 is able to produce a regular output and traces at the
9390 same time. Traces are heavily used in the GNU Build System:
9391 ‘autoheader’ uses them to build ‘config.h.in’, ‘autoreconf’ to determine
9392 what GNU Build System components are used, ‘automake’ to “parse”
9393 ‘configure.ac’ etc. To avoid recomputation, traces are cached while
9394 performing regular expansion, and conversely. This cache is (actually,
9395 the caches are) stored in the directory ‘autom4te.cache’. _It can
9396 safely be removed_ at any moment (especially if for some reason
9397 ‘autom4te’ considers it trashed).
9398
9399 ‘--cache=DIRECTORY’
9400 ‘-C DIRECTORY’
9401 Specify the name of the directory where the result should be
9402 cached. Passing an empty value disables caching. Be sure to pass
9403 a relative file name, as for the time being, global caches are not
9404 supported.
9405
9406 ‘--no-cache’
9407 Don’t cache the results.
9408
9409 ‘--force’
9410 ‘-f’
9411 If a cache is used, consider it obsolete (but update it anyway).
9412
9413
9414 Because traces are so important to the GNU Build System, ‘autom4te’
9415 provides high level tracing features as compared to M4, and helps
9416 exploiting the cache:
9417
9418 ‘--trace=MACRO[:FORMAT]’
9419 ‘-t MACRO[:FORMAT]’
9420 Trace the invocations of MACRO according to the FORMAT. Multiple
9421 ‘--trace’ arguments can be used to list several macros. Multiple
9422 ‘--trace’ arguments for a single macro are not cumulative; instead,
9423 you should just make FORMAT as long as needed.
9424
9425 The FORMAT is a regular string, with newlines if desired, and
9426 several special escape codes. It defaults to ‘$f:$l:$n:$%’. It
9427 can use the following special escapes:
9428
9429 ‘$$’
9430 The character ‘$’.
9431
9432 ‘$f’
9433 The file name from which MACRO is called.
9434
9435 ‘$l’
9436 The line number from which MACRO is called.
9437
9438 ‘$d’
9439 The depth of the MACRO call. This is an M4 technical detail
9440 that you probably don’t want to know about.
9441
9442 ‘$n’
9443 The name of the MACRO.
9444
9445 ‘$NUM’
9446 The NUMth argument of the call to MACRO.
9447
9448 ‘$@’
9449 ‘$SEP@’
9450 ‘${SEPARATOR}@’
9451 All the arguments passed to MACRO, separated by the character
9452 SEP or the string SEPARATOR (‘,’ by default). Each argument
9453 is quoted, i.e., enclosed in a pair of square brackets.
9454
9455 ‘$*’
9456 ‘$SEP*’
9457 ‘${SEPARATOR}*’
9458 As above, but the arguments are not quoted.
9459
9460 ‘$%’
9461 ‘$SEP%’
9462 ‘${SEPARATOR}%’
9463 As above, but the arguments are not quoted, all new line
9464 characters in the arguments are smashed, and the default
9465 separator is ‘:’.
9466
9467 The escape ‘$%’ produces single-line trace outputs (unless you
9468 put newlines in the ‘separator’), while ‘$@’ and ‘$*’ do not.
9469
9470 *Note autoconf Invocation::, for examples of trace uses.
9471
9472 ‘--preselect=MACRO’
9473 ‘-p MACRO’
9474 Cache the traces of MACRO, but do not enable traces. This is
9475 especially important to save CPU cycles in the future. For
9476 instance, when invoked, ‘autoconf’ pre-selects all the macros that
9477 ‘autoheader’, ‘automake’, ‘autoreconf’, etc., trace, so that
9478 running ‘m4’ is not needed to trace them: the cache suffices. This
9479 results in a huge speed-up.
9480
9481
9482 Finally, ‘autom4te’ introduces the concept of “Autom4te libraries”.
9483 They consists in a powerful yet extremely simple feature: sets of
9484 combined command line arguments:
9485
9486 ‘--language=LANGUAGE’
9487 ‘-l LANGUAGE’
9488 Use the LANGUAGE Autom4te library. Current languages include:
9489
9490 ‘M4sugar’
9491 create M4sugar output.
9492
9493 ‘M4sh’
9494 create M4sh executable shell scripts.
9495
9496 ‘Autotest’
9497 create Autotest executable test suites.
9498
9499 ‘Autoconf-without-aclocal-m4’
9500 create Autoconf executable configure scripts without reading
9501 ‘aclocal.m4’.
9502
9503 ‘Autoconf’
9504 create Autoconf executable configure scripts. This language
9505 inherits all the characteristics of
9506 ‘Autoconf-without-aclocal-m4’ and additionally reads
9507 ‘aclocal.m4’.
9508
9509 ‘--prepend-include=DIR’
9510 ‘-B DIR’
9511 Prepend directory DIR to the search path. This is used to include
9512 the language-specific files before any third-party macros.
9513
9514 As an example, if Autoconf is installed in its default location,
9515 ‘/usr/local’, the command ‘autom4te -l m4sugar foo.m4’ is strictly
9516 equivalent to the command:
9517
9518 autom4te --prepend-include /usr/local/share/autoconf \
9519 m4sugar/m4sugar.m4f foo.m4
9520
9521 Recursive expansion applies here: the command ‘autom4te -l m4sh foo.m4’
9522 is the same as ‘autom4te --language M4sugar m4sugar/m4sh.m4f foo.m4’,
9523 i.e.:
9524
9525 autom4te --prepend-include /usr/local/share/autoconf \
9526 m4sugar/m4sugar.m4f m4sugar/m4sh.m4f --mode 777 foo.m4
9527
9528 The definition of the languages is stored in ‘autom4te.cfg’.
9529
9530 
9531 File: autoconf.info, Node: Customizing autom4te, Prev: autom4te Invocation, Up: Using autom4te
9532
9533 8.2.2 Customizing ‘autom4te’
9534 ----------------------------
9535
9536 One can customize ‘autom4te’ via ‘~/.autom4te.cfg’ (i.e., as found in
9537 the user home directory), and ‘./.autom4te.cfg’ (i.e., as found in the
9538 directory from which ‘autom4te’ is run). The order is first reading
9539 ‘autom4te.cfg’, then ‘~/.autom4te.cfg’, then ‘./.autom4te.cfg’, and
9540 finally the command line arguments.
9541
9542 In these text files, comments are introduced with ‘#’, and empty
9543 lines are ignored. Customization is performed on a per-language basis,
9544 wrapped in between a ‘begin-language: "LANGUAGE"’, ‘end-language:
9545 "LANGUAGE"’ pair.
9546
9547 Customizing a language stands for appending options (*note autom4te
9548 Invocation::) to the current definition of the language. Options, and
9549 more generally arguments, are introduced by ‘args: ARGUMENTS’. You may
9550 use the traditional shell syntax to quote the ARGUMENTS.
9551
9552 As an example, to disable Autoconf caches (‘autom4te.cache’)
9553 globally, include the following lines in ‘~/.autom4te.cfg’:
9554
9555 ## ------------------ ##
9556 ## User Preferences. ##
9557 ## ------------------ ##
9558
9559 begin-language: "Autoconf-without-aclocal-m4"
9560 args: --no-cache
9561 end-language: "Autoconf-without-aclocal-m4"
9562
9563 
9564 File: autoconf.info, Node: Programming in M4sugar, Next: Debugging via autom4te, Prev: Using autom4te, Up: Programming in M4
9565
9566 8.3 Programming in M4sugar
9567 ==========================
9568
9569 M4 by itself provides only a small, but sufficient, set of all-purpose
9570 macros. M4sugar introduces additional generic macros. Its name was
9571 coined by Lars J. Aas: “Readability And Greater Understanding Stands 4
9572 M4sugar”.
9573
9574 M4sugar reserves the macro namespace ‘^_m4_’ for internal use, and
9575 the macro namespace ‘^m4_’ for M4sugar macros. You should not define
9576 your own macros into these namespaces.
9577
9578 * Menu:
9579
9580 * Redefined M4 Macros:: M4 builtins changed in M4sugar
9581 * Diagnostic Macros:: Diagnostic messages from M4sugar
9582 * Diversion support:: Diversions in M4sugar
9583 * Conditional constructs:: Conditions in M4
9584 * Looping constructs:: Iteration in M4
9585 * Evaluation Macros:: More quotation and evaluation control
9586 * Text processing Macros:: String manipulation in M4
9587 * Number processing Macros:: Arithmetic computation in M4
9588 * Set manipulation Macros:: Set manipulation in M4
9589 * Forbidden Patterns:: Catching unexpanded macros
9590
9591 
9592 File: autoconf.info, Node: Redefined M4 Macros, Next: Diagnostic Macros, Up: Programming in M4sugar
9593
9594 8.3.1 Redefined M4 Macros
9595 -------------------------
9596
9597 With a few exceptions, all the M4 native macros are moved in the ‘m4_’
9598 pseudo-namespace, e.g., M4sugar renames ‘define’ as ‘m4_define’ etc.
9599
9600 The list of macros unchanged from M4, except for their name, is:
9601 − m4_builtin
9602 − m4_changecom
9603 − m4_changequote
9604 − m4_debugfile
9605 − m4_debugmode
9606 − m4_decr
9607 − m4_define
9608 − m4_divnum
9609 − m4_errprint
9610 − m4_esyscmd
9611 − m4_eval
9612 − m4_format
9613 − m4_ifdef
9614 − m4_incr
9615 − m4_index
9616 − m4_indir
9617 − m4_len
9618 − m4_pushdef
9619 − m4_shift
9620 − m4_substr
9621 − m4_syscmd
9622 − m4_sysval
9623 − m4_traceoff
9624 − m4_traceon
9625 − m4_translit
9626
9627 Some M4 macros are redefined, and are slightly incompatible with
9628 their native equivalent.
9629
9630 — Macro: __file__
9631 — Macro: __line__
9632 All M4 macros starting with ‘__’ retain their original name: for
9633 example, no ‘m4__file__’ is defined.
9634
9635 — Macro: __oline__
9636 This is not technically a macro, but a feature of Autom4te. The
9637 sequence ‘__oline__’ can be used similarly to the other m4sugar
9638 location macros, but rather than expanding to the location of the
9639 input file, it is translated to the line number where it appears in
9640 the output file after all other M4 expansions.
9641
9642 — Macro: dnl
9643 This macro kept its original name: no ‘m4_dnl’ is defined.
9644
9645 — Macro: m4_bpatsubst(STRING, REGEXP, [REPLACEMENT])
9646 This is the M4sugar name for the M4 native macro ‘patsubst’.
9647
9648 It uses the same regular expression syntax as ‘m4_bregexp’; see
9649 *note m4_bregexp::. Also see *note Substituting text by regular
9650 expression: (m4)Patsubst, for details of how the REPLACEMENT is
9651 processed.
9652
9653 The name ‘m4_patsubst’ is reserved for use by a future version of
9654 M4sugar, when there is a version of GNU M4 that supports POSIX
9655 extended regular expression syntax.
9656
9657 — Macro: m4_bregexp(STRING, REGEXP, [REPLACEMENT])
9658 This is the M4sugar name for the M4 native macro ‘regexp’.
9659
9660 The only regular expression syntax understood by GNU M4 is similar
9661 to, but not the same as, POSIX basic regular expression syntax.
9662 *Note Searching for regular expressions: (m4)Regexp, for the
9663 precise syntax.
9664
9665 The name ‘m4_regexp’ is reserved for use by a future version of
9666 M4sugar, when there is a version of GNU M4 that supports POSIX
9667 extended regular expression syntax.
9668
9669 — Macro: m4_copy(SOURCE, DEST)
9670 — Macro: m4_copy_force(SOURCE, DEST)
9671 — Macro: m4_rename(SOURCE, DEST)
9672 — Macro: m4_rename_force(SOURCE, DEST)
9673 These macros aren’t directly builtins, but are closely related to
9674 ‘m4_pushdef’ and ‘m4_defn’. ‘m4_copy’ and ‘m4_rename’ ensure that
9675 DEST is undefined, while ‘m4_copy_force’ and ‘m4_rename_force’
9676 overwrite any existing definition. All four macros then proceed to
9677 copy the entire pushdef stack of definitions of SOURCE over to
9678 DEST. ‘m4_copy’ and ‘m4_copy_force’ preserve the source (including
9679 in the special case where SOURCE is undefined), while ‘m4_rename’
9680 and ‘m4_rename_force’ undefine the original macro name (making it
9681 an error to rename an undefined SOURCE).
9682
9683 Note that attempting to invoke a renamed macro might not work,
9684 since the macro may have a dependence on helper macros accessed via
9685 composition of ‘$0’ but that were not also renamed; likewise, other
9686 macros may have a hard-coded dependence on SOURCE and could break
9687 if SOURCE has been deleted. On the other hand, it is always safe
9688 to rename a macro to temporarily move it out of the way, then
9689 rename it back later to restore original semantics.
9690
9691 — Macro: m4_defn(MACRO...)
9692 This macro fails if MACRO is not defined, even when using older
9693 versions of M4 that did not warn. See ‘m4_undefine’.
9694 Unfortunately, in order to support these older versions of M4,
9695 there are some situations involving unbalanced quotes where
9696 concatenating multiple macros together will work in newer M4 but
9697 not in m4sugar; use quadrigraphs to work around this.
9698
9699 — Macro: m4_divert(DIVERSION)
9700 M4sugar relies heavily on diversions, so rather than behaving as a
9701 primitive, ‘m4_divert’ behaves like:
9702 m4_divert_pop()m4_divert_push([DIVERSION])
9703 *Note Diversion support::, for more details about the use of the
9704 diversion stack. In particular, this implies that DIVERSION should
9705 be a named diversion rather than a raw number. But be aware that
9706 it is seldom necessary to explicitly change the diversion stack,
9707 and that when done incorrectly, it can lead to syntactically
9708 invalid scripts.
9709
9710 — Macro: m4_dumpdef(NAME...)
9711 — Macro: m4_dumpdefs(NAME...)
9712 ‘m4_dumpdef’ is like the M4 builtin, except that this version
9713 requires at least one argument, output always goes to standard
9714 error rather than the current debug file, no sorting is done on
9715 multiple arguments, and an error is issued if any NAME is
9716 undefined. ‘m4_dumpdefs’ is a convenience macro that calls
9717 ‘m4_dumpdef’ for all of the ‘m4_pushdef’ stack of definitions,
9718 starting with the current, and silently does nothing if NAME is
9719 undefined.
9720
9721 Unfortunately, due to a limitation in M4 1.4.x, any macro defined
9722 as a builtin is output as the empty string. This behavior is
9723 rectified by using M4 1.6 or newer. However, this behavior
9724 difference means that ‘m4_dumpdef’ should only be used while
9725 developing m4sugar macros, and never in the final published form of
9726 a macro.
9727
9728 — Macro: m4_esyscmd_s(COMMAND)
9729 Like ‘m4_esyscmd’, this macro expands to the result of running
9730 COMMAND in a shell. The difference is that any trailing newlines
9731 are removed, so that the output behaves more like shell command
9732 substitution.
9733
9734 — Macro: m4_exit(EXIT-STATUS)
9735 This macro corresponds to ‘m4exit’.
9736
9737 — Macro: m4_if(COMMENT)
9738 — Macro: m4_if(STRING-1, STRING-2, EQUAL, [NOT-EQUAL])
9739 — Macro: m4_if(STRING-1, STRING-2, EQUAL-1, STRING-3, STRING-4,
9740 EQUAL-2, ..., [NOT-EQUAL])
9741 This macro corresponds to ‘ifelse’. STRING-1 and STRING-2 are
9742 compared literally, so usually one of the two arguments is passed
9743 unquoted. *Note Conditional constructs::, for more conditional
9744 idioms.
9745
9746 — Macro: m4_include(FILE)
9747 — Macro: m4_sinclude(FILE)
9748 Like the M4 builtins, but warn against multiple inclusions of FILE.
9749
9750 — Macro: m4_mkstemp(TEMPLATE)
9751 — Macro: m4_maketemp(TEMPLATE)
9752 Older versions of POSIX specified a macro ‘maketemp’, which
9753 replaced the trailing ‘X’ characters in TEMPLATE with the process
9754 id, without regards to the existence of a file by that name. This
9755 was a security hole, so current POSIX instead specifies a macro
9756 ‘mkstemp’ that always creates a uniquely named file. In M4sugar,
9757 ‘m4_maketemp’ and ‘m4_mkstemp’ are synonyms for each other, and
9758 both have the secure semantics regardless of which macro the
9759 underlying M4 provides.
9760
9761 — Macro: m4_popdef(MACRO...)
9762 This macro fails if MACRO is not defined, even when using older
9763 versions of M4 that did not warn. See ‘m4_undefine’.
9764
9765 — Macro: m4_undefine(MACRO...)
9766 This macro fails if MACRO is not defined, even when using older
9767 versions of M4 that did not warn. Use
9768
9769 m4_ifdef([MACRO], [m4_undefine([MACRO])])
9770
9771 if you are not sure whether MACRO is defined.
9772
9773 — Macro: m4_undivert(DIVERSION...)
9774 Unlike the M4 builtin, at least one DIVERSION must be specified.
9775 Also, since the M4sugar diversion stack prefers named diversions,
9776 the use of ‘m4_undivert’ to include files is risky. *Note
9777 Diversion support::, for more details about the use of the
9778 diversion stack. But be aware that it is seldom necessary to
9779 explicitly change the diversion stack, and that when done
9780 incorrectly, it can lead to syntactically invalid scripts.
9781
9782 — Macro: m4_wrap(TEXT)
9783 — Macro: m4_wrap_lifo(TEXT)
9784 These macros correspond to ‘m4wrap’. POSIX requires arguments of
9785 multiple wrap calls to be reprocessed at EOF in the same order as
9786 the original calls (first-in, first-out). GNU M4 versions through
9787 1.4.10, however, reprocess them in reverse order (last-in,
9788 first-out). Both orders are useful, therefore, you can rely on
9789 ‘m4_wrap’ to provide FIFO semantics and ‘m4_wrap_lifo’ for LIFO
9790 semantics, regardless of the underlying GNU M4 version.
9791
9792 Unlike the GNU M4 builtin, these macros only recognize one
9793 argument, and avoid token pasting between consecutive invocations.
9794 On the other hand, nested calls to ‘m4_wrap’ from within wrapped
9795 text work just as in the builtin.
9796
9797 
9798 File: autoconf.info, Node: Diagnostic Macros, Next: Diversion support, Prev: Redefined M4 Macros, Up: Programming in M4sugar
9799
9800 8.3.2 Diagnostic messages from M4sugar
9801 --------------------------------------
9802
9803 When macros statically diagnose abnormal situations, benign or fatal,
9804 they should report them using these macros. For issuing dynamic issues,
9805 i.e., when ‘configure’ is run, see *note Printing Messages::.
9806
9807 — Macro: m4_assert(EXPRESSION, [EXIT-STATUS = 1])
9808 Assert that the arithmetic EXPRESSION evaluates to non-zero.
9809 Otherwise, issue a fatal error, and exit ‘autom4te’ with
9810 EXIT-STATUS.
9811
9812 — Macro: m4_errprintn(MESSAGE)
9813 Similar to the builtin ‘m4_errprint’, except that a newline is
9814 guaranteed after MESSAGE.
9815
9816 — Macro: m4_fatal(MESSAGE)
9817 Report a severe error MESSAGE prefixed with the current location,
9818 and have ‘autom4te’ die.
9819
9820 — Macro: m4_location
9821 Useful as a prefix in a message line. Short for:
9822 __file__:__line__
9823
9824 — Macro: m4_warn(CATEGORY, MESSAGE)
9825 Report MESSAGE as a warning (or as an error if requested by the
9826 user) if warnings of the CATEGORY are turned on. If the message is
9827 emitted, it is prefixed with the current location, and followed by
9828 a call trace of all macros defined via ‘AC_DEFUN’ used to get to
9829 the current expansion.
9830
9831 The CATEGORY must be one of:
9832
9833 ‘cross’
9834 Warnings about constructs that may interfere with
9835 cross-compilation, such as using ‘AC_RUN_IFELSE’ without a
9836 default.
9837
9838 ‘gnu’
9839 Warnings related to the GNU Coding Standards (*note
9840 (standards)Top::). On by default.
9841
9842 ‘obsolete’
9843 Warnings about obsolete features. On by default.
9844
9845 ‘override’
9846 Warnings about redefinitions of Autoconf internals.
9847
9848 ‘portability’
9849 Warnings about non-portable constructs.
9850
9851 ‘portability-recursive’
9852 Warnings about recursive Make variable expansions
9853 (‘$(foo$(x))’).
9854
9855 ‘extra-portability’
9856 Extra warnings about non-portable constructs, covering
9857 rarely-used tools.
9858
9859 ‘syntax’
9860 Warnings about questionable syntactic constructs, incorrectly
9861 ordered macro calls, typos, etc. On by default.
9862
9863 ‘unsupported’
9864 Warnings about unsupported features. On by default.
9865
9866 *Hacking Note:* The set of categories is defined by code in
9867 ‘autom4te’, not by M4sugar itself. Additions should be coordinated
9868 with Automake, so that both sets of tools accept the same options.
9869
9870 
9871 File: autoconf.info, Node: Diversion support, Next: Conditional constructs, Prev: Diagnostic Macros, Up: Programming in M4sugar
9872
9873 8.3.3 Diversion support
9874 -----------------------
9875
9876 M4sugar makes heavy use of diversions under the hood, because it is
9877 often the case that text that must appear early in the output is not
9878 discovered until late in the input. Additionally, some of the
9879 topological sorting algorithms used in resolving macro dependencies use
9880 diversions. However, most macros should not need to change diversions
9881 directly, but rather rely on higher-level M4sugar macros to manage
9882 diversions transparently. If you change diversions improperly, you risk
9883 generating a syntactically invalid script, because an incorrect
9884 diversion will violate assumptions made by many macros about whether
9885 prerequisite text has been previously output. In short, if you manually
9886 change the diversion, you should not expect any macros provided by the
9887 Autoconf package to work until you have restored the diversion stack
9888 back to its original state.
9889
9890 In the rare case that it is necessary to write a macro that
9891 explicitly outputs text to a different diversion, it is important to be
9892 aware of an M4 limitation regarding diversions: text only goes to a
9893 diversion if it is not part of argument collection. Therefore, any
9894 macro that changes the current diversion cannot be used as an unquoted
9895 argument to another macro, but must be expanded at the top level. The
9896 macro ‘m4_expand’ will diagnose any attempt to change diversions, since
9897 it is generally useful only as an argument to another macro. The
9898 following example shows what happens when diversion manipulation is
9899 attempted within macro arguments:
9900
9901 m4_do([normal text]
9902 m4_divert_push([KILL])unwanted[]m4_divert_pop([KILL])
9903 [m4_divert_push([KILL])discarded[]m4_divert_pop([KILL])])dnl
9904 ⇒normal text
9905 ⇒unwanted
9906
9907 Notice that the unquoted text ‘unwanted’ is output, even though it was
9908 processed while the current diversion was ‘KILL’, because it was
9909 collected as part of the argument to ‘m4_do’. However, the text
9910 ‘discarded’ disappeared as desired, because the diversion changes were
9911 single-quoted, and were not expanded until the top-level rescan of the
9912 output of ‘m4_do’.
9913
9914 To make diversion management easier, M4sugar uses the concept of
9915 named diversions. Rather than using diversion numbers directly, it is
9916 nicer to associate a name with each diversion. The diversion number
9917 associated with a particular diversion name is an implementation detail,
9918 and a syntax warning is issued if a diversion number is used instead of
9919 a name. In general, you should not output text to a named diversion
9920 until after calling the appropriate initialization routine for your
9921 language (‘m4_init’, ‘AS_INIT’, ‘AT_INIT’, ...), although there are some
9922 exceptions documented below.
9923
9924 M4sugar defines two named diversions.
9925 ‘KILL’
9926 Text written to this diversion is discarded. This is the default
9927 diversion once M4sugar is initialized.
9928 ‘GROW’
9929 This diversion is used behind the scenes by topological sorting
9930 macros, such as ‘AC_REQUIRE’.
9931
9932 M4sh adds several more named diversions.
9933 ‘BINSH’
9934 This diversion is reserved for the ‘#!’ interpreter line.
9935 ‘HEADER-REVISION’
9936 This diversion holds text from ‘AC_REVISION’.
9937 ‘HEADER-COMMENT’
9938 This diversion holds comments about the purpose of a file.
9939 ‘HEADER-COPYRIGHT’
9940 This diversion is managed by ‘AC_COPYRIGHT’.
9941 ‘M4SH-SANITIZE’
9942 This diversion contains M4sh sanitization code, used to ensure M4sh
9943 is executing in a reasonable shell environment.
9944 ‘M4SH-INIT’
9945 This diversion contains M4sh initialization code, initializing
9946 variables that are required by other M4sh macros.
9947 ‘BODY’
9948 This diversion contains the body of the shell code, and is the
9949 default diversion once M4sh is initialized.
9950
9951 Autotest inherits diversions from M4sh, and changes the default
9952 diversion from ‘BODY’ back to ‘KILL’. It also adds several more named
9953 diversions, with the following subset designed for developer use.
9954 ‘PREPARE_TESTS’
9955 This diversion contains initialization sequences which are executed
9956 after ‘atconfig’ and ‘atlocal’, and after all command line
9957 arguments have been parsed, but prior to running any tests. It can
9958 be used to set up state that is required across all tests. This
9959 diversion will work even before ‘AT_INIT’.
9960
9961 Autoconf inherits diversions from M4sh, and adds the following named
9962 diversions which developers can utilize.
9963 ‘DEFAULTS’
9964 This diversion contains shell variable assignments to set defaults
9965 that must be in place before arguments are parsed. This diversion
9966 is placed early enough in ‘configure’ that it is unsafe to expand
9967 any autoconf macros into this diversion.
9968 ‘HELP_ENABLE’
9969 If ‘AC_PRESERVE_HELP_ORDER’ was used, then text placed in this
9970 diversion will be included as part of a quoted here-doc providing
9971 all of the ‘--help’ output of ‘configure’ related to options
9972 created by ‘AC_ARG_WITH’ and ‘AC_ARG_ENABLE’.
9973 ‘INIT_PREPARE’
9974 This diversion occurs after all command line options have been
9975 parsed, but prior to the main body of the ‘configure’ script. This
9976 diversion is the last chance to insert shell code such as variable
9977 assignments or shell function declarations that will used by the
9978 expansion of other macros.
9979
9980 For now, the remaining named diversions of Autoconf, Autoheader, and
9981 Autotest are not documented. In other words, intentionally outputting
9982 text into an undocumented diversion is subject to breakage in a future
9983 release of Autoconf.
9984
9985 — Macro: m4_cleardivert(DIVERSION...)
9986 Permanently discard any text that has been diverted into DIVERSION.
9987
9988 — Macro: m4_divert_once(DIVERSION, [CONTENT])
9989 Similar to ‘m4_divert_text’, except that CONTENT is only output to
9990 DIVERSION if this is the first time that ‘m4_divert_once’ has been
9991 called with its particular arguments.
9992
9993 — Macro: m4_divert_pop([DIVERSION])
9994 If provided, check that the current diversion is indeed DIVERSION.
9995 Then change to the diversion located earlier on the stack, giving
9996 an error if an attempt is made to pop beyond the initial m4sugar
9997 diversion of ‘KILL’.
9998
9999 — Macro: m4_divert_push(DIVERSION)
10000 Remember the former diversion on the diversion stack, and output
10001 subsequent text into DIVERSION. M4sugar maintains a diversion
10002 stack, and issues an error if there is not a matching pop for every
10003 push.
10004
10005 — Macro: m4_divert_text(DIVERSION, [CONTENT])
10006 Output CONTENT and a newline into DIVERSION, without affecting the
10007 current diversion. Shorthand for:
10008 m4_divert_push([DIVERSION])CONTENT
10009 m4_divert_pop([DIVERSION])dnl
10010
10011 One use of ‘m4_divert_text’ is to develop two related macros, where
10012 macro ‘MY_A’ does the work, but adjusts what work is performed
10013 based on whether the optional macro ‘MY_B’ has also been expanded.
10014 Of course, it is possible to use ‘AC_BEFORE’ within ‘MY_A’ to
10015 require that ‘MY_B’ occurs first, if it occurs at all. But this
10016 imposes an ordering restriction on the user; it would be nicer if
10017 macros ‘MY_A’ and ‘MY_B’ can be invoked in either order. The trick
10018 is to let ‘MY_B’ leave a breadcrumb in an early diversion, which
10019 ‘MY_A’ can then use to determine whether ‘MY_B’ has been expanded.
10020
10021 AC_DEFUN([MY_A],
10022 [# various actions
10023 if test -n "$b_was_used"; then
10024 # extra action
10025 fi])
10026 AC_DEFUN([MY_B],
10027 [AC_REQUIRE([MY_A])dnl
10028 m4_divert_text([INIT_PREPARE], [b_was_used=true])])
10029
10030 — Macro: m4_init
10031 Initialize the M4sugar environment, setting up the default named
10032 diversion to be ‘KILL’.
10033
10034 
10035 File: autoconf.info, Node: Conditional constructs, Next: Looping constructs, Prev: Diversion support, Up: Programming in M4sugar
10036
10037 8.3.4 Conditional constructs
10038 ----------------------------
10039
10040 The following macros provide additional conditional constructs as
10041 convenience wrappers around ‘m4_if’.
10042
10043 — Macro: m4_bmatch(STRING, REGEX-1, VALUE-1, [REGEX-2], [VALUE-2], ...,
10044 [DEFAULT])
10045 The string STRING is repeatedly compared against a series of REGEX
10046 arguments; if a match is found, the expansion is the corresponding
10047 VALUE, otherwise, the macro moves on to the next REGEX. If no
10048 REGEX match, then the result is the optional DEFAULT, or nothing.
10049
10050 The regular expression syntax understood by ‘m4_bmatch’ is the same
10051 as that understood by ‘m4_bregexp’; see *note m4_bregexp::. The
10052 name ‘m4_match’ is reserved for use by a future version of M4sugar,
10053 when there is a version of GNU M4 that supports POSIX extended
10054 regular expression syntax.
10055
10056 — Macro: m4_bpatsubsts(STRING, REGEX-1, SUBST-1, [REGEX-2], [SUBST-2],
10057 ...)
10058 The string STRING is altered by REGEX-1 and SUBST-1, as if by:
10059 m4_bpatsubst([[STRING]], [REGEX], [SUBST])
10060
10061 The result of the substitution is then passed through the next set
10062 of REGEX and SUBST, and so forth. An empty SUBST implies deletion
10063 of any matched portions in the current string. Note that this
10064 macro over-quotes STRING; this behavior is intentional, so that the
10065 result of each step of the recursion remains as a quoted string.
10066 However, it means that anchors (‘^’ and ‘$’ in the REGEX will line
10067 up with the extra quotations, and not the characters of the
10068 original string. The overquoting is removed after the final
10069 substitution.
10070
10071 The regular expression and replacement syntax understood by
10072 ‘m4_bpatsubsts’ is the same as that understood by ‘m4_bpatsubst’;
10073 see *note m4_bpatsubst::. The name ‘m4_patsubsts’ is reserved for
10074 use by future version of M4sugar, when there is a version of GNU M4
10075 that supports POSIX extended regular expression syntax.
10076
10077 — Macro: m4_case(STRING, VALUE-1, IF-VALUE-1, [VALUE-2], [IF-VALUE-2],
10078 ..., [DEFAULT])
10079 Test STRING against multiple VALUE possibilities, resulting in the
10080 first IF-VALUE for a match, or in the optional DEFAULT. This is
10081 shorthand for:
10082 m4_if([STRING], [VALUE-1], [IF-VALUE-1],
10083 [STRING], [VALUE-2], [IF-VALUE-2], ...,
10084 [DEFAULT])
10085
10086 — Macro: m4_cond(TEST-1, VALUE-1, IF-VALUE-1, [TEST-2], [VALUE-2],
10087 [IF-VALUE-2], ..., [DEFAULT])
10088 This macro was introduced in Autoconf 2.62. Similar to ‘m4_if’,
10089 except that each TEST is expanded only when it is encountered.
10090 This is useful for short-circuiting expensive tests; while ‘m4_if’
10091 requires all its strings to be expanded up front before doing
10092 comparisons, ‘m4_cond’ only expands a TEST when all earlier tests
10093 have failed.
10094
10095 For an example, these two sequences give the same result, but in
10096 the case where ‘$1’ does not contain a backslash, the ‘m4_cond’
10097 version only expands ‘m4_index’ once, instead of five times, for
10098 faster computation if this is a common case for ‘$1’. Notice that
10099 every third argument is unquoted for ‘m4_if’, and quoted for
10100 ‘m4_cond’:
10101
10102 m4_if(m4_index([$1], [\]), [-1], [$2],
10103 m4_eval(m4_index([$1], [\\]) >= 0), [1], [$2],
10104 m4_eval(m4_index([$1], [\$]) >= 0), [1], [$2],
10105 m4_eval(m4_index([$1], [\`]) >= 0), [1], [$3],
10106 m4_eval(m4_index([$1], [\"]) >= 0), [1], [$3],
10107 [$2])
10108 m4_cond([m4_index([$1], [\])], [-1], [$2],
10109 [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2],
10110 [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2],
10111 [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3],
10112 [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3],
10113 [$2])
10114
10115 — Macro: m4_default(EXPR-1, EXPR-2)
10116 — Macro: m4_default_quoted(EXPR-1, EXPR-2)
10117 — Macro: m4_default_nblank(EXPR-1, [EXPR-2])
10118 — Macro: m4_default_nblank_quoted(EXPR-1, [EXPR-2])
10119 If EXPR-1 contains text, use it. Otherwise, select EXPR-2.
10120 ‘m4_default’ expands the result, while ‘m4_default_quoted’ does
10121 not. Useful for providing a fixed default if the expression that
10122 results in EXPR-1 would otherwise be empty. The difference between
10123 ‘m4_default’ and ‘m4_default_nblank’ is whether an argument
10124 consisting of just blanks (space, tab, newline) is significant.
10125 When using the expanding versions, note that an argument may
10126 contain text but still expand to an empty string.
10127
10128 m4_define([active], [ACTIVE])dnl
10129 m4_define([empty], [])dnl
10130 m4_define([demo1], [m4_default([$1], [$2])])dnl
10131 m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
10132 m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
10133 m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
10134 demo1([active], [default])
10135 ⇒ACTIVE
10136 demo1([], [active])
10137 ⇒ACTIVE
10138 demo1([empty], [text])
10139 ⇒
10140 -demo1([ ], [active])-
10141 ⇒- -
10142 demo2([active], [default])
10143 ⇒active
10144 demo2([], [active])
10145 ⇒active
10146 demo2([empty], [text])
10147 ⇒empty
10148 -demo2([ ], [active])-
10149 ⇒- -
10150 demo3([active], [default])
10151 ⇒ACTIVE
10152 demo3([], [active])
10153 ⇒ACTIVE
10154 demo3([empty], [text])
10155 ⇒
10156 -demo3([ ], [active])-
10157 ⇒-ACTIVE-
10158 demo4([active], [default])
10159 ⇒active
10160 demo4([], [active])
10161 ⇒active
10162 demo4([empty], [text])
10163 ⇒empty
10164 -demo4([ ], [active])-
10165 ⇒-active-
10166
10167 — Macro: m4_define_default(MACRO, [DEFAULT-DEFINITION])
10168 If MACRO does not already have a definition, then define it to
10169 DEFAULT-DEFINITION.
10170
10171 — Macro: m4_ifblank(COND, [IF-BLANK], [IF-TEXT])
10172 — Macro: m4_ifnblank(COND, [IF-TEXT], [IF-BLANK])
10173 If COND is empty or consists only of blanks (space, tab, newline),
10174 then expand IF-BLANK; otherwise, expand IF-TEXT. Two variants
10175 exist, in order to make it easier to select the correct logical
10176 sense when using only two parameters. Note that this is more
10177 efficient than the equivalent behavior of:
10178 m4_ifval(m4_normalize([COND]), IF-TEXT, IF-BLANK)
10179
10180 — Macro: m4_ifndef(MACRO, IF-NOT-DEFINED, [IF-DEFINED])
10181 This is shorthand for:
10182 m4_ifdef([MACRO], [IF-DEFINED], [IF-NOT-DEFINED])
10183
10184 — Macro: m4_ifset(MACRO, [IF-TRUE], [IF-FALSE])
10185 If MACRO is undefined, or is defined as the empty string, expand to
10186 IF-FALSE. Otherwise, expands to IF-TRUE. Similar to:
10187 m4_ifval(m4_defn([MACRO]), [IF-TRUE], [IF-FALSE])
10188 except that it is not an error if MACRO is undefined.
10189
10190 — Macro: m4_ifval(COND, [IF-TRUE], [IF-FALSE])
10191 Expands to IF-TRUE if COND is not empty, otherwise to IF-FALSE.
10192 This is shorthand for:
10193 m4_if([COND], [], [IF-FALSE], [IF-TRUE])
10194
10195 — Macro: m4_ifvaln(COND, [IF-TRUE], [IF-FALSE])
10196 Similar to ‘m4_ifval’, except guarantee that a newline is present
10197 after any non-empty expansion. Often followed by ‘dnl’.
10198
10199 — Macro: m4_n(TEXT)
10200 Expand to TEXT, and add a newline if TEXT is not empty. Often
10201 followed by ‘dnl’.
10202
10203 
10204 File: autoconf.info, Node: Looping constructs, Next: Evaluation Macros, Prev: Conditional constructs, Up: Programming in M4sugar
10205
10206 8.3.5 Looping constructs
10207 ------------------------
10208
10209 The following macros are useful in implementing recursive algorithms in
10210 M4, including loop operations. An M4 list is formed by quoting a list
10211 of quoted elements; generally the lists are comma-separated, although
10212 ‘m4_foreach_w’ is whitespace-separated. For example, the list ‘[[a],
10213 [b,c]]’ contains two elements: ‘[a]’ and ‘[b,c]’. It is common to see
10214 lists with unquoted elements when those elements are not likely to be
10215 macro names, as in ‘[fputc_unlocked, fgetc_unlocked]’.
10216
10217 Although not generally recommended, it is possible for quoted lists
10218 to have side effects; all side effects are expanded only once, and prior
10219 to visiting any list element. On the other hand, the fact that unquoted
10220 macros are expanded exactly once means that macros without side effects
10221 can be used to generate lists. For example,
10222
10223 m4_foreach([i], [[1], [2], [3]m4_errprintn([hi])], [i])
10224 error→hi
10225 ⇒123
10226 m4_define([list], [[1], [2], [3]])
10227 ⇒
10228 m4_foreach([i], [list], [i])
10229 ⇒123
10230
10231 — Macro: m4_argn(N, [ARG]...)
10232 Extracts argument N (larger than 0) from the remaining arguments.
10233 If there are too few arguments, the empty string is used. For any
10234 N besides 1, this is more efficient than the similar
10235 ‘m4_car(m4_shiftn([N], [], [ARG...]))’.
10236
10237 — Macro: m4_car(ARG...)
10238 Expands to the quoted first ARG. Can be used with ‘m4_cdr’ to
10239 recursively iterate through a list. Generally, when using quoted
10240 lists of quoted elements, ‘m4_car’ should be called without any
10241 extra quotes.
10242
10243 — Macro: m4_cdr(ARG...)
10244 Expands to a quoted list of all but the first ARG, or the empty
10245 string if there was only one argument. Generally, when using
10246 quoted lists of quoted elements, ‘m4_cdr’ should be called without
10247 any extra quotes.
10248
10249 For example, this is a simple implementation of ‘m4_map’; note how
10250 each iteration checks for the end of recursion, then merely applies
10251 the first argument to the first element of the list, then repeats
10252 with the rest of the list. (The actual implementation in M4sugar
10253 is a bit more involved, to gain some speed and share code with
10254 ‘m4_map_sep’, and also to avoid expanding side effects in ‘$2’
10255 twice).
10256 m4_define([m4_map], [m4_ifval([$2],
10257 [m4_apply([$1], m4_car($2))[]$0([$1], m4_cdr($2))])])dnl
10258 m4_map([ m4_eval], [[[1]], [[1+1]], [[10],[16]]])
10259 ⇒ 1 2 a
10260
10261 — Macro: m4_for(VAR, FIRST, LAST, [STEP], EXPRESSION)
10262 Loop over the numeric values between FIRST and LAST including
10263 bounds by increments of STEP. For each iteration, expand
10264 EXPRESSION with the numeric value assigned to VAR. If STEP is
10265 omitted, it defaults to ‘1’ or ‘-1’ depending on the order of the
10266 limits. If given, STEP has to match this order. The number of
10267 iterations is determined independently from definition of VAR;
10268 iteration cannot be short-circuited or lengthened by modifying VAR
10269 from within EXPRESSION.
10270
10271 — Macro: m4_foreach(VAR, LIST, EXPRESSION)
10272 Loop over the comma-separated M4 list LIST, assigning each value to
10273 VAR, and expand EXPRESSION. The following example outputs two
10274 lines:
10275
10276 m4_foreach([myvar], [[foo], [bar, baz]],
10277 [echo myvar
10278 ])dnl
10279 ⇒echo foo
10280 ⇒echo bar, baz
10281
10282 Note that for some forms of EXPRESSION, it may be faster to use
10283 ‘m4_map_args’.
10284
10285 — Macro: m4_foreach_w(VAR, LIST, EXPRESSION)
10286 Loop over the white-space-separated list LIST, assigning each value
10287 to VAR, and expand EXPRESSION. If VAR is only referenced once in
10288 EXPRESSION, it is more efficient to use ‘m4_map_args_w’.
10289
10290 The deprecated macro ‘AC_FOREACH’ is an alias of ‘m4_foreach_w’.
10291
10292 — Macro: m4_map(MACRO, LIST)
10293 — Macro: m4_mapall(MACRO, LIST)
10294 — Macro: m4_map_sep(MACRO, SEPARATOR, LIST)
10295 — Macro: m4_mapall_sep(MACRO, SEPARATOR, LIST)
10296 Loop over the comma separated quoted list of argument descriptions
10297 in LIST, and invoke MACRO with the arguments. An argument
10298 description is in turn a comma-separated quoted list of quoted
10299 elements, suitable for ‘m4_apply’. The macros ‘m4_map’ and
10300 ‘m4_map_sep’ ignore empty argument descriptions, while ‘m4_mapall’
10301 and ‘m4_mapall_sep’ invoke MACRO with no arguments. The macros
10302 ‘m4_map_sep’ and ‘m4_mapall_sep’ additionally expand SEPARATOR
10303 between invocations of MACRO.
10304
10305 Note that SEPARATOR is expanded, unlike in ‘m4_join’. When
10306 separating output with commas, this means that the map result can
10307 be used as a series of arguments, by using a single-quoted comma as
10308 SEPARATOR, or as a single string, by using a double-quoted comma.
10309
10310 m4_map([m4_count], [])
10311 ⇒
10312 m4_map([ m4_count], [[],
10313 [[1]],
10314 [[1], [2]]])
10315 ⇒ 1 2
10316 m4_mapall([ m4_count], [[],
10317 [[1]],
10318 [[1], [2]]])
10319 ⇒ 0 1 2
10320 m4_map_sep([m4_eval], [,], [[[1+2]],
10321 [[10], [16]]])
10322 ⇒3,a
10323 m4_map_sep([m4_echo], [,], [[[a]], [[b]]])
10324 ⇒a,b
10325 m4_count(m4_map_sep([m4_echo], [,], [[[a]], [[b]]]))
10326 ⇒2
10327 m4_map_sep([m4_echo], [[,]], [[[a]], [[b]]])
10328 ⇒a,b
10329 m4_count(m4_map_sep([m4_echo], [[,]], [[[a]], [[b]]]))
10330 ⇒1
10331
10332 — Macro: m4_map_args(MACRO, ARG...)
10333 Repeatedly invoke MACRO with each successive ARG as its only
10334 argument. In the following example, three solutions are presented
10335 with the same expansion; the solution using ‘m4_map_args’ is the
10336 most efficient.
10337 m4_define([active], [ACTIVE])dnl
10338 m4_foreach([var], [[plain], [active]], [ m4_echo(m4_defn([var]))])
10339 ⇒ plain active
10340 m4_map([ m4_echo], [[[plain]], [[active]]])
10341 ⇒ plain active
10342 m4_map_args([ m4_echo], [plain], [active])
10343 ⇒ plain active
10344
10345 In cases where it is useful to operate on additional parameters
10346 besides the list elements, the macro ‘m4_curry’ can be used in
10347 MACRO to supply the argument currying necessary to generate the
10348 desired argument list. In the following example, ‘list_add_n’ is
10349 more efficient than ‘list_add_x’. On the other hand, using
10350 ‘m4_map_args_sep’ can be even more efficient.
10351
10352 m4_define([list], [[1], [2], [3]])dnl
10353 m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
10354 dnl list_add_n(N, ARG...)
10355 dnl Output a list consisting of each ARG added to N
10356 m4_define([list_add_n],
10357 [m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@)))])dnl
10358 list_add_n([1], list)
10359 ⇒2,3,4
10360 list_add_n([2], list)
10361 ⇒3,4,5
10362 m4_define([list_add_x],
10363 [m4_shift(m4_foreach([var], m4_dquote(m4_shift($@)),
10364 [,add([$1],m4_defn([var]))]))])dnl
10365 list_add_x([1], list)
10366 ⇒2,3,4
10367
10368 — Macro: m4_map_args_pair(MACRO, [MACRO-END = MACRO], ARG...)
10369 For every pair of arguments ARG, invoke MACRO with two arguments.
10370 If there is an odd number of arguments, invoke MACRO-END, which
10371 defaults to MACRO, with the remaining argument.
10372
10373 m4_map_args_pair([, m4_reverse], [], [1], [2], [3])
10374 ⇒, 2, 1, 3
10375 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])
10376 ⇒, 2, 1, [3]
10377 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])
10378 ⇒, 2, 1, 4, 3
10379
10380 — Macro: m4_map_args_sep([PRE], [POST], [SEP], ARG...)
10381 Expand the sequence ‘PRE[ARG]POST’ for each argument, additionally
10382 expanding SEP between arguments. One common use of this macro is
10383 constructing a macro call, where the opening and closing
10384 parentheses are split between PRE and POST; in particular,
10385 ‘m4_map_args([MACRO], [ARG])’ is equivalent to
10386 ‘m4_map_args_sep([MACRO(], [)], [], [ARG])’. This macro provides
10387 the most efficient means for iterating over an arbitrary list of
10388 arguments, particularly when repeatedly constructing a macro call
10389 with more arguments than ARG.
10390
10391 — Macro: m4_map_args_w(STRING, [PRE], [POST], [SEP])
10392 Expand the sequence ‘PRE[word]POST’ for each word in the
10393 whitespace-separated STRING, additionally expanding SEP between
10394 words. This macro provides the most efficient means for iterating
10395 over a whitespace-separated string. In particular,
10396 ‘m4_map_args_w([STRING], [ACTION(], [)])’ is more efficient than
10397 ‘m4_foreach_w([var], [STRING], [ACTION(m4_defn([var]))])’.
10398
10399 — Macro: m4_shiftn(COUNT, ...)
10400 — Macro: m4_shift2(...)
10401 — Macro: m4_shift3(...)
10402 ‘m4_shiftn’ performs COUNT iterations of ‘m4_shift’, along with
10403 validation that enough arguments were passed in to match the shift
10404 count, and that the count is positive. ‘m4_shift2’ and ‘m4_shift3’
10405 are specializations of ‘m4_shiftn’, introduced in Autoconf 2.62,
10406 and are more efficient for two and three shifts, respectively.
10407
10408 — Macro: m4_stack_foreach(MACRO, ACTION)
10409 — Macro: m4_stack_foreach_lifo(MACRO, ACTION)
10410 For each of the ‘m4_pushdef’ definitions of MACRO, expand ACTION
10411 with the single argument of a definition of MACRO.
10412 ‘m4_stack_foreach’ starts with the oldest definition, while
10413 ‘m4_stack_foreach_lifo’ starts with the current definition. ACTION
10414 should not push or pop definitions of MACRO, nor is there any
10415 guarantee that the current definition of MACRO matches the argument
10416 that was passed to ACTION. The macro ‘m4_curry’ can be used if
10417 ACTION needs more than one argument, although in that case it is
10418 more efficient to use M4_STACK_FOREACH_SEP.
10419
10420 Due to technical limitations, there are a few low-level m4sugar
10421 functions, such as ‘m4_pushdef’, that cannot be used as the MACRO
10422 argument.
10423
10424 m4_pushdef([a], [1])m4_pushdef([a], [2])dnl
10425 m4_stack_foreach([a], [ m4_incr])
10426 ⇒ 2 3
10427 m4_stack_foreach_lifo([a], [ m4_curry([m4_substr], [abcd])])
10428 ⇒ cd bcd
10429
10430 — Macro: m4_stack_foreach_sep(MACRO, [PRE], [POST], [SEP])
10431 — Macro: m4_stack_foreach_sep_lifo(MACRO, [PRE], [POST], [SEP])
10432 Expand the sequence ‘PRE[definition]POST’ for each ‘m4_pushdef’
10433 definition of MACRO, additionally expanding SEP between
10434 definitions. ‘m4_stack_foreach_sep’ visits the oldest definition
10435 first, while ‘m4_stack_foreach_sep_lifo’ visits the current
10436 definition first. This macro provides the most efficient means for
10437 iterating over a pushdef stack. In particular,
10438 ‘m4_stack_foreach([MACRO], [ACTION])’ is short for
10439 ‘m4_stack_foreach_sep([MACRO], [ACTION(], [)])’.
10440
10441 
10442 File: autoconf.info, Node: Evaluation Macros, Next: Text processing Macros, Prev: Looping constructs, Up: Programming in M4sugar
10443
10444 8.3.6 Evaluation Macros
10445 -----------------------
10446
10447 The following macros give some control over the order of the evaluation
10448 by adding or removing levels of quotes.
10449
10450 — Macro: m4_apply(MACRO, LIST)
10451 Apply the elements of the quoted, comma-separated LIST as the
10452 arguments to MACRO. If LIST is empty, invoke MACRO without
10453 arguments. Note the difference between ‘m4_indir’, which expects
10454 its first argument to be a macro name but can use names that are
10455 otherwise invalid, and ‘m4_apply’, where MACRO can contain other
10456 text, but must end in a valid macro name.
10457 m4_apply([m4_count], [])
10458 ⇒0
10459 m4_apply([m4_count], [[]])
10460 ⇒1
10461 m4_apply([m4_count], [[1], [2]])
10462 ⇒2
10463 m4_apply([m4_join], [[|], [1], [2]])
10464 ⇒1|2
10465
10466 — Macro: m4_count(ARG, ...)
10467 This macro returns the number of arguments it was passed.
10468
10469 — Macro: m4_curry(MACRO, ARG...)
10470 This macro performs argument currying. The expansion of this macro
10471 is another macro name that expects exactly one argument; that
10472 argument is then appended to the ARG list, and then MACRO is
10473 expanded with the resulting argument list.
10474
10475 m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
10476 ⇒3, 2, 1
10477
10478 Unfortunately, due to a limitation in M4 1.4.x, it is not possible
10479 to pass the definition of a builtin macro as the argument to the
10480 output of ‘m4_curry’; the empty string is used instead of the
10481 builtin token. This behavior is rectified by using M4 1.6 or
10482 newer.
10483
10484 — Macro: m4_do(ARG, ...)
10485 This macro loops over its arguments and expands each ARG in
10486 sequence. Its main use is for readability; it allows the use of
10487 indentation and fewer ‘dnl’ to result in the same expansion. This
10488 macro guarantees that no expansion will be concatenated with
10489 subsequent text; to achieve full concatenation, use
10490 ‘m4_unquote(m4_join([], ARG...))’.
10491
10492 m4_define([ab],[1])m4_define([bc],[2])m4_define([abc],[3])dnl
10493 m4_do([a],[b])c
10494 ⇒abc
10495 m4_unquote(m4_join([],[a],[b]))c
10496 ⇒3
10497 m4_define([a],[A])m4_define([b],[B])m4_define([c],[C])dnl
10498 m4_define([AB],[4])m4_define([BC],[5])m4_define([ABC],[6])dnl
10499 m4_do([a],[b])c
10500 ⇒ABC
10501 m4_unquote(m4_join([],[a],[b]))c
10502 ⇒3
10503
10504 — Macro: m4_dquote(ARG, ...)
10505 Return the arguments as a quoted list of quoted arguments.
10506 Conveniently, if there is just one ARG, this effectively adds a
10507 level of quoting.
10508
10509 — Macro: m4_dquote_elt(ARG, ...)
10510 Return the arguments as a series of double-quoted arguments.
10511 Whereas ‘m4_dquote’ returns a single argument, ‘m4_dquote_elt’
10512 returns as many arguments as it was passed.
10513
10514 — Macro: m4_echo(ARG, ...)
10515 Return the arguments, with the same level of quoting. Other than
10516 discarding whitespace after unquoted commas, this macro is a no-op.
10517
10518 — Macro: m4_expand(ARG)
10519 Return the expansion of ARG as a quoted string. Whereas ‘m4_quote’
10520 is designed to collect expanded text into a single argument,
10521 ‘m4_expand’ is designed to perform one level of expansion on quoted
10522 text. One distinction is in the treatment of whitespace following
10523 a comma in the original ARG. Any time multiple arguments are
10524 collected into one with ‘m4_quote’, the M4 argument collection
10525 rules discard the whitespace. However, with ‘m4_expand’,
10526 whitespace is preserved, even after the expansion of macros
10527 contained in ARG. Additionally, ‘m4_expand’ is able to expand text
10528 that would involve an unterminated comment, whereas expanding that
10529 same text as the argument to ‘m4_quote’ runs into difficulty in
10530 finding the end of the argument. Since manipulating diversions
10531 during argument collection is inherently unsafe, ‘m4_expand’ issues
10532 an error if ARG attempts to change the current diversion (*note
10533 Diversion support::).
10534
10535 m4_define([active], [ACT, IVE])dnl
10536 m4_define([active2], [[ACT, IVE]])dnl
10537 m4_quote(active, active)
10538 ⇒ACT,IVE,ACT,IVE
10539 m4_expand([active, active])
10540 ⇒ACT, IVE, ACT, IVE
10541 m4_quote(active2, active2)
10542 ⇒ACT, IVE,ACT, IVE
10543 m4_expand([active2, active2])
10544 ⇒ACT, IVE, ACT, IVE
10545 m4_expand([# m4_echo])
10546 ⇒# m4_echo
10547 m4_quote(# m4_echo)
10548 )
10549 ⇒# m4_echo)
10550 ⇒
10551
10552 Note that ‘m4_expand’ cannot handle an ARG that expands to literal
10553 unbalanced quotes, but that quadrigraphs can be used when
10554 unbalanced output is necessary. Likewise, unbalanced parentheses
10555 should be supplied with double quoting or a quadrigraph.
10556
10557 m4_define([pattern], [[!@<:@]])dnl
10558 m4_define([bar], [BAR])dnl
10559 m4_expand([case $foo in
10560 m4_defn([pattern])@:}@ bar ;;
10561 *[)] blah ;;
10562 esac])
10563 ⇒case $foo in
10564 ⇒ [![]) BAR ;;
10565 ⇒ *) blah ;;
10566 ⇒esac
10567
10568 — Macro: m4_ignore(...)
10569 This macro was introduced in Autoconf 2.62. Expands to nothing,
10570 ignoring all of its arguments. By itself, this isn’t very useful.
10571 However, it can be used to conditionally ignore an arbitrary number
10572 of arguments, by deciding which macro name to apply to a list of
10573 arguments.
10574 dnl foo outputs a message only if [debug] is defined.
10575 m4_define([foo],
10576 [m4_ifdef([debug],[AC_MSG_NOTICE],[m4_ignore])([debug message])])
10577
10578 Note that for earlier versions of Autoconf, the macro ‘__gnu__’ can
10579 serve the same purpose, although it is less readable.
10580
10581 — Macro: m4_make_list(ARG, ...)
10582 This macro exists to aid debugging of M4sugar algorithms. Its net
10583 effect is similar to ‘m4_dquote’—it produces a quoted list of
10584 quoted arguments, for each ARG. The difference is that this
10585 version uses a comma-newline separator instead of just comma, to
10586 improve readability of the list; with the result that it is less
10587 efficient than ‘m4_dquote’.
10588 m4_define([zero],[0])m4_define([one],[1])m4_define([two],[2])dnl
10589 m4_dquote(zero, [one], [[two]])
10590 ⇒[0],[one],[[two]]
10591 m4_make_list(zero, [one], [[two]])
10592 ⇒[0],
10593 ⇒[one],
10594 ⇒[[two]]
10595 m4_foreach([number], m4_dquote(zero, [one], [[two]]), [ number])
10596 ⇒ 0 1 two
10597 m4_foreach([number], m4_make_list(zero, [one], [[two]]), [ number])
10598 ⇒ 0 1 two
10599
10600 — Macro: m4_quote(ARG, ...)
10601 Return the arguments as a single entity, i.e., wrap them into a
10602 pair of quotes. This effectively collapses multiple arguments into
10603 one, although it loses whitespace after unquoted commas in the
10604 process.
10605
10606 — Macro: m4_reverse(ARG, ...)
10607 Outputs each argument with the same level of quoting, but in
10608 reverse order, and with space following each comma for readability.
10609
10610 m4_define([active], [ACT,IVE])
10611 ⇒
10612 m4_reverse(active, [active])
10613 ⇒active, IVE, ACT
10614
10615 — Macro: m4_unquote(ARG, ...)
10616 This macro was introduced in Autoconf 2.62. Expand each argument,
10617 separated by commas. For a single ARG, this effectively removes a
10618 layer of quoting, and ‘m4_unquote([ARG])’ is more efficient than
10619 the equivalent ‘m4_do([ARG])’. For multiple arguments, this
10620 results in an unquoted list of expansions. This is commonly used
10621 with ‘m4_split’, in order to convert a single quoted list into a
10622 series of quoted elements.
10623
10624 The following example aims at emphasizing the difference between
10625 several scenarios: not using these macros, using ‘m4_defn’, using
10626 ‘m4_quote’, using ‘m4_dquote’, and using ‘m4_expand’.
10627
10628 $ cat example.m4
10629 dnl Overquote, so that quotes are visible.
10630 m4_define([show], [$[]1 = [$1], $[]@ = [$@]])
10631 m4_define([a], [A])
10632 m4_define([mkargs], [1, 2[,] 3])
10633 m4_define([arg1], [[$1]])
10634 m4_divert([0])dnl
10635 show(a, b)
10636 show([a, b])
10637 show(m4_quote(a, b))
10638 show(m4_dquote(a, b))
10639 show(m4_expand([a, b]))
10640
10641 arg1(mkargs)
10642 arg1([mkargs])
10643 arg1(m4_defn([mkargs]))
10644 arg1(m4_quote(mkargs))
10645 arg1(m4_dquote(mkargs))
10646 arg1(m4_expand([mkargs]))
10647 $ autom4te -l m4sugar example.m4
10648 $1 = A, $@ = [A],[b]
10649 $1 = a, b, $@ = [a, b]
10650 $1 = A,b, $@ = [A,b]
10651 $1 = [A],[b], $@ = [[A],[b]]
10652 $1 = A, b, $@ = [A, b]
10653
10654 1
10655 mkargs
10656 1, 2[,] 3
10657 1,2, 3
10658 [1],[2, 3]
10659 1, 2, 3
10660
10661 
10662 File: autoconf.info, Node: Text processing Macros, Next: Number processing Macros, Prev: Evaluation Macros, Up: Programming in M4sugar
10663
10664 8.3.7 String manipulation in M4
10665 -------------------------------
10666
10667 The following macros may be used to manipulate strings in M4. Many of
10668 the macros in this section intentionally result in quoted strings as
10669 output, rather than subjecting the arguments to further expansions. As
10670 a result, if you are manipulating text that contains active M4
10671 characters, the arguments are passed with single quoting rather than
10672 double.
10673
10674 — Macro: m4_append(MACRO-NAME, STRING, [SEPARATOR])
10675 — Macro: m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR] [IF-UNIQ],
10676 [IF-DUPLICATE])
10677 Redefine MACRO-NAME to its former contents with SEPARATOR and
10678 STRING added at the end. If MACRO-NAME was undefined before (but
10679 not if it was defined but empty), then no SEPARATOR is added. As
10680 of Autoconf 2.62, neither STRING nor SEPARATOR are expanded during
10681 this macro; instead, they are expanded when MACRO-NAME is invoked.
10682
10683 ‘m4_append’ can be used to grow strings, and ‘m4_append_uniq’ to
10684 grow strings without duplicating substrings. Additionally,
10685 ‘m4_append_uniq’ takes two optional parameters as of Autoconf 2.62;
10686 IF-UNIQ is expanded if STRING was appended, and IF-DUPLICATE is
10687 expanded if STRING was already present. Also, ‘m4_append_uniq’
10688 warns if SEPARATOR is not empty, but occurs within STRING, since
10689 that can lead to duplicates.
10690
10691 Note that ‘m4_append’ can scale linearly in the length of the final
10692 string, depending on the quality of the underlying M4
10693 implementation, while ‘m4_append_uniq’ has an inherent quadratic
10694 scaling factor. If an algorithm can tolerate duplicates in the
10695 final string, use the former for speed. If duplicates must be
10696 avoided, consider using ‘m4_set_add’ instead (*note Set
10697 manipulation Macros::).
10698
10699 m4_define([active], [ACTIVE])dnl
10700 m4_append([sentence], [This is an])dnl
10701 m4_append([sentence], [ active ])dnl
10702 m4_append([sentence], [symbol.])dnl
10703 sentence
10704 ⇒This is an ACTIVE symbol.
10705 m4_undefine([active])dnl
10706 ⇒This is an active symbol.
10707 m4_append_uniq([list], [one], [, ], [new], [existing])
10708 ⇒new
10709 m4_append_uniq([list], [one], [, ], [new], [existing])
10710 ⇒existing
10711 m4_append_uniq([list], [two], [, ], [new], [existing])
10712 ⇒new
10713 m4_append_uniq([list], [three], [, ], [new], [existing])
10714 ⇒new
10715 m4_append_uniq([list], [two], [, ], [new], [existing])
10716 ⇒existing
10717 list
10718 ⇒one, two, three
10719 m4_dquote(list)
10720 ⇒[one],[two],[three]
10721 m4_append([list2], [one], [[, ]])dnl
10722 m4_append_uniq([list2], [two], [[, ]])dnl
10723 m4_append([list2], [three], [[, ]])dnl
10724 list2
10725 ⇒one, two, three
10726 m4_dquote(list2)
10727 ⇒[one, two, three]
10728
10729 — Macro: m4_append_uniq_w(MACRO-NAME, STRINGS)
10730 This macro was introduced in Autoconf 2.62. It is similar to
10731 ‘m4_append_uniq’, but treats STRINGS as a whitespace separated list
10732 of words to append, and only appends unique words. MACRO-NAME is
10733 updated with a single space between new words.
10734 m4_append_uniq_w([numbers], [1 1 2])dnl
10735 m4_append_uniq_w([numbers], [ 2 3 ])dnl
10736 numbers
10737 ⇒1 2 3
10738
10739 — Macro: m4_chomp(STRING)
10740 — Macro: m4_chomp_all(STRING)
10741 Output STRING in quotes, but without a trailing newline. The macro
10742 ‘m4_chomp’ is slightly faster, and removes at most one newline; the
10743 macro ‘m4_chomp_all’ removes all consecutive trailing newlines.
10744 Unlike ‘m4_flatten’, embedded newlines are left intact, and
10745 backslash does not influence the result.
10746
10747 — Macro: m4_combine([SEPARATOR], PREFIX-LIST, [INFIX], SUFFIX-1,
10748 [SUFFIX-2], ...)
10749 This macro produces a quoted string containing the pairwise
10750 combination of every element of the quoted, comma-separated
10751 PREFIX-LIST, and every element from the SUFFIX arguments. Each
10752 pairwise combination is joined with INFIX in the middle, and
10753 successive pairs are joined by SEPARATOR. No expansion occurs on
10754 any of the arguments. No output occurs if either the PREFIX or
10755 SUFFIX list is empty, but the lists can contain empty elements.
10756 m4_define([a], [oops])dnl
10757 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
10758 ⇒a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
10759 m4_combine([, ], [[a], [b]], [-])
10760 ⇒
10761 m4_combine([, ], [[a], [b]], [-], [])
10762 ⇒a-, b-
10763 m4_combine([, ], [], [-], [1], [2])
10764 ⇒
10765 m4_combine([, ], [[]], [-], [1], [2])
10766 ⇒-1, -2
10767
10768 — Macro: m4_escape(STRING)
10769 Convert all instances of ‘[’, ‘]’, ‘#’, and ‘$’ within STRING into
10770 their respective quadrigraphs. The result is still a quoted
10771 string.
10772
10773 — Macro: m4_flatten(STRING)
10774 Flatten STRING into a single line. Delete all backslash-newline
10775 pairs, and replace all remaining newlines with a space. The result
10776 is still a quoted string.
10777
10778 — Macro: m4_join([SEPARATOR], ARGS...)
10779 — Macro: m4_joinall([SEPARATOR], ARGS...)
10780 Concatenate each ARG, separated by SEPARATOR. ‘joinall’ uses every
10781 argument, while ‘join’ omits empty arguments so that there are no
10782 back-to-back separators in the output. The result is a quoted
10783 string.
10784 m4_define([active], [ACTIVE])dnl
10785 m4_join([|], [one], [], [active], [two])
10786 ⇒one|active|two
10787 m4_joinall([|], [one], [], [active], [two])
10788 ⇒one||active|two
10789
10790 Note that if all you intend to do is join ARGS with commas between
10791 them, to form a quoted list suitable for ‘m4_foreach’, it is more
10792 efficient to use ‘m4_dquote’.
10793
10794 — Macro: m4_newline([TEXT])
10795 This macro was introduced in Autoconf 2.62, and expands to a
10796 newline, followed by any TEXT. It is primarily useful for
10797 maintaining macro formatting, and ensuring that M4 does not discard
10798 leading whitespace during argument collection.
10799
10800 — Macro: m4_normalize(STRING)
10801 Remove leading and trailing spaces and tabs, sequences of
10802 backslash-then-newline, and replace multiple spaces, tabs, and
10803 newlines with a single space. This is a combination of
10804 ‘m4_flatten’ and ‘m4_strip’. To determine if STRING consists only
10805 of bytes that would be removed by ‘m4_normalize’, you can use
10806 ‘m4_ifblank’.
10807
10808 — Macro: m4_re_escape(STRING)
10809 Backslash-escape all characters in STRING that are active in
10810 regexps.
10811
10812 — Macro: m4_split(STRING, [REGEXP = [\t ]+])
10813 Split STRING into an M4 list of elements quoted by ‘[’ and ‘]’,
10814 while keeping white space at the beginning and at the end. If
10815 REGEXP is given, use it instead of ‘[\t ]+’ for splitting. If
10816 STRING is empty, the result is an empty list.
10817
10818 — Macro: m4_strip(STRING)
10819 Strip whitespace from STRING. Sequences of spaces and tabs are
10820 reduced to a single space, then leading and trailing spaces are
10821 removed. The result is still a quoted string. Note that this does
10822 not interfere with newlines; if you want newlines stripped as well,
10823 consider ‘m4_flatten’, or do it all at once with ‘m4_normalize’.
10824 To quickly test if STRING has only whitespace, use ‘m4_ifblank’.
10825
10826 — Macro: m4_text_box(MESSAGE, [FRAME = -])
10827 Add a text box around MESSAGE, using FRAME as the border character
10828 above and below the message. The FRAME argument must be a single
10829 byte, and does not support quadrigraphs. The frame correctly
10830 accounts for the subsequent expansion of MESSAGE. For example:
10831 m4_define([macro], [abc])dnl
10832 m4_text_box([macro])
10833 ⇒## --- ##
10834 ⇒## abc ##
10835 ⇒## --- ##
10836
10837 The MESSAGE must contain balanced quotes and parentheses, although
10838 quadrigraphs can be used to work around this.
10839
10840 — Macro: m4_text_wrap(STRING, [PREFIX], [PREFIX1 = PREFIX], [WIDTH =
10841 79])
10842 Break STRING into a series of whitespace-separated words, then
10843 output those words separated by spaces, and wrapping lines any time
10844 the output would exceed WIDTH columns. If given, PREFIX1 begins
10845 the first line, and PREFIX begins all wrapped lines. If PREFIX1 is
10846 longer than PREFIX, then the first line consists of just PREFIX1.
10847 If PREFIX is longer than PREFIX1, padding is inserted so that the
10848 first word of STRING begins at the same indentation as all wrapped
10849 lines. Note that using literal tab characters in any of the
10850 arguments will interfere with the calculation of width. No
10851 expansions occur on PREFIX, PREFIX1, or the words of STRING,
10852 although quadrigraphs are recognized.
10853
10854 For some examples:
10855 m4_text_wrap([Short string */], [ ], [/* ], [20])
10856 ⇒/* Short string */
10857 m4_text_wrap([Much longer string */], [ ], [/* ], [20])
10858 ⇒/* Much longer
10859 ⇒ string */
10860 m4_text_wrap([Short doc.], [ ], [ --short ], [30])
10861 ⇒ --short Short doc.
10862 m4_text_wrap([Short doc.], [ ], [ --too-wide ], [30])
10863 ⇒ --too-wide
10864 ⇒ Short doc.
10865 m4_text_wrap([Super long documentation.], [ ],
10866 [ --too-wide ], 30)
10867 ⇒ --too-wide
10868 ⇒ Super long
10869 ⇒ documentation.
10870
10871 — Macro: m4_tolower(STRING)
10872 — Macro: m4_toupper(STRING)
10873 Return STRING with letters converted to upper or lower case,
10874 respectively.
10875
10876 
10877 File: autoconf.info, Node: Number processing Macros, Next: Set manipulation Macros, Prev: Text processing Macros, Up: Programming in M4sugar
10878
10879 8.3.8 Arithmetic computation in M4
10880 ----------------------------------
10881
10882 The following macros facilitate integer arithmetic operations.
10883
10884 Where a parameter is documented as taking an arithmetic expression,
10885 you can use anything that can be parsed by ‘m4_eval’. Any other numeric
10886 parameter should consist of an optional sign followed by one or more
10887 decimal digits; it is treated as a decimal integer.
10888
10889 Macros that expand to a number do so as either ‘0’, or an optional
10890 ‘-’ followed by a nonzero decimal digit followed by zero or more decimal
10891 digits.
10892
10893 Due to ‘m4’ limitations, arithmetic expressions and numeric
10894 parameters should use only numbers that fit into a 32-bit signed
10895 integer.
10896
10897 — Macro: m4_cmp(EXPR-1, EXPR-2)
10898 Compare the arithmetic expressions EXPR-1 and EXPR-2, and expand to
10899 ‘-1’ if EXPR-1 is smaller, ‘0’ if they are equal, and ‘1’ if EXPR-1
10900 is larger.
10901
10902 — Macro: m4_list_cmp(LIST-1, LIST-2)
10903 Compare the two M4 lists consisting of comma-separated arithmetic
10904 expressions, left to right. Expand to ‘-1’ for the first element
10905 pairing where the value from LIST-1 is smaller, ‘1’ where the value
10906 from LIST-2 is smaller, or ‘0’ if both lists have the same values.
10907 If one list is shorter than the other, the remaining elements of
10908 the longer list are compared against zero.
10909 m4_list_cmp([1, 0], [1])
10910 ⇒0
10911 m4_list_cmp([1, [1 * 0]], [1, 0])
10912 ⇒0
10913 m4_list_cmp([1, 2], [1, 0])
10914 ⇒1
10915 m4_list_cmp([1, [1+1], 3],[1, 2])
10916 ⇒1
10917 m4_list_cmp([1, 2, -3], [1, 2])
10918 ⇒-1
10919 m4_list_cmp([1, 0], [1, 2])
10920 ⇒-1
10921 m4_list_cmp([1], [1, 2])
10922 ⇒-1
10923
10924 — Macro: m4_max(ARG, ...)
10925 This macro was introduced in Autoconf 2.62. Expand to the value of
10926 the maximum arithmetic expression among all the arguments.
10927
10928 — Macro: m4_min(ARG, ...)
10929 This macro was introduced in Autoconf 2.62. Expand to the value of
10930 the minimum arithmetic expression among all the arguments.
10931
10932 — Macro: m4_sign(EXPR)
10933 Expand to ‘-1’ if the arithmetic expression EXPR is negative, ‘1’
10934 if it is positive, and ‘0’ if it is zero.
10935
10936 — Macro: m4_version_compare(VERSION-1, VERSION-2)
10937 This macro was introduced in Autoconf 2.53, but had a number of
10938 usability limitations that were not lifted until Autoconf 2.62.
10939 Compare the version strings VERSION-1 and VERSION-2, and expand to
10940 ‘-1’ if VERSION-1 is smaller, ‘0’ if they are the same, or ‘1’
10941 VERSION-2 is smaller. Version strings must be a list of elements
10942 separated by ‘.’, ‘,’ or ‘-’, where each element is a number along
10943 with optional case-insensitive letters designating beta releases.
10944 The comparison stops at the leftmost element that contains a
10945 difference, although a 0 element compares equal to a missing
10946 element.
10947
10948 It is permissible to include commit identifiers in VERSION, such as
10949 an abbreviated SHA1 of the commit, provided there is still a
10950 monotonically increasing prefix to allow for accurate version-based
10951 comparisons. For example, this paragraph was written when the
10952 development snapshot of autoconf claimed to be at version
10953 ‘2.61a-248-dc51’, or 248 commits after the 2.61a release, with an
10954 abbreviated commit identification of ‘dc51’.
10955
10956 m4_version_compare([1.1], [2.0])
10957 ⇒-1
10958 m4_version_compare([2.0b], [2.0a])
10959 ⇒1
10960 m4_version_compare([1.1.1], [1.1.1a])
10961 ⇒-1
10962 m4_version_compare([1.2], [1.1.1a])
10963 ⇒1
10964 m4_version_compare([1.0], [1])
10965 ⇒0
10966 m4_version_compare([1.1pre], [1.1PRE])
10967 ⇒0
10968 m4_version_compare([1.1a], [1,10])
10969 ⇒-1
10970 m4_version_compare([2.61a], [2.61a-248-dc51])
10971 ⇒-1
10972 m4_version_compare([2.61b], [2.61a-248-dc51])
10973 ⇒1
10974
10975 — Macro: m4_version_prereq(VERSION, [IF-NEW-ENOUGH], [IF-OLD =
10976 m4_fatal])
10977 Compares VERSION against the version of Autoconf currently running.
10978 If the running version is at VERSION or newer, expand
10979 IF-NEW-ENOUGH, but if VERSION is larger than the version currently
10980 executing, expand IF-OLD, which defaults to printing an error
10981 message and exiting m4sugar with status 63. When given only one
10982 argument, this behaves like ‘AC_PREREQ’ (*note Versioning::).
10983 Remember that the autoconf philosophy favors feature checks over
10984 version checks.
10985
10986 
10987 File: autoconf.info, Node: Set manipulation Macros, Next: Forbidden Patterns, Prev: Number processing Macros, Up: Programming in M4sugar
10988
10989 8.3.9 Set manipulation in M4
10990 ----------------------------
10991
10992 Sometimes, it is necessary to track a set of data, where the order does
10993 not matter and where there are no duplicates in the set. The following
10994 macros facilitate set manipulations. Each set is an opaque object,
10995 which can only be accessed via these basic operations. The underlying
10996 implementation guarantees linear scaling for set creation, which is more
10997 efficient than using the quadratic ‘m4_append_uniq’. Both set names and
10998 values can be arbitrary strings, except for unbalanced quotes. This
10999 implementation ties up memory for removed elements until the next
11000 operation that must traverse all the elements of a set; and although
11001 that may slow down some operations until the memory for removed elements
11002 is pruned, it still guarantees linear performance.
11003
11004 — Macro: m4_set_add(SET, VALUE, [IF-UNIQ], [IF-DUP])
11005 Adds the string VALUE as a member of set SET. Expand IF-UNIQ if
11006 the element was added, or IF-DUP if it was previously in the set.
11007 Operates in amortized constant time, so that set creation scales
11008 linearly.
11009
11010 — Macro: m4_set_add_all(SET, VALUE...)
11011 Adds each VALUE to the set SET. This is slightly more efficient
11012 than repeatedly invoking ‘m4_set_add’.
11013
11014 — Macro: m4_set_contains(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
11015 Expands IF-PRESENT if the string VALUE is a member of SET,
11016 otherwise IF-ABSENT.
11017
11018 m4_set_contains([a], [1], [yes], [no])
11019 ⇒no
11020 m4_set_add([a], [1], [added], [dup])
11021 ⇒added
11022 m4_set_add([a], [1], [added], [dup])
11023 ⇒dup
11024 m4_set_contains([a], [1], [yes], [no])
11025 ⇒yes
11026 m4_set_remove([a], [1], [removed], [missing])
11027 ⇒removed
11028 m4_set_contains([a], [1], [yes], [no])
11029 ⇒no
11030 m4_set_remove([a], [1], [removed], [missing])
11031 ⇒missing
11032
11033 — Macro: m4_set_contents(SET, [SEP])
11034 — Macro: m4_set_dump(SET, [SEP])
11035 Expands to a single string consisting of all the members of the set
11036 SET, each separated by SEP, which is not expanded.
11037 ‘m4_set_contents’ leaves the elements in SET but reclaims any
11038 memory occupied by removed elements, while ‘m4_set_dump’ is a
11039 faster one-shot action that also deletes the set. No provision is
11040 made for disambiguating members that contain a non-empty SEP as a
11041 substring; use ‘m4_set_empty’ to distinguish between an empty set
11042 and the set containing only the empty string. The order of the
11043 output is unspecified; in the current implementation, part of the
11044 speed of ‘m4_set_dump’ results from using a different output order
11045 than ‘m4_set_contents’. These macros scale linearly in the size of
11046 the set before memory pruning, and ‘m4_set_contents([SET], [SEP])’
11047 is faster than ‘m4_joinall([SEP]m4_set_listc([SET]))’.
11048
11049 m4_set_add_all([a], [1], [2], [3])
11050 ⇒
11051 m4_set_contents([a], [-])
11052 ⇒1-2-3
11053 m4_joinall([-]m4_set_listc([a]))
11054 ⇒1-2-3
11055 m4_set_dump([a], [-])
11056 ⇒3-2-1
11057 m4_set_contents([a])
11058 ⇒
11059 m4_set_add([a], [])
11060 ⇒
11061 m4_set_contents([a], [-])
11062 ⇒
11063
11064 — Macro: m4_set_delete(SET)
11065 Delete all elements and memory associated with SET. This is linear
11066 in the set size, and faster than removing one element at a time.
11067
11068 — Macro: m4_set_difference(SETA, SETB)
11069 — Macro: m4_set_intersection(SETA, SETB)
11070 — Macro: m4_set_union(SETA, SETB)
11071 Compute the relation between SETA and SETB, and output the result
11072 as a list of quoted arguments without duplicates and with a leading
11073 comma. Set difference selects the elements in SETA but not SETB,
11074 intersection selects only elements in both sets, and union selects
11075 elements in either set. These actions are linear in the sum of the
11076 set sizes. The leading comma is necessary to distinguish between
11077 no elements and the empty string as the only element.
11078
11079 m4_set_add_all([a], [1], [2], [3])
11080 ⇒
11081 m4_set_add_all([b], [3], [], [4])
11082 ⇒
11083 m4_set_difference([a], [b])
11084 ⇒,1,2
11085 m4_set_difference([b], [a])
11086 ⇒,,4
11087 m4_set_intersection([a], [b])
11088 ⇒,3
11089 m4_set_union([a], [b])
11090 ⇒,1,2,3,,4
11091
11092 — Macro: m4_set_empty(SET, [IF-EMPTY], [IF-ELEMENTS])
11093 Expand IF-EMPTY if the set SET has no elements, otherwise expand
11094 IF-ELEMENTS. This macro operates in constant time. Using this
11095 macro can help disambiguate output from ‘m4_set_contents’ or
11096 ‘m4_set_list’.
11097
11098 — Macro: m4_set_foreach(SET, VARIABLE, ACTION)
11099 For each element in the set SET, expand ACTION with the macro
11100 VARIABLE defined as the set element. Behavior is unspecified if
11101 ACTION recursively lists the contents of SET (although listing
11102 other sets is acceptable), or if it modifies the set in any way
11103 other than removing the element currently contained in VARIABLE.
11104 This macro is faster than the corresponding ‘m4_foreach([VARIABLE],
11105 m4_indir([m4_dquote]m4_set_listc([SET])), [ACTION])’, although
11106 ‘m4_set_map’ might be faster still.
11107
11108 m4_set_add_all([a]m4_for([i], [1], [5], [], [,i]))
11109 ⇒
11110 m4_set_contents([a])
11111 ⇒12345
11112 m4_set_foreach([a], [i],
11113 [m4_if(m4_eval(i&1), [0], [m4_set_remove([a], i, [i])])])
11114 ⇒24
11115 m4_set_contents([a])
11116 ⇒135
11117
11118 — Macro: m4_set_list(SET)
11119 — Macro: m4_set_listc(SET)
11120 Produce a list of arguments, where each argument is a quoted
11121 element from the set SET. The variant ‘m4_set_listc’ is
11122 unambiguous, by adding a leading comma if there are any set
11123 elements, whereas the variant ‘m4_set_list’ cannot distinguish
11124 between an empty set and a set containing only the empty string.
11125 These can be directly used in macros that take multiple arguments,
11126 such as ‘m4_join’ or ‘m4_set_add_all’, or wrapped by ‘m4_dquote’
11127 for macros that take a quoted list, such as ‘m4_map’ or
11128 ‘m4_foreach’. Any memory occupied by removed elements is reclaimed
11129 during these macros.
11130
11131 m4_set_add_all([a], [1], [2], [3])
11132 ⇒
11133 m4_set_list([a])
11134 ⇒1,2,3
11135 m4_set_list([b])
11136 ⇒
11137 m4_set_listc([b])
11138 ⇒
11139 m4_count(m4_set_list([b]))
11140 ⇒1
11141 m4_set_empty([b], [0], [m4_count(m4_set_list([b]))])
11142 ⇒0
11143 m4_set_add([b], [])
11144 ⇒
11145 m4_set_list([b])
11146 ⇒
11147 m4_set_listc([b])
11148 ⇒,
11149 m4_count(m4_set_list([b]))
11150 ⇒1
11151 m4_set_empty([b], [0], [m4_count(m4_set_list([b]))])
11152 ⇒1
11153
11154 — Macro: m4_set_map(SET, ACTION)
11155 For each element in the set SET, expand ACTION with a single
11156 argument of the set element. Behavior is unspecified if ACTION
11157 recursively lists the contents of SET (although listing other sets
11158 is acceptable), or if it modifies the set in any way other than
11159 removing the element passed as an argument. This macro is faster
11160 than either corresponding counterpart of
11161 ‘m4_map_args([ACTION]m4_set_listc([SET]))’ or
11162 ‘m4_set_foreach([SET], [var], [ACTION(m4_defn([var]))])’. It is
11163 possible to use ‘m4_curry’ if more than one argument is needed for
11164 ACTION, although it is more efficient to use ‘m4_set_map_sep’ in
11165 that case.
11166
11167 — Macro: m4_set_map_sep(SET, [PRE], [POST], [SEP])
11168 For each element in the set SET, expand ‘PRE[element]POST’,
11169 additionally expanding SEP between elements. Behavior is
11170 unspecified if the expansion recursively lists the contents of SET
11171 (although listing other sets is acceptable), or if it modifies the
11172 set in any way other than removing the element visited by the
11173 expansion. This macro provides the most efficient means for
11174 non-destructively visiting the elements of a set; in particular,
11175 ‘m4_set_map([SET], [ACTION])’ is equivalent to
11176 ‘m4_set_map_sep([SET], [ACTION(], [)])’.
11177
11178 — Macro: m4_set_remove(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
11179 If VALUE is an element in the set SET, then remove it and expand
11180 IF-PRESENT. Otherwise expand IF-ABSENT. This macro operates in
11181 constant time so that multiple removals will scale linearly rather
11182 than quadratically; but when used outside of ‘m4_set_foreach’ or
11183 ‘m4_set_map’, it leaves memory occupied until the set is later
11184 compacted by ‘m4_set_contents’ or ‘m4_set_list’. Several other set
11185 operations are then less efficient between the time of element
11186 removal and subsequent memory compaction, but still maintain their
11187 guaranteed scaling performance.
11188
11189 — Macro: m4_set_size(SET)
11190 Expand to the size of the set SET. This implementation operates in
11191 constant time, and is thus more efficient than
11192 ‘m4_eval(m4_count(m4_set_listc([set])) - 1)’.
11193
11194 
11195 File: autoconf.info, Node: Forbidden Patterns, Prev: Set manipulation Macros, Up: Programming in M4sugar
11196
11197 8.3.10 Forbidden Patterns
11198 -------------------------
11199
11200 M4sugar provides a means to define suspicious patterns, patterns
11201 describing tokens which should not be found in the output. For
11202 instance, if an Autoconf ‘configure’ script includes tokens such as
11203 ‘AC_DEFINE’, or ‘dnl’, then most probably something went wrong
11204 (typically a macro was not evaluated because of overquotation).
11205
11206 M4sugar forbids all the tokens matching ‘^_?m4_’ and ‘^dnl$’.
11207 Additional layers, such as M4sh and Autoconf, add additional forbidden
11208 patterns to the list.
11209
11210 — Macro: m4_pattern_forbid(PATTERN)
11211 Declare that no token matching PATTERN must be found in the output.
11212 The output file is (temporarily) split into one word per line as
11213 part of the ‘autom4te’ post-processing, with each line (and
11214 therefore word) then being checked against the Perl regular
11215 expression PATTERN. If the regular expression matches, and
11216 ‘m4_pattern_allow’ does not also match, then an error is raised.
11217
11218 Comments are not checked; this can be a problem if, for instance,
11219 you have some macro left unexpanded after an ‘#include’. No
11220 consensus is currently found in the Autoconf community, as some
11221 people consider it should be valid to name macros in comments
11222 (which doesn’t make sense to the authors of this documentation:
11223 input, such as macros, should be documented by ‘dnl’ comments;
11224 reserving ‘#’-comments to document the output).
11225
11226 As an example, if you define your own macros that begin with ‘M_’
11227 and are composed from capital letters and underscores, the
11228 specification of ‘m4_pattern_forbid([^M_[A-Z_]+])’ will ensure all
11229 your macros are expanded when not used in comments.
11230
11231 As an example of a common use of this macro, consider what happens
11232 in packages that want to use the ‘pkg-config’ script via the
11233 third-party ‘PKG_CHECK_MODULES’ macro. By default, if a developer
11234 checks out the development tree but has not yet installed the
11235 pkg-config macros locally, they can manage to successfully run
11236 ‘autoconf’ on the package, but the resulting ‘configure’ file will
11237 likely result in a confusing shell message about a syntax error on
11238 the line mentioning the unexpanded ‘PKG_CHECK_MODULES’ macro. On
11239 the other hand, if ‘configure.ac’ includes
11240 ‘m4_pattern_forbid([^PKG_])’, the missing pkg-config macros will be
11241 detected immediately without allowing ‘autoconf’ to succeed.
11242
11243 Of course, you might encounter exceptions to these generic rules, for
11244 instance you might have to refer to ‘$m4_flags’.
11245
11246 — Macro: m4_pattern_allow(PATTERN)
11247 Any token matching PATTERN is allowed, including if it matches an
11248 ‘m4_pattern_forbid’ pattern.
11249
11250 For example, Gnulib uses ‘m4_pattern_forbid([^gl_])’ to reserve the
11251 ‘gl_’ namespace for itself, but also uses
11252 ‘m4_pattern_allow([^gl_ES$])’ to avoid a false negative on the
11253 valid locale name.
11254
11255 
11256 File: autoconf.info, Node: Debugging via autom4te, Prev: Programming in M4sugar, Up: Programming in M4
11257
11258 8.4 Debugging via autom4te
11259 ==========================
11260
11261 At times, it is desirable to see what was happening inside m4, to see
11262 why output was not matching expectations. However, post-processing done
11263 by ‘autom4te’ means that directly using the m4 builtin ‘m4_traceon’ is
11264 likely to interfere with operation. Also, frequent diversion changes
11265 and the concept of forbidden tokens make it difficult to use ‘m4_defn’
11266 to generate inline comments in the final output.
11267
11268 There are a couple of tools to help with this. One is the use of the
11269 ‘--trace’ option provided by ‘autom4te’ (as well as each of the programs
11270 that wrap ‘autom4te’, such as ‘autoconf’), in order to inspect when a
11271 macro is called and with which arguments. For example, when this
11272 paragraph was written, the autoconf version could be found by:
11273
11274 $ autoconf --trace=AC_INIT
11275 configure.ac:23:AC_INIT:GNU Autoconf:2.63b.95-3963:[email protected]
11276 $ autoconf --trace='AC_INIT:version is $2'
11277 version is 2.63b.95-3963
11278
11279 Another trick is to print out the expansion of various m4 expressions
11280 to standard error or to an independent file, with no further m4
11281 expansion, and without interfering with diversion changes or the
11282 post-processing done to standard output. ‘m4_errprintn’ shows a given
11283 expression on standard error. For example, if you want to see the
11284 expansion of an autoconf primitive or of one of your autoconf macros,
11285 you can do it like this:
11286
11287 $ cat <<\EOF > configure.ac
11288 AC_INIT
11289 m4_errprintn([The definition of AC_DEFINE_UNQUOTED:])
11290 m4_errprintn(m4_defn([AC_DEFINE_UNQUOTED]))
11291 AC_OUTPUT
11292 EOF
11293 $ autoconf
11294 error→The definition of AC_DEFINE_UNQUOTED:
11295 error→_AC_DEFINE_Q([], $@)
11296
11297 
11298 File: autoconf.info, Node: Programming in M4sh, Next: Writing Autoconf Macros, Prev: Programming in M4, Up: Top
11299
11300 9 Programming in M4sh
11301 *********************
11302
11303 M4sh, pronounced “mash”, is aiming at producing portable Bourne shell
11304 scripts. This name was coined by Lars J. Aas, who notes that, according
11305 to the Webster’s Revised Unabridged Dictionary (1913):
11306
11307 Mash \Mash\, n. [Akin to G. meisch, maisch, meische, maische,
11308 mash, wash, and prob. to AS. miscian to mix. See “Mix”.]
11309
11310 1. A mass of mixed ingredients reduced to a soft pulpy state by
11311 beating or pressure...
11312
11313 2. A mixture of meal or bran and water fed to animals.
11314
11315 3. A mess; trouble. [Obs.] –Beau. & Fl.
11316
11317 M4sh reserves the M4 macro namespace ‘^_AS_’ for internal use, and
11318 the namespace ‘^AS_’ for M4sh macros. It also reserves the shell and
11319 environment variable namespace ‘^as_’, and the here-document delimiter
11320 namespace ‘^_AS[A-Z]’ in the output file. You should not define your
11321 own macros or output shell code that conflicts with these namespaces.
11322
11323 * Menu:
11324
11325 * Common Shell Constructs:: Portability layer for common shell constructs
11326 * Polymorphic Variables:: Support for indirect variable names
11327 * Initialization Macros:: Macros to establish a sane shell environment
11328 * File Descriptor Macros:: File descriptor macros for input and output
11329
11330 
11331 File: autoconf.info, Node: Common Shell Constructs, Next: Polymorphic Variables, Up: Programming in M4sh
11332
11333 9.1 Common Shell Constructs
11334 ===========================
11335
11336 M4sh provides portable alternatives for some common shell constructs
11337 that unfortunately are not portable in practice.
11338
11339 — Macro: AS_BOX(TEXT, [CHAR = -])
11340 Expand into shell code that will output TEXT surrounded by a box
11341 with CHAR in the top and bottom border. TEXT should not contain a
11342 newline, but may contain shell expansions valid for unquoted
11343 here-documents. CHAR defaults to ‘-’, but can be any character
11344 except ‘/’, ‘'’, ‘"’, ‘\’, ‘&’, or ‘`’. This is useful for
11345 outputting a comment box into log files to separate distinct phases
11346 of script operation.
11347
11348 — Macro: AS_CASE(WORD, [PATTERN1], [IF-MATCHED1], ..., [DEFAULT])
11349 Expand into a shell ‘case’ statement, where WORD is matched against
11350 one or more patterns. IF-MATCHED is run if the corresponding
11351 pattern matched WORD, else DEFAULT is run. *Note Prerequisite
11352 Macros:: for why this macro should be used instead of plain ‘case’
11353 in code outside of an ‘AC_DEFUN’ macro, when the contents of the
11354 ‘case’ use ‘AC_REQUIRE’ directly or indirectly. *Note Limitations
11355 of Shell Builtins: case, for how this macro avoids some portability
11356 issues. *Note Balancing Parentheses:: for how this macro lets you
11357 write code with balanced parentheses even if your code must run on
11358 obsolescent shells.
11359
11360 — Macro: AS_DIRNAME(FILE-NAME)
11361 Output the directory portion of FILE-NAME. For example, if ‘$file’
11362 is ‘/one/two/three’, the command ‘dir=`AS_DIRNAME(["$file"])`’ sets
11363 ‘dir’ to ‘/one/two’.
11364
11365 ‘AS_DIRNAME’ was designed long ago when the ‘dirname’ command was
11366 not universally supported. Nowadays one can safely use
11367 ‘dir=`dirname -- "$file"`’ instead. This interface may be improved
11368 in the future to avoid forks and losing trailing newlines.
11369
11370 — Macro: AS_ECHO(WORD)
11371 Emit WORD to the standard output, followed by a newline. The WORD
11372 must be a single shell word (typically a quoted string). Output
11373 the shell expansion of WORD as-is, even if it starts with ‘-’ or
11374 contains ‘\’. Redirections can be placed outside the macro
11375 invocation.
11376
11377 If the shell variable FOO could contain ‘\’ or leading ‘-’.
11378 ‘AS_ECHO(["$foo"])’ is more portable than ‘echo "$foo"’. *Note
11379 Limitations of Shell Builtins: echo.
11380
11381 Also, ‘AS_ECHO(["$foo"])’ is often easier to read than the ‘printf
11382 '%s\n' "$foo"’ that it stands for. However, because it employs ‘'’
11383 characters, in contexts where ‘'’ is not allowed it is better to
11384 use ‘printf’ directly. For example, ‘`eval
11385 'foo=${'AS_ESCAPE([[$1]], [`\])'};printf "%s\\n" "$foo")'`’ would
11386 not work if ‘printf’ were replaced with ‘AS_ECHO’.
11387
11388 — Macro: AS_ECHO_N(WORD)
11389 Act like ‘AS_ECHO(WORD)’, except do not output a following newline.
11390
11391 — Macro: AS_ESCAPE(STRING, [CHARS = `\"$])
11392 Expands to STRING, with any characters in CHARS escaped with a
11393 backslash (‘\’). CHARS should be at most four bytes long, and only
11394 contain characters from the set ‘`\"$’; however, characters may be
11395 safely listed more than once in CHARS for the sake of syntax
11396 highlighting editors. The current implementation expands STRING
11397 after adding escapes; if STRING contains macro calls that in turn
11398 expand to text needing shell quoting, you can use
11399 ‘AS_ESCAPE(m4_dquote(m4_expand([string])))’.
11400
11401 The default for CHARS (‘\"$`’) is the set of characters needing
11402 escapes when STRING will be used literally within double quotes.
11403 One common variant is the set of characters to protect when STRING
11404 will be used literally within back-ticks or an unquoted
11405 here-document (‘\$`’). Another common variant is ‘""’, which can
11406 be used to form a double-quoted string containing the same
11407 expansions that would have occurred if STRING were expanded in an
11408 unquoted here-document; however, when using this variant, care must
11409 be taken that STRING does not use double quotes within complex
11410 variable expansions (such as ‘${foo-`echo "hi"`}’) that would be
11411 broken with improper escapes.
11412
11413 This macro is often used with ‘AS_ECHO’. For an example, observe
11414 the output generated by the shell code generated from this snippet:
11415
11416 foo=bar
11417 AS_ECHO(["AS_ESCAPE(["$foo" = ])AS_ESCAPE(["$foo"], [""])"])
11418 ⇒"$foo" = "bar"
11419 m4_define([macro], [a, [\b]])
11420 AS_ECHO(["AS_ESCAPE([[macro]])"])
11421 ⇒macro
11422 AS_ECHO(["AS_ESCAPE([macro])"])
11423 ⇒a, b
11424 AS_ECHO(["AS_ESCAPE(m4_dquote(m4_expand([macro])))"])
11425 ⇒a, \b
11426
11427 To escape a string that will be placed within single quotes, use:
11428
11429 m4_bpatsubst([[STRING]], ['], ['\\''])
11430
11431 — Macro: AS_EXECUTABLE_P(FILE)
11432 Emit code to probe whether FILE is a regular file with executable
11433 permissions (and not a directory with search permissions). The
11434 caller is responsible for quoting FILE.
11435
11436 — Macro: AS_EXIT([STATUS = $?])
11437 Emit code to exit the shell with STATUS, defaulting to ‘$?’. This
11438 macro works around shells that see the exit status of the command
11439 prior to ‘exit’ inside a ‘trap 0’ handler (*note Limitations of
11440 Shell Builtins: trap.).
11441
11442 — Macro: AS_IF(TEST1, [RUN-IF-TRUE1], ..., [RUN-IF-FALSE])
11443 Run shell code TEST1. If TEST1 exits with a zero status then run
11444 shell code RUN-IF-TRUE1, else examine further tests. If no test
11445 exits with a zero status, run shell code RUN-IF-FALSE, with
11446 simplifications if either RUN-IF-TRUE1 or RUN-IF-FALSE is empty.
11447 For example,
11448
11449 AS_IF([test "x$foo" = xyes], [HANDLE_FOO([yes])],
11450 [test "x$foo" != xno], [HANDLE_FOO([maybe])],
11451 [echo foo not specified])
11452
11453 ensures any required macros of ‘HANDLE_FOO’ are expanded before the
11454 first test.
11455
11456 This macro should be used instead of plain ‘if’ in code outside of
11457 an ‘AC_DEFUN’ macro, when the contents of the ‘if’ use ‘AC_REQUIRE’
11458 directly or indirectly (*note Prerequisite Macros::).
11459
11460 — Macro: AS_MKDIR_P(FILE-NAME)
11461 Make the directory FILE-NAME, including intervening directories as
11462 necessary. This is equivalent to ‘mkdir -p -- FILE-NAME’. If
11463 creation of FILE-NAME fails, exit the script.
11464
11465 Also see the ‘AC_PROG_MKDIR_P’ macro (*note Particular Programs::).
11466
11467 — Macro: AS_SET_STATUS(STATUS)
11468 Emit shell code to set the value of ‘$?’ to STATUS, as efficiently
11469 as possible. However, this is not guaranteed to abort a shell
11470 running with ‘set -e’ (*note Limitations of Shell Builtins: set.).
11471 This should also be used at the end of a complex shell function
11472 instead of ‘return’ (*note Shell Functions::) to avoid a DJGPP
11473 shell bug.
11474
11475 — Macro: AS_TR_CPP(EXPRESSION)
11476 Transform EXPRESSION into a valid right-hand side for a C
11477 ‘#define’. For example:
11478
11479 # This outputs "#define HAVE_CHAR_P 1".
11480 # Notice the m4 quoting around #, to prevent an m4 comment
11481 type="char *"
11482 echo "[#]define AS_TR_CPP([HAVE_$type]) 1"
11483
11484 — Macro: AS_TR_SH(EXPRESSION)
11485 Transform EXPRESSION into shell code that generates a valid shell
11486 variable name. The result is literal when possible at m4 time, but
11487 must be used with ‘eval’ if EXPRESSION causes shell indirections.
11488 For example:
11489
11490 # This outputs "Have it!".
11491 header="sys/some file.h"
11492 eval AS_TR_SH([HAVE_$header])=yes
11493 if test "x$HAVE_sys_some_file_h" = xyes; then echo "Have it!"; fi
11494
11495 — Macro: AS_SET_CATFILE(VAR, DIR, FILE)
11496 Set the polymorphic shell variable VAR to DIR/FILE, but optimizing
11497 the common cases (DIR or FILE is ‘.’, FILE is absolute, etc.).
11498
11499 — Macro: AS_UNSET(VAR)
11500 Unsets the shell variable VAR, working around bugs in older shells
11501 (*note Limitations of Shell Builtins: unset.). VAR can be a
11502 literal or indirect variable name.
11503
11504 — Macro: AS_VERSION_COMPARE(VERSION-1, VERSION-2, [ACTION-IF-LESS],
11505 [ACTION-IF-EQUAL], [ACTION-IF-GREATER])
11506 Compare two strings VERSION-1 and VERSION-2, possibly containing
11507 shell variables, as version strings, and expand ACTION-IF-LESS,
11508 ACTION-IF-EQUAL, or ACTION-IF-GREATER depending upon the result.
11509 The algorithm to compare is similar to the one used by strverscmp
11510 in glibc (*note String/Array Comparison: (libc)String/Array
11511 Comparison.).
11512
11513 
11514 File: autoconf.info, Node: Polymorphic Variables, Next: Initialization Macros, Prev: Common Shell Constructs, Up: Programming in M4sh
11515
11516 9.2 Support for indirect variable names
11517 =======================================
11518
11519 Often, it is convenient to write a macro that will emit shell code
11520 operating on a shell variable. The simplest case is when the variable
11521 name is known. But a more powerful idiom is writing shell code that can
11522 work through an indirection, where another variable or command
11523 substitution produces the name of the variable to actually manipulate.
11524 M4sh supports the notion of polymorphic shell variables, making it easy
11525 to write a macro that can deal with either literal or indirect variable
11526 names and output shell code appropriate for both use cases. Behavior is
11527 undefined if expansion of an indirect variable does not result in a
11528 literal variable name.
11529
11530 — Macro: AS_LITERAL_IF(EXPRESSION, [IF-LITERAL], [IF-NOT],
11531 [IF-SIMPLE-REF = IF-NOT])
11532 — Macro: AS_LITERAL_WORD_IF(EXPRESSION, [IF-LITERAL], [IF-NOT],
11533 [IF-SIMPLE-REF = IF-NOT])
11534 If the expansion of EXPRESSION is definitely a shell literal,
11535 expand IF-LITERAL. If the expansion of EXPRESSION looks like it
11536 might contain shell indirections (such as ‘$var’ or ‘`expr`’), then
11537 IF-NOT is expanded. Sometimes, it is possible to output optimized
11538 code if EXPRESSION consists only of shell variable expansions (such
11539 as ‘${var}’), in which case IF-SIMPLE-REF can be provided; but
11540 defaulting to IF-NOT should always be safe. ‘AS_LITERAL_WORD_IF’
11541 only expands IF-LITERAL if EXPRESSION looks like a single shell
11542 word, containing no whitespace; while ‘AS_LITERAL_IF’ allows
11543 whitespace in EXPRESSION.
11544
11545 In order to reduce the time spent recognizing whether an EXPRESSION
11546 qualifies as a literal or a simple indirection, the implementation
11547 is somewhat conservative: EXPRESSION must be a single shell word
11548 (possibly after stripping whitespace), consisting only of bytes
11549 that would have the same meaning whether unquoted or enclosed in
11550 double quotes (for example, ‘a.b’ results in IF-LITERAL, even
11551 though it is not a valid shell variable name; while both ‘'a'’ and
11552 ‘[$]’ result in IF-NOT, because they behave differently than
11553 ‘"'a'"’ and ‘"[$]"’). This macro can be used in contexts for
11554 recognizing portable file names (such as in the implementation of
11555 ‘AC_LIBSOURCE’), or coupled with some transliterations for forming
11556 valid variable names (such as in the implementation of ‘AS_TR_SH’,
11557 which uses an additional ‘m4_translit’ to convert ‘.’ to ‘_’).
11558
11559 This example shows how to read the contents of the shell variable
11560 ‘bar’, exercising all three arguments to ‘AS_LITERAL_IF’. It
11561 results in a script that will output the line ‘hello’ three times.
11562
11563 AC_DEFUN([MY_ACTION],
11564 [AS_LITERAL_IF([$1],
11565 [AS_ECHO(["$$1"])],
11566 [AS_VAR_COPY([var], [$1])
11567 AS_ECHO(["$var"])],
11568 [AS_ECHO(["$'"$1"\"])])])
11569 foo=bar bar=hello
11570 MY_ACTION([bar])
11571 MY_ACTION([`echo bar`])
11572 MY_ACTION([$foo])
11573
11574 — Macro: AS_VAR_APPEND(VAR, TEXT)
11575 Emit shell code to append the shell expansion of TEXT to the end of
11576 the current contents of the polymorphic shell variable VAR, taking
11577 advantage of shells that provide the ‘+=’ extension for more
11578 efficient scaling.
11579
11580 For situations where the final contents of VAR are relatively short
11581 (less than 256 bytes), it is more efficient to use the simpler code
11582 sequence of ‘VAR=${VAR}TEXT’ (or its polymorphic equivalent of
11583 ‘AS_VAR_COPY([t], [VAR])’ and ‘AS_VAR_SET([VAR], ["$t"TEXT])’).
11584 But in the case when the script will be repeatedly appending text
11585 into ‘var’, issues of scaling start to become apparent. A naive
11586 implementation requires execution time linear to the length of the
11587 current contents of VAR as well as the length of TEXT for a single
11588 append, for an overall quadratic scaling with multiple appends.
11589 This macro takes advantage of shells which provide the extension
11590 ‘VAR+=TEXT’, which can provide amortized constant time for a single
11591 append, for an overall linear scaling with multiple appends. Note
11592 that unlike ‘AS_VAR_SET’, this macro requires that TEXT be quoted
11593 properly to avoid field splitting and file name expansion.
11594
11595 — Macro: AS_VAR_ARITH(VAR, EXPRESSION)
11596 Emit shell code to compute the arithmetic expansion of EXPRESSION,
11597 assigning the result as the contents of the polymorphic shell
11598 variable VAR. The code takes advantage of shells that provide
11599 ‘$(())’ for fewer forks, but uses ‘expr’ as a fallback. Therefore,
11600 the syntax for a valid EXPRESSION is rather limited: all operators
11601 must occur as separate shell arguments and with proper quoting; the
11602 only operators supported are ‘*’, ‘/’, ‘%’, binary ‘+’, binary ‘-’,
11603 ‘>’, ‘>=’, ‘<’, ‘<=’, ‘!=’, ‘&’, and ‘|’; all variables containing
11604 numbers must be expanded prior to the computation; the first shell
11605 argument must not start with ‘-’; and each number must be an
11606 optional ‘-’ followed by one or more decimal digits, where the
11607 first digit is nonzero if there is more than one digit. In the
11608 following example, this snippet will print ‘(2+3)*4 == 20’.
11609
11610 bar=3
11611 AS_VAR_ARITH([foo], [\( 2 + $bar \) \* 4])
11612 echo "(2+$bar)*4 == $foo"
11613
11614 — Macro: AS_VAR_COPY(DEST, SOURCE)
11615 Emit shell code to assign the contents of the polymorphic shell
11616 variable SOURCE to the polymorphic shell variable DEST. For
11617 example, executing this M4sh snippet will output ‘bar hi’:
11618
11619 foo=bar bar=hi
11620 AS_VAR_COPY([a], [foo])
11621 AS_VAR_COPY([b], [$foo])
11622 echo "$a $b"
11623
11624 When it is necessary to access the contents of an indirect variable
11625 inside a shell double-quoted context, the recommended idiom is to
11626 first copy the contents into a temporary literal shell variable.
11627
11628 for header in stdint_h inttypes_h ; do
11629 AS_VAR_COPY([var], [ac_cv_header_$header])
11630 AS_ECHO(["$header detected: $var"])
11631 done
11632
11633 — Macro: AS_VAR_IF(VAR, [WORD], [IF-EQUAL], [IF-NOT-EQUAL])
11634 Output a shell conditional statement. If the contents of the
11635 polymorphic shell variable VAR match the string WORD, execute
11636 IF-EQUAL; otherwise execute IF-NOT-EQUAL. WORD must be a single
11637 shell word (typically a quoted string). Avoids shell bugs if an
11638 interrupt signal arrives while a command substitution in VAR is
11639 being expanded.
11640
11641 — Macro: AS_VAR_PUSHDEF(M4-NAME, VALUE)
11642 — Macro: AS_VAR_POPDEF(M4-NAME)
11643 A common M4sh idiom involves composing shell variable names from an
11644 m4 argument (for example, writing a macro that uses a cache
11645 variable). VALUE can be an arbitrary string, which will be
11646 transliterated into a valid shell name by ‘AS_TR_SH’. In order to
11647 access the composed variable name based on VALUE, it is easier to
11648 declare a temporary m4 macro M4-NAME with ‘AS_VAR_PUSHDEF’, then
11649 use that macro as the argument to subsequent ‘AS_VAR’ macros as a
11650 polymorphic variable name, and finally free the temporary macro
11651 with ‘AS_VAR_POPDEF’. These macros are often followed with ‘dnl’,
11652 to avoid excess newlines in the output.
11653
11654 Here is an involved example, that shows the power of writing macros
11655 that can handle composed shell variable names:
11656
11657 m4_define([MY_CHECK_HEADER],
11658 [AS_VAR_PUSHDEF([my_Header], [ac_cv_header_$1])dnl
11659 AS_VAR_IF([my_Header], [yes], [echo "header $1 detected"])dnl
11660 AS_VAR_POPDEF([my_Header])dnl
11661 ])
11662 MY_CHECK_HEADER([stdint.h])
11663 for header in inttypes.h stdlib.h ; do
11664 MY_CHECK_HEADER([$header])
11665 done
11666
11667 In the above example, ‘MY_CHECK_HEADER’ can operate on polymorphic
11668 variable names. In the first invocation, the m4 argument is
11669 ‘stdint.h’, which transliterates into a literal ‘stdint_h’. As a
11670 result, the temporary macro ‘my_Header’ expands to the literal
11671 shell name ‘ac_cv_header_stdint_h’. In the second invocation, the
11672 m4 argument to ‘MY_CHECK_HEADER’ is ‘$header’, and the temporary
11673 macro ‘my_Header’ expands to the indirect shell name
11674 ‘$as_my_Header’. During the shell execution of the for loop, when
11675 ‘$header’ contains ‘inttypes.h’, then ‘$as_my_Header’ contains
11676 ‘ac_cv_header_inttypes_h’. If this script is then run on a
11677 platform where all three headers have been previously detected, the
11678 output of the script will include:
11679
11680 header stdint.h detected
11681 header inttypes.h detected
11682 header stdlib.h detected
11683
11684 — Macro: AS_VAR_SET(VAR, [VALUE])
11685 Emit shell code to assign the contents of the polymorphic shell
11686 variable VAR to the shell expansion of VALUE. VALUE is not subject
11687 to field splitting or file name expansion, so if command
11688 substitution is used, it may be done with ‘`""`’ rather than using
11689 an intermediate variable (*note Shell Substitutions::). However,
11690 VALUE does undergo rescanning for additional macro names; behavior
11691 is unspecified if late expansion results in any shell
11692 meta-characters.
11693
11694 — Macro: AS_VAR_SET_IF(VAR, [IF-SET], [IF-UNDEF])
11695 Emit a shell conditional statement, which executes IF-SET if the
11696 polymorphic shell variable ‘var’ is set to any value, and IF-UNDEF
11697 otherwise.
11698
11699 — Macro: AS_VAR_TEST_SET(VAR)
11700 Emit a shell statement that results in a successful exit status
11701 only if the polymorphic shell variable ‘var’ is set.
11702
11703 
11704 File: autoconf.info, Node: Initialization Macros, Next: File Descriptor Macros, Prev: Polymorphic Variables, Up: Programming in M4sh
11705
11706 9.3 Initialization Macros
11707 =========================
11708
11709 — Macro: AS_BOURNE_COMPATIBLE
11710 Set up the shell to be more compatible with the Bourne shell as
11711 standardized by POSIX, if possible. This may involve setting
11712 environment variables, or setting options, or similar
11713 implementation-specific actions. This macro is deprecated, since
11714 ‘AS_INIT’ already invokes it.
11715
11716 — Macro: AS_INIT
11717 Initialize the M4sh environment. This macro calls ‘m4_init’, then
11718 outputs the ‘#! /bin/sh’ line, a notice about where the output was
11719 generated from, and code to sanitize the environment for the rest
11720 of the script. Among other initializations, this sets ‘SHELL’ to
11721 the shell chosen to run the script (*note CONFIG_SHELL::), and
11722 ‘LC_ALL’ to ensure the C locale. Finally, it changes the current
11723 diversion to ‘BODY’. ‘AS_INIT’ is called automatically by
11724 ‘AC_INIT’ and ‘AT_INIT’, so shell code in ‘configure’,
11725 ‘config.status’, and ‘testsuite’ all benefit from a sanitized shell
11726 environment.
11727
11728 — Macro: AS_INIT_GENERATED(FILE, [COMMENT])
11729 Emit shell code to start the creation of a subsidiary shell script
11730 in FILE, including changing FILE to be executable. This macro
11731 populates the child script with information learned from the parent
11732 (thus, the emitted code is equivalent in effect, but more
11733 efficient, than the code output by ‘AS_INIT’,
11734 ‘AS_BOURNE_COMPATIBLE’, and ‘AS_SHELL_SANITIZE’). If present,
11735 COMMENT is output near the beginning of the child, prior to the
11736 shell initialization code, and is subject to parameter expansion,
11737 command substitution, and backslash quote removal. The parent
11738 script should check the exit status after this macro, in case FILE
11739 could not be properly created (for example, if the disk was full).
11740 If successfully created, the parent script can then proceed to
11741 append additional M4sh constructs into the child script.
11742
11743 Note that the child script starts life without a log file open, so
11744 if the parent script uses logging (*note AS_MESSAGE_LOG_FD::), you
11745 must temporarily disable any attempts to use the log file until
11746 after emitting code to open a log within the child. On the other
11747 hand, if the parent script has ‘AS_MESSAGE_FD’ redirected somewhere
11748 besides ‘1’, then the child script already has code that copies
11749 stdout to that descriptor. Currently, the suggested idiom for
11750 writing a M4sh shell script from within another script is:
11751
11752 AS_INIT_GENERATED([FILE], [[# My child script.
11753 ]]) || { AS_ECHO(["Failed to create child script"]); AS_EXIT; }
11754 m4_pushdef([AS_MESSAGE_LOG_FD])dnl
11755 cat >> "FILE" <<\__EOF__
11756 # Code to initialize AS_MESSAGE_LOG_FD
11757 m4_popdef([AS_MESSAGE_LOG_FD])dnl
11758 # Additional code
11759 __EOF__
11760
11761 This, however, may change in the future as the M4sh interface is
11762 stabilized further.
11763
11764 Also, be aware that use of ‘LINENO’ within the child script may
11765 report line numbers relative to their location in the parent
11766 script, even when using ‘AS_LINENO_PREPARE’, if the parent script
11767 was unable to locate a shell with working ‘LINENO’ support.
11768
11769 — Macro: AS_LINENO_PREPARE
11770 Find a shell that supports the special variable ‘LINENO’, which
11771 contains the number of the currently executing line. This macro is
11772 automatically invoked by ‘AC_INIT’ in configure scripts.
11773
11774 — Macro: AS_ME_PREPARE
11775 Set up variable ‘as_me’ to be the basename of the currently
11776 executing script. This macro is automatically invoked by ‘AC_INIT’
11777 in configure scripts.
11778
11779 — Macro: AS_TMPDIR(PREFIX, [DIR = ${TMPDIR:=/tmp}])
11780 Create, as safely as possible, a temporary sub-directory within DIR
11781 with a name starting with PREFIX. PREFIX should be 2–4 characters,
11782 to make it slightly easier to identify the owner of the directory.
11783 If DIR is omitted, then the value of ‘TMPDIR’ will be used
11784 (defaulting to ‘/tmp’). On success, the name of the newly created
11785 directory is stored in the shell variable ‘tmp’. On error, the
11786 script is aborted.
11787
11788 Typically, this macro is coupled with some exit traps to delete the
11789 created directory and its contents on exit or interrupt. However,
11790 there is a slight window between when the directory is created and
11791 when the name is actually known to the shell, so an interrupt at
11792 the right moment might leave the temporary directory behind. Hence
11793 it is important to use a PREFIX that makes it easier to determine
11794 if a leftover temporary directory from an interrupted script is
11795 safe to delete.
11796
11797 If you set ‘TMPDIR=$tmp’ after invoking this macro, you should
11798 reset ‘TMPDIR’ before deleting the created directory, to avoid
11799 breaking commands that rely on ‘$TMPDIR’.
11800
11801 The use of the output variable ‘$tmp’ rather than something in the
11802 ‘as_’ namespace is historical; it has the unfortunate consequence
11803 that reusing this otherwise common name for any other purpose
11804 inside your script has the potential to break any cleanup traps
11805 designed to remove the temporary directory.
11806
11807 — Macro: AS_SHELL_SANITIZE
11808 Initialize the shell suitably for ‘configure’ scripts. This has
11809 the effect of ‘AS_BOURNE_COMPATIBLE’, and sets some other
11810 environment variables for predictable results from configuration
11811 tests. For example, it sets ‘LC_ALL’ to change to the default C
11812 locale. *Note Special Shell Variables::. This macro is
11813 deprecated, since ‘AS_INIT’ already invokes it.
11814
11815 
11816 File: autoconf.info, Node: File Descriptor Macros, Prev: Initialization Macros, Up: Programming in M4sh
11817
11818 9.4 File Descriptor Macros
11819 ==========================
11820
11821 The following macros define file descriptors used to output messages (or
11822 input values) from ‘configure’ scripts. For example:
11823
11824 AS_ECHO(["$wombats found"]) >&AS_MESSAGE_LOG_FD
11825 AS_ECHO_N(['Enter desired kangaroo count: ']) >&AS_MESSAGE_FD
11826 read kangaroos <&AS_ORIGINAL_STDIN_FD
11827
11828 However doing so is seldom needed, because Autoconf provides higher
11829 level macros as described below.
11830
11831 — Macro: AS_MESSAGE_FD
11832 The file descriptor for ‘checking for...’ messages and results. By
11833 default, ‘AS_INIT’ sets this to ‘1’ for standalone M4sh clients.
11834 However, ‘AC_INIT’ shuffles things around to another file
11835 descriptor, in order to allow the ‘-q’ option of ‘configure’ to
11836 choose whether messages should go to the script’s standard output
11837 or be discarded.
11838
11839 If you want to display some messages, consider using one of the
11840 printing macros (*note Printing Messages::) instead. Copies of
11841 messages output via these macros are also recorded in ‘config.log’.
11842
11843 — Macro: AS_MESSAGE_LOG_FD
11844 This must either be empty, or expand to a file descriptor for log
11845 messages. By default, ‘AS_INIT’ sets this macro to the empty
11846 string for standalone M4sh clients, thus disabling logging.
11847 However, ‘AC_INIT’ shuffles things around so that both ‘configure’
11848 and ‘config.status’ use ‘config.log’ for log messages. Macros that
11849 run tools, like ‘AC_COMPILE_IFELSE’ (*note Running the Compiler::),
11850 redirect all output to this descriptor. You may want to do so if
11851 you develop such a low-level macro.
11852
11853 — Macro: AS_ORIGINAL_STDIN_FD
11854 This must expand to a file descriptor for the original standard
11855 input. By default, ‘AS_INIT’ sets this macro to ‘0’ for standalone
11856 M4sh clients. However, ‘AC_INIT’ shuffles things around for
11857 safety.
11858
11859 When ‘configure’ runs, it may accidentally execute an interactive
11860 command that has the same name as the non-interactive meant to be
11861 used or checked. If the standard input was the terminal, such
11862 interactive programs would cause ‘configure’ to stop, pending some
11863 user input. Therefore ‘configure’ redirects its standard input
11864 from ‘/dev/null’ during its initialization. This is not normally a
11865 problem, since ‘configure’ normally does not need user input.
11866
11867 In the extreme case where your ‘configure’ script really needs to
11868 obtain some values from the original standard input, you can read
11869 them explicitly from ‘AS_ORIGINAL_STDIN_FD’.
11870
11871 
11872 File: autoconf.info, Node: Writing Autoconf Macros, Next: Portable Shell, Prev: Programming in M4sh, Up: Top
11873
11874 10 Writing Autoconf Macros
11875 **************************
11876
11877 When you write a feature test that could be applicable to more than one
11878 software package, the best thing to do is encapsulate it in a new macro.
11879 Here are some instructions and guidelines for writing Autoconf macros.
11880 You should also familiarize yourself with M4sugar (*note Programming in
11881 M4::) and M4sh (*note Programming in M4sh::).
11882
11883 * Menu:
11884
11885 * Macro Definitions:: Basic format of an Autoconf macro
11886 * Macro Names:: What to call your new macros
11887 * Dependencies Between Macros:: What to do when macros depend on other macros
11888 * Obsoleting Macros:: Warning about old ways of doing things
11889 * Coding Style:: Writing Autoconf macros à la Autoconf
11890
11891 
11892 File: autoconf.info, Node: Macro Definitions, Next: Macro Names, Up: Writing Autoconf Macros
11893
11894 10.1 Macro Definitions
11895 ======================
11896
11897 — Macro: AC_DEFUN(NAME, [BODY])
11898 Autoconf macros are defined using the ‘AC_DEFUN’ macro, which is
11899 similar to the M4 builtin ‘m4_define’ macro; this creates a macro
11900 named NAME and with BODY as its expansion. In addition to defining
11901 a macro, ‘AC_DEFUN’ adds to it some code that is used to constrain
11902 the order in which macros are called, while avoiding redundant
11903 output (*note Prerequisite Macros::).
11904
11905 An Autoconf macro definition looks like this:
11906
11907 AC_DEFUN(MACRO-NAME, MACRO-BODY)
11908
11909 You can refer to any arguments passed to the macro as ‘$1’, ‘$2’,
11910 etc. *Note How to define new macros: (m4)Definitions, for more complete
11911 information on writing M4 macros.
11912
11913 Most macros fall in one of two general categories. The first
11914 category includes macros which take arguments, in order to generate
11915 output parameterized by those arguments. Macros in this category are
11916 designed to be directly expanded, often multiple times, and should not
11917 be used as the argument to ‘AC_REQUIRE’. The other category includes
11918 macros which are shorthand for a fixed block of text, and therefore do
11919 not take arguments. For this category of macros, directly expanding the
11920 macro multiple times results in redundant output, so it is more common
11921 to use the macro as the argument to ‘AC_REQUIRE’, or to declare the
11922 macro with ‘AC_DEFUN_ONCE’ (*note One-Shot Macros::).
11923
11924 Be sure to properly quote both the MACRO-BODY _and_ the MACRO-NAME to
11925 avoid any problems if the macro happens to have been previously defined.
11926
11927 Each macro should have a header comment that gives its prototype, and
11928 a brief description. When arguments have default values, display them
11929 in the prototype. For example:
11930
11931 # AC_MSG_ERROR(ERROR, [EXIT-STATUS = 1])
11932 # --------------------------------------
11933 m4_define([AC_MSG_ERROR],
11934 [{ AS_MESSAGE([error: $1], [2])
11935 exit m4_default([$2], [1]); }])
11936
11937 Comments about the macro should be left in the header comment. Most
11938 other comments make their way into ‘configure’, so just keep using ‘#’
11939 to introduce comments.
11940
11941 If you have some special comments about pure M4 code, comments that
11942 make no sense in ‘configure’ and in the header comment, then use the
11943 builtin ‘dnl’: it causes M4 to discard the text through the next
11944 newline.
11945
11946 Keep in mind that ‘dnl’ is rarely needed to introduce comments; ‘dnl’
11947 is more useful to get rid of the newlines following macros that produce
11948 no output, such as ‘AC_REQUIRE’.
11949
11950 Public third-party macros need to use ‘AC_DEFUN’, and not
11951 ‘m4_define’, in order to be found by ‘aclocal’ (*note
11952 (automake)Extending aclocal::). Additionally, if it is ever determined
11953 that a macro should be made obsolete, it is easy to convert from
11954 ‘AC_DEFUN’ to ‘AU_DEFUN’ in order to have ‘autoupdate’ assist the user
11955 in choosing a better alternative, but there is no corresponding way to
11956 make ‘m4_define’ issue an upgrade notice (*note AU_DEFUN::).
11957
11958 There is another subtle, but important, difference between using
11959 ‘m4_define’ and ‘AC_DEFUN’: only the former is unaffected by
11960 ‘AC_REQUIRE’. When writing a file, it is always safe to replace a block
11961 of text with a ‘m4_define’ macro that will expand to the same text. But
11962 replacing a block of text with an ‘AC_DEFUN’ macro with the same content
11963 does not necessarily give the same results, because it changes the
11964 location where any embedded but unsatisfied ‘AC_REQUIRE’ invocations
11965 within the block will be expanded. For an example of this, see *note
11966 Expanded Before Required::.
11967
11968 
11969 File: autoconf.info, Node: Macro Names, Next: Dependencies Between Macros, Prev: Macro Definitions, Up: Writing Autoconf Macros
11970
11971 10.2 Macro Names
11972 ================
11973
11974 All of the public Autoconf macros have all-uppercase names in the
11975 namespace ‘^AC_’ to prevent them from accidentally conflicting with
11976 other text; Autoconf also reserves the namespace ‘^_AC_’ for internal
11977 macros. All shell variables that they use for internal purposes have
11978 mostly-lowercase names starting with ‘ac_’. Autoconf also uses
11979 here-document delimiters in the namespace ‘^_AC[A-Z]’. During
11980 ‘configure’, files produced by Autoconf make heavy use of the file
11981 system namespace ‘^conf’.
11982
11983 Since Autoconf is built on top of M4sugar (*note Programming in
11984 M4sugar::) and M4sh (*note Programming in M4sh::), you must also be
11985 aware of those namespaces (‘^_?\(m4\|AS\)_’). And since ‘configure.ac’
11986 is also designed to be scanned by Autoheader, Autoscan, Autoupdate, and
11987 Automake, you should be aware of the ‘^_?A[HNUM]_’ namespaces. In
11988 general, you _should not use_ the namespace of a package that does not
11989 own the macro or shell code you are writing.
11990
11991 To ensure that your macros don’t conflict with present or future
11992 Autoconf macros, you should prefix your own macro names and any shell
11993 variables they use with some other sequence. Possibilities include your
11994 initials, or an abbreviation for the name of your organization or
11995 software package. Historically, people have not always followed the
11996 rule of using a namespace appropriate for their package, and this has
11997 made it difficult for determining the origin of a macro (and where to
11998 report bugs about that macro), as well as difficult for the true
11999 namespace owner to add new macros without interference from pre-existing
12000 uses of third-party macros. Perhaps the best example of this confusion
12001 is the ‘AM_GNU_GETTEXT’ macro, which belongs, not to Automake, but to
12002 Gettext.
12003
12004 Most of the Autoconf macros’ names follow a structured naming
12005 convention that indicates the kind of feature check by the name. The
12006 macro names consist of several words, separated by underscores, going
12007 from most general to most specific. The names of their cache variables
12008 use the same convention (*note Cache Variable Names::, for more
12009 information on them).
12010
12011 The first word of the name after the namespace initials (such as
12012 ‘AC_’) usually tells the category of the feature being tested. Here are
12013 the categories used in Autoconf for specific test macros, the kind of
12014 macro that you are more likely to write. They are also used for cache
12015 variables, in all-lowercase. Use them where applicable; where they’re
12016 not, invent your own categories.
12017
12018 ‘C’
12019 C language builtin features.
12020 ‘DECL’
12021 Declarations of C variables in header files.
12022 ‘FUNC’
12023 Functions in libraries.
12024 ‘GROUP’
12025 POSIX group owners of files.
12026 ‘HEADER’
12027 Header files.
12028 ‘LIB’
12029 C libraries.
12030 ‘PROG’
12031 The base names of programs.
12032 ‘MEMBER’
12033 Members of aggregates.
12034 ‘SYS’
12035 Operating system features.
12036 ‘TYPE’
12037 C builtin or declared types.
12038 ‘VAR’
12039 C variables in libraries.
12040
12041 After the category comes the name of the particular feature being
12042 tested. Any further words in the macro name indicate particular aspects
12043 of the feature. For example, ‘AC_PROG_MAKE_SET’ checks whether ‘make’
12044 sets a variable to its own name.
12045
12046 An internal macro should have a name that starts with an underscore;
12047 Autoconf internals should therefore start with ‘_AC_’. Additionally, a
12048 macro that is an internal subroutine of another macro should have a name
12049 that starts with an underscore and the name of that other macro,
12050 followed by one or more words saying what the internal macro does. For
12051 example, ‘AC_PATH_X’ has internal macros ‘_AC_PATH_X_XMKMF’ and
12052 ‘_AC_PATH_X_DIRECT’.
12053
12054 
12055 File: autoconf.info, Node: Dependencies Between Macros, Next: Obsoleting Macros, Prev: Macro Names, Up: Writing Autoconf Macros
12056
12057 10.3 Dependencies Between Macros
12058 ================================
12059
12060 Some Autoconf macros depend on other macros having been called first in
12061 order to work correctly. Autoconf provides a way to ensure that certain
12062 macros are called if needed and a way to warn the user if macros are
12063 called in an order that might cause incorrect operation.
12064
12065 * Menu:
12066
12067 * Prerequisite Macros:: Ensuring required information
12068 * Suggested Ordering:: Warning about possible ordering problems
12069 * One-Shot Macros:: Ensuring a macro is called only once
12070
12071 
12072 File: autoconf.info, Node: Prerequisite Macros, Next: Suggested Ordering, Up: Dependencies Between Macros
12073
12074 10.3.1 Prerequisite Macros
12075 --------------------------
12076
12077 A macro that you write might need to use values that have previously
12078 been computed by other macros. For example, ‘AC_DECL_YYTEXT’ examines
12079 the output of ‘flex’ or ‘lex’, so it depends on ‘AC_PROG_LEX’ having
12080 been called first to set the shell variable ‘LEX’.
12081
12082 Rather than forcing the user of the macros to keep track of the
12083 dependencies between them, you can use the ‘AC_REQUIRE’ macro to do it
12084 automatically. ‘AC_REQUIRE’ can ensure that a macro is only called if
12085 it is needed, and only called once.
12086
12087 — Macro: AC_REQUIRE(MACRO-NAME)
12088 If the M4 macro MACRO-NAME has not already been called, call it
12089 (without any arguments). Make sure to quote MACRO-NAME with square
12090 brackets. MACRO-NAME must have been defined using ‘AC_DEFUN’ or
12091 else contain a call to ‘AC_PROVIDE’ to indicate that it has been
12092 called.
12093
12094 ‘AC_REQUIRE’ must be used inside a macro defined by ‘AC_DEFUN’; it
12095 must not be called from the top level. Also, it does not make
12096 sense to require a macro that takes parameters.
12097
12098 ‘AC_REQUIRE’ is often misunderstood. It really implements
12099 dependencies between macros in the sense that if one macro depends upon
12100 another, the latter is expanded _before_ the body of the former. To be
12101 more precise, the required macro is expanded before the outermost
12102 defined macro in the current expansion stack. In particular,
12103 ‘AC_REQUIRE([FOO])’ is not replaced with the body of ‘FOO’. For
12104 instance, this definition of macros:
12105
12106 AC_DEFUN([TRAVOLTA],
12107 [test "$body_temperature_in_Celsius" -gt 38 &&
12108 dance_floor=occupied])
12109 AC_DEFUN([NEWTON_JOHN],
12110 [test "x$hair_style" = xcurly &&
12111 dance_floor=occupied])
12112
12113 AC_DEFUN([RESERVE_DANCE_FLOOR],
12114 [if test "x`date +%A`" = xSaturday; then
12115 AC_REQUIRE([TRAVOLTA])
12116 AC_REQUIRE([NEWTON_JOHN])
12117 fi])
12118
12119 with this ‘configure.ac’
12120
12121 AC_INIT([Dance Manager], [1.0], [[email protected]])
12122 RESERVE_DANCE_FLOOR
12123 if test "x$dance_floor" = xoccupied; then
12124 AC_MSG_ERROR([cannot pick up here, let's move])
12125 fi
12126
12127 does not leave you with a better chance to meet a kindred soul on days
12128 other than Saturday, since the call to ‘RESERVE_DANCE_FLOOR’ expands to:
12129
12130 test "$body_temperature_in_Celsius" -gt 38 &&
12131 dance_floor=occupied
12132 test "x$hair_style" = xcurly &&
12133 dance_floor=occupied
12134 if test "x`date +%A`" = xSaturday; then
12135
12136
12137 fi
12138
12139 This behavior was chosen on purpose: (i) it prevents messages in
12140 required macros from interrupting the messages in the requiring macros;
12141 (ii) it avoids bad surprises when shell conditionals are used, as in:
12142
12143 if ...; then
12144 AC_REQUIRE([SOME_CHECK])
12145 fi
12146 ...
12147 SOME_CHECK
12148
12149 However, this implementation can lead to another class of problems.
12150 Consider the case where an outer macro first expands, then indirectly
12151 requires, an inner macro:
12152
12153 AC_DEFUN([TESTA], [[echo in A
12154 if test -n "$SEEN_A" ; then echo duplicate ; fi
12155 SEEN_A=:]])
12156 AC_DEFUN([TESTB], [AC_REQUIRE([TESTA])[echo in B
12157 if test -z "$SEEN_A" ; then echo bug ; fi]])
12158 AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])
12159 AC_DEFUN([OUTER], [[echo in OUTER]
12160 TESTA
12161 TESTC])
12162 OUTER
12163
12164 Prior to Autoconf 2.64, the implementation of ‘AC_REQUIRE’ recognized
12165 that ‘TESTB’ needed to be hoisted prior to the expansion of ‘OUTER’, but
12166 because ‘TESTA’ had already been directly expanded, it failed to hoist
12167 ‘TESTA’. Therefore, the expansion of ‘TESTB’ occurs prior to its
12168 prerequisites, leading to the following output:
12169
12170 in B
12171 bug
12172 in OUTER
12173 in A
12174 in C
12175
12176 Newer Autoconf is smart enough to recognize this situation, and hoists
12177 ‘TESTA’ even though it has already been expanded, but issues a syntax
12178 warning in the process. This is because the hoisted expansion of
12179 ‘TESTA’ defeats the purpose of using ‘AC_REQUIRE’ to avoid redundant
12180 code, and causes its own set of problems if the hoisted macro is not
12181 idempotent:
12182
12183 in A
12184 in B
12185 in OUTER
12186 in A
12187 duplicate
12188 in C
12189
12190 The bug is not in Autoconf, but in the macro definitions. If you
12191 ever pass a particular macro name to ‘AC_REQUIRE’, then you are implying
12192 that the macro only needs to be expanded once. But to enforce this,
12193 either the macro must be declared with ‘AC_DEFUN_ONCE’ (although this
12194 only helps in Autoconf 2.64 or newer), or all uses of that macro should
12195 be through ‘AC_REQUIRE’; directly expanding the macro defeats the point
12196 of using ‘AC_REQUIRE’ to eliminate redundant expansion. In the example,
12197 this rule of thumb was violated because ‘TESTB’ requires ‘TESTA’ while
12198 ‘OUTER’ directly expands it. One way of fixing the bug is to factor
12199 ‘TESTA’ into two macros, the portion designed for direct and repeated
12200 use (here, named ‘TESTA’), and the portion designed for one-shot output
12201 and used only inside ‘AC_REQUIRE’ (here, named ‘TESTA_PREREQ’). Then,
12202 by fixing all clients to use the correct calling convention according to
12203 their needs:
12204
12205 AC_DEFUN([TESTA], [AC_REQUIRE([TESTA_PREREQ])[echo in A]])
12206 AC_DEFUN([TESTA_PREREQ], [[echo in A_PREREQ
12207 if test -n "$SEEN_A" ; then echo duplicate ; fi
12208 SEEN_A=:]])
12209 AC_DEFUN([TESTB], [AC_REQUIRE([TESTA_PREREQ])[echo in B
12210 if test -z "$SEEN_A" ; then echo bug ; fi]])
12211 AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])
12212 AC_DEFUN([OUTER], [[echo in OUTER]
12213 TESTA
12214 TESTC])
12215 OUTER
12216
12217 the resulting output will then obey all dependency rules and avoid any
12218 syntax warnings, whether the script is built with old or new Autoconf
12219 versions:
12220
12221 in A_PREREQ
12222 in B
12223 in OUTER
12224 in A
12225 in C
12226
12227 You can use the helper macros ‘AS_IF’ and ‘AS_CASE’ in top-level code
12228 to enforce expansion of required macros outside of shell conditional
12229 constructs; these helpers are not needed in the bodies of macros defined
12230 by ‘AC_DEFUN’. You are furthermore encouraged, although not required,
12231 to put all ‘AC_REQUIRE’ calls at the beginning of a macro. You can use
12232 ‘dnl’ to avoid the empty lines they leave.
12233
12234 Autoconf will normally warn if an ‘AC_REQUIRE’ call refers to a macro
12235 that has not been defined. However, the ‘aclocal’ tool relies on
12236 parsing an incomplete set of input files to trace which macros have been
12237 required, in order to then pull in additional files that provide those
12238 macros; for this particular use case, pre-defining the macro
12239 ‘m4_require_silent_probe’ will avoid the warnings.
12240
12241 
12242 File: autoconf.info, Node: Suggested Ordering, Next: One-Shot Macros, Prev: Prerequisite Macros, Up: Dependencies Between Macros
12243
12244 10.3.2 Suggested Ordering
12245 -------------------------
12246
12247 Some macros should be run before another macro if both are called, but
12248 neither _requires_ that the other be called. For example, a macro that
12249 changes the behavior of the C compiler should be called before any
12250 macros that run the C compiler. Many of these dependencies are noted in
12251 the documentation.
12252
12253 Autoconf provides the ‘AC_BEFORE’ macro to warn users when macros
12254 with this kind of dependency appear out of order in a ‘configure.ac’
12255 file. The warning occurs when creating ‘configure’ from ‘configure.ac’,
12256 not when running ‘configure’.
12257
12258 For example, ‘AC_PROG_CPP’ checks whether the C compiler can run the
12259 C preprocessor when given the ‘-E’ option. It should therefore be
12260 called after any macros that change which C compiler is being used, such
12261 as ‘AC_PROG_CC’. So ‘AC_PROG_CC’ contains:
12262
12263 AC_BEFORE([$0], [AC_PROG_CPP])dnl
12264
12265 This warns the user if a call to ‘AC_PROG_CPP’ has already occurred when
12266 ‘AC_PROG_CC’ is called.
12267
12268 — Macro: AC_BEFORE(THIS-MACRO-NAME, CALLED-MACRO-NAME)
12269 Make M4 print a warning message to the standard error output if
12270 CALLED-MACRO-NAME has already been called. THIS-MACRO-NAME should
12271 be the name of the macro that is calling ‘AC_BEFORE’. The macro
12272 CALLED-MACRO-NAME must have been defined using ‘AC_DEFUN’ or else
12273 contain a call to ‘AC_PROVIDE’ to indicate that it has been called.
12274
12275 
12276 File: autoconf.info, Node: One-Shot Macros, Prev: Suggested Ordering, Up: Dependencies Between Macros
12277
12278 10.3.3 One-Shot Macros
12279 ----------------------
12280
12281 Some macros should be called only once, either because calling them
12282 multiple time is unsafe, or because it is bad style. For instance
12283 Autoconf ensures that ‘AC_CANONICAL_BUILD’ and cousins (*note
12284 Canonicalizing::) are evaluated only once, because it makes no sense to
12285 run these expensive checks more than once. Such one-shot macros can be
12286 defined using ‘AC_DEFUN_ONCE’.
12287
12288 — Macro: AC_DEFUN_ONCE(MACRO-NAME, MACRO-BODY)
12289 Declare macro MACRO-NAME like ‘AC_DEFUN’ would (*note Macro
12290 Definitions::), but add additional logic that guarantees that only
12291 the first use of the macro (whether by direct expansion or
12292 ‘AC_REQUIRE’) causes an expansion of MACRO-BODY; the expansion will
12293 occur before the start of any enclosing macro defined by
12294 ‘AC_DEFUN’. Subsequent expansions are silently ignored.
12295 Generally, it does not make sense for MACRO-BODY to use parameters
12296 such as ‘$1’.
12297
12298 Prior to Autoconf 2.64, a macro defined by ‘AC_DEFUN_ONCE’ would emit
12299 a warning if it was directly expanded a second time, so for portability,
12300 it is better to use ‘AC_REQUIRE’ than direct invocation of MACRO-NAME
12301 inside a macro defined by ‘AC_DEFUN’ (*note Prerequisite Macros::).
12302
12303 
12304 File: autoconf.info, Node: Obsoleting Macros, Next: Coding Style, Prev: Dependencies Between Macros, Up: Writing Autoconf Macros
12305
12306 10.4 Obsoleting Macros
12307 ======================
12308
12309 Configuration and portability technology has evolved over the years.
12310 Often better ways of solving a particular problem are developed, or
12311 ad-hoc approaches are systematized. This process has occurred in many
12312 parts of Autoconf. One result is that some of the macros are now
12313 considered “obsolete”; they still work, but are no longer considered the
12314 best thing to do, hence they should be replaced with more modern macros.
12315 Ideally, ‘autoupdate’ should replace the old macro calls with their
12316 modern implementation.
12317
12318 Autoconf provides a simple means to obsolete a macro.
12319
12320 — Macro: AU_DEFUN(OLD-MACRO, IMPLEMENTATION, [MESSAGE], [SILENT])
12321 Define OLD-MACRO as IMPLEMENTATION, just like ‘AC_DEFUN’, but also
12322 declare OLD-MACRO to be obsolete. When ‘autoupdate’ is run,
12323 occurrences of OLD-MACRO will be replaced by the text of
12324 IMPLEMENTATION in the updated ‘configure.ac’ file.
12325
12326 If a simple textual replacement is not enough to finish the job of
12327 updating a ‘configure.ac’ to modern style, provide instructions for
12328 whatever additional manual work is required as MESSAGE. These
12329 instructions will be printed by ‘autoupdate’, and embedded in the
12330 updated ‘configure.ac’ file, next to the text of IMPLEMENTATION.
12331
12332 Normally, ‘autoconf’ will also issue a warning (in the “obsolete”
12333 category) when it expands OLD-MACRO. This warning does not include
12334 MESSAGE; it only advises the maintainer to run ‘autoupdate’. If it
12335 is inappropriate to issue this warning, set the SILENT argument to
12336 the word ‘silent’. One might want to use a silent ‘AU_DEFUN’ when
12337 OLD-MACRO is used in a widely-distributed third-party macro. If
12338 that macro’s maintainers are aware of the need to update their
12339 code, it’s unnecessary to nag all of the transitive users of
12340 OLD-MACRO as well. This capability was added to ‘AU_DEFUN’ in
12341 Autoconf 2.70; older versions of autoconf will ignore the SILENT
12342 argument and issue the warning anyway.
12343
12344 *Caution:* If IMPLEMENTATION contains M4 or M4sugar macros, they
12345 will be evaluated when ‘autoupdate’ is run, not emitted verbatim
12346 like the rest of IMPLEMENTATION. This cannot be avoided with extra
12347 quotation, because then OLD-MACRO will not work when it is called
12348 normally. See the definition of ‘AC_FOREACH’ in ‘general.m4’ for a
12349 workaround.
12350
12351 — Macro: AU_ALIAS(OLD-NAME, NEW-NAME, [SILENT])
12352 A shorthand version of ‘AU_DEFUN’, to be used when a macro has
12353 simply been renamed. ‘autoupdate’ will replace calls to OLD-NAME
12354 with calls to NEW-NAME, keeping any arguments intact. No
12355 instructions for additional manual work will be printed.
12356
12357 The SILENT argument works the same as the SILENT argument to
12358 ‘AU_DEFUN’. It was added to ‘AU_ALIAS’ in Autoconf 2.70.
12359
12360 *Caution:* ‘AU_ALIAS’ cannot be used when NEW-NAME is an M4 or
12361 M4sugar macro. See above.
12362
12363 
12364 File: autoconf.info, Node: Coding Style, Prev: Obsoleting Macros, Up: Writing Autoconf Macros
12365
12366 10.5 Coding Style
12367 =================
12368
12369 The Autoconf macros follow a strict coding style. You are encouraged to
12370 follow this style, especially if you intend to distribute your macro,
12371 either by contributing it to Autoconf itself or the Autoconf Macro
12372 Archive (https://www.gnu.org/software/autoconf-archive/), or by other
12373 means.
12374
12375 The first requirement is to pay great attention to the quotation.
12376 For more details, see *note Autoconf Language::, and *note M4
12377 Quotation::.
12378
12379 Do not try to invent new interfaces. It is likely that there is a
12380 macro in Autoconf that resembles the macro you are defining: try to
12381 stick to this existing interface (order of arguments, default values,
12382 etc.). We _are_ conscious that some of these interfaces are not
12383 perfect; nevertheless, when harmless, homogeneity should be preferred
12384 over creativity.
12385
12386 Be careful about clashes both between M4 symbols and between shell
12387 variables.
12388
12389 If you stick to the suggested M4 naming scheme (*note Macro Names::),
12390 you are unlikely to generate conflicts. Nevertheless, when you need to
12391 set a special value, _avoid using a regular macro name_; rather, use an
12392 “impossible” name. For instance, up to version 2.13, the macro
12393 ‘AC_SUBST’ used to remember what SYMBOL macros were already defined by
12394 setting ‘AC_SUBST_SYMBOL’, which is a regular macro name. But since
12395 there is a macro named ‘AC_SUBST_FILE’, it was just impossible to
12396 ‘AC_SUBST(FILE)’! In this case, ‘AC_SUBST(SYMBOL)’ or
12397 ‘_AC_SUBST(SYMBOL)’ should have been used (yes, with the parentheses).
12398
12399 No Autoconf macro should ever enter the user-variable name space;
12400 i.e., except for the variables that are the actual result of running the
12401 macro, all shell variables should start with ‘ac_’. In addition, small
12402 macros or any macro that is likely to be embedded in other macros should
12403 be careful not to use obvious names.
12404
12405 Do not use ‘dnl’ to introduce comments: most of the comments you are
12406 likely to write are either header comments which are not output anyway,
12407 or comments that should make their way into ‘configure’. There are
12408 exceptional cases where you do want to comment special M4 constructs, in
12409 which case ‘dnl’ is right, but keep in mind that it is unlikely.
12410
12411 M4 ignores the leading blanks and newlines before each argument. Use
12412 this feature to indent in such a way that arguments are (more or less)
12413 aligned with the opening parenthesis of the macro being called. For
12414 instance, instead of
12415
12416 AC_CACHE_CHECK(for EMX OS/2 environment,
12417 ac_cv_emxos2,
12418 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __EMX__;])],
12419 [ac_cv_emxos2=yes], [ac_cv_emxos2=no])])
12420
12421 write
12422
12423 AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
12424 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
12425 [ac_cv_emxos2=yes],
12426 [ac_cv_emxos2=no])])
12427
12428 or even
12429
12430 AC_CACHE_CHECK([for EMX OS/2 environment],
12431 [ac_cv_emxos2],
12432 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
12433 [return __EMX__;])],
12434 [ac_cv_emxos2=yes],
12435 [ac_cv_emxos2=no])])
12436
12437 When using ‘AC_RUN_IFELSE’ or any macro that cannot work when
12438 cross-compiling, provide a pessimistic value (typically ‘no’).
12439
12440 Feel free to use various tricks to prevent auxiliary tools, such as
12441 syntax-highlighting editors, from behaving improperly. For instance,
12442 instead of:
12443
12444 m4_bpatsubst([$1], [$"])
12445
12446 use
12447
12448 m4_bpatsubst([$1], [$""])
12449
12450 so that Emacsen do not open an endless “string” at the first quote. For
12451 the same reasons, avoid:
12452
12453 test $[#] != 0
12454
12455 and use:
12456
12457 test $[@%:@] != 0
12458
12459 Otherwise, the closing bracket would be hidden inside a ‘#’-comment,
12460 breaking the bracket-matching highlighting from Emacsen. Note the
12461 preferred style to escape from M4: ‘$[1]’, ‘$[@]’, etc. Do not escape
12462 when it is unnecessary. Common examples of useless quotation are
12463 ‘[$]$1’ (write ‘$$1’), ‘[$]var’ (use ‘$var’), etc.
12464
12465 When using ‘sed’, don’t use ‘-e’ except for indenting purposes. With
12466 the ‘s’ and ‘y’ commands, the preferred separator is ‘/’ unless ‘/’
12467 itself might appear in the pattern or replacement, in which case you
12468 should use ‘|’, or optionally ‘,’ if you know the pattern and
12469 replacement cannot contain a file name. If none of these characters
12470 will do, choose a printable character that cannot appear in the pattern
12471 or replacement. Characters from the set ‘"#$&'()*;<=>?`|~’ are good
12472 choices if the pattern or replacement might contain a file name, since
12473 they have special meaning to the shell and are less likely to occur in
12474 file names.
12475
12476 *Note Macro Definitions::, for details on how to define a macro. If
12477 a macro doesn’t use ‘AC_REQUIRE’, is expected to never be the object of
12478 an ‘AC_REQUIRE’ directive, and macros required by other macros inside
12479 arguments do not need to be expanded before this macro, then use
12480 ‘m4_define’. In case of doubt, use ‘AC_DEFUN’. Also take into account
12481 that public third-party macros need to use ‘AC_DEFUN’ in order to be
12482 found by ‘aclocal’ (*note (automake)Extending aclocal::). All the
12483 ‘AC_REQUIRE’ statements should be at the beginning of the macro, and
12484 each statement should be followed by ‘dnl’.
12485
12486 You should not rely on the number of arguments: instead of checking
12487 whether an argument is missing, test that it is not empty. It provides
12488 both a simpler and a more predictable interface to the user, and saves
12489 room for further arguments.
12490
12491 Unless the macro is short, try to leave the closing ‘])’ at the
12492 beginning of a line, followed by a comment that repeats the name of the
12493 macro being defined. This introduces an additional newline in
12494 ‘configure’; normally, that is not a problem, but if you want to remove
12495 it you can use ‘[]dnl’ on the last line. You can similarly use ‘[]dnl’
12496 after a macro call to remove its newline. ‘[]dnl’ is recommended
12497 instead of ‘dnl’ to ensure that M4 does not interpret the ‘dnl’ as being
12498 attached to the preceding text or macro output. For example, instead
12499 of:
12500
12501 AC_DEFUN([AC_PATH_X],
12502 [AC_MSG_CHECKING([for X])
12503 AC_REQUIRE_CPP()
12504 # ...omitted...
12505 AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
12506 fi])
12507
12508 you would write:
12509
12510 AC_DEFUN([AC_PATH_X],
12511 [AC_REQUIRE_CPP()[]dnl
12512 AC_MSG_CHECKING([for X])
12513 # ...omitted...
12514 AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
12515 fi[]dnl
12516 ])# AC_PATH_X
12517
12518 If the macro is long, try to split it into logical chunks.
12519 Typically, macros that check for a bug in a function and prepare its
12520 ‘AC_LIBOBJ’ replacement should have an auxiliary macro to perform this
12521 setup. Do not hesitate to introduce auxiliary macros to factor your
12522 code.
12523
12524 In order to highlight the recommended coding style, here is a macro
12525 written the old way:
12526
12527 dnl Check for EMX on OS/2.
12528 dnl _AC_EMXOS2
12529 AC_DEFUN(_AC_EMXOS2,
12530 [AC_CACHE_CHECK(for EMX OS/2 environment, ac_cv_emxos2,
12531 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return __EMX__;)],
12532 ac_cv_emxos2=yes, ac_cv_emxos2=no)])
12533 test "x$ac_cv_emxos2" = xyes && EMXOS2=yes])
12534
12535 and the new way:
12536
12537 # _AC_EMXOS2
12538 # ----------
12539 # Check for EMX on OS/2.
12540 m4_define([_AC_EMXOS2],
12541 [AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
12542 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
12543 [ac_cv_emxos2=yes],
12544 [ac_cv_emxos2=no])])
12545 test "x$ac_cv_emxos2" = xyes && EMXOS2=yes[]dnl
12546 ])# _AC_EMXOS2
12547
12548 
12549 File: autoconf.info, Node: Portable Shell, Next: Portable Make, Prev: Writing Autoconf Macros, Up: Top
12550
12551 11 Portable Shell Programming
12552 *****************************
12553
12554 When writing your own checks, there are some shell-script programming
12555 techniques you should avoid in order to make your code portable. The
12556 Bourne shell and upward-compatible shells like the Korn shell and Bash
12557 have evolved over the years, and many features added to the original
12558 System7 shell are now supported on all interesting porting targets.
12559 However, the following discussion between Russ Allbery and Robert Lipe
12560 is worth reading:
12561
12562 Russ Allbery:
12563
12564 The GNU assumption that ‘/bin/sh’ is the one and only shell leads
12565 to a permanent deadlock. Vendors don’t want to break users’
12566 existing shell scripts, and there are some corner cases in the
12567 Bourne shell that are not completely compatible with a POSIX shell.
12568 Thus, vendors who have taken this route will _never_ (OK...“never
12569 say never”) replace the Bourne shell (as ‘/bin/sh’) with a POSIX
12570 shell.
12571
12572 Robert Lipe:
12573
12574 This is exactly the problem. While most (at least most System V’s)
12575 do have a Bourne shell that accepts shell functions most vendor
12576 ‘/bin/sh’ programs are not the POSIX shell.
12577
12578 So while most modern systems do have a shell _somewhere_ that meets
12579 the POSIX standard, the challenge is to find it.
12580
12581 For this reason, part of the job of M4sh (*note Programming in
12582 M4sh::) is to find such a shell. But to prevent trouble, if you’re not
12583 using M4sh you should not take advantage of features that were added
12584 after Unix version 7, circa 1977 (*note Systemology::); you should not
12585 use aliases, negated character classes, or even ‘unset’. ‘#’ comments,
12586 while not in Unix version 7, were retrofitted in the original Bourne
12587 shell and can be assumed to be part of the least common denominator.
12588
12589 On the other hand, if you’re using M4sh you can assume that the shell
12590 has the features that were added in SVR2 (circa 1984), including shell
12591 functions, ‘return’, ‘unset’, and I/O redirection for builtins. For
12592 more information, refer to <https://www.in-ulm.de/~mascheck/bourne/>.
12593 However, some pitfalls have to be avoided for portable use of these
12594 constructs; these will be documented in the rest of this chapter. See
12595 in particular *note Shell Functions:: and *note Limitations of Shell
12596 Builtins: Limitations of Builtins.
12597
12598 The set of external programs you should run in a ‘configure’ script
12599 is fairly small. *Note Utilities in Makefiles: (standards)Utilities in
12600 Makefiles, for the list. This restriction allows users to start out
12601 with a fairly small set of programs and build the rest, avoiding too
12602 many interdependencies between packages.
12603
12604 Some of these external utilities have a portable subset of features;
12605 see *note Limitations of Usual Tools::.
12606
12607 There are other sources of documentation about shells. The
12608 specification for the POSIX Shell Command Language
12609 (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html),
12610 though more generous than the restrictive shell subset described above,
12611 is fairly portable nowadays. Also please see the Shell FAQs
12612 (http://www.faqs.org/faqs/unix-faq/shell/).
12613
12614 * Menu:
12615
12616 * Systemology:: A zoology of operating systems
12617 * Shellology:: A zoology of shells
12618 * Invoking the Shell:: Invoking the shell as a command
12619 * Here-Documents:: Quirks and tricks
12620 * File Descriptors:: FDs and redirections
12621 * Signal Handling:: Shells, signals, and headaches
12622 * File System Conventions:: File names
12623 * Shell Pattern Matching:: Pattern matching
12624 * Shell Substitutions:: Variable and command expansions
12625 * Assignments:: Varying side effects of assignments
12626 * Parentheses:: Parentheses in shell scripts
12627 * Special Shell Variables:: Variables you should not change
12628 * Shell Functions:: What to look out for if you use them
12629 * Limitations of Builtins:: Portable use of not so portable /bin/sh
12630 * Limitations of Usual Tools:: Portable use of portable tools
12631
12632 
12633 File: autoconf.info, Node: Systemology, Next: Shellology, Up: Portable Shell
12634
12635 11.1 Systemology
12636 ================
12637
12638 This section aims at presenting some systems and pointers to
12639 documentation. It may help you addressing particular problems reported
12640 by users.
12641
12642 POSIX-conforming systems (https://en.wikipedia.org/wiki/POSIX) are
12643 derived from the Unix operating system
12644 (https://en.wikipedia.org/wiki/Unix).
12645
12646 The Rosetta Stone for Unix (https://bhami.com/rosetta.html) contains
12647 a table correlating the features of various POSIX-conforming systems.
12648 Unix History (https://www.levenez.com/unix/) is a simplified diagram of
12649 how many Unix systems were derived from each other.
12650
12651 The Heirloom Project (https://heirloom.sourceforge.net/) provides
12652 some variants of traditional implementations of Unix utilities.
12653
12654 Darwin
12655 Darwin is a partially proprietary operating system maintained by
12656 Apple Computer and used by most of their products. It is also
12657 known as macOS, iOS, etc. depending on the exact variant. Older
12658 versions were called “Mac OS X.”
12659
12660 By default the file system will be case insensitive, albeit case
12661 preserving. This can cause nasty problems: for instance, the
12662 installation attempt for a package having an ‘INSTALL’ file can
12663 result in ‘make install’ reporting that nothing is to be done!
12664
12665 Darwin does support case-sensitive file systems, but they must be
12666 formatted specially as such, and Apple discourages use of a
12667 case-sensitive volume for the base operating system. To build
12668 software that expects case-sensitive filenames, it is best to
12669 create a separate disk volume or disk image formatted as case
12670 sensitive; this can be done using the ‘diskutil’ command or the
12671 Disk Utility application.
12672
12673 QNX
12674 QNX is a realtime operating system running on Intel architecture
12675 meant to be scalable from the small embedded systems to the hundred
12676 processor super-computer. More information is available on the QNX
12677 home page (https://blackberry.qnx.com/en).
12678
12679 Unix version 7
12680 Officially this was called the “Seventh Edition” of “the UNIX
12681 time-sharing system” but we use the more-common name “Unix version
12682 7”. Documentation is available in the Unix Seventh Edition Manual
12683 (https://s3.amazonaws.com/plan9-bell-labs/7thEdMan/index.html).
12684 Previous versions of Unix are called “Unix version 6”, etc., but
12685 they were not as widely used.
12686
12687 
12688 File: autoconf.info, Node: Shellology, Next: Invoking the Shell, Prev: Systemology, Up: Portable Shell
12689
12690 11.2 Shellology
12691 ===============
12692
12693 There are several families of shells, most prominently the Bourne family
12694 and the C shell family which are deeply incompatible. If you want to
12695 write portable shell scripts, avoid members of the C shell family. The
12696 the Shell difference FAQ
12697 (http://www.faqs.org/faqs/unix-faq/shell/shell-differences/) includes a
12698 small history of POSIX shells, and a comparison between several of them.
12699
12700 Below we describe some of the members of the Bourne shell family.
12701
12702 Ash
12703 Ash is often used on GNU/Linux and BSD systems as a light-weight
12704 Bourne-compatible shell. Ash 0.2 has some bugs that are fixed in
12705 the 0.3.x series, but portable shell scripts should work around
12706 them, since version 0.2 is still shipped with many GNU/Linux
12707 distributions.
12708
12709 To be compatible with Ash 0.2:
12710
12711 − don’t use ‘$?’ after expanding empty or unset variables, or at
12712 the start of an ‘eval’:
12713
12714 foo=
12715 false
12716 $foo
12717 echo "Do not use it: $?"
12718 false
12719 eval 'echo "Do not use it: $?"'
12720
12721 − don’t use command substitution within variable expansion:
12722
12723 cat ${FOO=`bar`}
12724
12725 − beware that single builtin substitutions are not performed by
12726 a subshell, hence their effect applies to the current shell!
12727 *Note Shell Substitutions::, item “Command Substitution”.
12728
12729 Bash
12730 To detect whether you are running Bash, test whether ‘BASH_VERSION’
12731 is set. To require POSIX compatibility, run ‘set -o posix’. *Note
12732 Bash POSIX Mode: (bash)Bash POSIX Mode, for details.
12733
12734 Bash 2.05 and later
12735 Versions 2.05 and later of Bash use a different format for the
12736 output of the ‘set’ builtin, designed to make evaluating its output
12737 easier. However, this output is not compatible with earlier
12738 versions of Bash (or with many other shells, probably). So if you
12739 use Bash 2.05 or higher to execute ‘configure’, you’ll need to use
12740 Bash 2.05 for all other build tasks as well.
12741
12742 Ksh
12743 The Korn shell is compatible with the Bourne family and it mostly
12744 conforms to POSIX. It has two major variants commonly called
12745 ‘ksh88’ and ‘ksh93’, named after the years of initial release. It
12746 is usually called ‘ksh’, but is called ‘sh’ on some hosts if you
12747 set your path appropriately.
12748
12749 On Solaris 11, ‘/bin/sh’ and ‘/usr/bin/ksh’ are both ‘ksh93’. On
12750 Solaris 10 and earlier, ‘/bin/sh’ is a pre-POSIX Bourne shell and
12751 the Korn shell is found elsewhere: ‘/usr/bin/ksh’ is ‘ksh88’ on
12752 Solaris 10, ‘/usr/xpg4/bin/sh’ is a POSIX-compliant variant of
12753 ‘ksh88’ on Solaris 10 and later, and ‘/usr/dt/bin/dtksh’ is
12754 ‘ksh93’. Variants that are not standard may be parts of optional
12755 packages. There is no extra charge for these packages, but they
12756 are not part of a minimal OS install and therefore some
12757 installations may not have it.
12758
12759 Pdksh
12760 A public-domain clone of the Korn shell called ‘pdksh’ is widely
12761 available: it has most of the ‘ksh88’ features along with a few of
12762 its own. It usually sets ‘KSH_VERSION’, except if invoked as
12763 ‘/bin/sh’ on OpenBSD, and similarly to Bash you can require POSIX
12764 compatibility by running ‘set -o posix’. Unfortunately, with
12765 ‘pdksh’ 5.2.14 (the latest stable version as of 2025) POSIX mode is
12766 buggy and causes ‘pdksh’ to depart from POSIX in at least one
12767 respect, see *note Shell Substitutions::.
12768
12769 Zsh
12770 To detect whether you are running ‘zsh’, test whether ‘ZSH_VERSION’
12771 is set. By default ‘zsh’ is _not_ compatible with the Bourne
12772 shell: you must execute ‘emulate sh’, and for ‘zsh’ versions before
12773 3.1.6-dev-18 you must also set ‘NULLCMD’ to ‘:’. *Note
12774 Compatibility: (zsh)Compatibility, for details.
12775
12776 The default Mac OS X ‘sh’ was originally Zsh; it was changed to
12777 Bash in Mac OS X 10.2 (2002) and changed back to Zsh in macOS 10.15
12778 (2019).
12779
12780 
12781 File: autoconf.info, Node: Invoking the Shell, Next: Here-Documents, Prev: Shellology, Up: Portable Shell
12782
12783 11.3 Invoking the Shell
12784 =======================
12785
12786 The Korn shell (up to at least version M-12/28/93d) has a bug when
12787 invoked on a file whose name does not contain a slash. It first
12788 searches for the file’s name in ‘PATH’, and if found it executes that
12789 rather than the original file. For example, assuming there is a binary
12790 executable ‘/usr/bin/script’ in your ‘PATH’, the last command in the
12791 following example fails because the Korn shell finds ‘/usr/bin/script’
12792 and refuses to execute it as a shell script:
12793
12794 $ touch xxyzzyz script
12795 $ ksh xxyzzyz
12796 $ ksh ./script
12797 $ ksh script
12798 ksh: script: cannot execute
12799
12800 Bash 2.03 has a bug when invoked with the ‘-c’ option: if the
12801 option-argument ends in backslash-newline, Bash incorrectly reports a
12802 syntax error. The problem does not occur if a character follows the
12803 backslash:
12804
12805 $ $ bash -c 'echo foo \
12806 > '
12807 bash: -c: line 2: syntax error: unexpected end of file
12808 $ bash -c 'echo foo \
12809 > '
12810 foo
12811
12812 *Note Backslash-Newline-Empty::, for how this can cause problems in
12813 makefiles.
12814
12815 
12816 File: autoconf.info, Node: Here-Documents, Next: File Descriptors, Prev: Invoking the Shell, Up: Portable Shell
12817
12818 11.4 Here-Documents
12819 ===================
12820
12821 Because unquoted here-documents are subject to parameter expansion and
12822 command substitution, the characters ‘$’ and ‘`’ are special in unquoted
12823 here-documents and should be escaped by ‘\’ if you want them as-is.
12824 Also, ‘\’ is special if it precedes ‘$’, ‘`’, newline or ‘\’ itself, so
12825 ‘\’ should be doubled if it appears before these characters and you want
12826 it as-is.
12827
12828 Using command substitutions in a here-document that is fed to a shell
12829 function is not portable. For example, with Solaris 10 ‘/bin/sh’:
12830
12831 $ kitty () { cat; }
12832 $ kitty <<EOF
12833 > `echo ok`
12834 > EOF
12835 /tmp/sh199886: cannot open
12836 $ echo $?
12837 1
12838
12839 Some shells mishandle large here-documents: for example, Solaris 10
12840 ‘dtksh’ and the UnixWare 7.1.1 POSIX shell, which are derived from Korn
12841 shell version M-12/28/93d, mishandle braced variable expansion that
12842 crosses a 1024- or 4096-byte buffer boundary within a here-document.
12843 Only the part of the variable name after the boundary is used. For
12844 example, ‘${variable}’ could be replaced by the expansion of ‘${ble}’.
12845 If the end of the variable name is aligned with the block boundary, the
12846 shell reports an error, as if you used ‘${}’. Instead of
12847 ‘${variable-default}’, the shell may expand ‘${riable-default}’, or even
12848 ‘${fault}’. This bug can often be worked around by omitting the braces:
12849 ‘$variable’. The bug was fixed in ‘ksh93g’ (1998-04-30) but as of 2006
12850 many operating systems were still shipping older versions with the bug.
12851
12852 Empty here-documents are not portable either; with the following
12853 code, ‘zsh’ up to at least version 4.3.10 creates a file with a single
12854 newline, whereas other shells create an empty file:
12855
12856 cat >file <<EOF
12857 EOF
12858
12859 Many shells (including the Bourne shell) implement here-documents
12860 inefficiently. In particular, some shells can be extremely inefficient
12861 when a single statement contains many here-documents. For instance if
12862 your ‘configure.ac’ includes something like:
12863
12864 AS_IF([<cross_compiling>],
12865 [assume this and that],
12866 [check this
12867 check that
12868 check something else
12869 ...
12870 on and on forever
12871 ...])
12872
12873 A shell parses the whole ‘if’/‘fi’ construct generated by ‘AS_IF’,
12874 creating temporary files for each here-document in it. Some shells
12875 create links for such here-documents on every ‘fork’, so that the
12876 clean-up code they had installed correctly removes them. It is creating
12877 the links that can take the shell forever.
12878
12879 Moving the tests out of the ‘if’/‘fi’, or creating multiple ‘if’/‘fi’
12880 constructs, would improve the performance significantly. Anyway, this
12881 kind of construct is not exactly the typical use of Autoconf. In fact,
12882 it’s even not recommended, because M4 macros can’t look into shell
12883 conditionals, so we may fail to expand a macro when it was expanded
12884 before in a conditional path, and the condition turned out to be false
12885 at runtime, and we end up not executing the macro at all.
12886
12887 Be careful with the use of ‘<<-’ to unindent here-documents. The
12888 behavior is only portable for stripping leading <TAB>s, and things can
12889 silently break if an overzealous editor converts to using leading spaces
12890 (not all shells are nice enough to warn about unterminated
12891 here-documents).
12892
12893 $ printf 'cat <<-x\n\t1\n\t 2\n\tx\n' | bash && echo done
12894 1
12895 2
12896 done
12897 $ printf 'cat <<-x\n 1\n 2\n x\n' | bash-3.2 && echo done
12898 1
12899 2
12900 x
12901 done
12902
12903 
12904 File: autoconf.info, Node: File Descriptors, Next: Signal Handling, Prev: Here-Documents, Up: Portable Shell
12905
12906 11.5 File Descriptors
12907 =====================
12908
12909 Most shells, if not all (including Bash, Zsh, Ash), output traces on
12910 stderr, even for subshells. This might result in undesirable content if
12911 you meant to capture the standard-error output of the inner command:
12912
12913 $ ash -x -c '(eval "echo foo >&2") 2>stderr'
12914 $ cat stderr
12915 + eval echo foo >&2
12916 + echo foo
12917 foo
12918 $ bash -x -c '(eval "echo foo >&2") 2>stderr'
12919 $ cat stderr
12920 + eval 'echo foo >&2'
12921 ++ echo foo
12922 foo
12923 $ zsh -x -c '(eval "echo foo >&2") 2>stderr'
12924 # Traces on startup files deleted here.
12925 $ cat stderr
12926 +zsh:1> eval echo foo >&2
12927 +zsh:1> echo foo
12928 foo
12929
12930 One workaround is to grep out uninteresting lines, hoping not to remove
12931 good ones.
12932
12933 If you intend to redirect both standard error and standard output,
12934 redirect standard output first. This works better with AIX, since its
12935 shell mishandles tracing if standard error is redirected first:
12936
12937 $ sh -x -c ': 2>err >out'
12938 + :
12939 + 2> err $ cat err
12940 1> out
12941
12942 Don’t try to redirect the standard error of a command substitution.
12943 It must be done _inside_ the command substitution. When running ‘: `cd
12944 /zorglub` 2>/dev/null’ expect the error message to escape, while ‘: `cd
12945 /zorglub 2>/dev/null`’ works properly.
12946
12947 On the other hand, some shells, such as Solaris or FreeBSD ‘/bin/sh’,
12948 warn about missing programs before performing redirections. Therefore,
12949 to silently check whether a program exists, it is necessary to perform
12950 redirections on a subshell or brace group:
12951 $ /bin/sh -c 'nosuch 2>/dev/null'
12952 nosuch: not found
12953 $ /bin/sh -c '(nosuch) 2>/dev/null'
12954 $ /bin/sh -c '{ nosuch; } 2>/dev/null'
12955 $ bash -c 'nosuch 2>/dev/null'
12956
12957 FreeBSD 6.2 sh may mix the trace output lines from the statements in
12958 a shell pipeline.
12959
12960 It is worth noting that Zsh (but not Ash nor Bash) makes it possible
12961 in assignments though: ‘foo=`cd /zorglub` 2>/dev/null’.
12962
12963 Some shells, like ‘ash’, don’t recognize bi-directional redirection
12964 (‘<>’). And even on shells that recognize it, it is not portable to use
12965 on fifos: POSIX does not require read-write support for named pipes, and
12966 Cygwin does not support it:
12967
12968 $ mkfifo fifo
12969 $ exec 5<>fifo
12970 $ echo hi >&5
12971 bash: echo: write error: Communication error on send
12972
12973 Furthermore, versions of ‘dash’ before 0.5.6 mistakenly truncate regular
12974 files when using ‘<>’:
12975
12976 $ echo a > file
12977 $ bash -c ': 1<>file'; cat file
12978 a
12979 $ dash -c ': 1<>file'; cat file
12980 $ rm a
12981
12982 Solaris 10 ‘/bin/sh’ executes redirected compound commands in a
12983 subshell, while other shells don’t:
12984
12985 $ /bin/sh -c 'foo=0; { foo=1; } 2>/dev/null; echo $foo'
12986 0
12987 $ ksh -c 'foo=0; { foo=1; } 2>/dev/null; echo $foo'
12988 1
12989 $ bash -c 'foo=0; { foo=1; } 2>/dev/null; echo $foo'
12990 1
12991
12992 Solaris 10 ‘sh’ will try to optimize away a ‘:’ command (even if it
12993 is redirected) in a loop after the first iteration, or in a shell
12994 function after the first call:
12995
12996 $ for i in 1 2 3 ; do : >x$i; done
12997 $ ls x*
12998 x1
12999 $ f () { : >$1; }; f y1; f y2; f y3;
13000 $ ls y*
13001 y1
13002
13003 As a workaround, ‘echo’ or ‘eval’ can be used.
13004
13005 When running a subsidiary program be careful if descriptor 0 is not
13006 open for reading or decriptors 1 and 2 are not open for writing, as the
13007 subsidiary program might not behave as expected. In particular, don’t
13008 rely on file descriptors 0, 1, and 2 remaining closed in a subsidiary
13009 program. If any of these descriptors is closed, the operating system
13010 may open an unspecified file for the descriptor in the newly created
13011 process.
13012
13013 If you want a file descriptor above 2 to be inherited into a child
13014 process, then you must use redirections specific to that command or a
13015 containing subshell or command group, rather than relying on ‘exec’ in
13016 the shell. In ‘ksh’ as well as HP-UX ‘sh’, file descriptors above 2
13017 which are opened using ‘exec N>file’ are closed by a subsequent ‘exec’
13018 (such as that involved in the fork-and-exec which runs a program or
13019 script):
13020
13021 $ echo 'echo hello >&5' >k
13022 $ /bin/sh -c 'exec 5>t; ksh ./k; exec 5>&-; cat t
13023 hello
13024 $ bash -c 'exec 5>t; ksh ./k; exec 5>&-; cat t
13025 hello
13026 $ ksh -c 'exec 5>t; ksh ./k; exec 5>&-; cat t
13027 ./k[1]: 5: cannot open [Bad file number]
13028 $ ksh -c '(ksh ./k) 5>t; cat t'
13029 hello
13030 $ ksh -c '{ ksh ./k; } 5>t; cat t'
13031 hello
13032 $ ksh -c '5>t ksh ./k; cat t
13033 hello
13034
13035 Don’t rely on duplicating a closed file descriptor to cause an error.
13036 With Solaris 10 ‘/bin/sh’, failed duplication is silently ignored, which
13037 can cause unintended leaks to the original file descriptor. In this
13038 example, observe the leak to standard output:
13039
13040 $ bash -c 'echo hi >&3' 3>&-; echo $?
13041 bash: 3: Bad file descriptor
13042 1
13043 $ /bin/sh -c 'echo hi >&3' 3>&-; echo $?
13044 hi
13045 0
13046
13047 Fortunately, an attempt to close an already closed file descriptor
13048 will portably succeed. Likewise, it is safe to use either style of
13049 ‘N<&-’ or ‘N>&-’ for closing a file descriptor, even if it doesn’t match
13050 the read/write mode that the file descriptor was opened with.
13051
13052 DOS variants cannot rename or remove open files, such as in ‘mv foo
13053 bar >foo’ or ‘rm foo >foo’, even though this is perfectly portable among
13054 POSIX hosts.
13055
13056 A few ancient systems reserved some file descriptors. By convention,
13057 file descriptor 3 was opened to ‘/dev/tty’ when you logged into Eighth
13058 Edition (1985) through Tenth Edition Unix (1989). File descriptor 4 had
13059 a special use on the Stardent/Kubota Titan (circa 1990), though we don’t
13060 now remember what it was. Both these systems are obsolete, so it’s now
13061 safe to treat file descriptors 3 and 4 like any other file descriptors.
13062
13063 On the other hand, you can’t portably use multi-digit file
13064 descriptors. ‘dash’ and Solaris ‘ksh’ don’t understand any file
13065 descriptor larger than ‘9’:
13066
13067 $ bash -c 'exec 10>&-'; echo $?
13068 0
13069 $ ksh -c 'exec 9>&-'; echo $?
13070 0
13071 $ ksh -c 'exec 10>&-'; echo $?
13072 ksh[1]: exec: 10: not found
13073 127
13074 $ dash -c 'exec 9>&-'; echo $?
13075 0
13076 $ dash -c 'exec 10>&-'; echo $?
13077 exec: 1: 10: not found
13078 2
13079
13080 
13081 File: autoconf.info, Node: Signal Handling, Next: File System Conventions, Prev: File Descriptors, Up: Portable Shell
13082
13083 11.6 Signal Handling
13084 ====================
13085
13086 Portable handling of signals within the shell is another major source of
13087 headaches. This is worsened by the fact that various different,
13088 mutually incompatible approaches are possible in this area, each with
13089 its distinctive merits and demerits. A detailed description of these
13090 possible approaches, as well as of their pros and cons, can be found in
13091 this article (https://www.cons.org/cracauer/sigint.html).
13092
13093 Solaris 10 ‘/bin/sh’ automatically traps most signals by default; the
13094 shell still exits with error upon termination by one of those signals,
13095 but in such a case the exit status might be somewhat unexpected (even if
13096 allowed by POSIX, strictly speaking):
13097
13098 $ bash -c 'kill -1 $$'; echo $? # Will exit 128 + (signal number).
13099 Hangup
13100 129
13101 $ /bin/ksh -c 'kill -15 $$'; echo $? # Likewise.
13102 Terminated
13103 143
13104 $ for sig in 1 2 3 15; do
13105 > echo $sig:
13106 > /bin/sh -c "kill -$s \$\$"; echo $?
13107 > done
13108 signal 1:
13109 Hangup
13110 129
13111 signal 2:
13112 208
13113 signal 3:
13114 208
13115 signal 15:
13116 208
13117
13118 This gets even worse if one is using the POSIX “wait” interface to
13119 get details about the shell process terminations: it will result in the
13120 shell having exited normally, rather than by receiving a signal.
13121
13122 $ cat > foo.c <<'END'
13123 #include <stdio.h> /* for printf */
13124 #include <stdlib.h> /* for system */
13125 #include <sys/wait.h> /* for WIF* macros */
13126 int main(void)
13127 {
13128 int status = system ("kill -15 $$");
13129 printf ("Terminated by signal: %s\n",
13130 WIFSIGNALED (status) ? "yes" : "no");
13131 printf ("Exited normally: %s\n",
13132 WIFEXITED (status) ? "yes" : "no");
13133 return 0;
13134 }
13135 END
13136 $ cc -o foo foo.c
13137 $ ./a.out # On GNU/Linux
13138 Terminated by signal: no
13139 Exited normally: yes
13140 $ ./a.out # On Solaris 10
13141 Terminated by signal: yes
13142 Exited normally: no
13143
13144 Various shells seem to handle ‘SIGQUIT’ specially: they ignore it
13145 even if it is not blocked, and even if the shell is not running
13146 interactively (in fact, even if the shell has no attached tty); among
13147 these shells are at least Bash (from version 2 onward), Zsh 4.3.12,
13148 Solaris 10 ‘/bin/ksh’ and ‘/usr/xpg4/bin/sh’, and AT&T ‘ksh93’ (2011).
13149 Still, ‘SIGQUIT’ seems to be trappable quite portably within all these
13150 shells. OTOH, some other shells doesn’t special-case the handling of
13151 ‘SIGQUIT’; among these shells are at least ‘pdksh’ 5.2.14, Solaris 10
13152 and NetBSD 5.1 ‘/bin/sh’, and the Almquist Shell 0.5.5.1.
13153
13154 Some shells (especially Korn shells and derivatives) might try to
13155 propagate to themselves a signal that has killed a child process; this
13156 is not a bug, but a conscious design choice (although its overall value
13157 might be debatable). The exact details of how this is attained vary
13158 from shell to shell. For example, upon running ‘perl -e 'kill 2, $$'’,
13159 after the perl process has been interrupted, AT&T ‘ksh93’ (2011) will
13160 proceed to send itself a ‘SIGINT’, while Solaris 10 ‘/bin/ksh’ and
13161 ‘/usr/xpg4/bin/sh’ will proceed to exit with status 130 (i.e., 128 + 2).
13162 In any case, if there is an active trap associated with ‘SIGINT’, those
13163 shells will correctly execute it.
13164
13165 Some Korn shells, when a child process die due receiving a signal
13166 with signal number N, can leave in ‘$?’ an exit status of 256+N instead
13167 of the more common 128+N. Observe the difference between AT&T ‘ksh93’
13168 (2011) and ‘bash’ 4.1.5 on Debian:
13169
13170 $ /bin/ksh -c 'sh -c "kill -1 \$\$"; echo $?'
13171 /bin/ksh: line 1: 7837: Hangup
13172 257
13173 $ /bin/bash -c 'sh -c "kill -1 \$\$"; echo $?'
13174 /bin/bash: line 1: 7861 Hangup (sh -c "kill -1 \$\$")
13175 129
13176
13177 This ‘ksh’ behavior is allowed by POSIX, if implemented with due care;
13178 see this Austin Group discussion
13179 (https://www.austingroupbugs.net/view.php?id=51) for more background.
13180 However, if it is not implemented with proper care, such a behavior
13181 might cause problems in some corner cases. To see why, assume we have a
13182 “wrapper” script like this:
13183
13184 #!/bin/sh
13185 # Ignore some signals in the shell only, not in its child processes.
13186 trap : 1 2 13 15
13187 wrapped_command "$@"
13188 ret=$?
13189 other_command
13190 exit $ret
13191
13192 If ‘wrapped_command’ is interrupted by a ‘SIGHUP’ (which has signal
13193 number 1), ‘ret’ will be set to 257. Unless the ‘exit’ shell builtin is
13194 smart enough to understand that such a value can only have originated
13195 from a signal, and adjust the final wait status of the shell
13196 appropriately, the value 257 will just get truncated to 1 by the closing
13197 ‘exit’ call, so that a caller of the script will have no way to
13198 determine that termination by a signal was involved. Observe the
13199 different behavior of AT&T ‘ksh93’ (2011) and ‘bash’ 4.1.5 on Debian:
13200
13201 $ cat foo.sh
13202 #!/bin/sh
13203 sh -c 'kill -1 $$'
13204 ret=$?
13205 echo $ret
13206 exit $ret
13207 $ /bin/ksh foo.sh; echo $?
13208 foo.sh: line 2: 12479: Hangup
13209 257
13210 1
13211 $ /bin/bash foo.sh; echo $?
13212 foo.sh: line 2: 12487 Hangup (sh -c 'kill -1 $$')
13213 129
13214 129
13215
13216 
13217 File: autoconf.info, Node: File System Conventions, Next: Shell Pattern Matching, Prev: Signal Handling, Up: Portable Shell
13218
13219 11.7 File System Conventions
13220 ============================
13221
13222 Autoconf uses shell-script processing extensively, so the file names
13223 that it processes should not contain characters that are special to the
13224 shell. Special characters include space, tab, newline, NUL, and the
13225 following:
13226
13227 " # $ & ' ( ) * ; < = > ? [ \ ` |
13228
13229 Also, file names should not begin with ‘~’ or ‘-’, and should contain
13230 neither ‘-’ immediately after ‘/’ nor ‘~’ immediately after ‘:’. On
13231 POSIX-like platforms, directory names should not contain ‘:’, as this
13232 runs afoul of ‘:’ used as the path separator.
13233
13234 These restrictions apply not only to the files that you distribute,
13235 but also to the absolute file names of your source, build, and
13236 destination directories.
13237
13238 On some POSIX-like platforms, ‘!’ and ‘^’ are special too, so they
13239 should be avoided.
13240
13241 POSIX lets implementations treat leading ‘//’ specially, but requires
13242 leading ‘///’ and beyond to be equivalent to ‘/’. Most Unix variants
13243 treat ‘//’ like ‘/’. However, some treat ‘//’ as a “super-root” that
13244 can provide access to files that are not otherwise reachable from ‘/’.
13245 The super-root tradition began with Apollo Domain/OS, which died out
13246 long ago, but unfortunately Cygwin has revived it.
13247
13248 While ‘autoconf’ and friends are usually run on some POSIX variety,
13249 they can be used on other systems, most notably DOS variants. This
13250 impacts several assumptions regarding file names.
13251
13252 For example, the following code:
13253
13254 case $foo_dir in
13255 /*) # Absolute
13256 ;;
13257 *)
13258 foo_dir=$dots$foo_dir ;;
13259 esac
13260
13261 fails to properly detect absolute file names on those systems, because
13262 they can use a drivespec, and usually use a backslash as directory
13263 separator. If you want to be portable to DOS variants (at the price of
13264 rejecting valid but oddball POSIX file names like ‘a:\b’), you can check
13265 for absolute file names like this:
13266
13267 case $foo_dir in
13268 [\\/]* | ?:[\\/]* ) # Absolute
13269 ;;
13270 *)
13271 foo_dir=$dots$foo_dir ;;
13272 esac
13273
13274 Make sure you quote the brackets if appropriate and keep the backslash
13275 as first character. *Note Limitations of Shell Builtins: case.
13276
13277 Also, because the colon is used as part of a drivespec, these systems
13278 don’t use it as path separator. When creating or accessing paths, you
13279 can use the ‘PATH_SEPARATOR’ output variable instead. ‘configure’ sets
13280 this to the appropriate value for the build system (‘:’ or ‘;’) when it
13281 starts up.
13282
13283 File names need extra care as well. While DOS variants that are
13284 POSIXy enough to run ‘autoconf’ (such as DJGPP) are usually able to
13285 handle long file names properly, there are still limitations that can
13286 seriously break packages. Several of these issues can be easily
13287 detected by the doschk
13288 (https://ftp.gnu.org/gnu/non-gnu/doschk/doschk-1.1.tar.gz) package.
13289
13290 A short overview follows; problems are marked with SFN/LFN to
13291 indicate where they apply: SFN means the issues are only relevant to
13292 plain DOS, not to DOS under Microsoft Windows variants, while LFN
13293 identifies problems that exist even under Microsoft Windows variants.
13294
13295 No multiple dots (SFN)
13296 DOS cannot handle multiple dots in file names. This is an
13297 especially important thing to remember when building a portable
13298 configure script, as ‘autoconf’ uses a .in suffix for template
13299 files.
13300
13301 This is perfectly OK on POSIX variants:
13302
13303 AC_CONFIG_HEADERS([config.h])
13304 AC_CONFIG_FILES([source.c foo.bar])
13305 AC_OUTPUT
13306
13307 but it causes problems on DOS, as it requires ‘config.h.in’,
13308 ‘source.c.in’ and ‘foo.bar.in’. To make your package more portable
13309 to DOS-based environments, you should use this instead:
13310
13311 AC_CONFIG_HEADERS([config.h:config.hin])
13312 AC_CONFIG_FILES([source.c:source.cin foo.bar:foobar.in])
13313 AC_OUTPUT
13314
13315 No leading dot (SFN)
13316 DOS cannot handle file names that start with a dot. This is
13317 usually not important for ‘autoconf’.
13318
13319 Case insensitivity (LFN)
13320 DOS is case insensitive, so you cannot, for example, have both a
13321 file called ‘INSTALL’ and a directory called ‘install’. This also
13322 affects ‘make’; if there’s a file called ‘INSTALL’ in the
13323 directory, ‘make install’ does nothing (unless the ‘install’ target
13324 is marked as PHONY).
13325
13326 The 8+3 limit (SFN)
13327 Because the DOS file system only stores the first 8 characters of
13328 the file name and the first 3 of the extension, those must be
13329 unique. That means that ‘foobar-part1.c’, ‘foobar-part2.c’ and
13330 ‘foobar-prettybird.c’ all resolve to the same file name
13331 (‘FOOBAR-P.C’). The same goes for ‘foo.bar’ and ‘foo.bartender’.
13332
13333 The 8+3 limit is not usually a problem under Microsoft Windows, as
13334 it uses numeric tails in the short version of file names to make
13335 them unique. However, a registry setting can turn this behavior
13336 off. While this makes it possible to share file trees containing
13337 long file names between SFN and LFN environments, it also means the
13338 above problem applies there as well.
13339
13340 Invalid characters (LFN)
13341 Some characters are invalid in DOS file names, and should therefore
13342 be avoided. In a LFN environment, these are ‘/’, ‘\’, ‘?’, ‘*’,
13343 ‘:’, ‘<’, ‘>’, ‘|’ and ‘"’. In a SFN environment, other characters
13344 are also invalid. These include ‘+’, ‘,’, ‘[’ and ‘]’.
13345
13346 Invalid names (LFN)
13347 Some DOS file names are reserved, and cause problems if you try to
13348 use files with those names. These names include ‘CON’, ‘AUX’,
13349 ‘COM1’, ‘COM2’, ‘COM3’, ‘COM4’, ‘LPT1’, ‘LPT2’, ‘LPT3’, ‘NUL’, and
13350 ‘PRN’. File names are case insensitive, so even names like
13351 ‘aux/config.guess’ are disallowed.
13352
13353 
13354 File: autoconf.info, Node: Shell Pattern Matching, Next: Shell Substitutions, Prev: File System Conventions, Up: Portable Shell
13355
13356 11.8 Shell Pattern Matching
13357 ===========================
13358
13359 Portable patterns should avoid the following constructs:
13360
13361 • A bracket expression like ‘[a-z]’ outside the C locale. This
13362 pattern may match characters that are not lower-case letters.
13363 Outside the C locale, use ‘[[:lower:]]’ instead, or to match just
13364 lower-case ASCII letters use ‘[abcdefghijklmnopqrstuvwxyz]’.
13365
13366 • A bracket expression starting with ‘^’. For example, ‘[!-aeiou]’
13367 is portable, but ‘[^-aeiou]’ is not.
13368
13369 • When matching file names, a pattern containing ‘*’, ‘?’ or ‘[...]’
13370 that might match the file names ‘.’ or ‘..’. For example ‘.*’
13371 might match ‘.’ and ‘..’, but it might not.
13372
13373 • Any of the following characters, unless quoted or escaped or in a
13374 bracket expression:
13375
13376 ! # % = [ ] ^ { } ~
13377
13378 An unescaped ‘[’ that does not introduce a bracket expression is
13379 problematic because, for example, ‘a*[’ might match the file name
13380 ‘abc[’, but it might not.
13381
13382 Curly braces are problematic because POSIX allows but does not
13383 require brace expansion. For example, the shell command ‘echo
13384 a{b,c,d}e’ outputs ‘abe ace ade’ with Bash, but ‘a{b,c,d}e’ with
13385 Dash.
13386
13387 • Backlashes in bracket expressions, unless doubled. For example,
13388 ‘[\\^]’ is portable, but ‘[\^]’ is not.
13389
13390 • An unescaped backslash at pattern end.
13391
13392 • A NUL byte. More generally, a NUL byte should never appear
13393 anywhere in a portable shell script.
13394
13395 
13396 File: autoconf.info, Node: Shell Substitutions, Next: Assignments, Prev: Shell Pattern Matching, Up: Portable Shell
13397
13398 11.9 Shell Substitutions
13399 ========================
13400
13401 Contrary to a persistent urban legend, the Bourne shell does not
13402 systematically split variables and back-quoted expressions, in
13403 particular on the right-hand side of assignments and in the argument of
13404 ‘case’. For instance, the following code:
13405
13406 case "$given_srcdir" in
13407 .) top_srcdir="`printf '%s\n' "$dots" | sed 's|/$||'`" ;;
13408 *) top_srcdir="$dots$given_srcdir" ;;
13409 esac
13410
13411 is more readable when written as:
13412
13413 case $given_srcdir in
13414 .) top_srcdir=`printf '%s\n' "$dots" | sed 's|/$||'` ;;
13415 *) top_srcdir=$dots$given_srcdir ;;
13416 esac
13417
13418 and in fact it is even _more_ portable: in the first case of the first
13419 attempt, the computation of ‘top_srcdir’ is not portable, since not all
13420 shells properly understand ‘"`..."..."...`"’, for example Solaris 10
13421 ‘ksh’:
13422
13423 $ foo="`echo " bar" | sed 's, ,,'`"
13424 ksh: : cannot execute
13425 ksh: bar | sed 's, ,,': cannot execute
13426
13427 POSIX does not specify behavior for this sequence. On the other hand,
13428 behavior for ‘"`...\"...\"...`"’ is specified by POSIX, but in practice,
13429 not all shells understand it the same way: pdksh 5.2.14 prints spurious
13430 quotes when in POSIX mode:
13431
13432 $ echo "`echo \"hello\"`"
13433 hello
13434 $ set -o posix
13435 $ echo "`echo \"hello\"`"
13436 "hello"
13437
13438 There is just no portable way to use double-quoted strings inside
13439 double-quoted back-quoted expressions (pfew!).
13440
13441 Bash 4.1 has a bug where quoted empty strings adjacent to unquoted
13442 parameter expansions are elided during word splitting. Meanwhile, zsh
13443 does not perform word splitting except when in Bourne compatibility
13444 mode. In the example below, the correct behavior is to have five
13445 arguments to the function, and exactly two spaces on either side of the
13446 middle ‘-’, since word splitting collapses multiple spaces in ‘$f’ but
13447 leaves empty arguments intact.
13448
13449 $ bash -c 'n() { echo "$#$@"; }; f=" - "; n - ""$f"" -'
13450 3- - -
13451 $ ksh -c 'n() { echo "$#$@"; }; f=" - "; n - ""$f"" -'
13452 5- - -
13453 $ zsh -c 'n() { echo "$#$@"; }; f=" - "; n - ""$f"" -'
13454 3- - -
13455 $ zsh -c 'emulate sh;
13456 > n() { echo "$#$@"; }; f=" - "; n - ""$f"" -'
13457 5- - -
13458
13459 You can work around this by doing manual word splitting, such as using
13460 ‘"$str" $list’ rather than ‘"$str"$list’.
13461
13462 There are also portability pitfalls with particular expansions:
13463
13464 ‘$@’
13465 Autoconf macros often use the ‘set’ command to update ‘$@’, so if
13466 you are writing shell code intended for ‘configure’ you should not
13467 assume that the value of ‘$@’ persists for any length of time.
13468
13469 You may see usages like ‘${1+"$@"}’ in older shell scripts designed
13470 to work around a portability problem in ancient shells.
13471 Unfortunately this runs afoul of bugs in more-recent shells, and
13472 nowadays it is better to use plain ‘"$@"’ instead.
13473
13474 The portability problem with ancient shells was significant. When
13475 there are no positional arguments ‘"$@"’ should be discarded, but
13476 the original Unix version 7 Bourne shell mistakenly treated it as
13477 equivalent to ‘""’ instead, and many ancient shells followed its
13478 lead.
13479
13480 For many years shell scripts worked around this portability problem
13481 by using ‘${1+"$@"}’ instead of ‘"$@"’, and you may see this usage
13482 in older scripts. Unfortunately, ‘${1+"$@"}’ does not work with
13483 ‘ksh93’ M 93t+ (2009) as shipped in AIX 7.2 (2015), as this shell
13484 drops a trailing empty argument:
13485
13486 $ set a b c ""
13487 $ set ${1+"$@"}
13488 $ echo $#
13489 3
13490
13491 Also, ‘${1+"$@"}’ does not work with Zsh 4.2.6 (2005) and earlier,
13492 as shipped in Mac OS X releases before 10.5, as this old Zsh
13493 incorrectly word splits the result:
13494
13495 zsh $ emulate sh
13496 zsh $ for i in "$@"; do echo $i; done
13497 Hello World
13498 !
13499 zsh $ for i in ${1+"$@"}; do echo $i; done
13500 Hello
13501 World
13502 !
13503
13504 To work around these problems Autoconf does two things. First, in
13505 the shell code that it generates Autoconf avoids ‘"$@"’ if it is
13506 possible that there may be no positional arguments. You can use
13507 this workaround in your own code, too, if you want it to be
13508 portable to ancient shells. For example, instead of:
13509
13510 cat conftest.c "$@"
13511
13512 you can use this:
13513
13514 case $# in
13515 0) cat conftest.c;;
13516 *) cat conftest.c "$@";;
13517 esac
13518
13519 Second, Autoconf-generated ‘configure’ scripts work around most of
13520 the old Zsh problem by using Zsh’s “global aliases” to convert
13521 ‘${1+"$@"}’ into ‘"$@"’ by itself:
13522
13523 test ${ZSH_VERSION+y} && alias -g '${1+"$@"}'='"$@"'
13524
13525 This workaround is for the benefit of any instances of ‘${1+"$@"}’
13526 in user-written code appearing in ‘configure’ scripts. However, it
13527 is not a complete solution, as Zsh recognizes the alias only when a
13528 shell word matches it exactly, which means older Zsh still
13529 mishandles more-complicated cases like ‘"foo"${1+"$@"}’.
13530
13531 ‘${10}’
13532 The 10th, 11th, ... positional parameters can be accessed only
13533 after a ‘shift’. The 7th Edition shell reported an error if given
13534 ‘${10}’, and Solaris 10 ‘/bin/sh’ still acts that way:
13535
13536 $ set 1 2 3 4 5 6 7 8 9 10
13537 $ echo ${10}
13538 bad substitution
13539
13540 Conversely, not all shells obey the POSIX rule that when braces are
13541 omitted, multiple digits beyond a ‘$’ imply the single-digit
13542 positional parameter expansion concatenated with the remaining
13543 literal digits. To work around the issue, you must use braces.
13544
13545 $ bash -c 'set a b c d e f g h i j; echo $10 ${1}0'
13546 a0 a0
13547 $ dash -c 'set a b c d e f g h i j; echo $10 ${1}0'
13548 j a0
13549
13550 ‘${VAR-VALUE}’
13551 ‘${VAR:-VALUE}’
13552 ‘${VAR=VALUE}’
13553 ‘${VAR:=VALUE}’
13554 ‘${VAR?VALUE}’
13555 ‘${VAR:?VALUE}’
13556 ‘${VAR+VALUE}’
13557 ‘${VAR:+VALUE}’
13558 When using ‘${VAR-VALUE}’ or similar notations that modify a
13559 parameter expansion, POSIX requires that VALUE must be a single
13560 shell word, which can contain quoted strings but cannot contain
13561 unquoted spaces. If this requirement is not met Solaris 10
13562 ‘/bin/sh’ sometimes complains, and anyway the behavior is not
13563 portable.
13564
13565 $ /bin/sh -c 'echo ${a-b c}'
13566 /bin/sh: bad substitution
13567 $ /bin/sh -c 'echo ${a-'\''b c'\''}'
13568 b c
13569 $ /bin/sh -c 'echo "${a-b c}"'
13570 b c
13571 $ /bin/sh -c 'cat <<EOF
13572 ${a-b c}
13573 EOF
13574 b c
13575
13576 Most shells treat the special parameters ‘*’ and ‘@’ as being unset
13577 if there are no positional parameters. However, some shells treat
13578 them as being set to the empty string. POSIX does not clearly
13579 specify either behavior.
13580
13581 $ bash -c 'echo "* is ${*-unset}."'
13582 * is unset.
13583 $ dash -c 'echo "* is ${*-unset}."'
13584 * is .
13585
13586 According to POSIX, if an expansion occurs inside double quotes,
13587 then the use of unquoted double quotes within VALUE is unspecified,
13588 and any single quotes become literal characters; in that case,
13589 escaping must be done with backslash. Likewise, the use of
13590 unquoted here-documents is a case where double quotes have
13591 unspecified results:
13592
13593 $ /bin/sh -c 'echo "${a-"b c"}"'
13594 /bin/sh: bad substitution
13595 $ ksh -c 'echo "${a-"b c"}"'
13596 b c
13597 $ bash -c 'echo "${a-"b c"}"'
13598 b c
13599 $ /bin/sh -c 'a=; echo ${a+'\''b c'\''}'
13600 b c
13601 $ /bin/sh -c 'a=; echo "${a+'\''b c'\''}"'
13602 'b c'
13603 $ /bin/sh -c 'a=; echo "${a+\"b c\"}"'
13604 "b c"
13605 $ /bin/sh -c 'a=; echo "${a+b c}"'
13606 b c
13607 $ /bin/sh -c 'cat <<EOF
13608 ${a-"b c"}
13609 EOF'
13610 "b c"
13611 $ /bin/sh -c 'cat <<EOF
13612 ${a-'b c'}
13613 EOF'
13614 'b c'
13615 $ bash -c 'cat <<EOF
13616 ${a-"b c"}
13617 EOF'
13618 b c
13619 $ bash -c 'cat <<EOF
13620 ${a-'b c'}
13621 EOF'
13622 'b c'
13623
13624 Perhaps the easiest way to work around quoting issues in a manner
13625 portable to all shells is to place the results in a temporary
13626 variable, then use ‘$t’ as the VALUE, rather than trying to inline
13627 the expression needing quoting.
13628
13629 $ /bin/sh -c 't="b c\"'\''}\\"; echo "${a-$t}"'
13630 b c"'}\
13631 $ ksh -c 't="b c\"'\''}\\"; echo "${a-$t}"'
13632 b c"'}\
13633 $ bash -c 't="b c\"'\''}\\"; echo "${a-$t}"'
13634 b c"'}\
13635
13636 ‘${VAR=VALUE}’
13637 When using ‘${VAR=VALUE}’ to assign a default value to VAR,
13638 remember that even though the assignment to VAR does not undergo
13639 file name expansion, the result of the variable expansion does
13640 unless the expansion occurred within double quotes. In particular,
13641 when using ‘:’ followed by unquoted variable expansion for the side
13642 effect of setting a default value, if the final value of ‘$var’
13643 contains any globbing characters (either from VALUE or from prior
13644 contents), the shell has to spend time performing file name
13645 expansion and field splitting even though those results will not be
13646 used. Therefore, it is a good idea to consider double quotes when
13647 performing default initialization; while remembering how this
13648 impacts any quoting characters appearing in VALUE.
13649
13650 $ time bash -c ': "${a=/usr/bin/*}"; echo "$a"'
13651 /usr/bin/*
13652
13653 real 0m0.005s
13654 user 0m0.002s
13655 sys 0m0.003s
13656 $ time bash -c ': ${a=/usr/bin/*}; echo "$a"'
13657 /usr/bin/*
13658
13659 real 0m0.039s
13660 user 0m0.026s
13661 sys 0m0.009s
13662 $ time bash -c 'a=/usr/bin/*; : ${a=noglob}; echo "$a"'
13663 /usr/bin/*
13664
13665 real 0m0.031s
13666 user 0m0.020s
13667 sys 0m0.010s
13668
13669 $ time bash -c 'a=/usr/bin/*; : "${a=noglob}"; echo "$a"'
13670 /usr/bin/*
13671
13672 real 0m0.006s
13673 user 0m0.002s
13674 sys 0m0.003s
13675
13676 As with ‘+’ and ‘-’, VALUE must be a single shell word, otherwise
13677 some shells, such as Solaris 10 ‘/bin/sh’ or on Digital Unix V 5.0,
13678 die because of a “bad substitution”. Meanwhile, POSIX requires
13679 that with ‘=’, quote removal happens prior to the assignment, and
13680 the expansion be the final contents of VAR without quoting (and
13681 thus subject to field splitting), in contrast to the behavior with
13682 ‘-’ passing the quoting through to the final expansion. However,
13683 ‘bash’ 4.1 does not obey this rule.
13684
13685 $ ksh -c 'echo ${var-a\ \ b}'
13686 a b
13687 $ ksh -c 'echo ${var=a\ \ b}'
13688 a b
13689 $ bash -c 'echo ${var=a\ \ b}'
13690 a b
13691
13692 Finally, POSIX states that when mixing ‘${a=b}’ with regular
13693 commands, it is unspecified whether the assignments affect the
13694 parent shell environment. It is best to perform assignments
13695 independently from commands, to avoid the problems demonstrated in
13696 this example running on Solaris 10:
13697
13698 $ cmd='x= y=${x:=b} sh -c "echo +\$x+\$y+";printf "%s\\n" -$x-'
13699 $ bash -c "$cmd"
13700 +b+b+
13701 -b-
13702 $ /bin/sh -c "$cmd"
13703 ++b+
13704 --
13705 $ ksh -c "$cmd"
13706 +b+b+
13707 --
13708
13709 ‘${VAR=VALUE}’
13710 Solaris 10 ‘/bin/sh’ has a frightening bug in its handling of
13711 literal assignments. Imagine you need set a variable to a string
13712 containing ‘}’. This ‘}’ character confuses Solaris 10 ‘/bin/sh’
13713 when the affected variable was already set. This bug can be
13714 exercised by running:
13715
13716 $ unset foo
13717 $ foo=${foo='}'}
13718 $ echo $foo
13719 }
13720 $ foo=${foo='}' # no error; this hints to what the bug is
13721 $ echo $foo
13722 }
13723 $ foo=${foo='}'}
13724 $ echo $foo
13725 }}
13726 ^ ugh!
13727
13728 It seems that ‘}’ is interpreted as matching ‘${’, even though it
13729 is enclosed in single quotes. The problem doesn’t happen using
13730 double quotes, or when using a temporary variable holding the
13731 problematic string.
13732
13733 ‘${VAR=EXPANDED-VALUE}’
13734 On shells so old that they are no longer relevant, the command
13735
13736 # Set the shell variable to a default value
13737 # if it is not already set.
13738 : ${var="$default"}
13739
13740 misbehaved badly in some cases. Older scripts worked around the
13741 bugs by using one of following two lines, the latter of which was
13742 more portable:
13743
13744 var=${var="$default"}
13745 test ${var+y} || var=$default
13746
13747 However, these workarounds are no longer needed.
13748
13749 ‘${#VAR}’
13750 ‘${VAR%WORD}’
13751 ‘${VAR%%WORD}’
13752 ‘${VAR#WORD}’
13753 ‘${VAR##WORD}’
13754 POSIX requires support for these usages, but they do not work with
13755 many traditional shells, e.g., Solaris 10 ‘/bin/sh’.
13756
13757 Also, ‘pdksh’ 5.2.14 mishandles some WORD forms. For example if
13758 ‘$1’ is ‘a/b’ and ‘$2’ is ‘a’, then ‘${1#$2}’ should yield ‘/b’,
13759 but with ‘pdksh’ it yields the empty string.
13760
13761 ‘`COMMANDS`’
13762 POSIX requires shells to trim all trailing newlines from command
13763 output before substituting it, so assignments like ‘dir=`printf
13764 '%s\n' "$file" | tr a A`’ do not work as expected if ‘$file’ ends
13765 in a newline.
13766
13767 While in general it makes no sense, do not substitute a single
13768 builtin with side effects, because Ash 0.2, trying to optimize,
13769 does not fork a subshell to perform the command. For instance, if
13770 you wanted to check that ‘cd’ is silent, do not use ‘test -z "`cd
13771 /`"’ because the following can happen:
13772
13773 $ pwd
13774 /tmp
13775 $ test -z "`cd /`" && pwd
13776 /
13777
13778 The result of ‘foo=`exit 1`’ is left as an exercise to the reader.
13779
13780 The MSYS shell leaves a stray byte in the expansion of a
13781 double-quoted command substitution of a native program, if the end
13782 of the substitution is not aligned with the end of the double
13783 quote. This may be worked around by inserting another pair of
13784 quotes:
13785
13786 $ echo "`printf 'foo\r\n'` bar" > broken
13787 $ echo "`printf 'foo\r\n'`"" bar" | cmp - broken
13788 - broken differ: char 4, line 1
13789
13790 Upon interrupt or SIGTERM, some shells may abort a command
13791 substitution, replace it with a null string, and wrongly evaluate
13792 the enclosing command before entering the trap or ending the
13793 script. This can lead to spurious errors:
13794
13795 $ sh -c 'if test `sleep 5; echo hi` = hi; then echo yes; fi'
13796 $ ^C
13797 sh: test: hi: unexpected operator/operand
13798
13799 You can avoid this by assigning the command substitution to a
13800 temporary variable:
13801
13802 $ sh -c 'res=`sleep 5; echo hi`
13803 if test "x$res" = xhi; then echo yes; fi'
13804 $ ^C
13805
13806 ‘$(COMMANDS)’
13807 This construct is meant to replace ‘`COMMANDS`’, and it has most of
13808 the problems listed under ‘`COMMANDS`’.
13809
13810 This construct can be nested while this is impossible to do
13811 portably with back quotes. Although it is almost universally
13812 supported, unfortunately Solaris 10 and earlier releases lack it:
13813
13814 $ showrev -c /bin/sh | grep version
13815 Command version: SunOS 5.10 Generic 142251-02 Sep 2010
13816 $ echo $(echo blah)
13817 syntax error: `(' unexpected
13818
13819 If you do use ‘$(COMMANDS)’, make sure that the commands do not
13820 start with a parenthesis, as that would cause confusion with a
13821 different notation ‘$((EXPRESSION))’ that in modern shells is an
13822 arithmetic expression not a command. To avoid the confusion,
13823 insert a space between the two opening parentheses.
13824
13825 Avoid COMMANDS that contain unbalanced parentheses in
13826 here-documents, comments, or case statement patterns, as many
13827 shells mishandle them. For example, Bash 3.1, ‘ksh88’, ‘pdksh’
13828 5.2.14, and Zsh 4.2.6 all mishandle the following valid command:
13829
13830 echo $(case x in x) echo hello;; esac)
13831
13832 ‘$((EXPRESSION))’
13833 Arithmetic expansion is not portable as some shells (most notably
13834 Solaris 10 ‘/bin/sh’) don’t support it.
13835
13836 Among shells that do support ‘$(( ))’, not all of them obey the
13837 POSIX rule that octal and hexadecimal constants must be recognized:
13838
13839 $ bash -c 'echo $(( 010 + 0x10 ))'
13840 24
13841 $ zsh -c 'echo $(( 010 + 0x10 ))'
13842 26
13843 $ zsh -c 'emulate sh; echo $(( 010 + 0x10 ))'
13844 24
13845 $ pdksh -c 'echo $(( 010 + 0x10 ))'
13846 pdksh: 010 + 0x10 : bad number `0x10'
13847 $ pdksh -c 'echo $(( 010 ))'
13848 10
13849
13850 When it is available, using arithmetic expansion provides a
13851 noticeable speedup in script execution; but testing for support
13852 requires ‘eval’ to avoid syntax errors. The following construct is
13853 used by ‘AS_VAR_ARITH’ to provide arithmetic computation when all
13854 arguments are decimal integers without leading zeros, and all
13855 operators are properly quoted and appear as distinct arguments:
13856
13857 if ( eval 'test $(( 1 + 1 )) = 2' ) 2>/dev/null; then
13858 eval 'func_arith ()
13859 {
13860 func_arith_result=$(( $* ))
13861 }'
13862 else
13863 func_arith ()
13864 {
13865 func_arith_result=`expr "$@"`
13866 }
13867 fi
13868 func_arith 1 + 1
13869 foo=$func_arith_result
13870
13871 ‘^’
13872 Always quote ‘^’, otherwise traditional shells such as ‘/bin/sh’ on
13873 Solaris 10 treat this like ‘|’.
13874
13875 
13876 File: autoconf.info, Node: Assignments, Next: Parentheses, Prev: Shell Substitutions, Up: Portable Shell
13877
13878 11.10 Assignments
13879 =================
13880
13881 When setting several variables in a row, be aware that the order of the
13882 evaluation is undefined. For instance ‘foo=1 foo=2; echo $foo’ gives
13883 ‘1’ with Solaris 10 ‘/bin/sh’, but ‘2’ with Bash. You must use ‘;’ to
13884 enforce the order: ‘foo=1; foo=2; echo $foo’.
13885
13886 Don’t rely on the following to find ‘subdir/program’:
13887
13888 PATH=subdir$PATH_SEPARATOR$PATH program
13889
13890 as this does not work with Zsh 3.0.6. Use something like this instead:
13891
13892 (PATH=subdir$PATH_SEPARATOR$PATH; export PATH; exec program)
13893
13894 Don’t rely on the exit status of an assignment: Ash 0.2 does not
13895 change the status and propagates that of the last statement:
13896
13897 $ false || foo=bar; echo $?
13898 1
13899 $ false || foo=`:`; echo $?
13900 0
13901
13902 and to make things even worse, QNX 4.25 just sets the exit status to 0
13903 in any case:
13904
13905 $ foo=`exit 1`; echo $?
13906 0
13907
13908 To assign default values, follow this algorithm:
13909
13910 1. If the default value is a literal and does not contain any closing
13911 brace, use:
13912
13913 : "${var='my literal'}"
13914
13915 2. If the default value contains no closing brace, has to be expanded,
13916 and the variable being initialized is not intended to be IFS-split
13917 (i.e., it’s not a list), then use:
13918
13919 : ${var="$default"}
13920
13921 3. If the default value contains no closing brace, has to be expanded,
13922 and the variable being initialized is intended to be IFS-split
13923 (i.e., it’s a list), then use:
13924
13925 var=${var="$default"}
13926
13927 4. If the default value contains a closing brace, then use:
13928
13929 test ${var+y} || var="has a '}'"
13930
13931 In most cases ‘var=${var="$default"}’ is fine, but in case of doubt,
13932 just use the last form. *Note Shell Substitutions::, items
13933 ‘${VAR:-VALUE}’ and ‘${VAR=VALUE}’ for the rationale.
13934
13935 
13936 File: autoconf.info, Node: Parentheses, Next: Special Shell Variables, Prev: Assignments, Up: Portable Shell
13937
13938 11.11 Parentheses in Shell Scripts
13939 ==================================
13940
13941 Beware of two opening parentheses in a row, as many shell
13942 implementations treat them specially, and POSIX says that a portable
13943 script cannot use ‘((’ outside the ‘$((’ form used for shell arithmetic.
13944 In traditional shells, ‘((cat))’ behaves like ‘(cat)’; but many shells,
13945 including Bash and the Korn shell, treat ‘((cat))’ as an arithmetic
13946 expression equivalent to ‘let "cat"’, and may or may not report an error
13947 when they detect that ‘cat’ is not a number. As another example,
13948 ‘pdksh’ 5.2.14 does not treat the following code as a traditional shell
13949 would:
13950
13951 if ((true) || false); then
13952 echo ok
13953 fi
13954
13955 To work around this problem, insert a space between the two opening
13956 parentheses. There is a similar problem and workaround with ‘$((’; see
13957 *note Shell Substitutions::.
13958
13959 
13960 File: autoconf.info, Node: Special Shell Variables, Next: Shell Functions, Prev: Parentheses, Up: Portable Shell
13961
13962 11.12 Special Shell Variables
13963 =============================
13964
13965 Some shell variables should not be used, since they can have a deep
13966 influence on the behavior of the shell. In order to recover a sane
13967 behavior from the shell, some variables should be unset; M4sh takes care
13968 of this and provides fallback values, whenever needed, to cater for a
13969 very old ‘/bin/sh’ that does not support ‘unset’. (*note Portable Shell
13970 Programming: Portable Shell.).
13971
13972 As a general rule, shell variable names containing a lower-case
13973 letter are safe; you can define and use these variables without worrying
13974 about their effect on the underlying system, and without worrying about
13975 whether the shell changes them unexpectedly. (The exception is the
13976 shell variable ‘status’, as described below.)
13977
13978 Here is a list of names that are known to cause trouble. This list
13979 is not exhaustive, but you should be safe if you avoid the name ‘status’
13980 and names containing only upper-case letters and underscores.
13981
13982 ‘?’
13983 Not all shells correctly reset ‘$?’ after conditionals (*note
13984 Limitations of Shell Builtins: if.). Not all shells manage ‘$?’
13985 correctly in shell functions (*note Shell Functions::) or in traps
13986 (*note Limitations of Shell Builtins: trap.). Not all shells reset
13987 ‘$?’ to zero after an empty command.
13988
13989 $ bash -c 'false; $empty; echo $?'
13990 0
13991 $ zsh -c 'false; $empty; echo $?'
13992 1
13993
13994 ‘_’
13995 Many shells reserve ‘$_’ for various purposes, e.g., the name of
13996 the last command executed.
13997
13998 ‘CDPATH’
13999 When this variable is set it specifies a list of directories to
14000 search when invoking ‘cd’ with a relative file name that did not
14001 start with ‘./’ or ‘../’. POSIX says that if a nonempty directory
14002 name from ‘CDPATH’ is used successfully, ‘cd’ prints the resulting
14003 absolute file name. Unfortunately this output can break idioms
14004 like ‘abs=`cd src && pwd`’ because ‘abs’ receives the name twice.
14005 Also, many shells do not conform to this part of POSIX; for
14006 example, ‘zsh’ prints the result only if a directory name other
14007 than ‘.’ was chosen from ‘CDPATH’.
14008
14009 In practice the shells that have this problem also support ‘unset’,
14010 so you can work around the problem as follows:
14011
14012 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
14013
14014 You can also avoid output by ensuring that your directory name is
14015 absolute or anchored at ‘./’, as in ‘abs=`cd ./src && pwd`’.
14016
14017 Configure scripts use M4sh, which automatically unsets ‘CDPATH’ if
14018 possible, so you need not worry about this problem in those
14019 scripts.
14020
14021 ‘CLICOLOR_FORCE’
14022 When this variable is set, some implementations of tools like ‘ls’
14023 attempt to add color to their output via terminal escape sequences,
14024 even when the output is not directed to a terminal, and can thus
14025 cause spurious failures in scripts. Configure scripts use M4sh,
14026 which automatically unsets this variable.
14027
14028 ‘DUALCASE’
14029 In the MKS shell, case statements and file name generation are
14030 case-insensitive unless ‘DUALCASE’ is nonzero. Autoconf-generated
14031 scripts export this variable when they start up.
14032
14033 ‘ENV’
14034 ‘MAIL’
14035 ‘MAILPATH’
14036 ‘PS1’
14037 ‘PS2’
14038 ‘PS4’
14039 These variables should not matter for shell scripts, since they are
14040 supposed to affect only interactive shells. However, at least one
14041 shell (the pre-3.0 UWIN Korn shell) gets confused about whether it
14042 is interactive, which means that (for example) a ‘PS1’ with a side
14043 effect can unexpectedly modify ‘$?’. To work around this bug, M4sh
14044 scripts (including ‘configure’ scripts) do something like this:
14045
14046 (unset ENV) >/dev/null 2>&1 && unset ENV MAIL MAILPATH
14047 PS1='$ '
14048 PS2='> '
14049 PS4='+ '
14050
14051 (actually, there is some complication due to bugs in ‘unset’; *note
14052 Limitations of Shell Builtins: unset.).
14053
14054 ‘FPATH’
14055 The Korn shell uses ‘FPATH’ to find shell functions, so avoid
14056 ‘FPATH’ in portable scripts. ‘FPATH’ is consulted after ‘PATH’,
14057 but you still need to be wary of tests that use ‘PATH’ to find
14058 whether a command exists, since they might report the wrong result
14059 if ‘FPATH’ is also set.
14060
14061 ‘GREP_OPTIONS’
14062 When this variable is set, some implementations of ‘grep’ honor
14063 these options, even if the options include direction to enable
14064 colored output via terminal escape sequences, and the result can
14065 cause spurious failures when the output is not directed to a
14066 terminal. Configure scripts use M4sh, which automatically unsets
14067 this variable.
14068
14069 ‘HOME’
14070 Strange things can happen if ‘HOME’ is unset or empty. For
14071 example, plain ‘cd’ (with no arguments) has unspecified behavior.
14072 Also, ‘HOME’ should be absolute, not relative.
14073
14074 ‘IFS’
14075 Long ago, shell scripts inherited ‘IFS’ from the environment, but
14076 this caused many problems so modern shells ignore any environment
14077 settings for ‘IFS’.
14078
14079 Don’t set the first character of ‘IFS’ to backslash. Indeed,
14080 Bourne shells use the first character (backslash) when joining the
14081 components in ‘"$@"’ and some shells then reinterpret (!) the
14082 backslash escapes, so you can end up with backspace and other
14083 strange characters.
14084
14085 The proper value for ‘IFS’ (in regular code, not when performing
14086 splits) is ‘<SPC><TAB><RET>’. The first character is especially
14087 important, as it is used to join the arguments in ‘$*’; however,
14088 note that traditional shells, but also bash-2.04, fail to adhere to
14089 this and join with a space anyway.
14090
14091 M4sh guarantees that ‘IFS’ will have the default value at the
14092 beginning of a script, and many macros within autoconf rely on this
14093 setting. It is okay to use blocks of shell code that temporarily
14094 change the value of ‘IFS’ in order to split on another character,
14095 but remember to restore it before expanding further macros.
14096
14097 Unsetting ‘IFS’ instead of resetting it to the default sequence is
14098 not suggested, since code that tries to save and restore the
14099 variable’s value will incorrectly reset it to an empty value, thus
14100 disabling field splitting:
14101
14102 unset IFS
14103 # default separators used for field splitting
14104
14105 save_IFS=$IFS
14106 IFS=:
14107 # ...
14108 IFS=$save_IFS
14109 # no field splitting performed
14110
14111 ‘LANG’
14112 ‘LC_ALL’
14113 ‘LC_COLLATE’
14114 ‘LC_CTYPE’
14115 ‘LC_MESSAGES’
14116 ‘LC_MONETARY’
14117 ‘LC_NUMERIC’
14118 ‘LC_TIME’
14119
14120 You should set all these variables to ‘C’ because so much
14121 configuration code assumes the C locale and POSIX requires that
14122 locale environment variables be set to ‘C’ if the C locale is
14123 desired; ‘configure’ scripts and M4sh do that for you. Export
14124 these variables after setting them.
14125
14126 ‘LANGUAGE’
14127
14128 ‘LANGUAGE’ is not specified by POSIX, but it is a GNU extension
14129 that overrides ‘LC_ALL’ in some cases, so you (or M4sh) should set
14130 it too.
14131
14132 ‘LC_ADDRESS’
14133 ‘LC_IDENTIFICATION’
14134 ‘LC_MEASUREMENT’
14135 ‘LC_NAME’
14136 ‘LC_PAPER’
14137 ‘LC_TELEPHONE’
14138
14139 These locale environment variables are GNU extensions. They are
14140 treated like their POSIX brethren (‘LC_COLLATE’, etc.) as described
14141 above.
14142
14143 ‘LINENO’
14144 Most modern shells provide the current line number in ‘LINENO’.
14145 Its value is the line number of the beginning of the current
14146 command. M4sh, and hence Autoconf, attempts to execute ‘configure’
14147 with a shell that supports ‘LINENO’. If no such shell is
14148 available, it attempts to implement ‘LINENO’ with a Sed prepass
14149 that replaces each instance of the string ‘$LINENO’ (not followed
14150 by an alphanumeric character) with the line’s number. In M4sh
14151 scripts you should execute ‘AS_LINENO_PREPARE’ so that these
14152 workarounds are included in your script; configure scripts do this
14153 automatically in ‘AC_INIT’.
14154
14155 You should not rely on ‘LINENO’ within ‘eval’ or shell functions,
14156 as the behavior differs in practice. The presence of a quoted
14157 newline within simple commands can alter which line number is used
14158 as the starting point for ‘$LINENO’ substitutions within that
14159 command. Also, the possibility of the Sed prepass means that you
14160 should not rely on ‘$LINENO’ when quoted, when in here-documents,
14161 or when line continuations are used. Subshells should be OK,
14162 though. In the following example, lines 1, 9, and 14 are portable,
14163 but the other instances of ‘$LINENO’ do not have deterministic
14164 values:
14165
14166 $ cat lineno
14167 echo 1. $LINENO
14168 echo "2. $LINENO
14169 3. $LINENO"
14170 cat <<EOF
14171 5. $LINENO
14172 6. $LINENO
14173 7. \$LINENO
14174 EOF
14175 ( echo 9. $LINENO )
14176 eval 'echo 10. $LINENO'
14177 eval 'echo 11. $LINENO
14178 echo 12. $LINENO'
14179 echo 13. '$LINENO'
14180 echo 14. $LINENO '
14181 15.' $LINENO
14182 f () { echo $1 $LINENO;
14183 echo $1 $LINENO }
14184 f 18.
14185 echo 19. \
14186 $LINENO
14187 $ bash-3.2 ./lineno
14188 1. 1
14189 2. 3
14190 3. 3
14191 5. 4
14192 6. 4
14193 7. $LINENO
14194 9. 9
14195 10. 10
14196 11. 12
14197 12. 13
14198 13. $LINENO
14199 14. 14
14200 15. 14
14201 18. 16
14202 18. 17
14203 19. 19
14204 $ zsh-4.3.4 ./lineno
14205 1. 1
14206 2. 2
14207 3. 2
14208 5. 4
14209 6. 4
14210 7. $LINENO
14211 9. 9
14212 10. 1
14213 11. 1
14214 12. 2
14215 13. $LINENO
14216 14. 14
14217 15. 14
14218 18. 0
14219 18. 1
14220 19. 19
14221 $ pdksh-5.2.14 ./lineno
14222 1. 1
14223 2. 2
14224 3. 2
14225 5. 4
14226 6. 4
14227 7. $LINENO
14228 9. 9
14229 10. 0
14230 11. 0
14231 12. 0
14232 13. $LINENO
14233 14. 14
14234 15. 14
14235 18. 16
14236 18. 17
14237 19. 19
14238 $ sed '=' <lineno |
14239 > sed '
14240 > N
14241 > s,$,-,
14242 > t loop
14243 > :loop
14244 > s,^\([0-9]*\)\(.*\)[$]LINENO\([^a-zA-Z0-9_]\),\1\2\1\3,
14245 > t loop
14246 > s,-$,,
14247 > s,^[0-9]*\n,,
14248 > ' |
14249 > sh
14250 1. 1
14251 2. 2
14252 3. 3
14253 5. 5
14254 6. 6
14255 7. \7
14256 9. 9
14257 10. 10
14258 11. 11
14259 12. 12
14260 13. 13
14261 14. 14
14262 15. 15
14263 18. 16
14264 18. 17
14265 19. 20
14266
14267 In particular, note that ‘config.status’ (and any other subsidiary
14268 script created by ‘AS_INIT_GENERATED’) might report line numbers
14269 relative to the parent script as a result of the potential Sed
14270 pass.
14271
14272 ‘NULLCMD’
14273 When executing the command ‘>foo’, ‘zsh’ executes ‘$NULLCMD >foo’
14274 unless it is operating in Bourne shell compatibility mode and the
14275 ‘zsh’ version is newer than 3.1.6-dev-18. If you are using an
14276 older ‘zsh’ and forget to set ‘NULLCMD’, your script might be
14277 suspended waiting for data on its standard input.
14278
14279 ‘OLDPWD’
14280 POSIX requires that ‘cd’ must update the ‘OLDPWD’ environment
14281 variable, if set, to point to the name of the previous directory,
14282 but Solaris 10 ‘/bin/sh’ does not support this.
14283
14284 ‘options’
14285 For ‘zsh’ 4.3.10, ‘options’ is treated as an associative array even
14286 after ‘emulate sh’, so it should not be used.
14287
14288 ‘PATH_SEPARATOR’
14289 On DJGPP systems, the ‘PATH_SEPARATOR’ environment variable can be
14290 set to either ‘:’ or ‘;’ to control the path separator Bash uses to
14291 set up certain environment variables (such as ‘PATH’). You can set
14292 this variable to ‘;’ if you want ‘configure’ to use ‘;’ as a
14293 separator; this might be useful if you plan to use non-POSIX shells
14294 to execute files. *Note File System Conventions::, for more
14295 information about ‘PATH_SEPARATOR’.
14296
14297 ‘POSIXLY_CORRECT’
14298 In the GNU environment, exporting ‘POSIXLY_CORRECT’ with any value
14299 (even empty) causes programs to try harder to conform to POSIX.
14300 Autoconf does not directly manipulate this variable, but ‘bash’
14301 ties the shell variable ‘POSIXLY_CORRECT’ to whether the script is
14302 running in POSIX mode. Therefore, take care when exporting or
14303 unsetting this variable, so as not to change whether ‘bash’ is in
14304 POSIX mode.
14305
14306 $ bash --posix -c 'set -o | grep posix
14307 > unset POSIXLY_CORRECT
14308 > set -o | grep posix'
14309 posix on
14310 posix off
14311
14312 ‘PWD’
14313 POSIX requires that ‘cd’ must update the ‘PWD’ environment variable
14314 to point to the name of the current directory, but traditional
14315 shells do not support this. This can cause confusion if one shell
14316 instance maintains ‘PWD’ but a subsidiary and different shell does
14317 not know about ‘PWD’ and executes ‘cd’; in this case ‘PWD’ points
14318 to the wrong directory. Use ‘`pwd`’ rather than ‘$PWD’.
14319
14320 ‘RANDOM’
14321 Many shells provide ‘RANDOM’, a variable that returns a different
14322 integer each time it is used. It is common practice to use
14323 ‘$RANDOM’ as part of a file name, but code shouldn’t rely on
14324 ‘$RANDOM’ expanding to a nonempty string.
14325
14326 ‘status’
14327 This variable is an alias to ‘$?’ for ‘zsh’ (at least 3.1.6), hence
14328 read-only. Do not use it.
14329
14330 
14331 File: autoconf.info, Node: Shell Functions, Next: Limitations of Builtins, Prev: Special Shell Variables, Up: Portable Shell
14332
14333 11.13 Shell Functions
14334 =====================
14335
14336 Nowadays, it is difficult to find a shell that does not support shell
14337 functions at all. However, some differences should be expected.
14338
14339 When declaring a shell function, you must include whitespace between
14340 the ‘)’ after the function name and the start of the compound
14341 expression, to avoid upsetting ‘ksh’. While it is possible to use any
14342 compound command, most scripts use ‘{...}’.
14343
14344 $ /bin/sh -c 'a(){ echo hi;}; a'
14345 hi
14346 $ ksh -c 'a(){ echo hi;}; a'
14347 ksh: syntax error at line 1: `}' unexpected
14348 $ ksh -c 'a() { echo hi;}; a'
14349 hi
14350
14351 Inside a shell function, you should not rely on the error status of a
14352 subshell if the last command of that subshell was ‘exit’ or ‘trap’, as
14353 this triggers bugs in zsh 4.x; while Autoconf tries to find a shell that
14354 does not exhibit the bug, zsh might be the only shell present on the
14355 user’s machine.
14356
14357 Likewise, the state of ‘$?’ is not reliable when entering a shell
14358 function. This has the effect that using a function as the first
14359 command in a ‘trap’ handler can cause problems.
14360
14361 $ bash -c 'foo() { echo $?; }; trap foo 0; (exit 2); exit 2'; echo $?
14362 2
14363 2
14364 $ ash -c 'foo() { echo $?; }; trap foo 0; (exit 2); exit 2'; echo $?
14365 0
14366 2
14367
14368 DJGPP bash 2.04 has a bug in that ‘return’ from a shell function
14369 which also used a command substitution causes a segmentation fault. To
14370 work around the issue, you can use ‘return’ from a subshell, or
14371 ‘AS_SET_STATUS’ as last command in the execution flow of the function
14372 (*note Common Shell Constructs::).
14373
14374 Not all shells treat shell functions as simple commands impacted by
14375 ‘set -e’, for example with Solaris 10 ‘/bin/sh’:
14376
14377 $ bash -c 'f() { return 1; }; set -e; f; echo oops'
14378 $ /bin/sh -c 'f() { return 1; }; set -e; f; echo oops'
14379 oops
14380
14381 Shell variables and functions may share the same namespace, for
14382 example with Solaris 10 ‘/bin/sh’:
14383
14384 $ f () { :; }; f=; f
14385 f: not found
14386
14387 For this reason, Autoconf (actually M4sh, *note Programming in M4sh::)
14388 uses the prefix ‘as_fn_’ for its functions.
14389
14390 Handling of positional parameters and shell options varies among
14391 shells. For example, Korn shells reset and restore trace output (‘set
14392 -x’) and other options upon function entry and exit.
14393
14394 It is not portable to pass temporary environment variables to shell
14395 functions. Solaris 10 ‘/bin/sh’ does not see the variable. Meanwhile,
14396 not all shells follow the POSIX rule that the assignment must affect the
14397 current environment in the same manner as special built-ins.
14398
14399 $ /bin/sh -c 'func() { echo $a;}; a=1 func; echo $a'
14400 ⇒
14401 ⇒
14402 $ ash -c 'func() { echo $a;}; a=1 func; echo $a'
14403 ⇒1
14404 ⇒
14405 $ bash -c 'set -o posix; func() { echo $a;}; a=1 func; echo $a'
14406 ⇒1
14407 ⇒1
14408
14409 Some ancient Bourne shell variants with function support did not
14410 reset ‘$I, I >= 0’, upon function exit, so effectively the arguments of
14411 the script were lost after the first function invocation. It is
14412 probably not worth worrying about these shells any more.
14413
14414 With AIX sh, a ‘trap’ on 0 installed in a shell function triggers at
14415 function exit rather than at script exit. *Note Limitations of Shell
14416 Builtins: trap.
14417
14418 
14419 File: autoconf.info, Node: Limitations of Builtins, Next: Limitations of Usual Tools, Prev: Shell Functions, Up: Portable Shell
14420
14421 11.14 Limitations of Shell Builtins
14422 ===================================
14423
14424 No, no, we are serious: some shells do have limitations! :)
14425
14426 You should always keep in mind that any builtin or command may
14427 support options, and therefore differ in behavior with arguments
14428 starting with a dash. For instance, even the innocent ‘echo "$word"’
14429 can give unexpected results when ‘word’ starts with a dash. To avoid
14430 this problem, use ‘printf '%s\n' "$word"’. Many of these limitations
14431 can be worked around using M4sh (*note Programming in M4sh::).
14432
14433 ‘.’
14434 Use ‘.’ only with regular files (use ‘test -f’). Bash 2.03, for
14435 instance, chokes on ‘. /dev/null’. Remember that ‘.’ uses ‘PATH’
14436 if its argument contains no slashes. Also, some shells, including
14437 bash 3.2, implicitly append the current directory to this ‘PATH’
14438 search, even though POSIX forbids it. So if you want to use ‘.’ on
14439 a file ‘foo’ in the current directory, you must use ‘. ./foo’.
14440
14441 Not all shells gracefully handle syntax errors within a sourced
14442 file. On one extreme, some non-interactive shells abort the entire
14443 script. On the other, ‘zsh’ 4.3.10 has a bug where it fails to
14444 react to the syntax error.
14445
14446 $ echo 'fi' > syntax
14447 $ bash -c '. ./syntax; echo $?'
14448 ./syntax: line 1: syntax error near unexpected token `fi'
14449 ./syntax: line 1: `fi'
14450 2
14451 $ ash -c '. ./syntax; echo $?'
14452 ./syntax: 1: Syntax error: "fi" unexpected
14453 $ zsh -c '. ./syntax; echo $?'
14454 ./syntax:1: parse error near `fi'
14455 0
14456
14457 ‘!’
14458 The Unix version 7 shell did not support negating the exit status
14459 of commands with ‘!’, and this feature is still absent from some
14460 shells (e.g., Solaris 10 ‘/bin/sh’). Other shells, such as FreeBSD
14461 ‘/bin/sh’ or ‘ash’, have bugs when using ‘!’:
14462
14463 $ sh -c '! : | :'; echo $?
14464 1
14465 $ ash -c '! : | :'; echo $?
14466 0
14467 $ sh -c '! { :; }'; echo $?
14468 1
14469 $ ash -c '! { :; }'; echo $?
14470 {: not found
14471 Syntax error: "}" unexpected
14472 2
14473
14474 Shell code like this:
14475
14476 if ! cmp file1 file2 >/dev/null 2>&1; then
14477 echo files differ or trouble
14478 fi
14479
14480 is therefore not portable in practice. Typically it is easy to
14481 rewrite such code, e.g.:
14482
14483 cmp file1 file2 >/dev/null 2>&1 ||
14484 echo files differ or trouble
14485
14486 In M4sh, the ‘AS_IF’ macro provides an easy way to write these
14487 kinds of conditionals:
14488
14489 AS_IF([cmp -s file file.new], [],
14490 [echo files differ or trouble])
14491
14492 This kind of rewriting is needed in code outside macro definitions
14493 that calls other macros. *Note Common Shell Constructs::. It is
14494 also useful inside macro definitions, where the “then” and “else”
14495 branches might contain macro arguments.
14496
14497 More generally, one can always rewrite ‘! COMMAND’ as:
14498
14499 AS_IF([COMMAND], [(exit 1)])
14500
14501 ‘&&’ and ‘||’
14502 If an AND-OR list is not inside ‘AC_DEFUN’, and it contains calls
14503 to Autoconf macros, it should be rewritten using ‘AS_IF’. *Note
14504 Common Shell Constructs::. The operators ‘&&’ and ‘||’ have equal
14505 precedence and are left associative, so instead of:
14506
14507 # This is dangerous outside AC_DEFUN.
14508 cmp a b >/dev/null 2>&1 &&
14509 AS_ECHO([files are same]) >$tmpfile ||
14510 AC_MSG_NOTICE([files differ, or echo failed])
14511
14512 you can use:
14513
14514 # This is OK outside AC_DEFUN.
14515 AS_IF([AS_IF([cmp a b >/dev/null 2>&1],
14516 [AS_ECHO([files are same]) >$tmpfile],
14517 [false])],
14518 [AC_MSG_NOTICE([files differ, or echo failed])])
14519
14520 ‘{...}’
14521 Bash 3.2 (and earlier versions) sometimes does not properly set
14522 ‘$?’ when failing to write redirected output of a compound command.
14523 This problem is most commonly observed with ‘{...}’; it does not
14524 occur with ‘(...)’. For example:
14525
14526 $ bash -c '{ echo foo; } >/bad; echo $?'
14527 bash: line 1: /bad: Permission denied
14528 0
14529 $ bash -c 'while :; do echo; done >/bad; echo $?'
14530 bash: line 1: /bad: Permission denied
14531 0
14532
14533 To work around the bug, prepend ‘:;’:
14534
14535 $ bash -c ':;{ echo foo; } >/bad; echo $?'
14536 bash: line 1: /bad: Permission denied
14537 1
14538
14539 POSIX requires a syntax error if a brace list has no contents.
14540 However, not all shells obey this rule; and on shells where empty
14541 lists are permitted, the effect on ‘$?’ is inconsistent. To avoid
14542 problems, ensure that a brace list is never empty.
14543
14544 $ bash -c 'false; { }; echo $?' || echo $?
14545 bash: line 1: syntax error near unexpected token `}'
14546 bash: line 1: `false; { }; echo $?'
14547 2
14548 $ zsh -c 'false; { }; echo $?' || echo $?
14549 1
14550 $ pdksh -c 'false; { }; echo $?' || echo $?
14551 0
14552
14553 ‘break’
14554 The use of ‘break 2’ etc. is safe.
14555
14556 ‘case’
14557 If a ‘case’ command is not inside ‘AC_DEFUN’, and it contains calls
14558 to Autoconf macros, it should be rewritten using ‘AS_CASE’. *Note
14559 Common Shell Constructs::. Instead of:
14560
14561 # This is dangerous outside AC_DEFUN.
14562 case $filename in
14563 *.[ch]) AC_MSG_NOTICE([C source file]);;
14564 esac
14565
14566 use:
14567
14568 # This is OK outside AC_DEFUN.
14569 AS_CASE([$filename],
14570 [[*.[ch]]], [AC_MSG_NOTICE([C source file])])
14571
14572 You don’t need to quote the argument; no splitting is performed.
14573
14574 You don’t need the final ‘;;’, but you should use it.
14575
14576 POSIX requires support for ‘case’ patterns with opening parentheses
14577 like this:
14578
14579 case $file_name in
14580 (*.c) echo "C source code";;
14581 esac
14582
14583 but the ‘(’ in this example is not portable to a few obsolescent
14584 Bourne shell implementations, which is a pity for those of us using
14585 tools that rely on balanced parentheses. For instance, with
14586 Solaris 10 ‘/bin/sh’:
14587
14588 $ case foo in (foo) echo foo;; esac
14589 error→syntax error: `(' unexpected
14590
14591 The leading ‘(’ can be omitted safely. Unfortunately, there are
14592 contexts where unbalanced parentheses cause other problems, such as
14593 when using a syntax-highlighting editor that searches for the
14594 balancing counterpart, or more importantly, when using a case
14595 statement as an underquoted argument to an Autoconf macro. *Note
14596 Balancing Parentheses::, for trade-offs involved in various styles
14597 of dealing with unbalanced ‘)’.
14598
14599 Zsh handles pattern fragments derived from parameter expansions or
14600 command substitutions as though quoted:
14601
14602 $ pat=\?; case aa in ?$pat) echo match;; esac
14603 $ pat=\?; case a? in ?$pat) echo match;; esac
14604 match
14605
14606 Because of a bug in its ‘fnmatch’, Bash fails to properly handle
14607 backslashes in character classes:
14608
14609 bash-2.02$ case /tmp in [/\\]*) echo OK;; esac
14610 bash-2.02$
14611
14612 This is extremely unfortunate, since you are likely to use this
14613 code to handle POSIX or MS-DOS absolute file names. To work around
14614 this bug, always put the backslash first:
14615
14616 bash-2.02$ case '\TMP' in [\\/]*) echo OK;; esac
14617 OK
14618 bash-2.02$ case /tmp in [\\/]*) echo OK;; esac
14619 OK
14620
14621 Many Bourne shells cannot handle closing brackets in character
14622 classes correctly.
14623
14624 Some shells also have problems with backslash escaping in case you
14625 do not want to match the backslash: both a backslash and the
14626 escaped character match this pattern. To work around this, specify
14627 the character class in a variable, so that quote removal does not
14628 apply afterwards, and the special characters don’t have to be
14629 backslash-escaped:
14630
14631 $ case '\' in [\<]) echo OK;; esac
14632 OK
14633 $ scanset='[<]'; case '\' in $scanset) echo OK;; esac
14634 $
14635
14636 Even with this, Solaris ‘ksh’ matches a backslash if the set
14637 contains any of the characters ‘|’, ‘&’, ‘(’, or ‘)’.
14638
14639 Some shells, such as Ash 0.3.8, are confused by an empty
14640 ‘case’/‘esac’:
14641
14642 ash-0.3.8 $ case foo in esac;
14643 error→Syntax error: ";" unexpected (expecting ")")
14644
14645 POSIX requires ‘case’ to give an exit status of 0 if no cases
14646 match. However, ‘/bin/sh’ in Solaris 10 does not obey this rule.
14647 Meanwhile, it is unclear whether a case that matches, but contains
14648 no statements, must also change the exit status to 0. The M4sh
14649 macro ‘AS_CASE’ works around these inconsistencies.
14650
14651 $ bash -c 'case `false` in ?) ;; esac; echo $?'
14652 0
14653 $ /bin/sh -c 'case `false` in ?) ;; esac; echo $?'
14654 255
14655
14656 ‘cd’
14657 POSIX requires that ‘cd’ must support the ‘-L’ (“logical”) and ‘-P’
14658 (“physical”) options, with ‘-L’ being the default. However,
14659 traditional shells do not support these options, and their ‘cd’
14660 command has the ‘-P’ behavior.
14661
14662 Portable scripts should assume neither option is supported, and
14663 should assume neither behavior is the default. This can be a bit
14664 tricky, since the POSIX default behavior means that, for example,
14665 ‘ls ..’ and ‘cd ..’ may refer to different directories if the
14666 current logical directory is a symbolic link. It is safe to use
14667 ‘cd DIR’ if DIR contains no ‘..’ components. Also,
14668 Autoconf-generated scripts check for this problem when computing
14669 variables like ‘ac_top_srcdir’ (*note Configuration Actions::), so
14670 it is safe to ‘cd’ to these variables.
14671
14672 POSIX specifies an ‘-e’ option that affects the exit status when
14673 the ‘-P’ option is in effect. Portable scripts should avoid it for
14674 the same reason they avoid ‘-P’.
14675
14676 POSIX says that a successful ‘cd’ updates the values of the
14677 ‘OLDPWD’ and ‘PWD’ variables, and that ‘cd -’ acts like ‘cd
14678 "$OLDPWD"’. Older shells, such as Solaris 10 ‘/bin/sh’, do not
14679 support this and portable scripts should not rely on it.
14680
14681 If ‘HOME’ is unset or empty, the behavior of ‘cd’ with no arguments
14682 is implementation-defined, so portable scripts should avoid it in
14683 that case.
14684
14685 POSIX 1003.1-2024 states that ‘cd’ must fail if given an explicit
14686 empty argument. However, earlier POSIX editions did not specify
14687 the behavior and some shells do nothing, some change to the first
14688 entry in ‘CDPATH’, some change to ‘HOME’, and some exit the shell
14689 rather than returning an error. Unfortunately, this means that if
14690 ‘$var’ is empty, then ‘cd "$var"’ is less predictable than ‘cd
14691 $var’ (at least the latter is well-behaved in all shells at
14692 changing to ‘HOME’, although this is probably not what you wanted
14693 in a script). You should check that a directory name was supplied
14694 before trying to change locations.
14695
14696 If ‘cd’ fails, POSIX requires the invoking shell to behave as if
14697 ‘cd’ exited with status 1, which means the invoking shell can
14698 continue. However, Solaris 10 ‘/bin/sh’ aborts the containing
14699 command if interactive, and exits otherwise.
14700
14701 *Note Special Shell Variables::, for portability problems involving
14702 ‘cd’ and the ‘CDPATH’ environment variable. Also please see the
14703 discussion of the ‘pwd’ command.
14704
14705 ‘echo’
14706 The simple ‘echo’ is probably the most surprising source of
14707 portability troubles. It is not possible to use ‘echo’ portably
14708 unless both options and escape sequences are omitted.
14709
14710 Do not use options, as some shells support them and others do not.
14711 For example, POSIX says that the behavior of ‘echo -n foo’ is
14712 implementation-defined. On some platforms the output is ‘foo’
14713 without a trailing newline, on others it is ‘-n foo’ with a
14714 trailing newline, and POSIX allows even other behavior.
14715
14716 Do not use backslashes in the arguments, as there is no consensus
14717 on their handling. For ‘echo '\n' | wc -l’, the ‘sh’ of Solaris 10
14718 outputs 2, but Bash and Zsh (in ‘sh’ emulation mode) output 1. The
14719 problem is truly ‘echo’: all the shells understand ‘'\n'’ as the
14720 string composed of a backslash and an ‘n’.
14721
14722 Because of these problems, do not pass a string containing
14723 arbitrary characters to ‘echo’. For example, ‘echo "$foo"’ is safe
14724 only if you know that FOO’s value cannot contain backslashes and
14725 cannot start with ‘-’.
14726
14727 Normally, ‘printf’ is safer and easier to use than ‘echo’ and ‘echo
14728 -n’. Thus, you should use ‘printf '%s\n'’ instead of ‘echo’, and
14729 similarly use ‘printf %s’ instead of ‘echo -n’.
14730
14731 Older scripts, written before ‘printf’ was portable, sometimes used
14732 a here-document as a safer alternative to ‘echo’, like this:
14733
14734 cat <<EOF
14735 $foo
14736 EOF
14737
14738 However, this usage is problematic, as even some modern shells have
14739 hard-to-reproduce bugs when dealing with here-documents.
14740
14741 ‘eval’
14742 The ‘eval’ command is useful in limited circumstances, e.g., using
14743 commands like ‘eval table_$key=\$value’ and ‘eval value=table_$key’
14744 to simulate a hash table when the key is known to be alphanumeric.
14745
14746 You should also be wary of common bugs in ‘eval’ implementations.
14747 In some shell implementations (e.g., older ‘ash’, OpenBSD 3.8 ‘sh’,
14748 ‘pdksh’ v5.2.14 99/07/13.2, and ‘zsh’ 4.2.5), the arguments of
14749 ‘eval’ are evaluated in a context where ‘$?’ is 0, so they exhibit
14750 behavior like this:
14751
14752 $ false; eval 'echo $?'
14753 0
14754
14755 The correct behavior here is to output a nonzero value, but
14756 portable scripts should not rely on this.
14757
14758 You should not rely on ‘LINENO’ within ‘eval’. *Note Special Shell
14759 Variables::.
14760
14761 Note that, even though these bugs are easily avoided, ‘eval’ is
14762 tricky to use on arbitrary arguments. It is obviously unwise to
14763 use ‘eval $cmd’ if the string value of ‘cmd’ was derived from an
14764 untrustworthy source. But even if the string value is valid, ‘eval
14765 $cmd’ might not work as intended, since it causes field splitting
14766 and file name expansion to occur twice, once for the ‘eval’ and
14767 once for the command itself. It is therefore safer to use ‘eval
14768 "$cmd"’. For example, if CMD has the value ‘cat test?.c’, ‘eval
14769 $cmd’ might expand to the equivalent of ‘cat test;.c’ if there
14770 happens to be a file named ‘test;.c’ in the current directory; and
14771 this in turn mistakenly attempts to invoke ‘cat’ on the file ‘test’
14772 and then execute the command ‘.c’. To avoid this problem, use
14773 ‘eval "$cmd"’ rather than ‘eval $cmd’.
14774
14775 However, suppose that you want to output the text of the evaluated
14776 command just before executing it. Assuming the previous example,
14777 ‘printf '%s\n' "Executing: $cmd"’ outputs ‘Executing: cat test?.c’,
14778 but this output doesn’t show the user that ‘test;.c’ is the actual
14779 name of the copied file. Conversely, ‘printf 'Executing:'; eval
14780 "printf ' %s' $cmd"; printf '\n'’ works on this example, but it
14781 fails with ‘cmd='cat foo >bar'’, since it mistakenly replaces the
14782 contents of ‘bar’ by the string ‘ cat foo’. No simple, general,
14783 and portable solution to this problem is known.
14784
14785 ‘exec’
14786 POSIX describes several categories of shell built-ins. Special
14787 built-ins (such as ‘exit’) must impact the environment of the
14788 current shell, and need not be available through ‘exec’. All other
14789 built-ins are regular, and must not propagate variable assignments
14790 to the environment of the current shell. However, the group of
14791 regular built-ins is further distinguished by commands that do not
14792 require a ‘PATH’ search (such as ‘cd’), in contrast to built-ins
14793 that are offered as a more efficient version of something that must
14794 still be found in a ‘PATH’ search (such as ‘echo’). POSIX is not
14795 clear on whether ‘exec’ must work with the list of 17 utilities
14796 that are invoked without a ‘PATH’ search, and many platforms lack
14797 an executable for some of those built-ins:
14798
14799 $ sh -c 'exec cd /tmp'
14800 sh: line 0: exec: cd: not found
14801
14802 All other built-ins that provide utilities specified by POSIX must
14803 have a counterpart executable that exists on ‘PATH’, although POSIX
14804 allows ‘exec’ to use the built-in instead of the executable. For
14805 example, contrast ‘bash’ 3.2 and ‘pdksh’ 5.2.14:
14806
14807 $ bash -c 'pwd --version' | head -n1
14808 bash: line 0: pwd: --: invalid option
14809 pwd: usage: pwd [-LP]
14810 $ bash -c 'exec pwd --version' | head -n1
14811 pwd (GNU coreutils) 6.10
14812 $ pdksh -c 'exec pwd --version' | head -n1
14813 pdksh: pwd: --: unknown option
14814
14815 When it is desired to avoid a regular shell built-in, the
14816 workaround is to use some other forwarding command, such as ‘env’
14817 or ‘nice’, that will ensure a path search:
14818
14819 $ pdksh -c 'exec true --version' | head -n1
14820 $ pdksh -c 'nice true --version' | head -n1
14821 true (GNU coreutils) 6.10
14822 $ pdksh -c 'env true --version' | head -n1
14823 true (GNU coreutils) 6.10
14824
14825 ‘exit’
14826 The default value of ‘exit’ is supposed to be ‘$?’; unfortunately,
14827 some shells, such as the DJGPP port of Bash 2.04, just perform
14828 ‘exit 0’.
14829
14830 bash-2.04$ foo=`exit 1` || echo fail
14831 fail
14832 bash-2.04$ foo=`(exit 1)` || echo fail
14833 fail
14834 bash-2.04$ foo=`(exit 1); exit` || echo fail
14835 bash-2.04$
14836
14837 Using ‘exit $?’ restores the expected behavior.
14838
14839 Some shell scripts, such as those generated by ‘autoconf’, use a
14840 trap to clean up before exiting. If the last shell command exited
14841 with nonzero status, the trap also exits with nonzero status so
14842 that the invoker can tell that an error occurred.
14843
14844 Unfortunately, in some shells, such as Solaris 10 ‘/bin/sh’, an
14845 exit trap ignores the ‘exit’ command’s argument. In these shells,
14846 a trap cannot determine whether it was invoked by plain ‘exit’ or
14847 by ‘exit 1’. Instead of calling ‘exit’ directly, use the
14848 ‘AC_MSG_ERROR’ macro that has a workaround for this problem.
14849
14850 ‘export’
14851 The builtin ‘export’ dubs a shell variable “environment variable”.
14852 Each update of exported variables corresponds to an update of the
14853 environment variables. Conversely, each environment variable
14854 received by the shell when it is launched should be imported as a
14855 shell variable marked as exported.
14856
14857 Alas, some older shells, such as Solaris 10 ‘/bin/sh’, forget to
14858 ‘export’ the environment variables they receive. As a result, two
14859 variables coexist: the environment variable and the shell variable.
14860 The following code demonstrates this failure:
14861
14862 #!/bin/sh
14863 echo $FOO
14864 FOO=bar
14865 echo $FOO
14866 exec /bin/sh $0
14867
14868 when run with ‘FOO=foo’ in the environment, these shells print
14869 alternately ‘foo’ and ‘bar’, although they should print only ‘foo’
14870 and then a sequence of ‘bar’s.
14871
14872 Therefore you should ‘export’ again each environment variable that
14873 you update; the export can occur before or after the assignment.
14874
14875 POSIX is not clear on whether the ‘export’ of an undefined variable
14876 causes the variable to be defined with the value of an empty
14877 string, or merely marks any future definition of a variable by that
14878 name for export. Various shells behave differently in this regard:
14879
14880 $ sh -c 'export foo; env | grep foo'
14881 $ ash -c 'export foo; env | grep foo'
14882 foo=
14883
14884 POSIX requires ‘export’ to honor assignments made as arguments, but
14885 older shells do not support this, including ‘/bin/sh’ in Solaris
14886 10. Portable scripts should separate assignments and exports into
14887 different statements.
14888
14889 $ bash -c 'export foo=bar; echo $foo'
14890 bar
14891 $ /bin/sh -c 'export foo=bar; echo $foo'
14892 /bin/sh: foo=bar: is not an identifier
14893 $ /bin/sh -c 'export foo; foo=bar; echo $foo'
14894 bar
14895
14896 POSIX requires ‘export’ to work with any arbitrary value for the
14897 contents of the variable being exported, as long as the total size
14898 of the environment combined with arguments doesn’t exceed ‘ARG_MAX’
14899 when executing a child process. However, some shells have
14900 extensions that involve interpreting some environment values
14901 specially, regardless of the variable name. We currently know of
14902 one case: all versions of Bash released prior to 27 September 2014
14903 interpret an environment variable with an initial content substring
14904 of ‘() {’ as an exported function definition (this is the
14905 “Shellshock” remote execution bug, CVE-2014-6271 and friends, where
14906 it was possible to exploit the function parser to cause remote code
14907 execution on child bash startup; newer versions of Bash use special
14908 environment variable _names_ instead of values to implement the
14909 same feature).
14910
14911 There may be entries inherited into the environment that are not
14912 valid as shell variable names; POSIX states that processes should
14913 be tolerant of these names. Some shells such as ‘dash’ do this by
14914 removing those names from the environment at startup, while others
14915 such as ‘bash’ hide the entry from shell access but still pass it
14916 on to child processes. While you can set such names using ‘env’
14917 for a direct child process, you cannot rely on them being preserved
14918 through an intermediate pass through the shell.
14919
14920 ‘false’
14921 Don’t expect ‘false’ to exit with status 1: in native Solaris
14922 ‘/bin/false’ exits with status 255.
14923
14924 ‘for’
14925 To loop over positional arguments, use:
14926
14927 for arg
14928 do
14929 printf '%s\n' "$arg"
14930 done
14931
14932 You may _not_ leave the ‘do’ on the same line as ‘for’, since some
14933 shells improperly grok:
14934
14935 for arg; do
14936 printf '%s\n' "$arg"
14937 done
14938
14939 If you want to explicitly refer to the positional arguments, use:
14940
14941 for arg in "$@"; do
14942 printf '%s\n' "$arg"
14943 done
14944
14945 POSIX requires support for a ‘for’ loop with no list after ‘in’.
14946 However, Solaris 10 ‘/bin/sh’ treats that as a syntax error. It is
14947 possible to work around this by providing any shell word that
14948 expands to nothing, or by ignoring an obvious sentinel.
14949
14950 $ /bin/sh -c 'for a in $empty; do echo hi; done'
14951 $ /bin/sh -c 'for a in ; do echo hi; done'
14952 /bin/sh: syntax error at line 1: `;' unexpected
14953
14954 This syntax problem is most frequently encountered in code that
14955 goes through several layers of expansion, such as an m4 macro or
14956 makefile variable used as a list body, where the first layer of
14957 expansion (m4 or make) can end up expanding to nothing in the
14958 version handed to the shell. In the makefile context, one common
14959 workaround is to use a shell variable rather than a make variable
14960 as the source of the list.
14961
14962 $ cat Makefile
14963 list =
14964 bad:
14965 @for arg in $(list); do \
14966 printf '%s\n' $$arg; \
14967 done
14968 good:
14969 @list='$(list)'; \
14970 for arg in $$list; do \
14971 printf '%s\n' $$arg; \
14972 done
14973 $ make bad 2&>1 | head -n1
14974 sh: syntax error at line 1: `;' unexpected
14975 $ make bad list='a b'
14976 a
14977 b
14978 $ make good
14979 $ make good list='a b'
14980 a
14981 b
14982
14983 In Solaris 10 ‘/bin/sh’, when the list of arguments of a ‘for’ loop
14984 starts with _unquoted_ tokens looking like variable assignments,
14985 the loop is not executed on those tokens:
14986
14987 $ /bin/sh -c 'for v in a=b c=d x e=f; do echo $v; done'
14988 x
14989 e=f
14990
14991 Thankfully, quoting the assignment-like tokens, or starting the
14992 list with other tokens (including unquoted variable expansion that
14993 results in an assignment-like result), avoids the problem, so it is
14994 easy to work around:
14995
14996 $ /bin/sh -c 'for v in "a=b"; do echo $v; done'
14997 a=b
14998 $ /bin/sh -c 'x=a=b; for v in $x c=d; do echo $v; done'
14999 a=b
15000 c=d
15001
15002 ‘if’
15003 If an ‘if’ command is not inside ‘AC_DEFUN’, and it contains calls
15004 to Autoconf macros, it should be rewritten using ‘AS_IF’. *Note
15005 Common Shell Constructs::.
15006
15007 Using ‘if ! ...’ is not portable. *Note ‘!’ notes: !.
15008
15009 Some very old shells did not reset the exit status from an ‘if’
15010 with no ‘else’:
15011
15012 $ if (exit 42); then true; fi; echo $?
15013 42
15014
15015 whereas a proper shell should have printed ‘0’. Although this is
15016 no longer a portability problem, as any shell that supports
15017 functions gets it correct, it explains why some makefiles have
15018 lengthy constructs:
15019
15020 if test -f "$file"; then
15021 install "$file" "$dest"
15022 else
15023 :
15024 fi
15025
15026 ‘printf’
15027 A format string starting with a ‘-’ can cause problems. Bash
15028 interprets it as an option and gives an error. And ‘--’ to mark
15029 the end of options is not good in the NetBSD Almquist shell (e.g.,
15030 0.4.6) which takes that literally as the format string. Putting
15031 the ‘-’ in a ‘%c’ or ‘%s’ is probably easiest:
15032
15033 printf %s -foo
15034
15035 AIX 7.2 ‘sh’ mishandles octal escapes in multi-byte locales by
15036 treating them as characters instead of bytes. For example, in a
15037 locale using the UTF-8 encoding, ‘printf '\351'’ outputs the two
15038 bytes C3, A9 (the UTF-8 encoding for U+00E9) instead of the desired
15039 single byte E9. To work around the bug, use the C locale.
15040
15041 Bash 2.03 mishandles an escape sequence that happens to evaluate to
15042 ‘%’:
15043
15044 $ printf '\045'
15045 bash: printf: `%': missing format character
15046
15047 Large outputs may cause trouble. On Solaris 10, for example,
15048 ‘/usr/bin/printf’ is buggy, so when using ‘/bin/sh’ the command
15049 ‘printf %010000x 123’ normally dumps core.
15050
15051 Since ‘printf’ is not always a shell builtin, there is a potential
15052 speed penalty for using ‘printf '%s\n'’ as a replacement for an
15053 ‘echo’ that does not interpret ‘\’ or leading ‘-’. With Solaris
15054 ‘ksh’, it is possible to use ‘print -r --’ for this role instead.
15055
15056 *Note Limitations of Shell Builtins: echo, for a discussion of
15057 portable alternatives to both ‘printf’ and ‘echo’.
15058
15059 ‘pwd’
15060 With modern shells, plain ‘pwd’ outputs a “logical” directory name,
15061 some of whose components may be symbolic links. These directory
15062 names are in contrast to “physical” directory names, whose
15063 components are all directories.
15064
15065 POSIX requires that ‘pwd’ must support the ‘-L’ (“logical”) and
15066 ‘-P’ (“physical”) options, with ‘-L’ being the default. However,
15067 traditional shells do not support these options, and their ‘pwd’
15068 command has the ‘-P’ behavior.
15069
15070 Portable scripts should assume neither option is supported, and
15071 should assume neither behavior is the default. Also, on many hosts
15072 ‘/bin/pwd’ is equivalent to ‘pwd -P’, but POSIX does not require
15073 this behavior and portable scripts should not rely on it.
15074
15075 Typically it’s best to use plain ‘pwd’. On modern hosts this
15076 outputs logical directory names, which have the following
15077 advantages:
15078
15079 • Logical names are what the user specified.
15080 • Physical names may not be portable from one installation host
15081 to another due to network file system gymnastics.
15082 • On modern hosts ‘pwd -P’ may fail due to lack of permissions
15083 to some parent directory, but plain ‘pwd’ cannot fail for this
15084 reason.
15085
15086 Also please see the discussion of the ‘cd’ command.
15087
15088 ‘read’
15089 No options are portable, not even support ‘-r’ (Solaris 10
15090 ‘/bin/sh’ for example).
15091
15092 ‘set’
15093 With the FreeBSD 6.0 shell, the ‘set’ command (without any options)
15094 does not sort its output.
15095
15096 The ‘set’ builtin faces the usual problem with arguments starting
15097 with a dash. Modern shells understand ‘--’ to specify the end of
15098 the options (any argument after ‘--’ is a parameter, even ‘-x’ for
15099 instance), but some ancient shells stop option processing only
15100 after a non-option argument is found. Therefore, use ‘dummy’ or
15101 simply ‘x’ to end the option processing, and use ‘shift’ to pop it
15102 out:
15103
15104 set x $my_list; shift
15105
15106 Avoid ‘set -’, e.g., ‘set - $my_list’. POSIX no longer requires
15107 support for this command, and in traditional shells ‘set -
15108 $my_list’ resets the ‘-v’ and ‘-x’ options, which makes scripts
15109 harder to debug.
15110
15111 Some nonstandard shells do not recognize more than one option
15112 (e.g., ‘set -e -x’ assigns ‘-x’ to the command line). It is better
15113 to combine them:
15114
15115 set -ex
15116
15117 The ‘-e’ option has historically been under-specified, with enough
15118 ambiguities to cause numerous differences across various shell
15119 implementations; see for example this overview
15120 (https://www.in-ulm.de/~mascheck/various/set-e/), or this link
15121 (https://www.austingroupbugs.net/view.php?id=52), documenting a
15122 change to POSIX 2008 to match ‘ksh88’ behavior. Note that mixing
15123 ‘set -e’ and shell functions is asking for surprises:
15124
15125 set -e
15126 doit()
15127 {
15128 rm file
15129 echo one
15130 }
15131 doit || echo two
15132
15133 According to the recommendation, ‘one’ should always be output
15134 regardless of whether the ‘rm’ failed, because it occurs within the
15135 body of the shell function ‘doit’ invoked on the left side of ‘||’,
15136 where the effects of ‘set -e’ are not enforced. Likewise, ‘two’
15137 should never be printed, since the failure of ‘rm’ does not abort
15138 the function, such that the status of ‘doit’ is 0.
15139
15140 The BSD shell has had several problems with the ‘-e’ option. Older
15141 versions of the BSD shell (circa 1990) mishandled ‘&&’, ‘||’, ‘if’,
15142 and ‘case’ when ‘-e’ was in effect, causing the shell to exit
15143 unexpectedly in some cases. This was particularly a problem with
15144 makefiles, and led to circumlocutions like ‘sh -c 'test -f file ||
15145 touch file'’, where the seemingly-unnecessary ‘sh -c '...'’ wrapper
15146 works around the bug (*note Failure in Make Rules::).
15147
15148 Even relatively-recent versions of the BSD shell (e.g., OpenBSD
15149 3.4) wrongly exit with ‘-e’ if the last command within a compound
15150 statement fails and is guarded by an ‘&&’ only. For example:
15151
15152 #! /bin/sh
15153 set -e
15154 foo=''
15155 test -n "$foo" && exit 1
15156 echo one
15157 if :; then
15158 test -n "$foo" && exit 1
15159 echo two
15160 test -n "$foo" && exit 1
15161 fi
15162 echo three
15163
15164 does not print ‘three’. One workaround is to change the last
15165 instance of ‘test -n "$foo" && exit 1’ to be ‘if test -n "$foo";
15166 then exit 1; fi’ instead. Another possibility is to warn BSD users
15167 not to use ‘sh -e’.
15168
15169 When ‘set -e’ is in effect, a failed command substitution in
15170 Solaris 10 ‘/bin/sh’ cannot be ignored, even with ‘||’.
15171
15172 $ /bin/sh -c 'set -e; foo=`false` || echo foo; echo bar'
15173 $ bash -c 'set -e; foo=`false` || echo foo; echo bar'
15174 foo
15175 bar
15176
15177 Moreover, a command substitution, successful or not, causes this
15178 shell to exit from a failing outer command even in presence of an
15179 ‘&&’ list:
15180
15181 $ bash -c 'set -e; false `true` && echo notreached; echo ok'
15182 ok
15183 $ sh -c 'set -e; false `true` && echo notreached; echo ok'
15184 $
15185
15186 Job control is not provided by all shells, so the use of ‘set -m’
15187 or ‘set -b’ must be done with care. When using ‘zsh’ in native
15188 mode, asynchronous notification (‘set -b’) is enabled by default,
15189 and using ‘emulate sh’ to switch to POSIX mode does not clear this
15190 setting (although asynchronous notification has no impact unless
15191 job monitoring is also enabled). Also, ‘zsh’ 4.3.10 and earlier
15192 have a bug where job control can be manipulated in interactive
15193 shells, but not in subshells or scripts. Furthermore, some shells,
15194 like ‘pdksh’, fail to treat subshells as interactive, even though
15195 the parent shell was.
15196
15197 $ echo $ZSH_VERSION
15198 4.3.10
15199 $ set -m; echo $?
15200 0
15201 $ zsh -c 'set -m; echo $?'
15202 set: can't change option: -m
15203 $ (set -m); echo $?
15204 set: can't change option: -m
15205 1
15206 $ pdksh -ci 'echo $-; (echo $-)'
15207 cim
15208 c
15209
15210 Use of ‘set -n’ (typically via ‘sh -n script’) to validate a script
15211 is not foolproof. Modern ‘ksh93’ tries to be helpful by informing
15212 you about better syntax, but switching the script to use the
15213 suggested syntax in order to silence the warnings would render the
15214 script no longer portable to older shells:
15215
15216 $ ksh -nc '``'
15217 ksh: warning: line 1: `...` obsolete, use $(...)
15218 0
15219
15220 Autoconf itself uses ‘sh -n’ within its testsuite to check that
15221 correct scripts were generated, but only after first probing for
15222 other shell features (such as ‘test ${BASH_VERSION+y}’) that
15223 indicate a reasonably fast and working implementation.
15224
15225 ‘shift’
15226 Not only is ‘shift’ing a bad idea when there is nothing left to
15227 shift, but in addition it is not portable: the shell of MIPS
15228 RISC/OS 4.52 refuses to do it.
15229
15230 Don’t use ‘shift 2’ etc.; while it in the SVR1 shell (1983), it is
15231 also absent in many pre-POSIX shells.
15232
15233 ‘source’
15234 This command is not portable, as POSIX does not require it; use ‘.’
15235 instead.
15236
15237 ‘test’
15238 The ‘test’ program is the way to perform many file and string
15239 tests. It is often invoked by the alternate name ‘[’, but using
15240 that name in Autoconf code is asking for trouble since it is an M4
15241 quote character.
15242
15243 The ‘-a’, ‘-o’, ‘(’, and ‘)’ operands are not present in all
15244 implementations, and have been marked obsolete by POSIX 2008. This
15245 is because there are inherent ambiguities in using them. For
15246 example, ‘test "$1" -a "$2"’ looks like a binary operator to check
15247 whether two strings are both non-empty, but if ‘$1’ is the literal
15248 ‘!’, then some implementations of ‘test’ treat it as a negation of
15249 the unary operator ‘-a’.
15250
15251 Thus, portable uses of ‘test’ should never have more than four
15252 arguments, and scripts should use shell constructs like ‘&&’ and
15253 ‘||’ instead. If you combine ‘&&’ and ‘||’ in the same statement,
15254 keep in mind that they have equal precedence, so it is often better
15255 to parenthesize even when this is redundant. For example:
15256
15257 # Not portable:
15258 test "X$a" = "X$b" -a \
15259 '(' "X$c" != "X$d" -o "X$e" = "X$f" ')'
15260
15261 # Portable:
15262 test "X$a" = "X$b" &&
15263 { test "X$c" != "X$d" || test "X$e" = "X$f"; }
15264
15265 ‘test’ does not process options like most other commands do; for
15266 example, it does not recognize the ‘--’ argument as marking the end
15267 of options.
15268
15269 It is safe to use ‘!’ as a ‘test’ operator. For example, ‘if test
15270 ! -d foo; ...’ is portable even though ‘if ! test -d foo; ...’ is
15271 not.
15272
15273 ‘test’ (files)
15274 To enable ‘configure’ scripts to support cross-compilation, they
15275 shouldn’t do anything that tests features of the build system
15276 instead of the host system. But occasionally you may find it
15277 necessary to check whether some arbitrary file exists. To do so,
15278 use ‘test -f’, ‘test -r’, or ‘test -x’. Do not use ‘test -e’,
15279 because Solaris 10 ‘/bin/sh’ lacks it.
15280
15281 To test for symbolic links on systems that have them, use ‘test -h’
15282 rather than ‘test -L’; either form conforms to POSIX, but ‘-h’ has
15283 been around longer.
15284
15285 The commands ‘test A -ot B’ and ‘test A -nt B’ are not reliable on
15286 macOS ‘sh’ through at least macOS Sequoia 15.1.1 (2024), where
15287 ‘test’ ignores the subsecond part of file timestamps. To work
15288 around this bug, arrange for the timestamps to be at least one
15289 second apart.
15290
15291 For historical reasons, POSIX reluctantly allows implementations of
15292 ‘test -x’ that will succeed for the root user, even if no execute
15293 permissions are present. Furthermore, shells do not all agree on
15294 whether Access Control Lists should affect ‘test -r’, ‘test -w’,
15295 and ‘test -x’; some shells base test results strictly on the
15296 current user id compared to file owner and mode, as if by
15297 ‘stat(2)’; while other shells base test results on whether the
15298 current user has the given right, even if that right is only
15299 granted by an ACL, as if by ‘faccessat(2)’. Furthermore, there is
15300 a classic time of check to time of use race between any use of
15301 ‘test’ followed by operating on the just-checked file. Therefore,
15302 it is a good idea to write scripts that actually attempt an
15303 operation, and are prepared for the resulting failure if permission
15304 is denied, rather than trying to avoid an operation based solely on
15305 whether ‘test’ guessed that it might not be permitted.
15306
15307 ‘test’ (strings)
15308 POSIX says that ‘test "STRING"’ succeeds if STRING is not null, but
15309 this usage is not portable to traditional platforms like Solaris 10
15310 ‘/bin/sh’, which mishandle strings like ‘!’ and ‘-n’. However, it
15311 _is_ portable to test if a variable is set to a non-empty value, by
15312 using ‘test ${var+y}’, since all known implementations properly
15313 distinguish between no arguments and a known-safe string of ‘y’.
15314
15315 POSIX also says that ‘test ! "STRING"’, ‘test -n "STRING"’ and
15316 ‘test -z "STRING"’ work with any string, but some shells (such as
15317 Solaris 10) get confused if STRING looks like an operator:
15318
15319 $ test -n =
15320 test: argument expected
15321 $ test ! -n
15322 test: argument expected
15323 $ test -z ")"; echo $?
15324 0
15325
15326 Similarly, POSIX says that both ‘test "STRING1" = "STRING2"’ and
15327 ‘test "STRING1" != "STRING2"’ work for any pairs of strings, but in
15328 practice this is not true for troublesome strings that look like
15329 operators or parentheses, or that begin with ‘-’.
15330
15331 It is best to protect such strings with a leading ‘X’, e.g., ‘test
15332 "XSTRING" != X’ rather than ‘test -n "STRING"’ or ‘test !
15333 "STRING"’.
15334
15335 It is common to find variations of the following idiom:
15336
15337 test -n "`echo $ac_feature | sed 's/[a-zA-Z0-9_-]//g'`" &&
15338 ACTION
15339
15340 to take an action when a token matches a given pattern. Such
15341 constructs should be avoided by using:
15342
15343 AS_CASE([$ac_feature],
15344 [[*[!-a-zA-Z0-9_]*]], [ACTION])
15345
15346 If the pattern is a complicated regular expression that cannot be
15347 expressed as a shell pattern, use something like this instead:
15348
15349 expr "X$ac_feature" : 'X.*[^-a-zA-Z0-9_]' >/dev/null &&
15350 ACTION
15351
15352 ‘expr "XFOO" : "XBAR"’ is more robust than ‘echo "XFOO" | grep
15353 "^XBAR"’, because it avoids problems when ‘FOO’ contains
15354 backslashes.
15355
15356 ‘trap’
15357 It is safe to trap at least the signals 1, 2, 13, and 15. You can
15358 also trap 0, i.e., have the ‘trap’ run when the script ends (either
15359 via an explicit ‘exit’, or the end of the script). The trap for 0
15360 should be installed outside of a shell function, or AIX 7.3
15361 ‘/bin/sh’ will invoke the trap at the end of this function.
15362
15363 POSIX says that ‘trap - 1 2 13 15’ resets the traps for the
15364 specified signals to their default values, but many common shells
15365 (e.g., Solaris 10 ‘/bin/sh’) misinterpret this and attempt to
15366 execute a “command” named ‘-’ when the specified conditions arise.
15367 POSIX 2008 also added a requirement to support ‘trap 1 2 13 15’ to
15368 reset traps, as this is supported by a larger set of shells, but
15369 there are still shells like ‘dash’ that mistakenly try to execute
15370 ‘1’ instead of resetting the traps. Therefore, there is no
15371 portable workaround, except for ‘trap - 0’, for which ‘trap '' 0’
15372 is a portable substitute.
15373
15374 Although POSIX is not absolutely clear on this point, it is widely
15375 admitted that when entering the trap ‘$?’ should be set to the exit
15376 status of the last command run before the trap. The ambiguity can
15377 be summarized as: “when the trap is launched by an ‘exit’, what is
15378 the _last_ command run: that before ‘exit’, or ‘exit’ itself?”
15379
15380 Bash considers ‘exit’ to be the last command, while Zsh and Solaris
15381 10 ‘/bin/sh’ consider that when the trap is run it is _still_ in
15382 the ‘exit’, hence it is the previous exit status that the trap
15383 receives:
15384
15385 $ cat trap.sh
15386 trap 'echo $?' 0
15387 (exit 42); exit 0
15388 $ zsh trap.sh
15389 42
15390 $ bash trap.sh
15391 0
15392
15393 The portable solution is then simple: when you want to ‘exit 42’,
15394 run ‘(exit 42); exit 42’, the first ‘exit’ being used to set the
15395 exit status to 42 for Zsh, and the second to trigger the trap and
15396 pass 42 as exit status for Bash. In M4sh, this is covered by using
15397 ‘AS_EXIT’.
15398
15399 The shell in FreeBSD 4.0 has the following bug: ‘$?’ is reset to 0
15400 by empty lines if the code is inside ‘trap’.
15401
15402 $ trap 'false
15403
15404 echo $?' 0
15405 $ exit
15406 0
15407
15408 Fortunately, this bug only affects ‘trap’.
15409
15410 Several shells fail to execute an exit trap that is defined inside
15411 a subshell, when the last command of that subshell is not a
15412 builtin. A workaround is to use ‘exit $?’ as the shell builtin.
15413
15414 $ bash -c '(trap "echo hi" 0; /bin/true)'
15415 hi
15416 $ /bin/sh -c '(trap "echo hi" 0; /bin/true)'
15417 $ /bin/sh -c '(trap "echo hi" 0; /bin/true; exit $?)'
15418 hi
15419
15420 Likewise, older implementations of ‘bash’ failed to preserve ‘$?’
15421 across an exit trap consisting of a single cleanup command.
15422
15423 $ bash -c 'trap "/bin/true" 0; exit 2'; echo $?
15424 2
15425 $ bash-2.05b -c 'trap "/bin/true" 0; exit 2'; echo $?
15426 0
15427 $ bash-2.05b -c 'trap ":; /bin/true" 0; exit 2'; echo $?
15428 2
15429
15430 Be aware that a trap can be called from any number of places in
15431 your script, and therefore the trap handler should not make
15432 assumptions about shell state. For some examples, if your script
15433 temporarily modifies ‘IFS’, then the trap should include an
15434 initialization back to its typical value of space-tab-newline
15435 (autoconf does this for generated ‘configure’ files). Likewise, if
15436 your script changes the current working directory at some point
15437 after the trap is installed, then your trap cannot assume which
15438 directory it is in, and should begin by changing directories to an
15439 absolute path if that is important to the cleanup efforts (autotest
15440 does this for generated ‘testsuite’ files).
15441
15442 ‘true’
15443 Don’t worry: as far as we know ‘true’ is portable. Nevertheless,
15444 it’s not always a builtin (e.g., Bash 1.x), and the portable shell
15445 community tends to prefer using ‘:’. This has a funny side effect:
15446 when asked whether ‘false’ is more portable than ‘true’ Alexandre
15447 Oliva answered:
15448
15449 In a sense, yes, because if it doesn’t exist, the shell will
15450 produce an exit status of failure, which is correct for
15451 ‘false’, but not for ‘true’.
15452
15453 Remember that even though ‘:’ ignores its arguments, it still takes
15454 time to compute those arguments. It is a good idea to use double
15455 quotes around any arguments to ‘:’ to avoid time spent in field
15456 splitting and file name expansion.
15457
15458 ‘unset’
15459 In some nonconforming shells (e.g., Solaris 10 ‘/bin/ksh’ and
15460 ‘/usr/xpg4/bin/sh’, NetBSD 5.99.43 sh, or Bash 2.05a), ‘unset FOO’
15461 fails when ‘FOO’ is not set. This can interfere with ‘set -e’
15462 operation. You can use
15463
15464 FOO=; unset FOO
15465
15466 if you are not sure that ‘FOO’ is set.
15467
15468 A few ancient shells lack ‘unset’ entirely. For some variables
15469 such as ‘PS1’, you can use a neutralizing value instead:
15470
15471 PS1='$ '
15472
15473 Usually, shells that do not support ‘unset’ need less effort to
15474 make the environment sane, so for example is not a problem if you
15475 cannot unset ‘CDPATH’ on those shells. However, Bash 2.01
15476 mishandles ‘unset MAIL’ and ‘unset MAILPATH’ in some cases and
15477 dumps core. So, you should do something like
15478
15479 ( (unset MAIL) || exit 1) >/dev/null 2>&1 && unset MAIL || :
15480
15481 *Note Special Shell Variables::, for some neutralizing values.
15482 Also, see *note Limitations of Builtins: export, for the case of
15483 environment variables.
15484
15485 ‘wait’
15486 The exit status of ‘wait’ is not always reliable.
15487
15488 
15489 File: autoconf.info, Node: Limitations of Usual Tools, Prev: Limitations of Builtins, Up: Portable Shell
15490
15491 11.15 Limitations of Usual Tools
15492 ================================
15493
15494 The small set of tools you can expect to find on any machine can still
15495 include some limitations you should be aware of.
15496
15497 ‘awk’
15498 Don’t leave white space before the opening parenthesis in a user
15499 function call. POSIX does not allow this and GNU Awk rejects it:
15500
15501 $ gawk 'function die () { print "Aaaaarg!" }
15502 BEGIN { die () }'
15503 gawk: cmd. line:2: BEGIN { die () }
15504 gawk: cmd. line:2: ^ parse error
15505 $ gawk 'function die () { print "Aaaaarg!" }
15506 BEGIN { die() }'
15507 Aaaaarg!
15508
15509 POSIX says that if a program contains only ‘BEGIN’ actions, and
15510 contains no instances of ‘getline’, then the program merely
15511 executes the actions without reading input. However, traditional
15512 Awk implementations (such as Solaris 10 ‘awk’) read and discard
15513 input in this case. Portable scripts can redirect input from
15514 ‘/dev/null’ to work around the problem. For example:
15515
15516 awk 'BEGIN {print "hello world"}' </dev/null
15517
15518 POSIX says that in an ‘END’ action, ‘$NF’ (and presumably, ‘$1’)
15519 retain their value from the last record read, if no intervening
15520 ‘getline’ occurred. However, some implementations (such as Solaris
15521 10 ‘/usr/bin/awk’, ‘nawk’, or Darwin ‘awk’) reset these variables.
15522 A workaround is to use an intermediate variable prior to the ‘END’
15523 block. For example:
15524
15525 $ cat end.awk
15526 { tmp = $1 }
15527 END { print "a", $1, $NF, "b", tmp }
15528 $ echo 1 | awk -f end.awk
15529 a b 1
15530 $ echo 1 | gawk -f end.awk
15531 a 1 1 b 1
15532
15533 If you want your program to be deterministic, don’t depend on ‘for’
15534 on arrays:
15535
15536 $ cat for.awk
15537 END {
15538 arr["foo"] = 1
15539 arr["bar"] = 1
15540 for (i in arr)
15541 print i
15542 }
15543 $ gawk -f for.awk </dev/null
15544 foo
15545 bar
15546 $ nawk -f for.awk </dev/null
15547 bar
15548 foo
15549
15550 Some Awk implementations, such as HP-UX 11.0’s native one,
15551 mishandle anchors:
15552
15553 $ echo xfoo | $AWK '/foo|^bar/ { print }'
15554 $ echo bar | $AWK '/foo|^bar/ { print }'
15555 bar
15556 $ echo xfoo | $AWK '/^bar|foo/ { print }'
15557 xfoo
15558 $ echo bar | $AWK '/^bar|foo/ { print }'
15559 bar
15560
15561 Either do not depend on such patterns (i.e., use ‘/^(.*foo|bar)/’,
15562 or use a simple test to reject such implementations.
15563
15564 On ‘ia64-hp-hpux11.23’, Awk mishandles ‘printf’ conversions after
15565 ‘%u’:
15566
15567 $ awk 'BEGIN { printf "%u %d\n", 0, -1 }'
15568 0 0
15569
15570 AIX version 5.2 has an arbitrary limit of 399 on the length of
15571 regular expressions and literal strings in an Awk program.
15572
15573 Traditional Awk implementations derived from Unix version 7, such
15574 as Solaris ‘/bin/awk’, have many limitations and do not conform to
15575 POSIX. Nowadays ‘AC_PROG_AWK’ (*note Particular Programs::) finds
15576 you an Awk that doesn’t have these problems, but if for some reason
15577 you prefer not to use ‘AC_PROG_AWK’ you may need to address them.
15578 For more detailed descriptions, see *note ‘awk’ language history:
15579 (gawk)Language History.
15580
15581 Traditional Awk does not support multidimensional arrays or
15582 user-defined functions.
15583
15584 Traditional Awk does not support the ‘-v’ option. You can use
15585 assignments after the program instead, e.g., ‘$AWK '{print v $1}'
15586 v=x’; however, don’t forget that such assignments are not evaluated
15587 until they are encountered (e.g., after any ‘BEGIN’ action).
15588
15589 Traditional Awk does not support the keywords ‘delete’ or ‘do’.
15590
15591 Traditional Awk does not support the expressions ‘A?B:C’, ‘!A’,
15592 ‘A^B’, or ‘A^=B’.
15593
15594 Traditional Awk does not support the predefined ‘CONVFMT’ or
15595 ‘ENVIRON’ variables.
15596
15597 Traditional Awk supports only the predefined functions ‘exp’,
15598 ‘index’, ‘int’, ‘length’, ‘log’, ‘split’, ‘sprintf’, ‘sqrt’, and
15599 ‘substr’.
15600
15601 Traditional Awk ‘getline’ is not at all compatible with POSIX;
15602 avoid it.
15603
15604 Traditional Awk has ‘for (i in a) ...’ but no other uses of the
15605 ‘in’ keyword. For example, it lacks ‘if (i in a) ...’.
15606
15607 In code portable to both traditional and modern Awk, ‘FS’ must be a
15608 string containing just one ordinary character, and similarly for
15609 the field-separator argument to ‘split’.
15610
15611 Traditional Awk has a limit of 99 fields in a record and splits the
15612 input even if you don’t refer to any field in the script. To
15613 circumvent this problem, set ‘FS’ to an unusual character and use
15614 ‘split’.
15615
15616 Traditional Awk has a limit of at most 99 bytes in a number
15617 formatted by ‘OFMT’; for example, ‘OFMT="%.300e"; print 0.1;’
15618 typically dumps core.
15619
15620 The original version of Awk had a limit of at most 99 bytes per
15621 ‘split’ field, 99 bytes per ‘substr’ substring, and 99 bytes per
15622 run of non-special characters in a ‘printf’ format, but these bugs
15623 have been fixed on all practical hosts that we know of.
15624
15625 HP-UX 11.00 Awk requires that input files have a line length of at
15626 most 3070 bytes.
15627
15628 ‘basename’
15629 Long ago some hosts lacked a working ‘basename’, and portable
15630 scripts needed to use ‘expr’ instead. Nowadays it is safe to use
15631 ‘basename’. For example:
15632
15633 base=`basename -- "$file"`
15634
15635 ‘cat’
15636 Don’t rely on any option.
15637
15638 ‘cc’
15639 The command ‘cc -c foo.c’ traditionally produces an object file
15640 named ‘foo.o’. Most compilers allow ‘-c’ to be combined with ‘-o’
15641 to specify a different object file name, but POSIX does not require
15642 this combination and a few compilers lack support for it. *Note C
15643 Compiler::, for how GNU Make tests for this feature with
15644 ‘AC_PROG_CC_C_O’.
15645
15646 When a compilation such as ‘cc -o foo foo.c’ fails, some compilers
15647 (such as CDS on Reliant Unix) leave a ‘foo.o’.
15648
15649 HP-UX ‘cc’ doesn’t accept ‘.S’ files to preprocess and assemble.
15650 ‘cc -c foo.S’ appears to succeed, but in fact does nothing.
15651
15652 The default executable, produced by ‘cc foo.c’, can be
15653
15654 • ‘a.out’ – usual POSIX convention.
15655 • ‘b.out’ – i960 compilers (including ‘gcc’).
15656 • ‘a.exe’ – DJGPP port of ‘gcc’.
15657 • ‘a_out.exe’ – GNV ‘cc’ wrapper for DEC C on OpenVMS.
15658 • ‘foo.exe’ – various MS-DOS compilers.
15659
15660 The C compiler’s traditional name is ‘cc’, but other names like
15661 ‘gcc’ are common. POSIX 1003.1-2024 specifies the name ‘c17’, but
15662 older POSIX editions specified ‘c99’ or ‘c89’, future POSIX
15663 standards will likely specify other commands, and anyway these
15664 standard names are rarely used in practice. Typically the C
15665 compiler is invoked from makefiles that use ‘$(CC)’, so the value
15666 of the ‘CC’ make variable selects the compiler name.
15667
15668 ‘chgrp’
15669 ‘chown’
15670 It is not portable to change a file’s group to a group that the
15671 owner does not belong to.
15672
15673 ‘chmod’
15674 Avoid usages like ‘chmod -w file’; use ‘chmod a-w file’ instead,
15675 for two reasons. First, plain ‘-w’ does not necessarily make the
15676 file unwritable, since it does not affect mode bits that correspond
15677 to bits in the file mode creation mask. Second, POSIX says that
15678 the ‘-w’ might be interpreted as an implementation-specific option,
15679 not as a mode; POSIX suggests using ‘chmod -- -w file’ to avoid
15680 this confusion, but unfortunately ‘--’ does not work on some older
15681 hosts.
15682
15683 ‘cmp’
15684 ‘cmp’ performs a raw data comparison of two files, while ‘diff’
15685 compares two text files. Therefore, if you might compare DOS
15686 files, even if only checking whether two files are different, use
15687 ‘diff’ to avoid spurious differences due to differences of newline
15688 encoding.
15689
15690 ‘cp’
15691 The ‘-i’, ‘-f’, ‘-p’ and ‘-R’ options are widely used. POSIX also
15692 specifies ‘-H’, ‘-L’, and ‘-P’. Avoid other options in portable
15693 scripts.
15694
15695 Traditionally, file timestamps had 1-second resolution, and ‘cp -p’
15696 copied the timestamps exactly. However, many modern file systems
15697 have timestamps with 1-nanosecond resolution. Unfortunately, some
15698 older ‘cp -p’ implementations truncate timestamps when copying
15699 files, which can cause the destination file to appear to be older
15700 than the source. The exact amount of truncation depends on the
15701 resolution of the system calls that ‘cp’ uses. Traditionally this
15702 was ‘utime’, which has 1-second resolution. Since GNU Core
15703 Utilities 6.12 (2008), GNU ‘cp’ can set timestamps to the full
15704 nanosecond resolution, using the system calls ‘futimens’ and
15705 ‘utimensat’ when they are available. As of 2024, though, some
15706 platforms (such as AIX 7.3) still have ‘cp -p’ that supports only
15707 1-second resolution, and some operating systems and file systems
15708 have similar limitations even when running GNU ‘cp’.
15709
15710 Although ‘cp -p’ always _tries_ to copy ownerships, whether it
15711 actually does so is a system dependent policy decision implemented
15712 by the kernel. If the kernel allows it then it happens. If the
15713 kernel does not allow it then it does not happen. It is not
15714 something ‘cp’ itself has control over.
15715
15716 In Unix System V any user can chown files to any other user, and
15717 System V also has a non-sticky ‘/tmp’. That probably derives from
15718 the heritage of System V in a business environment without hostile
15719 users. BSD changed this to be a more secure model where only root
15720 can ‘chown’ files and a sticky ‘/tmp’ is used. That undoubtedly
15721 derives from the heritage of BSD in a campus environment.
15722
15723 GNU/Linux and Solaris by default follow BSD, but can be configured
15724 to allow a System V style ‘chown’. On the other hand, HP-UX
15725 follows System V, but can be configured to use the modern security
15726 model and disallow ‘chown’. Since it is an
15727 administrator-configurable parameter you can’t use the name of the
15728 kernel as an indicator of the behavior.
15729
15730 ‘date’
15731 When most versions of ‘date’ do not recognize a ‘%’ conversion
15732 specification, they quietly pass it through, and exit with success:
15733
15734 $ date --version | head -n 1
15735 date (GNU coreutils) 9.5
15736 $ date +'%H:%M %Q'
15737 17:25 %Q
15738
15739 However, this behavior is not required by POSIX.
15740
15741 ‘dirname’
15742 Long ago some hosts lacked a working ‘dirname’ and portable scripts
15743 needed to use use ‘AS_DIRNAME’ (*note Programming in M4sh::).
15744 Nowadays ‘dirname’ suffices and the following are equivalent:
15745
15746 dir=`dirname -- "$file"`
15747 dir=`AS_DIRNAME(["$file"])`
15748
15749 ‘egrep’
15750 Although POSIX stopped requiring ‘egrep’ in 2001, a few traditional
15751 hosts (notably Solaris 11) do not support the POSIX replacement
15752 ‘grep -E’. Also, some traditional implementations do not work on
15753 long input lines. To work around these problems, invoke
15754 ‘AC_PROG_EGREP’ and then use ‘$EGREP’.
15755
15756 Portable extended regular expressions should use ‘\’ only to escape
15757 characters in the string ‘$()*+.?[\^{|’. For example, ‘\}’ is not
15758 portable, even though it typically matches ‘}’.
15759
15760 The empty alternative is not portable. Use ‘?’ instead. For
15761 instance with Digital Unix v5.0:
15762
15763 > printf 'foo\n|foo\n' | $EGREP '^(|foo|bar)$'
15764 |foo
15765 > printf 'bar\nbar|\n' | $EGREP '^(foo|bar|)$'
15766 bar|
15767 > printf 'foo\nfoo|\n|bar\nbar\n' | $EGREP '^(foo||bar)$'
15768 foo
15769 |bar
15770
15771 For more information about what can appear in portable extended
15772 regular expressions, *note (grep)Problematic Expressions::.
15773
15774 ‘$EGREP’ also suffers the limitations of ‘grep’ (*note Limitations
15775 of Usual Tools: grep.).
15776
15777 ‘expr’
15778 Not all implementations obey the POSIX rule that ‘--’ separates
15779 options from arguments; likewise, not all implementations provide
15780 the extension to POSIX that the first argument can be treated as
15781 part of a valid expression rather than an invalid option if it
15782 begins with ‘-’. When performing arithmetic, use ‘expr 0 + $var’
15783 if ‘$var’ might be a negative number, to keep ‘expr’ from
15784 interpreting it as an option.
15785
15786 No ‘expr’ keyword starts with ‘X’, so use ‘expr X"WORD" : 'XREGEX'’
15787 to keep ‘expr’ from misinterpreting WORD.
15788
15789 Don’t use ‘length’, ‘substr’, ‘match’ and ‘index’.
15790
15791 ‘expr’ (‘|’)
15792 You can use ‘|’. Although POSIX does require that ‘expr ''’ return
15793 the empty string, it does not specify the result when you ‘|’
15794 together the empty string (or zero) with the empty string. For
15795 example:
15796
15797 expr '' \| ''
15798
15799 POSIX 1003.2-1992 returns the empty string for this case, but
15800 traditional Unix returns ‘0’ (Solaris is one such example). In
15801 POSIX 1003.1-2001, the specification was changed to match
15802 traditional Unix’s behavior (which is bizarre, but it’s too late to
15803 fix this). Please note that the same problem does arise when the
15804 empty string results from a computation, as in:
15805
15806 expr bar : foo \| foo : bar
15807
15808 Avoid this portability problem by avoiding the empty string.
15809
15810 ‘expr’ (‘:’)
15811 Portable ‘expr’ regular expressions should use ‘\’ to escape only
15812 characters in the string ‘$()*.123456789[\^{}’. For example,
15813 alternation, ‘\|’, is common but POSIX does not require its
15814 support, so it should be avoided in portable scripts. Similarly,
15815 ‘\+’ and ‘\?’ should be avoided.
15816
15817 Portable ‘expr’ regular expressions should not begin with ‘^’.
15818 Patterns are automatically anchored so leading ‘^’ is not needed
15819 anyway.
15820
15821 On the other hand, the behavior of the ‘$’ anchor is not portable
15822 on multi-line strings. POSIX is ambiguous whether the anchor
15823 applies to each line, as was done in older versions of the GNU Core
15824 Utilities, or whether it applies only to the end of the overall
15825 string, as in Coreutils 6.0 and most other implementations.
15826
15827 $ baz='foo
15828 > bar'
15829 $ expr "X$baz" : 'X\(foo\)$'
15830
15831 $ expr-5.97 "X$baz" : 'X\(foo\)$'
15832 foo
15833
15834 The POSIX standard is ambiguous as to whether ‘expr 'a' : '\(b\)'’
15835 outputs ‘0’ or the empty string. In practice, it outputs the empty
15836 string on most platforms, but portable scripts should not assume
15837 this. For instance, the QNX 4.25 native ‘expr’ returns ‘0’.
15838
15839 One might think that a way to get a uniform behavior would be to
15840 use the empty string as a default value:
15841
15842 expr a : '\(b\)' \| ''
15843
15844 Unfortunately this behaves exactly as the original expression; see
15845 the ‘expr’ (‘|’) entry for more information.
15846
15847 Some ancient ‘expr’ implementations (e.g., Solaris 10
15848 ‘/usr/ucb/expr’) have a silly length limit that causes ‘expr’ to
15849 fail if the matched substring is longer than 120 bytes. In this
15850 case, you might want to fall back on ‘printf|sed’ if ‘expr’ fails.
15851 Nowadays this is of practical importance only for the rare
15852 installer who mistakenly puts ‘/usr/ucb’ before ‘/usr/bin’ in
15853 ‘PATH’ on Solaris 10.
15854
15855 On Mac OS X 10.4, ‘expr’ mishandles the pattern ‘[^-]’ in some
15856 cases. For example, the command
15857 expr Xpowerpc-apple-darwin8.1.0 : 'X[^-]*-[^-]*-\(.*\)'
15858
15859 outputs ‘apple-darwin8.1.0’ rather than the correct ‘darwin8.1.0’.
15860 This particular case can be worked around by substituting ‘[^--]’
15861 for ‘[^-]’.
15862
15863 Don’t leave, there is some more!
15864
15865 The QNX 4.25 ‘expr’, in addition of preferring ‘0’ to the empty
15866 string, has a funny behavior in its exit status: it’s always 1 when
15867 parentheses are used!
15868
15869 $ val=`expr 'a' : 'a'`; echo "$?: $val"
15870 0: 1
15871 $ val=`expr 'a' : 'b'`; echo "$?: $val"
15872 1: 0
15873
15874 $ val=`expr 'a' : '\(a\)'`; echo "?: $val"
15875 1: a
15876 $ val=`expr 'a' : '\(b\)'`; echo "?: $val"
15877 1: 0
15878
15879 In practice this can be a big problem if you are ready to catch
15880 failures of ‘expr’ programs with some other method (such as using
15881 ‘sed’), since you may get twice the result. For instance
15882
15883 $ expr 'a' : '\(a\)' || echo 'a' | sed 's/^\(a\)$/\1/'
15884
15885 outputs ‘a’ on most hosts, but ‘aa’ on QNX 4.25. A simple
15886 workaround consists of testing ‘expr’ and using a variable set to
15887 ‘expr’ or to ‘false’ according to the result.
15888
15889 On HP-UX 11, ‘expr’ supports only a single sub-expression.
15890
15891 $ expr 'Xfoo' : 'X\(f\(oo\)*\)$'
15892 expr: More than one '\(' was used.
15893
15894 ‘fgrep’
15895 Although POSIX stopped requiring ‘fgrep’ in 2001, a few traditional
15896 hosts (notably Solaris 11) do not support the POSIX replacement
15897 ‘grep -F’. Also, some traditional implementations do not work on
15898 long input lines. To work around these problems, invoke
15899 ‘AC_PROG_FGREP’ and then use ‘$FGREP’.
15900
15901 ‘find’
15902 Many operands of GNU ‘find’ are not standardized by POSIX and are
15903 missing on many platforms. These nonportable operands include
15904 ‘-follow’, ‘-maxdepth’, ‘-mindepth’, ‘-printf’, and ‘,’. See the
15905 POSIX spec for ‘find’
15906 (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html)
15907 for ‘find’ operands that should be portable nowadays.
15908
15909 The replacement of ‘{}’ is guaranteed only if the argument is
15910 exactly ‘{}’, not if ‘{}’ only a part of a larger argument. For
15911 instance, on AIX 7.3:
15912
15913 $ touch foo
15914 $ find . -name foo -exec echo '{}-{}' \;
15915 {}-{}
15916
15917 while GNU ‘find’ reports ‘./foo-./foo’. POSIX allows either
15918 behavior.
15919
15920 AIX 7.3 ‘find ... -exec COMMAND +’ incorrectly fails if COMMAND is
15921 not executed. For example, ‘find . -name '*.tmp' -exec rm {} +’
15922 incorrectly outputs a diagnostic and fails if no file names end in
15923 ‘.tmp’. To work around this problem you can use a circumlocution
15924 like ‘find . -name '*.tmp' -exec rm -f {} + -o -exec true ';'’.
15925
15926 ‘grep’
15927 Portable scripts can rely on the ‘grep’ options ‘-c’, ‘-l’, ‘-n’,
15928 and ‘-v’, but should avoid other options. For example, don’t use
15929 ‘-w’, as POSIX does not require it. Also, portable scripts should
15930 not combine ‘-c’ with ‘-l’, as POSIX does not allow this.
15931
15932 Some of the options required by POSIX are not portable in practice.
15933 Don’t use ‘grep -q’ to suppress output, because traditional ‘grep’
15934 implementations (e.g., Solaris 10) do not support ‘-q’. Don’t use
15935 ‘grep -s’ to suppress output either, because POSIX says ‘-s’ does
15936 not suppress output, only some error messages; also, the ‘-s’
15937 option of traditional ‘grep’ behaved like ‘-q’ does in most modern
15938 implementations. Instead, redirect the standard output and
15939 standard error (in case the file doesn’t exist) of ‘grep’ to
15940 ‘/dev/null’. Check the exit status of ‘grep’ to determine whether
15941 it found a match.
15942
15943 The QNX4 implementation fails to count lines with ‘grep -c '$'’,
15944 but works with ‘grep -c '^'’. Other alternatives for counting
15945 lines are to use ‘sed -n '$='’ or ‘wc -l’.
15946
15947 Some traditional ‘grep’ implementations do not work on long input
15948 lines. On AIX the default ‘grep’ silently truncates long lines on
15949 the input before matching.
15950
15951 Also, Solaris 11 ‘grep’ does not support ‘-e’. To work around
15952 this, invoke ‘AC_PROG_GREP’ and then use ‘$GREP’.
15953
15954 Another possible workaround for the multiple ‘-e’ problem is to
15955 separate the patterns by newlines, for example:
15956
15957 grep 'foo
15958 bar' in.txt
15959
15960 except that this fails with traditional ‘grep’ implementations and
15961 with OpenBSD 3.8 ‘grep’.
15962
15963 Traditional ‘grep’ implementations (e.g., Solaris 11) do not
15964 support the ‘-E’ or ‘-F’ options. To work around these problems,
15965 invoke ‘AC_PROG_EGREP’ and then use ‘$EGREP’, and similarly for
15966 ‘AC_PROG_FGREP’ and ‘$FGREP’. Even if you are willing to require
15967 support for POSIX ‘grep’, your script should not use both ‘-E’ and
15968 ‘-F’, since POSIX does not allow this combination.
15969
15970 Portable ‘grep’ regular expressions should use ‘\’ only to escape
15971 characters in the string ‘$()*.123456789[\^{}’. For example,
15972 alternation, ‘\|’, is common but POSIX does not require its support
15973 in basic regular expressions, so it should be avoided in portable
15974 scripts. Solaris and HP-UX ‘grep’ do not support it. Similarly,
15975 the following escape sequences should also be avoided: ‘\<’, ‘\>’,
15976 ‘\+’, ‘\?’, ‘\`’, ‘\'’, ‘\B’, ‘\b’, ‘\S’, ‘\s’, ‘\W’, and ‘\w’.
15977 For more information about what can appear in portable regular
15978 expressions, *note (grep)Problematic Expressions::.
15979
15980 POSIX does not specify the behavior of ‘grep’ on binary files. An
15981 example where this matters is using BSD ‘grep’ to search text that
15982 includes embedded ANSI escape sequences for colored output to
15983 terminals (‘\033[m’ is the sequence to restore normal output); the
15984 behavior depends on whether input is seekable:
15985
15986 $ printf 'esc\033[mape\n' > sample
15987 $ grep . sample
15988 Binary file sample matches
15989 $ cat sample | grep .
15990 escape
15991
15992 ‘join’
15993 On NetBSD, ‘join -a 1 file1 file2’ mistakenly behaves like ‘join -a
15994 1 -a 2 1 file1 file2’, resulting in a usage warning; the workaround
15995 is to use ‘join -a1 file1 file2’ instead.
15996
15997 On some circa-2020 BSD-based systems ‘join’ mishandles inputs with
15998 missing fields. For example, an empty line is not treated as
15999 containing an empty join field. As a workaround, input lines
16000 should always have a join field.
16001
16002 On platforms with the BusyBox tools, the ‘join’ command is entirely
16003 missing. As a workaround, you can simulate special cases of the
16004 ‘join’ command using an ‘awk’ script. For an example, see
16005 <https://lists.gnu.org/r/bug-gnulib/2021-04/msg00054.html>.
16006
16007 ‘ln’
16008 The ‘-f’ option is portable nowadays.
16009
16010 Symbolic links are not available on some systems; use ‘$(LN_S)’ as
16011 a portable substitute.
16012
16013 For versions of the DJGPP before 2.04, ‘ln’ emulates symbolic links
16014 to executables by generating a stub that in turn calls the real
16015 program. This feature also works with nonexistent files like in
16016 the POSIX spec. So ‘ln -s file link’ generates ‘link.exe’, which
16017 attempts to call ‘file.exe’ if run. But this feature only works
16018 for executables, so ‘cp -p’ is used instead for these systems.
16019 DJGPP versions 2.04 and later have full support for symbolic links.
16020
16021 ‘ls’
16022 The portable options are ‘-acdilrtu’. Current practice is for ‘-l’
16023 to output both owner and group, even though ancient versions of
16024 ‘ls’ omitted the group.
16025
16026 On ancient hosts, ‘ls foo’ sent the diagnostic ‘foo not found’ to
16027 standard output if ‘foo’ did not exist. Hence a shell command like
16028 ‘sources=`ls *.c 2>/dev/null`’ did not always work, since it was
16029 equivalent to ‘sources='*.c not found'’ in the absence of ‘.c’
16030 files. This is no longer a practical problem, since current ‘ls’
16031 implementations send diagnostics to standard error.
16032
16033 The behavior of ‘ls’ on a directory that is being concurrently
16034 modified is not always predictable, because of a data race where
16035 cached information returned by ‘readdir’ does not match the current
16036 directory state. In fact, Mac OS X 10.5 had an intermittent bug
16037 where ‘readdir’, and thus ‘ls’, sometimes lists a file more than
16038 once if other files were added or removed from the directory
16039 immediately prior to the ‘ls’ call. Since ‘ls’ already sorts its
16040 output, the duplicate entries can be avoided by piping the results
16041 through ‘uniq’.
16042
16043 ‘mkdir’
16044 Combining the ‘-m’ and ‘-p’ options, as in ‘mkdir -m go-w -p DIR’,
16045 often leads to trouble. FreeBSD ‘mkdir’ incorrectly attempts to
16046 change the permissions of DIR even if it already exists. HP-UX
16047 11.23 ‘mkdir’ often assigns the wrong permissions to any
16048 newly-created parents of DIR.
16049
16050 POSIX does not clearly specify whether ‘mkdir -p foo’ should
16051 succeed when ‘foo’ is a symbolic link to an already-existing
16052 directory. The GNU ‘mkdir’ succeeds, but Solaris 10 ‘mkdir’ fails.
16053
16054 Traditional ‘mkdir -p’ implementations suffer from race conditions.
16055 For example, if you invoke ‘mkdir -p a/b’ and ‘mkdir -p a/c’ at the
16056 same time, both processes might detect that ‘a’ is missing, one
16057 might create ‘a’, then the other might try to create ‘a’ and fail
16058 with a ‘File exists’ diagnostic. Solaris 10 ‘mkdir’ is vulnerable,
16059 and other traditional Unix systems are probably vulnerable too.
16060 This possible race is harmful in parallel builds when several Make
16061 rules call ‘mkdir -p’ to construct directories. You may use
16062 ‘install-sh -d’ as a safe replacement, for example by setting
16063 ‘MKDIR_P='/path/to/install-sh -d'’ in the environment of
16064 ‘configure’, assuming the package distributes ‘install-sh’.
16065
16066 ‘mkfifo’
16067 ‘mknod’
16068 The GNU Coding Standards state that ‘mknod’ is safe to use on
16069 platforms where it has been tested to exist; but it is generally
16070 portable only for creating named FIFOs, since device numbers are
16071 platform-specific. Autotest uses ‘mkfifo’ to implement parallel
16072 testsuites. POSIX states that behavior is unspecified when opening
16073 a named FIFO for both reading and writing; on at least Cygwin, this
16074 results in failure on any attempt to read or write to that file
16075 descriptor.
16076
16077 ‘mktemp’
16078 Shell scripts can use temporary files safely with ‘mktemp’, but it
16079 does not exist on all systems. A portable way to create a safe
16080 temporary file name is to create a temporary directory with mode
16081 700 and use a file inside this directory. Both methods prevent
16082 attackers from gaining control, though ‘mktemp’ is far less likely
16083 to fail gratuitously under attack.
16084
16085 Here is sample code to create a new temporary directory ‘$dir’
16086 safely:
16087
16088 # Create a temporary directory $dir in $TMPDIR (default /tmp).
16089 # Use mktemp if possible; otherwise fall back on mkdir,
16090 # with $RANDOM to make collisions less likely.
16091 : "${TMPDIR:=/tmp}"
16092 {
16093 dir=`
16094 (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
16095 ` &&
16096 test -d "$dir"
16097 } || {
16098 dir=$TMPDIR/foo$$-$RANDOM
16099 (umask 077 && mkdir "$dir")
16100 } || exit $?
16101
16102 ‘mv’
16103 The only portable options are ‘-f’ and ‘-i’.
16104
16105 Moving individual files between file systems is portable (it was in
16106 Unix version 6), but it is not always atomic: when doing ‘mv new
16107 existing’, there’s a critical section where neither the old nor the
16108 new version of ‘existing’ actually exists.
16109
16110 On some systems moving files from ‘/tmp’ can sometimes cause
16111 undesirable (but perfectly valid) warnings, even if you created
16112 these files. This is because ‘/tmp’ belongs to a group that
16113 ordinary users are not members of, and files created in ‘/tmp’
16114 inherit the group of ‘/tmp’. When the file is copied, ‘mv’ issues
16115 a diagnostic without failing:
16116
16117 $ touch /tmp/foo
16118 $ mv /tmp/foo .
16119 error→mv: ./foo: set owner/group (was: 100/0): Operation not permitted
16120 $ echo $?
16121 0
16122 $ ls foo
16123 foo
16124
16125 This annoying behavior conforms to POSIX, unfortunately.
16126
16127 Moving directories across mount points is not portable, use ‘cp’
16128 and ‘rm’.
16129
16130 DOS variants cannot rename or remove open files, and do not support
16131 commands like ‘mv foo bar >foo’, even though this is perfectly
16132 portable among POSIX hosts.
16133
16134 ‘od’
16135
16136 In Mac OS X versions prior to 10.4.3, ‘od’ does not support the
16137 standard POSIX options ‘-A’, ‘-j’, ‘-N’, or ‘-t’, or the XSI
16138 option, ‘-s’. The only supported POSIX option is ‘-v’, and the
16139 only supported XSI options are those in ‘-bcdox’. The BSD
16140 ‘hexdump’ program can be used instead.
16141
16142 In some versions of some operating systems derived from Solaris 11,
16143 ‘od’ prints decimal byte values padded with zeros rather than with
16144 spaces:
16145
16146 $ printf '#!' | od -A n -t d1 -N 2
16147 035 033
16148
16149 instead of
16150
16151 $ printf '#!' | od -A n -t d1 -N 2
16152 35 33
16153
16154 We have observed this on both OpenIndiana and OmniOS; Illumos may
16155 also be affected. As a workaround, you can use octal output
16156 (option ‘-t o1’).
16157
16158 ‘rm’
16159 The ‘-f’ and ‘-r’ options are portable.
16160
16161 It is not portable to invoke ‘rm’ without options or operands. On
16162 the other hand, POSIX now requires ‘rm -f’ to silently succeed when
16163 there are no operands (useful for constructs like ‘rm -rf
16164 $filelist’ without first checking if ‘$filelist’ was empty). But
16165 this was not always portable; at least NetBSD ‘rm’ built before
16166 2008 would fail with a diagnostic.
16167
16168 A file might not be removed even if its parent directory is
16169 writable and searchable. Many POSIX hosts cannot remove a mount
16170 point, a named stream, a working directory, or a last link to a
16171 file that is being executed.
16172
16173 DOS variants cannot rename or remove open files, and do not support
16174 commands like ‘rm foo >foo’, even though this is perfectly portable
16175 among POSIX hosts.
16176
16177 ‘rmdir’
16178 Just as with ‘rm’, some platforms refuse to remove a working
16179 directory.
16180
16181 ‘sed’
16182 The portable options are ‘-e’, ‘-f’, and ‘-n’. POSIX standardized
16183 ‘-E’ in 2024 but some older implementations lack it. Although GNU
16184 ‘sed’ supports other options like ‘-i’, these can be missing or
16185 have different meanings elsewhere.
16186
16187 Patterns should not include the separator (unless escaped), even as
16188 part of a character class. Even when escaped, patterns should not
16189 include separators that are also used as ‘sed’ metacharacters. For
16190 example, GNU sed 4.0.9 rejects ‘s,x\{1\,\},,’, while sed 4.1 strips
16191 the backslash before the comma before evaluating the basic regular
16192 expression.
16193
16194 Avoid empty patterns, such as the parenthesized empty pattern in
16195 ‘\(\)’ or the empty pattern followed by an interval expression in
16196 ‘\{2\}’. POSIX does not require support for empty patterns.
16197
16198 Comments in Sed scripts should not contain ‘n’ immediately after
16199 the leading ‘#’. Although POSIX.1-2024 says this is equivalent to
16200 the ‘-n’ option, earlier POSIX editions said that the equivalence
16201 occurs only if the comment is the first line of the script, and
16202 many ‘sed’ implementations are confused about this. It is more
16203 portable to use ‘-n’.
16204
16205 HP-UX sed has a limit of 99 commands (not counting ‘:’ commands)
16206 and 48 labels, which cannot be circumvented by using more than one
16207 script file. It can execute up to 19 reads with the ‘r’ command
16208 per cycle. Solaris 10 ‘/usr/ucb/sed’ rejects usages that exceed a
16209 limit of about 6000 bytes for the internal representation of
16210 commands.
16211
16212 Some ‘sed’ implementations have a buffer limited to 4000 bytes, and
16213 this limits the size of input lines, output lines, and internal
16214 buffers that can be processed portably. Likewise, not all ‘sed’
16215 implementations can handle embedded ‘NUL’ or a missing trailing
16216 newline.
16217
16218 Ranges within a bracket expression of a regular expression are only
16219 well-defined in the ‘C’ (or ‘POSIX’) locale. Meanwhile, support
16220 for character classes like ‘[[:upper:]]’ is not yet universal, so
16221 if you cannot guarantee the setting of ‘LC_ALL’, it is better to
16222 spell out a range ‘[ABCDEFGHIJKLMNOPQRSTUVWXYZ]’ than to rely on
16223 ‘[A-Z]’.
16224
16225 Additionally, POSIX states that regular expressions are only
16226 well-defined on characters. Unfortunately, there exist platforms
16227 such as Mac OS X 10.5 where not all 8-bit byte values are valid
16228 characters, even though that platform has a single-byte ‘C’ locale.
16229 Although this practice was disallowed by recent releases of POSIX,
16230 it means that in the ‘C’ locale not all bytes will be matched by
16231 the regular expression ‘.’:
16232
16233 $ printf '\200\n' | LC_ALL=C sed -n /./p | wc -l
16234 0
16235 $ printf '\200\n' | LC_ALL=en_US.ISO8859-1 sed -n /./p | wc -l
16236 1
16237
16238 Anchors (‘^’ and ‘$’) inside groups are not portable.
16239
16240 Some ‘sed’ implementations, e.g., Solaris 11.4, restrict the
16241 special role of the asterisk ‘*’ to one-character regular
16242 expressions and back-references, and the special role of interval
16243 expressions ‘\{M\}’, ‘\{M,\}’, or ‘\{M,N\}’ to one-character
16244 regular expressions. This may lead to unexpected behavior:
16245
16246 $ echo '1*23*4' | /usr/bin/sed 's/\(.\)*/x/g'
16247 x2x4
16248 $ echo '1*23*4' | /usr/xpg4/bin/sed 's/\(.\)*/x/g'
16249 x
16250
16251 In the normal case when ‘-E’ is not used, portable ‘sed’ regular
16252 expressions should use ‘\’ only to escape characters in the string
16253 ‘$*.123456789[\^n’. For example, POSIX.1-2024 says it is
16254 implementation-defined whether ‘\|’ means alternation or simply
16255 matches ‘|’, so it should be avoided in portable scripts. Solaris
16256 ‘sed’ does not support alternation; e.g., ‘sed '/a\|b/d'’ deletes
16257 only lines that contain the literal string ‘a|b’. Similarly, ‘\+’
16258 and ‘\?’ should be avoided.
16259
16260 Portable ‘sed’ replacement strings should use ‘\’ only to escape
16261 the delimiter character, newline, and characters in the string
16262 ‘&123456789\’. For example, although in GNU ‘sed’ the command
16263 ‘s/AB/\n/’ replaces the first ‘AB’ with a newline, in OpenBSD and
16264 Solaris ‘sed’ it acts like ‘s/AB/n/’. To be portable, escape a
16265 newline instead:
16266
16267 # This is portable; "sed 's/AB/\n/'" is not.
16268 sed 's/AB/\
16269 /'
16270
16271 The ‘-e’ option is mostly portable. However, its argument cannot
16272 be empty, as this fails on AIX 7.3. Some people prefer to use
16273 ‘-e’:
16274
16275 sed -e 'COMMAND-1' \
16276 -e 'COMMAND-2'
16277
16278 as opposed to the equivalent:
16279
16280 sed '
16281 COMMAND-1
16282 COMMAND-2
16283 '
16284
16285 The following usage is sometimes equivalent:
16286
16287 sed 'COMMAND-1;COMMAND-2'
16288
16289 but POSIX says that this use of a semicolon has undefined effect if
16290 COMMAND-1’s verb is ‘{’, ‘a’, ‘b’, ‘c’, ‘i’, ‘r’, ‘t’, ‘w’ or ‘:’,
16291 or if COMMAND-1 is an ‘s’ with the ‘w’ option, so you should use
16292 semicolon only with simple scripts that do not use these
16293 constructs.
16294
16295 Avoid redundant ‘;’, as some ‘sed’ implementations, such as NetBSD
16296 1.4.2’s, incorrectly try to interpret the second ‘;’ as a command:
16297
16298 $ echo a | sed 's/x/x/;;s/x/x/'
16299 sed: 1: "s/x/x/;;s/x/x/": invalid command code ;
16300
16301 POSIX requires each ‘-e’ and ‘-f’ option to specify a syntactically
16302 complete script. Although GNU ‘sed’ also allows ‘-e’ and ‘-f’
16303 options to specify script fragments that it assembles into a full
16304 script, this is not portable. For example, the ‘sed’ programs on
16305 Solaris 11, HP-UX 11, and AIX do not allow script fragments:
16306
16307 $ sed -e 'i\' -e ouch
16308 Unrecognized command: ouch
16309
16310 In practice, however, this technique of joining fragments through
16311 ‘-e’ works for multiple ‘sed’ functions within ‘{’ and ‘}’, even if
16312 that is not specified by POSIX:
16313
16314 $ echo a | sed -n -e '/a/{' -e s/a/b/ -e p -e '}'
16315 b
16316
16317 Commands should not be followed by white space. Although trailing
16318 white space often works, it can be dicey in some situations and it
16319 is simpler to avoid it entirely.
16320
16321 Commands inside { } brackets are further restricted. POSIX.1-2004
16322 says that they cannot be preceded by addresses, ‘!’, or ‘;’, and
16323 that each command must be followed immediately by a newline,
16324 without any intervening blanks or semicolons. The closing bracket
16325 must be alone on a line, other than white space preceding or
16326 following it. Although these restrictions were lifted in
16327 POSIX.1-2008, it is more portable to respect them.
16328
16329 Contrary to yet another urban legend, you may portably use ‘&’ in
16330 the replacement part of the ‘s’ command to mean “what was matched”.
16331 All descendants of Unix version 7 ‘sed’ (at least; we don’t have
16332 first hand experience with older ‘sed’ implementations) have
16333 supported it.
16334
16335 POSIX requires that you must not have any white space between ‘!’
16336 and the following command. It is OK to have blanks between the
16337 address and the ‘!’. For instance, on Solaris:
16338
16339 $ echo "foo" | sed -n '/bar/ ! p'
16340 error→Unrecognized command: /bar/ ! p
16341 $ echo "foo" | sed -n '/bar/! p'
16342 error→Unrecognized command: /bar/! p
16343 $ echo "foo" | sed -n '/bar/ !p'
16344 foo
16345
16346 POSIX also says that you should not combine ‘!’ and ‘;’. If you
16347 use ‘!’, it is best to put it on a command that is delimited by
16348 newlines rather than ‘;’.
16349
16350 POSIX requires that the ‘b’, ‘t’, ‘r’, and ‘w’ commands be followed
16351 by exactly one space before their argument. On the other hand, no
16352 white space is allowed between ‘:’ and the subsequent label.
16353 Branch labels should contain at most 8 bytes, each of which should
16354 be an ASCII graphical character. Do not put trailing white space
16355 after a branch label.
16356
16357 If a sed script is specified on the command line and ends in an
16358 ‘a’, ‘c’, or ‘i’ command, the last line of inserted text should be
16359 followed by a newline. Otherwise some ‘sed’ implementations (e.g.,
16360 OpenBSD 3.9) do not append a newline to the inserted text.
16361
16362 Many ‘sed’ implementations (e.g., Mac OS X 10.4, OpenBSD 3.9,
16363 Solaris 11 ‘/usr/ucb/sed’) strip leading white space from the text
16364 of ‘a’, ‘c’, and ‘i’ commands. Prepend a backslash to work around
16365 this incompatibility with POSIX:
16366
16367 $ echo flushleft | sed 'a\
16368 > indented
16369 > '
16370 flushleft
16371 indented
16372 $ echo foo | sed 'a\
16373 > \ indented
16374 > '
16375 flushleft
16376 indented
16377
16378 POSIX requires that with a missing regular expression, the last
16379 regular expression from either an address specification or
16380 substitution command is used. However, busybox 1.6.1 complains
16381 when using a substitution command with a replacement containing a
16382 back-reference to a missing regular expression; the workaround is
16383 repeating the regular expression.
16384
16385 $ echo abc | busybox sed '/a\(b\)c/ s//\1/'
16386 sed: No previous regexp.
16387 $ echo abc | busybox sed '/a\(b\)c/ s/a\(b\)c/\1/'
16388 b
16389
16390 Portable scripts should be aware of the inconsistencies and options
16391 for handling word boundaries, as these are not specified by POSIX.
16392
16393 \< \b [[:<:]]
16394 Solaris 11 yes no no
16395 Solaris XPG4 yes no error
16396 NetBSD 5.1 no no yes
16397 FreeBSD 9.1 no no yes
16398 GNU yes yes error
16399 busybox yes yes error
16400
16401 ‘sed’ (‘t’)
16402 There are two things one should remember about ‘t’ in ‘sed’.
16403 First, ‘t’ jumps if _some_ substitution succeeded, not only the
16404 immediately preceding substitution. Therefore, always use a fake
16405 ‘t clear’ followed by a ‘:clear’ on the next line, to reset the ‘t’
16406 flag where needed.
16407
16408 Second, do not rely on ‘sed’ to clear the flag at each new cycle.
16409
16410 For example, the following script replaces all instances of “keep
16411 me” with “kept”, and replaces the contents of all lines that did
16412 not contain “keep me” with “deleted”.
16413
16414 t clear
16415 :clear
16416 s/keep me/kept/g
16417 t end
16418 s/.*/deleted/g
16419 :end
16420
16421 ‘sed’ (‘w’)
16422
16423 When a script contains multiple commands to write lines to the same
16424 output file, BusyBox ‘sed’ mistakenly opens a separate output
16425 stream for each command. This can cause one of the commands to
16426 “win” and the others to “lose”, in the sense that their output is
16427 discarded. For example:
16428
16429 sed -n -e '
16430 /a/w xxx
16431 /b/w xxx
16432 ' <<EOF
16433 a
16434 b
16435 EOF
16436
16437 This might output only ‘a’ to ‘xxx’; the ‘b’ is lost. To avoid the
16438 problem, a portable script should contain at most one ‘w’ or
16439 ‘s/.../.../w’ command per output file.
16440
16441 ‘sleep’
16442 Using ‘sleep’ is generally portable. However, remember that adding
16443 a ‘sleep’ to work around timestamp issues, with a minimum
16444 granularity of one second, doesn’t scale well for parallel builds
16445 on modern machines with sub-second process completion.
16446
16447 ‘sort’
16448 Remember that sort order is influenced by the current locale.
16449 Inside ‘configure’, the C locale is in effect, but in Makefile
16450 snippets, you may need to specify ‘LC_ALL=C sort’.
16451
16452 ‘tar’
16453 There are multiple file formats for ‘tar’; if you use Automake, the
16454 macro ‘AM_INIT_AUTOMAKE’ has some options controlling which level
16455 of portability to use.
16456
16457 ‘touch’
16458 If you specify the desired timestamp (e.g., with the ‘-r’ option),
16459 older ‘touch’ implementations use the ‘utime’ or ‘utimes’ system
16460 call, which can result in the same kind of timestamp truncation
16461 problems that ‘cp -p’ has.
16462
16463 ‘tr’
16464
16465 Many ‘tr’ implementations do not support multi-byte locales well.
16466 For example, Solaris 10 ‘tr’ rejects character classes in
16467 multi-byte locales. Also, ranges have well-defined behavior only
16468 in the ‘C’ (or ‘POSIX’) locale, so if you cannot guarantee the
16469 setting of ‘LC_ALL’ it is better to spell out a range
16470 ‘[ABCDEFGHIJKLMNOPQRSTUVWXYZ]’ than to rely on ‘[A-Z]’.
16471
16472 Not all versions of ‘tr’ handle all backslash character escapes.
16473 For example, Solaris 10 ‘/usr/ucb/tr’ falls over, even though
16474 Solaris contains more modern ‘tr’ in other locations. Using octal
16475 escapes is more portable for carriage returns, since ‘\015’ is the
16476 same for both ASCII and EBCDIC, and since use of literal carriage
16477 returns in scripts causes a number of other problems. But for
16478 other characters, like newline, using octal escapes ties the
16479 operation to ASCII, so it is better to use literal characters.
16480
16481 $ { echo moon; echo light; } | /usr/ucb/tr -d '\n' ; echo
16482 moo
16483 light
16484 $ { echo moon; echo light; } | /usr/bin/tr -d '\n' ; echo
16485 moonlight
16486 $ { echo moon; echo light; } | /usr/ucb/tr -d '\012' ; echo
16487 moonlight
16488 $ nl='
16489 '; { echo moon; echo light; } | /usr/ucb/tr -d "$nl" ; echo
16490 moonlight
16491
16492 Not all versions of ‘tr’ recognize direct ranges of characters: at
16493 least Solaris ‘/usr/bin/tr’ still fails to do so. But you can use
16494 ‘/usr/xpg4/bin/tr’ instead, or add brackets (which in POSIX
16495 transliterate to themselves).
16496
16497 $ echo "Hazy Fantazy" | LC_ALL=C /usr/bin/tr a-z A-Z
16498 HAZy FAntAZy
16499 $ echo "Hazy Fantazy" | LC_ALL=C /usr/bin/tr '[a-z]' '[A-Z]'
16500 HAZY FANTAZY
16501 $ echo "Hazy Fantazy" | LC_ALL=C /usr/xpg4/bin/tr a-z A-Z
16502 HAZY FANTAZY
16503
16504 When providing two arguments, be sure the second string is at least
16505 as long as the first.
16506
16507 $ echo abc | /usr/xpg4/bin/tr bc d
16508 adc
16509 $ echo abc | coreutils/tr bc d
16510 add
16511
16512 On platforms with the BusyBox tools, ‘tr’ does not support the
16513 ‘[X*N]’ option syntax.
16514
16515 $ echo abc | tr 'abcd' '[A*4]'
16516 [A*
16517 $ echo abc | coreutils/tr 'abcd' '[A*4]'
16518 AAA
16519 $ echo xyz | tr 'a-z' '[A*]'
16520 ]]]
16521 $ echo xyz | coreutils/tr 'a-z' '[A*]'
16522 AAA
16523
16524 POSIX requires ‘tr’ to operate on binary files. But at least
16525 Solaris ‘/usr/ucb/tr’ and ‘/usr/bin/tr’ silently discard ‘NUL’ in
16526 the input prior to doing any translation. When using ‘tr’ to
16527 process a binary file that may contain ‘NUL’ bytes, it is necessary
16528 to use ‘/usr/xpg4/bin/tr’ instead, or ‘/usr/xpg6/bin/tr’ if that is
16529 available.
16530
16531 $ printf 'a\0b' | /usr/ucb/tr x x | od -An -tx1
16532 61 62
16533 $ printf 'a\0b' | /usr/bin/tr x x | od -An -tx1
16534 61 62
16535 $ printf 'a\0b' | /usr/xpg4/bin/tr x x | od -An -tx1
16536 61 00 62
16537
16538 Solaris ‘/usr/ucb/tr’ additionally fails to handle ‘\0’ as the
16539 octal escape for ‘NUL’.
16540
16541 $ printf 'abc' | /usr/ucb/tr 'bc' '\0d' | od -An -tx1
16542 61 62 63
16543 $ printf 'abc' | /usr/bin/tr 'bc' '\0d' | od -An -tx1
16544 61 00 64
16545 $ printf 'abc' | /usr/xpg4/bin/tr 'bc' '\0d' | od -An -tx1
16546 61 00 64
16547
16548 
16549 File: autoconf.info, Node: Portable Make, Next: Portable C and C++, Prev: Portable Shell, Up: Top
16550
16551 12 Portable Make Programming
16552 ****************************
16553
16554 Writing portable makefiles is an art. Since a makefile’s commands are
16555 executed by the shell, you must consider the shell portability issues
16556 already mentioned. However, other issues are specific to ‘make’ itself.
16557
16558 * Menu:
16559
16560 * $< in Ordinary Make Rules:: $< in ordinary rules
16561 * Failure in Make Rules:: Failing portably in rules
16562 * Command Line Prefixes:: What’s at the start of makefile command lines
16563 * Special Chars in Names:: Special characters in macro names
16564 * Backslash-Newline-Empty:: Empty lines after backslash-newline
16565 * Backslash-Newline Comments:: Spanning comments across line boundaries
16566 * Macros and Submakes:: ‘make macro=value’ and submakes
16567 * The Make Macro MAKEFLAGS:: ‘$(MAKEFLAGS)’ portability issues
16568 * The Make Macro SHELL:: ‘$(SHELL)’ portability issues
16569 * Parallel Make:: Parallel ‘make’ quirks
16570 * Comments in Make Rules:: Other problems with Make comments
16571 * Newlines in Make Rules:: Using literal newlines in rules
16572 * Comments in Make Macros:: Other problems with Make comments in macros
16573 * Trailing whitespace in Make Macros:: Macro substitution problems
16574 * Command-line Macros and whitespace:: Whitespace trimming of values
16575 * obj/ and Make:: Don’t name a subdirectory ‘obj’
16576 * make -k Status:: Exit status of ‘make -k’
16577 * VPATH and Make:: ‘VPATH’ woes
16578 * Single Suffix Rules:: Single suffix rules and separated dependencies
16579 * Timestamps and Make:: Sub-second timestamp resolution
16580
16581 
16582 File: autoconf.info, Node: $< in Ordinary Make Rules, Next: Failure in Make Rules, Up: Portable Make
16583
16584 12.1 ‘$<’ in Ordinary Make Rules
16585 ================================
16586
16587 POSIX says that the ‘$<’ construct in makefiles can be used only in
16588 inference rules and in the ‘.DEFAULT’ rule; its meaning in ordinary
16589 rules is unspecified. Solaris ‘make’ for instance replaces it with the
16590 empty string. OpenBSD (3.0 and later) ‘make’ diagnoses these uses and
16591 errors out.
16592
16593 
16594 File: autoconf.info, Node: Failure in Make Rules, Next: Command Line Prefixes, Prev: $< in Ordinary Make Rules, Up: Portable Make
16595
16596 12.2 Failure in Make Rules
16597 ==========================
16598
16599 Unless errors are being ignored (e.g., because a makefile command line
16600 is preceded by a ‘-’ prefix), POSIX 2008 requires that ‘make’ must
16601 invoke each command with the equivalent of a ‘sh -e -c’ subshell, which
16602 causes the subshell to exit immediately if a subsidiary simple-command
16603 fails, with some complicated exceptions. Historically not all ‘make’
16604 implementations followed this rule. For example, the command ‘touch T;
16605 rm -f U’ may attempt to remove ‘U’ even if the ‘touch’ fails, although
16606 this is not permitted with POSIX make. One way to work around failures
16607 in simple commands is to reword them so that they always succeed, e.g.,
16608 ‘touch T || :; rm -f U’. However, even this approach can run into
16609 common bugs in BSD implementations of the ‘-e’ option of ‘sh’ and ‘set’
16610 (*note Limitations of Shell Builtins: set.), so if you are worried about
16611 porting to buggy BSD shells it may be simpler to migrate complicated
16612 ‘make’ actions into separate scripts.
16613
16614 
16615 File: autoconf.info, Node: Command Line Prefixes, Next: Special Chars in Names, Prev: Failure in Make Rules, Up: Portable Make
16616
16617 12.3 Makefile Command Line Prefixes
16618 ===================================
16619
16620 Makefile command lines can be preceded by zero or more of the command
16621 line prefixes ‘-’, ‘@’, and ‘+’, which modify how ‘make’ processes the
16622 command. Although POSIX says these are the only command line prefixes,
16623 some ‘make’ implementations, such as Solaris ‘make’, support the
16624 additional prefixes ‘!’ and ‘?’. Portable makefiles should therefore
16625 avoid using these two characters at the start of a makefile command
16626 line. For example:
16627
16628 mishandled-by-Solaris-make:; ! grep FIXME foo.c
16629 portable-to-Solaris-make:; :;! grep FIXME foo.c
16630
16631 
16632 File: autoconf.info, Node: Special Chars in Names, Next: Backslash-Newline-Empty, Prev: Command Line Prefixes, Up: Portable Make
16633
16634 12.4 Special Characters in Make Macro Names
16635 ===========================================
16636
16637 POSIX limits macro names to nonempty strings containing only ASCII
16638 letters and digits, ‘.’, and ‘_’. Many ‘make’ implementations allow a
16639 wider variety of characters, but portable makefiles should avoid them.
16640 It is portable to start a name with a special character, e.g.,
16641 ‘$(.FOO)’.
16642
16643 Some ancient ‘make’ implementations don’t support leading underscores
16644 in macro names. An example is NEWS-OS 4.2R.
16645
16646 $ cat Makefile
16647 _am_include = #
16648 _am_quote =
16649 all:; @echo this is test
16650 $ make
16651 Make: Must be a separator on rules line 2. Stop.
16652 $ cat Makefile2
16653 am_include = #
16654 am_quote =
16655 all:; @echo this is test
16656 $ make -f Makefile2
16657 this is test
16658
16659 However, this problem is no longer of practical concern.
16660
16661 
16662 File: autoconf.info, Node: Backslash-Newline-Empty, Next: Backslash-Newline Comments, Prev: Special Chars in Names, Up: Portable Make
16663
16664 12.5 Backslash-Newline Before Empty Lines
16665 =========================================
16666
16667 On some versions of HP-UX, ‘make’ reads multiple newlines following a
16668 backslash, continuing to the next non-empty line. For example,
16669
16670 FOO = one \
16671
16672 BAR = two
16673
16674 test:
16675 : FOO is "$(FOO)"
16676 : BAR is "$(BAR)"
16677
16678 shows ‘FOO’ equal to ‘one BAR = two’. Other implementations sensibly
16679 let a backslash continue only to the immediately following line.
16680
16681 
16682 File: autoconf.info, Node: Backslash-Newline Comments, Next: Macros and Submakes, Prev: Backslash-Newline-Empty, Up: Portable Make
16683
16684 12.6 Backslash-Newline in Make Comments
16685 =======================================
16686
16687 According to POSIX, Make comments start with ‘#’ and continue until an
16688 unescaped newline is reached.
16689
16690 $ cat Makefile
16691 # A = foo \
16692 bar \
16693 baz
16694
16695 all:
16696 @echo ok
16697 $ make # GNU make
16698 ok
16699
16700 However this is not always the case. Some implementations discard
16701 everything from ‘#’ through the end of the line, ignoring any trailing
16702 backslash.
16703
16704 $ pmake # BSD make
16705 "Makefile", line 3: Need an operator
16706 Fatal errors encountered -- cannot continue
16707
16708 Therefore, if you want to comment out a multi-line definition, prefix
16709 each line with ‘#’, not only the first.
16710
16711 # A = foo \
16712 # bar \
16713 # baz
16714
16715 
16716 File: autoconf.info, Node: Macros and Submakes, Next: The Make Macro MAKEFLAGS, Prev: Backslash-Newline Comments, Up: Portable Make
16717
16718 12.7 ‘make macro=value’ and Submakes
16719 ====================================
16720
16721 A command-line variable definition such as ‘foo=bar’ overrides any
16722 definition of ‘foo’ in a makefile. Some ‘make’ implementations (such as
16723 GNU ‘make’) propagate this override to subsidiary invocations of ‘make’.
16724 Some other implementations do not pass the substitution along to
16725 submakes.
16726
16727 $ cat Makefile
16728 foo = foo
16729 one:
16730 @printf '%s\n' $(foo)
16731 $(MAKE) two
16732 two:
16733 @printf '%s\n' $(foo)
16734 $ make foo=bar # GNU make 3.79.1
16735 bar
16736 make two
16737 make[1]: Entering directory `/home/adl'
16738 bar
16739 make[1]: Leaving directory `/home/adl'
16740 $ pmake foo=bar # BSD make
16741 bar
16742 pmake two
16743 foo
16744
16745 You have a few possibilities if you do want the ‘foo=bar’ override to
16746 propagate to submakes. One is to use the ‘-e’ option, which causes all
16747 environment variables to have precedence over the makefile macro
16748 definitions, and declare foo as an environment variable:
16749
16750 $ env foo=bar make -e
16751
16752 The ‘-e’ option is propagated to submakes automatically, and since
16753 the environment is inherited between ‘make’ invocations, the ‘foo’ macro
16754 is overridden in submakes as expected.
16755
16756 This syntax (‘foo=bar make -e’) is portable only when used outside of
16757 a makefile, for instance from a script or from the command line. When
16758 run inside a ‘make’ rule, GNU ‘make’ 3.80 and prior versions forget to
16759 propagate the ‘-e’ option to submakes.
16760
16761 Moreover, using ‘-e’ could have unexpected side effects if your
16762 environment contains some other macros usually defined by the makefile.
16763 (See also the note about ‘make -e’ and ‘SHELL’ below.)
16764
16765 If you can foresee all macros that a user might want to override,
16766 then you can propagate them to submakes manually, from your makefile:
16767
16768 foo = foo
16769 one:
16770 @printf '%s\n' $(foo)
16771 $(MAKE) foo=$(foo) two
16772 two:
16773 @printf '%s\n' $(foo)
16774
16775 Another way to propagate a variable to submakes in a portable way is
16776 to expand an extra variable in every invocation of ‘$(MAKE)’ within your
16777 makefile:
16778
16779 foo = foo
16780 one:
16781 @printf '%s\n' $(foo)
16782 $(MAKE) $(SUBMAKEFLAGS) two
16783 two:
16784 @printf '%s\n' $(foo)
16785
16786 Users must be aware that this technique is in use to take advantage
16787 of it, e.g. with ‘make foo=bar SUBMAKEFLAGS='foo=bar'’, but it allows
16788 any macro to be overridden. Makefiles generated by ‘automake’ use this
16789 technique, expanding ‘$(AM_MAKEFLAGS)’ on the command lines of submakes
16790 (*note Automake: (automake)Subdirectories.).
16791
16792 
16793 File: autoconf.info, Node: The Make Macro MAKEFLAGS, Next: The Make Macro SHELL, Prev: Macros and Submakes, Up: Portable Make
16794
16795 12.8 The Make Macro MAKEFLAGS
16796 =============================
16797
16798 POSIX requires ‘make’ to use ‘MAKEFLAGS’ to affect the current and
16799 recursive invocations of make, but allows implementations several
16800 formats for the variable. It is tricky to parse ‘$MAKEFLAGS’ to
16801 determine whether ‘-s’ for silent execution or ‘-k’ for continued
16802 execution are in effect. For example, you cannot assume that the first
16803 space-separated word in ‘$MAKEFLAGS’ contains single-letter options,
16804 since in the Cygwin version of GNU ‘make’ it is either ‘--unix’ or
16805 ‘--win32’ with the second word containing single-letter options.
16806
16807 $ cat Makefile
16808 all:
16809 @printf 'MAKEFLAGS = %s\n' '$(MAKEFLAGS)'
16810 $ make
16811 MAKEFLAGS = --unix
16812 $ make -k
16813 MAKEFLAGS = --unix -k
16814
16815 
16816 File: autoconf.info, Node: The Make Macro SHELL, Next: Parallel Make, Prev: The Make Macro MAKEFLAGS, Up: Portable Make
16817
16818 12.9 The Make Macro ‘SHELL’
16819 ===========================
16820
16821 Many ‘make’ implementations use the ‘$(SHELL)’ macro to spawn shell
16822 processes and execute Make rules. This is a builtin macro with a
16823 default value upplied by ‘make’; the default can be overridden by a
16824 makefile or by a command-line argument, though not by the environment.
16825
16826 Other ‘make’ implementations use other ways to spawn shell processes,
16827 and the POSIX standard for ‘make’ says that portable makefiles should
16828 neither define nor use the ‘$(SHELL)’ macro.
16829
16830 Despite this prohibition, in practice it does not hurt to define and
16831 then possibly use ‘SHELL’ in your makefiles and in some cases it can
16832 help your builds use a better shell to spawn shell processes. So it’s a
16833 good idea to define ‘SHELL’ in your makefiles. If you use Autoconf, you
16834 can use its standard output variable ‘SHELL’ as follows:
16835
16836 SHELL = @SHELL@
16837
16838 If you use Automake, this is done for you.
16839
16840 Do not force ‘SHELL = /bin/sh’ because that is not correct
16841 everywhere. Remember, ‘/bin/sh’ is not POSIX compliant on some systems,
16842 such as Solaris 10. Additionally, DJGPP lacks ‘/bin/sh’, and when its
16843 GNU ‘make’ port sees such a setting it enters a special emulation mode
16844 where features like pipes and redirections are emulated on top of DOS’s
16845 ‘command.com’. Unfortunately this emulation is incomplete; for instance
16846 it does not handle command substitutions. Using ‘@SHELL@’ means that
16847 your makefile will benefit from the same improved shell, such as ‘bash’
16848 or ‘ksh’, that was discovered during ‘configure’, so that you aren’t
16849 fighting two different sets of shell bugs between the two contexts.
16850
16851 Do not rely on whether ‘make’’s ‘SHELL’ settings are exported to
16852 subprocesses, as implementations differ:
16853
16854 $ cat Makefile
16855 all:
16856 @printf '%s\n' '$(SHELL)'
16857 @printenv SHELL
16858 $ env SHELL=/bin/sh make -e SHELL=/bin/ksh # BSD make, AIX make
16859 /bin/ksh
16860 /bin/ksh
16861 $ env SHELL=/bin/sh make -e SHELL=/bin/ksh # GNU make
16862 /bin/ksh
16863 sh
16864
16865 
16866 File: autoconf.info, Node: Parallel Make, Next: Comments in Make Rules, Prev: The Make Macro SHELL, Up: Portable Make
16867
16868 12.10 Parallel Make
16869 ===================
16870
16871 Support for parallel execution in ‘make’ implementation varies.
16872 Generally, using GNU make is your best bet.
16873
16874 When NetBSD or FreeBSD ‘make’ are run in parallel mode, they will
16875 reuse the same shell for multiple commands within one recipe. This can
16876 have various unexpected consequences. For example, changes of
16877 directories or variables persist between recipes, so that:
16878
16879 all:
16880 @var=value; cd /; pwd; echo $$var; echo $$$$
16881 @pwd; echo $$var; echo $$$$
16882
16883 may output the following with ‘make -j1’, at least on NetBSD up to 5.1
16884 and FreeBSD up to 8.2:
16885
16886 /
16887 value
16888 32235
16889 /
16890 value
16891 32235
16892
16893 while without ‘-j1’, or with ‘-B’, the output looks less surprising:
16894
16895 /
16896 value
16897 32238
16898 /tmp
16899
16900 32239
16901
16902 Another consequence is that, if one command in a recipe uses ‘exit 0’ to
16903 indicate a successful exit, the shell will be gone and the remaining
16904 commands of this recipe will not be executed.
16905
16906 The BSD ‘make’ implementations, when run in parallel mode, will also
16907 pass the ‘Makefile’ recipes to the shell through its standard input,
16908 thus making it unusable from the recipes:
16909
16910 $ cat Makefile
16911 read:
16912 @read line; echo LINE: $$line
16913 $ echo foo | make read
16914 LINE: foo
16915 $ echo foo | make -j1 read # NetBSD 5.1 and FreeBSD 8.2
16916 LINE:
16917
16918 Moreover, when FreeBSD ‘make’ (up at least to 8.2) is run in parallel
16919 mode, it implements the ‘@’ and ‘-’ “recipe modifiers” by dynamically
16920 modifying the active shell flags. This behavior has the effects of
16921 potentially clobbering the exit status of recipes silenced with the ‘@’
16922 modifier if they also unset the ‘errexit’ shell flag, and of mangling
16923 the output in unexpected ways:
16924
16925 $ cat Makefile
16926 a:
16927 @echo $$-; set +e; false
16928 b:
16929 -echo $$-; false; echo set -
16930 $ make a; echo status: $?
16931 ehBc
16932 *** Error code 1
16933 status: 1
16934 $ make -j1 a; echo status: $?
16935 ehB
16936 status: 0
16937 $ make b
16938 echo $-; echo set -
16939 hBc
16940 set -
16941 $ make -j1 b
16942 echo $-; echo hvB
16943
16944 You can avoid all these issues by using the ‘-B’ option to enable
16945 compatibility semantics. However, that will effectively also disable
16946 all parallelism as that will cause prerequisites to be updated in the
16947 order they are listed in a rule.
16948
16949 Some make implementations (among them, FreeBSD ‘make’, NetBSD ‘make’,
16950 and Solaris ‘dmake’), when invoked with a ‘-jN’ option, connect the
16951 standard output and standard error of all their child processes to pipes
16952 or temporary regular files. This can lead to subtly different semantics
16953 in the behavior of the spawned processes. For example, even if the
16954 ‘make’ standard output is connected to a tty, the recipe command will
16955 not be:
16956
16957 $ cat Makefile
16958 all:
16959 @test -t 1 && echo "Is a tty" || echo "Is not a tty"
16960 $ make -j 2 # FreeBSD 8.2 make
16961 Is not a tty
16962 $ make -j 2 # NetBSD 5.1 make
16963 --- all ---
16964 Is not a tty
16965 $ dmake -j 2 # Solaris 10 dmake
16966 HOSTNAME --> 1 job
16967 HOSTNAME --> Job output
16968 Is not a tty
16969
16970 On the other hand:
16971
16972 $ make -j 2 # GNU make, Heirloom make
16973 Is a tty
16974
16975 The above examples also show additional status output produced in
16976 parallel mode for targets being updated by Solaris ‘dmake’ and NetBSD
16977 ‘make’ (but _not_ by FreeBSD ‘make’).
16978
16979 Furthermore, parallel runs of those ‘make’ implementations will route
16980 standard error from commands that they spawn into their own standard
16981 output, and may remove leading whitespace from output lines.
16982
16983 
16984 File: autoconf.info, Node: Comments in Make Rules, Next: Newlines in Make Rules, Prev: Parallel Make, Up: Portable Make
16985
16986 12.11 Comments in Make Rules
16987 ============================
16988
16989 Do not try to put comments (lines beginning with ‘#’) in a rule, as they
16990 end the rule. It is OK for a rule line to start with a tab followed by
16991 ‘#’, as a comment passed to a shell that does nothing.
16992
16993 To use the ‘#’ character in a command, put it in a rule not a macro,
16994 as the character cannot portably appear in macros (*note Comments in
16995 Make Macros::). So for example, assuming the output variable
16996 ‘COMMENT_CHAR’ stands for ‘#’, the following replaces ‘@COMMENT_CHAR@’
16997 by ‘#’ in a generated header:
16998
16999 foo.h: foo.h.in
17000 sed -e 's|@''COMMENT_CHAR''@|@COMMENT_CHAR@|g' \
17001 '$(srcdir)/foo.h.in' > $@
17002
17003 The funny shell quoting avoids a substitution at ‘config.status’ run
17004 time of the left-hand side of the ‘sed’ ‘s’ command.
17005
17006 
17007 File: autoconf.info, Node: Newlines in Make Rules, Next: Comments in Make Macros, Prev: Comments in Make Rules, Up: Portable Make
17008
17009 12.12 Newlines in Make Rules
17010 ============================
17011
17012 In shell scripts, newlines can be used inside string literals. But in
17013 the shell statements of ‘Makefile’ rules, this is not possible: a
17014 newline not preceded by a backslash separates commands, whereas a
17015 newline preceded by a backslash becomes part of the shell statement.
17016 So, how can a newline be used in a string literal?
17017
17018 The trick is to set up a shell variable ‘nl’ that contains a newline.
17019 For example, the following uses a multi-line ‘sed’ expression that
17020 appends an empty line after every line of a file:
17021
17022 output: input
17023 eval "$$(printf 'nl="\n"\n')"; \
17024 sed "a\\$$nl" input >$@
17025
17026 
17027 File: autoconf.info, Node: Comments in Make Macros, Next: Trailing whitespace in Make Macros, Prev: Newlines in Make Rules, Up: Portable Make
17028
17029 12.13 Comments in Make Macros
17030 =============================
17031
17032 In macro definitions, text from ‘#’ until line end is ignored, which has
17033 the unfortunate effect of disallowing ‘#’ even in quotes. Thus, the
17034 following does not work:
17035
17036 CPPFLAGS = "-DCOMMENT_CHAR='#'"
17037
17038 as ‘CPPFLAGS’ is expanded to ‘"-DCOMMENT_CHAR='’.
17039
17040 GNU ‘make’, when not in POSIX mode, lets you put ‘#’ into a macro
17041 value by escaping it with a backslash, i.e., ‘\#’. However, this usage
17042 is not portable. *Note Comments in Make Rules::, for a portable
17043 alternative.
17044
17045 Even without quoting involved, comments can have surprising effects,
17046 because the whitespace before them is part of the variable value:
17047
17048 foo = bar # trailing comment
17049 print: ; @echo "$(foo)."
17050
17051 prints ‘bar .’, which is usually not intended, and can expose ‘make’
17052 bugs as described below.
17053
17054 
17055 File: autoconf.info, Node: Trailing whitespace in Make Macros, Next: Command-line Macros and whitespace, Prev: Comments in Make Macros, Up: Portable Make
17056
17057 12.14 Trailing whitespace in Make Macros
17058 ========================================
17059
17060 GNU ‘make’ 3.80 mistreats trailing whitespace in macro substitutions and
17061 appends another spurious suffix:
17062
17063 empty =
17064 foo = bar $(empty)
17065 print: ; @echo $(foo:=.test)
17066
17067 prints ‘bar.test .test’.
17068
17069 BSD and Solaris ‘make’ implementations do not honor trailing
17070 whitespace in macro definitions as POSIX requires:
17071
17072 foo = bar # Note the space after "bar".
17073 print: ; @echo $(foo)t
17074
17075 prints ‘bart’ instead of ‘bar t’. To work around this, you can use a
17076 helper macro as in the previous example.
17077
17078 
17079 File: autoconf.info, Node: Command-line Macros and whitespace, Next: obj/ and Make, Prev: Trailing whitespace in Make Macros, Up: Portable Make
17080
17081 12.15 Command-line Macros and whitespace
17082 ========================================
17083
17084 Some ‘make’ implementations may strip trailing whitespace off of macros
17085 set on the command line in addition to leading whitespace. Further,
17086 some may strip leading whitespace off of macros set from environment
17087 variables:
17088
17089 $ echo 'print: ; @echo "x$(foo)x$(bar)x"' |
17090 foo=' f f ' make -f - bar=' b b '
17091 x f f xb b x # AIX, BSD, GNU make
17092 xf f xb b x # HP-UX
17093 x f f xb bx # Solaris make
17094
17095 
17096 File: autoconf.info, Node: obj/ and Make, Next: make -k Status, Prev: Command-line Macros and whitespace, Up: Portable Make
17097
17098 12.16 The ‘obj/’ Subdirectory and Make
17099 ======================================
17100
17101 Never name one of your subdirectories ‘obj/’ if you don’t like
17102 surprises.
17103
17104 If an ‘obj/’ directory exists, BSD ‘make’ enters it before reading
17105 the makefile. Hence the makefile in the current directory is not read.
17106
17107 $ cat Makefile
17108 all:
17109 echo Hello
17110 $ cat obj/Makefile
17111 all:
17112 echo World
17113 $ make # GNU make
17114 echo Hello
17115 Hello
17116 $ pmake # BSD make
17117 echo World
17118 World
17119
17120 
17121 File: autoconf.info, Node: make -k Status, Next: VPATH and Make, Prev: obj/ and Make, Up: Portable Make
17122
17123 12.17 Exit Status of ‘make -k’
17124 ==============================
17125
17126 Do not rely on the exit status of ‘make -k’. Some implementations
17127 reflect whether they encountered an error in their exit status; other
17128 implementations always succeed.
17129
17130 $ cat Makefile
17131 all:
17132 false
17133 $ make -k; echo exit status: $? # GNU make
17134 false
17135 make: *** [all] Error 1
17136 exit status: 2
17137 $ pmake -k; echo exit status: $? # BSD make
17138 false
17139 *** Error code 1 (continuing)
17140 exit status: 0
17141
17142 
17143 File: autoconf.info, Node: VPATH and Make, Next: Single Suffix Rules, Prev: make -k Status, Up: Portable Make
17144
17145 12.18 ‘VPATH’ and Make
17146 ======================
17147
17148 POSIX does not specify the semantics of ‘VPATH’. Typically, ‘make’
17149 supports ‘VPATH’, but its implementation is not consistent.
17150
17151 Autoconf and Automake support makefiles whose usages of ‘VPATH’ are
17152 portable to recent-enough popular implementations of ‘make’, but to keep
17153 the resulting makefiles portable, a package’s makefile prototypes must
17154 take the following issues into account. These issues are complicated
17155 and are often poorly understood, and installers who use ‘VPATH’ should
17156 expect to find many bugs in this area. If you use ‘VPATH’, the simplest
17157 way to avoid these portability bugs is to stick with GNU ‘make’, since
17158 it is the most commonly-used ‘make’ among Autoconf users.
17159
17160 Here are some known issues with some ‘VPATH’ implementations.
17161
17162 * Menu:
17163
17164 * Variables listed in VPATH:: ‘VPATH’ must be literal on ancient hosts
17165 * VPATH and Double-colon:: Problems with ‘::’ on ancient hosts
17166 * $< in Explicit Rules:: ‘$<’ does not work in ordinary rules
17167 * Automatic Rule Rewriting:: ‘VPATH’ goes wild on Solaris
17168 * Make Target Lookup:: More details about ‘VPATH’ lookup
17169
17170 
17171 File: autoconf.info, Node: Variables listed in VPATH, Next: VPATH and Double-colon, Up: VPATH and Make
17172
17173 12.18.1 Variables listed in ‘VPATH’
17174 -----------------------------------
17175
17176 Do not set ‘VPATH’ to the value of another variable, for example ‘VPATH
17177 = $(srcdir)’, because some ancient versions of ‘make’ do not do variable
17178 substitutions on the value of ‘VPATH’. For example, use this
17179
17180 srcdir = @srcdir@
17181 VPATH = @srcdir@
17182
17183 rather than ‘VPATH = $(srcdir)’. Note that with GNU Automake, there is
17184 no need to set this yourself.
17185
17186 
17187 File: autoconf.info, Node: VPATH and Double-colon, Next: $< in Explicit Rules, Prev: Variables listed in VPATH, Up: VPATH and Make
17188
17189 12.18.2 ‘VPATH’ and Double-colon Rules
17190 --------------------------------------
17191
17192 With ancient versions of Sun ‘make’, any assignment to ‘VPATH’ causes
17193 ‘make’ to execute only the first set of double-colon rules. However,
17194 this problem is no longer of practical concern.
17195
17196 
17197 File: autoconf.info, Node: $< in Explicit Rules, Next: Automatic Rule Rewriting, Prev: VPATH and Double-colon, Up: VPATH and Make
17198
17199 12.18.3 ‘$<’ Not Supported in Explicit Rules
17200 --------------------------------------------
17201
17202 Using ‘$<’ in explicit rules is not portable. The prerequisite file
17203 must be named explicitly in the rule. If you want to find the
17204 prerequisite via a ‘VPATH’ search, you have to code the whole thing
17205 manually. *Note Build Directories::.
17206
17207 
17208 File: autoconf.info, Node: Automatic Rule Rewriting, Next: Make Target Lookup, Prev: $< in Explicit Rules, Up: VPATH and Make
17209
17210 12.18.4 Automatic Rule Rewriting
17211 --------------------------------
17212
17213 Some ‘make’ implementations, such as Solaris, search for prerequisites
17214 in ‘VPATH’ and then rewrite each occurrence as a plain word in the rule.
17215 For instance:
17216
17217 # This isn't portable to GNU make.
17218 VPATH = ../pkg/src
17219 f.c: if.c
17220 cp if.c f.c
17221
17222 executes ‘cp ../pkg/src/if.c f.c’ if ‘if.c’ is found in ‘../pkg/src’.
17223
17224 However, this rule leads to real problems in practice. For example,
17225 if the source directory contains an ordinary file named ‘test’ that is
17226 used in a dependency, Solaris ‘make’ rewrites commands like ‘if test -r
17227 foo; ...’ to ‘if ../pkg/src/test -r foo; ...’, which is typically
17228 undesirable. In fact, ‘make’ is completely unaware of shell syntax used
17229 in the rules, so the VPATH rewrite can potentially apply to _any_
17230 whitespace-separated word in a rule, including shell variables,
17231 functions, and keywords.
17232
17233 $ mkdir build
17234 $ cd build
17235 $ cat > Makefile <<'END'
17236 VPATH = ..
17237 all: arg func for echo
17238 func () { for arg in "$$@"; do echo $$arg; done; }; \
17239 func "hello world"
17240 END
17241 $ touch ../arg ../func ../for ../echo
17242 $ make
17243 ../func () { ../for ../arg in "$@"; do ../echo $arg; done; }; \
17244 ../func "hello world"
17245 sh: syntax error at line 1: `do' unexpected
17246 *** Error code 2
17247
17248 To avoid this problem, portable makefiles should never mention a source
17249 file or dependency whose name is that of a shell keyword like ‘for’ or
17250 ‘until’, a shell command like ‘cat’ or ‘gcc’ or ‘test’, or a shell
17251 function or variable used in the corresponding ‘Makefile’ recipe.
17252
17253 Because of these problems GNU ‘make’ and many other ‘make’
17254 implementations do not rewrite commands, so portable makefiles should
17255 search ‘VPATH’ manually. It is tempting to write this:
17256
17257 # This isn't portable to Solaris make.
17258 VPATH = ../pkg/src
17259 f.c: if.c
17260 cp `test -f if.c || echo $(VPATH)/`if.c f.c
17261
17262 However, the “prerequisite rewriting” still applies here. So if ‘if.c’
17263 is in ‘../pkg/src’, Solaris ‘make’ executes
17264
17265 cp `test -f ../pkg/src/if.c || echo ../pkg/src/`if.c f.c
17266
17267 which reduces to
17268
17269 cp if.c f.c
17270
17271 and thus fails. Oops.
17272
17273 A simple workaround, and good practice anyway, is to use ‘$?’ and
17274 ‘$@’ when possible:
17275
17276 VPATH = ../pkg/src
17277 f.c: if.c
17278 cp $? $@
17279
17280 but this does not generalize well to commands with multiple
17281 prerequisites. A more general workaround is to rewrite the rule so that
17282 the prerequisite ‘if.c’ never appears as a plain word. For example,
17283 these three rules would be safe, assuming ‘if.c’ is in ‘../pkg/src’ and
17284 the other files are in the working directory:
17285
17286 VPATH = ../pkg/src
17287 f.c: if.c f1.c
17288 cat `test -f ./if.c || echo $(VPATH)/`if.c f1.c >$@
17289 g.c: if.c g1.c
17290 cat `test -f 'if.c' || echo $(VPATH)/`if.c g1.c >$@
17291 h.c: if.c h1.c
17292 cat `test -f "if.c" || echo $(VPATH)/`if.c h1.c >$@
17293
17294 Things get worse when your prerequisites are in a macro.
17295
17296 VPATH = ../pkg/src
17297 HEADERS = f.h g.h h.h
17298 install-HEADERS: $(HEADERS)
17299 for i in $(HEADERS); do \
17300 $(INSTALL) -m 644 \
17301 `test -f $$i || echo $(VPATH)/`$$i \
17302 $(DESTDIR)$(includedir)/$$i; \
17303 done
17304
17305 The above ‘install-HEADERS’ rule is not Solaris-proof because ‘for i
17306 in $(HEADERS);’ is expanded to ‘for i in f.h g.h h.h;’ where ‘f.h’ and
17307 ‘g.h’ are plain words and are hence subject to ‘VPATH’ adjustments.
17308
17309 If the three files are in ‘../pkg/src’, the rule is run as:
17310
17311 for i in ../pkg/src/f.h ../pkg/src/g.h h.h; do \
17312 install -m 644 \
17313 `test -f $i || echo ../pkg/src/`$i \
17314 /usr/local/include/$i; \
17315 done
17316
17317 where the two first ‘install’ calls fail. For instance, consider the
17318 ‘f.h’ installation:
17319
17320 install -m 644 \
17321 `test -f ../pkg/src/f.h || \
17322 echo ../pkg/src/ \
17323 `../pkg/src/f.h \
17324 /usr/local/include/../pkg/src/f.h;
17325
17326 It reduces to:
17327
17328 install -m 644 \
17329 ../pkg/src/f.h \
17330 /usr/local/include/../pkg/src/f.h;
17331
17332 Note that the manual ‘VPATH’ search did not cause any problems here;
17333 however this command installs ‘f.h’ in an incorrect directory.
17334
17335 Trying to quote ‘$(HEADERS)’ in some way, as we did for ‘foo.c’ a few
17336 makefiles ago, does not help:
17337
17338 install-HEADERS: $(HEADERS)
17339 headers='$(HEADERS)'; \
17340 for i in $$headers; do \
17341 $(INSTALL) -m 644 \
17342 `test -f $$i || echo $(VPATH)/`$$i \
17343 $(DESTDIR)$(includedir)/$$i; \
17344 done
17345
17346 Now, ‘headers='$(HEADERS)'’ macro-expands to:
17347
17348 headers='f.h g.h h.h'
17349
17350 but ‘g.h’ is still a plain word. (As an aside, the idiom
17351 ‘headers='$(HEADERS)'; for i in $$headers;’ is a good idea if
17352 ‘$(HEADERS)’ can be empty, because some shells diagnose a syntax error
17353 on ‘for i in;’.)
17354
17355 One workaround is to strip this unwanted ‘../pkg/src/’ prefix
17356 manually:
17357
17358 VPATH = ../pkg/src
17359 HEADERS = f.h g.h h.h
17360 install-HEADERS: $(HEADERS)
17361 headers='$(HEADERS)'; \
17362 for i in $$headers; do \
17363 i=`expr "$$i" : '$(VPATH)/\(.*\)'`;
17364 $(INSTALL) -m 644 \
17365 `test -f $$i || echo $(VPATH)/`$$i \
17366 $(DESTDIR)$(includedir)/$$i; \
17367 done
17368
17369 Automake does something similar.
17370
17371 
17372 File: autoconf.info, Node: Make Target Lookup, Prev: Automatic Rule Rewriting, Up: VPATH and Make
17373
17374 12.18.5 Make Target Lookup
17375 --------------------------
17376
17377 GNU ‘make’ uses a complex algorithm to decide when it should use files
17378 found via a ‘VPATH’ search. *Note How Directory Searches are Performed:
17379 (make)Search Algorithm.
17380
17381 If a target needs to be rebuilt, GNU ‘make’ discards the file name
17382 found during the ‘VPATH’ search for this target, and builds the file
17383 locally using the file name given in the makefile. If a target does not
17384 need to be rebuilt, GNU ‘make’ uses the file name found during the
17385 ‘VPATH’ search.
17386
17387 Other ‘make’ implementations, like NetBSD ‘make’, are easier to
17388 describe: the file name found during the ‘VPATH’ search is used whether
17389 the target needs to be rebuilt or not. Therefore new files are created
17390 locally, but existing files are updated at their ‘VPATH’ location.
17391
17392 OpenBSD and FreeBSD ‘make’, however, never perform a ‘VPATH’ search
17393 for a dependency that has an explicit rule. This is extremely annoying.
17394
17395 When attempting a ‘VPATH’ build for an autoconfiscated package (e.g.,
17396 ‘mkdir build && cd build && ../configure’), this means GNU ‘make’ builds
17397 everything locally in the ‘build’ directory, while BSD ‘make’ builds new
17398 files locally and updates existing files in the source directory.
17399
17400 $ cat Makefile
17401 VPATH = ..
17402 all: foo.x bar.x
17403 foo.x bar.x: newer.x
17404 @echo Building $@
17405 $ touch ../bar.x
17406 $ touch ../newer.x
17407 $ make # GNU make
17408 Building foo.x
17409 Building bar.x
17410 $ pmake # NetBSD make
17411 Building foo.x
17412 Building ../bar.x
17413 $ fmake # FreeBSD make, OpenBSD make
17414 Building foo.x
17415 Building bar.x
17416 $ make # GNU make
17417 Building foo.x
17418 $ pmake # NetBSD make
17419 Building foo.x
17420 $ fmake # FreeBSD make, OpenBSD make
17421 Building foo.x
17422 Building bar.x
17423
17424 Note how NetBSD ‘make’ updates ‘../bar.x’ in its VPATH location, and
17425 how FreeBSD and OpenBSD ‘make’ always update ‘bar.x’, even when
17426 ‘../bar.x’ is up to date.
17427
17428 Another point worth mentioning is that once GNU ‘make’ has decided to
17429 ignore a ‘VPATH’ file name (e.g., it ignored ‘../bar.x’ in the above
17430 example) it continues to ignore it when the target occurs as a
17431 prerequisite of another rule.
17432
17433 The following example shows that GNU ‘make’ does not look up ‘bar.x’
17434 in ‘VPATH’ before performing the ‘.x.y’ rule, because it ignored the
17435 ‘VPATH’ result of ‘bar.x’ while running the ‘bar.x: newer.x’ rule.
17436
17437 $ cat Makefile
17438 VPATH = ..
17439 all: bar.y
17440 bar.x: newer.x
17441 @echo Building $@
17442 .SUFFIXES: .x .y
17443 .x.y:
17444 cp $< $@
17445 $ touch ../bar.x
17446 $ touch ../newer.x
17447 $ make # GNU make
17448 Building bar.x
17449 cp bar.x bar.y
17450 cp: cannot stat 'bar.x': No such file or directory
17451 make: *** [bar.y] Error 1
17452 $ pmake # NetBSD make
17453 Building ../bar.x
17454 cp ../bar.x bar.y
17455 $ rm bar.y
17456 $ fmake # FreeBSD make, OpenBSD make
17457 echo Building bar.x
17458 cp bar.x bar.y
17459 cp: cannot stat 'bar.x': No such file or directory
17460 *** Error code 1
17461
17462 Note that if you drop away the command from the ‘bar.x: newer.x’
17463 rule, GNU ‘make’ magically starts to work: it knows that ‘bar.x’ hasn’t
17464 been updated, therefore it doesn’t discard the result from ‘VPATH’
17465 (‘../bar.x’) in succeeding uses. FreeBSD and OpenBSD still don’t work,
17466 though.
17467
17468 $ cat Makefile
17469 VPATH = ..
17470 all: bar.y
17471 bar.x: newer.x
17472 .SUFFIXES: .x .y
17473 .x.y:
17474 cp $< $@
17475 $ touch ../bar.x
17476 $ touch ../newer.x
17477 $ make # GNU make
17478 cp ../bar.x bar.y
17479 $ rm bar.y
17480 $ pmake # NetBSD make
17481 cp ../bar.x bar.y
17482 $ rm bar.y
17483 $ fmake # FreeBSD make, OpenBSD make
17484 cp bar.x bar.y
17485 cp: cannot stat 'bar.x': No such file or directory
17486 *** Error code 1
17487
17488 It seems the sole solution that would please every ‘make’
17489 implementation is to never rely on ‘VPATH’ searches for targets. In
17490 other words, ‘VPATH’ should be reserved to sources that are not built.
17491
17492 
17493 File: autoconf.info, Node: Single Suffix Rules, Next: Timestamps and Make, Prev: VPATH and Make, Up: Portable Make
17494
17495 12.19 Single Suffix Rules and Separated Dependencies
17496 ====================================================
17497
17498 A “Single Suffix Rule” is basically a usual suffix (inference) rule
17499 (‘.from.to:’), but which _destination_ suffix is empty (‘.from:’).
17500
17501 “Separated dependencies” simply refers to listing the prerequisite of
17502 a target, without defining a rule. Usually one can list on the one hand
17503 side, the rules, and on the other hand side, the dependencies.
17504
17505 Solaris ‘make’ does not support separated dependencies for targets
17506 defined by single suffix rules:
17507
17508 $ cat Makefile
17509 .SUFFIXES: .in
17510 foo: foo.in
17511 .in:
17512 cp $< $@
17513 $ touch foo.in
17514 $ make
17515 $ ls
17516 Makefile foo.in
17517
17518 while GNU Make does:
17519
17520 $ gmake
17521 cp foo.in foo
17522 $ ls
17523 Makefile foo foo.in
17524
17525 Note it works without the ‘foo: foo.in’ dependency.
17526
17527 $ cat Makefile
17528 .SUFFIXES: .in
17529 .in:
17530 cp $< $@
17531 $ make foo
17532 cp foo.in foo
17533
17534 and it works with double suffix inference rules:
17535
17536 $ cat Makefile
17537 foo.out: foo.in
17538 .SUFFIXES: .in .out
17539 .in.out:
17540 cp $< $@
17541 $ make
17542 cp foo.in foo.out
17543
17544 As a result, in such a case, you have to write target rules.
17545
17546 
17547 File: autoconf.info, Node: Timestamps and Make, Prev: Single Suffix Rules, Up: Portable Make
17548
17549 12.20 Timestamp Resolution and Make
17550 ===================================
17551
17552 Traditionally, file timestamps had 1-second resolution, and ‘make’ used
17553 those timestamps to determine whether one file was newer than the other.
17554 However, many modern file systems have timestamps with 1-nanosecond
17555 resolution. Some ‘make’ implementations look at the entire timestamp;
17556 others ignore the fractional part, which can lead to incorrect results.
17557 Normally this is not a problem, but in some extreme cases you may need
17558 to use tricks like ‘sleep 1’ to work around timestamp truncation bugs.
17559
17560 Traditionally, commands like ‘cp -p’ and ‘touch -r’ did not copy file
17561 timestamps to their full resolutions (*note Limitations of Usual Tools:
17562 touch.). Hence you should be wary of rules like this:
17563
17564 dest: src
17565 cp -p src dest
17566
17567 as ‘dest’ often appears to be older than ‘src’ after the timestamp is
17568 truncated, and this can cause ‘make’ to do needless rework the next time
17569 it is invoked. To work around this problem, you can use a timestamp
17570 file, e.g.:
17571
17572 dest-stamp: src
17573 cp -p src dest
17574 echo >dest-stamp
17575
17576 Apart from timestamp resolution, there are also differences in
17577 handling equal timestamps. Although POSIX suggests that ‘make’ update a
17578 target with the same timestamp as its newest prerequisite, only HP-UX
17579 ‘make’ is known to do so; GNU and other ‘make’ implementations do not
17580 update, a behavior that POSIX also allows.
17581
17582 The HP-UX behavior can cause spurious rebuilds and this in turn can
17583 cause ‘make’ to fail if it tries to rebuild generated files in a
17584 possibly read-only source tree with tools not present on the build
17585 machine. Conversely, if a source file is updated immediately after
17586 running ‘make’ in a file system with low-resolution timestamps, the GNU
17587 behavior can cause a later ‘make’ to neglect rebuilds and quietly
17588 generate incorrect results. To avoid both these problems, use GNU
17589 ‘make’ on a platform with high-resolution timestamps.
17590
17591 
17592 File: autoconf.info, Node: Portable C and C++, Next: Manual Configuration, Prev: Portable Make, Up: Top
17593
17594 13 Portable C and C++ Programming
17595 *********************************
17596
17597 C and C++ programs often use low-level features of the underlying
17598 system, and therefore are often more difficult to make portable to other
17599 platforms.
17600
17601 Several standards have been developed to help make your programs more
17602 portable. If you write programs with these standards in mind, you can
17603 have greater confidence that your programs work on a wide variety of
17604 systems. *Note Language Standards Supported by GCC: (gcc)Standards, for
17605 a list of C-related standards. Many programs also assume the POSIX
17606 standard (https://en.wikipedia.org/wiki/POSIX).
17607
17608 The first widely used C variant was K&R C, which predates any C
17609 standard. K&R C compilers are no longer of practical interest, though,
17610 and Autoconf assumes at least C89, the first C standard, which is
17611 sometimes called “C90” due to a delay in standardization. C has since
17612 gone through the standards C99, C11, C17, and C23, and Autoconf is
17613 compatible with all these standards.
17614
17615 Program portability is a huge topic, and this section can only
17616 briefly introduce common pitfalls. *Note Portability between System
17617 Types: (standards)System Portability, for more information.
17618
17619 * Menu:
17620
17621 * Varieties of Unportability:: How to make your programs unportable
17622 * Integer Overflow:: When integers get too large
17623 * Preprocessor Arithmetic:: ‘#if’ expression problems
17624 * Null Pointers:: Properties of null pointers
17625 * Buffer Overruns:: Subscript errors and the like
17626 * Volatile Objects:: ‘volatile’ and signals
17627 * Floating Point Portability:: Portable floating-point arithmetic
17628 * Exiting Portably:: Exiting and the exit status
17629
17630 
17631 File: autoconf.info, Node: Varieties of Unportability, Next: Integer Overflow, Up: Portable C and C++
17632
17633 13.1 Varieties of Unportability
17634 ===============================
17635
17636 Autoconf tests and ordinary programs often need to test what is allowed
17637 on a system, and therefore they may need to deliberately exceed the
17638 boundaries of what the standards allow, if only to see whether an
17639 optional feature is present. When you write such a program, you should
17640 keep in mind the difference between constraints, unspecified behavior,
17641 and undefined behavior.
17642
17643 In C, a “constraint” is a rule that the compiler must enforce. An
17644 example constraint is that C programs must not declare a bit-field with
17645 negative width. Tests can therefore reliably assume that programs with
17646 negative-width bit-fields are rejected by a compiler that conforms to
17647 the standard.
17648
17649 “Unspecified behavior” is valid behavior, where the standard allows
17650 multiple possibilities. For example, the order of evaluation of
17651 function arguments is unspecified. Some unspecified behavior is
17652 “implementation-defined”, i.e., documented by the implementation, but
17653 since Autoconf tests cannot read the documentation they cannot
17654 distinguish between implementation-defined and other unspecified
17655 behavior. It is common for Autoconf tests to probe implementations to
17656 determine otherwise-unspecified behavior.
17657
17658 “Undefined behavior” is invalid behavior, where the standard allows
17659 the implementation to do anything it pleases. For example,
17660 dereferencing a null pointer leads to undefined behavior. If possible,
17661 test programs should avoid undefined behavior, since a program with
17662 undefined behavior might succeed on a test that should fail.
17663
17664 The above rules apply to programs that are intended to conform to the
17665 standard. However, strictly-conforming programs are quite rare, since
17666 the standards are so limiting. A major goal of Autoconf is to support
17667 programs that use implementation features not described by the standard,
17668 and it is fairly common for test programs to violate the above rules, if
17669 the programs work well enough in practice.
17670
17671 
17672 File: autoconf.info, Node: Integer Overflow, Next: Preprocessor Arithmetic, Prev: Varieties of Unportability, Up: Portable C and C++
17673
17674 13.2 Integer Overflow
17675 =====================
17676
17677 Although some traditional C programs assume that signed integer overflow
17678 wraps around reliably using two’s complement arithmetic, the C standard
17679 says that program behavior is undefined on overflow, and these C
17680 programs may not work on many modern implementations.
17681
17682 * Menu:
17683
17684 * Integer Overflow Basics:: Why integer overflow is a problem
17685 * Signed Overflow Examples:: Examples of code assuming wraparound
17686 * Optimization and Wraparound:: Optimizations that break uses of wraparound
17687 * Signed Overflow Advice:: Practical advice for signed overflow issues
17688 * Signed Integer Division:: ‘INT_MIN / -1’ and ‘INT_MIN % -1’
17689
17690 
17691 File: autoconf.info, Node: Integer Overflow Basics, Next: Signed Overflow Examples, Up: Integer Overflow
17692
17693 13.2.1 Basics of Integer Overflow
17694 ---------------------------------
17695
17696 In languages like C, integer overflow wraps around for unsigned integer
17697 types that are at least as wide as ‘unsigned int’; e.g., ‘UINT_MAX + 1’
17698 yields zero. This is guaranteed by the C standard and is portable in
17699 practice, unless you specify aggressive, nonstandard optimization
17700 options suitable only for special applications.
17701
17702 In contrast, the C standard says that signed integer overflow leads
17703 to undefined behavior where a program can do anything, including dumping
17704 core or overrunning a buffer. The misbehavior can even precede the
17705 overflow. Such an overflow can occur during addition, subtraction,
17706 multiplication, division, and left shift. It can even occur for
17707 unsigned types like ‘unsigned short int’ that are narrower than ‘int’,
17708 as values of these types are widened to ‘int’ before computation.
17709
17710 Despite this requirement of the standard, some C programs assume that
17711 signed integer overflow silently wraps around modulo a power of two,
17712 using two’s complement arithmetic, so long as you convert the resulting
17713 value to a signed integer type. These programs can have problems,
17714 especially when optimization is enabled. If you assume a GCC-like
17715 compiler, you can work around the problems by compiling with GCC’s
17716 ‘-fwrapv’ option; however, this is not portable.
17717
17718 For historical reasons C17 and earlier also allowed implementations
17719 with ones’ complement or signed magnitude arithmetic, but C23 requires
17720 two’s complement and it is safe to assume two’s complement nowadays.
17721
17722 Also, overflow can occur when converting an out-of-range value to a
17723 signed integer type. Here a standard implementation must define what
17724 happens, and this can include raising an exception. Although practical
17725 implementations typically wrap around silently in this case, a few
17726 debugging implementations trap instead.
17727
17728 
17729 File: autoconf.info, Node: Signed Overflow Examples, Next: Optimization and Wraparound, Prev: Integer Overflow Basics, Up: Integer Overflow
17730
17731 13.2.2 Examples of Code Assuming Wraparound Overflow
17732 ----------------------------------------------------
17733
17734 There was long a tension between what the C standard requires for signed
17735 integer overflow, and what traditional C programs commonly assumed. The
17736 standard allows aggressive optimizations based on assumptions that
17737 overflow never occurs, but traditionally many C programs relied on
17738 overflow wrapping around. Although these programs did not conform to
17739 the standard, they formerly worked in practice because traditionally
17740 compilers did not optimize in such a way that would break the programs.
17741 Nowadays, though, compilers do perform these optimizations, so portable
17742 programs can no longer assume reliable wraparound on signed integer
17743 overflow.
17744
17745 The C Standard says that if a program has signed integer overflow its
17746 behavior is undefined, and the undefined behavior can even precede the
17747 overflow. To take an extreme example:
17748
17749 if (password == expected_password)
17750 allow_superuser_privileges ();
17751 else if (counter++ == INT_MAX)
17752 abort ();
17753 else
17754 printf ("%d password mismatches\n", counter);
17755
17756 If the ‘int’ variable ‘counter’ equals ‘INT_MAX’, ‘counter++’ must
17757 overflow and the behavior is undefined, so the C standard allows the
17758 compiler to optimize away the test against ‘INT_MAX’ and the ‘abort’
17759 call. Worse, if an earlier bug in the program lets the compiler deduce
17760 that ‘counter == INT_MAX’ or that ‘counter’ previously overflowed, the C
17761 standard allows the compiler to optimize away the password test and
17762 generate code that allows superuser privileges unconditionally.
17763
17764 Here is an example derived from the 7th Edition Unix implementation
17765 of ‘atoi’ (1979-01-10):
17766
17767 char *p;
17768 int f, n;
17769 ...
17770 while (*p >= '0' && *p <= '9')
17771 n = n * 10 + *p++ - '0';
17772 return (f ? -n : n);
17773
17774 Even if the input string is in range, on most modern machines this has
17775 signed overflow when computing the most negative integer (the ‘-n’
17776 overflows) or a value near an extreme integer (the ‘+’ overflows).
17777
17778 Here is another example, derived from the 7th Edition implementation
17779 of ‘rand’ (1979-01-10). Here the programmer expects both multiplication
17780 and addition to wrap on overflow:
17781
17782 static long int randx = 1;
17783 ...
17784 randx = randx * 1103515245 + 12345;
17785 return (randx >> 16) & 077777;
17786
17787 In the following example, derived from the GNU C Library 2.15
17788 implementation of ‘mktime’ (2012-03-21), the code assumes wraparound
17789 arithmetic in ‘+’ to detect signed overflow:
17790
17791 time_t t, t1, t2;
17792 int sec_requested, sec_adjustment;
17793 ...
17794 t1 = t + sec_requested;
17795 t2 = t1 + sec_adjustment;
17796 if (((t1 < t) != (sec_requested < 0))
17797 | ((t2 < t1) != (sec_adjustment < 0)))
17798 return -1;
17799
17800 Although some of these examples will likely behave as if signed
17801 integer overflow wraps around reliably, other examples are likely to
17802 misbehave when optimization is enabled. All these examples should be
17803 avoided in portable code because signed integer overflow is not reliable
17804 on modern systems, and it’s not worth worrying about which of these
17805 examples happen to work on most platforms and which do not.
17806
17807 
17808 File: autoconf.info, Node: Optimization and Wraparound, Next: Signed Overflow Advice, Prev: Signed Overflow Examples, Up: Integer Overflow
17809
17810 13.2.3 Optimizations That Break Wraparound Arithmetic
17811 -----------------------------------------------------
17812
17813 Compilers sometimes generate code that is incompatible with wraparound
17814 integer arithmetic. A simple example is an algebraic simplification: a
17815 compiler might translate ‘(i * 2000) / 1000’ to ‘i * 2’ because it
17816 assumes that ‘i * 2000’ does not overflow. The translation is not
17817 equivalent to the original when overflow occurs: e.g., in the typical
17818 case of 32-bit signed two’s complement wraparound ‘int’, if ‘i’ has type
17819 ‘int’ and value ‘1073742’, the original expression returns −2147483 but
17820 the optimized version returns the mathematically correct value 2147484.
17821
17822 More subtly, loop induction optimizations often exploit the undefined
17823 behavior of signed overflow. Consider the following contrived function
17824 ‘sumc’:
17825
17826 int
17827 sumc (int lo, int hi)
17828 {
17829 int sum = 0;
17830 for (int i = lo; i <= hi; i++)
17831 sum ^= i * 53;
17832 return sum;
17833 }
17834
17835 To avoid multiplying by 53 each time through the loop, an optimizing
17836 compiler might internally transform ‘sumc’ to the equivalent of the
17837 following:
17838
17839 int
17840 transformed_sumc (int lo, int hi)
17841 {
17842 int sum = 0;
17843 int hic = hi * 53;
17844 for (int ic = lo * 53; ic <= hic; ic += 53)
17845 sum ^= ic;
17846 return sum;
17847 }
17848
17849 This transformation is allowed by the C standard, but it is invalid for
17850 wraparound arithmetic when ‘INT_MAX / 53 < hi’, because then the
17851 overflow in computing expressions like ‘hi * 53’ can cause the
17852 expression ‘i <= hi’ to yield a different value from the transformed
17853 expression ‘ic <= hic’.
17854
17855 For this reason, compilers that use loop induction and similar
17856 techniques often do not support reliable wraparound arithmetic when a
17857 loop induction variable like ‘ic’ is involved. Since loop induction
17858 variables are generated by the compiler, and are not visible in the
17859 source code, it is not always trivial to say whether the problem affects
17860 your code.
17861
17862 Hardly any code actually depends on wraparound arithmetic in cases
17863 like these, so in practice these loop induction optimizations are almost
17864 always useful. However, edge cases in this area can cause problems.
17865 For example:
17866
17867 for (int j = 1; 0 < j; j *= 2)
17868 test (j);
17869
17870 Here, the loop attempts to iterate through all powers of 2 that ‘int’
17871 can represent, but the C standard allows a compiler to optimize away the
17872 comparison and generate an infinite loop, under the argument that
17873 behavior is undefined on overflow. As of this writing this optimization
17874 is done on some platforms by GCC with ‘-O2’, so this code is not
17875 portable in practice.
17876
17877 
17878 File: autoconf.info, Node: Signed Overflow Advice, Next: Signed Integer Division, Prev: Optimization and Wraparound, Up: Integer Overflow
17879
17880 13.2.4 Practical Advice for Signed Overflow Issues
17881 --------------------------------------------------
17882
17883 Ideally the safest approach is to avoid signed integer overflow
17884 entirely. For example, instead of multiplying two signed integers, you
17885 can convert them to double-width integers, multiply the wider values,
17886 then test whether the result is in the narrower range. Or you can use
17887 more-complicated code employing unsigned integers of the same width.
17888
17889 Rewriting code in this way will be inconvenient, though, especially
17890 if the signed values might be negative and no wider type is available.
17891 Using unsigned arithmetic to check for overflow is particularly painful
17892 to do portably and efficiently when dealing with an integer type like
17893 ‘uid_t’ whose width and signedness vary from platform to platform.
17894 Also, this approach may hurt performance.
17895
17896 Hence it is often useful to maintain code that needs wraparound on
17897 overflow, instead of rewriting the code. The rest of this section
17898 attempts to give practical advice for this situation.
17899
17900 To detect integer overflow portably when attempting operations like
17901 ‘sum = a + b’, you can use the C23 ‘<stdckdint.h>’ macros ‘ckd_add’,
17902 ‘ckd_sub’, and ‘ckd_mul’. The following code adds two integers with
17903 overflow wrapping around reliably in the sum:
17904
17905 #include <stdckdint.h>
17906 ...
17907 /* Set sum = a + b, with wraparound. */
17908 if (ckd_add (&sum, a, b))
17909 /* 'sum' has just the low order bits. */;
17910 else
17911 /* 'sum' is the correct answer. */;
17912
17913 To be portable to pre-C23 platforms you can use Gnulib’s ‘stdckdint’
17914 module, which emulates this part of C23 (*note Gnulib::). Invoking the
17915 ‘stdckdint’ macros typically costs just one machine instruction for the
17916 arithmetic and another instruction for the rare branch on overflow.
17917
17918 If your code uses a signed loop index, make sure that the index
17919 cannot overflow, along with all signed expressions derived from the
17920 index. Here is a contrived example of problematic code with two
17921 instances of overflow.
17922
17923 for (int i = INT_MAX - 10; i <= INT_MAX; i++)
17924 if (i + 1 < 0)
17925 {
17926 report_overflow ();
17927 break;
17928 }
17929
17930 Because of the two overflows, a compiler might optimize away or
17931 transform the two comparisons in a way that is incompatible with the
17932 wraparound assumption.
17933
17934 If your code is intended to be compiled only by GCC and assumes
17935 wraparound behavior, and you want to insulate it against any GCC
17936 optimizations that would fail to support that behavior, you should use
17937 GCC’s ‘-fwrapv’ option, which causes signed overflow to wrap around
17938 reliably (except for division and remainder, as discussed in the next
17939 section).
17940
17941 If you need to write portable code and therefore cannot assume that
17942 signed integer overflow wraps around reliably, you should consider
17943 debugging with a GCC option that causes signed overflow to raise an
17944 exception. These options include ‘-fsanitize=undefined’ and ‘-ftrapv’.
17945
17946 
17947 File: autoconf.info, Node: Signed Integer Division, Prev: Signed Overflow Advice, Up: Integer Overflow
17948
17949 13.2.5 Signed Integer Division and Integer Overflow
17950 ---------------------------------------------------
17951
17952 Overflow in signed integer division is not always harmless: for example,
17953 on CPUs of the i386 family, dividing ‘INT_MIN’ by ‘-1’ yields a SIGFPE
17954 signal which by default terminates the program. Worse, taking the
17955 remainder of these two values typically yields the same signal on these
17956 CPUs, behavior that the C standard allows.
17957
17958 
17959 File: autoconf.info, Node: Preprocessor Arithmetic, Next: Null Pointers, Prev: Integer Overflow, Up: Portable C and C++
17960
17961 13.3 Preprocessor Arithmetic
17962 ============================
17963
17964 In C99 and later, preprocessor arithmetic, used for ‘#if’ expressions,
17965 must be evaluated as if all signed values are of type ‘intmax_t’ and all
17966 unsigned values of type ‘uintmax_t’. Many compilers are buggy in this
17967 area, though. For example, as of 2007, Sun C mishandles ‘#if LLONG_MIN
17968 < 0’ on a platform with 32-bit ‘long int’ and 64-bit ‘long long int’.
17969 Also, some older preprocessors mishandle constants ending in ‘LL’. To
17970 work around these problems, you can compute the value of expressions
17971 like ‘LONG_MAX < LLONG_MAX’ at ‘configure’-time rather than at
17972 ‘#if’-time.
17973
17974 
17975 File: autoconf.info, Node: Null Pointers, Next: Buffer Overruns, Prev: Preprocessor Arithmetic, Up: Portable C and C++
17976
17977 13.4 Properties of Null Pointers
17978 ================================
17979
17980 Most modern hosts reliably fail when you attempt to dereference a null
17981 pointer.
17982
17983 On almost all modern hosts, null pointers use an all-bits-zero
17984 internal representation, so you can reliably use ‘memset’ with 0 to set
17985 all the pointers in an array to null values.
17986
17987 If ‘p’ is a null pointer to an object type, the C expression ‘p + 0’
17988 always evaluates to ‘p’ on modern hosts, even though the standard says
17989 that it has undefined behavior.
17990
17991 
17992 File: autoconf.info, Node: Buffer Overruns, Next: Volatile Objects, Prev: Null Pointers, Up: Portable C and C++
17993
17994 13.5 Buffer Overruns and Subscript Errors
17995 =========================================
17996
17997 Buffer overruns and subscript errors are the most common dangerous
17998 errors in C programs. They result in undefined behavior because storing
17999 outside an array typically modifies storage that is used by some other
18000 object, and most modern systems lack runtime checks to catch these
18001 errors. Programs should not rely on buffer overruns being caught.
18002
18003 There is one exception to the usual rule that a portable program
18004 cannot address outside an array. In C, it is valid to compute the
18005 address just past an object, e.g., ‘&a[N]’ where ‘a’ has ‘N’ elements,
18006 so long as you do not dereference the resulting pointer. But it is not
18007 valid to compute the address just before an object, e.g., ‘&a[-1]’; nor
18008 is it valid to compute two past the end, e.g., ‘&a[N+1]’. On most
18009 platforms ‘&a[-1] < &a[0] && &a[N] < &a[N+1]’, but this is not reliable
18010 in general, and it is usually easy enough to avoid the potential
18011 portability problem, e.g., by allocating an extra unused array element
18012 at the start or end.
18013
18014 Valgrind (https://www.valgrind.org/) can catch many overruns. GCC
18015 users might also consider using the ‘-fsanitize=’ options to catch
18016 overruns. *Note Program Instrumentation Options: (gcc)Instrumentation
18017 Options.
18018
18019 Buffer overruns are usually caused by off-by-one errors, but there
18020 are more subtle ways to get them.
18021
18022 Using ‘int’ values to index into an array or compute array sizes
18023 causes problems on typical 64-bit hosts where an array index might be
18024 2^{31} or larger. Index values of type ‘size_t’ avoid this problem, but
18025 cannot be negative. Index values of type ‘ptrdiff_t’ are signed, and
18026 are wide enough in practice.
18027
18028 If you add or multiply two numbers to calculate an array size, e.g.,
18029 ‘malloc (x * sizeof y + z)’, havoc ensues if the addition or
18030 multiplication overflows.
18031
18032 Many implementations of the ‘alloca’ function silently misbehave and
18033 can generate buffer overflows if given sizes that are too large. The
18034 size limits are implementation dependent, but are at least 4000 bytes on
18035 all platforms that we know about.
18036
18037 The standard functions ‘asctime’, ‘asctime_r’, ‘ctime’, ‘ctime_r’,
18038 and ‘gets’ are prone to buffer overflows, and portable code should not
18039 use them unless the inputs are known to be within certain limits. The
18040 time-related functions can overflow their buffers if given timestamps
18041 out of range (e.g., a year less than -999 or greater than 9999).
18042 Time-related buffer overflows cannot happen with recent-enough versions
18043 of the GNU C library, but are possible with other implementations. The
18044 ‘gets’ function is the worst, since it almost invariably overflows its
18045 buffer when presented with an input line larger than the buffer.
18046
18047 
18048 File: autoconf.info, Node: Volatile Objects, Next: Floating Point Portability, Prev: Buffer Overruns, Up: Portable C and C++
18049
18050 13.6 Volatile Objects
18051 =====================
18052
18053 The keyword ‘volatile’ is often misunderstood in portable code. Its use
18054 inhibits some memory-access optimizations, but programmers often wish
18055 that it had a different meaning than it actually does.
18056
18057 ‘volatile’ was designed for code that accesses special objects like
18058 memory-mapped device registers whose contents spontaneously change.
18059 Such code is inherently low-level, and it is difficult to specify
18060 portably what ‘volatile’ means in these cases. The C standard says,
18061 “What constitutes an access to an object that has volatile-qualified
18062 type is implementation-defined,” so in theory each implementation is
18063 supposed to fill in the gap by documenting what ‘volatile’ means for
18064 that implementation. In practice, though, this documentation is usually
18065 absent or incomplete.
18066
18067 One area of confusion is the distinction between objects defined with
18068 volatile types, and volatile lvalues. From the C standard’s point of
18069 view, an object defined with a volatile type has externally visible
18070 behavior. You can think of such objects as having little oscilloscope
18071 probes attached to them, so that the user can observe some properties of
18072 accesses to them, just as the user can observe data written to output
18073 files. However, accesses via volatile lvalues to ordinary objects are
18074 merely side effects (i.e., changes to the state of the execution
18075 environment), and the implementation is not required to document their
18076 visibility any further. For example:
18077
18078 /* Declare and access a volatile object.
18079 Accesses to X are "visible" to users. */
18080 static int volatile x;
18081 x = 1;
18082
18083 /* Access two ordinary objects via a volatile lvalue.
18084 Although each read and write is a side effect,
18085 the accesses are not directly "visible" to users. */
18086 int y = 0;
18087 int *z = malloc (sizeof *z);
18088 *z = 7;
18089 int volatile *p;
18090 p = &y;
18091 *p = *p + 1;
18092 p = z;
18093 *p = *p + 1;
18094
18095 Programmers often wish that ‘volatile’ meant “Perform the memory
18096 access here and now, without merging several memory accesses, without
18097 changing the memory word size, and without reordering.” But the C
18098 standard does not require this. For objects defined with a volatile
18099 type, accesses must be done before the next sequence point; but
18100 otherwise merging, reordering, and word-size change is allowed.
18101
18102 Even when accessing objects defined with a volatile type, the C
18103 standard allows only extremely limited signal handlers: in C23 the
18104 behavior is undefined if a signal handler refers to any non-local object
18105 that is not a lock-free atomic object and that is not ‘constexpr’ (other
18106 than by writing to a ‘sig_atomic_t volatile’ object), or calls any
18107 standard library function other than from a small set that includes
18108 ‘abort’, ‘_Exit’, ‘quick_exit’, some ‘<stdatomic.h>’ functions, and
18109 ‘signal’. Hence C compilers need not worry about a signal handler
18110 disturbing ordinary computation. POSIX allows some additional behavior
18111 in a portable signal handler, but is still quite restrictive. *Note
18112 When is a Volatile Object Accessed?: (gcc)Volatiles, for some
18113 restrictions imposed by GCC. *Note Defining Signal Handlers:
18114 (libc)Defining Handlers, for some restrictions imposed by the GNU C
18115 library. Restrictions differ on other platforms.
18116
18117 If possible, it is best to use a signal handler that fits within the
18118 limits imposed by the C and POSIX standards.
18119
18120 If this is not practical, you can try the following rules of thumb.
18121 A signal handler should access only volatile lvalues, preferably lvalues
18122 that refer to objects defined with a volatile type, and should not
18123 assume that the accessed objects have an internally consistent state if
18124 they are larger than a machine word. Furthermore, installers should
18125 employ compilers and compiler options that are commonly used for
18126 building operating system kernels, because kernels often need more from
18127 ‘volatile’ than the C Standard requires, and installers who compile an
18128 application in a similar environment can sometimes benefit from the
18129 extra constraints imposed by kernels on compilers. Admittedly we are
18130 hand-waving somewhat here, as there are few guarantees in this area; the
18131 rules of thumb may help to fix some bugs but there is a good chance that
18132 they will not fix them all.
18133
18134 For ‘volatile’, C++ has the same problems that C does. Multithreaded
18135 applications have even more problems with ‘volatile’, but they are
18136 beyond the scope of this section.
18137
18138 The bottom line is that using ‘volatile’ typically hurts performance
18139 but should not hurt correctness. In some cases its use does help
18140 correctness, but these cases are often so poorly understood that all too
18141 often adding ‘volatile’ to a data structure merely alleviates some
18142 symptoms of a bug while not fixing the bug in general.
18143
18144 
18145 File: autoconf.info, Node: Floating Point Portability, Next: Exiting Portably, Prev: Volatile Objects, Up: Portable C and C++
18146
18147 13.7 Floating Point Portability
18148 ===============================
18149
18150 Almost all modern systems use IEEE-754 floating point, and it is safe to
18151 assume IEEE-754 in most portable code these days. For more information,
18152 please see David Goldberg’s classic paper What Every Computer Scientist
18153 Should Know About Floating-Point Arithmetic
18154 (https://www.validlab.com/goldberg/paper.pdf).
18155
18156 
18157 File: autoconf.info, Node: Exiting Portably, Prev: Floating Point Portability, Up: Portable C and C++
18158
18159 13.8 Exiting Portably
18160 =====================
18161
18162 A C or C++ program can exit with status N by returning N from the ‘main’
18163 function. Portable programs are supposed to exit either with status 0
18164 or ‘EXIT_SUCCESS’ to succeed, or with status ‘EXIT_FAILURE’ to fail, but
18165 in practice it is portable to fail by exiting with status 1, and test
18166 programs that assume POSIX can fail by exiting with status values from 1
18167 through 255.
18168
18169 A program can also exit with status N by passing N to the ‘exit’
18170 function, and a program can fail by calling the ‘abort’ function. If a
18171 program is specialized to just some platforms, it can fail by calling
18172 functions specific to those platforms, e.g., ‘_exit’ (POSIX). However,
18173 like other functions, an exit function should be declared, typically by
18174 including a header. For example, if a C program calls ‘exit’, it should
18175 include ‘stdlib.h’ either directly or via the default includes (*note
18176 Default Includes::).
18177
18178 A program can fail due to undefined behavior such as dereferencing a
18179 null pointer, but this is not recommended as undefined behavior allows
18180 an implementation to do whatever it pleases and this includes exiting
18181 successfully.
18182
18183 
18184 File: autoconf.info, Node: Manual Configuration, Next: Site Configuration, Prev: Portable C and C++, Up: Top
18185
18186 14 Manual Configuration
18187 ***********************
18188
18189 A few kinds of features can’t be guessed automatically by running test
18190 programs. For example, the details of the object-file format, or
18191 special options that need to be passed to the compiler or linker.
18192 Autoconf provides a uniform method for handling unguessable features, by
18193 giving each operating system a “canonical system type”, also known as a
18194 “canonical name” or “target triplet”.
18195
18196 If you use any of the macros described in this chapter, you must
18197 distribute the helper scripts ‘config.guess’ and ‘config.sub’ along with
18198 your source code. Some Autoconf macros use these macros internally, so
18199 you may need to distribute these scripts even if you do not use any of
18200 these macros yourself. *Note Input::, for information about the
18201 ‘AC_CONFIG_AUX_DIR’ macro which you can use to control in which
18202 directory ‘configure’ looks for helper scripts, and where to get the
18203 scripts from.
18204
18205 * Menu:
18206
18207 * Specifying Target Triplets:: Specifying target triplets
18208 * Canonicalizing:: Getting the canonical system type
18209 * Using System Type:: What to do with the system type
18210
18211 
18212 File: autoconf.info, Node: Specifying Target Triplets, Next: Canonicalizing, Up: Manual Configuration
18213
18214 14.1 Specifying target triplets
18215 ===============================
18216
18217 Autoconf-generated ‘configure’ scripts can make decisions based on a
18218 canonical name for the system type, or “target triplet”, which has the
18219 form: ‘CPU-VENDOR-OS’, where OS can be ‘SYSTEM’ or ‘KERNEL-SYSTEM’
18220
18221 ‘configure’ can usually guess the canonical name for the type of
18222 system it’s running on. To do so it runs a script called
18223 ‘config.guess’, which infers the name using the ‘uname’ command or
18224 symbols predefined by the C preprocessor.
18225
18226 Alternately, the user can specify the system type with command line
18227 arguments to ‘configure’ (*note System Types::. Doing so is necessary
18228 when cross-compiling. In the most complex case of cross-compiling,
18229 three system types are involved. The options to specify them are:
18230
18231 ‘--build=BUILD-TYPE’
18232 the type of system on which the package is being configured and
18233 compiled. It defaults to the result of running ‘config.guess’.
18234 Specifying a BUILD-TYPE that differs from HOST-TYPE enables
18235 cross-compilation mode.
18236
18237 ‘--host=HOST-TYPE’
18238 the type of system on which the package runs. By default it is the
18239 same as the build machine. The tools that get used to build and
18240 manipulate binaries will, by default, all be prefixed with
18241 ‘HOST-TYPE-’, such as ‘HOST-TYPE-gcc’, ‘HOST-TYPE-g++’,
18242 ‘HOST-TYPE-ar’, and ‘HOST-TYPE-nm’. If the binaries produced by
18243 these tools can be executed by the build system, the configure
18244 script will make use of it in ‘AC_RUN_IFELSE’ invocations;
18245 otherwise, cross-compilation mode is enabled. Specifying a
18246 HOST-TYPE that differs from BUILD-TYPE, when BUILD-TYPE was also
18247 explicitly specified, equally enables cross-compilation mode.
18248
18249 ‘--target=TARGET-TYPE’
18250 the type of system for which any compiler tools in the package
18251 produce code (rarely needed). By default, it is the same as host.
18252
18253 If you mean to override the result of ‘config.guess’ but still
18254 produce binaries for the build machine, use ‘--build’, not ‘--host’.
18255
18256 So, for example, to produce binaries for 64-bit MinGW, use a command
18257 like this:
18258
18259 ./configure --host=x86_64-w64-mingw64
18260
18261 If your system has the ability to execute MinGW binaries but you
18262 don’t want to make use of this feature and instead prefer
18263 cross-compilation guesses, use a command like this:
18264
18265 ./configure --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw64
18266
18267 Note that if you do not specify ‘--host’, ‘configure’ fails if it can’t
18268 run the code generated by the specified compiler. For example,
18269 configuring as follows fails:
18270
18271 ./configure CC=x86_64-w64-mingw64-gcc
18272
18273 When cross-compiling, ‘configure’ will warn about any tools
18274 (compilers, linkers, assemblers) whose name is not prefixed with the
18275 host type. This is an aid to users performing cross-compilation.
18276 Continuing the example above, if a cross-compiler named ‘cc’ is used
18277 with a native ‘pkg-config’, then libraries found by ‘pkg-config’ will
18278 likely cause subtle build failures; but using the names
18279 ‘x86_64-w64-mingw64-gcc’ and ‘x86_64-w64-mingw64-pkg-config’ avoids any
18280 confusion. Avoiding the warning is as simple as creating the correct
18281 symlinks naming the cross tools.
18282
18283 ‘configure’ recognizes short aliases for some system types; for
18284 example, ‘mingw64’ can be used instead of ‘x86_64-pc-mingw64’.
18285 ‘configure’ runs a script called ‘config.sub’ to canonicalize system
18286 type aliases.
18287
18288 This section deliberately omits the description of the obsolete
18289 interface; see *note Hosts and Cross-Compilation::.
18290
18291 
18292 File: autoconf.info, Node: Canonicalizing, Next: Using System Type, Prev: Specifying Target Triplets, Up: Manual Configuration
18293
18294 14.2 Getting the Canonical System Type
18295 ======================================
18296
18297 The following macros make the system type available to ‘configure’
18298 scripts.
18299
18300 The variables ‘build_alias’, ‘host_alias’, and ‘target_alias’ are
18301 always exactly the arguments of ‘--build’, ‘--host’, and ‘--target’; in
18302 particular, they are left empty if the user did not use them, even if
18303 the corresponding ‘AC_CANONICAL’ macro was run. Any configure script
18304 may use these variables anywhere. These are the variables that should
18305 be used when in interaction with the user.
18306
18307 If you need to recognize some special environments based on their
18308 system type, run the following macros to get canonical system names.
18309 These variables are not set before the macro call.
18310
18311 — Macro: AC_CANONICAL_BUILD
18312 Compute the canonical build-system type variable, ‘build’, and its
18313 three individual parts ‘build_cpu’, ‘build_vendor’, and ‘build_os’.
18314
18315 If ‘--build’ was specified, then ‘build’ is the canonicalization of
18316 ‘build_alias’ by ‘config.sub’, otherwise it is determined by the
18317 shell script ‘config.guess’.
18318
18319 — Macro: AC_CANONICAL_HOST
18320 Compute the canonical host-system type variable, ‘host’, and its
18321 three individual parts ‘host_cpu’, ‘host_vendor’, and ‘host_os’.
18322
18323 If ‘--host’ was specified, then ‘host’ is the canonicalization of
18324 ‘host_alias’ by ‘config.sub’, otherwise it defaults to ‘build’.
18325
18326 — Macro: AC_CANONICAL_TARGET
18327 Compute the canonical target-system type variable, ‘target’, and
18328 its three individual parts ‘target_cpu’, ‘target_vendor’, and
18329 ‘target_os’.
18330
18331 If ‘--target’ was specified, then ‘target’ is the canonicalization
18332 of ‘target_alias’ by ‘config.sub’, otherwise it defaults to ‘host’.
18333
18334 Note that there can be artifacts due to the backward compatibility
18335 code. *Note Hosts and Cross-Compilation::, for more.
18336
18337 
18338 File: autoconf.info, Node: Using System Type, Prev: Canonicalizing, Up: Manual Configuration
18339
18340 14.3 Using the System Type
18341 ==========================
18342
18343 In ‘configure.ac’ the system type is generally used by one or more
18344 ‘case’ statements to select system-specifics. Shell wildcards can be
18345 used to match a group of system types.
18346
18347 For example, an extra assembler code object file could be chosen,
18348 giving access to a CPU cycle counter register. ‘$(CYCLE_OBJ)’ in the
18349 following would be used in a makefile to add the object to a program or
18350 library.
18351
18352 AS_CASE([$host],
18353 [aarch64*-*-*], [CYCLE_OBJ=pmccntr.o],
18354 [i?86-*-*], [CYCLE_OBJ=rdtsc.o],
18355 [CYCLE_OBJ=""])
18356 AC_SUBST([CYCLE_OBJ])
18357
18358 ‘AC_CONFIG_LINKS’ (*note Configuration Links::) is another good way
18359 to select variant source files, for example optimized code for some
18360 CPUs. The configured CPU type doesn’t always indicate exact CPU types,
18361 so some runtime capability checks may be necessary too.
18362
18363 AS_CASE([$host],
18364 [aarch64*-*-*], [AC_CONFIG_LINKS([dither.c:aarch64/dither.c])],
18365 [powerpc*-*-*], [AC_CONFIG_LINKS([dither.c:powerpc/dither.c])],
18366 [AC_CONFIG_LINKS([dither.c:generic/dither.c])])
18367
18368 The host system type can also be used to find cross-compilation tools
18369 with ‘AC_CHECK_TOOL’ (*note Generic Programs::).
18370
18371 The above examples all show ‘$host’, since this is where the code is
18372 going to run. Only rarely is it necessary to test ‘$build’ (which is
18373 where the build is being done).
18374
18375 Whenever you’re tempted to use ‘$host’ it’s worth considering whether
18376 some sort of probe would be better. New system types come along
18377 periodically or previously missing features are added. Well-written
18378 probes can adapt themselves to such things, but hard-coded lists of
18379 names can’t. Here are some guidelines,
18380
18381 • Availability of libraries and library functions should always be
18382 checked by probing.
18383 • Variant behavior of system calls is best identified with runtime
18384 tests if possible, but bug workarounds or obscure difficulties
18385 might have to be driven from ‘$host’.
18386 • Assembler code is inevitably highly CPU-specific and is best
18387 selected according to ‘$host_cpu’.
18388 • Assembler variations like underscore prefix on globals or ELF
18389 versus COFF type directives are however best determined by probing,
18390 perhaps even examining the compiler output.
18391
18392 ‘$target’ is for use by a package creating a compiler or similar.
18393 For ordinary packages it’s meaningless and should not be used. It
18394 indicates what the created compiler should generate code for, if it can
18395 cross-compile. ‘$target’ generally selects various hard-coded CPU and
18396 system conventions, since usually the compiler or tools under
18397 construction themselves determine how the target works.
18398
18399 
18400 File: autoconf.info, Node: Site Configuration, Next: Running configure Scripts, Prev: Manual Configuration, Up: Top
18401
18402 15 Site Configuration
18403 *********************
18404
18405 ‘configure’ scripts support several kinds of local configuration
18406 decisions. There are ways for users to specify where external software
18407 packages are, include or exclude optional features, install programs
18408 under modified names, and set default values for ‘configure’ options.
18409
18410 * Menu:
18411
18412 * Help Formatting:: Customizing ‘configure --help’
18413 * External Software:: Working with other optional software
18414 * Package Options:: Selecting optional features
18415 * Pretty Help Strings:: Formatting help string
18416 * Option Checking:: Controlling checking of ‘configure’ options
18417 * Site Details:: Configuring site details
18418 * Transforming Names:: Changing program names when installing
18419 * Site Defaults:: Giving ‘configure’ local defaults
18420
18421 
18422 File: autoconf.info, Node: Help Formatting, Next: External Software, Up: Site Configuration
18423
18424 15.1 Controlling Help Output
18425 ============================
18426
18427 Users consult ‘configure --help’ to learn of configuration decisions
18428 specific to your package. By default, ‘configure’ breaks this output
18429 into sections for each type of option; within each section, help strings
18430 appear in the order ‘configure.ac’ defines them:
18431
18432 Optional Features:
18433 ...
18434 --enable-bar include bar
18435
18436 Optional Packages:
18437 ...
18438 --with-foo use foo
18439
18440 — Macro: AC_PRESERVE_HELP_ORDER
18441
18442 Request an alternate ‘--help’ format, in which options of all types
18443 appear together, in the order defined. Call this macro before any
18444 ‘AC_ARG_ENABLE’ or ‘AC_ARG_WITH’.
18445
18446 Optional Features and Packages:
18447 ...
18448 --enable-bar include bar
18449 --with-foo use foo
18450
18451 
18452 File: autoconf.info, Node: External Software, Next: Package Options, Prev: Help Formatting, Up: Site Configuration
18453
18454 15.2 Working With External Software
18455 ===================================
18456
18457 Some packages require, or can optionally use, other software packages
18458 that are already installed. The user can give ‘configure’ command line
18459 options to specify which such external software to use. The options
18460 have one of these forms:
18461
18462 --with-PACKAGE[=ARG]
18463 --without-PACKAGE
18464
18465 For example, ‘--with-gnu-ld’ means work with the GNU linker instead
18466 of some other linker. ‘--with-x’ means work with The X Window System.
18467
18468 The user can give an argument by following the package name with ‘=’
18469 and the argument. Giving an argument of ‘no’ is for packages that are
18470 used by default; it says to _not_ use the package. An argument that is
18471 neither ‘yes’ nor ‘no’ could include a name or number of a version of
18472 the other package, to specify more precisely which other package this
18473 program is supposed to work with. If no argument is given, it defaults
18474 to ‘yes’. ‘--without-PACKAGE’ is equivalent to ‘--with-PACKAGE=no’.
18475
18476 Normally ‘configure’ scripts complain about ‘--with-PACKAGE’ options
18477 that they do not support. *Note Option Checking::, for details, and for
18478 how to override the defaults.
18479
18480 For each external software package that may be used, ‘configure.ac’
18481 should call ‘AC_ARG_WITH’ to detect whether the ‘configure’ user asked
18482 to use it. Whether each package is used or not by default, and which
18483 arguments are valid, is up to you.
18484
18485 — Macro: AC_ARG_WITH(PACKAGE, HELP-STRING, [ACTION-IF-GIVEN],
18486 [ACTION-IF-NOT-GIVEN])
18487 If the user gave ‘configure’ the option ‘--with-PACKAGE’ or
18488 ‘--without-PACKAGE’, run shell commands ACTION-IF-GIVEN. If
18489 neither option was given, run shell commands ACTION-IF-NOT-GIVEN.
18490 The name PACKAGE indicates another software package that this
18491 program should work with. It should consist only of alphanumeric
18492 characters, dashes, plus signs, and dots.
18493
18494 The option’s argument is available to the shell commands
18495 ACTION-IF-GIVEN in the shell variable ‘withval’, which is actually
18496 just the value of the shell variable named ‘with_PACKAGE’, with any
18497 non-alphanumeric characters in PACKAGE changed into ‘_’. You may
18498 use that variable instead, if you wish.
18499
18500 Note that ACTION-IF-NOT-GIVEN is not expanded until the point that
18501 ‘AC_ARG_WITH’ was expanded. If you need the value of
18502 ‘with_PACKAGE’ set to a default value by the time argument parsing
18503 is completed, use ‘m4_divert_text’ to the ‘DEFAULTS’ diversion
18504 (*note m4_divert_text::) (if done as an argument to ‘AC_ARG_WITH’,
18505 also provide non-diverted text to avoid a shell syntax error).
18506
18507 The argument HELP-STRING is a description of the option that looks
18508 like this:
18509 --with-readline support fancy command line editing
18510
18511 HELP-STRING may be more than one line long, if more detail is
18512 needed. Just make sure the columns line up in ‘configure --help’.
18513 Avoid tabs in the help string. The easiest way to provide the
18514 proper leading whitespace is to format your HELP-STRING with the
18515 macro ‘AS_HELP_STRING’ (*note Pretty Help Strings::).
18516
18517 The following example shows how to use the ‘AC_ARG_WITH’ macro in a
18518 common situation. You want to let the user decide whether to
18519 enable support for an external library (e.g., the readline
18520 library); if the user specified neither ‘--with-readline’ nor
18521 ‘--without-readline’, you want to enable support for readline only
18522 if the library is available on the system.
18523
18524 AC_ARG_WITH([readline],
18525 [AS_HELP_STRING([--with-readline],
18526 [support fancy command line editing @<:@default=check@:>@])],
18527 [],
18528 [: m4_divert_text([DEFAULTS], [with_readline=check])])
18529
18530 LIBREADLINE=
18531 AS_IF([test "x$with_readline" != xno],
18532 [AC_CHECK_LIB([readline], [main],
18533 [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
18534 AC_DEFINE([HAVE_LIBREADLINE], [1],
18535 [Define if you have libreadline])
18536 ],
18537 [if test "x$with_readline" != xcheck; then
18538 AC_MSG_FAILURE(
18539 [--with-readline was given, but test for readline failed])
18540 fi
18541 ], -lncurses)])
18542
18543 The next example shows how to use ‘AC_ARG_WITH’ to give the user
18544 the possibility to enable support for the readline library, in case
18545 it is still experimental and not well tested, and is therefore
18546 disabled by default.
18547
18548 AC_ARG_WITH([readline],
18549 [AS_HELP_STRING([--with-readline],
18550 [enable experimental support for readline])],
18551 [],
18552 [with_readline=no])
18553
18554 LIBREADLINE=
18555 AS_IF([test "x$with_readline" != xno],
18556 [AC_CHECK_LIB([readline], [main],
18557 [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
18558 AC_DEFINE([HAVE_LIBREADLINE], [1],
18559 [Define if you have libreadline])
18560 ],
18561 [AC_MSG_FAILURE(
18562 [--with-readline was given, but test for readline failed])],
18563 [-lncurses])])
18564
18565 The last example shows how to use ‘AC_ARG_WITH’ to give the user
18566 the possibility to disable support for the readline library, given
18567 that it is an important feature and that it should be enabled by
18568 default.
18569
18570 AC_ARG_WITH([readline],
18571 [AS_HELP_STRING([--without-readline],
18572 [disable support for readline])],
18573 [],
18574 [with_readline=yes])
18575
18576 LIBREADLINE=
18577 AS_IF([test "x$with_readline" != xno],
18578 [AC_CHECK_LIB([readline], [main],
18579 [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
18580 AC_DEFINE([HAVE_LIBREADLINE], [1],
18581 [Define if you have libreadline])
18582 ],
18583 [AC_MSG_FAILURE(
18584 [readline test failed (--without-readline to disable)])],
18585 [-lncurses])])
18586
18587 These three examples can be easily adapted to the case where
18588 ‘AC_ARG_ENABLE’ should be preferred to ‘AC_ARG_WITH’ (see *note
18589 Package Options::).
18590
18591 
18592 File: autoconf.info, Node: Package Options, Next: Pretty Help Strings, Prev: External Software, Up: Site Configuration
18593
18594 15.3 Choosing Package Options
18595 =============================
18596
18597 If a software package has optional compile-time features, the user can
18598 give ‘configure’ command line options to specify whether to compile
18599 them. The options have one of these forms:
18600
18601 --enable-FEATURE[=ARG]
18602 --disable-FEATURE
18603
18604 These options allow users to choose which optional features to build
18605 and install. ‘--enable-FEATURE’ options should never make a feature
18606 behave differently or cause one feature to replace another. They should
18607 only cause parts of the program to be built rather than left out.
18608
18609 The user can give an argument by following the feature name with ‘=’
18610 and the argument. Giving an argument of ‘no’ requests that the feature
18611 _not_ be made available. A feature with an argument looks like
18612 ‘--enable-debug=stabs’. If no argument is given, it defaults to ‘yes’.
18613 ‘--disable-FEATURE’ is equivalent to ‘--enable-FEATURE=no’.
18614
18615 Normally ‘configure’ scripts complain about ‘--enable-PACKAGE’
18616 options that they do not support. *Note Option Checking::, for details,
18617 and for how to override the defaults.
18618
18619 For each optional feature, ‘configure.ac’ should call ‘AC_ARG_ENABLE’
18620 to detect whether the ‘configure’ user asked to include it. Whether
18621 each feature is included or not by default, and which arguments are
18622 valid, is up to you.
18623
18624 — Macro: AC_ARG_ENABLE(FEATURE, HELP-STRING, [ACTION-IF-GIVEN],
18625 [ACTION-IF-NOT-GIVEN])
18626 If the user gave ‘configure’ the option ‘--enable-FEATURE’ or
18627 ‘--disable-FEATURE’, run shell commands ACTION-IF-GIVEN. If
18628 neither option was given, run shell commands ACTION-IF-NOT-GIVEN.
18629 The name FEATURE indicates an optional user-level facility. It
18630 should consist only of alphanumeric characters, dashes, plus signs,
18631 and dots.
18632
18633 The option’s argument is available to the shell commands
18634 ACTION-IF-GIVEN in the shell variable ‘enableval’, which is
18635 actually just the value of the shell variable named
18636 ‘enable_FEATURE’, with any non-alphanumeric characters in FEATURE
18637 changed into ‘_’. You may use that variable instead, if you wish.
18638 The HELP-STRING argument is like that of ‘AC_ARG_WITH’ (*note
18639 External Software::).
18640
18641 Note that ACTION-IF-NOT-GIVEN is not expanded until the point that
18642 ‘AC_ARG_ENABLE’ was expanded. If you need the value of
18643 ‘enable_FEATURE’ set to a default value by the time argument
18644 parsing is completed, use ‘m4_divert_text’ to the ‘DEFAULTS’
18645 diversion (*note m4_divert_text::) (if done as an argument to
18646 ‘AC_ARG_ENABLE’, also provide non-diverted text to avoid a shell
18647 syntax error).
18648
18649 You should format your HELP-STRING with the macro ‘AS_HELP_STRING’
18650 (*note Pretty Help Strings::).
18651
18652 See the examples suggested with the definition of ‘AC_ARG_WITH’
18653 (*note External Software::) to get an idea of possible applications
18654 of ‘AC_ARG_ENABLE’.
18655
18656 
18657 File: autoconf.info, Node: Pretty Help Strings, Next: Option Checking, Prev: Package Options, Up: Site Configuration
18658
18659 15.4 Making Your Help Strings Look Pretty
18660 =========================================
18661
18662 Properly formatting the ‘help strings’ which are used in ‘AC_ARG_WITH’
18663 (*note External Software::) and ‘AC_ARG_ENABLE’ (*note Package
18664 Options::) can be challenging. Specifically, you want your own ‘help
18665 strings’ to line up in the appropriate columns of ‘configure --help’
18666 just like the standard Autoconf ‘help strings’ do. This is the purpose
18667 of the ‘AS_HELP_STRING’ macro.
18668
18669 — Macro: AS_HELP_STRING(LEFT-HAND-SIDE, RIGHT-HAND-SIDE [INDENT-COLUMN
18670 = 26], [WRAP-COLUMN = 79])
18671
18672 Expands into a help string that looks pretty when the user executes
18673 ‘configure --help’. It is typically used in ‘AC_ARG_WITH’ (*note
18674 External Software::) or ‘AC_ARG_ENABLE’ (*note Package Options::).
18675 The following example makes this clearer.
18676
18677 AC_ARG_WITH([foo],
18678 [AS_HELP_STRING([--with-foo],
18679 [use foo (default is no)])],
18680 [use_foo=$withval],
18681 [use_foo=no])
18682
18683 Then the last few lines of ‘configure --help’ appear like this:
18684
18685 --enable and --with options recognized:
18686 --with-foo use foo (default is no)
18687
18688 Macro expansion is performed on the first argument. However, the
18689 second argument of ‘AS_HELP_STRING’ is treated as a whitespace
18690 separated list of text to be reformatted, and is not subject to
18691 macro expansion. Since it is not expanded, it should not be double
18692 quoted. *Note Autoconf Language::, for a more detailed
18693 explanation.
18694
18695 The ‘AS_HELP_STRING’ macro is particularly helpful when the
18696 LEFT-HAND-SIDE and/or RIGHT-HAND-SIDE are composed of macro
18697 arguments, as shown in the following example. Be aware that
18698 LEFT-HAND-SIDE may not expand to unbalanced quotes, although
18699 quadrigraphs can be used.
18700
18701 AC_DEFUN([MY_ARG_WITH],
18702 [AC_ARG_WITH(m4_translit([[$1]], [_], [-]),
18703 [AS_HELP_STRING([--with-m4_translit([$1], [_], [-])],
18704 [use $1 (default is $2)])],
18705 [use_[]$1=$withval],
18706 [use_[]$1=$2])])
18707 MY_ARG_WITH([a_b], [no])
18708 Here, the last few lines of ‘configure --help’ will include:
18709
18710 --enable and --with options recognized:
18711 --with-a-b use a_b (default is no)
18712
18713 The parameters INDENT-COLUMN and WRAP-COLUMN were introduced in
18714 Autoconf 2.62. Generally, they should not be specified; they exist
18715 for fine-tuning of the wrapping.
18716 AS_HELP_STRING([--option], [description of option])
18717 ⇒ --option description of option
18718 AS_HELP_STRING([--option], [description of option], [15], [30])
18719 ⇒ --option description of
18720 ⇒ option
18721
18722 
18723 File: autoconf.info, Node: Option Checking, Next: Site Details, Prev: Pretty Help Strings, Up: Site Configuration
18724
18725 15.5 Controlling Checking of ‘configure’ Options
18726 ================================================
18727
18728 The ‘configure’ script checks its command-line options against a list of
18729 known options, like ‘--help’ or ‘--config-cache’. An unknown option
18730 ordinarily indicates a mistake by the user and ‘configure’ halts with an
18731 error. However, by default unknown ‘--with-PACKAGE’ and
18732 ‘--enable-FEATURE’ options elicit only a warning, to support configuring
18733 entire source trees.
18734
18735 Source trees often contain multiple packages with a top-level
18736 ‘configure’ script that uses the ‘AC_CONFIG_SUBDIRS’ macro (*note
18737 Subdirectories::). Because the packages generally support different
18738 ‘--with-PACKAGE’ and ‘--enable-FEATURE’ options, the GNU Coding
18739 Standards say they must accept unrecognized options without halting.
18740 Even a warning message is undesirable here, so ‘AC_CONFIG_SUBDIRS’
18741 automatically disables the warnings.
18742
18743 This default behavior may be modified in two ways. First, the
18744 installer can invoke ‘configure --disable-option-checking’ to disable
18745 these warnings, or invoke ‘configure --enable-option-checking=fatal’
18746 options to turn them into fatal errors, respectively. Second, the
18747 maintainer can use ‘AC_DISABLE_OPTION_CHECKING’.
18748
18749 — Macro: AC_DISABLE_OPTION_CHECKING
18750
18751 By default, disable warnings related to any unrecognized
18752 ‘--with-PACKAGE’ or ‘--enable-FEATURE’ options. This is implied by
18753 ‘AC_CONFIG_SUBDIRS’.
18754
18755 The installer can override this behavior by passing
18756 ‘--enable-option-checking’ (enable warnings) or
18757 ‘--enable-option-checking=fatal’ (enable errors) to ‘configure’.
18758
18759 
18760 File: autoconf.info, Node: Site Details, Next: Transforming Names, Prev: Option Checking, Up: Site Configuration
18761
18762 15.6 Configuring Site Details
18763 =============================
18764
18765 Some software packages require complex site-specific information. Some
18766 examples are host names to use for certain services, company names, and
18767 email addresses to contact. Since some configuration scripts generated
18768 by Metaconfig ask for such information interactively, people sometimes
18769 wonder how to get that information in Autoconf-generated configuration
18770 scripts, which aren’t interactive.
18771
18772 Such site configuration information should be put in a file that is
18773 edited _only by users_, not by programs. The location of the file can
18774 either be based on the ‘prefix’ variable, or be a standard location such
18775 as the user’s home directory. It could even be specified by an
18776 environment variable. The programs should examine that file at runtime,
18777 rather than at compile time. Runtime configuration is more convenient
18778 for users and makes the configuration process simpler than getting the
18779 information while configuring. *Note Variables for Installation
18780 Directories: (standards)Directory Variables, for more information on
18781 where to put data files.
18782
18783 
18784 File: autoconf.info, Node: Transforming Names, Next: Site Defaults, Prev: Site Details, Up: Site Configuration
18785
18786 15.7 Transforming Program Names When Installing
18787 ===============================================
18788
18789 Autoconf supports changing the names of programs when installing them.
18790 In order to use these transformations, ‘configure.ac’ must call the
18791 macro ‘AC_ARG_PROGRAM’.
18792
18793 — Macro: AC_ARG_PROGRAM
18794 Place in output variable ‘program_transform_name’ a sequence of
18795 ‘sed’ commands for changing the names of installed programs.
18796
18797 If any of the options described below are given to ‘configure’,
18798 program names are transformed accordingly. Otherwise, if
18799 ‘AC_CANONICAL_TARGET’ has been called and a ‘--target’ value is
18800 given, the target type followed by a dash is used as a prefix.
18801 Otherwise, no program name transformation is done.
18802
18803 * Menu:
18804
18805 * Transformation Options:: ‘configure’ options to transform names
18806 * Transformation Examples:: Sample uses of transforming names
18807 * Transformation Rules:: Makefile uses of transforming names
18808
18809 
18810 File: autoconf.info, Node: Transformation Options, Next: Transformation Examples, Up: Transforming Names
18811
18812 15.7.1 Transformation Options
18813 -----------------------------
18814
18815 You can specify name transformations by giving ‘configure’ these command
18816 line options:
18817
18818 ‘--program-prefix=PREFIX’
18819 prepend PREFIX to the names;
18820
18821 ‘--program-suffix=SUFFIX’
18822 append SUFFIX to the names;
18823
18824 ‘--program-transform-name=EXPRESSION’
18825 perform ‘sed’ substitution EXPRESSION on the names.
18826
18827 
18828 File: autoconf.info, Node: Transformation Examples, Next: Transformation Rules, Prev: Transformation Options, Up: Transforming Names
18829
18830 15.7.2 Transformation Examples
18831 ------------------------------
18832
18833 These transformations are useful with programs that can be part of a
18834 cross-compilation development environment. For example, a
18835 cross-assembler running on x86-64 configured with
18836 ‘--target=aarch64-linux-gnu’ is normally installed as
18837 ‘aarch64-linux-gnu-as’, rather than ‘as’, which could be confused with a
18838 native x86-64 assembler.
18839
18840 You can force a program name to begin with ‘g’, if you don’t want GNU
18841 programs installed on your system to shadow other programs with the same
18842 name. For example, if you configure GNU ‘diff’ with
18843 ‘--program-prefix=g’, then when you run ‘make install’ it is installed
18844 as ‘/usr/local/bin/gdiff’.
18845
18846 As a more sophisticated example, you could use
18847
18848 --program-transform-name='s/^/g/; s/^gg/g/; s/^gless/less/'
18849
18850 to prepend ‘g’ to most of the program names in a source tree,
18851 excepting those like ‘gdb’ that already have one and those like ‘less’
18852 and ‘lesskey’ that aren’t GNU programs. (That is assuming that you have
18853 a source tree containing those programs that is set up to use this
18854 feature.)
18855
18856 One way to install multiple versions of some programs simultaneously
18857 is to append a version number to the name of one or both. For example,
18858 if you want to keep Autoconf version 1 around for awhile, you can
18859 configure Autoconf version 2 using ‘--program-suffix=2’ to install the
18860 programs as ‘/usr/local/bin/autoconf2’, ‘/usr/local/bin/autoheader2’,
18861 etc. Nevertheless, pay attention that only the binaries are renamed,
18862 therefore you’d have problems with the library files which might
18863 overlap.
18864
18865 
18866 File: autoconf.info, Node: Transformation Rules, Prev: Transformation Examples, Up: Transforming Names
18867
18868 15.7.3 Transformation Rules
18869 ---------------------------
18870
18871 Here is how to use the variable ‘program_transform_name’ in a
18872 ‘Makefile.in’:
18873
18874 PROGRAMS = cp ls rm
18875 transform = @program_transform_name@
18876 install:
18877 for p in $(PROGRAMS); do \
18878 $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p | \
18879 sed '$(transform)'`; \
18880 done
18881
18882 uninstall:
18883 for p in $(PROGRAMS); do \
18884 rm -f $(DESTDIR)$(bindir)/`echo $$p | sed '$(transform)'`; \
18885 done
18886
18887 It is guaranteed that ‘program_transform_name’ is never empty, and
18888 that there are no useless separators. Therefore you may safely embed
18889 ‘program_transform_name’ within a sed program using ‘;’:
18890
18891 transform = @program_transform_name@
18892 transform_exe = s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/
18893
18894 Whether to do the transformations on documentation files (Texinfo or
18895 ‘man’) is a tricky question; there seems to be no perfect answer, due to
18896 the several reasons for name transforming. Documentation is not usually
18897 particular to a specific architecture, and Texinfo files do not conflict
18898 with system documentation. But they might conflict with earlier
18899 versions of the same files, and ‘man’ pages sometimes do conflict with
18900 system documentation. As a compromise, it is probably best to do name
18901 transformations on ‘man’ pages but not on Texinfo manuals.
18902
18903 
18904 File: autoconf.info, Node: Site Defaults, Prev: Transforming Names, Up: Site Configuration
18905
18906 15.8 Setting Site Defaults
18907 ==========================
18908
18909 Autoconf-generated ‘configure’ scripts allow your site to provide
18910 default values for some configuration values. You do this by creating
18911 site- and system-wide initialization files.
18912
18913 If the environment variable ‘CONFIG_SITE’ is set, ‘configure’ uses
18914 its value as a space-separated list of shell scripts to read; it is
18915 recommended that these be absolute file names. Otherwise, it reads the
18916 shell script ‘PREFIX/share/config.site’ if it exists, then
18917 ‘PREFIX/etc/config.site’ if it exists. Thus, settings in
18918 machine-specific files override those in machine-independent ones in
18919 case of conflict.
18920
18921 Site files can be arbitrary shell scripts, but only certain kinds of
18922 code are really appropriate to be in them. Because ‘configure’ reads
18923 any cache file after it has read any site files, a site file can define
18924 a default cache file to be shared between all Autoconf-generated
18925 ‘configure’ scripts run on that system (*note Cache Files::). If you
18926 set a default cache file in a site file, it is a good idea to also set
18927 the output variable ‘CC’ in that site file, because the cache file is
18928 only valid for a particular compiler, but many systems have several
18929 available.
18930
18931 You can examine or override the value set by a command line option to
18932 ‘configure’ in a site file; options set shell variables that have the
18933 same names as the options, with any dashes turned into underscores. The
18934 exceptions are that ‘--without-’ and ‘--disable-’ options are like
18935 giving the corresponding ‘--with-’ or ‘--enable-’ option and the value
18936 ‘no’. Thus, ‘--cache-file=localcache’ sets the variable ‘cache_file’ to
18937 the value ‘localcache’; ‘--enable-warnings=no’ or ‘--disable-warnings’
18938 sets the variable ‘enable_warnings’ to the value ‘no’; ‘--prefix=/usr’
18939 sets the variable ‘prefix’ to the value ‘/usr’; etc.
18940
18941 Site files are also good places to set default values for other
18942 output variables, such as ‘CFLAGS’, if you need to give them non-default
18943 values: anything you would normally do, repetitively, on the command
18944 line. If you use non-default values for PREFIX or EXEC_PREFIX (wherever
18945 you locate the site file), you can set them in the site file if you
18946 specify it with the ‘CONFIG_SITE’ environment variable.
18947
18948 You can set some cache values in the site file itself. Doing this is
18949 useful if you are cross-compiling, where it is impossible to check
18950 features that require running a test program. You could “prime the
18951 cache” by setting those values correctly for that system in
18952 ‘PREFIX/etc/config.site’. To find out the names of the cache variables
18953 you need to set, see the documentation of the respective Autoconf macro.
18954 If the variables or their semantics are undocumented, you may need to
18955 look for shell variables with ‘_cv_’ in their names in the affected
18956 ‘configure’ scripts, or in the Autoconf M4 source code for those macros;
18957 but in that case, their name or semantics may change in a future
18958 Autoconf version.
18959
18960 The cache file is careful to not override any variables set in the
18961 site files. Similarly, you should not override command-line options in
18962 the site files. Your code should check that variables such as ‘prefix’
18963 and ‘cache_file’ have their default values (as set near the top of
18964 ‘configure’) before changing them.
18965
18966 Here is a sample file ‘/usr/share/local/gnu/share/config.site’. The
18967 command ‘configure --prefix=/usr/share/local/gnu’ would read this file
18968 (if ‘CONFIG_SITE’ is not set to a different file).
18969
18970 # /usr/share/local/gnu/share/config.site for configure
18971 #
18972 # Change some defaults.
18973 test "$prefix" = NONE && prefix=/usr/share/local/gnu
18974 test "$exec_prefix" = NONE && exec_prefix=/usr/local/gnu
18975 test "$sharedstatedir" = '${prefix}/com' && sharedstatedir=/var
18976 test "$localstatedir" = '${prefix}/var' && localstatedir=/var
18977 test "$runstatedir" = '${localstatedir}/run' && runstatedir=/run
18978
18979 # Give Autoconf 2.x generated configure scripts a shared default
18980 # cache file for feature test results, architecture-specific.
18981 if test "$cache_file" = /dev/null; then
18982 cache_file="$prefix/var/config.cache"
18983 # A cache file is only valid for one C compiler.
18984 CC=gcc
18985 fi
18986
18987 Another use of ‘config.site’ is for priming the directory variables
18988 in a manner consistent with the Filesystem Hierarchy Standard (FHS).
18989 Once the following file is installed at ‘/usr/share/config.site’, a user
18990 can execute simply ‘./configure --prefix=/usr’ to get all the
18991 directories chosen in the locations recommended by FHS.
18992
18993 # /usr/share/config.site for FHS defaults when installing below /usr,
18994 # and the respective settings were not changed on the command line.
18995 if test "$prefix" = /usr; then
18996 test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
18997 test "$sharedstatedir" = '${prefix}/com' && sharedstatedir=/var
18998 test "$localstatedir" = '${prefix}/var' && localstatedir=/var
18999 fi
19000
19001 Likewise, on platforms where 64-bit libraries are built by default,
19002 then installed in ‘/usr/local/lib64’ instead of ‘/usr/local/lib’, it is
19003 appropriate to install ‘/usr/local/share/config.site’:
19004
19005 # /usr/local/share/config.site for platforms that prefer
19006 # the directory /usr/local/lib64 over /usr/local/lib.
19007 test "$libdir" = '${exec_prefix}/lib' && libdir='${exec_prefix}/lib64'
19008
19009 
19010 File: autoconf.info, Node: Running configure Scripts, Next: config.status Invocation, Prev: Site Configuration, Up: Top
19011
19012 16 Running ‘configure’ Scripts
19013 ******************************
19014
19015 Below are instructions on how to configure a package that uses a
19016 ‘configure’ script, suitable for inclusion as an ‘INSTALL’ file in the
19017 package. A plain-text version of ‘INSTALL’ which you may use comes with
19018 Autoconf.
19019
19020 * Menu:
19021
19022 * Basic Installation:: Instructions for typical cases
19023 * Installation Prerequisites:: What you need to install
19024 * Compilers and Options:: Selecting compilers and optimization
19025 * Multiple Architectures:: Compiling for multiple architectures at once
19026 * Installation Names:: Installing in different directories
19027 * Optional Features:: Selecting optional features
19028 * System Types:: Specifying a system type
19029 * Sharing Defaults:: Setting site-wide defaults for ‘configure’
19030 * Defining Variables:: Specifying the compiler etc.
19031 * configure Invocation:: Changing how ‘configure’ runs
19032
19033 
19034 File: autoconf.info, Node: Basic Installation, Next: Installation Prerequisites, Up: Running configure Scripts
19035
19036 16.1 Basic Installation
19037 =======================
19038
19039 The following shell commands:
19040
19041 test -f configure || ./bootstrap
19042 ./configure
19043 make
19044 make install
19045
19046 should configure, build, and install this package. The first line,
19047 which bootstraps, is intended for developers; when building from
19048 distribution tarballs it does nothing and can be skipped. A package
19049 might name the bootstrapping script differently; if the name is
19050 ‘autogen.sh’, for example, the first line should say ‘./autogen.sh’
19051 instead of ‘./bootstrap’.
19052
19053 The following more-detailed instructions are generic; see the
19054 ‘README’ file for instructions specific to this package. More
19055 recommendations for GNU packages can be found in *note Makefile
19056 Conventions: (standards)Makefile Conventions.
19057
19058 Many packages have scripts meant for developers instead of ordinary
19059 builders, as they may use developer tools that are less commonly
19060 installed, or they may access the network, which has privacy
19061 implications. These scripts attempt to bootstrap by building the
19062 ‘configure’ script and related files, possibly using developer tools or
19063 the network. Because the output of bootstrapping is system-independent,
19064 it is normally run by a package developer so that its output can be put
19065 into the distribution tarball and ordinary builders and users need not
19066 bootstrap. Some packages have commands like ‘./autopull.sh’ and
19067 ‘./autogen.sh’ that you can run instead of ‘./bootstrap’, for more
19068 fine-grained control over bootstrapping.
19069
19070 The ‘configure’ script attempts to guess correct values for various
19071 system-dependent variables used during compilation. It uses those
19072 values to create a ‘Makefile’ in each directory of the package. It may
19073 also create one or more ‘.h’ files containing system-dependent
19074 definitions. Finally, it creates a script ‘config.status’ that you can
19075 run in the future to recreate the current configuration, and a file
19076 ‘config.log’ containing output useful for debugging ‘configure’.
19077
19078 It can also use an optional file (typically called ‘config.cache’ and
19079 enabled with ‘--cache-file=config.cache’ or simply ‘-C’) that saves the
19080 results of its tests to speed up reconfiguring. Caching is disabled by
19081 default to prevent problems with accidental use of stale cache files.
19082
19083 If you need to do unusual things to compile the package, please try
19084 to figure out how ‘configure’ could check whether to do them, and mail
19085 diffs or instructions to the address given in the ‘README’ so they can
19086 be considered for the next release. If you are using the cache, and at
19087 some point ‘config.cache’ contains results you don’t want to keep, you
19088 may remove or edit it.
19089
19090 The ‘autoconf’ program generates ‘configure’ from the file
19091 ‘configure.ac’. Normally you should edit ‘configure.ac’ instead of
19092 editing ‘configure’ directly.
19093
19094 The simplest way to compile this package is:
19095
19096 1. ‘cd’ to the directory containing the package’s source code.
19097
19098 2. If this is a developer checkout and file ‘configure’ does not yet
19099 exist, run the bootstrapping script (typically ‘./bootstrap’ or
19100 ‘./autogen.sh’) to bootstrap and create the file. You may need
19101 special developer tools and network access to bootstrap, and the
19102 network access may have privacy implications.
19103
19104 3. Type ‘./configure’ to configure the package for your system. This
19105 might take a while. While running, ‘configure’ prints messages
19106 telling which features it is checking for.
19107
19108 4. Type ‘make’ to compile the package.
19109
19110 5. Optionally, type ‘make check’ to run any self-tests that come with
19111 the package, generally using the just-built uninstalled binaries.
19112
19113 6. Type ‘make install’ to install the programs and any data files and
19114 documentation. When installing into a prefix owned by root, it is
19115 recommended that the package be configured and built as a regular
19116 user, and only the ‘make install’ phase executed with root
19117 privileges.
19118
19119 7. Optionally, type ‘make installcheck’ to repeat any self-tests, but
19120 this time using the binaries in their final installed location.
19121 This target does not install anything. Running this target as a
19122 regular user, particularly if the prior ‘make install’ required
19123 root privileges, verifies that the installation completed
19124 correctly.
19125
19126 8. You can remove the program binaries and object files from the
19127 source code directory by typing ‘make clean’. To also remove the
19128 files that ‘configure’ created (so you can compile the package for
19129 a different kind of computer), type ‘make distclean’. There is
19130 also a ‘make maintainer-clean’ target, but that is intended mainly
19131 for the package’s developers. If you use it, you may have to
19132 bootstrap again.
19133
19134 9. If the package follows the GNU Coding Standards, you can type ‘make
19135 uninstall’ to remove the installed files.
19136
19137 
19138 File: autoconf.info, Node: Installation Prerequisites, Next: Compilers and Options, Prev: Basic Installation, Up: Running configure Scripts
19139
19140 16.2 Installation Prerequisites
19141 ===============================
19142
19143 Installation requires a POSIX-like environment with a shell and at least
19144 the following standard utilities:
19145
19146 awk cat cp diff echo expr false ls mkdir mv printf pwd rm rmdir sed
19147 sort test tr
19148
19149 This package’s installation may need other standard utilities such as
19150 ‘grep’, ‘make’, ‘sleep’ and ‘touch’, along with compilers like ‘gcc’.
19151
19152 
19153 File: autoconf.info, Node: Compilers and Options, Next: Multiple Architectures, Prev: Installation Prerequisites, Up: Running configure Scripts
19154
19155 16.3 Compilers and Options
19156 ==========================
19157
19158 Some systems require unusual options for compilation or linking that the
19159 ‘configure’ script does not know about. Run ‘./configure --help’ for
19160 details on some of the pertinent environment variables.
19161
19162 You can give ‘configure’ initial values for configuration parameters
19163 by setting variables in the command line or in the environment. Here is
19164 an example:
19165
19166 ./configure CC=gcc CFLAGS=-g LIBS=-lposix
19167
19168 *note Defining Variables:: and *note Preset Output Variables:: for
19169 more details.
19170
19171 
19172 File: autoconf.info, Node: Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Running configure Scripts
19173
19174 16.4 Compiling For Multiple Architectures
19175 =========================================
19176
19177 You can compile the package for more than one kind of computer at the
19178 same time, by placing the object files for each system in their own
19179 directory. To do this, you can use GNU ‘make’. ‘cd’ to the directory
19180 where you want the object files and executables to go and run the
19181 ‘configure’ script. ‘configure’ automatically checks for the source
19182 code in the directory that ‘configure’ is in and in ‘..’. This is known
19183 as a “VPATH” build.
19184
19185 With a non-GNU ‘make’, it is safer to compile the package for one
19186 system at a time in the source code directory. After you have installed
19187 the package for one system, use ‘make distclean’ before reconfiguring
19188 for another system.
19189
19190 Some platforms, notably macOS, support “fat” or “universal” binaries,
19191 where a single binary can execute on different architectures. On these
19192 platforms you can configure and compile just once, with options specific
19193 to that platform.
19194
19195 
19196 File: autoconf.info, Node: Installation Names, Next: Optional Features, Prev: Multiple Architectures, Up: Running configure Scripts
19197
19198 16.5 Installation Names
19199 =======================
19200
19201 By default, ‘make install’ installs the package’s commands under
19202 ‘/usr/local/bin’, include files under ‘/usr/local/include’, etc. You
19203 can specify an installation prefix other than ‘/usr/local’ by giving
19204 ‘configure’ the option ‘--prefix=PREFIX’, where PREFIX must be an
19205 absolute file name.
19206
19207 You can specify separate installation prefixes for
19208 architecture-specific files and architecture-independent files. If you
19209 pass the option ‘--exec-prefix=PREFIX’ to ‘configure’, the package uses
19210 PREFIX as the prefix for installing programs and libraries.
19211 Documentation and other data files still use the regular prefix.
19212
19213 In addition, if you use an unusual directory layout you can give
19214 options like ‘--bindir=DIR’ to specify different values for particular
19215 kinds of files. Run ‘configure --help’ for a list of the directories
19216 you can set and what kinds of files go in them. In general, the default
19217 for these options is expressed in terms of ‘${prefix}’, so that
19218 specifying just ‘--prefix’ will affect all of the other directory
19219 specifications that were not explicitly provided.
19220
19221 The most portable way to affect installation locations is to pass the
19222 correct locations to ‘configure’; however, many packages provide one or
19223 both of the following shortcuts of passing variable assignments to the
19224 ‘make install’ command line to change installation locations without
19225 having to reconfigure or recompile.
19226
19227 The first method involves providing an override variable for each
19228 affected directory. For example, ‘make install
19229 prefix=/alternate/directory’ will choose an alternate location for all
19230 directory configuration variables that were expressed in terms of
19231 ‘${prefix}’. Any directories that were specified during ‘configure’,
19232 but not in terms of ‘${prefix}’, must each be overridden at install time
19233 for the entire installation to be relocated. The approach of makefile
19234 variable overrides for each directory variable is required by the GNU
19235 Coding Standards, and ideally causes no recompilation. However, some
19236 platforms have known limitations with the semantics of shared libraries
19237 that end up requiring recompilation when using this method, particularly
19238 noticeable in packages that use GNU Libtool.
19239
19240 The second method involves providing the ‘DESTDIR’ variable. For
19241 example, ‘make install DESTDIR=/alternate/directory’ will prepend
19242 ‘/alternate/directory’ before all installation names. The approach of
19243 ‘DESTDIR’ overrides is not required by the GNU Coding Standards, and
19244 does not work on platforms that have drive letters. On the other hand,
19245 it does better at avoiding recompilation issues, and works well even
19246 when some directory options were not specified in terms of ‘${prefix}’
19247 at ‘configure’ time.
19248
19249 
19250 File: autoconf.info, Node: Optional Features, Next: System Types, Prev: Installation Names, Up: Running configure Scripts
19251
19252 16.6 Optional Features
19253 ======================
19254
19255 If the package supports it, you can cause programs to be installed with
19256 an extra prefix or suffix on their names by giving ‘configure’ the
19257 option ‘--program-prefix=PREFIX’ or ‘--program-suffix=SUFFIX’.
19258
19259 Some packages pay attention to ‘--enable-FEATURE’ and
19260 ‘--disable-FEATURE’ options to ‘configure’, where FEATURE indicates an
19261 optional part of the package. They may also pay attention to
19262 ‘--with-PACKAGE’ and ‘--without-PACKAGE’ options, where PACKAGE is
19263 something like ‘gnu-ld’. ‘./configure --help’ should mention the
19264 ‘--enable-...’ and ‘--with-...’ options that the package recognizes.
19265
19266 Some packages offer the ability to configure how verbose the
19267 execution of ‘make’ will be. For these packages, running ‘./configure
19268 --enable-silent-rules’ sets the default to minimal output, which can be
19269 overridden with ‘make V=1’; while running ‘./configure
19270 --disable-silent-rules’ sets the default to verbose, which can be
19271 overridden with ‘make V=0’.
19272
19273 
19274 File: autoconf.info, Node: System Types, Next: Sharing Defaults, Prev: Optional Features, Up: Running configure Scripts
19275
19276 16.7 Specifying a System Type
19277 =============================
19278
19279 By default ‘configure’ builds for the current system. To create
19280 binaries that can run on a different system type, specify a
19281 ‘--host=TYPE’ option along with compiler variables that specify how to
19282 generate object code for TYPE. For example, to create binaries intended
19283 to run on a 64-bit ARM processor:
19284
19285 ./configure --host=aarch64-linux-gnu \
19286 CC=aarch64-linux-gnu-gcc \
19287 CXX=aarch64-linux-gnu-g++
19288
19289 If done on a machine that can execute these binaries (e.g., via
19290 ‘qemu-aarch64’, ‘$QEMU_LD_PREFIX’, and Linux’s ‘binfmt_misc’
19291 capability), the build behaves like a native build. Otherwise it is a
19292 cross-build: ‘configure’ will make cross-compilation guesses instead of
19293 running test programs, and ‘make check’ will not work.
19294
19295 A system type can either be a short name like ‘mingw64’, or a
19296 canonical name like ‘x86_64-pc-linux-gnu’. Canonical names have the
19297 form CPU-COMPANY-SYSTEM where SYSTEM is either OS or KERNEL-OS. To
19298 canonicalize and validate a system type, you can run the command
19299 ‘config.sub’, which is often squirreled away in a subdirectory like
19300 ‘build-aux’. For example:
19301
19302 $ build-aux/config.sub arm64-linux
19303 aarch64-unknown-linux-gnu
19304 $ build-aux/config.sub riscv-lnx
19305 Invalid configuration 'riscv-lnx': OS 'lnx' not recognized
19306
19307 You can look at the ‘config.sub’ file to see which types are recognized.
19308 If the file is absent, this package does not need the system type.
19309
19310 If ‘configure’ fails with the diagnostic “cannot guess build type”.
19311 ‘config.sub’ did not recognize your system’s type. In this case, first
19312 fetch the newest versions of these files from the GNU config package
19313 (https://savannah.gnu.org/projects/config). If that fixes things,
19314 please report it to the maintainers of the package containing
19315 ‘configure’. Otherwise, you can try the configure option ‘--build=TYPE’
19316 where TYPE comes close to your system type; also, please report the
19317 problem to <[email protected]>.
19318
19319 For more details about configuring system types, see *note Manual
19320 Configuration::.
19321
19322 
19323 File: autoconf.info, Node: Sharing Defaults, Next: Defining Variables, Prev: System Types, Up: Running configure Scripts
19324
19325 16.8 Sharing Defaults
19326 =====================
19327
19328 If you want to set default values for ‘configure’ scripts to share, you
19329 can create a site shell script called ‘config.site’ that gives default
19330 values for variables like ‘CC’, ‘cache_file’, and ‘prefix’. ‘configure’
19331 looks for ‘PREFIX/share/config.site’ if it exists, then
19332 ‘PREFIX/etc/config.site’ if it exists. Or, you can set the
19333 ‘CONFIG_SITE’ environment variable to the location of the site script.
19334 A warning: not all ‘configure’ scripts look for a site script.
19335
19336 
19337 File: autoconf.info, Node: Defining Variables, Next: configure Invocation, Prev: Sharing Defaults, Up: Running configure Scripts
19338
19339 16.9 Defining Variables
19340 =======================
19341
19342 Variables not defined in a site shell script can be set in the
19343 environment passed to ‘configure’. However, some packages may run
19344 configure again during the build, and the customized values of these
19345 variables may be lost. In order to avoid this problem, you should set
19346 them in the ‘configure’ command line, using ‘VAR=value’. For example:
19347
19348 ./configure CC=/usr/local2/bin/gcc
19349
19350 causes the specified ‘gcc’ to be used as the C compiler (unless it is
19351 overridden in the site shell script).
19352
19353 Unfortunately, this technique does not work for ‘CONFIG_SHELL’ due to an
19354 Autoconf limitation. Until the limitation is lifted, you can use this
19355 workaround:
19356
19357 CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
19358
19359 
19360 File: autoconf.info, Node: configure Invocation, Prev: Defining Variables, Up: Running configure Scripts
19361
19362 16.10 ‘configure’ Invocation
19363 ============================
19364
19365 ‘configure’ recognizes the following options to control how it operates.
19366
19367 ‘--help’
19368 ‘-h’
19369 Print a summary of all of the options to ‘configure’, and exit.
19370
19371 ‘--help=short’
19372 ‘--help=recursive’
19373 Print a summary of the options unique to this package’s
19374 ‘configure’, and exit. The ‘short’ variant lists options used only
19375 in the top level, while the ‘recursive’ variant lists options also
19376 present in any nested packages.
19377
19378 ‘--version’
19379 ‘-V’
19380 Print the version of Autoconf used to generate the ‘configure’
19381 script, and exit.
19382
19383 ‘--cache-file=FILE’
19384 Enable the cache: use and save the results of the tests in FILE,
19385 traditionally ‘config.cache’. FILE defaults to ‘/dev/null’ to
19386 disable caching.
19387
19388 ‘--config-cache’
19389 ‘-C’
19390 Alias for ‘--cache-file=config.cache’.
19391
19392 ‘--srcdir=DIR’
19393 Look for the package’s source code in directory DIR. Usually
19394 ‘configure’ can determine that directory automatically.
19395
19396 ‘--prefix=DIR’
19397 Use DIR as the installation prefix. *note Installation Names:: for
19398 more details, including other options available for fine-tuning the
19399 installation locations.
19400
19401 ‘--host=TYPE’
19402 Build binaries for system TYPE. *Note System Types::.
19403
19404 ‘--enable-FEATURE’
19405 ‘--disable-FEATURE’
19406 Enable or disable the optional FEATURE. *Note Optional Features::.
19407
19408 ‘--with-PACKAGE’
19409 ‘--without-PACKAGE’
19410 Use or omit PACKAGE when building. *Note Optional Features::.
19411
19412 ‘--quiet’
19413 ‘--silent’
19414 ‘-q’
19415 Do not print messages saying which checks are being made. To
19416 suppress all normal output, redirect it to ‘/dev/null’ (any error
19417 messages will still be shown).
19418
19419 ‘--no-create’
19420 ‘-n’
19421 Run the configure checks, but stop before creating any output
19422 files.
19423
19424 ‘configure’ also recognizes several environment variables, and accepts
19425 some other, less widely useful, options. Run ‘configure --help’ for
19426 more details.
19427
19428 
19429 File: autoconf.info, Node: config.status Invocation, Next: Obsolete Constructs, Prev: Running configure Scripts, Up: Top
19430
19431 17 config.status Invocation
19432 ***************************
19433
19434 The ‘configure’ script creates a file named ‘config.status’, which
19435 actually configures, “instantiates”, the template files. It also
19436 records the configuration options that were specified when the package
19437 was last configured in case reconfiguring is needed.
19438
19439 Synopsis:
19440 ./config.status [OPTION]... [TAG]...
19441
19442 It configures each TAG; if none are specified, all the templates are
19443 instantiated. A TAG refers to a file or other tag associated with a
19444 configuration action, as specified by an ‘AC_CONFIG_ITEMS’ macro (*note
19445 Configuration Actions::). The files must be specified without their
19446 dependencies, as in
19447
19448 ./config.status foobar
19449
19450 not
19451
19452 ./config.status foobar:foo.in:bar.in
19453
19454 The supported options are:
19455
19456 ‘--help’
19457 ‘-h’
19458 Print a summary of the command line options, the list of the
19459 template files, and exit.
19460
19461 ‘--version’
19462 ‘-V’
19463 Print the version number of Autoconf and the configuration
19464 settings, and exit.
19465
19466 ‘--config’
19467 Print the configuration settings in reusable way, quoted for the
19468 shell, and exit. For example, for a debugging build that otherwise
19469 reuses the configuration from a different build directory BUILD-DIR
19470 of a package in SRC-DIR, you could use the following:
19471
19472 args=`BUILD-DIR/config.status --config`
19473 eval SRC-DIR/configure "$args" CFLAGS=-g --srcdir=SRC-DIR
19474
19475 Note that it may be necessary to override a ‘--srcdir’ setting that
19476 was saved in the configuration, if the arguments are used in a
19477 different build directory.
19478
19479 ‘--silent’
19480 ‘--quiet’
19481 ‘-q’
19482 Do not print progress messages.
19483
19484 ‘--debug’
19485 ‘-d’
19486 Don’t remove the temporary files.
19487
19488 ‘--file=FILE[:TEMPLATE]’
19489 Require that FILE be instantiated as if
19490 ‘AC_CONFIG_FILES(FILE:TEMPLATE)’ was used. Both FILE and TEMPLATE
19491 may be ‘-’ in which case the standard output and/or standard input,
19492 respectively, is used. If a TEMPLATE file name is relative, it is
19493 first looked for in the build tree, and then in the source tree.
19494 *Note Configuration Actions::, for more details.
19495
19496 This option and the following ones provide one way for separately
19497 distributed packages to share the values computed by ‘configure’.
19498 Doing so can be useful if some of the packages need a superset of
19499 the features that one of them, perhaps a common library, does.
19500 These options allow a ‘config.status’ file to create files other
19501 than the ones that its ‘configure.ac’ specifies, so it can be used
19502 for a different package, or for extracting a subset of values. For
19503 example,
19504
19505 echo '@CC@' | ./config.status --file=-
19506
19507 provides the value of ‘@CC@’ on standard output.
19508
19509 ‘--header=FILE[:TEMPLATE]’
19510 Same as ‘--file’ above, but with ‘AC_CONFIG_HEADERS’.
19511
19512 ‘--recheck’
19513 Ask ‘config.status’ to update itself and exit (no instantiation).
19514 This option is useful if you change ‘configure’, so that the
19515 results of some tests might be different from the previous run.
19516 The ‘--recheck’ option reruns ‘configure’ with the same arguments
19517 you used before, plus the ‘--no-create’ option, which prevents
19518 ‘configure’ from running ‘config.status’ and creating ‘Makefile’
19519 and other files, and the ‘--no-recursion’ option, which prevents
19520 ‘configure’ from running other ‘configure’ scripts in
19521 subdirectories. (This is so other Make rules can run
19522 ‘config.status’ when it changes; *note Automatic Remaking::, for an
19523 example).
19524
19525 ‘config.status’ checks several optional environment variables that
19526 can alter its behavior:
19527
19528 — Variable: CONFIG_SHELL
19529 The shell with which to run ‘configure’. It must be
19530 Bourne-compatible, and the absolute name of the shell should be
19531 passed. The default is a shell that supports ‘LINENO’ if
19532 available, and ‘/bin/sh’ otherwise.
19533
19534 — Variable: CONFIG_STATUS
19535 The file name to use for the shell script that records the
19536 configuration. The default is ‘./config.status’. This variable is
19537 useful when one package uses parts of another and the ‘configure’
19538 scripts shouldn’t be merged because they are maintained separately.
19539
19540 You can use ‘./config.status’ in your makefiles. For example, in the
19541 dependencies given above (*note Automatic Remaking::), ‘config.status’
19542 is run twice when ‘configure.ac’ has changed. If that bothers you, you
19543 can make each run only regenerate the files for that rule:
19544 config.h: stamp-h
19545 stamp-h: config.h.in config.status
19546 ./config.status config.h
19547 echo > stamp-h
19548
19549 Makefile: Makefile.in config.status
19550 ./config.status Makefile
19551
19552 The calling convention of ‘config.status’ has changed; see *note
19553 Obsolete config.status Use::, for details.
19554
19555 
19556 File: autoconf.info, Node: Obsolete Constructs, Next: Using Autotest, Prev: config.status Invocation, Up: Top
19557
19558 18 Obsolete Constructs
19559 **********************
19560
19561 Autoconf changes, and throughout the years some constructs have been
19562 obsoleted. Most of the changes involve the macros, but in some cases
19563 the tools themselves, or even some concepts, are now considered
19564 obsolete.
19565
19566 You may completely skip this chapter if you are new to Autoconf. Its
19567 intention is mainly to help maintainers updating their packages by
19568 understanding how to move to more modern constructs.
19569
19570 * Menu:
19571
19572 * Obsolete config.status Use:: Obsolete convention for ‘config.status’
19573 * acconfig Header:: Additional entries in ‘config.h.in’
19574 * autoupdate Invocation:: Automatic update of ‘configure.ac’
19575 * Obsolete Macros:: Backward compatibility macros
19576 * Autoconf 1:: Tips for upgrading your files
19577 * Autoconf 2.13:: Some fresher tips
19578
19579 
19580 File: autoconf.info, Node: Obsolete config.status Use, Next: acconfig Header, Up: Obsolete Constructs
19581
19582 18.1 Obsolete ‘config.status’ Invocation
19583 ========================================
19584
19585 ‘config.status’ now supports arguments to specify the files to
19586 instantiate; see *note config.status Invocation::, for more details.
19587 Before, environment variables had to be used.
19588
19589 — Variable: CONFIG_COMMANDS
19590 The tags of the commands to execute. The default is the arguments
19591 given to ‘AC_OUTPUT’ and ‘AC_CONFIG_COMMANDS’ in ‘configure.ac’.
19592
19593 — Variable: CONFIG_FILES
19594 The files in which to perform ‘@VARIABLE@’ substitutions. The
19595 default is the arguments given to ‘AC_OUTPUT’ and ‘AC_CONFIG_FILES’
19596 in ‘configure.ac’.
19597
19598 — Variable: CONFIG_HEADERS
19599 The files in which to substitute C ‘#define’ statements. The
19600 default is the arguments given to ‘AC_CONFIG_HEADERS’; if that
19601 macro was not called, ‘config.status’ ignores this variable.
19602
19603 — Variable: CONFIG_LINKS
19604 The symbolic links to establish. The default is the arguments
19605 given to ‘AC_CONFIG_LINKS’; if that macro was not called,
19606 ‘config.status’ ignores this variable.
19607
19608 In *note config.status Invocation::, using this old interface, the
19609 example would be:
19610
19611 config.h: stamp-h
19612 stamp-h: config.h.in config.status
19613 CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_FILES= \
19614 CONFIG_HEADERS=config.h ./config.status
19615 echo > stamp-h
19616
19617 Makefile: Makefile.in config.status
19618 CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_HEADERS= \
19619 CONFIG_FILES=Makefile ./config.status
19620
19621 (If ‘configure.ac’ does not call ‘AC_CONFIG_HEADERS’, there is no need
19622 to set ‘CONFIG_HEADERS’ in the ‘make’ rules. Equally for
19623 ‘CONFIG_COMMANDS’, etc.)
19624
19625 
19626 File: autoconf.info, Node: acconfig Header, Next: autoupdate Invocation, Prev: Obsolete config.status Use, Up: Obsolete Constructs
19627
19628 18.2 ‘acconfig.h’
19629 =================
19630
19631 In order to produce ‘config.h.in’, ‘autoheader’ needs to build or to
19632 find templates for each symbol. Modern releases of Autoconf use
19633 ‘AH_VERBATIM’ and ‘AH_TEMPLATE’ (*note Autoheader Macros::), but in
19634 older releases a file, ‘acconfig.h’, contained the list of needed
19635 templates. ‘autoheader’ copied comments and ‘#define’ and ‘#undef’
19636 statements from ‘acconfig.h’ in the current directory, if present. This
19637 file used to be mandatory if you ‘AC_DEFINE’ any additional symbols.
19638
19639 Modern releases of Autoconf also provide ‘AH_TOP’ and ‘AH_BOTTOM’ if
19640 you need to prepend/append some information to ‘config.h.in’. Ancient
19641 versions of Autoconf had a similar feature: if ‘./acconfig.h’ contains
19642 the string ‘@TOP@’, ‘autoheader’ copies the lines before the line
19643 containing ‘@TOP@’ into the top of the file that it generates.
19644 Similarly, if ‘./acconfig.h’ contains the string ‘@BOTTOM@’,
19645 ‘autoheader’ copies the lines after that line to the end of the file it
19646 generates. Either or both of those strings may be omitted. An even
19647 older alternate way to produce the same effect in ancient versions of
19648 Autoconf is to create the files ‘FILE.top’ (typically ‘config.h.top’)
19649 and/or ‘FILE.bot’ in the current directory. If they exist, ‘autoheader’
19650 copies them to the beginning and end, respectively, of its output.
19651
19652 In former versions of Autoconf, the files used in preparing a
19653 software package for distribution were:
19654 configure.ac --. .------> autoconf* -----> configure
19655 +---+
19656 [aclocal.m4] --+ `---.
19657 [acsite.m4] ---' |
19658 +--> [autoheader*] -> [config.h.in]
19659 [acconfig.h] ----. |
19660 +-----'
19661 [config.h.top] --+
19662 [config.h.bot] --'
19663
19664 Using only the ‘AH_’ macros, ‘configure.ac’ should be self-contained,
19665 and should not depend upon ‘acconfig.h’ etc.
19666
19667 
19668 File: autoconf.info, Node: autoupdate Invocation, Next: Obsolete Macros, Prev: acconfig Header, Up: Obsolete Constructs
19669
19670 18.3 Using ‘autoupdate’ to Modernize ‘configure.ac’
19671 ===================================================
19672
19673 The ‘autoupdate’ program updates a ‘configure.ac’ file that calls
19674 Autoconf macros by their old names to use the current macro names. In
19675 version 2 of Autoconf, most of the macros were renamed to use a more
19676 uniform and descriptive naming scheme. *Note Macro Names::, for a
19677 description of the new scheme. Although the old names still work (*note
19678 Obsolete Macros::, for a list of the old macros and the corresponding
19679 new names), you can make your ‘configure.ac’ files more readable and
19680 make it easier to use the current Autoconf documentation if you update
19681 them to use the new macro names.
19682
19683 If given no arguments, ‘autoupdate’ updates ‘configure.ac’, backing
19684 up the original version with the suffix ‘~’ (or the value of the
19685 environment variable ‘SIMPLE_BACKUP_SUFFIX’, if that is set). If you
19686 give ‘autoupdate’ an argument, it reads that file instead of
19687 ‘configure.ac’ and writes the updated file to the standard output.
19688
19689 ‘autoupdate’ accepts the following options:
19690
19691 ‘--help’
19692 ‘-h’
19693 Print a summary of the command line options and exit.
19694
19695 ‘--version’
19696 ‘-V’
19697 Print the version number of Autoconf and exit.
19698
19699 ‘--verbose’
19700 ‘-v’
19701 Report processing steps.
19702
19703 ‘--debug’
19704 ‘-d’
19705 Don’t remove the temporary files.
19706
19707 ‘--force’
19708 ‘-f’
19709 Force the update even if the file has not changed. Disregard the
19710 cache.
19711
19712 ‘--include=DIR’
19713 ‘-I DIR’
19714 Also look for input files in DIR. Multiple invocations accumulate.
19715 Directories are browsed from last to first.
19716
19717 ‘--prepend-include=DIR’
19718 ‘-B DIR’
19719 Prepend directory DIR to the search path. This is used to include
19720 the language-specific files before any third-party macros.
19721
19722 
19723 File: autoconf.info, Node: Obsolete Macros, Next: Autoconf 1, Prev: autoupdate Invocation, Up: Obsolete Constructs
19724
19725 18.4 Obsolete Macros
19726 ====================
19727
19728 Several macros are obsoleted in Autoconf, for various reasons (typically
19729 they failed to quote properly, couldn’t be extended for more recent
19730 issues, etc.). They are still supported, but deprecated: their use
19731 should be avoided.
19732
19733 During the jump from Autoconf version 1 to version 2, most of the
19734 macros were renamed to use a more uniform and descriptive naming scheme,
19735 but their signature did not change. *Note Macro Names::, for a
19736 description of the new naming scheme. Below, if there is just the
19737 mapping from old names to new names for these macros, the reader is
19738 invited to refer to the definition of the new macro for the signature
19739 and the description.
19740
19741 — Macro: AC_AIX
19742 This macro is a platform-specific subset of
19743 ‘AC_USE_SYSTEM_EXTENSIONS’ (*note AC_USE_SYSTEM_EXTENSIONS::).
19744
19745 — Macro: AC_ALLOCA
19746 Replaced by ‘AC_FUNC_ALLOCA’ (*note AC_FUNC_ALLOCA::).
19747
19748 — Macro: AC_ARG_ARRAY
19749 Removed because of limited usefulness.
19750
19751 — Macro: AC_C_CROSS
19752 This macro is obsolete; it does nothing.
19753
19754 — Macro: AC_C_LONG_DOUBLE
19755 If the C compiler supports a working ‘long double’ type with more
19756 range or precision than the ‘double’ type, define
19757 ‘HAVE_LONG_DOUBLE’.
19758
19759 You should use ‘AC_TYPE_LONG_DOUBLE’ or ‘AC_TYPE_LONG_DOUBLE_WIDER’
19760 instead. *Note Particular Types::.
19761
19762 — Macro: AC_CANONICAL_SYSTEM
19763 Determine the system type and set output variables to the names of
19764 the canonical system types. *Note Canonicalizing::, for details
19765 about the variables this macro sets.
19766
19767 The user is encouraged to use either ‘AC_CANONICAL_BUILD’, or
19768 ‘AC_CANONICAL_HOST’, or ‘AC_CANONICAL_TARGET’, depending on the
19769 needs. Using ‘AC_CANONICAL_TARGET’ is enough to run the two other
19770 macros (*note Canonicalizing::).
19771
19772 — Macro: AC_CHAR_UNSIGNED
19773 Replaced by ‘AC_C_CHAR_UNSIGNED’ (*note AC_C_CHAR_UNSIGNED::).
19774
19775 — Macro: AC_CHECK_TYPE(TYPE, DEFAULT)
19776 Autoconf, up to 2.13, used to provide this version of
19777 ‘AC_CHECK_TYPE’, deprecated because of its flaws. First, although
19778 it is a member of the ‘CHECK’ clan, it does more than just
19779 checking. Secondly, missing types are defined using ‘#define’, not
19780 ‘typedef’, and this can lead to problems in the case of pointer
19781 types.
19782
19783 This use of ‘AC_CHECK_TYPE’ is obsolete and discouraged; see *note
19784 Generic Types::, for the description of the current macro.
19785
19786 If the type TYPE is not defined, define it to be the C (or C++)
19787 builtin type DEFAULT, e.g., ‘short int’ or ‘unsigned int’.
19788
19789 This macro is equivalent to:
19790
19791 AC_CHECK_TYPE([TYPE], [],
19792 [AC_DEFINE_UNQUOTED([TYPE], [DEFAULT],
19793 [Define to 'DEFAULT'
19794 if <sys/types.h> does not define.])])
19795
19796 In order to keep backward compatibility, the two versions of
19797 ‘AC_CHECK_TYPE’ are implemented, selected using these heuristics:
19798
19799 1. If there are three or four arguments, the modern version is
19800 used.
19801
19802 2. If the second argument appears to be a C or C++ type, then the
19803 obsolete version is used. This happens if the argument is a C
19804 or C++ _builtin_ type or a C identifier ending in ‘_t’,
19805 optionally followed by one of ‘[(* ’ and then by a string of
19806 zero or more characters taken from the set ‘[]()* _a-zA-Z0-9’.
19807
19808 3. If the second argument is spelled with the alphabet of valid C
19809 and C++ types, the user is warned and the modern version is
19810 used.
19811
19812 4. Otherwise, the modern version is used.
19813
19814 You are encouraged either to use a valid builtin type, or to use
19815 the equivalent modern code (see above), or better yet, to use
19816 ‘AC_CHECK_TYPES’ together with
19817
19818 #ifndef HAVE_LOFF_T
19819 typedef loff_t off_t;
19820 #endif
19821
19822 — Macro: AC_CHECKING(FEATURE-DESCRIPTION)
19823 Same as
19824
19825 AC_MSG_NOTICE([checking FEATURE-DESCRIPTION...]
19826
19827 *Note AC_MSG_NOTICE::.
19828
19829 — Macro: AC_COMPILE_CHECK(ECHO-TEXT, INCLUDES, FUNCTION-BODY,
19830 ACTION-IF-TRUE, [ACTION-IF-FALSE])
19831 This is an obsolete version of ‘AC_TRY_COMPILE’ itself replaced by
19832 ‘AC_COMPILE_IFELSE’ (*note Running the Compiler::), with the
19833 addition that it prints ‘checking for ECHO-TEXT’ to the standard
19834 output first, if ECHO-TEXT is non-empty. Use ‘AC_MSG_CHECKING’ and
19835 ‘AC_MSG_RESULT’ instead to print messages (*note Printing
19836 Messages::).
19837
19838 — Macro: AC_CONST
19839 Replaced by ‘AC_C_CONST’ (*note AC_C_CONST::).
19840
19841 — Macro: AC_CROSS_CHECK
19842 Same as ‘AC_C_CROSS’, which is obsolete too, and does nothing
19843 ‘:-)’.
19844
19845 — Macro: AC_CYGWIN
19846 Check for the Cygwin environment in which case the shell variable
19847 ‘CYGWIN’ is set to ‘yes’. Don’t use this macro, the dignified
19848 means to check the nature of the host is using ‘AC_CANONICAL_HOST’
19849 (*note Canonicalizing::). As a matter of fact this macro is
19850 defined as:
19851
19852 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
19853 case $host_os in
19854 *cygwin* ) CYGWIN=yes;;
19855 * ) CYGWIN=no;;
19856 esac
19857
19858 Beware that the variable ‘CYGWIN’ has a special meaning when
19859 running Cygwin, and should not be changed. That’s yet another
19860 reason not to use this macro.
19861
19862 — Macro: AC_DECL_SYS_SIGLIST
19863 Same as:
19864
19865 AC_CHECK_DECLS([sys_siglist], [], [],
19866 [#include <signal.h>
19867 /* NetBSD declares sys_siglist in unistd.h. */
19868 #ifdef HAVE_UNISTD_H
19869 # include <unistd.h>
19870 #endif
19871 ])
19872
19873 *Note AC_CHECK_DECLS::.
19874
19875 — Macro: AC_DECL_YYTEXT
19876 Does nothing, now integrated in ‘AC_PROG_LEX’ (*note
19877 AC_PROG_LEX::).
19878
19879 — Macro: AC_DIAGNOSE(CATEGORY, MESSAGE)
19880 Replaced by ‘m4_warn’ (*note m4_warn::).
19881
19882 — Macro: AC_DIR_HEADER
19883 Like calling ‘AC_FUNC_CLOSEDIR_VOID’ (*note
19884 AC_FUNC_CLOSEDIR_VOID::) and ‘AC_HEADER_DIRENT’ (*note
19885 AC_HEADER_DIRENT::), but defines a different set of C preprocessor
19886 macros to indicate which header file is found:
19887
19888 Header Old Symbol New Symbol
19889 ‘dirent.h’ ‘DIRENT’ ‘HAVE_DIRENT_H’
19890 ‘sys/ndir.h’ ‘SYSNDIR’ ‘HAVE_SYS_NDIR_H’
19891 ‘sys/dir.h’ ‘SYSDIR’ ‘HAVE_SYS_DIR_H’
19892 ‘ndir.h’ ‘NDIR’ ‘HAVE_NDIR_H’
19893
19894 — Macro: AC_DYNIX_SEQ
19895 If on DYNIX/ptx, add ‘-lseq’ to output variable ‘LIBS’. This macro
19896 used to be defined as
19897
19898 AC_CHECK_LIB([seq], [getmntent], [LIBS="-lseq $LIBS"])
19899
19900 now it is just ‘AC_FUNC_GETMNTENT’ (*note AC_FUNC_GETMNTENT::).
19901
19902 — Macro: AC_EXEEXT
19903 Defined the output variable ‘EXEEXT’ based on the output of the
19904 compiler, which is now done automatically. Typically set to empty
19905 string if POSIX and ‘.exe’ if a DOS variant.
19906
19907 — Macro: AC_EMXOS2
19908 Similar to ‘AC_CYGWIN’ but checks for the EMX environment on OS/2
19909 and sets ‘EMXOS2’. Don’t use this macro, the dignified means to
19910 check the nature of the host is using ‘AC_CANONICAL_HOST’ (*note
19911 Canonicalizing::).
19912
19913 — Macro: AC_ENABLE(FEATURE, ACTION-IF-GIVEN, [ACTION-IF-NOT-GIVEN])
19914 This is an obsolete version of ‘AC_ARG_ENABLE’ that does not
19915 support providing a help string (*note AC_ARG_ENABLE::).
19916
19917 — Macro: AC_ERROR
19918 Replaced by ‘AC_MSG_ERROR’ (*note AC_MSG_ERROR::).
19919
19920 — Macro: AC_FATAL(MESSAGE)
19921 Replaced by ‘m4_fatal’ (*note m4_fatal::).
19922
19923 — Macro: AC_FIND_X
19924 Replaced by ‘AC_PATH_X’ (*note AC_PATH_X::).
19925
19926 — Macro: AC_FIND_XTRA
19927 Replaced by ‘AC_PATH_XTRA’ (*note AC_PATH_XTRA::).
19928
19929 — Macro: AC_FOREACH
19930 Replaced by ‘m4_foreach_w’ (*note m4_foreach_w::).
19931
19932 — Macro: AC_FUNC_CHECK
19933 Replaced by ‘AC_CHECK_FUNC’ (*note AC_CHECK_FUNC::).
19934
19935 — Macro: AC_FUNC_SETVBUF_REVERSED
19936 Do nothing. Formerly, this macro checked whether ‘setvbuf’ takes
19937 the buffering type as its second argument and the buffer pointer as
19938 the third, instead of the other way around, and defined
19939 ‘SETVBUF_REVERSED’. However, the last systems to have the problem
19940 were those based on SVR2, which became obsolete in 1987, and the
19941 macro is no longer needed.
19942
19943 — Macro: AC_FUNC_WAIT3
19944 If ‘wait3’ is found and fills in the contents of its third argument
19945 (a ‘struct rusage *’), which HP-UX does not do, define
19946 ‘HAVE_WAIT3’.
19947
19948 These days portable programs should use ‘waitpid’, not ‘wait3’, as
19949 ‘wait3’ has been removed from POSIX.
19950
19951 — Macro: AC_GCC_TRADITIONAL
19952 Replaced by ‘AC_PROG_GCC_TRADITIONAL’ (*note
19953 AC_PROG_GCC_TRADITIONAL::), which is itself obsolete.
19954
19955 — Macro: AC_GETGROUPS_T
19956 Replaced by ‘AC_TYPE_GETGROUPS’ (*note AC_TYPE_GETGROUPS::).
19957
19958 — Macro: AC_GETLOADAVG
19959 Replaced by ‘AC_FUNC_GETLOADAVG’ (*note AC_FUNC_GETLOADAVG::).
19960
19961 — Macro: AC_GNU_SOURCE
19962 This macro is a platform-specific subset of
19963 ‘AC_USE_SYSTEM_EXTENSIONS’ (*note AC_USE_SYSTEM_EXTENSIONS::).
19964
19965 — Macro: AC_HAVE_FUNCS
19966 Replaced by ‘AC_CHECK_FUNCS’ (*note AC_CHECK_FUNCS::).
19967
19968 — Macro: AC_HAVE_HEADERS
19969 Replaced by ‘AC_CHECK_HEADERS’ (*note AC_CHECK_HEADERS::).
19970
19971 — Macro: AC_HAVE_LIBRARY(LIBRARY, [ACTION-IF-FOUND],
19972 [ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES])
19973 This macro is equivalent to calling ‘AC_CHECK_LIB’ with a FUNCTION
19974 argument of ‘main’. In addition, LIBRARY can be written as any of
19975 ‘foo’, ‘-lfoo’, or ‘libfoo.a’. In all of those cases, the compiler
19976 is passed ‘-lfoo’. However, LIBRARY cannot be a shell variable; it
19977 must be a literal name. *Note AC_CHECK_LIB::.
19978
19979 — Macro: AC_HAVE_POUNDBANG
19980 Replaced by ‘AC_SYS_INTERPRETER’ (*note AC_SYS_INTERPRETER::).
19981
19982 — Macro: AC_HEADER_CHECK
19983 Replaced by ‘AC_CHECK_HEADER’ (*note AC_CHECK_HEADER::).
19984
19985 — Macro: AC_HEADER_EGREP
19986 Replaced by ‘AC_EGREP_HEADER’ (*note AC_EGREP_HEADER::).
19987
19988 — Macro: AC_HEADER_TIME
19989 This macro used to check whether it was possible to include
19990 ‘time.h’ and ‘sys/time.h’ in the same source file, defining
19991 ‘TIME_WITH_SYS_TIME’ if so.
19992
19993 Nowadays, it is equivalent to ‘AC_CHECK_HEADERS([sys/time.h])’,
19994 although it does still define ‘TIME_WITH_SYS_TIME’ for
19995 compatibility’s sake. ‘time.h’ is universally present, and the
19996 systems on which ‘sys/time.h’ conflicted with ‘time.h’ are
19997 obsolete.
19998
19999 — Macro: AC_HELP_STRING
20000 Replaced by ‘AS_HELP_STRING’ (*note AS_HELP_STRING::).
20001
20002 — Macro: AC_INIT(UNIQUE-FILE-IN-SOURCE-DIR)
20003 Formerly ‘AC_INIT’ used to have a single argument, and was
20004 equivalent to:
20005
20006 AC_INIT
20007 AC_CONFIG_SRCDIR(UNIQUE-FILE-IN-SOURCE-DIR)
20008 See *note AC_INIT:: and *note AC_CONFIG_SRCDIR::.
20009
20010 — Macro: AC_INLINE
20011 Replaced by ‘AC_C_INLINE’ (*note AC_C_INLINE::).
20012
20013 — Macro: AC_INT_16_BITS
20014 If the C type ‘int’ is 16 bits wide, define ‘INT_16_BITS’. Use
20015 ‘AC_CHECK_SIZEOF(int)’ instead (*note AC_CHECK_SIZEOF::).
20016
20017 — Macro: AC_IRIX_SUN
20018 If on IRIX (Silicon Graphics Unix), add ‘-lsun’ to output ‘LIBS’.
20019 If you were using it to get ‘getmntent’, use ‘AC_FUNC_GETMNTENT’
20020 instead. If you used it for the NIS versions of the password and
20021 group functions, use ‘AC_CHECK_LIB(sun, getpwnam)’. Up to Autoconf
20022 2.13, it used to be
20023
20024 AC_CHECK_LIB([sun], [getmntent], [LIBS="-lsun $LIBS"])
20025
20026 now it is defined as
20027
20028 AC_FUNC_GETMNTENT
20029 AC_CHECK_LIB([sun], [getpwnam])
20030
20031 See *note AC_FUNC_GETMNTENT:: and *note AC_CHECK_LIB::.
20032
20033 — Macro: AC_ISC_POSIX
20034 This macro adds ‘-lcposix’ to output variable ‘LIBS’ if necessary
20035 for POSIX facilities. Sun dropped support for the obsolete
20036 INTERACTIVE Systems Corporation Unix on 2006-07-23. New programs
20037 need not use this macro. It is implemented as
20038 ‘AC_SEARCH_LIBS([strerror], [cposix])’ (*note AC_SEARCH_LIBS::).
20039
20040 — Macro: AC_LANG_C
20041 Same as ‘AC_LANG([C])’ (*note AC_LANG::).
20042
20043 — Macro: AC_LANG_CPLUSPLUS
20044 Same as ‘AC_LANG([C++])’ (*note AC_LANG::).
20045
20046 — Macro: AC_LANG_FORTRAN77
20047 Same as ‘AC_LANG([Fortran 77])’ (*note AC_LANG::).
20048
20049 — Macro: AC_LANG_RESTORE
20050 Select the LANGUAGE that is saved on the top of the stack, as set
20051 by ‘AC_LANG_SAVE’, remove it from the stack, and call
20052 ‘AC_LANG(LANGUAGE)’. *Note Language Choice::, for the preferred
20053 way to change languages.
20054
20055 — Macro: AC_LANG_SAVE
20056 Remember the current language (as set by ‘AC_LANG’) on a stack.
20057 The current language does not change. ‘AC_LANG_PUSH’ is preferred
20058 (*note AC_LANG_PUSH::).
20059
20060 — Macro: AC_LINK_FILES(SOURCE..., DEST...)
20061 This is an obsolete version of ‘AC_CONFIG_LINKS’ (*note
20062 AC_CONFIG_LINKS::. An updated version of:
20063
20064 AC_LINK_FILES(config/$machine.h config/$obj_format.h,
20065 host.h object.h)
20066
20067 is:
20068
20069 AC_CONFIG_LINKS([host.h:config/$machine.h
20070 object.h:config/$obj_format.h])
20071
20072 — Macro: AC_LN_S
20073 Replaced by ‘AC_PROG_LN_S’ (*note AC_PROG_LN_S::).
20074
20075 — Macro: AC_LONG_64_BITS
20076 Define ‘LONG_64_BITS’ if the C type ‘long int’ is 64 bits wide.
20077 Use the generic macro ‘AC_CHECK_SIZEOF([long int])’ instead (*note
20078 AC_CHECK_SIZEOF::).
20079
20080 — Macro: AC_LONG_DOUBLE
20081 If the C compiler supports a working ‘long double’ type with more
20082 range or precision than the ‘double’ type, define
20083 ‘HAVE_LONG_DOUBLE’.
20084
20085 You should use ‘AC_TYPE_LONG_DOUBLE’ or ‘AC_TYPE_LONG_DOUBLE_WIDER’
20086 instead. *Note Particular Types::.
20087
20088 — Macro: AC_LONG_FILE_NAMES
20089 Replaced by
20090 AC_SYS_LONG_FILE_NAMES
20091 *Note AC_SYS_LONG_FILE_NAMES::.
20092
20093 — Macro: AC_MAJOR_HEADER
20094 Replaced by ‘AC_HEADER_MAJOR’ (*note AC_HEADER_MAJOR::).
20095
20096 — Macro: AC_MEMORY_H
20097 Used to define ‘NEED_MEMORY_H’ if the ‘mem’ functions were defined
20098 in ‘memory.h’. Today it is equivalent to
20099 ‘AC_CHECK_HEADERS([memory.h])’ (*note AC_CHECK_HEADERS::). Adjust
20100 your code to get the ‘mem’ functions from ‘string.h’ instead.
20101
20102 — Macro: AC_MINGW32
20103 Similar to ‘AC_CYGWIN’ but checks for the MinGW compiler
20104 environment and sets ‘MINGW32’. Don’t use this macro, the
20105 dignified means to check the nature of the host is using
20106 ‘AC_CANONICAL_HOST’ (*note Canonicalizing::).
20107
20108 — Macro: AC_MINIX
20109 This macro is a platform-specific subset of
20110 ‘AC_USE_SYSTEM_EXTENSIONS’ (*note AC_USE_SYSTEM_EXTENSIONS::).
20111
20112 — Macro: AC_MINUS_C_MINUS_O
20113 Replaced by ‘AC_PROG_CC_C_O’ (*note AC_PROG_CC_C_O::).
20114
20115 — Macro: AC_MMAP
20116 Replaced by ‘AC_FUNC_MMAP’ (*note AC_FUNC_MMAP::).
20117
20118 — Macro: AC_MODE_T
20119 Replaced by ‘AC_TYPE_MODE_T’ (*note AC_TYPE_MODE_T::).
20120
20121 — Macro: AC_OBJEXT
20122 Defined the output variable ‘OBJEXT’ based on the output of the
20123 compiler, after .c files have been excluded. Typically set to ‘o’
20124 if POSIX, ‘obj’ if a DOS variant. Now the compiler checking macros
20125 handle this automatically.
20126
20127 — Macro: AC_OBSOLETE(THIS-MACRO-NAME, [SUGGESTION])
20128 Make M4 print a message to the standard error output warning that
20129 THIS-MACRO-NAME is obsolete, and giving the file and line number
20130 where it was called. THIS-MACRO-NAME should be the name of the
20131 macro that is calling ‘AC_OBSOLETE’. If SUGGESTION is given, it is
20132 printed at the end of the warning message; for example, it can be a
20133 suggestion for what to use instead of THIS-MACRO-NAME.
20134
20135 For instance
20136
20137 AC_OBSOLETE([$0], [; use AC_CHECK_HEADERS(unistd.h) instead])dnl
20138
20139 You are encouraged to use ‘AU_DEFUN’ instead, since it gives better
20140 services to the user (*note AU_DEFUN::).
20141
20142 — Macro: AC_OFF_T
20143 Replaced by ‘AC_TYPE_OFF_T’ (*note AC_TYPE_OFF_T::).
20144
20145 — Macro: AC_OUTPUT([FILE]..., [EXTRA-CMDS], [INIT-CMDS])
20146 The use of ‘AC_OUTPUT’ with arguments is deprecated. This
20147 obsoleted interface is equivalent to:
20148
20149 AC_CONFIG_FILES(FILE...)
20150 AC_CONFIG_COMMANDS([default],
20151 EXTRA-CMDS, INIT-CMDS)
20152 AC_OUTPUT
20153
20154 See *note AC_CONFIG_FILES::, *note AC_CONFIG_COMMANDS::, and *note
20155 AC_OUTPUT::.
20156
20157 — Macro: AC_OUTPUT_COMMANDS(EXTRA-CMDS, [INIT-CMDS])
20158 Specify additional shell commands to run at the end of
20159 ‘config.status’, and shell commands to initialize any variables
20160 from ‘configure’. This macro may be called multiple times. It is
20161 obsolete, replaced by ‘AC_CONFIG_COMMANDS’ (*note
20162 AC_CONFIG_COMMANDS::).
20163
20164 Here is an unrealistic example:
20165
20166 fubar=27
20167 AC_OUTPUT_COMMANDS(
20168 [AS_ECHO(["this is extra $fubar, and so on."])],
20169 [fubar=$fubar])
20170 AC_OUTPUT_COMMANDS(
20171 [AS_ECHO(["this is another, extra, bit"])],
20172 [AS_ECHO(["init bit"])])
20173
20174 Aside from the fact that ‘AC_CONFIG_COMMANDS’ requires an
20175 additional key, an important difference is that
20176 ‘AC_OUTPUT_COMMANDS’ is quoting its arguments twice, unlike
20177 ‘AC_CONFIG_COMMANDS’. This means that ‘AC_CONFIG_COMMANDS’ can
20178 safely be given macro calls as arguments:
20179
20180 AC_CONFIG_COMMANDS(foo, [my_FOO()])
20181
20182 Conversely, where one level of quoting was enough for literal
20183 strings with ‘AC_OUTPUT_COMMANDS’, you need two with
20184 ‘AC_CONFIG_COMMANDS’. The following lines are equivalent:
20185
20186 AC_OUTPUT_COMMANDS([echo "Square brackets: []"])
20187 AC_CONFIG_COMMANDS([default], [[echo "Square brackets: []"]])
20188
20189 — Macro: AC_PID_T
20190 Replaced by ‘AC_TYPE_PID_T’ (*note AC_TYPE_PID_T::).
20191
20192 — Macro: AC_PREFIX
20193 Replaced by ‘AC_PREFIX_PROGRAM’ (*note AC_PREFIX_PROGRAM::).
20194
20195 — Macro: AC_PROG_CC_C89
20196 Now done by ‘AC_PROG_CC’ (*note AC_PROG_CC::).
20197
20198 — Macro: AC_PROG_CC_C99
20199 Now done by ‘AC_PROG_CC’ (*note AC_PROG_CC::).
20200
20201 — Macro: AC_PROG_CC_STDC
20202 Now done by ‘AC_PROG_CC’ (*note AC_PROG_CC::).
20203
20204 — Macro: AC_PROG_GCC_TRADITIONAL
20205 Used to put GCC into “traditional” (pre-ISO C) compilation mode, on
20206 systems with headers that did not work correctly with a
20207 standard-compliant compiler. GCC has not supported traditional
20208 compilation in many years, and all of the systems that required
20209 this are long obsolete themselves. This macro is now a
20210 compatibility synonym for ‘AC_PROG_CC’ (*note AC_PROG_CC::).
20211
20212 — Macro: AC_PROGRAMS_CHECK
20213 Replaced by ‘AC_CHECK_PROGS’ (*note AC_CHECK_PROGS::).
20214
20215 — Macro: AC_PROGRAMS_PATH
20216 Replaced by ‘AC_PATH_PROGS’ (*note AC_PATH_PROGS::).
20217
20218 — Macro: AC_PROGRAM_CHECK
20219 Replaced by ‘AC_CHECK_PROG’ (*note AC_CHECK_PROG::).
20220
20221 — Macro: AC_PROGRAM_EGREP
20222 Replaced by ‘AC_EGREP_CPP’ (*note AC_EGREP_CPP::).
20223
20224 — Macro: AC_PROGRAM_PATH
20225 Replaced by ‘AC_PATH_PROG’ (*note AC_PATH_PROG::).
20226
20227 — Macro: AC_REMOTE_TAPE
20228 Removed because of limited usefulness.
20229
20230 — Macro: AC_RESTARTABLE_SYSCALLS
20231 This macro was renamed ‘AC_SYS_RESTARTABLE_SYSCALLS’. However,
20232 these days portable programs should use ‘sigaction’ with
20233 ‘SA_RESTART’ if they want restartable system calls. They should
20234 not rely on ‘HAVE_RESTARTABLE_SYSCALLS’, since nowadays whether a
20235 system call is restartable is a dynamic issue, not a
20236 configuration-time issue.
20237
20238 — Macro: AC_RETSIGTYPE
20239 Replaced by ‘AC_TYPE_SIGNAL’ (*note AC_TYPE_SIGNAL::), which itself
20240 is obsolete.
20241
20242 — Macro: AC_RSH
20243 Removed because of limited usefulness.
20244
20245 — Macro: AC_SCO_INTL
20246 Equivalent to the obsolescent macro ‘AC_FUNC_STRFTIME’. *Note
20247 AC_FUNC_STRFTIME::.
20248
20249 — Macro: AC_SETVBUF_REVERSED
20250 Replaced by
20251 AC_FUNC_SETVBUF_REVERSED
20252 *Note AC_FUNC_SETVBUF_REVERSED::.
20253
20254 — Macro: AC_SET_MAKE
20255 Replaced by ‘AC_PROG_MAKE_SET’ (*note AC_PROG_MAKE_SET::).
20256
20257 — Macro: AC_SIZEOF_TYPE
20258 Replaced by ‘AC_CHECK_SIZEOF’ (*note AC_CHECK_SIZEOF::).
20259
20260 — Macro: AC_SIZE_T
20261 Replaced by ‘AC_TYPE_SIZE_T’ (*note AC_TYPE_SIZE_T::).
20262
20263 — Macro: AC_STAT_MACROS_BROKEN
20264 Replaced by ‘AC_HEADER_STAT’ (*note AC_HEADER_STAT::).
20265
20266 — Macro: AC_STDC_HEADERS
20267 Replaced by ‘AC_HEADER_STDC’ (*note AC_HEADER_STDC::), which is
20268 itself obsolete. Nowadays it is safe to assume the facilities of
20269 C89 exist.
20270
20271 — Macro: AC_STRCOLL
20272 Replaced by ‘AC_FUNC_STRCOLL’ (*note AC_FUNC_STRCOLL::).
20273
20274 — Macro: AC_STRUCT_ST_BLKSIZE
20275 If ‘struct stat’ contains an ‘st_blksize’ member, define
20276 ‘HAVE_STRUCT_STAT_ST_BLKSIZE’. The former name, ‘HAVE_ST_BLKSIZE’
20277 is to be avoided, as its support will cease in the future. This
20278 macro is obsoleted, and should be replaced by
20279
20280 AC_CHECK_MEMBERS([struct stat.st_blksize])
20281 *Note AC_CHECK_MEMBERS::.
20282
20283 — Macro: AC_STRUCT_ST_RDEV
20284 If ‘struct stat’ contains an ‘st_rdev’ member, define
20285 ‘HAVE_STRUCT_STAT_ST_RDEV’. The former name for this macro,
20286 ‘HAVE_ST_RDEV’, is to be avoided as it will cease to be supported
20287 in the future. Actually, even the new macro is obsolete and should
20288 be replaced by:
20289 AC_CHECK_MEMBERS([struct stat.st_rdev])
20290 *Note AC_CHECK_MEMBERS::.
20291
20292 — Macro: AC_ST_BLKSIZE
20293 Replaced by ‘AC_CHECK_MEMBERS’ (*note AC_CHECK_MEMBERS::).
20294
20295 — Macro: AC_ST_BLOCKS
20296 Replaced by ‘AC_STRUCT_ST_BLOCKS’ (*note AC_STRUCT_ST_BLOCKS::).
20297
20298 — Macro: AC_ST_RDEV
20299 Replaced by ‘AC_CHECK_MEMBERS’ (*note AC_CHECK_MEMBERS::).
20300
20301 — Macro: AC_SYS_RESTARTABLE_SYSCALLS
20302 If the system automatically restarts a system call that is
20303 interrupted by a signal, define ‘HAVE_RESTARTABLE_SYSCALLS’. This
20304 macro does not check whether system calls are restarted in
20305 general—it checks whether a signal handler installed with ‘signal’
20306 (but not ‘sigaction’) causes system calls to be restarted. It does
20307 not check whether system calls can be restarted when interrupted by
20308 signals that have no handler.
20309
20310 These days portable programs should use ‘sigaction’ with
20311 ‘SA_RESTART’ if they want restartable system calls. They should
20312 not rely on ‘HAVE_RESTARTABLE_SYSCALLS’, since nowadays whether a
20313 system call is restartable is a dynamic issue, not a
20314 configuration-time issue.
20315
20316 — Macro: AC_SYS_SIGLIST_DECLARED
20317 This macro was renamed ‘AC_DECL_SYS_SIGLIST’. However, even that
20318 name is obsolete, as the same functionality is now achieved via
20319 ‘AC_CHECK_DECLS’ (*note AC_CHECK_DECLS::).
20320
20321 — Macro: AC_TEST_CPP
20322 This macro was renamed ‘AC_TRY_CPP’, which in turn was replaced by
20323 ‘AC_PREPROC_IFELSE’ (*note AC_PREPROC_IFELSE::).
20324
20325 — Macro: AC_TEST_PROGRAM
20326 This macro was renamed ‘AC_TRY_RUN’, which in turn was replaced by
20327 ‘AC_RUN_IFELSE’ (*note AC_RUN_IFELSE::).
20328
20329 — Macro: AC_TIMEZONE
20330 Replaced by ‘AC_STRUCT_TIMEZONE’ (*note AC_STRUCT_TIMEZONE::).
20331
20332 — Macro: AC_TIME_WITH_SYS_TIME
20333 Replaced by ‘AC_HEADER_TIME’ (*note AC_HEADER_TIME::), which is
20334 itself obsolete; nowadays one need only do
20335 ‘AC_CHECK_HEADERS([sys/time.h])’.
20336
20337 — Macro: AC_TRY_COMPILE(INCLUDES, FUNCTION-BODY, [ACTION-IF-TRUE],
20338 [ACTION-IF-FALSE])
20339 Same as:
20340
20341 AC_COMPILE_IFELSE(
20342 [AC_LANG_PROGRAM([[INCLUDES]],
20343 [[FUNCTION-BODY]])],
20344 [ACTION-IF-TRUE],
20345 [ACTION-IF-FALSE])
20346
20347 *Note Running the Compiler::.
20348
20349 This macro double quotes both INCLUDES and FUNCTION-BODY.
20350
20351 For C and C++, INCLUDES is any ‘#include’ statements needed by the
20352 code in FUNCTION-BODY (INCLUDES is ignored if the currently
20353 selected language is Fortran or Fortran 77). The compiler and
20354 compilation flags are determined by the current language (*note
20355 Language Choice::).
20356
20357 — Macro: AC_TRY_CPP(INPUT, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
20358 Same as:
20359
20360 AC_PREPROC_IFELSE(
20361 [AC_LANG_SOURCE([[INPUT]])],
20362 [ACTION-IF-TRUE],
20363 [ACTION-IF-FALSE])
20364
20365 *Note Running the Preprocessor::.
20366
20367 This macro double quotes the INPUT.
20368
20369 — Macro: AC_TRY_LINK(INCLUDES, FUNCTION-BODY, [ACTION-IF-TRUE],
20370 [ACTION-IF-FALSE])
20371 Same as:
20372
20373 AC_LINK_IFELSE(
20374 [AC_LANG_PROGRAM([[INCLUDES]],
20375 [[FUNCTION-BODY]])],
20376 [ACTION-IF-TRUE],
20377 [ACTION-IF-FALSE])
20378
20379 *Note Running the Linker::.
20380
20381 This macro double quotes both INCLUDES and FUNCTION-BODY.
20382
20383 Depending on the current language (*note Language Choice::), create
20384 a test program to see whether a function whose body consists of
20385 FUNCTION-BODY can be compiled and linked. If the file compiles and
20386 links successfully, run shell commands ACTION-IF-FOUND, otherwise
20387 run ACTION-IF-NOT-FOUND.
20388
20389 This macro double quotes both INCLUDES and FUNCTION-BODY.
20390
20391 For C and C++, INCLUDES is any ‘#include’ statements needed by the
20392 code in FUNCTION-BODY (INCLUDES is ignored if the currently
20393 selected language is Fortran or Fortran 77). The compiler and
20394 compilation flags are determined by the current language (*note
20395 Language Choice::), and in addition ‘LDFLAGS’ and ‘LIBS’ are used
20396 for linking.
20397
20398 — Macro: AC_TRY_LINK_FUNC(FUNCTION, [ACTION-IF-FOUND],
20399 [ACTION-IF-NOT-FOUND])
20400 This macro is equivalent to
20401 AC_LINK_IFELSE([AC_LANG_CALL([], [FUNCTION])],
20402 [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
20403 *Note Running the Linker::.
20404
20405 — Macro: AC_TRY_RUN(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE],
20406 [ACTION-IF-CROSS-COMPILING = AC_MSG_FAILURE])
20407 Same as:
20408
20409 AC_RUN_IFELSE(
20410 [AC_LANG_SOURCE([[PROGRAM]])],
20411 [ACTION-IF-TRUE],
20412 [ACTION-IF-FALSE],
20413 [ACTION-IF-CROSS-COMPILING])
20414
20415 *Note Runtime::.
20416
20417 — Macro: AC_TYPE_SIGNAL
20418 If ‘signal.h’ declares ‘signal’ as returning a pointer to a
20419 function returning ‘void’, define ‘RETSIGTYPE’ to be ‘void’;
20420 otherwise, define it to be ‘int’. These days, it is portable to
20421 assume C89, and that signal handlers return ‘void’, without needing
20422 to use this macro or ‘RETSIGTYPE’.
20423
20424 — Macro: AC_UID_T
20425 Replaced by ‘AC_TYPE_UID_T’ (*note AC_TYPE_UID_T::).
20426
20427 — Macro: AC_UNISTD_H
20428 Same as ‘AC_CHECK_HEADERS([unistd.h])’ (*note AC_CHECK_HEADERS::),
20429 which is one of the tests done as a side effect by
20430 ‘AC_INCLUDES_DEFAULT’ (*note Default Includes::), so usually
20431 unnecessary to write explicitly.
20432
20433 — Macro: AC_USG
20434 Define ‘USG’ if the BSD string functions (‘bcopy’, ‘bzero’,
20435 ‘index’, ‘rindex’, etc) are _not_ defined in ‘strings.h’. Modern
20436 code should assume ‘string.h’ exists and should use the standard C
20437 string functions (‘memmove’, ‘memset’, ‘strchr’, ‘strrchr’, etc)
20438 unconditionally.
20439
20440 ‘strings.h’ may be the only header that declares ‘strcasecmp’,
20441 ‘strncasecmp’, and ‘ffs’. ‘AC_INCLUDES_DEFAULT’ checks for it
20442 (*note Default Includes::); test ‘HAVE_STRINGS_H’.
20443
20444 — Macro: AC_UTIME_NULL
20445 Replaced by ‘AC_FUNC_UTIME_NULL’ (*note AC_FUNC_UTIME_NULL::).
20446
20447 — Macro: AC_VALIDATE_CACHED_SYSTEM_TUPLE([CMD])
20448 If the cache file is inconsistent with the current host, target and
20449 build system types, it used to execute CMD or print a default error
20450 message. This is now handled by default.
20451
20452 — Macro: AC_VERBOSE(RESULT-DESCRIPTION)
20453 Replaced by ‘AC_MSG_RESULT’ (*note AC_MSG_RESULT::).
20454
20455 — Macro: AC_VFORK
20456 Replaced by ‘AC_FUNC_FORK’ (*note AC_FUNC_FORK::).
20457
20458 — Macro: AC_VPRINTF
20459 Replaced by ‘AC_FUNC_VPRINTF’ (*note AC_FUNC_VPRINTF::).
20460
20461 — Macro: AC_WAIT3
20462 This macro was renamed ‘AC_FUNC_WAIT3’. However, these days
20463 portable programs should use ‘waitpid’, not ‘wait3’, as ‘wait3’ has
20464 been removed from POSIX.
20465
20466 — Macro: AC_WARN
20467 Replaced by ‘AC_MSG_WARN’ (*note AC_MSG_WARN::).
20468
20469 — Macro: AC_WARNING(MESSAGE)
20470 Replaced by ‘m4_warn’ (*note m4_warn::).
20471
20472 — Macro: AC_WITH(PACKAGE, ACTION-IF-GIVEN, [ACTION-IF-NOT-GIVEN])
20473 This is an obsolete version of ‘AC_ARG_WITH’ that does not support
20474 providing a help string (*note AC_ARG_WITH::).
20475
20476 — Macro: AC_WORDS_BIGENDIAN
20477 Replaced by ‘AC_C_BIGENDIAN’ (*note AC_C_BIGENDIAN::).
20478
20479 — Macro: AC_XENIX_DIR
20480 This macro is equivalent to the obsolescent ‘AC_HEADER_DIRENT’
20481 macro, plus it also sets the shell variable ‘XENIX’. Don’t use
20482 this macro, the dignified means to check the nature of the host is
20483 using ‘AC_CANONICAL_HOST’ (*note Canonicalizing::).
20484
20485 — Macro: AC_YYTEXT_POINTER
20486 This macro was renamed ‘AC_DECL_YYTEXT’, which in turn was
20487 integrated into ‘AC_PROG_LEX’ (*note AC_PROG_LEX::).
20488
20489 
20490 File: autoconf.info, Node: Autoconf 1, Next: Autoconf 2.13, Prev: Obsolete Macros, Up: Obsolete Constructs
20491
20492 18.5 Upgrading From Version 1
20493 =============================
20494
20495 Autoconf version 2 is mostly backward compatible with version 1.
20496 However, it introduces better ways to do some things, and doesn’t
20497 support some of the ugly things in version 1. So, depending on how
20498 sophisticated your ‘configure.ac’ files are, you might have to do some
20499 manual work in order to upgrade to version 2. This chapter points out
20500 some problems to watch for when upgrading. Also, perhaps your
20501 ‘configure’ scripts could benefit from some of the new features in
20502 version 2; the changes are summarized in the file ‘NEWS’ in the Autoconf
20503 distribution.
20504
20505 * Menu:
20506
20507 * Changed File Names:: Files you might rename
20508 * Changed Makefiles:: New things to put in ‘Makefile.in’
20509 * Changed Macros:: Macro calls you might replace
20510 * Changed Results:: Changes in how to check test results
20511 * Changed Macro Writing:: Better ways to write your own macros
20512
20513 
20514 File: autoconf.info, Node: Changed File Names, Next: Changed Makefiles, Up: Autoconf 1
20515
20516 18.5.1 Changed File Names
20517 -------------------------
20518
20519 If you have an ‘aclocal.m4’ installed with Autoconf (as opposed to in a
20520 particular package’s source directory), you must rename it to
20521 ‘acsite.m4’. *Note autoconf Invocation::.
20522
20523 If you distribute ‘install.sh’ with your package, rename it to
20524 ‘install-sh’ so ‘make’ builtin rules don’t inadvertently create a file
20525 called ‘install’ from it. ‘AC_PROG_INSTALL’ looks for the script under
20526 both names, but it is best to use the new name.
20527
20528 If you were using ‘config.h.top’, ‘config.h.bot’, or ‘acconfig.h’,
20529 you still can, but you have less clutter if you use the ‘AH_’ macros.
20530 *Note Autoheader Macros::.
20531
20532 
20533 File: autoconf.info, Node: Changed Makefiles, Next: Changed Macros, Prev: Changed File Names, Up: Autoconf 1
20534
20535 18.5.2 Changed Makefiles
20536 ------------------------
20537
20538 Add ‘@CFLAGS@’, ‘@CPPFLAGS@’, and ‘@LDFLAGS@’ in your ‘Makefile.in’
20539 files, so they can take advantage of the values of those variables in
20540 the environment when ‘configure’ is run. Doing this isn’t necessary,
20541 but it’s a convenience for users.
20542
20543 Also add ‘@configure_input@’ in a comment to each input file for
20544 ‘AC_OUTPUT’, so that the output files contain a comment saying they were
20545 produced by ‘configure’. Automatically selecting the right comment
20546 syntax for all the kinds of files that people call ‘AC_OUTPUT’ on became
20547 too much work.
20548
20549 Add ‘config.log’ and ‘config.cache’ to the list of files you remove
20550 in ‘distclean’ targets.
20551
20552 If you have the following in ‘Makefile.in’:
20553
20554 prefix = /usr/local
20555 exec_prefix = $(prefix)
20556
20557 you must change it to:
20558
20559 prefix = @prefix@
20560 exec_prefix = @exec_prefix@
20561
20562 The old behavior of replacing those variables without ‘@’ characters
20563 around them has been removed.
20564
20565 
20566 File: autoconf.info, Node: Changed Macros, Next: Changed Results, Prev: Changed Makefiles, Up: Autoconf 1
20567
20568 18.5.3 Changed Macros
20569 ---------------------
20570
20571 Many of the macros were renamed in Autoconf version 2. You can still
20572 use the old names, but the new ones are clearer, and it’s easier to find
20573 the documentation for them. *Note Obsolete Macros::, for a table
20574 showing the new names for the old macros. Use the ‘autoupdate’ program
20575 to convert your ‘configure.ac’ to using the new macro names. *Note
20576 autoupdate Invocation::.
20577
20578 Some macros have been superseded by similar ones that do the job
20579 better, but are not call-compatible. If you get warnings about calling
20580 obsolete macros while running ‘autoconf’, you may safely ignore them,
20581 but your ‘configure’ script generally works better if you follow the
20582 advice that is printed about what to replace the obsolete macros with.
20583 In particular, the mechanism for reporting the results of tests has
20584 changed. If you were using ‘echo’ or ‘AC_VERBOSE’ (perhaps via
20585 ‘AC_COMPILE_CHECK’), your ‘configure’ script’s output looks better if
20586 you switch to ‘AC_MSG_CHECKING’ and ‘AC_MSG_RESULT’. *Note Printing
20587 Messages::. Those macros work best in conjunction with cache variables.
20588 *Note Caching Results::.
20589
20590 
20591 File: autoconf.info, Node: Changed Results, Next: Changed Macro Writing, Prev: Changed Macros, Up: Autoconf 1
20592
20593 18.5.4 Changed Results
20594 ----------------------
20595
20596 If you were checking the results of previous tests by examining the
20597 shell variable ‘DEFS’, you need to switch to checking the values of the
20598 cache variables for those tests. ‘DEFS’ no longer exists while
20599 ‘configure’ is running; it is only created when generating output files.
20600 This difference from version 1 is because properly quoting the contents
20601 of that variable turned out to be too cumbersome and inefficient to do
20602 every time ‘AC_DEFINE’ is called. *Note Cache Variable Names::.
20603
20604 For example, here is a ‘configure.ac’ fragment written for Autoconf
20605 version 1:
20606
20607 AC_HAVE_FUNCS(syslog)
20608 case "$DEFS" in
20609 *-DHAVE_SYSLOG*) ;;
20610 *) # syslog is not in the default libraries. See if it's in some other.
20611 saved_LIBS="$LIBS"
20612 for lib in bsd socket inet; do
20613 AC_CHECKING(for syslog in -l$lib)
20614 LIBS="-l$lib $saved_LIBS"
20615 AC_HAVE_FUNCS(syslog)
20616 case "$DEFS" in
20617 *-DHAVE_SYSLOG*) break ;;
20618 *) ;;
20619 esac
20620 LIBS="$saved_LIBS"
20621 done ;;
20622 esac
20623
20624 Here is a way to write it for version 2:
20625
20626 AC_CHECK_FUNCS([syslog])
20627 AS_IF([test "x$ac_cv_func_syslog" = xno],
20628 [# syslog is not in the default libraries. See if it's in some other.
20629 for lib in bsd socket inet; do
20630 AC_CHECK_LIB([$lib], [syslog],
20631 [AC_DEFINE([HAVE_SYSLOG])
20632 LIBS="-l$lib $LIBS"; break])
20633 done])
20634
20635 If you were working around bugs in ‘AC_DEFINE_UNQUOTED’ by adding
20636 backslashes before quotes, you need to remove them. It now works
20637 predictably, and does not treat quotes (except back quotes) specially.
20638 *Note Setting Output Variables::.
20639
20640 All of the Boolean shell variables set by Autoconf macros now use
20641 ‘yes’ for the true value. Most of them use ‘no’ for false, though for
20642 backward compatibility some use the empty string instead. If you were
20643 relying on a shell variable being set to something like 1 or ‘t’ for
20644 true, you need to change your tests.
20645
20646 
20647 File: autoconf.info, Node: Changed Macro Writing, Prev: Changed Results, Up: Autoconf 1
20648
20649 18.5.5 Changed Macro Writing
20650 ----------------------------
20651
20652 When defining your own macros, you should now use ‘AC_DEFUN’ instead of
20653 ‘define’. ‘AC_DEFUN’ automatically calls ‘AC_PROVIDE’ and ensures that
20654 macros called via ‘AC_REQUIRE’ do not interrupt other macros, to prevent
20655 nested ‘checking...’ messages on the screen. There’s no actual harm in
20656 continuing to use the older way, but it’s less convenient and
20657 attractive. *Note Macro Definitions::.
20658
20659 You probably looked at the macros that came with Autoconf as a guide
20660 for how to do things. It would be a good idea to take a look at the new
20661 versions of them, as the style is somewhat improved and they take
20662 advantage of some new features.
20663
20664 If you were doing tricky things with undocumented Autoconf internals
20665 (macros, variables, diversions), check whether you need to change
20666 anything to account for changes that have been made. Perhaps you can
20667 even use an officially supported technique in version 2 instead of
20668 kludging. Or perhaps not.
20669
20670 To speed up your locally written feature tests, add caching to them.
20671 See whether any of your tests are of general enough usefulness to
20672 encapsulate them into macros that you can share.
20673
20674 
20675 File: autoconf.info, Node: Autoconf 2.13, Prev: Autoconf 1, Up: Obsolete Constructs
20676
20677 18.6 Upgrading From Version 2.13
20678 ================================
20679
20680 The introduction of the previous section (*note Autoconf 1::) perfectly
20681 suits this section...
20682
20683 Autoconf version 2.50 is mostly backward compatible with version
20684 2.13. However, it introduces better ways to do some things, and
20685 doesn’t support some of the ugly things in version 2.13. So,
20686 depending on how sophisticated your ‘configure.ac’ files are, you
20687 might have to do some manual work in order to upgrade to version
20688 2.50. This chapter points out some problems to watch for when
20689 upgrading. Also, perhaps your ‘configure’ scripts could benefit
20690 from some of the new features in version 2.50; the changes are
20691 summarized in the file ‘NEWS’ in the Autoconf distribution.
20692
20693 * Menu:
20694
20695 * Changed Quotation:: Broken code which used to work
20696 * New Macros:: Interaction with foreign macros
20697 * Hosts and Cross-Compilation:: Bugward compatibility kludges
20698 * AC_LIBOBJ vs LIBOBJS:: LIBOBJS is a forbidden token
20699 * AC_ACT_IFELSE vs AC_TRY_ACT:: A more generic scheme for testing sources
20700
20701 
20702 File: autoconf.info, Node: Changed Quotation, Next: New Macros, Up: Autoconf 2.13
20703
20704 18.6.1 Changed Quotation
20705 ------------------------
20706
20707 The most important changes are invisible to you: the implementation of
20708 most macros have completely changed. This allowed more factorization of
20709 the code, better error messages, a higher uniformity of the user’s
20710 interface etc. Unfortunately, as a side effect, some construct which
20711 used to (miraculously) work might break starting with Autoconf 2.50.
20712 The most common culprit is bad quotation.
20713
20714 For instance, in the following example, the message is not properly
20715 quoted:
20716
20717 AC_INIT
20718 AC_CHECK_HEADERS(foo.h, ,
20719 AC_MSG_ERROR(cannot find foo.h, bailing out))
20720 AC_OUTPUT
20721
20722 Autoconf 2.13 simply ignores it:
20723
20724 $ autoconf-2.13; ./configure --silent
20725 creating cache ./config.cache
20726 configure: error: cannot find foo.h
20727 $
20728
20729 while Autoconf 2.50 produces a broken ‘configure’:
20730
20731 $ autoconf-2.50; ./configure --silent
20732 configure: error: cannot find foo.h
20733 ./configure: exit: bad non-numeric arg `bailing'
20734 ./configure: exit: bad non-numeric arg `bailing'
20735 $
20736
20737 The message needs to be quoted, and the ‘AC_MSG_ERROR’ invocation
20738 too!
20739
20740 AC_INIT([Example], [1.0], [[email protected]])
20741 AC_CHECK_HEADERS([foo.h], [],
20742 [AC_MSG_ERROR([cannot find foo.h, bailing out])])
20743 AC_OUTPUT
20744
20745 Many many (and many more) Autoconf macros were lacking proper
20746 quotation, including no less than... ‘AC_DEFUN’ itself!
20747
20748 $ cat configure.in
20749 AC_DEFUN([AC_PROG_INSTALL],
20750 [# My own much better version
20751 ])
20752 AC_INIT
20753 AC_PROG_INSTALL
20754 AC_OUTPUT
20755 $ autoconf-2.13
20756 autoconf: Undefined macros:
20757 ***BUG in Autoconf--please report*** AC_FD_MSG
20758 ***BUG in Autoconf--please report*** AC_EPI
20759 configure.in:1:AC_DEFUN([AC_PROG_INSTALL],
20760 configure.in:5:AC_PROG_INSTALL
20761 $ autoconf-2.50
20762 $
20763
20764 
20765 File: autoconf.info, Node: New Macros, Next: Hosts and Cross-Compilation, Prev: Changed Quotation, Up: Autoconf 2.13
20766
20767 18.6.2 New Macros
20768 -----------------
20769
20770 While Autoconf was relatively dormant in the late 1990s, Automake
20771 provided Autoconf-like macros for a while. Starting with Autoconf 2.50
20772 in 2001, Autoconf provided versions of these macros, integrated in the
20773 ‘AC_’ namespace, instead of ‘AM_’. But in order to ease the upgrading
20774 via ‘autoupdate’, bindings to such ‘AM_’ macros are provided.
20775
20776 Unfortunately older versions of Automake (e.g., Automake 1.4) did not
20777 quote the names of these macros. Therefore, when ‘m4’ finds something
20778 like ‘AC_DEFUN(AM_TYPE_PTRDIFF_T, ...)’ in ‘aclocal.m4’,
20779 ‘AM_TYPE_PTRDIFF_T’ is expanded, replaced with its Autoconf definition.
20780
20781 Fortunately Autoconf catches pre-‘AC_INIT’ expansions, and complains,
20782 in its own words:
20783
20784 $ cat configure.ac
20785 AC_INIT([Example], [1.0], [[email protected]])
20786 AM_TYPE_PTRDIFF_T
20787 $ aclocal-1.4
20788 $ autoconf
20789 aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversion
20790 aclocal.m4:17: the top level
20791 autom4te: m4 failed with exit status: 1
20792 $
20793
20794 Modern versions of Automake no longer define most of these macros,
20795 and properly quote the names of the remaining macros. If you must use
20796 an old Automake, do not depend upon macros from Automake as it is simply
20797 not its job to provide macros (but the one it requires itself):
20798
20799 $ cat configure.ac
20800 AC_INIT([Example], [1.0], [[email protected]])
20801 AM_TYPE_PTRDIFF_T
20802 $ rm aclocal.m4
20803 $ autoupdate
20804 autoupdate: 'configure.ac' is updated
20805 $ cat configure.ac
20806 AC_INIT([Example], [1.0], [[email protected]])
20807 AC_CHECK_TYPES([ptrdiff_t])
20808 $ aclocal-1.4
20809 $ autoconf
20810 $
20811
20812 
20813 File: autoconf.info, Node: Hosts and Cross-Compilation, Next: AC_LIBOBJ vs LIBOBJS, Prev: New Macros, Up: Autoconf 2.13
20814
20815 18.6.3 Hosts and Cross-Compilation
20816 ----------------------------------
20817
20818 Based on the experience of compiler writers, and after long public
20819 debates, many aspects of the cross-compilation chain have changed:
20820
20821 − the relationship between the build, host, and target architecture
20822 types,
20823
20824 − the command line interface for specifying them to ‘configure’,
20825
20826 − the variables defined in ‘configure’,
20827
20828 − the enabling of cross-compilation mode.
20829
20830
20831 The relationship between build, host, and target have been cleaned
20832 up: the chain of default is now simply: target defaults to host, host to
20833 build, and build to the result of ‘config.guess’. Nevertheless, in
20834 order to ease the transition from 2.13 to 2.50, the following transition
20835 scheme is implemented. _Do not rely on it_, as it will be completely
20836 disabled in a couple of releases (we cannot keep it, as it proves to
20837 cause more problems than it cures).
20838
20839 They all default to the result of running ‘config.guess’, unless you
20840 specify either ‘--build’ or ‘--host’. In this case, the default becomes
20841 the system type you specified. If you specify both, and they’re
20842 different, ‘configure’ enters cross compilation mode, so it doesn’t run
20843 any tests that require execution.
20844
20845 Hint: if you mean to override the result of ‘config.guess’, prefer
20846 ‘--build’ over ‘--host’.
20847
20848
20849 For backward compatibility, ‘configure’ accepts a system type as an
20850 option by itself. Such an option overrides the defaults for build,
20851 host, and target system types. The following configure statement
20852 configures a cross toolchain that runs on NetBSD/aarch64 but generates
20853 code for GNU Hurd/riscv64, which is also the build platform.
20854
20855 ./configure --host=aarch64-netbsd riscv64-gnu
20856
20857
20858 In Autoconf 2.13 and before, the variables ‘build’, ‘host’, and
20859 ‘target’ had a different semantics before and after the invocation of
20860 ‘AC_CANONICAL_BUILD’ etc. Now, the argument of ‘--build’ is strictly
20861 copied into ‘build_alias’, and is left empty otherwise. After the
20862 ‘AC_CANONICAL_BUILD’, ‘build’ is set to the canonicalized build type.
20863 To ease the transition, before, its contents is the same as that of
20864 ‘build_alias’. Do _not_ rely on this broken feature.
20865
20866 For consistency with the backward compatibility scheme exposed above,
20867 when ‘--host’ is specified but ‘--build’ isn’t, the build system is
20868 assumed to be the same as ‘--host’, and ‘build_alias’ is set to that
20869 value. Eventually, this historically incorrect behavior will go away.
20870
20871
20872 The former scheme to enable cross-compilation proved to cause more
20873 harm than good, in particular, it used to be triggered too easily,
20874 leaving regular end users puzzled in front of cryptic error messages.
20875 ‘configure’ could even enter cross-compilation mode only because the
20876 compiler was not functional. This is mainly because ‘configure’ used to
20877 try to detect cross-compilation, instead of waiting for an explicit flag
20878 from the user.
20879
20880 Now, ‘configure’ enters cross-compilation mode if and only if
20881 ‘--host’ is passed.
20882
20883 That’s the short documentation. To ease the transition between 2.13
20884 and its successors, a more complicated scheme is implemented. _Do not
20885 rely on the following_, as it will be removed in the near future.
20886
20887 If you specify ‘--host’, but not ‘--build’, when ‘configure’ performs
20888 the first compiler test it tries to run an executable produced by the
20889 compiler. If the execution fails, it enters cross-compilation mode.
20890 This is fragile. Moreover, by the time the compiler test is performed,
20891 it may be too late to modify the build-system type: other tests may have
20892 already been performed. Therefore, whenever you specify ‘--host’, be
20893 sure to specify ‘--build’ too.
20894
20895 ./configure --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw64
20896
20897 enters cross-compilation mode. The former interface, which consisted in
20898 setting the compiler to a cross-compiler without informing ‘configure’
20899 is obsolete. For instance, ‘configure’ fails if it can’t run the code
20900 generated by the specified compiler if you configure as follows:
20901
20902 ./configure CC=x86_64-w64-mingw64-gcc
20903
20904 
20905 File: autoconf.info, Node: AC_LIBOBJ vs LIBOBJS, Next: AC_ACT_IFELSE vs AC_TRY_ACT, Prev: Hosts and Cross-Compilation, Up: Autoconf 2.13
20906
20907 18.6.4 ‘AC_LIBOBJ’ vs. ‘LIBOBJS’
20908 --------------------------------
20909
20910 Up to Autoconf 2.13, the replacement of functions was triggered via the
20911 variable ‘LIBOBJS’. Since Autoconf 2.50, the macro ‘AC_LIBOBJ’ should
20912 be used instead (*note Generic Functions::). Starting at Autoconf 2.53,
20913 the use of ‘LIBOBJS’ is an error.
20914
20915 This change is mandated by the unification of the GNU Build System
20916 components. In particular, the various fragile techniques used to parse
20917 a ‘configure.ac’ are all replaced with the use of traces. As a
20918 consequence, any action must be traceable, which obsoletes critical
20919 variable assignments. Fortunately, ‘LIBOBJS’ was the only problem, and
20920 it can even be handled gracefully (read, “without your having to change
20921 something”).
20922
20923 There were two typical uses of ‘LIBOBJS’: asking for a replacement
20924 function, and adjusting ‘LIBOBJS’ for Automake and/or Libtool.
20925
20926
20927 As for function replacement, the fix is immediate: use ‘AC_LIBOBJ’.
20928 For instance:
20929
20930 LIBOBJS="$LIBOBJS fnmatch.o"
20931 LIBOBJS="$LIBOBJS malloc.$ac_objext"
20932
20933 should be replaced with:
20934
20935 AC_LIBOBJ([fnmatch])
20936 AC_LIBOBJ([malloc])
20937
20938
20939 When used with Automake 1.10 or newer, a suitable value for
20940 ‘LIBOBJDIR’ is set so that the ‘LIBOBJS’ and ‘LTLIBOBJS’ can be
20941 referenced from any ‘Makefile.am’. Even without Automake, arranging for
20942 ‘LIBOBJDIR’ to be set correctly enables referencing ‘LIBOBJS’ and
20943 ‘LTLIBOBJS’ in another directory. The ‘LIBOBJDIR’ feature is
20944 experimental.
20945
20946 
20947 File: autoconf.info, Node: AC_ACT_IFELSE vs AC_TRY_ACT, Prev: AC_LIBOBJ vs LIBOBJS, Up: Autoconf 2.13
20948
20949 18.6.5 ‘AC_ACT_IFELSE’ vs. ‘AC_TRY_ACT’
20950 ---------------------------------------
20951
20952 Since Autoconf 2.50, internal codes uses ‘AC_PREPROC_IFELSE’,
20953 ‘AC_COMPILE_IFELSE’, ‘AC_LINK_IFELSE’, and ‘AC_RUN_IFELSE’ on one hand
20954 and ‘AC_LANG_SOURCE’, and ‘AC_LANG_PROGRAM’ on the other hand instead of
20955 the deprecated ‘AC_TRY_CPP’, ‘AC_TRY_COMPILE’, ‘AC_TRY_LINK’, and
20956 ‘AC_TRY_RUN’. The motivations where:
20957 − a more consistent interface: ‘AC_TRY_COMPILE’ etc. were double
20958 quoting their arguments;
20959
20960 − the combinatorial explosion is solved by decomposing on the one
20961 hand the generation of sources, and on the other hand executing the
20962 program;
20963
20964 − this scheme helps supporting more languages than plain C and C++.
20965
20966 In addition to the change of syntax, the philosophy has changed too:
20967 while emphasis was put on speed at the expense of accuracy, today’s
20968 Autoconf promotes accuracy of the testing framework at, ahem..., the
20969 expense of speed.
20970
20971 As a perfect example of what is _not_ to be done, here is how to find
20972 out whether a header file contains a particular declaration, such as a
20973 typedef, a structure, a structure member, or a function. Use
20974 ‘AC_EGREP_HEADER’ instead of running ‘grep’ directly on the header file;
20975 on some systems the symbol might be defined in another header file that
20976 the file you are checking includes.
20977
20978 As a (bad) example, here is how you should not check for C
20979 preprocessor symbols, either defined by header files or predefined by
20980 the C preprocessor: using ‘AC_EGREP_CPP’:
20981
20982 AC_EGREP_CPP(yes,
20983 [#ifdef _AIX
20984 yes
20985 #endif
20986 ], is_aix=yes, is_aix=no)
20987
20988 The above example, properly written would (i) use ‘AC_LANG_PROGRAM’,
20989 and (ii) run the compiler:
20990
20991 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
20992 [[#ifndef _AIX
20993 error: This isn't AIX!
20994 #endif
20995 ]])],
20996 [is_aix=yes],
20997 [is_aix=no])
20998
20999 
21000 File: autoconf.info, Node: Using Autotest, Next: FAQ, Prev: Obsolete Constructs, Up: Top
21001
21002 19 Generating Test Suites with Autotest
21003 ***************************************
21004
21005 *N.B.: This section describes a feature which is still
21006 stabilizing. Although we believe that Autotest is useful as-is, this
21007 documentation describes an interface which might change in the future:
21008 do not depend upon Autotest without subscribing to the Autoconf mailing
21009 lists.*
21010
21011 It is paradoxical that portable projects depend on nonportable tools
21012 to run their test suite. Autoconf by itself is the paragon of this
21013 problem: although it aims at perfectly portability, up to 2.13 its test
21014 suite was using DejaGNU, a rich and complex testing framework, but which
21015 is far from being standard on POSIX systems. Worse yet, it was likely
21016 to be missing on the most fragile platforms, the very platforms that are
21017 most likely to torture Autoconf and exhibit deficiencies.
21018
21019 To circumvent this problem, many package maintainers have developed
21020 their own testing framework, based on simple shell scripts whose sole
21021 outputs are exit status values describing whether the test succeeded.
21022 Most of these tests share common patterns, and this can result in lots
21023 of duplicated code and tedious maintenance.
21024
21025 Following exactly the same reasoning that yielded to the inception of
21026 Autoconf, Autotest provides a test suite generation framework, based on
21027 M4 macros building a portable shell script. The suite itself is
21028 equipped with automatic logging and tracing facilities which greatly
21029 diminish the interaction with bug reporters, and simple timing reports.
21030
21031 Autoconf itself has been using Autotest for years, and we do attest
21032 that it has considerably improved the strength of the test suite and the
21033 quality of bug reports. Other projects are known to use some generation
21034 of Autotest, such as Bison, GNU Wdiff, GNU Tar, each of them with
21035 different needs, and this usage has validated Autotest as a general
21036 testing framework.
21037
21038 Nonetheless, compared to DejaGNU, Autotest is inadequate for
21039 interactive tool testing, which is probably its main limitation.
21040
21041 * Menu:
21042
21043 * Using an Autotest Test Suite:: Autotest and the user
21044 * Writing Testsuites:: Autotest macros
21045 * testsuite Invocation:: Running ‘testsuite’ scripts
21046 * Making testsuite Scripts:: Using autom4te to create ‘testsuite’
21047
21048 
21049 File: autoconf.info, Node: Using an Autotest Test Suite, Next: Writing Testsuites, Up: Using Autotest
21050
21051 19.1 Using an Autotest Test Suite
21052 =================================
21053
21054 * Menu:
21055
21056 * testsuite Scripts:: The concepts of Autotest
21057 * Autotest Logs:: Their contents
21058
21059 
21060 File: autoconf.info, Node: testsuite Scripts, Next: Autotest Logs, Up: Using an Autotest Test Suite
21061
21062 19.1.1 ‘testsuite’ Scripts
21063 --------------------------
21064
21065 Generating testing or validation suites using Autotest is rather easy.
21066 The whole validation suite is held in a file to be processed through
21067 ‘autom4te’, itself using GNU M4 under the hood, to produce a stand-alone
21068 Bourne shell script which then gets distributed. Neither ‘autom4te’ nor
21069 GNU M4 are needed at the installer’s end.
21070
21071 Each test of the validation suite should be part of some test group.
21072 A “test group” is a sequence of interwoven tests that ought to be
21073 executed together, usually because one test in the group creates data
21074 files that a later test in the same group needs to read. Complex test
21075 groups make later debugging more tedious. It is much better to keep
21076 only a few tests per test group. Ideally there is only one test per
21077 test group.
21078
21079 For all but the simplest packages, some file such as ‘testsuite.at’
21080 does not fully hold all test sources, as these are often easier to
21081 maintain in separate files. Each of these separate files holds a single
21082 test group, or a sequence of test groups all addressing some common
21083 functionality in the package. In such cases, ‘testsuite.at’ merely
21084 initializes the validation suite, and sometimes does elementary health
21085 checking, before listing include statements for all other test files.
21086 The special file ‘package.m4’, containing the identification of the
21087 package, is automatically included if found.
21088
21089 A convenient alternative consists in moving all the global issues
21090 (local Autotest macros, elementary health checking, and ‘AT_INIT’
21091 invocation) into the file ‘local.at’, and making ‘testsuite.at’ be a
21092 simple list of ‘m4_include’s of sub test suites. In such case,
21093 generating the whole test suite or pieces of it is only a matter of
21094 choosing the ‘autom4te’ command line arguments.
21095
21096 The validation scripts that Autotest produces are by convention
21097 called ‘testsuite’. When run, ‘testsuite’ executes each test group in
21098 turn, producing only one summary line per test to say if that particular
21099 test succeeded or failed. At end of all tests, summarizing counters get
21100 printed. One debugging directory is left for each test group which
21101 failed, if any: such directories are named ‘testsuite.dir/NN’, where NN
21102 is the sequence number of the test group, and they include:
21103
21104 • a debugging script named ‘run’ which reruns the test in “debug
21105 mode” (*note testsuite Invocation::). The automatic generation of
21106 debugging scripts has the purpose of easing the chase for bugs.
21107
21108 • all the files created with ‘AT_DATA’
21109
21110 • all the Erlang source code files created with ‘AT_CHECK_EUNIT’
21111
21112 • a log of the run, named ‘testsuite.log’
21113
21114 In the ideal situation, none of the tests fail, and consequently no
21115 debugging directory is left behind for validation.
21116
21117 It often happens in practice that individual tests in the validation
21118 suite need to get information coming out of the configuration process.
21119 Some of this information, common for all validation suites, is provided
21120 through the file ‘atconfig’, automatically created by
21121 ‘AC_CONFIG_TESTDIR’. For configuration information which your testing
21122 environment specifically needs, you might prepare an optional file named
21123 ‘atlocal.in’, instantiated by ‘AC_CONFIG_FILES’. The configuration
21124 process produces ‘atconfig’ and ‘atlocal’ out of these two input files,
21125 and these two produced files are automatically read by the ‘testsuite’
21126 script.
21127
21128 Here is a diagram showing the relationship between files.
21129
21130 Files used in preparing a software package for distribution:
21131
21132 [package.m4] -->.
21133 \
21134 subfile-1.at ->. [local.at] ---->+
21135 ... \ \
21136 subfile-i.at ---->-- testsuite.at -->-- autom4te* -->testsuite
21137 ... /
21138 subfile-n.at ->'
21139
21140 Files used in configuring a software package:
21141
21142 .--> atconfig
21143 /
21144 [atlocal.in] --> config.status* --<
21145 \
21146 `--> [atlocal]
21147
21148 Files created during test suite execution:
21149
21150 atconfig -->. .--> testsuite.log
21151 \ /
21152 >-- testsuite* --<
21153 / \
21154 [atlocal] ->' `--> [testsuite.dir]
21155
21156 
21157 File: autoconf.info, Node: Autotest Logs, Prev: testsuite Scripts, Up: Using an Autotest Test Suite
21158
21159 19.1.2 Autotest Logs
21160 --------------------
21161
21162 When run, the test suite creates a log file named after itself, e.g., a
21163 test suite named ‘testsuite’ creates ‘testsuite.log’. It contains a lot
21164 of information, usually more than maintainers actually need, but
21165 therefore most of the time it contains all that is needed:
21166
21167 command line arguments
21168 A bad but unfortunately widespread habit consists of setting
21169 environment variables before the command, such as in
21170 ‘CC=my-home-grown-cc ./testsuite’. The test suite does not know
21171 this change, hence (i) it cannot report it to you, and (ii) it
21172 cannot preserve the value of ‘CC’ for subsequent runs. Autoconf
21173 faced exactly the same problem, and solved it by asking users to
21174 pass the variable definitions as command line arguments. Autotest
21175 requires this rule, too, but has no means to enforce it; the log
21176 then contains a trace of the variables that were changed by the
21177 user.
21178
21179 ‘ChangeLog’ excerpts
21180 The topmost lines of all the ‘ChangeLog’ files found in the source
21181 hierarchy. This is especially useful when bugs are reported
21182 against development versions of the package, since the version
21183 string does not provide sufficient information to know the exact
21184 state of the sources the user compiled. Of course, this relies on
21185 the use of a ‘ChangeLog’.
21186
21187 build machine
21188 Running a test suite in a cross-compile environment is not an easy
21189 task, since it would mean having the test suite run on a machine
21190 BUILD, while running programs on a machine HOST. It is much
21191 simpler to run both the test suite and the programs on HOST, but
21192 then, from the point of view of the test suite, there remains a
21193 single environment, HOST = BUILD. The log contains relevant
21194 information on the state of the BUILD machine, including some
21195 important environment variables.
21196
21197 tested programs
21198 The absolute file name and answers to ‘--version’ of the tested
21199 programs (see *note Writing Testsuites::, ‘AT_TESTED’).
21200
21201 configuration log
21202 The contents of ‘config.log’, as created by ‘configure’, are
21203 appended. It contains the configuration flags and a detailed
21204 report on the configuration itself.
21205
21206 
21207 File: autoconf.info, Node: Writing Testsuites, Next: testsuite Invocation, Prev: Using an Autotest Test Suite, Up: Using Autotest
21208
21209 19.2 Writing ‘testsuite.at’
21210 ===========================
21211
21212 The ‘testsuite.at’ is a Bourne shell script making use of special
21213 Autotest M4 macros. It often contains a call to ‘AT_INIT’ near its
21214 beginning followed by one call to ‘m4_include’ per source file for
21215 tests. Each such included file, or the remainder of ‘testsuite.at’ if
21216 include files are not used, contain a sequence of test groups. Each
21217 test group begins with a call to ‘AT_SETUP’, then an arbitrary number of
21218 shell commands or calls to ‘AT_CHECK’, and then completes with a call to
21219 ‘AT_CLEANUP’. Multiple test groups can be categorized by a call to
21220 ‘AT_BANNER’.
21221
21222 All of the public Autotest macros have all-uppercase names in the
21223 namespace ‘^AT_’ to prevent them from accidentally conflicting with
21224 other text; Autoconf also reserves the namespace ‘^_AT_’ for internal
21225 macros. All shell variables used in the testsuite for internal purposes
21226 have mostly-lowercase names starting with ‘at_’. Autotest also uses
21227 here-document delimiters in the namespace ‘^_AT[A-Z]’, and makes use of
21228 the file system namespace ‘^at-’.
21229
21230 Since Autoconf is built on top of M4sugar (*note Programming in
21231 M4sugar::) and M4sh (*note Programming in M4sh::), you must also be
21232 aware of those namespaces (‘^_?\(m4\|AS\)_’). In general, you _should
21233 not use_ the namespace of a package that does not own the macro or shell
21234 code you are writing.
21235
21236 — Macro: AT_INIT([NAME])
21237 Initialize Autotest. Giving a NAME to the test suite is encouraged
21238 if your package includes several test suites. Before this macro is
21239 called, ‘AT_PACKAGE_STRING’ and ‘AT_PACKAGE_BUGREPORT’ must be
21240 defined, which are used to display information about the testsuite
21241 to the user. Typically, these macros are provided by a file
21242 ‘package.m4’ built by ‘make’ (*note Making testsuite Scripts::), in
21243 order to inherit the package name, version, and bug reporting
21244 address from ‘configure.ac’.
21245
21246 — Macro: AT_COPYRIGHT(COPYRIGHT-NOTICE)
21247 State that, in addition to the Free Software Foundation’s copyright
21248 on the Autotest macros, parts of your test suite are covered by
21249 COPYRIGHT-NOTICE.
21250
21251 The COPYRIGHT-NOTICE shows up in both the head of ‘testsuite’ and
21252 in ‘testsuite --version’.
21253
21254 — Macro: AT_ARG_OPTION(OPTIONS, HELP-TEXT, [ACTION-IF-GIVEN],
21255 [ACTION-IF-NOT-GIVEN])
21256 Accept options from the space-separated list OPTIONS, a list that
21257 has leading dashes removed from the options. Long options will be
21258 prefixed with ‘--’, single-character options with ‘-’. The first
21259 word in this list is the primary OPTION, any others are assumed to
21260 be short-hand aliases. The variable associated with it is
21261 ‘at_arg_OPTION’, with any dashes in OPTION replaced with
21262 underscores.
21263
21264 If the user passes ‘--OPTION’ to the ‘testsuite’, the variable will
21265 be set to ‘:’. If the user does not pass the option, or passes
21266 ‘--no-OPTION’, then the variable will be set to ‘false’.
21267
21268 ACTION-IF-GIVEN is run each time the option is encountered; here,
21269 the variable ‘at_optarg’ will be set to ‘:’ or ‘false’ as
21270 appropriate. ‘at_optarg’ is actually just a copy of
21271 ‘at_arg_OPTION’.
21272
21273 ACTION-IF-NOT-GIVEN will be run once after option parsing is
21274 complete and if no option from OPTIONS was used.
21275
21276 HELP-TEXT is added to the end of the list of options shown in
21277 ‘testsuite --help’ (*note AS_HELP_STRING::).
21278
21279 It is recommended that you use a package-specific prefix to OPTIONS
21280 names in order to avoid clashes with future Autotest built-in
21281 options.
21282
21283 — Macro: AT_ARG_OPTION_ARG(OPTIONS, HELP-TEXT, [ACTION-IF-GIVEN],
21284 [ACTION-IF-NOT-GIVEN])
21285 Accept options with arguments from the space-separated list
21286 OPTIONS, a list that has leading dashes removed from the options.
21287 Long options will be prefixed with ‘--’, single-character options
21288 with ‘-’. The first word in this list is the primary OPTION, any
21289 others are assumed to be short-hand aliases. The variable
21290 associated with it is ‘at_arg_OPTION’, with any dashes in OPTION
21291 replaced with underscores.
21292
21293 If the user passes ‘--OPTION=ARG’ or ‘--OPTION ARG’ to the
21294 ‘testsuite’, the variable will be set to ‘ARG’.
21295
21296 ACTION-IF-GIVEN is run each time the option is encountered; here,
21297 the variable ‘at_optarg’ will be set to ‘ARG’. ‘at_optarg’ is
21298 actually just a copy of ‘at_arg_OPTION’.
21299
21300 ACTION-IF-NOT-GIVEN will be run once after option parsing is
21301 complete and if no option from OPTIONS was used.
21302
21303 HELP-TEXT is added to the end of the list of options shown in
21304 ‘testsuite --help’ (*note AS_HELP_STRING::).
21305
21306 It is recommended that you use a package-specific prefix to OPTIONS
21307 names in order to avoid clashes with future Autotest built-in
21308 options.
21309
21310 — Macro: AT_COLOR_TESTS
21311 Enable colored test results by default when the output is connected
21312 to a terminal.
21313
21314 — Macro: AT_TESTED(EXECUTABLES)
21315 Log the file name and answer to ‘--version’ of each program in
21316 space-separated list EXECUTABLES. Several invocations register new
21317 executables, in other words, don’t fear registering one program
21318 several times.
21319
21320 Autotest test suites rely on ‘PATH’ to find the tested program.
21321 This avoids the need to generate absolute names of the various
21322 tools, and makes it possible to test installed programs.
21323 Therefore, knowing which programs are being exercised is crucial to
21324 understanding problems in the test suite itself, or its occasional
21325 misuses. It is a good idea to also subscribe foreign programs you
21326 depend upon, to avoid incompatible diagnostics.
21327
21328 EXECUTABLES is implicitly wrapped in shell double quotes, but it
21329 will still use shell variable expansion (‘$’), command substitution
21330 (‘`’), and backslash escaping (‘\’). In particular, the ‘EXEEXT’
21331 variable is available if it is passed to the testsuite via
21332 ‘atlocal’ or ‘atconfig’.
21333
21334 — Macro: AT_PREPARE_TESTS(SHELL-CODE)
21335 Execute SHELL-CODE in the main testsuite process, after
21336 initializing the test suite and processing command-line options,
21337 but before running any tests. If this macro is used several times,
21338 all of the SHELL-CODEs will be executed, in the order they appeared
21339 in ‘testsuite.at’.
21340
21341 One reason to use ‘AT_PREPARE_TESTS’ is when the programs under
21342 test are sensitive to environment variables: you can unset all
21343 these variables or reset them to safe values in SHELL-CODE.
21344
21345 SHELL-CODE is only executed if at least one test is going to be
21346 run. In particular, it will not be executed if any of the
21347 ‘--help’, ‘--version’, ‘--list’, or ‘--clean’ options are given to
21348 ‘testsuite’ (*note testsuite Invocation::).
21349
21350 — Macro: AT_PREPARE_EACH_TEST(SHELL-CODE)
21351 Execute SHELL-CODE in each test group’s subshell, at the point of
21352 the ‘AT_SETUP’ that starts the test group.
21353
21354 — Macro: AT_TEST_HELPER_FN(NAME, ARGS, DESCRIPTION, CODE)
21355 Define a shell function that will be available to the code for each
21356 test group. Its name will be ‘ath_fn_NAME’, and its body will be
21357 CODE. (The prefix prevents name conflicts with shell functions
21358 defined by M4sh and Autotest.)
21359
21360 ARGS should describe the function’s arguments and DESCRIPTION what
21361 it does; these are used only for documentation comments in the
21362 generated testsuite script.
21363
21364
21365 — Macro: AT_BANNER(TEST-CATEGORY-NAME)
21366 This macro identifies the start of a category of related test
21367 groups. When the resulting ‘testsuite’ is invoked with more than
21368 one test group to run, its output will include a banner containing
21369 TEST-CATEGORY-NAME prior to any tests run from that category. The
21370 banner should be no more than about 40 or 50 characters. A blank
21371 banner indicates uncategorized tests; an empty line will be
21372 inserted after tests from an earlier category, effectively ending
21373 that category.
21374
21375 — Macro: AT_SETUP(TEST-GROUP-NAME)
21376 This macro starts a group of related tests, all to be executed in
21377 the same subshell. It accepts a single argument, which holds a few
21378 words (no more than about 30 or 40 characters) quickly describing
21379 the purpose of the test group being started. TEST-GROUP-NAME must
21380 not expand to unbalanced quotes, although quadrigraphs can be used.
21381
21382 — Macro: AT_KEYWORDS(KEYWORDS)
21383 Associate the space-separated list of KEYWORDS to the enclosing
21384 test group. This makes it possible to run “slices” of the test
21385 suite. For instance, if some of your test groups exercise some
21386 ‘foo’ feature, then using ‘AT_KEYWORDS(foo)’ lets you run
21387 ‘./testsuite -k foo’ to run exclusively these test groups. The
21388 TEST-GROUP-NAME of the test group is automatically recorded to
21389 ‘AT_KEYWORDS’.
21390
21391 Several invocations within a test group accumulate new keywords.
21392 In other words, don’t fear registering the same keyword several
21393 times in a test group.
21394
21395 — Macro: AT_CAPTURE_FILE(FILE)
21396 If the current test group fails, log the contents of FILE. Several
21397 identical calls within one test group have no additional effect.
21398
21399 — Macro: AT_FAIL_IF(SHELL-CONDITION)
21400 Make the test group fail and skip the rest of its execution, if
21401 SHELL-CONDITION is true. SHELL-CONDITION is a shell expression
21402 such as a ‘test’ command. Tests before ‘AT_FAIL_IF’ will be
21403 executed and may still cause the test group to be skipped. You can
21404 instantiate this macro many times from within the same test group.
21405
21406 You should use this macro only for very simple failure conditions.
21407 If the SHELL-CONDITION could emit any kind of output you should
21408 instead use ‘AT_CHECK’ like
21409 AT_CHECK([if SHELL-CONDITION; then exit 99; fi])
21410 so that such output is properly recorded in the ‘testsuite.log’
21411 file.
21412
21413 — Macro: AT_SKIP_IF(SHELL-CONDITION)
21414 Determine whether the test should be skipped because it requires
21415 features that are unsupported on the machine under test.
21416 SHELL-CONDITION is a shell expression such as a ‘test’ command.
21417 Tests before ‘AT_SKIP_IF’ will be executed and may still cause the
21418 test group to fail. You can instantiate this macro many times from
21419 within the same test group.
21420
21421 You should use this macro only for very simple skip conditions. If
21422 the SHELL-CONDITION could emit any kind of output you should
21423 instead use ‘AT_CHECK’ like
21424 AT_CHECK([if SHELL-CONDITION; then exit 77; fi])
21425 so that such output is properly recorded in the ‘testsuite.log’
21426 file.
21427
21428 — Macro: AT_XFAIL_IF(SHELL-CONDITION)
21429 Determine whether the test is expected to fail because it is a
21430 known bug (for unsupported features, you should skip the test).
21431 SHELL-CONDITION is a shell expression such as a ‘test’ command; you
21432 can instantiate this macro many times from within the same test
21433 group, and one of the conditions is enough to turn the test into an
21434 expected failure.
21435
21436 — Macro: AT_CLEANUP
21437 End the current test group.
21438
21439
21440 — Macro: AT_DATA(FILE, CONTENTS)
21441 — Macro: AT_DATA_UNQUOTED(FILE, CONTENTS)
21442 Initialize an input data FILE with given CONTENTS. Of course, the
21443 CONTENTS have to be properly quoted between square brackets to
21444 protect against included commas or spurious M4 expansion. CONTENTS
21445 must be empty or end with a newline. FILE must be a single shell
21446 word that expands into a single file name.
21447
21448 The difference between ‘AT_DATA’ and ‘AT_DATA_UNQUOTED’ is that
21449 only the latter performs shell variable expansion (‘$’), command
21450 substitution (‘`’), and backslash escaping (‘\’) on CONTENTS.
21451
21452 — Macro: AT_CHECK(COMMANDS, [STATUS = 0], [STDOUT], [STDERR],
21453 [RUN-IF-FAIL], [RUN-IF-PASS])
21454 — Macro: AT_CHECK_UNQUOTED(COMMANDS, [STATUS = 0], [STDOUT], [STDERR],
21455 [RUN-IF-FAIL], [RUN-IF-PASS])
21456 Perform a test, by running the shell COMMANDS in a subshell.
21457 COMMANDS is output as-is, so shell expansions are honored. These
21458 commands are expected to have a final exit status of STATUS, and to
21459 produce output as described by STDOUT and STDERR (see below).
21460
21461 This macro must be invoked in between ‘AT_SETUP’ and ‘AT_CLEANUP’.
21462
21463 If COMMANDS exit with unexpected status 77, then the rest of the
21464 test group is skipped. If COMMANDS exit with unexpected status 99,
21465 then the test group is immediately failed; this is called a _hard
21466 failure_. Otherwise, the test is considered to have succeeded if
21467 all of the status, stdout, and stderr expectations were met.
21468
21469 If RUN-IF-FAIL is nonempty, it provides extra shell commands to run
21470 when the test fails; if RUN-IF-PASS is nonempty, it provides extra
21471 shell commands to run when the test succeeds. These commands are
21472 _not_ run in a subshell, and they are not run when the test group
21473 is skipped (exit code 77) or hard-failed (exit code 99). They may
21474 change whether the test group is considered to have succeeded, by
21475 modifying the shell variable ‘at_failed’; set it to ‘:’ to indicate
21476 that the test group has failed, or ‘false’ to indicate that it has
21477 succeeded.
21478
21479 The exit status of COMMANDS is available to RUN-IF-FAIL and
21480 RUN-IF-PASS commands in the ‘at_status’ shell variable. The output
21481 from COMMANDS is also available, in the files named by the
21482 ‘at_stdout’ and ‘at_stderr’ variables.
21483
21484 If STATUS is the literal ‘ignore’, then the exit status of COMMANDS
21485 is not checked, except for the special cases of 77 (skip) and 99
21486 (hard failure). The existence of hard failures allows one to mark
21487 a test as an expected failure with ‘AT_XFAIL_IF’ because a feature
21488 has not yet been implemented, but to still distinguish between
21489 gracefully handling the missing feature and dumping core.
21490
21491 If the value of the STDOUT or STDERR parameter is one of the
21492 literals in the following table, then the test treats the output
21493 according to the rules of that literal.
21494
21495 ‘ignore’
21496 The content of the output is ignored, but still captured in
21497 the test group log (if the testsuite is run with the ‘-v’
21498 option, the test group log is displayed as the test is run; if
21499 the test group later fails, the test group log is also copied
21500 into the overall testsuite log). This action is valid for
21501 both STDOUT and STDERR.
21502
21503 ‘ignore-nolog’
21504 The content of the output is ignored, and nothing is captured
21505 in the log files. If COMMANDS are likely to produce binary
21506 output (including long lines) or large amounts of output, then
21507 logging the output can make it harder to locate details
21508 related to subsequent tests within the group, and could
21509 potentially corrupt terminal display of a user running
21510 ‘testsuite -v’. This action is valid for both STDOUT and
21511 STDERR.
21512
21513 ‘stdout’
21514 Only valid as the STDOUT parameter. Capture the content of
21515 standard output in both a file named ‘stdout’ and the test
21516 group log. Subsequent commands in the test group can then
21517 post-process the file. This action is often used when it is
21518 desired to use ‘grep’ to look for a substring in the output,
21519 or when the output must be post-processed to normalize error
21520 messages into a common form.
21521
21522 ‘stderr’
21523 Only valid as the STDERR parameter. Capture the content of
21524 standard error in both a file named ‘stderr’ and the test
21525 group log.
21526
21527 ‘stdout-nolog’
21528 ‘stderr-nolog’
21529 Like ‘stdout’ or ‘stderr’, except that the captured output is
21530 not duplicated into the test group log. This action is
21531 particularly useful for an intermediate check that produces
21532 large amounts of data, which will be followed by another check
21533 that filters down to the relevant data, as it makes it easier
21534 to locate details in the log.
21535
21536 ‘expout’
21537 Only valid as the STDOUT parameter. Compare standard output
21538 with the previously created file ‘expout’, and list any
21539 differences in the testsuite log.
21540
21541 ‘experr’
21542 Only valid as the STDERR parameter. Compare standard error
21543 with the previously created file ‘experr’, and list any
21544 differences in the testsuite log.
21545
21546 Otherwise, the values of the STDOUT and STDERR parameters are
21547 treated as text that must exactly match the output given by
21548 COMMANDS on standard output and standard error (including an empty
21549 parameter for no output); any differences are captured in the
21550 testsuite log and the test is failed (unless an unexpected exit
21551 status of 77 skipped the test instead).
21552
21553 ‘AT_CHECK_UNQUOTED’ performs shell variable expansion (‘$’),
21554 command substitution (‘`’), and backslash escaping (‘\’) on
21555 comparison text given in the STDOUT and STDERR parameters;
21556 ‘AT_CHECK’ does not. There is no difference in the interpretation
21557 of COMMANDS.
21558
21559 — Macro: AT_CHECK_EUNIT(MODULE, TEST-SPEC, [ERLFLAGS], [RUN-IF-FAIL],
21560 [RUN-IF-PASS])
21561 Initialize and execute an Erlang module named MODULE that performs
21562 tests following the TEST-SPEC EUnit test specification. TEST-SPEC
21563 must be a valid EUnit test specification, as defined in the EUnit
21564 Reference Manual (https://erlang.org/doc/apps/eunit/index.html).
21565 ERLFLAGS are optional command-line options passed to the Erlang
21566 interpreter to execute the test Erlang module. Typically, ERLFLAGS
21567 defines at least the paths to directories containing the compiled
21568 Erlang modules under test, as ‘-pa path1 path2 ...’.
21569
21570 For example, the unit tests associated with Erlang module ‘testme’,
21571 which compiled code is in subdirectory ‘src’, can be performed
21572 with:
21573
21574 AT_CHECK_EUNIT([testme_testsuite], [{module, testme}],
21575 [-pa "${abs_top_builddir}/src"])
21576
21577 This macro must be invoked in between ‘AT_SETUP’ and ‘AT_CLEANUP’.
21578
21579 Variables ‘ERL’, ‘ERLC’, and (optionally) ‘ERLCFLAGS’ must be
21580 defined as the path of the Erlang interpreter, the path of the
21581 Erlang compiler, and the command-line flags to pass to the
21582 compiler, respectively. Those variables should be configured in
21583 ‘configure.ac’ using the ‘AC_ERLANG_PATH_ERL’ and
21584 ‘AC_ERLANG_PATH_ERLC’ macros, and the configured values of those
21585 variables are automatically defined in the testsuite. If ‘ERL’ or
21586 ‘ERLC’ is not defined, the test group is skipped.
21587
21588 If the EUnit library cannot be found, i.e. if module ‘eunit’
21589 cannot be loaded, the test group is skipped. Otherwise, if
21590 TEST-SPEC is an invalid EUnit test specification, the test group
21591 fails. Otherwise, if the EUnit test passes, shell commands
21592 RUN-IF-PASS are executed or, if the EUnit test fails, shell
21593 commands RUN-IF-FAIL are executed and the test group fails.
21594
21595 Only the generated test Erlang module is automatically compiled and
21596 executed. If TEST-SPEC involves testing other Erlang modules, e.g.
21597 module ‘testme’ in the example above, those modules must be already
21598 compiled.
21599
21600 If the testsuite is run in verbose mode and with the ‘--verbose’
21601 option, EUnit is also run in verbose mode to output more details
21602 about individual unit tests.
21603
21604 
21605 File: autoconf.info, Node: testsuite Invocation, Next: Making testsuite Scripts, Prev: Writing Testsuites, Up: Using Autotest
21606
21607 19.3 Running ‘testsuite’ Scripts
21608 ================================
21609
21610 Autotest test suites support the following options:
21611
21612 ‘--help’
21613 ‘-h’
21614 Display the list of options and exit successfully.
21615
21616 ‘--version’
21617 ‘-V’
21618 Display the version of the test suite and exit successfully.
21619
21620 ‘--directory=DIR’
21621 ‘-C DIR’
21622 Change the current directory to DIR before creating any files.
21623 Useful for running the testsuite in a subdirectory from a top-level
21624 Makefile.
21625
21626 ‘--jobs[=N]’
21627 ‘-j[N]’
21628 Run N tests in parallel, if possible. If N is not given, run all
21629 given tests in parallel. Note that there should be no space before
21630 the argument to ‘-j’, as ‘-j NUMBER’ denotes the separate arguments
21631 ‘-j’ and ‘NUMBER’, see below.
21632
21633 In parallel mode, the standard input device of the testsuite script
21634 is not available to commands inside a test group. Furthermore,
21635 banner lines are not printed, and the summary line for each test
21636 group is output after the test group completes. Summary lines may
21637 appear unordered. If verbose and trace output are enabled (see
21638 below), they may appear intermixed from concurrently running tests.
21639
21640 Parallel mode requires the ‘mkfifo’ command to work, and will be
21641 silently disabled otherwise.
21642
21643 ‘--clean’
21644 ‘-c’
21645 Remove all the files the test suite might have created and exit.
21646 Meant for ‘clean’ Make targets.
21647
21648 ‘--list’
21649 ‘-l’
21650 List all the tests (or only the selection), including their
21651 possible keywords.
21652
21653
21654 By default all tests are performed (or described with ‘--list’)
21655 silently in the default environment, but the environment, set of tests,
21656 and verbosity level can be tuned:
21657
21658 ‘VARIABLE=VALUE’
21659 Set the environment VARIABLE to VALUE. Use this rather than
21660 ‘FOO=foo ./testsuite’ as debugging scripts would then run in a
21661 different environment.
21662
21663 The variable ‘AUTOTEST_PATH’ specifies the testing path to prepend
21664 to ‘PATH’. Relative directory names (not starting with ‘/’) are
21665 considered to be relative to the top level of the package being
21666 built. All directories are made absolute, first starting from the
21667 top level _build_ tree, then from the _source_ tree. For instance
21668 ‘./testsuite AUTOTEST_PATH=tests:bin’ for a ‘/src/foo-1.0’ source
21669 package built in ‘/tmp/foo’ results in
21670 ‘/tmp/foo/tests:/tmp/foo/bin’ and then
21671 ‘/src/foo-1.0/tests:/src/foo-1.0/bin’ being prepended to ‘PATH’.
21672
21673 ‘NUMBER’
21674 ‘NUMBER-NUMBER’
21675 ‘NUMBER-’
21676 ‘-NUMBER’
21677 Add the corresponding test groups, with obvious semantics, to the
21678 selection.
21679
21680 ‘--keywords=KEYWORDS’
21681 ‘-k KEYWORDS’
21682 Add to the selection the test groups with title or keywords
21683 (arguments to ‘AT_SETUP’ or ‘AT_KEYWORDS’) that match _all_
21684 keywords of the comma separated list KEYWORDS, case-insensitively.
21685 Use ‘!’ immediately before the keyword to invert the selection for
21686 this keyword. By default, the keywords match whole words; enclose
21687 them in ‘.*’ to also match parts of words.
21688
21689 For example, running
21690
21691 ./testsuite -k 'autoupdate,.*FUNC.*'
21692
21693 selects all tests tagged ‘autoupdate’ _and_ with tags containing
21694 ‘FUNC’ (as in ‘AC_CHECK_FUNC’, ‘AC_FUNC_ALLOCA’, etc.), while
21695
21696 ./testsuite -k '!autoupdate' -k '.*FUNC.*'
21697
21698 selects all tests not tagged ‘autoupdate’ _or_ with tags containing
21699 ‘FUNC’.
21700
21701 ‘--errexit’
21702 ‘-e’
21703 If any test fails, immediately abort testing. This implies
21704 ‘--debug’: post test group clean up, and top-level logging are
21705 inhibited. This option is meant for the full test suite, it is not
21706 really useful for generated debugging scripts. If the testsuite is
21707 run in parallel mode using ‘--jobs’, then concurrently running
21708 tests will finish before exiting.
21709
21710 ‘--verbose’
21711 ‘-v’
21712 Force more verbosity in the detailed output of what is being done.
21713 This is the default for debugging scripts.
21714
21715 ‘--color’
21716 ‘--color[=never|auto|always]’
21717 Enable colored test results. Without an argument, or with
21718 ‘always’, test results will be colored. With ‘never’, color mode
21719 is turned off. Otherwise, if either the macro ‘AT_COLOR_TESTS’ is
21720 used by the testsuite author, or the argument ‘auto’ is given, then
21721 test results are colored if standard output is connected to a
21722 terminal.
21723
21724 ‘--debug’
21725 ‘-d’
21726 Do not remove the files after a test group was performed—but they
21727 are still removed _before_, therefore using this option is sane
21728 when running several test groups. Create debugging scripts. Do
21729 not overwrite the top-level log (in order to preserve a supposedly
21730 existing full log file). This is the default for debugging
21731 scripts, but it can also be useful to debug the testsuite itself.
21732
21733 ‘--recheck’
21734 Add to the selection all test groups that failed or passed
21735 unexpectedly during the last non-debugging test run.
21736
21737 ‘--trace’
21738 ‘-x’
21739 Trigger shell tracing of the test groups.
21740
21741 Besides these options accepted by every Autotest testsuite, the
21742 testsuite author might have added package-specific options via the
21743 ‘AT_ARG_OPTION’ and ‘AT_ARG_OPTION_ARG’ macros (*note Writing
21744 Testsuites::); refer to ‘testsuite --help’ and the package documentation
21745 for details.
21746
21747 
21748 File: autoconf.info, Node: Making testsuite Scripts, Prev: testsuite Invocation, Up: Using Autotest
21749
21750 19.4 Making ‘testsuite’ Scripts
21751 ===============================
21752
21753 For putting Autotest into movement, you need some configuration and
21754 makefile machinery. We recommend, at least if your package uses deep or
21755 shallow hierarchies, that you use ‘tests/’ as the name of the directory
21756 holding all your tests and their makefile. Here is a check list of
21757 things to do, followed by an example, taking into consideration whether
21758 you are also using Automake.
21759
21760 − Make sure to create the file ‘package.m4’, which defines the
21761 identity of the package. It must define ‘AT_PACKAGE_STRING’, the
21762 full signature of the package, and ‘AT_PACKAGE_BUGREPORT’, the
21763 address to which bug reports should be sent. For sake of
21764 completeness, we suggest that you also define ‘AT_PACKAGE_NAME’,
21765 ‘AT_PACKAGE_TARNAME’, ‘AT_PACKAGE_VERSION’, and ‘AT_PACKAGE_URL’.
21766 *Note Initializing configure::, for a description of these
21767 variables. Be sure to distribute ‘package.m4’ and to put it into
21768 the source hierarchy: the test suite ought to be shipped! See
21769 below for an example.
21770
21771 − Invoke ‘AC_CONFIG_TESTDIR’ in your ‘configure.ac’.
21772
21773 — Macro: AC_CONFIG_TESTDIR(DIRECTORY, [TEST-PATH = DIRECTORY])
21774 An Autotest test suite is to be configured in DIRECTORY. This
21775 macro causes ‘DIRECTORY/atconfig’ to be created by
21776 ‘config.status’ and sets the default ‘AUTOTEST_PATH’ to
21777 TEST-PATH (*note testsuite Invocation::).
21778
21779 − Still within ‘configure.ac’, as appropriate, ensure that some
21780 ‘AC_CONFIG_FILES’ command includes substitution for
21781 ‘tests/atlocal’.
21782
21783 − Also within your ‘configure.ac’, arrange for the ‘AUTOM4TE’
21784 variable to be set.
21785
21786 − The appropriate ‘Makefile’ should be modified so the validation in
21787 your package is triggered by ‘make check’.
21788
21789 The following example demonstrates the above checklist, first by
21790 assuming that you are using Automake (see below for tweaks to make to
21791 get the same results without Automake). Begin by adding the following
21792 lines to your ‘configure.ac’:
21793
21794 # Initialize the test suite.
21795 AC_CONFIG_TESTDIR([tests])
21796 AC_CONFIG_FILES([tests/Makefile tests/atlocal])
21797 AM_MISSING_PROG([AUTOM4TE], [autom4te])
21798
21799 Next, add the following lines to your ‘tests/Makefile.am’, in order
21800 to link ‘make check’ with a validation suite.
21801
21802 $(srcdir)/package.m4: $(top_srcdir)/configure.ac
21803 printf >'$@' '%s\n' \
21804 '# Signature of the current package.' \
21805 'm4_define([AT_PACKAGE_NAME], [$(PACKAGE_NAME)])' \
21806 'm4_define([AT_PACKAGE_TARNAME], [$(PACKAGE_TARNAME)])' \
21807 'm4_define([AT_PACKAGE_VERSION], [$(PACKAGE_VERSION)])' \
21808 'm4_define([AT_PACKAGE_STRING], [$(PACKAGE_STRING)])' \
21809 'm4_define([AT_PACKAGE_URL], [$(PACKAGE_URL)])' \
21810 'm4_define([AT_PACKAGE_BUGREPORT], [$(PACKAGE_BUGREPORT)])'
21811
21812 EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) atlocal.in
21813 TESTSUITE = $(srcdir)/testsuite
21814
21815 check-local: atconfig atlocal $(TESTSUITE)
21816 $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
21817
21818 installcheck-local: atconfig atlocal $(TESTSUITE)
21819 $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \
21820 $(TESTSUITEFLAGS)
21821
21822 clean-local:
21823 test ! -f '$(TESTSUITE)' || \
21824 $(SHELL) '$(TESTSUITE)' --clean
21825
21826 AUTOTEST = $(AUTOM4TE) --language=autotest
21827 $(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
21828 $(AUTOTEST) -I '$(srcdir)' -o [email protected] [email protected]
21829 mv [email protected] $@
21830
21831 Note that the built testsuite is distributed; this is necessary
21832 because users might not have Autoconf installed, and thus would not be
21833 able to rebuild it. Likewise, the use of Automake’s ‘AM_MISSING_PROG’
21834 will arrange for the definition of ‘$AUTOM4TE’ within the Makefile to
21835 provide the user with a nicer error message if they modify a source file
21836 to the testsuite, and accidentally trigger the rebuild rules.
21837
21838 You might want to list explicitly the dependencies, i.e., the list of
21839 the files ‘testsuite.at’ includes.
21840
21841 If you don’t use Automake, you should make the following tweaks. In
21842 your ‘configure.ac’, replace the ‘AM_MISSING_PROG’ line above with
21843 ‘AC_PATH_PROG([AUTOM4TE], [autom4te], [false])’. You are welcome to
21844 also try using the ‘missing’ script from the Automake project instead of
21845 ‘false’, to try to get a nicer error message when the user modifies
21846 prerequisites but did not have Autoconf installed, but at that point you
21847 may be better off using Automake. Then, take the code suggested above
21848 for ‘tests/Makefile.am’ and place it in your ‘tests/Makefile.in’
21849 instead. Add code to your ‘tests/Makefile.in’ to ensure that
21850 ‘$(EXTRA_DIST)’ files are distributed, as well as adding the following
21851 additional lines to prepare the set of needed Makefile variables:
21852
21853 subdir = tests
21854 PACKAGE_NAME = @PACKAGE_NAME@
21855 PACKAGE_TARNAME = @PACKAGE_TARNAME@
21856 PACKAGE_VERSION = @PACKAGE_VERSION@
21857 PACKAGE_STRING = @PACKAGE_STRING@
21858 PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
21859 PACKAGE_URL = @PACKAGE_URL@
21860 AUTOM4TE = @AUTOM4TE@
21861
21862 atconfig: $(top_builddir)/config.status
21863 cd $(top_builddir) && \
21864 $(SHELL) ./config.status $(subdir)/$@
21865
21866 atlocal: $(srcdir)/atlocal.in $(top_builddir)/config.status
21867 cd $(top_builddir) && \
21868 $(SHELL) ./config.status $(subdir)/$@
21869
21870 Using the above example (with or without Automake), and assuming you
21871 were careful to not initialize ‘TESTSUITEFLAGS’ within your makefile,
21872 you can now fine-tune test suite execution at runtime by altering this
21873 variable, for example:
21874
21875 make check TESTSUITEFLAGS='-v -d -x 75 -k AC_PROG_CC CFLAGS=-g'
21876
21877 
21878 File: autoconf.info, Node: FAQ, Next: History, Prev: Using Autotest, Up: Top
21879
21880 20 Frequent Autoconf Questions, with answers
21881 ********************************************
21882
21883 Several questions about Autoconf come up occasionally. Here some of
21884 them are addressed.
21885
21886 * Menu:
21887
21888 * Distributing:: Distributing ‘configure’ scripts
21889 * Why GNU M4:: Why not use the standard M4?
21890 * Bootstrapping:: Autoconf and GNU M4 require each other?
21891 * Why Not Imake:: Why GNU uses ‘configure’ instead of Imake
21892 * Defining Directories:: Passing ‘datadir’ to program
21893 * Autom4te Cache:: What is it? Can I remove it?
21894 * Present But Cannot Be Compiled:: Compiler and Preprocessor Disagree
21895 * Expanded Before Required:: Expanded Before Required
21896 * Debugging:: Debugging ‘configure’ scripts
21897
21898 
21899 File: autoconf.info, Node: Distributing, Next: Why GNU M4, Up: FAQ
21900
21901 20.1 Distributing ‘configure’ Scripts
21902 =====================================
21903
21904 What are the restrictions on distributing ‘configure’
21905 scripts that Autoconf generates? How does that affect my
21906 programs that use them?
21907
21908 There are no restrictions on how the configuration scripts that
21909 Autoconf produces may be distributed or used. In Autoconf version 1,
21910 they were covered by the GNU General Public License. We still encourage
21911 software authors to distribute their work under terms like those of the
21912 GPL, but doing so is not required to use Autoconf.
21913
21914 Of the other files that might be used with ‘configure’, ‘config.h.in’
21915 is under whatever copyright you use for your ‘configure.ac’.
21916 ‘config.sub’ and ‘config.guess’ have an exception to the GPL when they
21917 are used with an Autoconf-generated ‘configure’ script, which permits
21918 you to distribute them under the same terms as the rest of your package.
21919 ‘install-sh’ is from the X Consortium and is not copyrighted.
21920
21921 
21922 File: autoconf.info, Node: Why GNU M4, Next: Bootstrapping, Prev: Distributing, Up: FAQ
21923
21924 20.2 Why Require GNU M4?
21925 ========================
21926
21927 Why does Autoconf require GNU M4?
21928
21929 Many M4 implementations have hard-coded limitations on the size and
21930 number of macros that Autoconf exceeds. They also lack several builtin
21931 macros that it would be difficult to get along without in a
21932 sophisticated application like Autoconf, including:
21933
21934 m4_builtin
21935 m4_indir
21936 m4_bpatsubst
21937 __file__
21938 __line__
21939
21940 Autoconf requires version 1.4.8 or later of GNU M4. It works better
21941 with version 1.4.16 or later.
21942
21943 Since only software maintainers need to use Autoconf, and since GNU
21944 M4 is simple to configure and install, it seems reasonable to require
21945 GNU M4 to be installed also. Many maintainers of GNU and other free
21946 software already have most of the GNU utilities installed, since they
21947 prefer them.
21948
21949 
21950 File: autoconf.info, Node: Bootstrapping, Next: Why Not Imake, Prev: Why GNU M4, Up: FAQ
21951
21952 20.3 How Can I Bootstrap?
21953 =========================
21954
21955 If Autoconf requires GNU M4 and GNU M4 has an Autoconf
21956 ‘configure’ script, how do I bootstrap? It seems like a chicken
21957 and egg problem!
21958
21959 This is a misunderstanding. Although GNU M4 does come with a
21960 ‘configure’ script produced by Autoconf, Autoconf is not required in
21961 order to run the script and install GNU M4. Autoconf is only required
21962 if you want to change the M4 ‘configure’ script, which few people have
21963 to do (mainly its maintainer).
21964
21965 
21966 File: autoconf.info, Node: Why Not Imake, Next: Defining Directories, Prev: Bootstrapping, Up: FAQ
21967
21968 20.4 Why Not Imake?
21969 ===================
21970
21971 Why not use Imake instead of ‘configure’ scripts?
21972
21973 Several people have written addressing this question, so adaptations
21974 of their explanations are included here.
21975
21976 The following answer is based on one written by Richard Pixley:
21977
21978 Autoconf generated scripts frequently work on machines that it has
21979 never been set up to handle before. That is, it does a good job of
21980 inferring a configuration for a new system. Imake cannot do this.
21981
21982 Imake uses a common database of host specific data. For X11, this
21983 makes sense because the distribution is made as a collection of
21984 tools, by one central authority who has control over the database.
21985
21986 GNU tools are not released this way. Each GNU tool has a
21987 maintainer; these maintainers are scattered across the world.
21988 Using a common database would be a maintenance nightmare. Autoconf
21989 may appear to be this kind of database, but in fact it is not.
21990 Instead of listing host dependencies, it lists program
21991 requirements.
21992
21993 If you view the GNU suite as a collection of native tools, then the
21994 problems are similar. But the GNU development tools can be
21995 configured as cross tools in almost any host+target permutation.
21996 All of these configurations can be installed concurrently. They
21997 can even be configured to share host independent files across
21998 hosts. Imake doesn’t address these issues.
21999
22000 Imake templates are a form of standardization. The GNU coding
22001 standards address the same issues without necessarily imposing the
22002 same restrictions.
22003
22004 Here is some further explanation, written by Per Bothner:
22005
22006 One of the advantages of Imake is that it is easy to generate large
22007 makefiles using the ‘#include’ and macro mechanisms of ‘cpp’.
22008 However, ‘cpp’ is not programmable: it has limited conditional
22009 facilities, and no looping. And ‘cpp’ cannot inspect its
22010 environment.
22011
22012 All of these problems are solved by using ‘sh’ instead of ‘cpp’.
22013 The shell is fully programmable, has macro substitution, can
22014 execute (or source) other shell scripts, and can inspect its
22015 environment.
22016
22017 Paul Eggert elaborates more:
22018
22019 With Autoconf, installers need not assume that Imake itself is
22020 already installed and working well. This may not seem like much of
22021 an advantage to people who are accustomed to Imake. But on many
22022 hosts Imake is not installed or the default installation is not
22023 working well, and requiring Imake to install a package hinders the
22024 acceptance of that package on those hosts. For example, the Imake
22025 template and configuration files might not be installed properly on
22026 a host, or the Imake build procedure might wrongly assume that all
22027 source files are in one big directory tree, or the Imake
22028 configuration might assume one compiler whereas the package or the
22029 installer needs to use another, or there might be a version
22030 mismatch between the Imake expected by the package and the Imake
22031 supported by the host. These problems are much rarer with
22032 Autoconf, where each package comes with its own independent
22033 configuration processor.
22034
22035 Also, Imake often suffers from unexpected interactions between
22036 ‘make’ and the installer’s C preprocessor. The fundamental problem
22037 here is that the C preprocessor was designed to preprocess C
22038 programs, not makefiles. This is much less of a problem with
22039 Autoconf, which uses the general-purpose preprocessor M4, and where
22040 the package’s author (rather than the installer) does the
22041 preprocessing in a standard way.
22042
22043 Finally, Mark Eichin notes:
22044
22045 Imake isn’t all that extensible, either. In order to add new
22046 features to Imake, you need to provide your own project template,
22047 and duplicate most of the features of the existing one. This means
22048 that for a sophisticated project, using the vendor-provided Imake
22049 templates fails to provide any leverage—since they don’t cover
22050 anything that your own project needs (unless it is an X11 program).
22051
22052 On the other side, though:
22053
22054 The one advantage that Imake has over ‘configure’: ‘Imakefile’
22055 files tend to be much shorter (likewise, less redundant) than
22056 ‘Makefile.in’ files. There is a fix to this, however—at least for
22057 the Kerberos V5 tree, we’ve modified things to call in common
22058 ‘post.in’ and ‘pre.in’ makefile fragments for the entire tree.
22059 This means that a lot of common things don’t have to be duplicated,
22060 even though they normally are in ‘configure’ setups.
22061
22062 
22063 File: autoconf.info, Node: Defining Directories, Next: Autom4te Cache, Prev: Why Not Imake, Up: FAQ
22064
22065 20.5 How Do I ‘#define’ Installation Directories?
22066 =================================================
22067
22068 My program needs library files, installed in ‘datadir’ and
22069 similar. If I use
22070
22071 AC_DEFINE_UNQUOTED([DATADIR], [$datadir],
22072 [Define to the read-only architecture-independent
22073 data directory.])
22074
22075 I get
22076
22077 #define DATADIR "${prefix}/share"
22078
22079 As already explained, this behavior is on purpose, mandated by the
22080 GNU Coding Standards, see *note Installation Directory Variables::.
22081 There are several means to achieve a similar goal:
22082
22083 − Do not use ‘AC_DEFINE’ but use your makefile to pass the actual
22084 value of ‘datadir’ via compilation flags. *Note Installation
22085 Directory Variables::, for the details.
22086
22087 − This solution can be simplified when compiling a program: you may
22088 either extend the ‘CPPFLAGS’:
22089
22090 CPPFLAGS = -DDATADIR='"$(datadir)"' @CPPFLAGS@
22091
22092 If you are using Automake, you should use ‘AM_CPPFLAGS’ instead:
22093
22094 AM_CPPFLAGS = -DDATADIR='"$(datadir)"'
22095
22096 Alternatively, create a dedicated header file:
22097
22098 DISTCLEANFILES = myprog-paths.h
22099 myprog-paths.h: Makefile
22100 printf '%s\n' '#define DATADIR "$(datadir)"' >$@
22101
22102 The Gnulib module ‘configmake’ provides such a header with all the
22103 standard directory variables defined, *note (gnulib)configmake::.
22104
22105 − Use ‘AC_DEFINE’ but have ‘configure’ compute the literal value of
22106 ‘datadir’ and others. Many people have wrapped macros to automate
22107 this task; for an example, see the macro ‘AC_DEFINE_DIR’ from the
22108 Autoconf Macro Archive
22109 (https://www.gnu.org/software/autoconf-archive/).
22110
22111 This solution does not conform to the GNU Coding Standards.
22112
22113 − Note that all the previous solutions hard wire the absolute name of
22114 these directories in the executables, which is not a good property.
22115 You may try to compute the names relative to ‘prefix’, and try to
22116 find ‘prefix’ at runtime, this way your package is relocatable.
22117
22118 
22119 File: autoconf.info, Node: Autom4te Cache, Next: Present But Cannot Be Compiled, Prev: Defining Directories, Up: FAQ
22120
22121 20.6 What is ‘autom4te.cache’?
22122 ==============================
22123
22124 What is this directory ‘autom4te.cache’? Can I safely remove it?
22125
22126 In the GNU Build System, ‘configure.ac’ plays a central role and is
22127 read by many tools: ‘autoconf’ to create ‘configure’, ‘autoheader’ to
22128 create ‘config.h.in’, ‘automake’ to create ‘Makefile.in’, ‘autoscan’ to
22129 check the completeness of ‘configure.ac’, ‘autoreconf’ to check the GNU
22130 Build System components that are used. To “read ‘configure.ac’”
22131 actually means to compile it with M4, which can be a long process for
22132 complex ‘configure.ac’.
22133
22134 This is why all these tools, instead of running directly M4, invoke
22135 ‘autom4te’ (*note autom4te Invocation::) which, while answering to a
22136 specific demand, stores additional information in ‘autom4te.cache’ for
22137 future runs. For instance, if you run ‘autoconf’, behind the scenes,
22138 ‘autom4te’ also stores information for the other tools, so that when you
22139 invoke ‘autoheader’ or ‘automake’ etc., reprocessing ‘configure.ac’ is
22140 not needed. The speed up is frequently 30%, and is increasing with the
22141 size of ‘configure.ac’.
22142
22143 But it is and remains being simply a cache: you can safely remove it.
22144
22145
22146 Can I permanently get rid of it?
22147
22148 The creation of this cache can be disabled from ‘~/.autom4te.cfg’,
22149 see *note Customizing autom4te::, for more details. You should be aware
22150 that disabling the cache slows down the Autoconf test suite by 40%. The
22151 more GNU Build System components are used, the more the cache is useful;
22152 for instance running ‘autoreconf -f’ on the Core Utilities is twice
22153 slower without the cache _although ‘--force’ implies that the cache is
22154 not fully exploited_, and eight times slower than without ‘--force’.
22155
22156 
22157 File: autoconf.info, Node: Present But Cannot Be Compiled, Next: Expanded Before Required, Prev: Autom4te Cache, Up: FAQ
22158
22159 20.7 Header Present But Cannot Be Compiled
22160 ==========================================
22161
22162 The most important guideline to bear in mind when checking for features
22163 is to mimic as much as possible the intended use. Unfortunately, old
22164 versions of ‘AC_CHECK_HEADER’ and ‘AC_CHECK_HEADERS’ failed to follow
22165 this idea, and called the preprocessor, instead of the compiler, to
22166 check for headers. As a result, incompatibilities between headers went
22167 unnoticed during configuration, and maintainers finally had to deal with
22168 this issue elsewhere.
22169
22170 The transition began with Autoconf 2.56. As of Autoconf 2.64 both
22171 checks are performed, and ‘configure’ complains loudly if the compiler
22172 and the preprocessor do not agree. However, only the compiler result is
22173 considered. As of Autoconf 2.70, only the compiler check is performed.
22174
22175 Consider the following example:
22176
22177 $ cat number.h
22178 typedef int number;
22179 $ cat pi.h
22180 const number pi = 3;
22181 $ cat configure.ac
22182 AC_INIT([Example], [1.0], [[email protected]])
22183 AC_CHECK_HEADERS([pi.h])
22184 $ autoconf -Wall
22185 $ ./configure CPPFLAGS='-I.'
22186 checking for gcc... gcc
22187 checking whether the C compiler works... yes
22188 checking for C compiler default output file name... a.out
22189 checking for suffix of executables...
22190 checking whether we are cross compiling... no
22191 checking for suffix of object files... o
22192 checking whether the compiler supports GNU C... yes
22193 checking whether gcc accepts -g... yes
22194 checking for gcc option to enable C23 features... -std=gnu23
22195 checking for sys/types.h... yes
22196 checking for sys/stat.h... yes
22197 checking for strings.h... yes
22198 checking for inttypes.h... yes
22199 checking for stdint.h... yes
22200 checking for unistd.h... yes
22201 checking for pi.h... no
22202
22203 The proper way to handle this case is using the fourth argument (*note
22204 Generic Headers::):
22205
22206 $ cat configure.ac
22207 AC_INIT([Example], [1.0], [[email protected]])
22208 AC_CHECK_HEADERS([number.h pi.h], [], [],
22209 [[#ifdef HAVE_NUMBER_H
22210 # include <number.h>
22211 #endif
22212 ]])
22213 $ autoconf -Wall
22214 $ ./configure CPPFLAGS='-I.'
22215 checking for gcc... gcc
22216 checking whether the C compiler works... yes
22217 checking for C compiler default output file name... a.out
22218 checking for suffix of executables...
22219 checking whether we are cross compiling... no
22220 checking for suffix of object files... o
22221 checking whether the compiler supports GNU C... yes
22222 checking whether gcc accepts -g... yes
22223 checking for gcc option to enable C23 features... -std=gnu23
22224 checking for number.h... yes
22225 checking for pi.h... yes
22226
22227 See *note Particular Headers::, for a list of headers with their
22228 prerequisites.
22229
22230 
22231 File: autoconf.info, Node: Expanded Before Required, Next: Debugging, Prev: Present But Cannot Be Compiled, Up: FAQ
22232
22233 20.8 Expanded Before Required
22234 =============================
22235
22236 Older versions of Autoconf silently built files with incorrect ordering
22237 between dependent macros if an outer macro first expanded, then later
22238 indirectly required, an inner macro. Starting with Autoconf 2.64, this
22239 situation no longer generates out-of-order code, but results in
22240 duplicate output and a syntax warning:
22241
22242 $ cat configure.ac
22243 ⇒AC_DEFUN([TESTA], [[echo in A
22244 ⇒if test -n "$SEEN_A" ; then echo duplicate ; fi
22245 ⇒SEEN_A=:]])
22246 ⇒AC_DEFUN([TESTB], [AC_REQUIRE([TESTA])[echo in B
22247 ⇒if test -z "$SEEN_A" ; then echo bug ; fi]])
22248 ⇒AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])
22249 ⇒AC_DEFUN([OUTER], [[echo in OUTER]
22250 ⇒TESTA
22251 ⇒TESTC])
22252 ⇒AC_INIT
22253 ⇒OUTER
22254 ⇒AC_OUTPUT
22255 $ autoconf
22256 ⇒configure.ac:11: warning: AC_REQUIRE:
22257 ⇒ 'TESTA' was expanded before it was required
22258 ⇒configure.ac:4: TESTB is expanded from...
22259 ⇒configure.ac:6: TESTC is expanded from...
22260 ⇒configure.ac:7: OUTER is expanded from...
22261 ⇒configure.ac:11: the top level
22262
22263 To avoid this warning, decide what purpose the macro in question serves.
22264 If it only needs to be expanded once (for example, if it provides
22265 initialization text used by later macros), then the simplest fix is to
22266 change the macro to be declared with ‘AC_DEFUN_ONCE’ (*note One-Shot
22267 Macros::), although this only works in Autoconf 2.64 and newer. A more
22268 portable fix is to change all instances of direct calls to instead go
22269 through ‘AC_REQUIRE’ (*note Prerequisite Macros::). If, instead, the
22270 macro is parameterized by arguments or by the current definition of
22271 other macros in the m4 environment, then the macro should always be
22272 directly expanded instead of required.
22273
22274 For another case study, consider this example trimmed down from an
22275 actual package. Originally, the package contained shell code and
22276 multiple macro invocations at the top level of ‘configure.ac’:
22277
22278 AC_DEFUN([FOO], [AC_COMPILE_IFELSE([...])])
22279 foobar=
22280 AC_PROG_CC
22281 FOO
22282
22283 but that was getting complex, so the author wanted to offload some of
22284 the text into a new macro in another file included via ‘aclocal.m4’.
22285 The naïve approach merely wraps the text in a new macro:
22286
22287 AC_DEFUN([FOO], [AC_COMPILE_IFELSE([...])])
22288 AC_DEFUN([BAR], [
22289 foobar=
22290 AC_PROG_CC
22291 FOO
22292 ])
22293 BAR
22294
22295 With older versions of Autoconf, the setting of ‘foobar=’ occurs before
22296 the single compiler check, as the author intended. But with Autoconf
22297 2.64, this issues the “expanded before it was required” warning for
22298 ‘AC_PROG_CC’, and outputs two copies of the compiler check, one before
22299 ‘foobar=’, and one after. To understand why this is happening, remember
22300 that the use of ‘AC_COMPILE_IFELSE’ includes a call to
22301 ‘AC_REQUIRE([AC_PROG_CC])’ under the hood. According to the documented
22302 semantics of ‘AC_REQUIRE’, this means that ‘AC_PROG_CC’ _must_ occur
22303 before the body of the outermost ‘AC_DEFUN’, which in this case is
22304 ‘BAR’, thus preceding the use of ‘foobar=’. The older versions of
22305 Autoconf were broken with regards to the rules of ‘AC_REQUIRE’, which
22306 explains why the code changed from one over to two copies of
22307 ‘AC_PROG_CC’ when upgrading autoconf. In other words, the author was
22308 unknowingly relying on a bug exploit to get the desired results, and
22309 that exploit broke once the bug was fixed.
22310
22311 So, what recourse does the author have, to restore their intended
22312 semantics of setting ‘foobar=’ prior to a single compiler check,
22313 regardless of whether Autoconf 2.63 or 2.64 is used? One idea is to
22314 remember that only ‘AC_DEFUN’ is impacted by ‘AC_REQUIRE’; there is
22315 always the possibility of using the lower-level ‘m4_define’:
22316
22317 AC_DEFUN([FOO], [AC_COMPILE_IFELSE([...])])
22318 m4_define([BAR], [
22319 foobar=
22320 AC_PROG_CC
22321 FOO
22322 ])
22323 BAR
22324
22325 This works great if everything is in the same file. However, it does
22326 not help in the case where the author wants to have ‘aclocal’ find the
22327 definition of ‘BAR’ from its own file, since ‘aclocal’ requires the use
22328 of ‘AC_DEFUN’. In this case, a better fix is to recognize that if ‘BAR’
22329 also uses ‘AC_REQUIRE’, then there will no longer be direct expansion
22330 prior to a subsequent require. Then, by creating yet another helper
22331 macro, the author can once again guarantee a single invocation of
22332 ‘AC_PROG_CC’, which will still occur after ‘foobar=’. The author can
22333 also use ‘AC_BEFORE’ to make sure no other macro appearing before ‘BAR’
22334 has triggered an unwanted expansion of ‘AC_PROG_CC’.
22335
22336 AC_DEFUN([FOO], [AC_COMPILE_IFELSE([...])])
22337 AC_DEFUN([BEFORE_CC], [
22338 foobar=
22339 ])
22340 AC_DEFUN([BAR], [
22341 AC_BEFORE([$0], [AC_PROG_CC])dnl
22342 AC_REQUIRE([BEFORE_CC])dnl
22343 AC_REQUIRE([AC_PROG_CC])dnl
22344 FOO
22345 ])
22346 BAR
22347
22348 
22349 File: autoconf.info, Node: Debugging, Prev: Expanded Before Required, Up: FAQ
22350
22351 20.9 Debugging ‘configure’ scripts
22352 ==================================
22353
22354 While in general, ‘configure’ scripts generated by Autoconf strive to be
22355 fairly portable to various systems, compilers, shells, and other tools,
22356 it may still be necessary to debug a failing test, broken script or
22357 makefile, or fix or override an incomplete, faulty, or erroneous test,
22358 especially during macro development. Failures can occur at all levels,
22359 in M4 syntax or semantics, shell script issues, or due to bugs in the
22360 test or the tools invoked by ‘configure’. Together with the rather
22361 arcane error message that ‘m4’ and ‘make’ may produce when their input
22362 contains syntax errors, this can make debugging rather painful.
22363
22364 Nevertheless, here is a list of hints and strategies that may help:
22365
22366 • When ‘autoconf’ fails, common causes for error include:
22367
22368 • mismatched or unbalanced parentheses or braces (*note
22369 Balancing Parentheses::),
22370
22371 • under- or over-quoted macro arguments (*note Autoconf
22372 Language::, *note Quoting and Parameters::, *note Quotation
22373 and Nested Macros::),
22374
22375 • spaces between macro name and opening parenthesis (*note
22376 Autoconf Language::).
22377
22378 Typically, it helps to go back to the last working version of the
22379 input and compare the differences for each of these errors.
22380 Another possibility is to sprinkle pairs of ‘m4_traceon’ and
22381 ‘m4_traceoff’ judiciously in the code, either without a parameter
22382 or listing some macro names and watch ‘m4’ expand its input
22383 verbosely (*note Debugging via autom4te::).
22384
22385 • Sometimes ‘autoconf’ succeeds but the generated ‘configure’ script
22386 has invalid shell syntax. You can detect this case by running
22387 ‘bash -n configure’ or ‘sh -n configure’. If this command fails,
22388 the same tips apply, as if ‘autoconf’ had failed.
22389
22390 • Debugging ‘configure’ script execution may be done by sprinkling
22391 pairs of ‘set -x’ and ‘set +x’ into the shell script before and
22392 after the region that contains a bug. Running the whole script
22393 with ‘SHELL -vx ./configure 2>&1 | tee LOG-FILE’ with a decent
22394 SHELL may work, but produces lots of output. Here, it can help to
22395 search for markers like ‘checking for’ a particular test in the
22396 LOG-FILE.
22397
22398 • Alternatively, you might use a shell with debugging capabilities
22399 like bashdb (https://bashdb.sourceforge.net/).
22400
22401 • When ‘configure’ tests produce invalid results for your system, it
22402 may be necessary to override them:
22403
22404 • For programs, tools or libraries variables, preprocessor,
22405 compiler, or linker flags, it is often sufficient to override
22406 them at ‘make’ run time with some care (*note Macros and
22407 Submakes::). Since this normally won’t cause ‘configure’ to
22408 be run again with these changed settings, it may fail if the
22409 changed variable would have caused different test results from
22410 ‘configure’, so this may work only for simple differences.
22411
22412 • Most tests which produce their result in a substituted
22413 variable allow to override the test by setting the variable on
22414 the ‘configure’ command line (*note Compilers and Options::,
22415 *note Defining Variables::).
22416
22417 • Many tests store their result in a cache variable (*note
22418 Caching Results::). This lets you override them either on the
22419 ‘configure’ command line as above, or through a primed cache
22420 or site file (*note Cache Files::, *note Site Defaults::).
22421 The name of a cache variable is documented with a test macro
22422 or may be inferred from *note Cache Variable Names::; the
22423 precise semantics of undocumented variables are often internal
22424 details, subject to change.
22425
22426 • Alternatively, ‘configure’ may produce invalid results because of
22427 uncaught programming errors, in your package or in an upstream
22428 library package. For example, when ‘AC_CHECK_LIB’ fails to find a
22429 library with a specified function, always check ‘config.log’. This
22430 will reveal the exact error that produced the failing result: the
22431 library linked by ‘AC_CHECK_LIB’ probably has a fatal bug.
22432
22433 Conversely, as macro author, you can make it easier for users of your
22434 macro:
22435
22436 • by minimizing dependencies between tests and between test results
22437 as far as possible,
22438
22439 • by using ‘make’ variables to factorize and allow override of
22440 settings at ‘make’ run time,
22441
22442 • by honoring the GNU Coding Standards and not overriding flags
22443 reserved for the user except temporarily during ‘configure’ tests,
22444
22445 • by not requiring users of your macro to use the cache variables.
22446 Instead, expose the result of the test via RUN-IF-TRUE and
22447 RUN-IF-FALSE parameters. If the result is not a boolean, then
22448 provide it through documented shell variables.
22449
22450 
22451 File: autoconf.info, Node: History, Next: GNU Free Documentation License, Prev: FAQ, Up: Top
22452
22453 21 History of Autoconf
22454 **********************
22455
22456 _This chapter was written by the original author, David MacKenzie._
22457
22458 You may be wondering, Why was Autoconf originally written? How did
22459 it get into its present form? (Why does it look like gorilla spit?) If
22460 you’re not wondering, then this chapter contains no information useful
22461 to you, and you might as well skip it. If you _are_ wondering, then let
22462 there be light...
22463
22464 * Menu:
22465
22466 * Genesis:: Prehistory and naming of ‘configure’
22467 * Exodus:: The plagues of M4 and Perl
22468 * Leviticus:: The priestly code of portability arrives
22469 * Numbers:: Growth and contributors
22470 * Deuteronomy:: Approaching the promises of easy configuration
22471
22472 
22473 File: autoconf.info, Node: Genesis, Next: Exodus, Up: History
22474
22475 21.1 Genesis
22476 ============
22477
22478 In June 1991 I was maintaining many of the GNU utilities for the Free
22479 Software Foundation. As they were ported to more platforms and more
22480 programs were added, the number of ‘-D’ options that users had to select
22481 in the makefile (around 20) became burdensome. Especially for me—I had
22482 to test each new release on a bunch of different systems. So I wrote a
22483 little shell script to guess some of the correct settings for the
22484 fileutils package, and released it as part of fileutils 2.0. That
22485 ‘configure’ script worked well enough that the next month I adapted it
22486 (by hand) to create similar ‘configure’ scripts for several other GNU
22487 utilities packages. Brian Berliner also adapted one of my scripts for
22488 his CVS revision control system.
22489
22490 Later that summer, I learned that Richard Stallman and Richard Pixley
22491 were developing similar scripts to use in the GNU compiler tools; so I
22492 adapted my ‘configure’ scripts to support their evolving interface:
22493 using the file name ‘Makefile.in’ as the templates; adding ‘+srcdir’,
22494 the first option (of many); and creating ‘config.status’ files.
22495
22496 
22497 File: autoconf.info, Node: Exodus, Next: Leviticus, Prev: Genesis, Up: History
22498
22499 21.2 Exodus
22500 ===========
22501
22502 As I got feedback from users, I incorporated many improvements, using
22503 Emacs to search and replace, cut and paste, similar changes in each of
22504 the scripts. As I adapted more GNU utilities packages to use
22505 ‘configure’ scripts, updating them all by hand became impractical. Rich
22506 Murphey, the maintainer of the GNU graphics utilities, sent me mail
22507 saying that the ‘configure’ scripts were great, and asking if I had a
22508 tool for generating them that I could send him. No, I thought, but I
22509 should! So I started to work out how to generate them. And the journey
22510 from the slavery of hand-written ‘configure’ scripts to the abundance
22511 and ease of Autoconf began.
22512
22513 Cygnus ‘configure’, which was being developed at around that time, is
22514 table driven; it is meant to deal mainly with a discrete number of
22515 system types with a small number of mainly unguessable features (such as
22516 details of the object file format). The automatic configuration system
22517 that Brian Fox had developed for Bash takes a similar approach. For
22518 general use, it seems to me a hopeless cause to try to maintain an
22519 up-to-date database of which features each variant of each operating
22520 system has. It’s easier and more reliable to check for most features on
22521 the fly—especially on hybrid systems that people have hacked on locally
22522 or that have patches from vendors installed.
22523
22524 I considered using an architecture similar to that of Cygnus
22525 ‘configure’, where there is a single ‘configure’ script that reads
22526 pieces of ‘configure.in’ when run. But I didn’t want to have to
22527 distribute all of the feature tests with every package, so I settled on
22528 having a different ‘configure’ made from each ‘configure.in’ by a
22529 preprocessor. That approach also offered more control and flexibility.
22530
22531 I looked briefly into using the Metaconfig package, by Larry Wall,
22532 Harlan Stenn, and Raphael Manfredi, but I decided not to for several
22533 reasons. The ‘Configure’ scripts it produces are interactive, which I
22534 find quite inconvenient; I didn’t like the ways it checked for some
22535 features (such as library functions); I didn’t know that it was still
22536 being maintained, and the ‘Configure’ scripts I had seen didn’t work on
22537 many modern systems (such as System V R4 and NeXT); it wasn’t flexible
22538 in what it could do in response to a feature’s presence or absence; I
22539 found it confusing to learn; and it was too big and complex for my needs
22540 (I didn’t realize then how much Autoconf would eventually have to grow).
22541
22542 I considered using Perl to generate my style of ‘configure’ scripts,
22543 but decided that M4 was better suited to the job of simple textual
22544 substitutions: it gets in the way less, because output is implicit.
22545 Plus, everyone already has it. (Initially I didn’t rely on the GNU
22546 extensions to M4.) Also, some of my friends at the University of
22547 Maryland had recently been putting M4 front ends on several programs,
22548 including ‘tvtwm’, and I was interested in trying out a new language.
22549
22550 
22551 File: autoconf.info, Node: Leviticus, Next: Numbers, Prev: Exodus, Up: History
22552
22553 21.3 Leviticus
22554 ==============
22555
22556 Since my ‘configure’ scripts determine the system’s capabilities
22557 automatically, with no interactive user intervention, I decided to call
22558 the program that generates them Autoconfig. But with a version number
22559 tacked on, that name would be too long for old Unix file systems, so I
22560 shortened it to Autoconf.
22561
22562 In the fall of 1991 I called together a group of fellow questers
22563 after the Holy Grail of portability (er, that is, alpha testers) to give
22564 me feedback as I encapsulated pieces of my handwritten scripts in M4
22565 macros and continued to add features and improve the techniques used in
22566 the checks. Prominent among the testers were François Pinard, who came
22567 up with the idea of making an Autoconf shell script to run M4 and check
22568 for unresolved macro calls; Richard Pixley, who suggested running the
22569 compiler instead of searching the file system to find include files and
22570 symbols, for more accurate results; Karl Berry, who got Autoconf to
22571 configure TeX and added the macro index to the documentation; and Ian
22572 Lance Taylor, who added support for creating a C header file as an
22573 alternative to putting ‘-D’ options in a makefile, so he could use
22574 Autoconf for his UUCP package. The alpha testers cheerfully adjusted
22575 their files again and again as the names and calling conventions of the
22576 Autoconf macros changed from release to release. They all contributed
22577 many specific checks, great ideas, and bug fixes.
22578
22579 
22580 File: autoconf.info, Node: Numbers, Next: Deuteronomy, Prev: Leviticus, Up: History
22581
22582 21.4 Numbers
22583 ============
22584
22585 In July 1992, after months of alpha testing, I released Autoconf 1.0,
22586 and converted many GNU packages to use it. I was surprised by how
22587 positive the reaction to it was. More people started using it than I
22588 could keep track of, including people working on software that wasn’t
22589 part of the GNU Project (such as TCL, FSP, and Kerberos V5). Autoconf
22590 continued to improve rapidly, as many people using the ‘configure’
22591 scripts reported problems they encountered.
22592
22593 Autoconf turned out to be a good torture test for M4 implementations.
22594 Unix M4 started to dump core because of the length of the macros that
22595 Autoconf defined, and several bugs showed up in GNU M4 as well.
22596 Eventually, we realized that we needed to use some features that only
22597 GNU M4 has. 4.3BSD M4, in particular, has an impoverished set of
22598 builtin macros; the System V version is better, but still doesn’t
22599 provide everything we need.
22600
22601 More development occurred as people put Autoconf under more stresses
22602 (and to uses I hadn’t anticipated). Karl Berry added checks for X11.
22603 david zuhn contributed C++ support. François Pinard made it diagnose
22604 invalid arguments. Jim Blandy bravely coerced it into configuring GNU
22605 Emacs, laying the groundwork for several later improvements. Roland
22606 McGrath got it to configure the GNU C Library, wrote the ‘autoheader’
22607 script to automate the creation of C header file templates, and added a
22608 ‘--verbose’ option to ‘configure’. Noah Friedman added the
22609 ‘--autoconf-dir’ option and ‘AC_MACRODIR’ environment variable. (He
22610 also coined the term “autoconfiscate” to mean “adapt a software package
22611 to use Autoconf”.) Roland and Noah improved the quoting protection in
22612 ‘AC_DEFINE’ and fixed many bugs, especially when I got sick of dealing
22613 with portability problems from February through June, 1993.
22614
22615 
22616 File: autoconf.info, Node: Deuteronomy, Prev: Numbers, Up: History
22617
22618 21.5 Deuteronomy
22619 ================
22620
22621 A long wish list for major features had accumulated, and the effect of
22622 several years of patching by various people had left some residual
22623 cruft. In April 1994, while working for Cygnus Support, I began a major
22624 revision of Autoconf. I added most of the features of the Cygnus
22625 ‘configure’ that Autoconf had lacked, largely by adapting the relevant
22626 parts of Cygnus ‘configure’ with the help of david zuhn and Ken Raeburn.
22627 These features include support for using ‘config.sub’, ‘config.guess’,
22628 ‘--host’, and ‘--target’; making links to files; and running ‘configure’
22629 scripts in subdirectories. Adding these features enabled Ken to convert
22630 GNU ‘as’, and Rob Savoye to convert DejaGNU, to using Autoconf.
22631
22632 I added more features in response to other peoples’ requests. Many
22633 people had asked for ‘configure’ scripts to share the results of the
22634 checks between runs, because (particularly when configuring a large
22635 source tree, like Cygnus does) they were frustratingly slow. Mike
22636 Haertel suggested adding site-specific initialization scripts. People
22637 distributing software that had to unpack on MS-DOS asked for a way to
22638 override the ‘.in’ extension on the file names, which produced file
22639 names like ‘config.h.in’ containing two dots. Jim Avera did an
22640 extensive examination of the problems with quoting in ‘AC_DEFINE’ and
22641 ‘AC_SUBST’; his insights led to significant improvements. Richard
22642 Stallman asked that compiler output be sent to ‘config.log’ instead of
22643 ‘/dev/null’, to help people debug the Emacs ‘configure’ script.
22644
22645 I made some other changes because of my dissatisfaction with the
22646 quality of the program. I made the messages showing results of the
22647 checks less ambiguous, always printing a result. I regularized the
22648 names of the macros and cleaned up coding style inconsistencies. I
22649 added some auxiliary utilities that I had developed to help convert
22650 source code packages to use Autoconf. With the help of François Pinard,
22651 I made the macros not interrupt each others’ messages. (That feature
22652 revealed some performance bottlenecks in GNU M4, which he hastily
22653 corrected!) I reorganized the documentation around problems people want
22654 to solve. And I began a test suite, because experience had shown that
22655 Autoconf has a pronounced tendency to regress when we change it.
22656
22657 Again, several alpha testers gave invaluable feedback, especially
22658 François Pinard, Jim Meyering, Karl Berry, Rob Savoye, Ken Raeburn, and
22659 Mark Eichin.
22660
22661 Finally, version 2.0 was ready. And there was much rejoicing. (And
22662 I have free time again. I think. Yeah, right.)
22663
22664 
22665 File: autoconf.info, Node: GNU Free Documentation License, Next: Indices, Prev: History, Up: Top
22666
22667 Appendix A GNU Free Documentation License
22668 *****************************************
22669
22670 Version 1.3, 3 November 2008
22671
22672 Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
22673 <https://fsf.org/>
22674
22675 Everyone is permitted to copy and distribute verbatim copies
22676 of this license document, but changing it is not allowed.
22677
22678 0. PREAMBLE
22679
22680 The purpose of this License is to make a manual, textbook, or other
22681 functional and useful document “free” in the sense of freedom: to
22682 assure everyone the effective freedom to copy and redistribute it,
22683 with or without modifying it, either commercially or
22684 noncommercially. Secondarily, this License preserves for the
22685 author and publisher a way to get credit for their work, while not
22686 being considered responsible for modifications made by others.
22687
22688 This License is a kind of “copyleft”, which means that derivative
22689 works of the document must themselves be free in the same sense.
22690 It complements the GNU General Public License, which is a copyleft
22691 license designed for free software.
22692
22693 We have designed this License in order to use it for manuals for
22694 free software, because free software needs free documentation: a
22695 free program should come with manuals providing the same freedoms
22696 that the software does. But this License is not limited to
22697 software manuals; it can be used for any textual work, regardless
22698 of subject matter or whether it is published as a printed book. We
22699 recommend this License principally for works whose purpose is
22700 instruction or reference.
22701
22702 1. APPLICABILITY AND DEFINITIONS
22703
22704 This License applies to any manual or other work, in any medium,
22705 that contains a notice placed by the copyright holder saying it can
22706 be distributed under the terms of this License. Such a notice
22707 grants a world-wide, royalty-free license, unlimited in duration,
22708 to use that work under the conditions stated herein. The
22709 “Document”, below, refers to any such manual or work. Any member
22710 of the public is a licensee, and is addressed as “you”. You accept
22711 the license if you copy, modify or distribute the work in a way
22712 requiring permission under copyright law.
22713
22714 A “Modified Version” of the Document means any work containing the
22715 Document or a portion of it, either copied verbatim, or with
22716 modifications and/or translated into another language.
22717
22718 A “Secondary Section” is a named appendix or a front-matter section
22719 of the Document that deals exclusively with the relationship of the
22720 publishers or authors of the Document to the Document’s overall
22721 subject (or to related matters) and contains nothing that could
22722 fall directly within that overall subject. (Thus, if the Document
22723 is in part a textbook of mathematics, a Secondary Section may not
22724 explain any mathematics.) The relationship could be a matter of
22725 historical connection with the subject or with related matters, or
22726 of legal, commercial, philosophical, ethical or political position
22727 regarding them.
22728
22729 The “Invariant Sections” are certain Secondary Sections whose
22730 titles are designated, as being those of Invariant Sections, in the
22731 notice that says that the Document is released under this License.
22732 If a section does not fit the above definition of Secondary then it
22733 is not allowed to be designated as Invariant. The Document may
22734 contain zero Invariant Sections. If the Document does not identify
22735 any Invariant Sections then there are none.
22736
22737 The “Cover Texts” are certain short passages of text that are
22738 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
22739 that says that the Document is released under this License. A
22740 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
22741 be at most 25 words.
22742
22743 A “Transparent” copy of the Document means a machine-readable copy,
22744 represented in a format whose specification is available to the
22745 general public, that is suitable for revising the document
22746 straightforwardly with generic text editors or (for images composed
22747 of pixels) generic paint programs or (for drawings) some widely
22748 available drawing editor, and that is suitable for input to text
22749 formatters or for automatic translation to a variety of formats
22750 suitable for input to text formatters. A copy made in an otherwise
22751 Transparent file format whose markup, or absence of markup, has
22752 been arranged to thwart or discourage subsequent modification by
22753 readers is not Transparent. An image format is not Transparent if
22754 used for any substantial amount of text. A copy that is not
22755 “Transparent” is called “Opaque”.
22756
22757 Examples of suitable formats for Transparent copies include plain
22758 ASCII without markup, Texinfo input format, LaTeX input format,
22759 SGML or XML using a publicly available DTD, and standard-conforming
22760 simple HTML, PostScript or PDF designed for human modification.
22761 Examples of transparent image formats include PNG, XCF and JPG.
22762 Opaque formats include proprietary formats that can be read and
22763 edited only by proprietary word processors, SGML or XML for which
22764 the DTD and/or processing tools are not generally available, and
22765 the machine-generated HTML, PostScript or PDF produced by some word
22766 processors for output purposes only.
22767
22768 The “Title Page” means, for a printed book, the title page itself,
22769 plus such following pages as are needed to hold, legibly, the
22770 material this License requires to appear in the title page. For
22771 works in formats which do not have any title page as such, “Title
22772 Page” means the text near the most prominent appearance of the
22773 work’s title, preceding the beginning of the body of the text.
22774
22775 The “publisher” means any person or entity that distributes copies
22776 of the Document to the public.
22777
22778 A section “Entitled XYZ” means a named subunit of the Document
22779 whose title either is precisely XYZ or contains XYZ in parentheses
22780 following text that translates XYZ in another language. (Here XYZ
22781 stands for a specific section name mentioned below, such as
22782 “Acknowledgements”, “Dedications”, “Endorsements”, or “History”.)
22783 To “Preserve the Title” of such a section when you modify the
22784 Document means that it remains a section “Entitled XYZ” according
22785 to this definition.
22786
22787 The Document may include Warranty Disclaimers next to the notice
22788 which states that this License applies to the Document. These
22789 Warranty Disclaimers are considered to be included by reference in
22790 this License, but only as regards disclaiming warranties: any other
22791 implication that these Warranty Disclaimers may have is void and
22792 has no effect on the meaning of this License.
22793
22794 2. VERBATIM COPYING
22795
22796 You may copy and distribute the Document in any medium, either
22797 commercially or noncommercially, provided that this License, the
22798 copyright notices, and the license notice saying this License
22799 applies to the Document are reproduced in all copies, and that you
22800 add no other conditions whatsoever to those of this License. You
22801 may not use technical measures to obstruct or control the reading
22802 or further copying of the copies you make or distribute. However,
22803 you may accept compensation in exchange for copies. If you
22804 distribute a large enough number of copies you must also follow the
22805 conditions in section 3.
22806
22807 You may also lend copies, under the same conditions stated above,
22808 and you may publicly display copies.
22809
22810 3. COPYING IN QUANTITY
22811
22812 If you publish printed copies (or copies in media that commonly
22813 have printed covers) of the Document, numbering more than 100, and
22814 the Document’s license notice requires Cover Texts, you must
22815 enclose the copies in covers that carry, clearly and legibly, all
22816 these Cover Texts: Front-Cover Texts on the front cover, and
22817 Back-Cover Texts on the back cover. Both covers must also clearly
22818 and legibly identify you as the publisher of these copies. The
22819 front cover must present the full title with all words of the title
22820 equally prominent and visible. You may add other material on the
22821 covers in addition. Copying with changes limited to the covers, as
22822 long as they preserve the title of the Document and satisfy these
22823 conditions, can be treated as verbatim copying in other respects.
22824
22825 If the required texts for either cover are too voluminous to fit
22826 legibly, you should put the first ones listed (as many as fit
22827 reasonably) on the actual cover, and continue the rest onto
22828 adjacent pages.
22829
22830 If you publish or distribute Opaque copies of the Document
22831 numbering more than 100, you must either include a machine-readable
22832 Transparent copy along with each Opaque copy, or state in or with
22833 each Opaque copy a computer-network location from which the general
22834 network-using public has access to download using public-standard
22835 network protocols a complete Transparent copy of the Document, free
22836 of added material. If you use the latter option, you must take
22837 reasonably prudent steps, when you begin distribution of Opaque
22838 copies in quantity, to ensure that this Transparent copy will
22839 remain thus accessible at the stated location until at least one
22840 year after the last time you distribute an Opaque copy (directly or
22841 through your agents or retailers) of that edition to the public.
22842
22843 It is requested, but not required, that you contact the authors of
22844 the Document well before redistributing any large number of copies,
22845 to give them a chance to provide you with an updated version of the
22846 Document.
22847
22848 4. MODIFICATIONS
22849
22850 You may copy and distribute a Modified Version of the Document
22851 under the conditions of sections 2 and 3 above, provided that you
22852 release the Modified Version under precisely this License, with the
22853 Modified Version filling the role of the Document, thus licensing
22854 distribution and modification of the Modified Version to whoever
22855 possesses a copy of it. In addition, you must do these things in
22856 the Modified Version:
22857
22858 A. Use in the Title Page (and on the covers, if any) a title
22859 distinct from that of the Document, and from those of previous
22860 versions (which should, if there were any, be listed in the
22861 History section of the Document). You may use the same title
22862 as a previous version if the original publisher of that
22863 version gives permission.
22864
22865 B. List on the Title Page, as authors, one or more persons or
22866 entities responsible for authorship of the modifications in
22867 the Modified Version, together with at least five of the
22868 principal authors of the Document (all of its principal
22869 authors, if it has fewer than five), unless they release you
22870 from this requirement.
22871
22872 C. State on the Title page the name of the publisher of the
22873 Modified Version, as the publisher.
22874
22875 D. Preserve all the copyright notices of the Document.
22876
22877 E. Add an appropriate copyright notice for your modifications
22878 adjacent to the other copyright notices.
22879
22880 F. Include, immediately after the copyright notices, a license
22881 notice giving the public permission to use the Modified
22882 Version under the terms of this License, in the form shown in
22883 the Addendum below.
22884
22885 G. Preserve in that license notice the full lists of Invariant
22886 Sections and required Cover Texts given in the Document’s
22887 license notice.
22888
22889 H. Include an unaltered copy of this License.
22890
22891 I. Preserve the section Entitled “History”, Preserve its Title,
22892 and add to it an item stating at least the title, year, new
22893 authors, and publisher of the Modified Version as given on the
22894 Title Page. If there is no section Entitled “History” in the
22895 Document, create one stating the title, year, authors, and
22896 publisher of the Document as given on its Title Page, then add
22897 an item describing the Modified Version as stated in the
22898 previous sentence.
22899
22900 J. Preserve the network location, if any, given in the Document
22901 for public access to a Transparent copy of the Document, and
22902 likewise the network locations given in the Document for
22903 previous versions it was based on. These may be placed in the
22904 “History” section. You may omit a network location for a work
22905 that was published at least four years before the Document
22906 itself, or if the original publisher of the version it refers
22907 to gives permission.
22908
22909 K. For any section Entitled “Acknowledgements” or “Dedications”,
22910 Preserve the Title of the section, and preserve in the section
22911 all the substance and tone of each of the contributor
22912 acknowledgements and/or dedications given therein.
22913
22914 L. Preserve all the Invariant Sections of the Document, unaltered
22915 in their text and in their titles. Section numbers or the
22916 equivalent are not considered part of the section titles.
22917
22918 M. Delete any section Entitled “Endorsements”. Such a section
22919 may not be included in the Modified Version.
22920
22921 N. Do not retitle any existing section to be Entitled
22922 “Endorsements” or to conflict in title with any Invariant
22923 Section.
22924
22925 O. Preserve any Warranty Disclaimers.
22926
22927 If the Modified Version includes new front-matter sections or
22928 appendices that qualify as Secondary Sections and contain no
22929 material copied from the Document, you may at your option designate
22930 some or all of these sections as invariant. To do this, add their
22931 titles to the list of Invariant Sections in the Modified Version’s
22932 license notice. These titles must be distinct from any other
22933 section titles.
22934
22935 You may add a section Entitled “Endorsements”, provided it contains
22936 nothing but endorsements of your Modified Version by various
22937 parties—for example, statements of peer review or that the text has
22938 been approved by an organization as the authoritative definition of
22939 a standard.
22940
22941 You may add a passage of up to five words as a Front-Cover Text,
22942 and a passage of up to 25 words as a Back-Cover Text, to the end of
22943 the list of Cover Texts in the Modified Version. Only one passage
22944 of Front-Cover Text and one of Back-Cover Text may be added by (or
22945 through arrangements made by) any one entity. If the Document
22946 already includes a cover text for the same cover, previously added
22947 by you or by arrangement made by the same entity you are acting on
22948 behalf of, you may not add another; but you may replace the old
22949 one, on explicit permission from the previous publisher that added
22950 the old one.
22951
22952 The author(s) and publisher(s) of the Document do not by this
22953 License give permission to use their names for publicity for or to
22954 assert or imply endorsement of any Modified Version.
22955
22956 5. COMBINING DOCUMENTS
22957
22958 You may combine the Document with other documents released under
22959 this License, under the terms defined in section 4 above for
22960 modified versions, provided that you include in the combination all
22961 of the Invariant Sections of all of the original documents,
22962 unmodified, and list them all as Invariant Sections of your
22963 combined work in its license notice, and that you preserve all
22964 their Warranty Disclaimers.
22965
22966 The combined work need only contain one copy of this License, and
22967 multiple identical Invariant Sections may be replaced with a single
22968 copy. If there are multiple Invariant Sections with the same name
22969 but different contents, make the title of each such section unique
22970 by adding at the end of it, in parentheses, the name of the
22971 original author or publisher of that section if known, or else a
22972 unique number. Make the same adjustment to the section titles in
22973 the list of Invariant Sections in the license notice of the
22974 combined work.
22975
22976 In the combination, you must combine any sections Entitled
22977 “History” in the various original documents, forming one section
22978 Entitled “History”; likewise combine any sections Entitled
22979 “Acknowledgements”, and any sections Entitled “Dedications”. You
22980 must delete all sections Entitled “Endorsements.”
22981
22982 6. COLLECTIONS OF DOCUMENTS
22983
22984 You may make a collection consisting of the Document and other
22985 documents released under this License, and replace the individual
22986 copies of this License in the various documents with a single copy
22987 that is included in the collection, provided that you follow the
22988 rules of this License for verbatim copying of each of the documents
22989 in all other respects.
22990
22991 You may extract a single document from such a collection, and
22992 distribute it individually under this License, provided you insert
22993 a copy of this License into the extracted document, and follow this
22994 License in all other respects regarding verbatim copying of that
22995 document.
22996
22997 7. AGGREGATION WITH INDEPENDENT WORKS
22998
22999 A compilation of the Document or its derivatives with other
23000 separate and independent documents or works, in or on a volume of a
23001 storage or distribution medium, is called an “aggregate” if the
23002 copyright resulting from the compilation is not used to limit the
23003 legal rights of the compilation’s users beyond what the individual
23004 works permit. When the Document is included in an aggregate, this
23005 License does not apply to the other works in the aggregate which
23006 are not themselves derivative works of the Document.
23007
23008 If the Cover Text requirement of section 3 is applicable to these
23009 copies of the Document, then if the Document is less than one half
23010 of the entire aggregate, the Document’s Cover Texts may be placed
23011 on covers that bracket the Document within the aggregate, or the
23012 electronic equivalent of covers if the Document is in electronic
23013 form. Otherwise they must appear on printed covers that bracket
23014 the whole aggregate.
23015
23016 8. TRANSLATION
23017
23018 Translation is considered a kind of modification, so you may
23019 distribute translations of the Document under the terms of section
23020 4. Replacing Invariant Sections with translations requires special
23021 permission from their copyright holders, but you may include
23022 translations of some or all Invariant Sections in addition to the
23023 original versions of these Invariant Sections. You may include a
23024 translation of this License, and all the license notices in the
23025 Document, and any Warranty Disclaimers, provided that you also
23026 include the original English version of this License and the
23027 original versions of those notices and disclaimers. In case of a
23028 disagreement between the translation and the original version of
23029 this License or a notice or disclaimer, the original version will
23030 prevail.
23031
23032 If a section in the Document is Entitled “Acknowledgements”,
23033 “Dedications”, or “History”, the requirement (section 4) to
23034 Preserve its Title (section 1) will typically require changing the
23035 actual title.
23036
23037 9. TERMINATION
23038
23039 You may not copy, modify, sublicense, or distribute the Document
23040 except as expressly provided under this License. Any attempt
23041 otherwise to copy, modify, sublicense, or distribute it is void,
23042 and will automatically terminate your rights under this License.
23043
23044 However, if you cease all violation of this License, then your
23045 license from a particular copyright holder is reinstated (a)
23046 provisionally, unless and until the copyright holder explicitly and
23047 finally terminates your license, and (b) permanently, if the
23048 copyright holder fails to notify you of the violation by some
23049 reasonable means prior to 60 days after the cessation.
23050
23051 Moreover, your license from a particular copyright holder is
23052 reinstated permanently if the copyright holder notifies you of the
23053 violation by some reasonable means, this is the first time you have
23054 received notice of violation of this License (for any work) from
23055 that copyright holder, and you cure the violation prior to 30 days
23056 after your receipt of the notice.
23057
23058 Termination of your rights under this section does not terminate
23059 the licenses of parties who have received copies or rights from you
23060 under this License. If your rights have been terminated and not
23061 permanently reinstated, receipt of a copy of some or all of the
23062 same material does not give you any rights to use it.
23063
23064 10. FUTURE REVISIONS OF THIS LICENSE
23065
23066 The Free Software Foundation may publish new, revised versions of
23067 the GNU Free Documentation License from time to time. Such new
23068 versions will be similar in spirit to the present version, but may
23069 differ in detail to address new problems or concerns. See
23070 <https://www.gnu.org/licenses/>.
23071
23072 Each version of the License is given a distinguishing version
23073 number. If the Document specifies that a particular numbered
23074 version of this License “or any later version” applies to it, you
23075 have the option of following the terms and conditions either of
23076 that specified version or of any later version that has been
23077 published (not as a draft) by the Free Software Foundation. If the
23078 Document does not specify a version number of this License, you may
23079 choose any version ever published (not as a draft) by the Free
23080 Software Foundation. If the Document specifies that a proxy can
23081 decide which future versions of this License can be used, that
23082 proxy’s public statement of acceptance of a version permanently
23083 authorizes you to choose that version for the Document.
23084
23085 11. RELICENSING
23086
23087 “Massive Multiauthor Collaboration Site” (or “MMC Site”) means any
23088 World Wide Web server that publishes copyrightable works and also
23089 provides prominent facilities for anybody to edit those works. A
23090 public wiki that anybody can edit is an example of such a server.
23091 A “Massive Multiauthor Collaboration” (or “MMC”) contained in the
23092 site means any set of copyrightable works thus published on the MMC
23093 site.
23094
23095 “CC-BY-SA” means the Creative Commons Attribution-Share Alike 3.0
23096 license published by Creative Commons Corporation, a not-for-profit
23097 corporation with a principal place of business in San Francisco,
23098 California, as well as future copyleft versions of that license
23099 published by that same organization.
23100
23101 “Incorporate” means to publish or republish a Document, in whole or
23102 in part, as part of another Document.
23103
23104 An MMC is “eligible for relicensing” if it is licensed under this
23105 License, and if all works that were first published under this
23106 License somewhere other than this MMC, and subsequently
23107 incorporated in whole or in part into the MMC, (1) had no cover
23108 texts or invariant sections, and (2) were thus incorporated prior
23109 to November 1, 2008.
23110
23111 The operator of an MMC Site may republish an MMC contained in the
23112 site under CC-BY-SA on the same site at any time before August 1,
23113 2009, provided the MMC is eligible for relicensing.
23114
23115 ADDENDUM: How to use this License for your documents
23116 ====================================================
23117
23118 To use this License in a document you have written, include a copy of
23119 the License in the document and put the following copyright and license
23120 notices just after the title page:
23121
23122 Copyright (C) YEAR YOUR NAME.
23123 Permission is granted to copy, distribute and/or modify this document
23124 under the terms of the GNU Free Documentation License, Version 1.3
23125 or any later version published by the Free Software Foundation;
23126 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
23127 Texts. A copy of the license is included in the section entitled ``GNU
23128 Free Documentation License''.
23129
23130 If you have Invariant Sections, Front-Cover Texts and Back-Cover
23131 Texts, replace the “with...Texts.” line with this:
23132
23133 with the Invariant Sections being LIST THEIR TITLES, with
23134 the Front-Cover Texts being LIST, and with the Back-Cover Texts
23135 being LIST.
23136
23137 If you have Invariant Sections without Cover Texts, or some other
23138 combination of the three, merge those two alternatives to suit the
23139 situation.
23140
23141 If your document contains nontrivial examples of program code, we
23142 recommend releasing these examples in parallel under your choice of free
23143 software license, such as the GNU General Public License, to permit
23144 their use in free software.
23145
23146 
23147 File: autoconf.info, Node: Indices, Prev: GNU Free Documentation License, Up: Top
23148
23149 Appendix B Indices
23150 ******************
23151
23152 * Menu:
23153
23154 * Environment Variable Index:: Index of environment variables used
23155 * Output Variable Index:: Index of variables set in output files
23156 * Preprocessor Symbol Index:: Index of C preprocessor symbols defined
23157 * Cache Variable Index:: Index of documented cache variables
23158 * Autoconf Macro Index:: Index of Autoconf macros
23159 * M4 Macro Index:: Index of M4, M4sugar, and M4sh macros
23160 * Autotest Macro Index:: Index of Autotest macros
23161 * Program & Function Index:: Index of those with portability problems
23162 * Concept Index:: General index
23163
23164 
23165 File: autoconf.info, Node: Environment Variable Index, Next: Output Variable Index, Up: Indices
23166
23167 B.1 Environment Variable Index
23168 ==============================
23169
23170 This is an alphabetical list of the environment variables that might
23171 influence Autoconf checks.
23172
23173 [index]
23174 * Menu:
23175
23176 * _: Special Shell Variables.
23177 (line 36)
23178 * A68FLAGS: Preset Output Variables.
23179 (line 170)
23180 * CC: C Compiler. (line 52)
23181 * CDPATH: Special Shell Variables.
23182 (line 40)
23183 * CFLAGS: Preset Output Variables.
23184 (line 23)
23185 * CFLAGS <1>: C Compiler. (line 52)
23186 * CLICOLOR_FORCE: Special Shell Variables.
23187 (line 63)
23188 * CONFIG_COMMANDS: Obsolete config.status Use.
23189 (line 11)
23190 * CONFIG_FILES: Obsolete config.status Use.
23191 (line 15)
23192 * CONFIG_HEADERS: Obsolete config.status Use.
23193 (line 20)
23194 * CONFIG_LINKS: Obsolete config.status Use.
23195 (line 25)
23196 * CONFIG_SHELL: config.status Invocation.
23197 (line 101)
23198 * CONFIG_SITE: Site Defaults. (line 10)
23199 * CONFIG_STATUS: config.status Invocation.
23200 (line 107)
23201 * CPP: C Compiler. (line 134)
23202 * CPPFLAGS: Preset Output Variables.
23203 (line 75)
23204 * CXX: C++ Compiler. (line 7)
23205 * CXXCPP: C++ Compiler. (line 40)
23206 * CXXFLAGS: Preset Output Variables.
23207 (line 97)
23208 * CXXFLAGS <1>: C++ Compiler. (line 7)
23209 * CYGWIN: Obsolete Macros. (line 124)
23210 * DUALCASE: Special Shell Variables.
23211 (line 70)
23212 * ENV: Special Shell Variables.
23213 (line 80)
23214 * ERL: Erlang Compiler and Interpreter.
23215 (line 29)
23216 * ERLC: Erlang Compiler and Interpreter.
23217 (line 10)
23218 * ERLCFLAGS: Preset Output Variables.
23219 (line 116)
23220 * ERLCFLAGS <1>: Erlang Compiler and Interpreter.
23221 (line 10)
23222 * F77: Fortran Compiler. (line 19)
23223 * FC: Fortran Compiler. (line 44)
23224 * FCFLAGS: Preset Output Variables.
23225 (line 122)
23226 * FCFLAGS <1>: Fortran Compiler. (line 44)
23227 * FFLAGS: Preset Output Variables.
23228 (line 129)
23229 * FFLAGS <1>: Fortran Compiler. (line 19)
23230 * FPATH: Special Shell Variables.
23231 (line 96)
23232 * GOFLAGS: Preset Output Variables.
23233 (line 166)
23234 * GREP_OPTIONS: Special Shell Variables.
23235 (line 103)
23236 * HOME: Special Shell Variables.
23237 (line 111)
23238 * HOME <1>: Limitations of Builtins.
23239 (line 263)
23240 * IFS: Special Shell Variables.
23241 (line 116)
23242 * LANG: Special Shell Variables.
23243 (line 160)
23244 * LANGUAGE: Special Shell Variables.
23245 (line 168)
23246 * LC_ADDRESS: Special Shell Variables.
23247 (line 179)
23248 * LC_ALL: Initialization Macros.
23249 (line 14)
23250 * LC_ALL <1>: Special Shell Variables.
23251 (line 160)
23252 * LC_COLLATE: Special Shell Variables.
23253 (line 160)
23254 * LC_CTYPE: Special Shell Variables.
23255 (line 160)
23256 * LC_IDENTIFICATION: Special Shell Variables.
23257 (line 179)
23258 * LC_MEASUREMENT: Special Shell Variables.
23259 (line 179)
23260 * LC_MESSAGES: Special Shell Variables.
23261 (line 160)
23262 * LC_MONETARY: Special Shell Variables.
23263 (line 160)
23264 * LC_NAME: Special Shell Variables.
23265 (line 179)
23266 * LC_NUMERIC: Special Shell Variables.
23267 (line 160)
23268 * LC_PAPER: Special Shell Variables.
23269 (line 179)
23270 * LC_TELEPHONE: Special Shell Variables.
23271 (line 179)
23272 * LC_TIME: Special Shell Variables.
23273 (line 160)
23274 * LDFLAGS: Preset Output Variables.
23275 (line 136)
23276 * LIBS: Preset Output Variables.
23277 (line 150)
23278 * LINENO: Initialization Macros.
23279 (line 67)
23280 * LINENO <1>: Special Shell Variables.
23281 (line 185)
23282 * M4: autom4te Invocation. (line 10)
23283 * MAIL: Special Shell Variables.
23284 (line 80)
23285 * MAILPATH: Special Shell Variables.
23286 (line 80)
23287 * NULLCMD: Special Shell Variables.
23288 (line 314)
23289 * OBJC: Objective C Compiler.
23290 (line 7)
23291 * OBJCFLAGS: Preset Output Variables.
23292 (line 158)
23293 * OBJCFLAGS <1>: Objective C Compiler.
23294 (line 7)
23295 * OBJCPP: Objective C Compiler.
23296 (line 27)
23297 * OBJCXX: Objective C++ Compiler.
23298 (line 7)
23299 * OBJCXXCPP: Objective C++ Compiler.
23300 (line 27)
23301 * OBJCXXFLAGS: Preset Output Variables.
23302 (line 162)
23303 * OBJCXXFLAGS <1>: Objective C++ Compiler.
23304 (line 7)
23305 * OLDPWD: Special Shell Variables.
23306 (line 321)
23307 * OLDPWD <1>: Limitations of Builtins.
23308 (line 258)
23309 * options: Special Shell Variables.
23310 (line 326)
23311 * PATH_SEPARATOR: Special Shell Variables.
23312 (line 330)
23313 * POSIXLY_CORRECT: Special Shell Variables.
23314 (line 339)
23315 * PS1: Special Shell Variables.
23316 (line 80)
23317 * PS2: Special Shell Variables.
23318 (line 80)
23319 * PS4: Special Shell Variables.
23320 (line 80)
23321 * PWD: Special Shell Variables.
23322 (line 354)
23323 * PWD <1>: Limitations of Builtins.
23324 (line 258)
23325 * RANDOM: Special Shell Variables.
23326 (line 362)
23327 * SHELL: Initialization Macros.
23328 (line 14)
23329 * SIMPLE_BACKUP_SUFFIX: autoupdate Invocation.
23330 (line 16)
23331 * status: Special Shell Variables.
23332 (line 368)
23333 * TMPDIR: Initialization Macros.
23334 (line 77)
23335 * WARNINGS: autoconf Invocation. (line 62)
23336 * WARNINGS <1>: autoreconf Invocation.
23337 (line 130)
23338 * WARNINGS <2>: autoheader Invocation.
23339 (line 87)
23340 * WARNINGS <3>: autom4te Invocation. (line 58)
23341 * XMKMF: System Services. (line 10)
23342 * YACC: Particular Programs. (line 238)
23343 * YFLAGS: Particular Programs. (line 238)
23344
23345 
23346 File: autoconf.info, Node: Output Variable Index, Next: Preprocessor Symbol Index, Prev: Environment Variable Index, Up: Indices
23347
23348 B.2 Output Variable Index
23349 =========================
23350
23351 This is an alphabetical list of the variables that Autoconf can
23352 substitute into files that it creates, typically one or more makefiles.
23353 *Note Setting Output Variables::, for more information on how this is
23354 done.
23355
23356 [index]
23357 * Menu:
23358
23359 * A68FLAGS: Preset Output Variables.
23360 (line 170)
23361 * abs_builddir: Preset Output Variables.
23362 (line 177)
23363 * abs_srcdir: Preset Output Variables.
23364 (line 199)
23365 * abs_top_builddir: Preset Output Variables.
23366 (line 192)
23367 * abs_top_srcdir: Preset Output Variables.
23368 (line 206)
23369 * ac_empty: Fortran Compiler. (line 468)
23370 * ALLOCA: Particular Functions.
23371 (line 10)
23372 * AR: Particular Programs. (line 10)
23373 * AWK: Particular Programs. (line 14)
23374 * bindir: Installation Directory Variables.
23375 (line 15)
23376 * build: Canonicalizing. (line 21)
23377 * build_alias: Canonicalizing. (line 9)
23378 * build_cpu: Canonicalizing. (line 21)
23379 * build_os: Canonicalizing. (line 21)
23380 * build_vendor: Canonicalizing. (line 21)
23381 * builddir: Preset Output Variables.
23382 (line 174)
23383 * CC: C Compiler. (line 52)
23384 * CC <1>: System Services. (line 48)
23385 * CFLAGS: Preset Output Variables.
23386 (line 23)
23387 * CFLAGS <1>: C Compiler. (line 52)
23388 * configure_input: Preset Output Variables.
23389 (line 61)
23390 * CPP: C Compiler. (line 134)
23391 * CPP <1>: C Compiler. (line 149)
23392 * CPPFLAGS: Preset Output Variables.
23393 (line 75)
23394 * cross_compiling: Runtime. (line 77)
23395 * CXX: C++ Compiler. (line 7)
23396 * CXXCPP: C++ Compiler. (line 40)
23397 * CXXFLAGS: Preset Output Variables.
23398 (line 97)
23399 * CXXFLAGS <1>: C++ Compiler. (line 7)
23400 * datadir: Installation Directory Variables.
23401 (line 18)
23402 * datarootdir: Installation Directory Variables.
23403 (line 22)
23404 * DEFS: Preset Output Variables.
23405 (line 101)
23406 * docdir: Installation Directory Variables.
23407 (line 26)
23408 * dvidir: Installation Directory Variables.
23409 (line 30)
23410 * ECHO_C: Preset Output Variables.
23411 (line 111)
23412 * ECHO_N: Preset Output Variables.
23413 (line 111)
23414 * ECHO_T: Preset Output Variables.
23415 (line 111)
23416 * EGREP: Particular Programs. (line 37)
23417 * ERL: Erlang Compiler and Interpreter.
23418 (line 29)
23419 * ERL <1>: Language Choice. (line 40)
23420 * ERL <2>: Running the Compiler.
23421 (line 35)
23422 * ERLANG_ERTS_VER: Erlang Libraries. (line 12)
23423 * ERLANG_INSTALL_LIB_DIR: Installation Directory Variables.
23424 (line 210)
23425 * ERLANG_INSTALL_LIB_DIR <1>: Erlang Libraries. (line 86)
23426 * ERLANG_INSTALL_LIB_DIR_LIBRARY: Installation Directory Variables.
23427 (line 215)
23428 * ERLANG_INSTALL_LIB_DIR_LIBRARY <1>: Erlang Libraries. (line 94)
23429 * ERLANG_LIB_DIR: Erlang Libraries. (line 28)
23430 * ERLANG_LIB_DIR_LIBRARY: Erlang Libraries. (line 36)
23431 * ERLANG_LIB_VER_LIBRARY: Erlang Libraries. (line 36)
23432 * ERLANG_ROOT_DIR: Erlang Libraries. (line 22)
23433 * ERLC: Erlang Compiler and Interpreter.
23434 (line 10)
23435 * ERLC <1>: Language Choice. (line 40)
23436 * ERLCFLAGS: Preset Output Variables.
23437 (line 116)
23438 * ERLCFLAGS <1>: Erlang Compiler and Interpreter.
23439 (line 10)
23440 * ERLCFLAGS <2>: Language Choice. (line 40)
23441 * exec_prefix: Installation Directory Variables.
23442 (line 33)
23443 * EXEEXT: Compilers and Preprocessors.
23444 (line 6)
23445 * EXEEXT <1>: Obsolete Macros. (line 181)
23446 * F77: Fortran Compiler. (line 19)
23447 * FC: Fortran Compiler. (line 44)
23448 * FC_MODEXT: Fortran Compiler. (line 440)
23449 * FC_MODINC: Fortran Compiler. (line 468)
23450 * FC_MODOUT: Fortran Compiler. (line 505)
23451 * FCFLAGS: Preset Output Variables.
23452 (line 122)
23453 * FCFLAGS <1>: Fortran Compiler. (line 44)
23454 * FCLIBS: Fortran Compiler. (line 91)
23455 * FFLAGS: Preset Output Variables.
23456 (line 129)
23457 * FFLAGS <1>: Fortran Compiler. (line 19)
23458 * FGREP: Particular Programs. (line 44)
23459 * FLIBS: Fortran Compiler. (line 91)
23460 * GETGROUPS_LIB: Particular Functions.
23461 (line 144)
23462 * GETLOADAVG_LIBS: Particular Functions.
23463 (line 161)
23464 * GOFLAGS: Preset Output Variables.
23465 (line 166)
23466 * GREP: Particular Programs. (line 28)
23467 * host: Canonicalizing. (line 29)
23468 * host_alias: Canonicalizing. (line 9)
23469 * host_cpu: Canonicalizing. (line 29)
23470 * host_os: Canonicalizing. (line 29)
23471 * host_vendor: Canonicalizing. (line 29)
23472 * htmldir: Installation Directory Variables.
23473 (line 40)
23474 * includedir: Installation Directory Variables.
23475 (line 43)
23476 * infodir: Installation Directory Variables.
23477 (line 46)
23478 * INSTALL: Particular Programs. (line 51)
23479 * INSTALL_DATA: Particular Programs. (line 51)
23480 * INSTALL_PROGRAM: Particular Programs. (line 51)
23481 * INSTALL_SCRIPT: Particular Programs. (line 51)
23482 * KMEM_GROUP: Particular Functions.
23483 (line 161)
23484 * LDFLAGS: Preset Output Variables.
23485 (line 136)
23486 * LEX: Particular Programs. (line 112)
23487 * LEX_OUTPUT_ROOT: Particular Programs. (line 112)
23488 * LEXLIB: Particular Programs. (line 112)
23489 * libdir: Installation Directory Variables.
23490 (line 49)
23491 * libexecdir: Installation Directory Variables.
23492 (line 52)
23493 * LIBOBJDIR: AC_LIBOBJ vs LIBOBJS.
23494 (line 35)
23495 * LIBOBJS: Particular Functions.
23496 (line 161)
23497 * LIBOBJS <1>: Particular Functions.
23498 (line 294)
23499 * LIBOBJS <2>: Particular Functions.
23500 (line 304)
23501 * LIBOBJS <3>: Generic Functions. (line 56)
23502 * LIBOBJS <4>: Generic Functions. (line 117)
23503 * LIBOBJS <5>: Particular Structures.
23504 (line 26)
23505 * LIBS: Preset Output Variables.
23506 (line 150)
23507 * LIBS <1>: Obsolete Macros. (line 312)
23508 * LIBS <2>: Obsolete Macros. (line 524)
23509 * LIBS <3>: Obsolete Macros. (line 758)
23510 * LN_S: Particular Programs. (line 206)
23511 * localedir: Installation Directory Variables.
23512 (line 55)
23513 * localstatedir: Installation Directory Variables.
23514 (line 60)
23515 * mandir: Installation Directory Variables.
23516 (line 72)
23517 * MKDIR_P: Particular Programs. (line 88)
23518 * NEED_SETGID: Particular Functions.
23519 (line 161)
23520 * OBJC: Objective C Compiler.
23521 (line 7)
23522 * OBJCFLAGS: Preset Output Variables.
23523 (line 158)
23524 * OBJCFLAGS <1>: Objective C Compiler.
23525 (line 7)
23526 * OBJCPP: Objective C Compiler.
23527 (line 27)
23528 * OBJCXX: Objective C++ Compiler.
23529 (line 7)
23530 * OBJCXXCPP: Objective C++ Compiler.
23531 (line 27)
23532 * OBJCXXFLAGS: Preset Output Variables.
23533 (line 162)
23534 * OBJCXXFLAGS <1>: Objective C++ Compiler.
23535 (line 7)
23536 * OBJEXT: Compilers and Preprocessors.
23537 (line 10)
23538 * OBJEXT <1>: Obsolete Macros. (line 400)
23539 * oldincludedir: Installation Directory Variables.
23540 (line 75)
23541 * OPENMP_CFLAGS: Generic Compiler Characteristics.
23542 (line 63)
23543 * OPENMP_CXXFLAGS: Generic Compiler Characteristics.
23544 (line 63)
23545 * OPENMP_FCFLAGS: Generic Compiler Characteristics.
23546 (line 63)
23547 * OPENMP_FFLAGS: Generic Compiler Characteristics.
23548 (line 63)
23549 * PACKAGE_BUGREPORT: Initializing configure.
23550 (line 117)
23551 * PACKAGE_NAME: Initializing configure.
23552 (line 105)
23553 * PACKAGE_STRING: Initializing configure.
23554 (line 114)
23555 * PACKAGE_TARNAME: Initializing configure.
23556 (line 108)
23557 * PACKAGE_URL: Initializing configure.
23558 (line 121)
23559 * PACKAGE_VERSION: Initializing configure.
23560 (line 111)
23561 * pdfdir: Installation Directory Variables.
23562 (line 78)
23563 * POW_LIB: Particular Functions.
23564 (line 432)
23565 * prefix: Installation Directory Variables.
23566 (line 81)
23567 * program_transform_name: Transforming Names. (line 11)
23568 * psdir: Installation Directory Variables.
23569 (line 86)
23570 * RANLIB: Particular Programs. (line 225)
23571 * runstatedir: Installation Directory Variables.
23572 (line 64)
23573 * sbindir: Installation Directory Variables.
23574 (line 89)
23575 * SED: Particular Programs. (line 229)
23576 * SET_MAKE: Output. (line 45)
23577 * sharedstatedir: Installation Directory Variables.
23578 (line 93)
23579 * srcdir: Preset Output Variables.
23580 (line 195)
23581 * subdirs: Subdirectories. (line 12)
23582 * sysconfdir: Installation Directory Variables.
23583 (line 97)
23584 * target: Canonicalizing. (line 36)
23585 * target_alias: Canonicalizing. (line 9)
23586 * target_cpu: Canonicalizing. (line 36)
23587 * target_os: Canonicalizing. (line 36)
23588 * target_vendor: Canonicalizing. (line 36)
23589 * tmp: Initialization Macros.
23590 (line 77)
23591 * top_build_prefix: Preset Output Variables.
23592 (line 184)
23593 * top_builddir: Preset Output Variables.
23594 (line 180)
23595 * top_srcdir: Preset Output Variables.
23596 (line 202)
23597 * X_CFLAGS: System Services. (line 30)
23598 * X_EXTRA_LIBS: System Services. (line 30)
23599 * X_LIBS: System Services. (line 30)
23600 * X_PRE_LIBS: System Services. (line 30)
23601 * YACC: Particular Programs. (line 238)
23602
23603 
23604 File: autoconf.info, Node: Preprocessor Symbol Index, Next: Cache Variable Index, Prev: Output Variable Index, Up: Indices
23605
23606 B.3 Preprocessor Symbol Index
23607 =============================
23608
23609 This is an alphabetical list of the C preprocessor symbols that the
23610 Autoconf macros define. To work with Autoconf, C source code needs to
23611 use these names in ‘#if’ or ‘#ifdef’ directives.
23612
23613 [index]
23614 * Menu:
23615
23616 * __CHAR_UNSIGNED__: C Compiler. (line 274)
23617 * __EXTENSIONS__: C and POSIX Variants.
23618 (line 61)
23619 * __PROTOTYPES: C Compiler. (line 339)
23620 * __STDC_NO_VLA__: C Compiler. (line 322)
23621 * __STDC_WANT_DEC_FP__: C and POSIX Variants.
23622 (line 79)
23623 * __STDC_WANT_IEC_60559_ATTRIBS_EXT__: C and POSIX Variants.
23624 (line 37)
23625 * __STDC_WANT_IEC_60559_BFP_EXT__: C and POSIX Variants.
23626 (line 39)
23627 * __STDC_WANT_IEC_60559_DFP_EXT__: C and POSIX Variants.
23628 (line 41)
23629 * __STDC_WANT_IEC_60559_EXT__: C and POSIX Variants.
23630 (line 43)
23631 * __STDC_WANT_IEC_60559_FUNCS_EXT__: C and POSIX Variants.
23632 (line 45)
23633 * __STDC_WANT_IEC_60559_TYPES_EXT__: C and POSIX Variants.
23634 (line 47)
23635 * __STDC_WANT_LIB_EXT1__: C and POSIX Variants.
23636 (line 82)
23637 * __STDC_WANT_LIB_EXT2__: C and POSIX Variants.
23638 (line 50)
23639 * __STDC_WANT_MATH_SPEC_FUNCS__: C and POSIX Variants.
23640 (line 52)
23641 * _ALL_SOURCE: C and POSIX Variants.
23642 (line 21)
23643 * _ALL_SOURCE <1>: Obsolete Macros. (line 20)
23644 * _COSMO_SOURCE: C and POSIX Variants.
23645 (line 23)
23646 * _DARWIN_C_SOURCE: C and POSIX Variants.
23647 (line 25)
23648 * _FILE_OFFSET_BITS: System Services. (line 48)
23649 * _Generic: C Compiler. (line 231)
23650 * _GNU_SOURCE: C and POSIX Variants.
23651 (line 27)
23652 * _GNU_SOURCE <1>: Obsolete Macros. (line 240)
23653 * _LARGEFILE_SOURCE: Particular Functions.
23654 (line 131)
23655 * _MINIX: C and POSIX Variants.
23656 (line 68)
23657 * _MINIX <1>: Obsolete Macros. (line 387)
23658 * _NETBSD_SOURCE: C and POSIX Variants.
23659 (line 29)
23660 * _OPENBSD_SOURCE: C and POSIX Variants.
23661 (line 32)
23662 * _OPENMP: Generic Compiler Characteristics.
23663 (line 63)
23664 * _POSIX_1_SOURCE: C and POSIX Variants.
23665 (line 68)
23666 * _POSIX_1_SOURCE <1>: Obsolete Macros. (line 387)
23667 * _POSIX_PTHREAD_SEMANTICS: C and POSIX Variants.
23668 (line 35)
23669 * _POSIX_SOURCE: C and POSIX Variants.
23670 (line 68)
23671 * _POSIX_SOURCE <1>: Obsolete Macros. (line 387)
23672 * _POSIX_VERSION: Particular Headers. (line 183)
23673 * _TANDEM_SOURCE: C and POSIX Variants.
23674 (line 54)
23675 * _TIME_BITS: System Services. (line 48)
23676 * _XOPEN_SOURCE: C and POSIX Variants.
23677 (line 75)
23678 * ALIGNOF_TYPE: Generic Compiler Characteristics.
23679 (line 30)
23680 * C_ALLOCA: Particular Functions.
23681 (line 10)
23682 * C_GETLOADAVG: Particular Functions.
23683 (line 161)
23684 * CLOSEDIR_VOID: Particular Functions.
23685 (line 58)
23686 * const: C Compiler. (line 201)
23687 * CXX_NO_MINUS_C_MINUS_O: C++ Compiler. (line 57)
23688 * DGUX: Particular Functions.
23689 (line 161)
23690 * DIRENT: Obsolete Macros. (line 161)
23691 * F77_DUMMY_MAIN: Fortran Compiler. (line 129)
23692 * F77_FUNC: Fortran Compiler. (line 199)
23693 * F77_FUNC_: Fortran Compiler. (line 199)
23694 * F77_MAIN: Fortran Compiler. (line 174)
23695 * F77_NO_MINUS_C_MINUS_O: Fortran Compiler. (line 75)
23696 * FC_DUMMY_MAIN: Fortran Compiler. (line 129)
23697 * FC_FUNC: Fortran Compiler. (line 199)
23698 * FC_FUNC_: Fortran Compiler. (line 199)
23699 * FC_MAIN: Fortran Compiler. (line 174)
23700 * FC_NO_MINUS_C_MINUS_O: Fortran Compiler. (line 75)
23701 * FLEXIBLE_ARRAY_MEMBER: C Compiler. (line 298)
23702 * GETGROUPS_T: Particular Types. (line 14)
23703 * GETLOADAVG_PRIVILEGED: Particular Functions.
23704 (line 161)
23705 * GETPGRP_VOID: Particular Functions.
23706 (line 207)
23707 * gid_t: Particular Types. (line 125)
23708 * GWINSZ_IN_SYS_IOCTL: Particular Headers. (line 199)
23709 * HAVE__BOOL: Particular Headers. (line 10)
23710 * HAVE__BOOL <1>: Particular Headers. (line 130)
23711 * HAVE_AGGREGATE_MEMBER: Generic Structures. (line 29)
23712 * HAVE_ALLOCA_H: Particular Functions.
23713 (line 10)
23714 * HAVE_C_BACKSLASH_A: C Compiler. (line 160)
23715 * HAVE_C_VARARRAYS: C Compiler. (line 322)
23716 * HAVE_CHOWN: Particular Functions.
23717 (line 48)
23718 * HAVE_CONFIG_H: Configuration Headers.
23719 (line 37)
23720 * HAVE_DECL_STRERROR_R: Particular Functions.
23721 (line 409)
23722 * HAVE_DECL_SYMBOL: Generic Declarations.
23723 (line 34)
23724 * HAVE_DECL_SYMBOL <1>: Generic Declarations.
23725 (line 79)
23726 * HAVE_DECL_TZNAME: Particular Structures.
23727 (line 43)
23728 * HAVE_DIRENT_H: Particular Headers. (line 28)
23729 * HAVE_DOPRNT: Particular Functions.
23730 (line 475)
23731 * HAVE_FSEEKO: Particular Functions.
23732 (line 131)
23733 * HAVE_FUNCTION: Generic Functions. (line 27)
23734 * HAVE_FUNCTION <1>: Generic Functions. (line 38)
23735 * HAVE_FUNCTION <2>: Generic Functions. (line 117)
23736 * HAVE_GETGROUPS: Particular Functions.
23737 (line 144)
23738 * HAVE_GETMNTENT: Particular Functions.
23739 (line 195)
23740 * HAVE_HEADER: Generic Headers. (line 39)
23741 * HAVE_HEADER <1>: Generic Headers. (line 56)
23742 * HAVE_INT16_T: Particular Types. (line 39)
23743 * HAVE_INT32_T: Particular Types. (line 42)
23744 * HAVE_INT64_T: Particular Types. (line 45)
23745 * HAVE_INT8_T: Particular Types. (line 21)
23746 * HAVE_INTMAX_T: Particular Types. (line 48)
23747 * HAVE_INTPTR_T: Particular Types. (line 53)
23748 * HAVE_LONG_DOUBLE: Particular Types. (line 58)
23749 * HAVE_LONG_DOUBLE <1>: Obsolete Macros. (line 33)
23750 * HAVE_LONG_DOUBLE_WIDER: Particular Types. (line 69)
23751 * HAVE_LONG_FILE_NAMES: System Services. (line 133)
23752 * HAVE_LONG_LONG_INT: Particular Types. (line 77)
23753 * HAVE_LSTAT_EMPTY_STRING_BUG: Particular Functions.
23754 (line 384)
23755 * HAVE_MALLOC: Particular Functions.
23756 (line 249)
23757 * HAVE_MBRTOWC: Particular Functions.
23758 (line 283)
23759 * HAVE_MMAP: Particular Functions.
23760 (line 316)
23761 * HAVE_NDIR_H: Particular Headers. (line 28)
23762 * HAVE_NLIST_H: Particular Functions.
23763 (line 161)
23764 * HAVE_OBSTACK: Particular Functions.
23765 (line 328)
23766 * HAVE_REALLOC: Particular Functions.
23767 (line 338)
23768 * HAVE_RESOLV_H: Particular Headers. (line 102)
23769 * HAVE_RESTARTABLE_SYSCALLS: Obsolete Macros. (line 580)
23770 * HAVE_ST_BLKSIZE: Obsolete Macros. (line 553)
23771 * HAVE_ST_BLOCKS: Particular Structures.
23772 (line 26)
23773 * HAVE_ST_RDEV: Obsolete Macros. (line 562)
23774 * HAVE_STAT_EMPTY_STRING_BUG: Particular Functions.
23775 (line 384)
23776 * HAVE_STDBOOL_H: Particular Headers. (line 130)
23777 * HAVE_STRCOLL: Particular Functions.
23778 (line 399)
23779 * HAVE_STRERROR_R: Particular Functions.
23780 (line 409)
23781 * HAVE_STRFTIME: Particular Functions.
23782 (line 425)
23783 * HAVE_STRINGIZE: C Compiler. (line 288)
23784 * HAVE_STRNLEN: Particular Functions.
23785 (line 454)
23786 * HAVE_STRTOLD: Particular Functions.
23787 (line 444)
23788 * HAVE_STRUCT_DIRENT_D_INO: Particular Structures.
23789 (line 9)
23790 * HAVE_STRUCT_DIRENT_D_TYPE: Particular Structures.
23791 (line 21)
23792 * HAVE_STRUCT_STAT_ST_BLKSIZE: Obsolete Macros. (line 553)
23793 * HAVE_STRUCT_STAT_ST_BLOCKS: Particular Structures.
23794 (line 26)
23795 * HAVE_STRUCT_STAT_ST_RDEV: Obsolete Macros. (line 562)
23796 * HAVE_STRUCT_TM_TM_ZONE: Particular Structures.
23797 (line 43)
23798 * HAVE_SYS_DIR_H: Particular Headers. (line 28)
23799 * HAVE_SYS_NDIR_H: Particular Headers. (line 28)
23800 * HAVE_SYS_WAIT_H: Particular Headers. (line 159)
23801 * HAVE_TM_ZONE: Particular Structures.
23802 (line 43)
23803 * HAVE_TYPE: Generic Types. (line 27)
23804 * HAVE_TYPEOF: C Compiler. (line 332)
23805 * HAVE_TZNAME: Particular Structures.
23806 (line 43)
23807 * HAVE_UINT16_T: Particular Types. (line 137)
23808 * HAVE_UINT32_T: Particular Types. (line 140)
23809 * HAVE_UINT64_T: Particular Types. (line 143)
23810 * HAVE_UINT8_T: Particular Types. (line 131)
23811 * HAVE_UINTMAX_T: Particular Types. (line 146)
23812 * HAVE_UINTPTR_T: Particular Types. (line 151)
23813 * HAVE_UNSIGNED_LONG_LONG_INT: Particular Types. (line 156)
23814 * HAVE_UTIME_NULL: Particular Functions.
23815 (line 465)
23816 * HAVE_VFORK_H: Particular Functions.
23817 (line 107)
23818 * HAVE_VPRINTF: Particular Functions.
23819 (line 475)
23820 * HAVE_WAIT3: Obsolete Macros. (line 222)
23821 * HAVE_WORKING_FORK: Particular Functions.
23822 (line 107)
23823 * HAVE_WORKING_VFORK: Particular Functions.
23824 (line 107)
23825 * inline: C Compiler. (line 269)
23826 * INT_16_BITS: Obsolete Macros. (line 292)
23827 * int16_t: Particular Types. (line 39)
23828 * int32_t: Particular Types. (line 42)
23829 * int64_t: Particular Types. (line 45)
23830 * int8_t: Particular Types. (line 21)
23831 * intmax_t: Particular Types. (line 48)
23832 * intptr_t: Particular Types. (line 53)
23833 * LONG_64_BITS: Obsolete Macros. (line 354)
23834 * LSTAT_FOLLOWS_SLASHED_SYMLINK: Particular Functions.
23835 (line 230)
23836 * MAJOR_IN_MKDEV: Particular Headers. (line 71)
23837 * MAJOR_IN_SYSMACROS: Particular Headers. (line 71)
23838 * malloc: Particular Functions.
23839 (line 249)
23840 * mbstate_t: Particular Types. (line 87)
23841 * mode_t: Particular Types. (line 95)
23842 * NDEBUG: Particular Headers. (line 23)
23843 * NDIR: Obsolete Macros. (line 161)
23844 * NEED_MEMORY_H: Obsolete Macros. (line 375)
23845 * NEED_SETGID: Particular Functions.
23846 (line 161)
23847 * NLIST_NAME_UNION: Particular Functions.
23848 (line 161)
23849 * NO_MINUS_C_MINUS_O: C Compiler. (line 123)
23850 * off_t: Particular Types. (line 101)
23851 * PACKAGE_BUGREPORT: Initializing configure.
23852 (line 117)
23853 * PACKAGE_NAME: Initializing configure.
23854 (line 105)
23855 * PACKAGE_STRING: Initializing configure.
23856 (line 114)
23857 * PACKAGE_TARNAME: Initializing configure.
23858 (line 108)
23859 * PACKAGE_URL: Initializing configure.
23860 (line 121)
23861 * PACKAGE_VERSION: Initializing configure.
23862 (line 111)
23863 * PARAMS: C Compiler. (line 339)
23864 * pid_t: Particular Types. (line 107)
23865 * PROTOTYPES: C Compiler. (line 339)
23866 * realloc: Particular Functions.
23867 (line 338)
23868 * restrict: C Compiler. (line 235)
23869 * RETSIGTYPE: Obsolete Macros. (line 696)
23870 * SELECT_TYPE_ARG1: Particular Functions.
23871 (line 355)
23872 * SELECT_TYPE_ARG234: Particular Functions.
23873 (line 355)
23874 * SELECT_TYPE_ARG5: Particular Functions.
23875 (line 355)
23876 * SETPGRP_VOID: Particular Functions.
23877 (line 366)
23878 * SETVBUF_REVERSED: Obsolete Macros. (line 214)
23879 * size_t: Particular Types. (line 113)
23880 * SIZEOF_TYPE-OR-EXPR: Generic Compiler Characteristics.
23881 (line 8)
23882 * ssize_t: Particular Types. (line 119)
23883 * STAT_MACROS_BROKEN: Particular Headers. (line 121)
23884 * STDC_HEADERS: Particular Headers. (line 149)
23885 * STRERROR_R_CHAR_P: Particular Functions.
23886 (line 409)
23887 * SVR4: Particular Functions.
23888 (line 161)
23889 * SYS_SIGLIST_DECLARED: Obsolete Macros. (line 141)
23890 * SYSDIR: Obsolete Macros. (line 161)
23891 * SYSNDIR: Obsolete Macros. (line 161)
23892 * TIME_WITH_SYS_TIME: Obsolete Macros. (line 267)
23893 * TM_IN_SYS_TIME: Particular Structures.
23894 (line 35)
23895 * typeof: C Compiler. (line 332)
23896 * uid_t: Particular Types. (line 125)
23897 * uint16_t: Particular Types. (line 137)
23898 * uint32_t: Particular Types. (line 140)
23899 * uint64_t: Particular Types. (line 143)
23900 * uint8_t: Particular Types. (line 131)
23901 * uintmax_t: Particular Types. (line 146)
23902 * uintptr_t: Particular Types. (line 151)
23903 * UMAX: Particular Functions.
23904 (line 161)
23905 * UMAX4_3: Particular Functions.
23906 (line 161)
23907 * USG: Obsolete Macros. (line 712)
23908 * VARIABLE: Defining Symbols. (line 33)
23909 * VARIABLE <1>: Defining Symbols. (line 75)
23910 * vfork: Particular Functions.
23911 (line 107)
23912 * volatile: C Compiler. (line 253)
23913 * WORDS_BIGENDIAN: C Compiler. (line 168)
23914 * X_DISPLAY_MISSING: System Services. (line 30)
23915 * YYTEXT_POINTER: Particular Programs. (line 112)
23916
23917 
23918 File: autoconf.info, Node: Cache Variable Index, Next: Autoconf Macro Index, Prev: Preprocessor Symbol Index, Up: Indices
23919
23920 B.4 Cache Variable Index
23921 ========================
23922
23923 This is an alphabetical list of documented cache variables used by
23924 macros defined in Autoconf. Autoconf macros may use additional cache
23925 variables internally.
23926
23927 [index]
23928 * Menu:
23929
23930 * ac_cv_alignof_TYPE-OR-EXPR: Generic Compiler Characteristics.
23931 (line 30)
23932 * ac_cv_c_const: C Compiler. (line 201)
23933 * ac_cv_c_int16_t: Particular Types. (line 39)
23934 * ac_cv_c_int32_t: Particular Types. (line 42)
23935 * ac_cv_c_int64_t: Particular Types. (line 45)
23936 * ac_cv_c_int8_t: Particular Types. (line 21)
23937 * ac_cv_c_restrict: C Compiler. (line 235)
23938 * ac_cv_c_uint16_t: Particular Types. (line 137)
23939 * ac_cv_c_uint32_t: Particular Types. (line 140)
23940 * ac_cv_c_uint64_t: Particular Types. (line 143)
23941 * ac_cv_c_uint8_t: Particular Types. (line 131)
23942 * ac_cv_f77_compiler_gnu: Fortran Compiler. (line 19)
23943 * ac_cv_f77_dummy_main: Fortran Compiler. (line 129)
23944 * ac_cv_f77_implicit_none: Fortran Compiler. (line 428)
23945 * ac_cv_f77_libs: Fortran Compiler. (line 91)
23946 * ac_cv_f77_main: Fortran Compiler. (line 174)
23947 * ac_cv_f77_mangling: Fortran Compiler. (line 199)
23948 * ac_cv_fc_check_bounds: Fortran Compiler. (line 413)
23949 * ac_cv_fc_compiler_gnu: Fortran Compiler. (line 44)
23950 * ac_cv_fc_cray_pointer: Fortran Compiler. (line 531)
23951 * ac_cv_fc_dummy_main: Fortran Compiler. (line 129)
23952 * ac_cv_fc_fixedform: Fortran Compiler. (line 373)
23953 * ac_cv_fc_freeform: Fortran Compiler. (line 348)
23954 * ac_cv_fc_implicit_none: Fortran Compiler. (line 428)
23955 * ac_cv_fc_libs: Fortran Compiler. (line 91)
23956 * ac_cv_fc_line_length: Fortran Compiler. (line 395)
23957 * ac_cv_fc_main: Fortran Compiler. (line 174)
23958 * ac_cv_fc_mangling: Fortran Compiler. (line 199)
23959 * ac_cv_fc_module_ext: Fortran Compiler. (line 440)
23960 * ac_cv_fc_module_flag: Fortran Compiler. (line 468)
23961 * ac_cv_fc_module_output_flag: Fortran Compiler. (line 505)
23962 * ac_cv_fc_pp_define: Fortran Compiler. (line 332)
23963 * ac_cv_fc_pp_srcext_EXT: Fortran Compiler. (line 275)
23964 * ac_cv_fc_srcext_EXT: Fortran Compiler. (line 275)
23965 * ac_cv_file_FILE: Files. (line 12)
23966 * ac_cv_file_FILE <1>: Files. (line 20)
23967 * ac_cv_func_chown_works: Particular Functions.
23968 (line 48)
23969 * ac_cv_func_closedir_void: Particular Functions.
23970 (line 58)
23971 * ac_cv_func_fnmatch_gnu: Particular Functions.
23972 (line 96)
23973 * ac_cv_func_fnmatch_works: Particular Functions.
23974 (line 83)
23975 * ac_cv_func_fnmatch_works <1>: Particular Functions.
23976 (line 484)
23977 * ac_cv_func_FUNCTION: Generic Functions. (line 15)
23978 * ac_cv_func_getgroups_works: Particular Functions.
23979 (line 144)
23980 * ac_cv_func_getpgrp_void: Particular Functions.
23981 (line 207)
23982 * ac_cv_func_lstat_dereferences_slashed_symlink: Particular Functions.
23983 (line 230)
23984 * ac_cv_func_lstat_empty_string_bug: Particular Functions.
23985 (line 384)
23986 * ac_cv_func_malloc_0_nonnull: Particular Functions.
23987 (line 249)
23988 * ac_cv_func_mbrtowc: Particular Functions.
23989 (line 283)
23990 * ac_cv_func_memcmp_working: Particular Functions.
23991 (line 294)
23992 * ac_cv_func_mmap_fixed_mapped: Particular Functions.
23993 (line 316)
23994 * ac_cv_func_obstack: Particular Functions.
23995 (line 328)
23996 * ac_cv_func_pow: Particular Functions.
23997 (line 432)
23998 * ac_cv_func_realloc_0_nonnull: Particular Functions.
23999 (line 338)
24000 * ac_cv_func_setpgrp_void: Particular Functions.
24001 (line 366)
24002 * ac_cv_func_stat_empty_string_bug: Particular Functions.
24003 (line 384)
24004 * ac_cv_func_strcoll_works: Particular Functions.
24005 (line 399)
24006 * ac_cv_func_strerror_r_char_p: Particular Functions.
24007 (line 409)
24008 * ac_cv_func_strnlen_working: Particular Functions.
24009 (line 454)
24010 * ac_cv_func_strtod: Particular Functions.
24011 (line 432)
24012 * ac_cv_func_strtold: Particular Functions.
24013 (line 444)
24014 * ac_cv_func_utime_null: Particular Functions.
24015 (line 465)
24016 * ac_cv_func_working_mktime: Particular Functions.
24017 (line 304)
24018 * ac_cv_have_decl_SYMBOL: Generic Declarations.
24019 (line 11)
24020 * ac_cv_have_decl_SYMBOL <1>: Generic Declarations.
24021 (line 34)
24022 * ac_cv_header_HEADER-FILE: Generic Headers. (line 13)
24023 * ac_cv_header_HEADER-FILE <1>: Generic Headers. (line 39)
24024 * ac_cv_header_stdbool_h: Particular Headers. (line 10)
24025 * ac_cv_header_stdbool_h <1>: Particular Headers. (line 130)
24026 * ac_cv_header_stdc: Particular Headers. (line 149)
24027 * ac_cv_header_sys_wait_h: Particular Headers. (line 159)
24028 * ac_cv_header_time: Obsolete Macros. (line 267)
24029 * ac_cv_lib_error_at_line: Particular Functions.
24030 (line 73)
24031 * ac_cv_lib_LIBRARY_FUNCTION: Libraries. (line 11)
24032 * ac_cv_member_AGGREGATE_MEMBER: Generic Structures. (line 11)
24033 * ac_cv_member_struct_stat_st_blocks: Particular Structures.
24034 (line 26)
24035 * ac_cv_path_install: Particular Programs. (line 51)
24036 * ac_cv_path_mkdir: Particular Programs. (line 88)
24037 * ac_cv_path_SED: Particular Programs. (line 229)
24038 * ac_cv_path_VARIABLE: Generic Programs. (line 108)
24039 * ac_cv_path_VARIABLE <1>: Generic Programs. (line 115)
24040 * ac_cv_path_VARIABLE <2>: Generic Programs. (line 123)
24041 * ac_cv_prog_AWK: Particular Programs. (line 14)
24042 * ac_cv_prog_c_openmp: Generic Compiler Characteristics.
24043 (line 63)
24044 * ac_cv_prog_cc_COMPILER_c_o: C Compiler. (line 123)
24045 * ac_cv_prog_cxx_openmp: Generic Compiler Characteristics.
24046 (line 63)
24047 * ac_cv_prog_EGREP: Particular Programs. (line 37)
24048 * ac_cv_prog_f77_c_o: Fortran Compiler. (line 75)
24049 * ac_cv_prog_f77_g: Fortran Compiler. (line 19)
24050 * ac_cv_prog_f77_openmp: Generic Compiler Characteristics.
24051 (line 63)
24052 * ac_cv_prog_f77_v: Fortran Compiler. (line 91)
24053 * ac_cv_prog_fc_c_o: Fortran Compiler. (line 75)
24054 * ac_cv_prog_fc_g: Fortran Compiler. (line 44)
24055 * ac_cv_prog_fc_openmp: Generic Compiler Characteristics.
24056 (line 63)
24057 * ac_cv_prog_fc_v: Fortran Compiler. (line 91)
24058 * ac_cv_prog_FGREP: Particular Programs. (line 44)
24059 * ac_cv_prog_GREP: Particular Programs. (line 28)
24060 * ac_cv_prog_LEX: Particular Programs. (line 112)
24061 * ac_cv_prog_VARIABLE: Generic Programs. (line 24)
24062 * ac_cv_prog_VARIABLE <1>: Generic Programs. (line 36)
24063 * ac_cv_prog_YACC: Particular Programs. (line 238)
24064 * ac_cv_search_FUNCTION: Libraries. (line 52)
24065 * ac_cv_search_getmntent: Particular Functions.
24066 (line 195)
24067 * ac_cv_sizeof_TYPE-OR-EXPR: Generic Compiler Characteristics.
24068 (line 8)
24069 * ac_cv_sys_posix_termios: System Services. (line 137)
24070 * ac_cv_type_getgroups: Particular Types. (line 14)
24071 * ac_cv_type_long_double: Particular Types. (line 58)
24072 * ac_cv_type_long_double_wider: Particular Types. (line 69)
24073 * ac_cv_type_long_long_int: Particular Types. (line 77)
24074 * ac_cv_type_mbstate_t: Particular Types. (line 87)
24075 * ac_cv_type_mode_t: Particular Types. (line 95)
24076 * ac_cv_type_off_t: Particular Types. (line 101)
24077 * ac_cv_type_pid_t: Particular Types. (line 107)
24078 * ac_cv_type_size_t: Particular Types. (line 113)
24079 * ac_cv_type_ssize_t: Particular Types. (line 119)
24080 * ac_cv_type_TYPE: Generic Types. (line 11)
24081 * ac_cv_type_uid_t: Particular Types. (line 125)
24082 * ac_cv_type_unsigned_long_long_int: Particular Types. (line 156)
24083
24084 
24085 File: autoconf.info, Node: Autoconf Macro Index, Next: M4 Macro Index, Prev: Cache Variable Index, Up: Indices
24086
24087 B.5 Autoconf Macro Index
24088 ========================
24089
24090 This is an alphabetical list of the Autoconf macros.
24091
24092 [index]
24093 * Menu:
24094
24095 * AC_ACT_IFELSE: AC_ACT_IFELSE vs AC_TRY_ACT.
24096 (line 6)
24097 * AC_AIX: Obsolete Macros. (line 20)
24098 * AC_ALLOCA: Obsolete Macros. (line 24)
24099 * AC_ARG_ARRAY: Obsolete Macros. (line 27)
24100 * AC_ARG_ENABLE: Package Options. (line 35)
24101 * AC_ARG_PROGRAM: Transforming Names. (line 11)
24102 * AC_ARG_VAR: Setting Output Variables.
24103 (line 80)
24104 * AC_ARG_WITH: External Software. (line 36)
24105 * AC_AUTOCONF_VERSION: Versioning. (line 21)
24106 * AC_BEFORE: Suggested Ordering. (line 28)
24107 * AC_C__GENERIC: C Compiler. (line 231)
24108 * AC_C_BACKSLASH_A: C Compiler. (line 160)
24109 * AC_C_BIGENDIAN: C Compiler. (line 168)
24110 * AC_C_CHAR_UNSIGNED: C Compiler. (line 274)
24111 * AC_C_CONST: C Compiler. (line 201)
24112 * AC_C_CROSS: Obsolete Macros. (line 30)
24113 * AC_C_FLEXIBLE_ARRAY_MEMBER: C Compiler. (line 298)
24114 * AC_C_INLINE: C Compiler. (line 269)
24115 * AC_C_LONG_DOUBLE: Obsolete Macros. (line 33)
24116 * AC_C_PROTOTYPES: C Compiler. (line 339)
24117 * AC_C_RESTRICT: C Compiler. (line 235)
24118 * AC_C_STRINGIZE: C Compiler. (line 288)
24119 * AC_C_TYPEOF: C Compiler. (line 332)
24120 * AC_C_VARARRAYS: C Compiler. (line 322)
24121 * AC_C_VOLATILE: C Compiler. (line 253)
24122 * AC_CACHE_CHECK: Caching Results. (line 29)
24123 * AC_CACHE_LOAD: Cache Checkpointing. (line 13)
24124 * AC_CACHE_SAVE: Cache Checkpointing. (line 17)
24125 * AC_CACHE_VAL: Caching Results. (line 15)
24126 * AC_CANONICAL_BUILD: Canonicalizing. (line 21)
24127 * AC_CANONICAL_HOST: Canonicalizing. (line 29)
24128 * AC_CANONICAL_SYSTEM: Obsolete Macros. (line 41)
24129 * AC_CANONICAL_TARGET: Canonicalizing. (line 36)
24130 * AC_CHAR_UNSIGNED: Obsolete Macros. (line 51)
24131 * AC_CHECK_ALIGNOF: Generic Compiler Characteristics.
24132 (line 30)
24133 * AC_CHECK_DECL: Generic Declarations.
24134 (line 11)
24135 * AC_CHECK_DECLS: Generic Declarations.
24136 (line 34)
24137 * AC_CHECK_DECLS_ONCE: Generic Declarations.
24138 (line 79)
24139 * AC_CHECK_FILE: Files. (line 12)
24140 * AC_CHECK_FILES: Files. (line 20)
24141 * AC_CHECK_FUNC: Generic Functions. (line 15)
24142 * AC_CHECK_FUNCS: Generic Functions. (line 27)
24143 * AC_CHECK_FUNCS_ONCE: Generic Functions. (line 38)
24144 * AC_CHECK_HEADER: Generic Headers. (line 13)
24145 * AC_CHECK_HEADER_STDBOOL: Particular Headers. (line 10)
24146 * AC_CHECK_HEADERS: Generic Headers. (line 39)
24147 * AC_CHECK_HEADERS_ONCE: Generic Headers. (line 56)
24148 * AC_CHECK_INCLUDES_DEFAULT: Default Includes. (line 93)
24149 * AC_CHECK_LIB: Libraries. (line 11)
24150 * AC_CHECK_MEMBER: Generic Structures. (line 11)
24151 * AC_CHECK_MEMBERS: Generic Structures. (line 29)
24152 * AC_CHECK_PROG: Generic Programs. (line 24)
24153 * AC_CHECK_PROGS: Generic Programs. (line 36)
24154 * AC_CHECK_SIZEOF: Generic Compiler Characteristics.
24155 (line 8)
24156 * AC_CHECK_TARGET_TOOL: Generic Programs. (line 48)
24157 * AC_CHECK_TARGET_TOOLS: Generic Programs. (line 79)
24158 * AC_CHECK_TOOL: Generic Programs. (line 64)
24159 * AC_CHECK_TOOLS: Generic Programs. (line 92)
24160 * AC_CHECK_TYPE: Generic Types. (line 11)
24161 * AC_CHECK_TYPE <1>: Obsolete Macros. (line 54)
24162 * AC_CHECK_TYPES: Generic Types. (line 27)
24163 * AC_CHECKING: Obsolete Macros. (line 101)
24164 * AC_COMPILE_CHECK: Obsolete Macros. (line 109)
24165 * AC_COMPILE_IFELSE: Running the Compiler.
24166 (line 12)
24167 * AC_COMPUTE_INT: Generic Compiler Characteristics.
24168 (line 42)
24169 * AC_CONFIG_AUX_DIR: Input. (line 76)
24170 * AC_CONFIG_COMMANDS: Configuration Commands.
24171 (line 13)
24172 * AC_CONFIG_COMMANDS_POST: Configuration Commands.
24173 (line 42)
24174 * AC_CONFIG_COMMANDS_PRE: Configuration Commands.
24175 (line 36)
24176 * AC_CONFIG_FILES: Configuration Files. (line 9)
24177 * AC_CONFIG_HEADERS: Configuration Headers.
24178 (line 37)
24179 * AC_CONFIG_ITEMS: Configuration Actions.
24180 (line 12)
24181 * AC_CONFIG_LIBOBJ_DIR: Generic Functions. (line 97)
24182 * AC_CONFIG_LINKS: Configuration Links. (line 12)
24183 * AC_CONFIG_MACRO_DIR: Input. (line 24)
24184 * AC_CONFIG_MACRO_DIR_TRACE: Input. (line 24)
24185 * AC_CONFIG_MACRO_DIRS: Input. (line 24)
24186 * AC_CONFIG_SRCDIR: Input. (line 9)
24187 * AC_CONFIG_SUBDIRS: Subdirectories. (line 12)
24188 * AC_CONFIG_TESTDIR: Making testsuite Scripts.
24189 (line 27)
24190 * AC_CONST: Obsolete Macros. (line 117)
24191 * AC_COPYRIGHT: Notices. (line 10)
24192 * AC_CROSS_CHECK: Obsolete Macros. (line 120)
24193 * AC_CYGWIN: Obsolete Macros. (line 124)
24194 * AC_DATAROOTDIR_CHECKED: Changed Directory Variables.
24195 (line 58)
24196 * AC_DECL_SYS_SIGLIST: Obsolete Macros. (line 141)
24197 * AC_DECL_YYTEXT: Obsolete Macros. (line 154)
24198 * AC_DEFINE: Defining Symbols. (line 33)
24199 * AC_DEFINE_UNQUOTED: Defining Symbols. (line 75)
24200 * AC_DEFUN: Macro Definitions. (line 7)
24201 * AC_DEFUN_ONCE: One-Shot Macros. (line 14)
24202 * AC_DIAGNOSE: Obsolete Macros. (line 158)
24203 * AC_DIR_HEADER: Obsolete Macros. (line 161)
24204 * AC_DISABLE_OPTION_CHECKING: Option Checking. (line 28)
24205 * AC_DYNIX_SEQ: Obsolete Macros. (line 173)
24206 * AC_EGREP_CPP: Running the Preprocessor.
24207 (line 83)
24208 * AC_EGREP_HEADER: Running the Preprocessor.
24209 (line 73)
24210 * AC_EMXOS2: Obsolete Macros. (line 186)
24211 * AC_ENABLE: Obsolete Macros. (line 192)
24212 * AC_ERLANG_CHECK_LIB: Erlang Libraries. (line 36)
24213 * AC_ERLANG_NEED_ERL: Erlang Compiler and Interpreter.
24214 (line 41)
24215 * AC_ERLANG_NEED_ERLC: Erlang Compiler and Interpreter.
24216 (line 24)
24217 * AC_ERLANG_PATH_ERL: Erlang Compiler and Interpreter.
24218 (line 29)
24219 * AC_ERLANG_PATH_ERLC: Erlang Compiler and Interpreter.
24220 (line 10)
24221 * AC_ERLANG_SUBST_ERTS_VER: Erlang Libraries. (line 12)
24222 * AC_ERLANG_SUBST_INSTALL_LIB_DIR: Installation Directory Variables.
24223 (line 210)
24224 * AC_ERLANG_SUBST_INSTALL_LIB_DIR <1>: Erlang Libraries. (line 86)
24225 * AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR: Installation Directory Variables.
24226 (line 215)
24227 * AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR <1>: Erlang Libraries. (line 94)
24228 * AC_ERLANG_SUBST_LIB_DIR: Erlang Libraries. (line 28)
24229 * AC_ERLANG_SUBST_ROOT_DIR: Erlang Libraries. (line 22)
24230 * AC_ERROR: Obsolete Macros. (line 196)
24231 * AC_EXEEXT: Obsolete Macros. (line 181)
24232 * AC_F77_CRAY_POINTERS: Fortran Compiler. (line 531)
24233 * AC_F77_DUMMY_MAIN: Fortran Compiler. (line 129)
24234 * AC_F77_FUNC: Fortran Compiler. (line 262)
24235 * AC_F77_IMPLICIT_NONE: Fortran Compiler. (line 428)
24236 * AC_F77_LIBRARY_LDFLAGS: Fortran Compiler. (line 91)
24237 * AC_F77_MAIN: Fortran Compiler. (line 174)
24238 * AC_F77_WRAPPERS: Fortran Compiler. (line 199)
24239 * AC_FATAL: Obsolete Macros. (line 199)
24240 * AC_FC_CHECK_BOUNDS: Fortran Compiler. (line 413)
24241 * AC_FC_CRAY_POINTERS: Fortran Compiler. (line 531)
24242 * AC_FC_DUMMY_MAIN: Fortran Compiler. (line 129)
24243 * AC_FC_FIXEDFORM: Fortran Compiler. (line 373)
24244 * AC_FC_FREEFORM: Fortran Compiler. (line 348)
24245 * AC_FC_FUNC: Fortran Compiler. (line 262)
24246 * AC_FC_IMPLICIT_NONE: Fortran Compiler. (line 428)
24247 * AC_FC_LIBRARY_LDFLAGS: Fortran Compiler. (line 91)
24248 * AC_FC_LINE_LENGTH: Fortran Compiler. (line 395)
24249 * AC_FC_MAIN: Fortran Compiler. (line 174)
24250 * AC_FC_MODULE_EXTENSION: Fortran Compiler. (line 440)
24251 * AC_FC_MODULE_FLAG: Fortran Compiler. (line 468)
24252 * AC_FC_MODULE_OUTPUT_FLAG: Fortran Compiler. (line 505)
24253 * AC_FC_PP_DEFINE: Fortran Compiler. (line 332)
24254 * AC_FC_PP_SRCEXT: Fortran Compiler. (line 275)
24255 * AC_FC_SRCEXT: Fortran Compiler. (line 275)
24256 * AC_FC_WRAPPERS: Fortran Compiler. (line 199)
24257 * AC_FIND_X: Obsolete Macros. (line 202)
24258 * AC_FIND_XTRA: Obsolete Macros. (line 205)
24259 * AC_FOREACH: Obsolete Macros. (line 208)
24260 * AC_FUNC_ALLOCA: Particular Functions.
24261 (line 10)
24262 * AC_FUNC_CHECK: Obsolete Macros. (line 211)
24263 * AC_FUNC_CHOWN: Particular Functions.
24264 (line 48)
24265 * AC_FUNC_CLOSEDIR_VOID: Particular Functions.
24266 (line 58)
24267 * AC_FUNC_ERROR_AT_LINE: Particular Functions.
24268 (line 73)
24269 * AC_FUNC_FNMATCH: Particular Functions.
24270 (line 83)
24271 * AC_FUNC_FNMATCH_GNU: Particular Functions.
24272 (line 96)
24273 * AC_FUNC_FORK: Particular Functions.
24274 (line 107)
24275 * AC_FUNC_FSEEKO: Particular Functions.
24276 (line 131)
24277 * AC_FUNC_GETGROUPS: Particular Functions.
24278 (line 144)
24279 * AC_FUNC_GETLOADAVG: Particular Functions.
24280 (line 161)
24281 * AC_FUNC_GETMNTENT: Particular Functions.
24282 (line 195)
24283 * AC_FUNC_GETPGRP: Particular Functions.
24284 (line 207)
24285 * AC_FUNC_LSTAT: Particular Functions.
24286 (line 384)
24287 * AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK: Particular Functions.
24288 (line 230)
24289 * AC_FUNC_MALLOC: Particular Functions.
24290 (line 249)
24291 * AC_FUNC_MBRTOWC: Particular Functions.
24292 (line 283)
24293 * AC_FUNC_MEMCMP: Particular Functions.
24294 (line 294)
24295 * AC_FUNC_MKTIME: Particular Functions.
24296 (line 304)
24297 * AC_FUNC_MMAP: Particular Functions.
24298 (line 316)
24299 * AC_FUNC_OBSTACK: Particular Functions.
24300 (line 328)
24301 * AC_FUNC_REALLOC: Particular Functions.
24302 (line 338)
24303 * AC_FUNC_SELECT_ARGTYPES: Particular Functions.
24304 (line 355)
24305 * AC_FUNC_SETPGRP: Particular Functions.
24306 (line 366)
24307 * AC_FUNC_SETVBUF_REVERSED: Obsolete Macros. (line 214)
24308 * AC_FUNC_STAT: Particular Functions.
24309 (line 384)
24310 * AC_FUNC_STRCOLL: Particular Functions.
24311 (line 399)
24312 * AC_FUNC_STRERROR_R: Particular Functions.
24313 (line 409)
24314 * AC_FUNC_STRFTIME: Particular Functions.
24315 (line 425)
24316 * AC_FUNC_STRNLEN: Particular Functions.
24317 (line 454)
24318 * AC_FUNC_STRTOD: Particular Functions.
24319 (line 432)
24320 * AC_FUNC_STRTOLD: Particular Functions.
24321 (line 444)
24322 * AC_FUNC_UTIME_NULL: Particular Functions.
24323 (line 465)
24324 * AC_FUNC_VPRINTF: Particular Functions.
24325 (line 475)
24326 * AC_FUNC_WAIT3: Obsolete Macros. (line 222)
24327 * AC_GCC_TRADITIONAL: Obsolete Macros. (line 230)
24328 * AC_GETGROUPS_T: Obsolete Macros. (line 234)
24329 * AC_GETLOADAVG: Obsolete Macros. (line 237)
24330 * AC_GNU_SOURCE: Obsolete Macros. (line 240)
24331 * AC_HAVE_FUNCS: Obsolete Macros. (line 244)
24332 * AC_HAVE_HEADERS: Obsolete Macros. (line 247)
24333 * AC_HAVE_LIBRARY: Obsolete Macros. (line 251)
24334 * AC_HAVE_POUNDBANG: Obsolete Macros. (line 258)
24335 * AC_HEADER_ASSERT: Particular Headers. (line 23)
24336 * AC_HEADER_CHECK: Obsolete Macros. (line 261)
24337 * AC_HEADER_DIRENT: Particular Headers. (line 28)
24338 * AC_HEADER_EGREP: Obsolete Macros. (line 264)
24339 * AC_HEADER_MAJOR: Particular Headers. (line 71)
24340 * AC_HEADER_RESOLV: Particular Headers. (line 102)
24341 * AC_HEADER_STAT: Particular Headers. (line 121)
24342 * AC_HEADER_STDBOOL: Particular Headers. (line 130)
24343 * AC_HEADER_STDC: Particular Headers. (line 149)
24344 * AC_HEADER_SYS_WAIT: Particular Headers. (line 159)
24345 * AC_HEADER_TIME: Obsolete Macros. (line 267)
24346 * AC_HEADER_TIOCGWINSZ: Particular Headers. (line 199)
24347 * AC_HELP_STRING: Obsolete Macros. (line 278)
24348 * AC_INCLUDES_DEFAULT: Default Includes. (line 40)
24349 * AC_INIT: Initializing configure.
24350 (line 14)
24351 * AC_INIT <1>: Obsolete Macros. (line 281)
24352 * AC_INLINE: Obsolete Macros. (line 289)
24353 * AC_INT_16_BITS: Obsolete Macros. (line 292)
24354 * AC_IRIX_SUN: Obsolete Macros. (line 296)
24355 * AC_ISC_POSIX: Obsolete Macros. (line 312)
24356 * AC_LANG: Language Choice. (line 14)
24357 * AC_LANG_ASSERT: Language Choice. (line 83)
24358 * AC_LANG_C: Obsolete Macros. (line 319)
24359 * AC_LANG_CALL: Generating Sources. (line 145)
24360 * AC_LANG_CONFTEST: Generating Sources. (line 12)
24361 * AC_LANG_CPLUSPLUS: Obsolete Macros. (line 322)
24362 * AC_LANG_DEFINES_PROVIDED: Generating Sources. (line 34)
24363 * AC_LANG_FORTRAN77: Obsolete Macros. (line 325)
24364 * AC_LANG_FUNC_LINK_TRY: Generating Sources. (line 157)
24365 * AC_LANG_POP: Language Choice. (line 70)
24366 * AC_LANG_PROGRAM: Generating Sources. (line 81)
24367 * AC_LANG_PUSH: Language Choice. (line 65)
24368 * AC_LANG_RESTORE: Obsolete Macros. (line 328)
24369 * AC_LANG_SAVE: Obsolete Macros. (line 334)
24370 * AC_LANG_SOURCE: Generating Sources. (line 43)
24371 * AC_LANG_WERROR: Generic Compiler Characteristics.
24372 (line 53)
24373 * AC_LIBOBJ: Generic Functions. (line 56)
24374 * AC_LIBSOURCE: Generic Functions. (line 65)
24375 * AC_LIBSOURCES: Generic Functions. (line 89)
24376 * AC_LINK_FILES: Obsolete Macros. (line 339)
24377 * AC_LINK_IFELSE: Running the Linker. (line 24)
24378 * AC_LN_S: Obsolete Macros. (line 351)
24379 * AC_LONG_64_BITS: Obsolete Macros. (line 354)
24380 * AC_LONG_DOUBLE: Obsolete Macros. (line 359)
24381 * AC_LONG_FILE_NAMES: Obsolete Macros. (line 367)
24382 * AC_MAJOR_HEADER: Obsolete Macros. (line 372)
24383 * AC_MEMORY_H: Obsolete Macros. (line 375)
24384 * AC_MINGW32: Obsolete Macros. (line 381)
24385 * AC_MINIX: Obsolete Macros. (line 387)
24386 * AC_MINUS_C_MINUS_O: Obsolete Macros. (line 391)
24387 * AC_MMAP: Obsolete Macros. (line 394)
24388 * AC_MODE_T: Obsolete Macros. (line 397)
24389 * AC_MSG_CHECKING: Printing Messages. (line 24)
24390 * AC_MSG_ERROR: Printing Messages. (line 55)
24391 * AC_MSG_FAILURE: Printing Messages. (line 65)
24392 * AC_MSG_NOTICE: Printing Messages. (line 45)
24393 * AC_MSG_RESULT: Printing Messages. (line 35)
24394 * AC_MSG_WARN: Printing Messages. (line 71)
24395 * AC_OBJEXT: Obsolete Macros. (line 400)
24396 * AC_OBSOLETE: Obsolete Macros. (line 406)
24397 * AC_OFF_T: Obsolete Macros. (line 421)
24398 * AC_OPENMP: Generic Compiler Characteristics.
24399 (line 63)
24400 * AC_OUTPUT: Output. (line 13)
24401 * AC_OUTPUT <1>: Obsolete Macros. (line 424)
24402 * AC_OUTPUT_COMMANDS: Obsolete Macros. (line 436)
24403 * AC_PACKAGE_BUGREPORT: Initializing configure.
24404 (line 117)
24405 * AC_PACKAGE_NAME: Initializing configure.
24406 (line 105)
24407 * AC_PACKAGE_STRING: Initializing configure.
24408 (line 114)
24409 * AC_PACKAGE_TARNAME: Initializing configure.
24410 (line 108)
24411 * AC_PACKAGE_URL: Initializing configure.
24412 (line 121)
24413 * AC_PACKAGE_VERSION: Initializing configure.
24414 (line 111)
24415 * AC_PATH_PROG: Generic Programs. (line 108)
24416 * AC_PATH_PROGS: Generic Programs. (line 115)
24417 * AC_PATH_PROGS_FEATURE_CHECK: Generic Programs. (line 123)
24418 * AC_PATH_TARGET_TOOL: Generic Programs. (line 158)
24419 * AC_PATH_TOOL: Generic Programs. (line 163)
24420 * AC_PATH_X: System Services. (line 10)
24421 * AC_PATH_XTRA: System Services. (line 30)
24422 * AC_PID_T: Obsolete Macros. (line 468)
24423 * AC_PREFIX: Obsolete Macros. (line 471)
24424 * AC_PREFIX_DEFAULT: Default Prefix. (line 16)
24425 * AC_PREFIX_PROGRAM: Default Prefix. (line 25)
24426 * AC_PREPROC_IFELSE: Running the Preprocessor.
24427 (line 20)
24428 * AC_PREREQ: Versioning. (line 11)
24429 * AC_PRESERVE_HELP_ORDER: Help Formatting. (line 20)
24430 * AC_PROG_AR: Particular Programs. (line 10)
24431 * AC_PROG_AWK: Particular Programs. (line 14)
24432 * AC_PROG_CC: C Compiler. (line 52)
24433 * AC_PROG_CC_C_O: C Compiler. (line 123)
24434 * AC_PROG_CC_C89: Obsolete Macros. (line 474)
24435 * AC_PROG_CC_C99: Obsolete Macros. (line 477)
24436 * AC_PROG_CC_STDC: Obsolete Macros. (line 480)
24437 * AC_PROG_CPP: C Compiler. (line 134)
24438 * AC_PROG_CPP_WERROR: C Compiler. (line 149)
24439 * AC_PROG_CXX: C++ Compiler. (line 7)
24440 * AC_PROG_CXX_C_O: C++ Compiler. (line 57)
24441 * AC_PROG_CXXCPP: C++ Compiler. (line 40)
24442 * AC_PROG_EGREP: Particular Programs. (line 37)
24443 * AC_PROG_F77: Fortran Compiler. (line 19)
24444 * AC_PROG_F77_C_O: Fortran Compiler. (line 75)
24445 * AC_PROG_FC: Fortran Compiler. (line 44)
24446 * AC_PROG_FC_C_O: Fortran Compiler. (line 75)
24447 * AC_PROG_FGREP: Particular Programs. (line 44)
24448 * AC_PROG_GCC_TRADITIONAL: Obsolete Macros. (line 483)
24449 * AC_PROG_GREP: Particular Programs. (line 28)
24450 * AC_PROG_INSTALL: Particular Programs. (line 51)
24451 * AC_PROG_LEX: Particular Programs. (line 112)
24452 * AC_PROG_LN_S: Particular Programs. (line 206)
24453 * AC_PROG_MAKE_SET: Output. (line 45)
24454 * AC_PROG_MKDIR_P: Particular Programs. (line 88)
24455 * AC_PROG_OBJC: Objective C Compiler.
24456 (line 7)
24457 * AC_PROG_OBJCPP: Objective C Compiler.
24458 (line 27)
24459 * AC_PROG_OBJCXX: Objective C++ Compiler.
24460 (line 7)
24461 * AC_PROG_OBJCXXCPP: Objective C++ Compiler.
24462 (line 27)
24463 * AC_PROG_RANLIB: Particular Programs. (line 225)
24464 * AC_PROG_SED: Particular Programs. (line 229)
24465 * AC_PROG_YACC: Particular Programs. (line 238)
24466 * AC_PROGRAM_CHECK: Obsolete Macros. (line 497)
24467 * AC_PROGRAM_EGREP: Obsolete Macros. (line 500)
24468 * AC_PROGRAM_PATH: Obsolete Macros. (line 503)
24469 * AC_PROGRAMS_CHECK: Obsolete Macros. (line 491)
24470 * AC_PROGRAMS_PATH: Obsolete Macros. (line 494)
24471 * AC_REMOTE_TAPE: Obsolete Macros. (line 506)
24472 * AC_REPLACE_FNMATCH: Particular Functions.
24473 (line 484)
24474 * AC_REPLACE_FUNCS: Generic Functions. (line 117)
24475 * AC_REQUIRE: Prerequisite Macros. (line 17)
24476 * AC_REQUIRE_AUX_FILE: Input. (line 87)
24477 * AC_REQUIRE_CPP: Language Choice. (line 98)
24478 * AC_RESTARTABLE_SYSCALLS: Obsolete Macros. (line 509)
24479 * AC_RETSIGTYPE: Obsolete Macros. (line 517)
24480 * AC_REVISION: Notices. (line 18)
24481 * AC_RSH: Obsolete Macros. (line 521)
24482 * AC_RUN_IFELSE: Runtime. (line 20)
24483 * AC_SCO_INTL: Obsolete Macros. (line 524)
24484 * AC_SEARCH_LIBS: Libraries. (line 52)
24485 * AC_SET_MAKE: Obsolete Macros. (line 533)
24486 * AC_SETVBUF_REVERSED: Obsolete Macros. (line 528)
24487 * AC_SIZE_T: Obsolete Macros. (line 539)
24488 * AC_SIZEOF_TYPE: Obsolete Macros. (line 536)
24489 * AC_ST_BLKSIZE: Obsolete Macros. (line 571)
24490 * AC_ST_BLOCKS: Obsolete Macros. (line 574)
24491 * AC_ST_RDEV: Obsolete Macros. (line 577)
24492 * AC_STAT_MACROS_BROKEN: Obsolete Macros. (line 542)
24493 * AC_STDC_HEADERS: Obsolete Macros. (line 545)
24494 * AC_STRCOLL: Obsolete Macros. (line 550)
24495 * AC_STRUCT_DIRENT_D_INO: Particular Structures.
24496 (line 9)
24497 * AC_STRUCT_DIRENT_D_TYPE: Particular Structures.
24498 (line 21)
24499 * AC_STRUCT_ST_BLKSIZE: Obsolete Macros. (line 553)
24500 * AC_STRUCT_ST_BLOCKS: Particular Structures.
24501 (line 26)
24502 * AC_STRUCT_ST_RDEV: Obsolete Macros. (line 562)
24503 * AC_STRUCT_TIMEZONE: Particular Structures.
24504 (line 43)
24505 * AC_STRUCT_TM: Particular Structures.
24506 (line 35)
24507 * AC_SUBST: Setting Output Variables.
24508 (line 13)
24509 * AC_SUBST_FILE: Setting Output Variables.
24510 (line 39)
24511 * AC_SYS_INTERPRETER: System Services. (line 41)
24512 * AC_SYS_LARGEFILE: System Services. (line 48)
24513 * AC_SYS_LONG_FILE_NAMES: System Services. (line 133)
24514 * AC_SYS_POSIX_TERMIOS: System Services. (line 137)
24515 * AC_SYS_RESTARTABLE_SYSCALLS: Obsolete Macros. (line 580)
24516 * AC_SYS_SIGLIST_DECLARED: Obsolete Macros. (line 595)
24517 * AC_SYS_YEAR2038: System Services. (line 143)
24518 * AC_SYS_YEAR2038_RECOMMENDED: System Services. (line 149)
24519 * AC_TEST_CPP: Obsolete Macros. (line 600)
24520 * AC_TEST_PROGRAM: Obsolete Macros. (line 604)
24521 * AC_TIME_WITH_SYS_TIME: Obsolete Macros. (line 611)
24522 * AC_TIMEZONE: Obsolete Macros. (line 608)
24523 * AC_TRY_ACT: AC_ACT_IFELSE vs AC_TRY_ACT.
24524 (line 6)
24525 * AC_TRY_COMPILE: Obsolete Macros. (line 617)
24526 * AC_TRY_CPP: Obsolete Macros. (line 636)
24527 * AC_TRY_LINK: Obsolete Macros. (line 649)
24528 * AC_TRY_LINK_FUNC: Obsolete Macros. (line 678)
24529 * AC_TRY_RUN: Obsolete Macros. (line 685)
24530 * AC_TYPE_GETGROUPS: Particular Types. (line 14)
24531 * AC_TYPE_INT16_T: Particular Types. (line 39)
24532 * AC_TYPE_INT32_T: Particular Types. (line 42)
24533 * AC_TYPE_INT64_T: Particular Types. (line 45)
24534 * AC_TYPE_INT8_T: Particular Types. (line 21)
24535 * AC_TYPE_INTMAX_T: Particular Types. (line 48)
24536 * AC_TYPE_INTPTR_T: Particular Types. (line 53)
24537 * AC_TYPE_LONG_DOUBLE: Particular Types. (line 58)
24538 * AC_TYPE_LONG_DOUBLE_WIDER: Particular Types. (line 69)
24539 * AC_TYPE_LONG_LONG_INT: Particular Types. (line 77)
24540 * AC_TYPE_MBSTATE_T: Particular Types. (line 87)
24541 * AC_TYPE_MODE_T: Particular Types. (line 95)
24542 * AC_TYPE_OFF_T: Particular Types. (line 101)
24543 * AC_TYPE_PID_T: Particular Types. (line 107)
24544 * AC_TYPE_SIGNAL: Obsolete Macros. (line 696)
24545 * AC_TYPE_SIZE_T: Particular Types. (line 113)
24546 * AC_TYPE_SSIZE_T: Particular Types. (line 119)
24547 * AC_TYPE_UID_T: Particular Types. (line 125)
24548 * AC_TYPE_UINT16_T: Particular Types. (line 137)
24549 * AC_TYPE_UINT32_T: Particular Types. (line 140)
24550 * AC_TYPE_UINT64_T: Particular Types. (line 143)
24551 * AC_TYPE_UINT8_T: Particular Types. (line 131)
24552 * AC_TYPE_UINTMAX_T: Particular Types. (line 146)
24553 * AC_TYPE_UINTPTR_T: Particular Types. (line 151)
24554 * AC_TYPE_UNSIGNED_LONG_LONG_INT: Particular Types. (line 156)
24555 * AC_UID_T: Obsolete Macros. (line 703)
24556 * AC_UNISTD_H: Obsolete Macros. (line 706)
24557 * AC_USE_SYSTEM_EXTENSIONS: C and POSIX Variants.
24558 (line 11)
24559 * AC_USG: Obsolete Macros. (line 712)
24560 * AC_UTIME_NULL: Obsolete Macros. (line 723)
24561 * AC_VALIDATE_CACHED_SYSTEM_TUPLE: Obsolete Macros. (line 726)
24562 * AC_VERBOSE: Obsolete Macros. (line 731)
24563 * AC_VFORK: Obsolete Macros. (line 734)
24564 * AC_VPRINTF: Obsolete Macros. (line 737)
24565 * AC_WAIT3: Obsolete Macros. (line 740)
24566 * AC_WARN: Obsolete Macros. (line 745)
24567 * AC_WARNING: Obsolete Macros. (line 748)
24568 * AC_WITH: Obsolete Macros. (line 751)
24569 * AC_WORDS_BIGENDIAN: Obsolete Macros. (line 755)
24570 * AC_XENIX_DIR: Obsolete Macros. (line 758)
24571 * AC_YYTEXT_POINTER: Obsolete Macros. (line 764)
24572 * AH_BOTTOM: Autoheader Macros. (line 46)
24573 * AH_HEADER: Configuration Headers.
24574 (line 58)
24575 * AH_TEMPLATE: Autoheader Macros. (line 19)
24576 * AH_TOP: Autoheader Macros. (line 43)
24577 * AH_VERBATIM: Autoheader Macros. (line 36)
24578 * AU_ALIAS: Obsoleting Macros. (line 49)
24579 * AU_DEFUN: Obsoleting Macros. (line 18)
24580
24581 
24582 File: autoconf.info, Node: M4 Macro Index, Next: Autotest Macro Index, Prev: Autoconf Macro Index, Up: Indices
24583
24584 B.6 M4 Macro Index
24585 ==================
24586
24587 This is an alphabetical list of the M4, M4sugar, and M4sh macros.
24588
24589 [index]
24590 * Menu:
24591
24592 * __file__: Redefined M4 Macros. (line 41)
24593 * __line__: Redefined M4 Macros. (line 41)
24594 * __oline__: Redefined M4 Macros. (line 45)
24595 * AS_BOURNE_COMPATIBLE: Initialization Macros.
24596 (line 7)
24597 * AS_BOX: Common Shell Constructs.
24598 (line 10)
24599 * AS_CASE: Common Shell Constructs.
24600 (line 19)
24601 * AS_DIRNAME: Common Shell Constructs.
24602 (line 31)
24603 * AS_ECHO: Common Shell Constructs.
24604 (line 41)
24605 * AS_ECHO_N: Common Shell Constructs.
24606 (line 59)
24607 * AS_ESCAPE: Common Shell Constructs.
24608 (line 62)
24609 * AS_EXECUTABLE_P: Common Shell Constructs.
24610 (line 102)
24611 * AS_EXIT: Common Shell Constructs.
24612 (line 107)
24613 * AS_HELP_STRING: Pretty Help Strings. (line 15)
24614 * AS_IF: Common Shell Constructs.
24615 (line 113)
24616 * AS_INIT: Initialization Macros.
24617 (line 14)
24618 * AS_INIT_GENERATED: Initialization Macros.
24619 (line 26)
24620 * AS_LINENO_PREPARE: Initialization Macros.
24621 (line 67)
24622 * AS_LITERAL_IF: Polymorphic Variables.
24623 (line 21)
24624 * AS_LITERAL_WORD_IF: Polymorphic Variables.
24625 (line 21)
24626 * AS_ME_PREPARE: Initialization Macros.
24627 (line 72)
24628 * AS_MESSAGE_FD: File Descriptor Macros.
24629 (line 17)
24630 * AS_MESSAGE_LOG_FD: File Descriptor Macros.
24631 (line 29)
24632 * AS_MKDIR_P: Common Shell Constructs.
24633 (line 131)
24634 * AS_ORIGINAL_STDIN_FD: File Descriptor Macros.
24635 (line 39)
24636 * AS_SET_CATFILE: Common Shell Constructs.
24637 (line 166)
24638 * AS_SET_STATUS: Common Shell Constructs.
24639 (line 138)
24640 * AS_SHELL_SANITIZE: Initialization Macros.
24641 (line 105)
24642 * AS_TMPDIR: Initialization Macros.
24643 (line 77)
24644 * AS_TR_CPP: Common Shell Constructs.
24645 (line 146)
24646 * AS_TR_SH: Common Shell Constructs.
24647 (line 155)
24648 * AS_UNSET: Common Shell Constructs.
24649 (line 170)
24650 * AS_VAR_APPEND: Polymorphic Variables.
24651 (line 62)
24652 * AS_VAR_ARITH: Polymorphic Variables.
24653 (line 83)
24654 * AS_VAR_COPY: Polymorphic Variables.
24655 (line 102)
24656 * AS_VAR_IF: Polymorphic Variables.
24657 (line 121)
24658 * AS_VAR_POPDEF: Polymorphic Variables.
24659 (line 130)
24660 * AS_VAR_PUSHDEF: Polymorphic Variables.
24661 (line 130)
24662 * AS_VAR_SET: Polymorphic Variables.
24663 (line 172)
24664 * AS_VAR_SET_IF: Polymorphic Variables.
24665 (line 182)
24666 * AS_VAR_TEST_SET: Polymorphic Variables.
24667 (line 187)
24668 * AS_VERSION_COMPARE: Common Shell Constructs.
24669 (line 176)
24670 * dnl: Redefined M4 Macros. (line 52)
24671 * m4_append: Text processing Macros.
24672 (line 16)
24673 * m4_append_uniq: Text processing Macros.
24674 (line 16)
24675 * m4_append_uniq_w: Text processing Macros.
24676 (line 69)
24677 * m4_apply: Evaluation Macros. (line 10)
24678 * m4_argn: Looping constructs. (line 29)
24679 * m4_assert: Diagnostic Macros. (line 11)
24680 * m4_bmatch: Conditional constructs.
24681 (line 11)
24682 * m4_bpatsubst: Redefined M4 Macros. (line 55)
24683 * m4_bpatsubsts: Conditional constructs.
24684 (line 24)
24685 * m4_bregexp: Redefined M4 Macros. (line 67)
24686 * m4_builtin: Redefined M4 Macros. (line 6)
24687 * m4_car: Looping constructs. (line 35)
24688 * m4_case: Conditional constructs.
24689 (line 45)
24690 * m4_cdr: Looping constructs. (line 41)
24691 * m4_changecom: Redefined M4 Macros. (line 6)
24692 * m4_changequote: Redefined M4 Macros. (line 6)
24693 * m4_chomp: Text processing Macros.
24694 (line 80)
24695 * m4_chomp_all: Text processing Macros.
24696 (line 80)
24697 * m4_cleardivert: Diversion support. (line 116)
24698 * m4_cmp: Number processing Macros.
24699 (line 22)
24700 * m4_combine: Text processing Macros.
24701 (line 88)
24702 * m4_cond: Conditional constructs.
24703 (line 54)
24704 * m4_copy: Redefined M4 Macros. (line 82)
24705 * m4_copy_force: Redefined M4 Macros. (line 82)
24706 * m4_count: Evaluation Macros. (line 26)
24707 * m4_curry: Evaluation Macros. (line 29)
24708 * m4_debugfile: Redefined M4 Macros. (line 6)
24709 * m4_debugmode: Redefined M4 Macros. (line 6)
24710 * m4_decr: Redefined M4 Macros. (line 6)
24711 * m4_default: Conditional constructs.
24712 (line 85)
24713 * m4_default_nblank: Conditional constructs.
24714 (line 85)
24715 * m4_default_nblank_quoted: Conditional constructs.
24716 (line 85)
24717 * m4_default_quoted: Conditional constructs.
24718 (line 85)
24719 * m4_define: Redefined M4 Macros. (line 6)
24720 * m4_define_default: Conditional constructs.
24721 (line 134)
24722 * m4_defn: Redefined M4 Macros. (line 101)
24723 * m4_divert: Redefined M4 Macros. (line 109)
24724 * m4_divert_once: Diversion support. (line 119)
24725 * m4_divert_pop: Diversion support. (line 124)
24726 * m4_divert_push: Diversion support. (line 130)
24727 * m4_divert_text: Diversion support. (line 136)
24728 * m4_divnum: Redefined M4 Macros. (line 6)
24729 * m4_do: Evaluation Macros. (line 44)
24730 * m4_dquote: Evaluation Macros. (line 64)
24731 * m4_dquote_elt: Evaluation Macros. (line 69)
24732 * m4_dumpdef: Redefined M4 Macros. (line 121)
24733 * m4_dumpdefs: Redefined M4 Macros. (line 121)
24734 * m4_echo: Evaluation Macros. (line 74)
24735 * m4_errprint: Redefined M4 Macros. (line 6)
24736 * m4_errprintn: Diagnostic Macros. (line 16)
24737 * m4_escape: Text processing Macros.
24738 (line 108)
24739 * m4_esyscmd: Redefined M4 Macros. (line 6)
24740 * m4_esyscmd_s: Redefined M4 Macros. (line 138)
24741 * m4_eval: Redefined M4 Macros. (line 6)
24742 * m4_exit: Redefined M4 Macros. (line 144)
24743 * m4_expand: Evaluation Macros. (line 78)
24744 * m4_fatal: Diagnostic Macros. (line 20)
24745 * m4_flatten: Text processing Macros.
24746 (line 113)
24747 * m4_for: Looping constructs. (line 59)
24748 * m4_foreach: Looping constructs. (line 69)
24749 * m4_foreach_w: Looping constructs. (line 83)
24750 * m4_format: Redefined M4 Macros. (line 6)
24751 * m4_if: Redefined M4 Macros. (line 150)
24752 * m4_ifblank: Conditional constructs.
24753 (line 139)
24754 * m4_ifdef: Redefined M4 Macros. (line 6)
24755 * m4_ifnblank: Conditional constructs.
24756 (line 139)
24757 * m4_ifndef: Conditional constructs.
24758 (line 147)
24759 * m4_ifset: Conditional constructs.
24760 (line 151)
24761 * m4_ifval: Conditional constructs.
24762 (line 157)
24763 * m4_ifvaln: Conditional constructs.
24764 (line 162)
24765 * m4_ignore: Evaluation Macros. (line 128)
24766 * m4_include: Redefined M4 Macros. (line 157)
24767 * m4_incr: Redefined M4 Macros. (line 6)
24768 * m4_index: Redefined M4 Macros. (line 6)
24769 * m4_indir: Redefined M4 Macros. (line 6)
24770 * m4_init: Diversion support. (line 161)
24771 * m4_join: Text processing Macros.
24772 (line 119)
24773 * m4_joinall: Text processing Macros.
24774 (line 119)
24775 * m4_len: Redefined M4 Macros. (line 6)
24776 * m4_list_cmp: Number processing Macros.
24777 (line 27)
24778 * m4_location: Diagnostic Macros. (line 24)
24779 * m4_make_list: Evaluation Macros. (line 141)
24780 * m4_maketemp: Redefined M4 Macros. (line 161)
24781 * m4_map: Looping constructs. (line 93)
24782 * m4_map_args: Looping constructs. (line 130)
24783 * m4_map_args_pair: Looping constructs. (line 166)
24784 * m4_map_args_sep: Looping constructs. (line 178)
24785 * m4_map_args_w: Looping constructs. (line 189)
24786 * m4_map_sep: Looping constructs. (line 93)
24787 * m4_mapall: Looping constructs. (line 93)
24788 * m4_mapall_sep: Looping constructs. (line 93)
24789 * m4_max: Number processing Macros.
24790 (line 49)
24791 * m4_min: Number processing Macros.
24792 (line 53)
24793 * m4_mkstemp: Redefined M4 Macros. (line 161)
24794 * m4_n: Conditional constructs.
24795 (line 166)
24796 * m4_newline: Text processing Macros.
24797 (line 134)
24798 * m4_normalize: Text processing Macros.
24799 (line 140)
24800 * m4_pattern_allow: Forbidden Patterns. (line 53)
24801 * m4_pattern_forbid: Forbidden Patterns. (line 17)
24802 * m4_popdef: Redefined M4 Macros. (line 171)
24803 * m4_pushdef: Redefined M4 Macros. (line 6)
24804 * m4_quote: Evaluation Macros. (line 160)
24805 * m4_re_escape: Text processing Macros.
24806 (line 148)
24807 * m4_rename: Redefined M4 Macros. (line 82)
24808 * m4_rename_force: Redefined M4 Macros. (line 82)
24809 * m4_reverse: Evaluation Macros. (line 166)
24810 * m4_set_add: Set manipulation Macros.
24811 (line 19)
24812 * m4_set_add_all: Set manipulation Macros.
24813 (line 25)
24814 * m4_set_contains: Set manipulation Macros.
24815 (line 29)
24816 * m4_set_contents: Set manipulation Macros.
24817 (line 49)
24818 * m4_set_delete: Set manipulation Macros.
24819 (line 79)
24820 * m4_set_difference: Set manipulation Macros.
24821 (line 85)
24822 * m4_set_dump: Set manipulation Macros.
24823 (line 49)
24824 * m4_set_empty: Set manipulation Macros.
24825 (line 107)
24826 * m4_set_foreach: Set manipulation Macros.
24827 (line 113)
24828 * m4_set_intersection: Set manipulation Macros.
24829 (line 85)
24830 * m4_set_list: Set manipulation Macros.
24831 (line 134)
24832 * m4_set_listc: Set manipulation Macros.
24833 (line 134)
24834 * m4_set_map: Set manipulation Macros.
24835 (line 169)
24836 * m4_set_map_sep: Set manipulation Macros.
24837 (line 182)
24838 * m4_set_remove: Set manipulation Macros.
24839 (line 193)
24840 * m4_set_size: Set manipulation Macros.
24841 (line 204)
24842 * m4_set_union: Set manipulation Macros.
24843 (line 85)
24844 * m4_shift: Redefined M4 Macros. (line 6)
24845 * m4_shift2: Looping constructs. (line 199)
24846 * m4_shift3: Looping constructs. (line 199)
24847 * m4_shiftn: Looping constructs. (line 199)
24848 * m4_sign: Number processing Macros.
24849 (line 57)
24850 * m4_sinclude: Redefined M4 Macros. (line 157)
24851 * m4_split: Text processing Macros.
24852 (line 152)
24853 * m4_stack_foreach: Looping constructs. (line 207)
24854 * m4_stack_foreach_lifo: Looping constructs. (line 207)
24855 * m4_stack_foreach_sep: Looping constructs. (line 229)
24856 * m4_stack_foreach_sep_lifo: Looping constructs. (line 229)
24857 * m4_strip: Text processing Macros.
24858 (line 158)
24859 * m4_substr: Redefined M4 Macros. (line 6)
24860 * m4_syscmd: Redefined M4 Macros. (line 6)
24861 * m4_sysval: Redefined M4 Macros. (line 6)
24862 * m4_text_box: Text processing Macros.
24863 (line 166)
24864 * m4_text_wrap: Text processing Macros.
24865 (line 181)
24866 * m4_tolower: Text processing Macros.
24867 (line 212)
24868 * m4_toupper: Text processing Macros.
24869 (line 212)
24870 * m4_traceoff: Redefined M4 Macros. (line 6)
24871 * m4_traceon: Redefined M4 Macros. (line 6)
24872 * m4_translit: Redefined M4 Macros. (line 6)
24873 * m4_undefine: Redefined M4 Macros. (line 175)
24874 * m4_undivert: Redefined M4 Macros. (line 183)
24875 * m4_unquote: Evaluation Macros. (line 175)
24876 * m4_version_compare: Number processing Macros.
24877 (line 61)
24878 * m4_version_prereq: Number processing Macros.
24879 (line 101)
24880 * m4_warn: Diagnostic Macros. (line 28)
24881 * m4_wrap: Redefined M4 Macros. (line 193)
24882 * m4_wrap_lifo: Redefined M4 Macros. (line 193)
24883
24884 
24885 File: autoconf.info, Node: Autotest Macro Index, Next: Program & Function Index, Prev: M4 Macro Index, Up: Indices
24886
24887 B.7 Autotest Macro Index
24888 ========================
24889
24890 This is an alphabetical list of the Autotest macros.
24891
24892 [index]
24893 * Menu:
24894
24895 * AT_ARG_OPTION: Writing Testsuites. (line 50)
24896 * AT_ARG_OPTION_ARG: Writing Testsuites. (line 79)
24897 * AT_AT_PREPARE_EACH_TEST: Writing Testsuites. (line 145)
24898 * AT_BANNER: Writing Testsuites. (line 160)
24899 * AT_CAPTURE_FILE: Writing Testsuites. (line 190)
24900 * AT_CHECK: Writing Testsuites. (line 250)
24901 * AT_CHECK_EUNIT: Writing Testsuites. (line 355)
24902 * AT_CHECK_UNQUOTED: Writing Testsuites. (line 250)
24903 * AT_CLEANUP: Writing Testsuites. (line 231)
24904 * AT_COLOR_TESTS: Writing Testsuites. (line 105)
24905 * AT_COPYRIGHT: Writing Testsuites. (line 41)
24906 * AT_DATA: Writing Testsuites. (line 236)
24907 * AT_FAIL_IF: Writing Testsuites. (line 194)
24908 * AT_INIT: Writing Testsuites. (line 31)
24909 * AT_KEYWORDS: Writing Testsuites. (line 177)
24910 * AT_PACKAGE_BUGREPORT: Making testsuite Scripts.
24911 (line 13)
24912 * AT_PACKAGE_NAME: Making testsuite Scripts.
24913 (line 13)
24914 * AT_PACKAGE_STRING: Making testsuite Scripts.
24915 (line 13)
24916 * AT_PACKAGE_TARNAME: Making testsuite Scripts.
24917 (line 13)
24918 * AT_PACKAGE_URL: Making testsuite Scripts.
24919 (line 13)
24920 * AT_PACKAGE_VERSION: Making testsuite Scripts.
24921 (line 13)
24922 * AT_PREPARE_TESTS: Writing Testsuites. (line 129)
24923 * AT_SETUP: Writing Testsuites. (line 170)
24924 * AT_SKIP_IF: Writing Testsuites. (line 208)
24925 * AT_TESTED: Writing Testsuites. (line 109)
24926 * AT_XFAIL_IF: Writing Testsuites. (line 223)
24927
24928 
24929 File: autoconf.info, Node: Program & Function Index, Next: Concept Index, Prev: Autotest Macro Index, Up: Indices
24930
24931 B.8 Program and Function Index
24932 ==============================
24933
24934 This is an alphabetical list of the programs and functions whose
24935 portability is discussed in this document.
24936
24937 [index]
24938 * Menu:
24939
24940 * !: Limitations of Builtins.
24941 (line 40)
24942 * .: Limitations of Builtins.
24943 (line 16)
24944 * {...}: Limitations of Builtins.
24945 (line 103)
24946 * /usr/bin/ksh on Solaris: Shellology. (line 64)
24947 * /usr/dt/bin/dtksh on Solaris: Shellology. (line 66)
24948 * /usr/xpg4/bin/sh on Solaris: Shellology. (line 65)
24949 * &&: Limitations of Builtins.
24950 (line 84)
24951 * ||: Limitations of Builtins.
24952 (line 84)
24953 * alloca: Particular Functions.
24954 (line 10)
24955 * alloca.h: Particular Functions.
24956 (line 10)
24957 * assert.h: Default Includes. (line 6)
24958 * assert.h <1>: Particular Headers. (line 23)
24959 * awk: Limitations of Usual Tools.
24960 (line 10)
24961 * basename: Limitations of Usual Tools.
24962 (line 141)
24963 * break: Limitations of Builtins.
24964 (line 136)
24965 * case: Limitations of Builtins.
24966 (line 139)
24967 * cat: Limitations of Usual Tools.
24968 (line 148)
24969 * cc: Limitations of Usual Tools.
24970 (line 151)
24971 * cd: Limitations of Builtins.
24972 (line 239)
24973 * chgrp: Limitations of Usual Tools.
24974 (line 182)
24975 * chmod: Limitations of Usual Tools.
24976 (line 186)
24977 * chown: Particular Functions.
24978 (line 48)
24979 * chown <1>: Limitations of Usual Tools.
24980 (line 182)
24981 * closedir: Particular Functions.
24982 (line 58)
24983 * cmp: Limitations of Usual Tools.
24984 (line 196)
24985 * config.guess: Input. (line 58)
24986 * config.guess <1>: Manual Configuration.
24987 (line 13)
24988 * config.sub: Input. (line 58)
24989 * config.sub <1>: Manual Configuration.
24990 (line 13)
24991 * cp: Limitations of Usual Tools.
24992 (line 203)
24993 * ctype.h: Default Includes. (line 6)
24994 * date: Limitations of Usual Tools.
24995 (line 243)
24996 * dirent.h: Particular Headers. (line 28)
24997 * dirname: Limitations of Usual Tools.
24998 (line 254)
24999 * echo: Limitations of Builtins.
25000 (line 288)
25001 * egrep: Limitations of Usual Tools.
25002 (line 262)
25003 * errno.h: Default Includes. (line 6)
25004 * error_at_line: Particular Functions.
25005 (line 73)
25006 * eval: Limitations of Builtins.
25007 (line 324)
25008 * exec: Limitations of Builtins.
25009 (line 368)
25010 * exit: Function Portability.
25011 (line 17)
25012 * exit <1>: Limitations of Builtins.
25013 (line 408)
25014 * export: Limitations of Builtins.
25015 (line 433)
25016 * expr: Limitations of Usual Tools.
25017 (line 290)
25018 * expr <1>: Limitations of Usual Tools.
25019 (line 323)
25020 * expr (|): Limitations of Usual Tools.
25021 (line 304)
25022 * false: Limitations of Builtins.
25023 (line 503)
25024 * fgrep: Limitations of Usual Tools.
25025 (line 407)
25026 * find: Limitations of Usual Tools.
25027 (line 414)
25028 * float.h: Default Includes. (line 6)
25029 * fnmatch: Particular Functions.
25030 (line 83)
25031 * fnmatch <1>: Particular Functions.
25032 (line 96)
25033 * fnmatch <2>: Particular Functions.
25034 (line 484)
25035 * fnmatch.h: Particular Functions.
25036 (line 484)
25037 * for: Limitations of Builtins.
25038 (line 507)
25039 * fork: Particular Functions.
25040 (line 107)
25041 * fseeko: Particular Functions.
25042 (line 131)
25043 * ftello: Particular Functions.
25044 (line 131)
25045 * getgroups: Particular Functions.
25046 (line 144)
25047 * getloadavg: Particular Functions.
25048 (line 161)
25049 * getmntent: Particular Functions.
25050 (line 195)
25051 * getpgid: Particular Functions.
25052 (line 207)
25053 * getpgrp: Particular Functions.
25054 (line 207)
25055 * grep: Limitations of Usual Tools.
25056 (line 439)
25057 * if: Limitations of Builtins.
25058 (line 585)
25059 * install-sh: Input. (line 58)
25060 * install-sh <1>: Particular Programs.
25061 (line 51)
25062 * install-sh <2>: Particular Programs.
25063 (line 88)
25064 * inttypes.h: Header Portability. (line 57)
25065 * inttypes.h <1>: Particular Types. (line 6)
25066 * iso646.h: Default Includes. (line 6)
25067 * join: Limitations of Usual Tools.
25068 (line 505)
25069 * ksh: Shellology. (line 56)
25070 * ksh88: Shellology. (line 56)
25071 * ksh93: Shellology. (line 56)
25072 * limits.h: Default Includes. (line 6)
25073 * linux/irda.h: Header Portability. (line 64)
25074 * linux/random.h: Header Portability. (line 67)
25075 * ln: Limitations of Usual Tools.
25076 (line 520)
25077 * locale.h: Default Includes. (line 6)
25078 * ls: Limitations of Usual Tools.
25079 (line 534)
25080 * lstat: Particular Functions.
25081 (line 230)
25082 * lstat <1>: Particular Functions.
25083 (line 384)
25084 * make: Portable Make. (line 6)
25085 * malloc: Function Portability.
25086 (line 27)
25087 * malloc <1>: Particular Functions.
25088 (line 249)
25089 * math.h: Default Includes. (line 6)
25090 * mbrtowc: Particular Functions.
25091 (line 283)
25092 * memcmp: Particular Functions.
25093 (line 294)
25094 * memory.h: Header Portability. (line 46)
25095 * mkdir: Limitations of Usual Tools.
25096 (line 556)
25097 * mkfifo: Limitations of Usual Tools.
25098 (line 580)
25099 * mknod: Limitations of Usual Tools.
25100 (line 580)
25101 * mktemp: Limitations of Usual Tools.
25102 (line 590)
25103 * mktime: Particular Functions.
25104 (line 304)
25105 * mmap: Particular Functions.
25106 (line 316)
25107 * mv: Limitations of Usual Tools.
25108 (line 615)
25109 * ndir.h: Particular Headers. (line 28)
25110 * net/if.h: Header Portability. (line 70)
25111 * netinet/if_ether.h: Header Portability. (line 73)
25112 * nlist.h: Particular Functions.
25113 (line 178)
25114 * od: Limitations of Usual Tools.
25115 (line 647)
25116 * pdksh: Shellology. (line 73)
25117 * printf: Limitations of Builtins.
25118 (line 609)
25119 * putenv: Function Portability.
25120 (line 34)
25121 * pwd: Limitations of Builtins.
25122 (line 642)
25123 * read: Limitations of Builtins.
25124 (line 671)
25125 * realloc: Function Portability.
25126 (line 50)
25127 * realloc <1>: Particular Functions.
25128 (line 338)
25129 * resolv.h: Particular Headers. (line 102)
25130 * rm: Limitations of Usual Tools.
25131 (line 671)
25132 * rmdir: Limitations of Usual Tools.
25133 (line 690)
25134 * sed: Limitations of Usual Tools.
25135 (line 694)
25136 * sed (t): Limitations of Usual Tools.
25137 (line 914)
25138 * sed (w): Limitations of Usual Tools.
25139 (line 934)
25140 * select: Particular Functions.
25141 (line 355)
25142 * set: Limitations of Builtins.
25143 (line 675)
25144 * setjmp.h: Default Includes. (line 6)
25145 * setpgrp: Particular Functions.
25146 (line 366)
25147 * setvbuf: Obsolete Macros. (line 214)
25148 * shift: Limitations of Builtins.
25149 (line 808)
25150 * sigaction: Function Portability.
25151 (line 60)
25152 * signal: Function Portability.
25153 (line 60)
25154 * signal.h: Default Includes. (line 6)
25155 * signal.h <1>: Obsolete Macros. (line 696)
25156 * sleep: Limitations of Usual Tools.
25157 (line 954)
25158 * snprintf: Function Portability.
25159 (line 64)
25160 * sort: Limitations of Usual Tools.
25161 (line 960)
25162 * source: Limitations of Builtins.
25163 (line 816)
25164 * stat: Particular Functions.
25165 (line 384)
25166 * stdarg.h: Default Includes. (line 6)
25167 * stdbool.h: Particular Headers. (line 10)
25168 * stdbool.h <1>: Particular Headers. (line 130)
25169 * stddef.h: Default Includes. (line 6)
25170 * stdint.h: Header Portability. (line 57)
25171 * stdint.h <1>: Particular Types. (line 6)
25172 * stdio.h: Default Includes. (line 6)
25173 * stdlib.h: Default Includes. (line 6)
25174 * stdlib.h <1>: Particular Types. (line 6)
25175 * strcoll: Particular Functions.
25176 (line 399)
25177 * strerror_r: Function Portability.
25178 (line 78)
25179 * strerror_r <1>: Particular Functions.
25180 (line 409)
25181 * strftime: Particular Functions.
25182 (line 425)
25183 * string.h: Default Includes. (line 6)
25184 * strings.h: Header Portability. (line 49)
25185 * strnlen: Function Portability.
25186 (line 84)
25187 * strnlen <1>: Particular Functions.
25188 (line 454)
25189 * strtod: Particular Functions.
25190 (line 432)
25191 * strtold: Particular Functions.
25192 (line 444)
25193 * sys/dir.h: Particular Headers. (line 28)
25194 * sys/ioctl.h: Particular Headers. (line 199)
25195 * sys/mkdev.h: Particular Headers. (line 71)
25196 * sys/mount.h: Header Portability. (line 77)
25197 * sys/ndir.h: Particular Headers. (line 28)
25198 * sys/ptem.h: Header Portability. (line 80)
25199 * sys/socket.h: Header Portability. (line 83)
25200 * sys/stat.h: Particular Headers. (line 121)
25201 * sys/sysmacros.h: Particular Headers. (line 71)
25202 * sys/time.h: Particular Structures.
25203 (line 35)
25204 * sys/time.h <1>: Obsolete Macros. (line 267)
25205 * sys/types.h: Particular Types. (line 6)
25206 * sys/ucred.h: Header Portability. (line 86)
25207 * sys/wait.h: Particular Headers. (line 159)
25208 * sysconf: Function Portability.
25209 (line 104)
25210 * tar: Limitations of Usual Tools.
25211 (line 965)
25212 * termios.h: Particular Headers. (line 199)
25213 * test: Limitations of Builtins.
25214 (line 820)
25215 * time.h: Default Includes. (line 6)
25216 * time.h <1>: Particular Structures.
25217 (line 35)
25218 * time.h <2>: Obsolete Macros. (line 267)
25219 * touch: Limitations of Usual Tools.
25220 (line 970)
25221 * tr: Limitations of Usual Tools.
25222 (line 976)
25223 * trap: Limitations of Builtins.
25224 (line 939)
25225 * true: Limitations of Builtins.
25226 (line 1025)
25227 * unistd.h: Particular Headers. (line 183)
25228 * unlink: Function Portability.
25229 (line 108)
25230 * unset: Limitations of Builtins.
25231 (line 1041)
25232 * unsetenv: Function Portability.
25233 (line 114)
25234 * utime: Particular Functions.
25235 (line 465)
25236 * va_copy: Function Portability.
25237 (line 119)
25238 * va_list: Function Portability.
25239 (line 126)
25240 * vfork: Particular Functions.
25241 (line 107)
25242 * vfork.h: Particular Functions.
25243 (line 107)
25244 * vprintf: Particular Functions.
25245 (line 475)
25246 * vsnprintf: Function Portability.
25247 (line 64)
25248 * vsprintf: Particular Functions.
25249 (line 475)
25250 * wait: Limitations of Builtins.
25251 (line 1068)
25252 * wait3: Obsolete Macros. (line 222)
25253 * wchar.h: Default Includes. (line 6)
25254 * wchar.h <1>: Particular Types. (line 87)
25255 * wctype.h: Default Includes. (line 6)
25256 * X11/extensions/scrnsaver.h: Header Portability. (line 89)
25257
25258 
25259 File: autoconf.info, Node: Concept Index, Prev: Program & Function Index, Up: Indices
25260
25261 B.9 Concept Index
25262 =================
25263
25264 This is an alphabetical list of the files, tools, and concepts
25265 introduced in this document.
25266
25267 [index]
25268 * Menu:
25269
25270 * _m4_divert_diversion: New Macros. (line 6)
25271 * "$@": Shell Substitutions. (line 70)
25272 * @&t@: Quadrigraphs. (line 6)
25273 * @S|@: Quadrigraphs. (line 6)
25274 * `COMMANDS`: Shell Substitutions. (line 367)
25275 * ^ quoting: Shell Substitutions. (line 477)
25276 * $((EXPRESSION)): Shell Substitutions. (line 438)
25277 * $(COMMANDS): Shell Substitutions. (line 412)
25278 * ${#VAR}: Shell Substitutions. (line 359)
25279 * ${VAR-VALUE}: Shell Substitutions. (line 163)
25280 * ${VAR?VALUE}: Shell Substitutions. (line 163)
25281 * ${VAR##WORD}: Shell Substitutions. (line 359)
25282 * ${VAR#WORD}: Shell Substitutions. (line 359)
25283 * ${VAR%%WORD}: Shell Substitutions. (line 359)
25284 * ${VAR%WORD}: Shell Substitutions. (line 359)
25285 * ${VAR+VALUE}: Shell Substitutions. (line 163)
25286 * ${VAR=EXPANDED-VALUE}: Shell Substitutions. (line 339)
25287 * ${VAR=LITERAL}: Shell Substitutions. (line 315)
25288 * ${VAR=VALUE}: Shell Substitutions. (line 163)
25289 * ${VAR=VALUE} <1>: Shell Substitutions. (line 242)
25290 * $<, explicit rules, and VPATH: $< in Explicit Rules.
25291 (line 6)
25292 * 64-bit libraries: Site Defaults. (line 98)
25293 * A68FLAGS: Preset Output Variables.
25294 (line 169)
25295 * abs_builddir: Preset Output Variables.
25296 (line 176)
25297 * abs_srcdir: Preset Output Variables.
25298 (line 198)
25299 * abs_top_builddir: Preset Output Variables.
25300 (line 191)
25301 * abs_top_srcdir: Preset Output Variables.
25302 (line 205)
25303 * absolute file names, detect: File System Conventions.
25304 (line 51)
25305 * ac_aux_dir: Input. (line 87)
25306 * ac_objext: Generic Functions. (line 59)
25307 * ac_path_VARIABLE: Generic Programs. (line 123)
25308 * ac_path_VARIABLE_found: Generic Programs. (line 123)
25309 * ac_srcdir: Configuration Actions.
25310 (line 85)
25311 * ac_top_build_prefix: Configuration Actions.
25312 (line 80)
25313 * ac_top_srcdir: Configuration Actions.
25314 (line 76)
25315 * acconfig.h: acconfig Header. (line 6)
25316 * aclocal.m4: Making configure Scripts.
25317 (line 6)
25318 * Algol 68: Algol 68 Compiler. (line 6)
25319 * Ash: Shellology. (line 16)
25320 * at_arg_OPTION: Writing Testsuites. (line 50)
25321 * at_arg_OPTION <1>: Writing Testsuites. (line 79)
25322 * at_optarg: Writing Testsuites. (line 62)
25323 * at_optarg <1>: Writing Testsuites. (line 90)
25324 * at_optarg_OPTION: Writing Testsuites. (line 62)
25325 * at_status: Writing Testsuites. (line 250)
25326 * autoconf: autoconf Invocation. (line 6)
25327 * Autoconf upgrading: Autoconf 1. (line 6)
25328 * Autoconf upgrading <1>: Autoconf 2.13. (line 6)
25329 * Autoconf version: Versioning. (line 6)
25330 * autoheader: autoheader Invocation.
25331 (line 6)
25332 * Autoheader macros: Autoheader Macros. (line 6)
25333 * autom4te debugging tips: Debugging via autom4te.
25334 (line 6)
25335 * Autom4te Library: autom4te Invocation. (line 220)
25336 * autom4te.cache: autom4te Invocation. (line 126)
25337 * autom4te.cfg: autom4te Invocation. (line 252)
25338 * Automake: Automake. (line 19)
25339 * Automatic remaking: Automatic Remaking. (line 6)
25340 * automatic rule rewriting and VPATH: Automatic Rule Rewriting.
25341 (line 6)
25342 * autopoint: autoreconf Invocation.
25343 (line 38)
25344 * autoreconf: autoreconf Invocation.
25345 (line 6)
25346 * autoscan: autoscan Invocation. (line 6)
25347 * Autotest: Using Autotest. (line 6)
25348 * AUTOTEST_PATH: testsuite Invocation.
25349 (line 59)
25350 * autoupdate: autoupdate Invocation.
25351 (line 6)
25352 * balancing parentheses: Balancing Parentheses.
25353 (line 6)
25354 * Bash: Shellology. (line 43)
25355 * Bash 2.05 and later: Shellology. (line 48)
25356 * bindir: Installation Directory Variables.
25357 (line 14)
25358 * Bootstrap: Bootstrapping. (line 6)
25359 * BSD make and obj/: obj/ and Make. (line 6)
25360 * buffer overruns: Buffer Overruns. (line 6)
25361 * Build directories: Build Directories. (line 6)
25362 * builddir: Preset Output Variables.
25363 (line 173)
25364 * C function portability: Function Portability.
25365 (line 6)
25366 * C types: Types. (line 6)
25367 * C89, C99, C11, C17, and C23: Portable C and C++. (line 17)
25368 * Cache: Caching Results. (line 6)
25369 * Cache variable: Cache Variable Names.
25370 (line 6)
25371 * Cache, enabling: configure Invocation.
25372 (line 25)
25373 * Canonical system type: Canonicalizing. (line 6)
25374 * carriage return, deleting: Limitations of Usual Tools.
25375 (line 984)
25376 * CFLAGS: Preset Output Variables.
25377 (line 22)
25378 * changequote: Changequote is Evil. (line 6)
25379 * Coding style: Coding Style. (line 6)
25380 * Command Substitution: Shell Substitutions. (line 367)
25381 * command-line, macros set on: Command-line Macros and whitespace.
25382 (line 6)
25383 * Commands for configuration: Configuration Commands.
25384 (line 6)
25385 * Comments in Makefile macros: Comments in Make Macros.
25386 (line 6)
25387 * Comments in Makefile rules: Comments in Make Rules.
25388 (line 6)
25389 * Common autoconf behavior: Common Behavior. (line 6)
25390 * Compilers: Compilers and Preprocessors.
25391 (line 6)
25392 * composing variable names: Polymorphic Variables.
25393 (line 130)
25394 * CONFIG_COMMANDS: Obsolete config.status Use.
25395 (line 10)
25396 * CONFIG_FILES: Obsolete config.status Use.
25397 (line 14)
25398 * CONFIG_HEADERS: Obsolete config.status Use.
25399 (line 19)
25400 * CONFIG_LINKS: Obsolete config.status Use.
25401 (line 24)
25402 * CONFIG_SHELL: config.status Invocation.
25403 (line 100)
25404 * CONFIG_STATUS: config.status Invocation.
25405 (line 106)
25406 * config.h: Configuration Headers.
25407 (line 6)
25408 * config.h.bot: acconfig Header. (line 6)
25409 * config.h.in: Header Templates. (line 6)
25410 * config.h.top: acconfig Header. (line 6)
25411 * config.site: Site Defaults. (line 6)
25412 * config.status: config.status Invocation.
25413 (line 6)
25414 * config.sub: Specifying Target Triplets.
25415 (line 72)
25416 * Configuration actions: Configuration Actions.
25417 (line 6)
25418 * Configuration commands: Configuration Commands.
25419 (line 6)
25420 * Configuration file creation: Configuration Files. (line 6)
25421 * Configuration Header: Configuration Headers.
25422 (line 6)
25423 * Configuration Header Template: Header Templates. (line 6)
25424 * Configuration links: Configuration Links. (line 6)
25425 * configure: Making configure Scripts.
25426 (line 6)
25427 * configure <1>: Running configure Scripts.
25428 (line 6)
25429 * Configure subdirectories: Subdirectories. (line 6)
25430 * configure_input: Preset Output Variables.
25431 (line 60)
25432 * configure.ac: Making configure Scripts.
25433 (line 27)
25434 * configure.in: Writing Autoconf Input.
25435 (line 19)
25436 * Copyright Notice: Notices. (line 10)
25437 * Copyright Notice <1>: Writing Testsuites. (line 41)
25438 * CPPFLAGS: Preset Output Variables.
25439 (line 74)
25440 * Creating configuration files: Configuration Files. (line 6)
25441 * Creating temporary files: Limitations of Usual Tools.
25442 (line 590)
25443 * Cross compilation: Hosts and Cross-Compilation.
25444 (line 6)
25445 * CXXFLAGS: Preset Output Variables.
25446 (line 96)
25447 * Darwin: Systemology. (line 23)
25448 * Data structure, set: Set manipulation Macros.
25449 (line 6)
25450 * datadir: Installation Directory Variables.
25451 (line 17)
25452 * datarootdir: Changed Directory Variables.
25453 (line 6)
25454 * datarootdir <1>: Installation Directory Variables.
25455 (line 21)
25456 * debugging tips: Debugging via autom4te.
25457 (line 6)
25458 * Declaration, checking: Declarations. (line 6)
25459 * Default includes: Default Includes. (line 6)
25460 * DEFS: Preset Output Variables.
25461 (line 100)
25462 * deleting carriage return: Limitations of Usual Tools.
25463 (line 984)
25464 * Dependencies between macros: Dependencies Between Macros.
25465 (line 6)
25466 * descriptors: File Descriptor Macros.
25467 (line 6)
25468 * Descriptors: File Descriptors. (line 6)
25469 * Directories, build: Build Directories. (line 6)
25470 * Directories, installation: Installation Directory Variables.
25471 (line 6)
25472 * division, integer: Signed Integer Division.
25473 (line 6)
25474 * dnl: Macro Definitions. (line 50)
25475 * dnl <1>: Coding Style. (line 42)
25476 * docdir: Installation Directory Variables.
25477 (line 25)
25478 * double-colon rules and VPATH: VPATH and Double-colon.
25479 (line 6)
25480 * dvidir: Installation Directory Variables.
25481 (line 29)
25482 * ECHO_C: Preset Output Variables.
25483 (line 108)
25484 * ECHO_N: Preset Output Variables.
25485 (line 109)
25486 * ECHO_T: Preset Output Variables.
25487 (line 110)
25488 * Endianness: C Compiler. (line 168)
25489 * environment, macros set from: Command-line Macros and whitespace.
25490 (line 6)
25491 * Erlang: Erlang Compiler and Interpreter.
25492 (line 6)
25493 * ERLANG_INSTALL_LIB_DIR: Installation Directory Variables.
25494 (line 209)
25495 * ERLANG_INSTALL_LIB_DIR_LIBRARY: Installation Directory Variables.
25496 (line 214)
25497 * Erlang, Library, checking: Erlang Libraries. (line 6)
25498 * ERLCFLAGS: Preset Output Variables.
25499 (line 115)
25500 * exec_prefix: Installation Directory Variables.
25501 (line 32)
25502 * exiting portably: Exiting Portably. (line 6)
25503 * expanded before required: Expanded Before Required.
25504 (line 6)
25505 * explicit rules, $<, and VPATH: $< in Explicit Rules.
25506 (line 6)
25507 * External software: External Software. (line 6)
25508 * F77: Fortran Compiler. (line 6)
25509 * FCFLAGS: Preset Output Variables.
25510 (line 121)
25511 * FFLAGS: Preset Output Variables.
25512 (line 128)
25513 * FHS: Site Defaults. (line 84)
25514 * file descriptors: File Descriptor Macros.
25515 (line 6)
25516 * File descriptors: File Descriptors. (line 6)
25517 * File system conventions: File System Conventions.
25518 (line 6)
25519 * File, checking: Files. (line 6)
25520 * Filesystem Hierarchy Standard: Site Defaults. (line 84)
25521 * floating point: Floating Point Portability.
25522 (line 6)
25523 * Forbidden patterns: Forbidden Patterns. (line 6)
25524 * Fortran: Fortran Compiler. (line 6)
25525 * Function, checking: Particular Functions.
25526 (line 6)
25527 * Gettext: autoreconf Invocation.
25528 (line 38)
25529 * GNU build system: The GNU Build System.
25530 (line 6)
25531 * Gnulib: Gnulib. (line 11)
25532 * Go: Go Compiler. (line 6)
25533 * GOFLAGS: Preset Output Variables.
25534 (line 165)
25535 * Header portability: Header Portability. (line 6)
25536 * Header templates: Header Templates. (line 6)
25537 * Header, checking: Header Files. (line 6)
25538 * Help strings: Pretty Help Strings. (line 6)
25539 * Here-documents: Here-Documents. (line 6)
25540 * History of autoconf: History. (line 6)
25541 * htmldir: Installation Directory Variables.
25542 (line 39)
25543 * ifnames: ifnames Invocation. (line 6)
25544 * Imake: Why Not Imake. (line 6)
25545 * includedir: Installation Directory Variables.
25546 (line 42)
25547 * Includes, default: Default Includes. (line 6)
25548 * indirection, variable name: Polymorphic Variables.
25549 (line 6)
25550 * infodir: Installation Directory Variables.
25551 (line 45)
25552 * input: File Descriptor Macros.
25553 (line 6)
25554 * Install prefix: Default Prefix. (line 6)
25555 * Installation directories: Installation Directory Variables.
25556 (line 6)
25557 * Instantiation: Output. (line 13)
25558 * integer overflow: Integer Overflow. (line 6)
25559 * integer overflow <1>: Integer Overflow Basics.
25560 (line 6)
25561 * integer overflow <2>: Signed Overflow Examples.
25562 (line 6)
25563 * integer overflow <3>: Signed Overflow Advice.
25564 (line 6)
25565 * Introduction: Introduction. (line 6)
25566 * invoking the shell: Invoking the Shell. (line 6)
25567 * K&R C: Portable C and C++. (line 17)
25568 * Korn shell: Shellology. (line 56)
25569 * Ksh: Shellology. (line 56)
25570 * Language: Language Choice. (line 6)
25571 * Large file support: System Services. (line 48)
25572 * LDFLAGS: Preset Output Variables.
25573 (line 135)
25574 * LFS: System Services. (line 48)
25575 * lib64: Site Defaults. (line 98)
25576 * libdir: Installation Directory Variables.
25577 (line 48)
25578 * libexecdir: Installation Directory Variables.
25579 (line 51)
25580 * Library, checking: Libraries. (line 6)
25581 * LIBS: Preset Output Variables.
25582 (line 149)
25583 * Libtool: Libtool. (line 13)
25584 * License: Distributing. (line 6)
25585 * Limitations of make: Portable Make. (line 6)
25586 * Limitations of shell builtins: Limitations of Builtins.
25587 (line 6)
25588 * Limitations of usual tools: Limitations of Usual Tools.
25589 (line 6)
25590 * Links: Configuration Links. (line 12)
25591 * Links for configuration: Configuration Links. (line 6)
25592 * Listing directories: Limitations of Usual Tools.
25593 (line 534)
25594 * localedir: Installation Directory Variables.
25595 (line 54)
25596 * localstatedir: Installation Directory Variables.
25597 (line 59)
25598 * loop induction: Optimization and Wraparound.
25599 (line 6)
25600 * low-level output: File Descriptor Macros.
25601 (line 6)
25602 * M4: Programming in M4. (line 6)
25603 * M4 quotation: M4 Quotation. (line 6)
25604 * M4sugar: Programming in M4sugar.
25605 (line 6)
25606 * m4sugar debugging tips: Debugging via autom4te.
25607 (line 6)
25608 * Mac OS X: Systemology. (line 23)
25609 * macOS: Systemology. (line 23)
25610 * Macros, called once: One-Shot Macros. (line 6)
25611 * Macros, obsoleting: Obsoleting Macros. (line 6)
25612 * Macros, ordering: Suggested Ordering. (line 6)
25613 * Macros, prerequisites: Prerequisite Macros. (line 6)
25614 * make -k: make -k Status. (line 6)
25615 * make and MAKEFLAGS: The Make Macro MAKEFLAGS.
25616 (line 6)
25617 * make and SHELL: The Make Macro SHELL.
25618 (line 6)
25619 * Makefile macros and comments: Comments in Make Macros.
25620 (line 6)
25621 * Makefile macros and whitespace: Trailing whitespace in Make Macros.
25622 (line 6)
25623 * Makefile rules and comments: Comments in Make Rules.
25624 (line 6)
25625 * Makefile rules and newlines: Newlines in Make Rules.
25626 (line 6)
25627 * Makefile substitutions: Makefile Substitutions.
25628 (line 6)
25629 * MAKEFLAGS and make: The Make Macro MAKEFLAGS.
25630 (line 6)
25631 * Making directories: Limitations of Usual Tools.
25632 (line 556)
25633 * mandir: Installation Directory Variables.
25634 (line 71)
25635 * Messages, from configure: Printing Messages. (line 6)
25636 * Messages, from M4sugar: Diagnostic Macros. (line 6)
25637 * Moving open files: Limitations of Usual Tools.
25638 (line 615)
25639 * newline, deleting: Limitations of Usual Tools.
25640 (line 984)
25641 * Newlines in Makefile rules: Newlines in Make Rules.
25642 (line 6)
25643 * Notices in configure: Notices. (line 6)
25644 * null pointers: Null Pointers. (line 6)
25645 * obj/, subdirectory: obj/ and Make. (line 6)
25646 * OBJCFLAGS: Preset Output Variables.
25647 (line 157)
25648 * OBJCXXFLAGS: Preset Output Variables.
25649 (line 161)
25650 * Obsolete constructs: Obsolete Constructs. (line 6)
25651 * Obsoleting macros: Obsoleting Macros. (line 6)
25652 * obstack: Particular Functions.
25653 (line 328)
25654 * oldincludedir: Installation Directory Variables.
25655 (line 74)
25656 * One-shot macros: One-Shot Macros. (line 6)
25657 * Options, package: Package Options. (line 6)
25658 * Options, Package: Option Checking. (line 6)
25659 * Ordering macros: Suggested Ordering. (line 6)
25660 * Output variables: Preset Output Variables.
25661 (line 6)
25662 * Output variables <1>: Setting Output Variables.
25663 (line 6)
25664 * Output variables, special characters in: Special Chars in Variables.
25665 (line 6)
25666 * output, low-level: File Descriptor Macros.
25667 (line 6)
25668 * Outputting files: Output. (line 6)
25669 * overflow, signed integer: Integer Overflow. (line 6)
25670 * overflow, signed integer <1>: Integer Overflow Basics.
25671 (line 6)
25672 * overflow, signed integer <2>: Signed Overflow Examples.
25673 (line 6)
25674 * overflow, signed integer <3>: Signed Overflow Advice.
25675 (line 6)
25676 * Package options: Package Options. (line 6)
25677 * package.m4: Making testsuite Scripts.
25678 (line 13)
25679 * Parallel make: Parallel Make. (line 6)
25680 * parentheses, balancing: Balancing Parentheses.
25681 (line 6)
25682 * Patterns, forbidden: Forbidden Patterns. (line 6)
25683 * pdfdir: Installation Directory Variables.
25684 (line 77)
25685 * polymorphic variable name: Polymorphic Variables.
25686 (line 6)
25687 * portability: Varieties of Unportability.
25688 (line 6)
25689 * Portability of C functions: Function Portability.
25690 (line 6)
25691 * Portability of headers: Header Portability. (line 6)
25692 * Portable C and C++ programming: Portable C and C++. (line 6)
25693 * Portable shell programming: Portable Shell. (line 6)
25694 * positional parameters: Shell Substitutions. (line 137)
25695 * POSIX termios headers: System Services. (line 137)
25696 * Precious Variable: Setting Output Variables.
25697 (line 66)
25698 * prefix: Installation Directory Variables.
25699 (line 80)
25700 * Prefix for install: Default Prefix. (line 6)
25701 * preprocessor arithmetic: Preprocessor Arithmetic.
25702 (line 6)
25703 * Preprocessors: Compilers and Preprocessors.
25704 (line 6)
25705 * Prerequisite macros: Prerequisite Macros. (line 6)
25706 * Program names, transforming: Transforming Names. (line 6)
25707 * Programs, checking: Alternative Programs.
25708 (line 6)
25709 * psdir: Installation Directory Variables.
25710 (line 85)
25711 * QNX: Systemology. (line 42)
25712 * quadrigraphs: Quadrigraphs. (line 6)
25713 * quotation: Autoconf Language. (line 6)
25714 * quotation <1>: M4 Quotation. (line 6)
25715 * Remaking automatically: Automatic Remaking. (line 6)
25716 * Revision: Notices. (line 18)
25717 * Rule, Single Suffix Inference: Single Suffix Rules. (line 6)
25718 * runstatedir: Installation Directory Variables.
25719 (line 63)
25720 * sbindir: Installation Directory Variables.
25721 (line 88)
25722 * Separated Dependencies: Single Suffix Rules. (line 9)
25723 * set -b: Limitations of Builtins.
25724 (line 768)
25725 * set -e: Limitations of Builtins.
25726 (line 699)
25727 * set -m: Limitations of Builtins.
25728 (line 768)
25729 * set -n: Limitations of Builtins.
25730 (line 792)
25731 * Set manipulation: Set manipulation Macros.
25732 (line 6)
25733 * sharedstatedir: Installation Directory Variables.
25734 (line 92)
25735 * SHELL and make: The Make Macro SHELL.
25736 (line 6)
25737 * Shell assignments: Assignments. (line 6)
25738 * Shell builtins: Limitations of Builtins.
25739 (line 6)
25740 * Shell file descriptors: File Descriptors. (line 6)
25741 * Shell Functions: Shell Functions. (line 6)
25742 * Shell here-documents: Here-Documents. (line 6)
25743 * shell invocation: Invoking the Shell. (line 6)
25744 * Shell parentheses: Parentheses. (line 6)
25745 * Shell pattern matching: Shell Pattern Matching.
25746 (line 6)
25747 * Shell substitutions: Shell Substitutions. (line 6)
25748 * Shell variables: Special Shell Variables.
25749 (line 6)
25750 * Shellology: Shellology. (line 6)
25751 * Signal handling in the shell: Signal Handling. (line 6)
25752 * Signals, shells and: Signal Handling. (line 6)
25753 * signed integer overflow: Integer Overflow. (line 6)
25754 * signed integer overflow <1>: Integer Overflow Basics.
25755 (line 6)
25756 * signed integer overflow <2>: Signed Overflow Examples.
25757 (line 6)
25758 * signed integer overflow <3>: Signed Overflow Advice.
25759 (line 6)
25760 * Single Suffix Inference Rule: Single Suffix Rules. (line 6)
25761 * Site defaults: Site Defaults. (line 6)
25762 * Site details: Site Details. (line 6)
25763 * Special shell variables: Special Shell Variables.
25764 (line 6)
25765 * srcdir: Configuration Actions.
25766 (line 71)
25767 * srcdir <1>: Preset Output Variables.
25768 (line 194)
25769 * standard input: File Descriptor Macros.
25770 (line 6)
25771 * Standard symbols: Standard Symbols. (line 6)
25772 * Structure, checking: Structures. (line 6)
25773 * Subdirectory configure: Subdirectories. (line 6)
25774 * Substitutions in makefiles: Makefile Substitutions.
25775 (line 6)
25776 * Symbolic links: Limitations of Usual Tools.
25777 (line 522)
25778 * sysconfdir: Installation Directory Variables.
25779 (line 96)
25780 * System type: Specifying Target Triplets.
25781 (line 6)
25782 * System type <1>: Canonicalizing. (line 6)
25783 * Systemology: Systemology. (line 6)
25784 * Target triplet: Specifying Target Triplets.
25785 (line 6)
25786 * termios POSIX headers: System Services. (line 137)
25787 * test group: testsuite Scripts. (line 12)
25788 * testsuite: testsuite Scripts. (line 6)
25789 * testsuite <1>: testsuite Invocation.
25790 (line 6)
25791 * timestamp resolution: Limitations of Usual Tools.
25792 (line 207)
25793 * timestamp resolution <1>: Limitations of Usual Tools.
25794 (line 970)
25795 * timestamp resolution <2>: Timestamps and Make. (line 6)
25796 * tmp: Configuration Actions.
25797 (line 89)
25798 * top_build_prefix: Preset Output Variables.
25799 (line 183)
25800 * top_builddir: Preset Output Variables.
25801 (line 179)
25802 * top_srcdir: Preset Output Variables.
25803 (line 201)
25804 * Transforming program names: Transforming Names. (line 6)
25805 * Types: Types. (line 6)
25806 * unbalanced parentheses, managing: Balancing Parentheses.
25807 (line 6)
25808 * undefined macro: New Macros. (line 6)
25809 * Unix version 7: Systemology. (line 48)
25810 * Unordered set manipulation: Set manipulation Macros.
25811 (line 6)
25812 * Upgrading autoconf: Autoconf 1. (line 6)
25813 * Upgrading autoconf <1>: Autoconf 2.13. (line 6)
25814 * V7: Systemology. (line 48)
25815 * variable name indirection: Polymorphic Variables.
25816 (line 6)
25817 * variable names, composing: Polymorphic Variables.
25818 (line 130)
25819 * Variable, Precious: Setting Output Variables.
25820 (line 66)
25821 * variables and VPATH: Variables listed in VPATH.
25822 (line 6)
25823 * Version: Versioning. (line 11)
25824 * version, Autoconf: Versioning. (line 6)
25825 * volatile objects: Volatile Objects. (line 6)
25826 * VPATH: VPATH and Make. (line 6)
25827 * VPATH and automatic rule rewriting: Automatic Rule Rewriting.
25828 (line 6)
25829 * VPATH and double-colon rules: VPATH and Double-colon.
25830 (line 6)
25831 * VPATH and variables: Variables listed in VPATH.
25832 (line 6)
25833 * VPATH, explicit rules, and $<: $< in Explicit Rules.
25834 (line 6)
25835 * VPATH, resolving target pathnames: Make Target Lookup. (line 6)
25836 * whitespace in command-line macros: Command-line Macros and whitespace.
25837 (line 6)
25838 * whitespace in Makefile macros: Trailing whitespace in Make Macros.
25839 (line 6)
25840 * wraparound arithmetic: Integer Overflow. (line 6)
25841 * wraparound arithmetic <1>: Integer Overflow Basics.
25842 (line 6)
25843 * wraparound arithmetic <2>: Signed Overflow Examples.
25844 (line 6)
25845 * wraparound arithmetic <3>: Signed Overflow Advice.
25846 (line 6)
25847 * X Window System: System Services. (line 10)
25848 * Year 2038: System Services. (line 143)
25849 * Zsh: Shellology. (line 83)
25850
25851 
25852 Tag Table:
25853 Node: Top1984
25854 Node: Introduction21501
25855 Node: The GNU Build System28065
25856 Node: Automake29046
25857 Node: Gnulib31084
25858 Node: Libtool32489
25859 Node: Pointers33916
25860 Ref: Pointers-Footnote-135237
25861 Node: Making configure Scripts35401
25862 Node: Writing Autoconf Input38846
25863 Node: Shell Script Compiler40438
25864 Node: Autoconf Language42855
25865 Node: Autoconf Input Layout50448
25866 Node: autoscan Invocation51892
25867 Node: ifnames Invocation54588
25868 Node: autoconf Invocation55889
25869 Node: autoreconf Invocation61280
25870 Node: Setup68206
25871 Node: Initializing configure69538
25872 Ref: AC_INIT70075
25873 Node: Versioning76032
25874 Node: Notices77926
25875 Node: Input79253
25876 Ref: AC_CONFIG_SRCDIR79530
25877 Node: Output85665
25878 Ref: AC_OUTPUT86116
25879 Ref: AC_PROG_MAKE_SET87824
25880 Node: Configuration Actions88294
25881 Node: Configuration Files93805
25882 Ref: AC_CONFIG_FILES94066
25883 Node: Makefile Substitutions95411
25884 Node: Preset Output Variables97219
25885 Node: Installation Directory Variables107204
25886 Node: Changed Directory Variables115797
25887 Node: Build Directories118447
25888 Node: Automatic Remaking120603
25889 Node: Configuration Headers122827
25890 Node: Header Templates126616
25891 Node: autoheader Invocation129474
25892 Node: Autoheader Macros134063
25893 Node: Configuration Commands136116
25894 Ref: AC_CONFIG_COMMANDS136640
25895 Node: Configuration Links138027
25896 Ref: AC_CONFIG_LINKS138482
25897 Node: Subdirectories139575
25898 Node: Default Prefix142195
25899 Ref: AC_PREFIX_PROGRAM143130
25900 Node: Existing Tests143693
25901 Node: Common Behavior145500
25902 Node: Standard Symbols146139
25903 Node: Default Includes146736
25904 Node: Alternative Programs151240
25905 Node: Particular Programs151928
25906 Ref: AC_PROG_LEX157866
25907 Ref: AC_PROG_LN_S162558
25908 Node: Generic Programs164235
25909 Ref: AC_CHECK_PROG165229
25910 Ref: AC_CHECK_PROGS165961
25911 Ref: AC_PATH_PROG170041
25912 Ref: AC_PATH_PROGS170421
25913 Node: Files173501
25914 Node: Libraries174777
25915 Ref: AC_CHECK_LIB175018
25916 Ref: AC_SEARCH_LIBS177337
25917 Node: Library Functions178559
25918 Node: Function Portability179184
25919 Node: Particular Functions185858
25920 Ref: AC_FUNC_ALLOCA186190
25921 Ref: AC_FUNC_CLOSEDIR_VOID188223
25922 Ref: AC_FUNC_FORK190231
25923 Ref: AC_FUNC_FSEEKO191431
25924 Ref: AC_FUNC_GETLOADAVG192921
25925 Ref: AC_FUNC_GETMNTENT194565
25926 Ref: AC_FUNC_MMAP199317
25927 Ref: AC_FUNC_STRCOLL203170
25928 Ref: AC_FUNC_STRFTIME204458
25929 Ref: AC_FUNC_UTIME_NULL206143
25930 Ref: AC_FUNC_VPRINTF206510
25931 Node: Generic Functions207818
25932 Ref: AC_CHECK_FUNC208352
25933 Ref: AC_CHECK_FUNCS208993
25934 Node: Header Files213777
25935 Node: Header Portability214412
25936 Node: Particular Headers218081
25937 Ref: AC_HEADER_DIRENT219306
25938 Ref: AC_HEADER_MAJOR220908
25939 Ref: AC_HEADER_STAT222896
25940 Ref: AC_HEADER_STDC224154
25941 Node: Generic Headers226406
25942 Ref: AC_CHECK_HEADER226810
25943 Ref: AC_CHECK_HEADERS228223
25944 Node: Declarations231003
25945 Node: Particular Declarations231603
25946 Node: Generic Declarations231827
25947 Ref: AC_CHECK_DECLS233222
25948 Node: Structures235816
25949 Node: Particular Structures236435
25950 Ref: AC_STRUCT_ST_BLOCKS237558
25951 Ref: AC_STRUCT_TIMEZONE238312
25952 Node: Generic Structures238670
25953 Ref: AC_CHECK_MEMBERS239667
25954 Node: Types240510
25955 Node: Particular Types241032
25956 Ref: AC_TYPE_GETGROUPS241495
25957 Ref: AC_TYPE_MODE_T244694
25958 Ref: AC_TYPE_OFF_T244886
25959 Ref: AC_TYPE_PID_T245075
25960 Ref: AC_TYPE_SIZE_T245264
25961 Ref: AC_TYPE_UID_T245651
25962 Node: Generic Types247408
25963 Node: Compilers and Preprocessors249604
25964 Node: Specific Compiler Characteristics250957
25965 Node: Generic Compiler Characteristics252091
25966 Ref: AC_CHECK_SIZEOF252331
25967 Node: C Compiler258194
25968 Ref: AC_PROG_CC260066
25969 Ref: AC_PROG_CC_C_O264063
25970 Ref: AC_C_BIGENDIAN266068
25971 Ref: AC_C_CONST267926
25972 Ref: AC_C_INLINE271288
25973 Ref: AC_C_CHAR_UNSIGNED271532
25974 Node: C++ Compiler274509
25975 Node: Objective C Compiler277418
25976 Node: Objective C++ Compiler279036
25977 Node: Erlang Compiler and Interpreter280745
25978 Node: Fortran Compiler282866
25979 Node: Go Compiler309942
25980 Node: Algol 68 Compiler311061
25981 Node: System Services312441
25982 Ref: AC_PATH_X312692
25983 Ref: AC_PATH_XTRA313739
25984 Ref: AC_SYS_INTERPRETER314344
25985 Ref: AC_SYS_LARGEFILE314720
25986 Ref: AC_SYS_LONG_FILE_NAMES319853
25987 Ref: AC_SYS_YEAR2038320248
25988 Node: C and POSIX Variants320987
25989 Ref: AC_USE_SYSTEM_EXTENSIONS321370
25990 Node: Erlang Libraries325042
25991 Node: Writing Tests330169
25992 Node: Language Choice332136
25993 Ref: AC_LANG332641
25994 Ref: AC_LANG_PUSH334829
25995 Ref: Language Choice-Footnote-1336753
25996 Node: Writing Test Programs336909
25997 Node: Guidelines337487
25998 Node: Test Functions339837
25999 Node: Generating Sources341267
26000 Node: Running the Preprocessor347658
26001 Ref: AC_PREPROC_IFELSE348403
26002 Ref: AC_EGREP_HEADER350729
26003 Ref: AC_EGREP_CPP351209
26004 Node: Running the Compiler352593
26005 Node: Running the Linker354734
26006 Ref: AC_LINK_IFELSE355908
26007 Node: Runtime357158
26008 Ref: AC_RUN_IFELSE357942
26009 Node: Multiple Cases363256
26010 Node: Results365080
26011 Node: Defining Symbols365915
26012 Node: Setting Output Variables370913
26013 Node: Special Chars in Variables377098
26014 Node: Caching Results378394
26015 Node: Cache Variable Names382200
26016 Node: Cache Files383894
26017 Node: Cache Checkpointing386293
26018 Node: Printing Messages387693
26019 Ref: AC_MSG_RESULT389271
26020 Ref: AC_MSG_NOTICE389801
26021 Ref: AC_MSG_ERROR390177
26022 Ref: AC_MSG_WARN391054
26023 Node: Programming in M4391493
26024 Node: M4 Quotation392306
26025 Node: Active Characters393275
26026 Ref: Active Characters-Footnote-1394706
26027 Ref: Active Characters-Footnote-2394836
26028 Node: One Macro Call394862
26029 Node: Quoting and Parameters396452
26030 Node: Quotation and Nested Macros398838
26031 Node: Changequote is Evil401948
26032 Node: Quadrigraphs404571
26033 Node: Balancing Parentheses407401
26034 Node: Quotation Rule Of Thumb412125
26035 Node: Using autom4te415077
26036 Ref: Using autom4te-Footnote-1415744
26037 Node: autom4te Invocation415793
26038 Node: Customizing autom4te424721
26039 Node: Programming in M4sugar426058
26040 Node: Redefined M4 Macros427251
26041 Ref: m4_bpatsubst428828
26042 Ref: m4_bregexp429367
26043 Node: Diagnostic Macros436285
26044 Ref: m4_fatal437048
26045 Ref: m4_warn437292
26046 Node: Diversion support438914
26047 Ref: m4_divert_text445592
26048 Node: Conditional constructs446906
26049 Node: Looping constructs454534
26050 Ref: m4_foreach_w458212
26051 Node: Evaluation Macros465729
26052 Node: Text processing Macros474523
26053 Node: Number processing Macros484365
26054 Ref: m4_version_compare486792
26055 Node: Set manipulation Macros489141
26056 Node: Forbidden Patterns498411
26057 Node: Debugging via autom4te501566
26058 Node: Programming in M4sh503417
26059 Node: Common Shell Constructs504819
26060 Node: Polymorphic Variables513627
26061 Node: Initialization Macros523611
26062 Node: File Descriptor Macros529533
26063 Ref: AS_MESSAGE_LOG_FD530733
26064 Node: Writing Autoconf Macros532301
26065 Node: Macro Definitions533165
26066 Node: Macro Names536933
26067 Node: Dependencies Between Macros540812
26068 Node: Prerequisite Macros541500
26069 Node: Suggested Ordering548237
26070 Node: One-Shot Macros549836
26071 Node: Obsoleting Macros551225
26072 Ref: AU_DEFUN551986
26073 Node: Coding Style554421
26074 Node: Portable Shell562248
26075 Node: Systemology566413
26076 Node: Shellology568894
26077 Node: Invoking the Shell573142
26078 Node: Here-Documents574346
26079 Node: File Descriptors578046
26080 Node: Signal Handling584443
26081 Node: File System Conventions589767
26082 Node: Shell Pattern Matching595851
26083 Node: Shell Substitutions597567
26084 Node: Assignments615504
26085 Node: Parentheses617438
26086 Node: Special Shell Variables618446
26087 Node: Shell Functions632430
26088 Node: Limitations of Builtins635860
26089 Ref: !637642
26090 Ref: case641155
26091 Ref: echo647706
26092 Ref: export654919
26093 Ref: if661096
26094 Ref: set664947
26095 Ref: trap676746
26096 Ref: unset681483
26097 Node: Limitations of Usual Tools682638
26098 Ref: awk682937
26099 Ref: grep701707
26100 Ref: mkdir707852
26101 Ref: sed713874
26102 Ref: touch726163
26103 Node: Portable Make729915
26104 Node: $< in Ordinary Make Rules731638
26105 Node: Failure in Make Rules732124
26106 Node: Command Line Prefixes733322
26107 Node: Special Chars in Names734105
26108 Node: Backslash-Newline-Empty735099
26109 Node: Backslash-Newline Comments735716
26110 Node: Macros and Submakes736613
26111 Node: The Make Macro MAKEFLAGS739445
26112 Node: The Make Macro SHELL740377
26113 Node: Parallel Make742618
26114 Node: Comments in Make Rules746398
26115 Node: Newlines in Make Rules747381
26116 Node: Comments in Make Macros748207
26117 Node: Trailing whitespace in Make Macros749229
26118 Node: Command-line Macros and whitespace750000
26119 Node: obj/ and Make750652
26120 Node: make -k Status751321
26121 Node: VPATH and Make751951
26122 Node: Variables listed in VPATH753282
26123 Node: VPATH and Double-colon753845
26124 Node: $< in Explicit Rules754267
26125 Node: Automatic Rule Rewriting754746
26126 Node: Make Target Lookup760426
26127 Node: Single Suffix Rules764700
26128 Node: Timestamps and Make766070
26129 Node: Portable C and C++768208
26130 Node: Varieties of Unportability770032
26131 Node: Integer Overflow772145
26132 Node: Integer Overflow Basics772969
26133 Node: Signed Overflow Examples774993
26134 Node: Optimization and Wraparound778373
26135 Node: Signed Overflow Advice781217
26136 Node: Signed Integer Division784363
26137 Node: Preprocessor Arithmetic784912
26138 Node: Null Pointers785711
26139 Node: Buffer Overruns786361
26140 Node: Volatile Objects789302
26141 Node: Floating Point Portability794299
26142 Node: Exiting Portably794809
26143 Node: Manual Configuration796114
26144 Node: Specifying Target Triplets797392
26145 Ref: Specifying Names797565
26146 Node: Canonicalizing801172
26147 Node: Using System Type803314
26148 Node: Site Configuration806167
26149 Node: Help Formatting807159
26150 Node: External Software808128
26151 Ref: AC_ARG_WITH809734
26152 Node: Package Options814585
26153 Ref: AC_ARG_ENABLE816092
26154 Node: Pretty Help Strings817738
26155 Ref: AS_HELP_STRING818352
26156 Node: Option Checking820721
26157 Node: Site Details822535
26158 Node: Transforming Names823772
26159 Node: Transformation Options824887
26160 Node: Transformation Examples825384
26161 Node: Transformation Rules827182
26162 Node: Site Defaults828760
26163 Node: Running configure Scripts834351
26164 Node: Basic Installation835444
26165 Node: Installation Prerequisites840573
26166 Node: Compilers and Options841148
26167 Node: Multiple Architectures841857
26168 Node: Installation Names843037
26169 Node: Optional Features846031
26170 Node: System Types847228
26171 Node: Sharing Defaults849515
26172 Node: Defining Variables850195
26173 Node: configure Invocation851113
26174 Node: config.status Invocation853304
26175 Ref: CONFIG_SHELL857204
26176 Node: Obsolete Constructs858410
26177 Node: Obsolete config.status Use859385
26178 Node: acconfig Header861243
26179 Node: autoupdate Invocation863378
26180 Node: Obsolete Macros865350
26181 Ref: AC_FUNC_SETVBUF_REVERSED873458
26182 Ref: AC_HEADER_TIME875647
26183 Ref: AC_PROG_GCC_TRADITIONAL883877
26184 Ref: AC_TYPE_SIGNAL891820
26185 Node: Autoconf 1894876
26186 Node: Changed File Names895960
26187 Node: Changed Makefiles896758
26188 Node: Changed Macros897906
26189 Node: Changed Results899203
26190 Node: Changed Macro Writing901374
26191 Node: Autoconf 2.13902682
26192 Node: Changed Quotation903904
26193 Node: New Macros905836
26194 Node: Hosts and Cross-Compilation907667
26195 Node: AC_LIBOBJ vs LIBOBJS912007
26196 Node: AC_ACT_IFELSE vs AC_TRY_ACT913698
26197 Ref: AC_FOO_IFELSE vs AC_TRY_FOO913895
26198 Node: Using Autotest915777
26199 Node: Using an Autotest Test Suite918175
26200 Node: testsuite Scripts918466
26201 Node: Autotest Logs923066
26202 Node: Writing Testsuites925451
26203 Node: testsuite Invocation945641
26204 Node: Making testsuite Scripts951254
26205 Node: FAQ957285
26206 Node: Distributing958161
26207 Node: Why GNU M4959244
26208 Node: Bootstrapping960160
26209 Node: Why Not Imake960782
26210 Node: Defining Directories965600
26211 Node: Autom4te Cache967811
26212 Node: Present But Cannot Be Compiled969757
26213 Node: Expanded Before Required972651
26214 Node: Debugging977695
26215 Node: History982834
26216 Node: Genesis983709
26217 Node: Exodus984916
26218 Node: Leviticus988033
26219 Node: Numbers989571
26220 Node: Deuteronomy991528
26221 Node: GNU Free Documentation License994266
26222 Node: Indices1019617
26223 Node: Environment Variable Index1020336
26224 Node: Output Variable Index1032371
26225 Node: Preprocessor Symbol Index1050175
26226 Node: Cache Variable Index1071643
26227 Node: Autoconf Macro Index1082895
26228 Node: M4 Macro Index1117944
26229 Node: Autotest Macro Index1138694
26230 Node: Program & Function Index1141243
26231 Node: Concept Index1163752
26232 
26233 End Tag Table
26234
26235 
26236 Local Variables:
26237 coding: utf-8
26238 End: