| 1 |
This is autoconf.info, produced by makeinfo version 7.1.1 from |
| 2 |
autoconf.texi. |
| 3 |
|
| 4 |
INFO-DIR-SECTION GNU admin |
| 5 |
START-INFO-DIR-ENTRY |
| 6 |
* Autoconf: (autoconf). Create source code configuration scripts |
| 7 |
END-INFO-DIR-ENTRY |
| 8 |
|
| 9 |
INFO-DIR-SECTION Individual utilities |
| 10 |
START-INFO-DIR-ENTRY |
| 11 |
* autoscan: (autoconf)autoscan Invocation. |
| 12 |
Semi-automatic ‘configure.ac’ writing |
| 13 |
* ifnames: (autoconf)ifnames Invocation. |
| 14 |
Listing the conditionals in source code |
| 15 |
* autoconf: (autoconf)autoconf Invocation. |
| 16 |
How to create configuration scripts |
| 17 |
* autoreconf: (autoconf)autoreconf Invocation. |
| 18 |
Remaking multiple ‘configure’ scripts |
| 19 |
* configure: (autoconf)configure Invocation. |
| 20 |
Configuring a package |
| 21 |
* config.status: (autoconf)config.status Invocation. |
| 22 |
Recreating a configuration |
| 23 |
END-INFO-DIR-ENTRY |
| 24 |
|
| 25 |
Autoconf: Creating Automatic Configuration Scripts, by David MacKenzie. |
| 26 |
|
| 27 |
This file documents the GNU Autoconf package for creating scripts to |
| 28 |
configure source code packages using templates and an ‘m4’ macro |
| 29 |
package. |
| 30 |
|
| 31 |
Copyright 2003-2023,2025 Thomas E. Dickey |
| 32 |
Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 Free |
| 33 |
Software Foundation, Inc. |
| 34 |
|
| 35 |
Permission is granted to make and distribute verbatim copies of this |
| 36 |
manual provided the copyright notice and this permission notice are |
| 37 |
preserved on all copies. |
| 38 |
|
| 39 |
Permission is granted to copy and distribute modified versions of |
| 40 |
this manual under the conditions for verbatim copying, provided that the |
| 41 |
entire resulting derived work is distributed under the terms of a |
| 42 |
permission notice identical to this one. |
| 43 |
|
| 44 |
Permission is granted to copy and distribute translations of this |
| 45 |
manual into another language, under the above conditions for modified |
| 46 |
versions, except that this permission notice may be stated in a |
| 47 |
translation approved by the Foundation. |
| 48 |
|
| 49 |
|
| 50 |
File: autoconf.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) |
| 51 |
|
| 52 |
This file documents the GNU Autoconf package for creating scripts to |
| 53 |
configure source code packages using templates and the GNU M4 macro |
| 54 |
package. This is edition 2.52.20260412, for Autoconf version |
| 55 |
2.52.20260412. |
| 56 |
|
| 57 |
* Menu: |
| 58 |
|
| 59 |
* Introduction:: Autoconf's purpose, strengths, and weaknesses |
| 60 |
* The GNU build system:: A set of tools for portable software packages |
| 61 |
* Making configure Scripts:: How to organize and produce Autoconf scripts |
| 62 |
* Setup:: Initialization and output |
| 63 |
* Existing Tests:: Macros that check for particular features |
| 64 |
* Writing Tests:: How to write new feature checks |
| 65 |
* Results:: What to do with results from feature checks |
| 66 |
* Programming in M4:: Layers on top of which Autoconf is written |
| 67 |
* Writing Autoconf Macros:: Adding new macros to Autoconf |
| 68 |
* Portable Shell:: Shell script portability pitfalls |
| 69 |
* Manual Configuration:: Selecting features that can't be guessed |
| 70 |
* Site Configuration:: Local defaults for ‘configure’ |
| 71 |
* Running configure scripts:: How to use the Autoconf output |
| 72 |
* config.status Invocation:: Recreating a configuration |
| 73 |
* Obsolete Constructs:: Kept for backward compatibility |
| 74 |
* Questions:: Questions about Autoconf, with answers |
| 75 |
* History:: History of Autoconf |
| 76 |
* Environment Variable Index:: Index of environment variables used |
| 77 |
* Output Variable Index:: Index of variables set in output files |
| 78 |
* Preprocessor Symbol Index:: Index of C preprocessor symbols defined |
| 79 |
* Autoconf Macro Index:: Index of Autoconf macros |
| 80 |
* M4 Macro Index:: Index of M4, M4sugar, and M4sh macros |
| 81 |
* Concept Index:: General index |
| 82 |
|
| 83 |
-- The Detailed Node Listing -- |
| 84 |
|
| 85 |
The GNU build system |
| 86 |
|
| 87 |
* Automake:: Escaping Makefile hell |
| 88 |
* Libtool:: Building libraries portably |
| 89 |
* Pointers:: More info on the GNU build system |
| 90 |
|
| 91 |
Making ‘configure’ Scripts |
| 92 |
|
| 93 |
* Writing configure.ac:: What to put in an Autoconf input file |
| 94 |
* autoscan Invocation:: Semi-automatic ‘configure.ac’ writing |
| 95 |
* ifnames Invocation:: Listing the conditionals in source code |
| 96 |
* autoconf Invocation:: How to create configuration scripts |
| 97 |
* autoreconf Invocation:: Remaking multiple ‘configure’ scripts |
| 98 |
|
| 99 |
Writing ‘configure.ac’ |
| 100 |
|
| 101 |
* Shell Script Compiler:: Autoconf as solution of a problem |
| 102 |
* Autoconf Language:: Programming in Autoconf |
| 103 |
* configure.ac Layout:: Standard organization of configure.ac |
| 104 |
|
| 105 |
Initialization and Output Files |
| 106 |
|
| 107 |
* Notices:: Copyright, version numbers in ‘configure’ |
| 108 |
* Input:: Where Autoconf should find files |
| 109 |
* Output:: Outputting results from the configuration |
| 110 |
* Configuration Actions:: Preparing the output based on results |
| 111 |
* Configuration Files:: Creating output files |
| 112 |
* Makefile Substitutions:: Using output variables in ‘Makefile’s |
| 113 |
* Configuration Headers:: Creating a configuration header file |
| 114 |
* Configuration Commands:: Running arbitrary instantiation commands |
| 115 |
* Configuration Links:: Links depending from the configuration |
| 116 |
* Subdirectories:: Configuring independent packages together |
| 117 |
* Default Prefix:: Changing the default installation prefix |
| 118 |
|
| 119 |
Substitutions in Makefiles |
| 120 |
|
| 121 |
* Preset Output Variables:: Output variables that are always set |
| 122 |
* Installation Directory Variables:: Other preset output variables |
| 123 |
* Build Directories:: Supporting multiple concurrent compiles |
| 124 |
* Automatic Remaking:: Makefile rules for configuring |
| 125 |
|
| 126 |
Configuration Header Files |
| 127 |
|
| 128 |
* Header Templates:: Input for the configuration headers |
| 129 |
* autoheader Invocation:: How to create configuration templates |
| 130 |
* Autoheader Macros:: How to specify CPP templates |
| 131 |
|
| 132 |
Existing Tests |
| 133 |
|
| 134 |
* Common Behavior:: Macros' standard schemes |
| 135 |
* Alternative Programs:: Selecting between alternative programs |
| 136 |
* Files:: Checking for the existence of files |
| 137 |
* Libraries:: Library archives that might be missing |
| 138 |
* Library Functions:: C library functions that might be missing |
| 139 |
* Header Files:: Header files that might be missing |
| 140 |
* Declarations:: Declarations that may be missing |
| 141 |
* Structures:: Structures or members that might be missing |
| 142 |
* Types:: Types that might be missing |
| 143 |
* Compilers and Preprocessors:: Checking for compiling programs |
| 144 |
* System Services:: Operating system services |
| 145 |
* UNIX Variants:: Special kludges for specific UNIX variants |
| 146 |
|
| 147 |
Common Behavior |
| 148 |
|
| 149 |
* Standard Symbols:: Symbols defined by the macros |
| 150 |
* Default Includes:: Includes used by the generic macros |
| 151 |
|
| 152 |
Alternative Programs |
| 153 |
|
| 154 |
* Particular Programs:: Special handling to find certain programs |
| 155 |
* Generic Programs:: How to find other programs |
| 156 |
|
| 157 |
Library Functions |
| 158 |
|
| 159 |
* Function Portability:: Pitfalls with usual functions |
| 160 |
* Particular Functions:: Special handling to find certain functions |
| 161 |
* Generic Functions:: How to find other functions |
| 162 |
|
| 163 |
Header Files |
| 164 |
|
| 165 |
* Particular Headers:: Special handling to find certain headers |
| 166 |
* Generic Headers:: How to find other headers |
| 167 |
|
| 168 |
Declarations |
| 169 |
|
| 170 |
* Particular Declarations:: Macros to check for certain declarations |
| 171 |
* Generic Declarations:: How to find other declarations |
| 172 |
|
| 173 |
Structures |
| 174 |
|
| 175 |
* Particular Structures:: Macros to check for certain structure members |
| 176 |
* Generic Structures:: How to find other structure members |
| 177 |
|
| 178 |
Types |
| 179 |
|
| 180 |
* Particular Types:: Special handling to find certain types |
| 181 |
* Generic Types:: How to find other types |
| 182 |
|
| 183 |
Compilers and Preprocessors |
| 184 |
|
| 185 |
* Generic Compiler Characteristics:: Language independent tests |
| 186 |
* C Compiler:: Checking its characteristics |
| 187 |
* C++ Compiler:: Likewise |
| 188 |
* Fortran 77 Compiler:: Likewise |
| 189 |
|
| 190 |
Writing Tests |
| 191 |
|
| 192 |
* Examining Declarations:: Detecting header files and declarations |
| 193 |
* Examining Syntax:: Detecting language syntax features |
| 194 |
* Examining Libraries:: Detecting functions and global variables |
| 195 |
* Run Time:: Testing for run-time features |
| 196 |
* Systemology:: A zoology of operating systems |
| 197 |
* Multiple Cases:: Tests for several possible values |
| 198 |
* Language Choice:: Selecting which language to use for testing |
| 199 |
|
| 200 |
Checking Run Time Behavior |
| 201 |
|
| 202 |
* Test Programs:: Running test programs |
| 203 |
* Guidelines:: General rules for writing test programs |
| 204 |
* Test Functions:: Avoiding pitfalls in test programs |
| 205 |
|
| 206 |
Results of Tests |
| 207 |
|
| 208 |
* Defining Symbols:: Defining C preprocessor symbols |
| 209 |
* Setting Output Variables:: Replacing variables in output files |
| 210 |
* Caching Results:: Speeding up subsequent ‘configure’ runs |
| 211 |
* Printing Messages:: Notifying ‘configure’ users |
| 212 |
|
| 213 |
Caching Results |
| 214 |
|
| 215 |
* Cache Variable Names:: Shell variables used in caches |
| 216 |
* Cache Files:: Files ‘configure’ uses for caching |
| 217 |
* Cache Checkpointing:: Loading and saving the cache file |
| 218 |
|
| 219 |
Programming in M4 |
| 220 |
|
| 221 |
* M4 Quotation:: Protecting macros from unwanted expansion |
| 222 |
* Programming in M4sugar:: Convenient pure M4 macros |
| 223 |
|
| 224 |
M4 Quotation |
| 225 |
|
| 226 |
* Active Characters:: Characters that change the behavior of m4 |
| 227 |
* One Macro Call:: Quotation and one macro call |
| 228 |
* Quotation and Nested Macros:: Macros calling macros |
| 229 |
* Quadrigraphs:: Another way to escape special characters |
| 230 |
* Quotation Rule Of Thumb:: One parenthesis, one quote |
| 231 |
|
| 232 |
Programming in M4sugar |
| 233 |
|
| 234 |
* Redefined M4 Macros:: M4 builtins changed in M4sugar |
| 235 |
* Forbidden Patterns:: Catching unexpanded macros |
| 236 |
|
| 237 |
Writing Autoconf Macros |
| 238 |
|
| 239 |
* Macro Definitions:: Basic format of an Autoconf macro |
| 240 |
* Macro Names:: What to call your new macros |
| 241 |
* Reporting Messages:: Notifying ‘autoconf’ users |
| 242 |
* Dependencies Between Macros:: What to do when macros depend on other macros |
| 243 |
* Obsoleting Macros:: Warning about old ways of doing things |
| 244 |
* Coding Style:: Writing Autoconf macros à la Autoconf |
| 245 |
|
| 246 |
Dependencies Between Macros |
| 247 |
|
| 248 |
* Prerequisite Macros:: Ensuring required information |
| 249 |
* Suggested Ordering:: Warning about possible ordering problems |
| 250 |
|
| 251 |
Portable Shell Programming |
| 252 |
|
| 253 |
* Shellology:: A zoology of shells |
| 254 |
* Here-Documents:: Quirks and tricks |
| 255 |
* File Descriptors:: FDs and redirections |
| 256 |
* File System Conventions:: File- and pathnames |
| 257 |
* Shell Substitutions:: Variable and command expansions |
| 258 |
* Assignments:: Varying side effects of assignments |
| 259 |
* Special Shell Variables:: Variables you should not change |
| 260 |
* Limitations of Builtins:: Portable use of not so portable /bin/sh |
| 261 |
* Limitations of Usual Tools:: Portable use of portable tools |
| 262 |
* Limitations of Make:: Portable Makefiles |
| 263 |
|
| 264 |
Manual Configuration |
| 265 |
|
| 266 |
* Specifying Names:: Specifying the system type |
| 267 |
* Canonicalizing:: Getting the canonical system type |
| 268 |
* Using System Type:: What to do with the system type |
| 269 |
|
| 270 |
Site Configuration |
| 271 |
|
| 272 |
* External Software:: Working with other optional software |
| 273 |
* Package Options:: Selecting optional features |
| 274 |
* Pretty Help Strings:: Formatting help string |
| 275 |
* Site Details:: Configuring site details |
| 276 |
* Transforming Names:: Changing program names when installing |
| 277 |
* Site Defaults:: Giving ‘configure’ local defaults |
| 278 |
|
| 279 |
Transforming Program Names When Installing |
| 280 |
|
| 281 |
* Transformation Options:: ‘configure’ options to transform names |
| 282 |
* Transformation Examples:: Sample uses of transforming names |
| 283 |
* Transformation Rules:: ‘Makefile’ uses of transforming names |
| 284 |
|
| 285 |
Running ‘configure’ Scripts |
| 286 |
|
| 287 |
* Basic Installation:: Instructions for typical cases |
| 288 |
* Compilers and Options:: Selecting compilers and optimization |
| 289 |
* Multiple Architectures:: Compiling for multiple architectures at once |
| 290 |
* Installation Names:: Installing in different directories |
| 291 |
* Optional Features:: Selecting optional features |
| 292 |
* System Type:: Specifying the system type |
| 293 |
* Sharing Defaults:: Setting site-wide defaults for ‘configure’ |
| 294 |
* Environment Variables:: Defining environment variables. |
| 295 |
* configure Invocation:: Changing how ‘configure’ runs |
| 296 |
|
| 297 |
Obsolete Constructs |
| 298 |
|
| 299 |
* Obsolete config.status Use:: Different calling convention |
| 300 |
* acconfig.h:: Additional entries in ‘config.h.in’ |
| 301 |
* autoupdate Invocation:: Automatic update of ‘configure.ac’ |
| 302 |
* Obsolete Macros:: Backward compatibility macros |
| 303 |
* Autoconf 1:: Tips for upgrading your files |
| 304 |
* Autoconf 2.13:: Some fresher tips |
| 305 |
|
| 306 |
Upgrading From Version 1 |
| 307 |
|
| 308 |
* Changed File Names:: Files you might rename |
| 309 |
* Changed Makefiles:: New things to put in ‘Makefile.in’ |
| 310 |
* Changed Macros:: Macro calls you might replace |
| 311 |
* Changed Results:: Changes in how to check test results |
| 312 |
* Changed Macro Writing:: Better ways to write your own macros |
| 313 |
|
| 314 |
Upgrading From Version 2.13 |
| 315 |
|
| 316 |
* Changed Quotation:: Broken code which used to work |
| 317 |
* New Macros:: Interaction with foreign macros |
| 318 |
|
| 319 |
Questions About Autoconf |
| 320 |
|
| 321 |
* Distributing:: Distributing ‘configure’ scripts |
| 322 |
* Why GNU m4:: Why not use the standard M4? |
| 323 |
* Bootstrapping:: Autoconf and GNU M4 require each other? |
| 324 |
* Why Not Imake:: Why GNU uses ‘configure’ instead of Imake |
| 325 |
|
| 326 |
History of Autoconf |
| 327 |
|
| 328 |
* Genesis:: Prehistory and naming of ‘configure’ |
| 329 |
* Exodus:: The plagues of M4 and Perl |
| 330 |
* Leviticus:: The priestly code of portability arrives |
| 331 |
* Numbers:: Growth and contributors |
| 332 |
* Deuteronomy:: Approaching the promises of easy configuration |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
File: autoconf.info, Node: Introduction, Next: The GNU build system, Prev: Top, Up: Top |
| 337 |
|
| 338 |
1 Introduction |
| 339 |
************** |
| 340 |
|
| 341 |
A physicist, an engineer, and a computer scientist were discussing the |
| 342 |
nature of God. "Surely a Physicist," said the physicist, "because |
| 343 |
early in the Creation, God made Light; and you know, Maxwell's |
| 344 |
equations, the dual nature of electromagnetic waves, the relativistic |
| 345 |
consequences..." "An Engineer!," said the engineer, "because |
| 346 |
before making Light, God split the Chaos into Land and Water; it takes a |
| 347 |
hell of an engineer to handle that big amount of mud, and orderly |
| 348 |
separation of solids from liquids..." The computer scientist |
| 349 |
shouted: "And the Chaos, where do you think it was coming from, hmm?" |
| 350 |
|
| 351 |
--Anonymous |
| 352 |
|
| 353 |
Autoconf is a tool for producing shell scripts that automatically |
| 354 |
configure software source code packages to adapt to many kinds of |
| 355 |
UNIX-like systems. The configuration scripts produced by Autoconf are |
| 356 |
independent of Autoconf when they are run, so their users do not need to |
| 357 |
have Autoconf. |
| 358 |
|
| 359 |
The configuration scripts produced by Autoconf require no manual user |
| 360 |
intervention when run; they do not normally even need an argument |
| 361 |
specifying the system type. Instead, they individually test for the |
| 362 |
presence of each feature that the software package they are for might |
| 363 |
need. (Before each check, they print a one-line message stating what |
| 364 |
they are checking for, so the user doesn't get too bored while waiting |
| 365 |
for the script to finish.) As a result, they deal well with systems |
| 366 |
that are hybrids or customized from the more common UNIX variants. |
| 367 |
There is no need to maintain files that list the features supported by |
| 368 |
each release of each variant of UNIX. |
| 369 |
|
| 370 |
For each software package that Autoconf is used with, it creates a |
| 371 |
configuration script from a template file that lists the system features |
| 372 |
that the package needs or can use. After the shell code to recognize |
| 373 |
and respond to a system feature has been written, Autoconf allows it to |
| 374 |
be shared by many software packages that can use (or need) that feature. |
| 375 |
If it later turns out that the shell code needs adjustment for some |
| 376 |
reason, it needs to be changed in only one place; all of the |
| 377 |
configuration scripts can be regenerated automatically to take advantage |
| 378 |
of the updated code. |
| 379 |
|
| 380 |
The Metaconfig package is similar in purpose to Autoconf, but the |
| 381 |
scripts it produces require manual user intervention, which is quite |
| 382 |
inconvenient when configuring large source trees. Unlike Metaconfig |
| 383 |
scripts, Autoconf scripts can support cross-compiling, if some care is |
| 384 |
taken in writing them. |
| 385 |
|
| 386 |
Autoconf does not solve all problems related to making portable |
| 387 |
software packages--for a more complete solution, it should be used in |
| 388 |
concert with other GNU build tools like Automake and Libtool. These |
| 389 |
other tools take on jobs like the creation of a portable, recursive |
| 390 |
‘Makefile’ with all of the standard targets, linking of shared |
| 391 |
libraries, and so on. *Note The GNU build system::, for more |
| 392 |
information. |
| 393 |
|
| 394 |
Autoconf imposes some restrictions on the names of macros used with |
| 395 |
‘#if’ in C programs (*note Preprocessor Symbol Index::). |
| 396 |
|
| 397 |
Autoconf requires GNU M4 in order to generate the scripts. It uses |
| 398 |
features that some UNIX versions of M4, including GNU M4 1.3, do not |
| 399 |
have. You must use version 1.4 or later of GNU M4. |
| 400 |
|
| 401 |
*Note Autoconf 1::, for information about upgrading from version 1. |
| 402 |
*Note History::, for the story of Autoconf's development. *Note |
| 403 |
Questions::, for answers to some common questions about Autoconf. |
| 404 |
|
| 405 |
See the Autoconf web page(1) for up-to-date information, details on |
| 406 |
the mailing lists, pointers to a list of known bugs, etc. |
| 407 |
|
| 408 |
Mail suggestions to the Autoconf mailing list <[email protected]>. |
| 409 |
|
| 410 |
Bug reports should be preferably submitted to the Autoconf Gnats |
| 411 |
database(2), or sent to the Autoconf Bugs mailing list |
| 412 |
<[email protected]>. If possible, first check that your bug is not |
| 413 |
already solved in current development versions, and that it has not been |
| 414 |
reported yet. Be sure to include all the needed information and a short |
| 415 |
‘configure.ac’ that demonstrates the problem. |
| 416 |
|
| 417 |
Autoconf's development tree is accessible via CVS; see the Autoconf |
| 418 |
web page for details. There is also a CVSweb interface to the Autoconf |
| 419 |
development tree(3). Patches relative to the current CVS version can be |
| 420 |
sent for review to the Autoconf Patches mailing list |
| 421 |
<[email protected]>. |
| 422 |
|
| 423 |
Because of its mission, Autoconf includes only a set of often-used |
| 424 |
macros that have already demonstrated their usefulness. Nevertheless, |
| 425 |
if you wish to share your macros, or find existing ones, see the |
| 426 |
Autoconf Macro Archive(4), which is kindly run by Peter Simons |
| 427 |
<[email protected]>. |
| 428 |
|
| 429 |
---------- Footnotes ---------- |
| 430 |
|
| 431 |
(1) Autoconf web page, |
| 432 |
<http://www.gnu.org/software/autoconf/autoconf.html>. |
| 433 |
|
| 434 |
(2) Autoconf Gnats database, |
| 435 |
<http://sources.redhat.com/cgi-bin/gnatsweb.pl?database=autoconf>. |
| 436 |
|
| 437 |
(3) CVSweb interface to the Autoconf development tree, |
| 438 |
<http://subversions.gnu.org/cgi-bin/cvsweb/autoconf/>. |
| 439 |
|
| 440 |
(4) Autoconf Macro Archive, |
| 441 |
<http://www.gnu.org/software/ac-archive/>. |
| 442 |
|
| 443 |
|
| 444 |
File: autoconf.info, Node: The GNU build system, Next: Making configure Scripts, Prev: Introduction, Up: Top |
| 445 |
|
| 446 |
2 The GNU build system |
| 447 |
********************** |
| 448 |
|
| 449 |
Autoconf solves an important problem--reliable discovery of |
| 450 |
system-specific build and runtime information--but this is only one |
| 451 |
piece of the puzzle for the development of portable software. To this |
| 452 |
end, the GNU project has developed a suite of integrated utilities to |
| 453 |
finish the job Autoconf started: the GNU build system, whose most |
| 454 |
important components are Autoconf, Automake, and Libtool. In this |
| 455 |
chapter, we introduce you to those tools, point you to sources of more |
| 456 |
information, and try to convince you to use the entire GNU build system |
| 457 |
for your software. |
| 458 |
|
| 459 |
* Menu: |
| 460 |
|
| 461 |
* Automake:: Escaping Makefile hell |
| 462 |
* Libtool:: Building libraries portably |
| 463 |
* Pointers:: More info on the GNU build system |
| 464 |
|
| 465 |
|
| 466 |
File: autoconf.info, Node: Automake, Next: Libtool, Prev: The GNU build system, Up: The GNU build system |
| 467 |
|
| 468 |
2.1 Automake |
| 469 |
============ |
| 470 |
|
| 471 |
The ubiquity of ‘make’ means that a ‘Makefile’ is almost the only viable |
| 472 |
way to distribute automatic build rules for software, but one quickly |
| 473 |
runs into ‘make’'s numerous limitations. Its lack of support for |
| 474 |
automatic dependency tracking, recursive builds in subdirectories, |
| 475 |
reliable timestamps (e.g. for network filesystems), and so on, mean |
| 476 |
that developers must painfully (and often incorrectly) reinvent the |
| 477 |
wheel for each project. Portability is non-trivial, thanks to the |
| 478 |
quirks of ‘make’ on many systems. On top of all this is the manual |
| 479 |
labor required to implement the many standard targets that users have |
| 480 |
come to expect (‘make install’, ‘make distclean’, ‘make uninstall’, |
| 481 |
etc.). Since you are, of course, using Autoconf, you also have to |
| 482 |
insert repetitive code in your ‘Makefile.in’ to recognize ‘@CC@’, |
| 483 |
‘@CFLAGS@’, and other substitutions provided by ‘configure’. Into this |
| 484 |
mess steps “Automake”. |
| 485 |
|
| 486 |
Automake allows you to specify your build needs in a ‘Makefile.am’ |
| 487 |
file with a vastly simpler and more powerful syntax than that of a plain |
| 488 |
‘Makefile’, and then generates a portable ‘Makefile.in’ for use with |
| 489 |
Autoconf. For example, the ‘Makefile.am’ to build and install a simple |
| 490 |
"Hello world" program might look like: |
| 491 |
|
| 492 |
bin_PROGRAMS = hello |
| 493 |
hello_SOURCES = hello.c |
| 494 |
|
| 495 |
The resulting ‘Makefile.in’ (~400 lines) automatically supports all the |
| 496 |
standard targets, the substitutions provided by Autoconf, automatic |
| 497 |
dependency tracking, ‘VPATH’ building, and so on. ‘make’ will build the |
| 498 |
‘hello’ program, and ‘make install’ will install it in ‘/usr/local/bin’ |
| 499 |
(or whatever prefix was given to ‘configure’, if not ‘/usr/local’). |
| 500 |
|
| 501 |
Automake may require that additional tools be present on the |
| 502 |
_developer's_ machine. For example, the ‘Makefile.in’ that the |
| 503 |
developer works with may not be portable (e.g. it might use special |
| 504 |
features of your compiler to automatically generate dependency |
| 505 |
information). Running ‘make dist’, however, produces a |
| 506 |
‘hello-1.0.tar.gz’ package (or whatever the program/version is) with a |
| 507 |
‘Makefile.in’ that will work on any system. |
| 508 |
|
| 509 |
The benefits of Automake increase for larger packages (especially |
| 510 |
ones with subdirectories), but even for small programs the added |
| 511 |
convenience and portability can be substantial. And that's not all... |
| 512 |
|
| 513 |
|
| 514 |
File: autoconf.info, Node: Libtool, Next: Pointers, Prev: Automake, Up: The GNU build system |
| 515 |
|
| 516 |
2.2 Libtool |
| 517 |
=========== |
| 518 |
|
| 519 |
Very often, one wants to build not only programs, but libraries, so that |
| 520 |
other programs can benefit from the fruits of your labor. Ideally, one |
| 521 |
would like to produce _shared_ (dynamically-linked) libraries, which can |
| 522 |
be used by multiple programs without duplication on disk or in memory |
| 523 |
and can be updated independently of the linked programs. Producing |
| 524 |
shared libraries portably, however, is the stuff of nightmares--each |
| 525 |
system has its own incompatible tools, compiler flags, and magic |
| 526 |
incantations. Fortunately, GNU provides a solution: “Libtool”. |
| 527 |
|
| 528 |
Libtool handles all the requirements of building shared libraries for |
| 529 |
you, and at this time seems to be the _only_ way to do so with any |
| 530 |
portability. It also handles many other headaches, such as: the |
| 531 |
interaction of ‘Makefile’ rules with the variable suffixes of shared |
| 532 |
libraries, linking reliably to shared libraries before they are |
| 533 |
installed by the superuser, and supplying a consistent versioning system |
| 534 |
(so that different versions of a library can be installed or upgraded |
| 535 |
without breaking binary compatibility). Although Libtool, like |
| 536 |
Autoconf, can be used on its own, it is most simply utilized in |
| 537 |
conjunction with Automake--there, Libtool is used automatically whenever |
| 538 |
shared libraries are needed, and you need not know its syntax. |
| 539 |
|
| 540 |
|
| 541 |
File: autoconf.info, Node: Pointers, Prev: Libtool, Up: The GNU build system |
| 542 |
|
| 543 |
2.3 Pointers |
| 544 |
============ |
| 545 |
|
| 546 |
Developers who are used to the simplicity of ‘make’ for small projects |
| 547 |
on a single system might be daunted at the prospect of learning to use |
| 548 |
Automake and Autoconf. As your software is distributed to more and more |
| 549 |
users, however, you will otherwise quickly find yourself putting lots of |
| 550 |
effort into reinventing the services that the GNU build tools provide, |
| 551 |
and making the same mistakes that they once made and overcame. |
| 552 |
(Besides, since you're already learning Autoconf, Automake will be a |
| 553 |
piece of cake.) |
| 554 |
|
| 555 |
There are a number of places that you can go to for more information |
| 556 |
on the GNU build tools. |
| 557 |
|
| 558 |
− Web |
| 559 |
|
| 560 |
The home pages for Autoconf(1), and Libtool(2). |
| 561 |
|
| 562 |
− Books |
| 563 |
|
| 564 |
The book ‘GNU Autoconf, Automake and Libtool’(3) describes the |
| 565 |
complete GNU build environment. You can also find the entire book |
| 566 |
on-line at "The Goat Book" home page(4). |
| 567 |
|
| 568 |
− Tutorials and Examples |
| 569 |
|
| 570 |
The Autoconf Developer Page(5) maintains links to a number of |
| 571 |
Autoconf/Automake tutorials online, and also links to the Autoconf |
| 572 |
Macro Archive(6). |
| 573 |
|
| 574 |
---------- Footnotes ---------- |
| 575 |
|
| 576 |
(1) Autoconf, <http://www.gnu.org/software/autoconf/>. |
| 577 |
|
| 578 |
(2) Libtool, <http://www.gnu.org/software/libtool/>. |
| 579 |
|
| 580 |
(3) ‘GNU Autoconf, Automake and Libtool’, by G. V. Vaughan, B. |
| 581 |
Elliston, T. Tromey, and I. L. Taylor. New Riders, 2000, ISBN |
| 582 |
1578701902. |
| 583 |
|
| 584 |
(4) "The Goat Book" home page, <http://sources.redhat.com/autobook/>. |
| 585 |
|
| 586 |
(5) Autoconf Developer Page, <http://sources.redhat.com/autoconf/>. |
| 587 |
|
| 588 |
(6) Autoconf Macro Archive, |
| 589 |
<http://www.gnu.org/software/ac-archive/>. |
| 590 |
|
| 591 |
|
| 592 |
File: autoconf.info, Node: Making configure Scripts, Next: Setup, Prev: The GNU build system, Up: Top |
| 593 |
|
| 594 |
3 Making ‘configure’ Scripts |
| 595 |
**************************** |
| 596 |
|
| 597 |
The configuration scripts that Autoconf produces are by convention |
| 598 |
called ‘configure’. When run, ‘configure’ creates several files, |
| 599 |
replacing configuration parameters in them with appropriate values. The |
| 600 |
files that ‘configure’ creates are: |
| 601 |
|
| 602 |
− one or more ‘Makefile’ files, one in each subdirectory of the |
| 603 |
package (*note Makefile Substitutions::); |
| 604 |
|
| 605 |
− optionally, a C header file, the name of which is configurable, |
| 606 |
containing ‘#define’ directives (*note Configuration Headers::); |
| 607 |
|
| 608 |
− a shell script called ‘config.status’ that, when run, will recreate |
| 609 |
the files listed above (*note config.status Invocation::); |
| 610 |
|
| 611 |
− an optional shell script normally called ‘config.cache’ (created |
| 612 |
when using ‘configure --config-cache’) that saves the results of |
| 613 |
running many of the tests (*note Cache Files::); |
| 614 |
|
| 615 |
− a file called ‘config.log’ containing any messages produced by |
| 616 |
compilers, to help debugging if ‘configure’ makes a mistake. |
| 617 |
|
| 618 |
To create a ‘configure’ script with Autoconf, you need to write an |
| 619 |
Autoconf input file ‘configure.ac’ (or ‘configure.in’) and run |
| 620 |
‘autoconf’ on it. If you write your own feature tests to supplement |
| 621 |
those that come with Autoconf, you might also write files called |
| 622 |
‘aclocal.m4’ and ‘acsite.m4’. If you use a C header file to contain |
| 623 |
‘#define’ directives, you might also run ‘autoheader’, and you will |
| 624 |
distribute the generated file ‘config.h.in’ with the package. |
| 625 |
|
| 626 |
Here is a diagram showing how the files that can be used in |
| 627 |
configuration are produced. Programs that are executed are suffixed by |
| 628 |
‘*’. Optional files are enclosed in square brackets (‘[]’). ‘autoconf’ |
| 629 |
and ‘autoheader’ also read the installed Autoconf macro files (by |
| 630 |
reading ‘autoconf.m4’). |
| 631 |
|
| 632 |
Files used in preparing a software package for distribution: |
| 633 |
your source files --> [autoscan*] --> [configure.scan] --> configure.ac |
| 634 |
|
| 635 |
configure.ac --. |
| 636 |
| .------> autoconf* -----> configure |
| 637 |
[aclocal.m4] --+---+ |
| 638 |
| `-----> [autoheader*] --> [config.h.in] |
| 639 |
[acsite.m4] ---' |
| 640 |
|
| 641 |
Makefile.in -------------------------------> Makefile.in |
| 642 |
|
| 643 |
Files used in configuring a software package: |
| 644 |
.-------------> [config.cache] |
| 645 |
configure* ------------+-------------> config.log |
| 646 |
| |
| 647 |
[config.h.in] -. v .-> [config.h] -. |
| 648 |
+--> config.status* -+ +--> make* |
| 649 |
Makefile.in ---' `-> Makefile ---' |
| 650 |
|
| 651 |
* Menu: |
| 652 |
|
| 653 |
* Writing configure.ac:: What to put in an Autoconf input file |
| 654 |
* autoscan Invocation:: Semi-automatic ‘configure.ac’ writing |
| 655 |
* ifnames Invocation:: Listing the conditionals in source code |
| 656 |
* autoconf Invocation:: How to create configuration scripts |
| 657 |
* autoreconf Invocation:: Remaking multiple ‘configure’ scripts |
| 658 |
|
| 659 |
|
| 660 |
File: autoconf.info, Node: Writing configure.ac, Next: autoscan Invocation, Prev: Making configure Scripts, Up: Making configure Scripts |
| 661 |
|
| 662 |
3.1 Writing ‘configure.ac’ |
| 663 |
========================== |
| 664 |
|
| 665 |
To produce a ‘configure’ script for a software package, create a file |
| 666 |
called ‘configure.ac’ that contains invocations of the Autoconf macros |
| 667 |
that test the system features your package needs or can use. Autoconf |
| 668 |
macros already exist to check for many features; see *note Existing |
| 669 |
Tests::, for their descriptions. For most other features, you can use |
| 670 |
Autoconf template macros to produce custom checks; see *note Writing |
| 671 |
Tests::, for information about them. For especially tricky or |
| 672 |
specialized features, ‘configure.ac’ might need to contain some |
| 673 |
hand-crafted shell commands; see *note Portable Shell::. The ‘autoscan’ |
| 674 |
program can give you a good start in writing ‘configure.ac’ (*note |
| 675 |
autoscan Invocation::, for more information). |
| 676 |
|
| 677 |
Previous versions of Autoconf promoted the name ‘configure.in’, which |
| 678 |
is somewhat ambiguous (the tool needed to produce this file is not |
| 679 |
described by its extension), and introduces a slight confusion with |
| 680 |
‘config.h.in’ and so on (for which ‘.in’ means "to be processed by |
| 681 |
‘configure’"). Using ‘configure.ac’ is now preferred. |
| 682 |
|
| 683 |
* Menu: |
| 684 |
|
| 685 |
* Shell Script Compiler:: Autoconf as solution of a problem |
| 686 |
* Autoconf Language:: Programming in Autoconf |
| 687 |
* configure.ac Layout:: Standard organization of configure.ac |
| 688 |
|
| 689 |
|
| 690 |
File: autoconf.info, Node: Shell Script Compiler, Next: Autoconf Language, Prev: Writing configure.ac, Up: Writing configure.ac |
| 691 |
|
| 692 |
3.1.1 A Shell Script Compiler |
| 693 |
----------------------------- |
| 694 |
|
| 695 |
Just as for any other computer language, in order to properly program |
| 696 |
‘configure.ac’ in Autoconf you must understand _what_ problem the |
| 697 |
language tries to address and _how_ it does so. |
| 698 |
|
| 699 |
The problem Autoconf addresses is that the world is a mess. After |
| 700 |
all, you are using Autoconf in order to have your package compile easily |
| 701 |
on all sorts of different systems, some of them being extremely hostile. |
| 702 |
Autoconf itself bears the price for these differences: ‘configure’ must |
| 703 |
run on all those systems, and thus ‘configure’ must limit itself to |
| 704 |
their lowest common denominator of features. |
| 705 |
|
| 706 |
Naturally, you might then think of shell scripts; who needs |
| 707 |
‘autoconf’? A set of properly written shell functions is enough to make |
| 708 |
it easy to write ‘configure’ scripts by hand. Sigh! Unfortunately, |
| 709 |
shell functions do not belong to the least common denominator; |
| 710 |
therefore, where you would like to define a function and use it ten |
| 711 |
times, you would instead need to copy its body ten times. |
| 712 |
|
| 713 |
So, what is really needed is some kind of compiler, ‘autoconf’, that |
| 714 |
takes an Autoconf program, ‘configure.ac’, and transforms it into a |
| 715 |
portable shell script, ‘configure’. |
| 716 |
|
| 717 |
How does ‘autoconf’ perform this task? |
| 718 |
|
| 719 |
There are two obvious possibilities: creating a brand new language or |
| 720 |
extending an existing one. The former option is very attractive: all |
| 721 |
sorts of optimizations could easily be implemented in the compiler and |
| 722 |
many rigorous checks could be performed on the Autoconf program (e.g. |
| 723 |
rejecting any non-portable construct). Alternatively, you can extend an |
| 724 |
existing language, such as the ‘sh’ (Bourne shell) language. |
| 725 |
|
| 726 |
Autoconf does the latter: it is a layer on top of ‘sh’. It was |
| 727 |
therefore most convenient to implement ‘autoconf’ as a macro expander: a |
| 728 |
program that repeatedly performs “macro expansions” on text input, |
| 729 |
replacing macro calls with macro bodies and producing a pure ‘sh’ script |
| 730 |
in the end. Instead of implementing a dedicated Autoconf macro |
| 731 |
expander, it is natural to use an existing general-purpose macro |
| 732 |
language, such as M4, and implement the extensions as a set of M4 |
| 733 |
macros. |
| 734 |
|
| 735 |
|
| 736 |
File: autoconf.info, Node: Autoconf Language, Next: configure.ac Layout, Prev: Shell Script Compiler, Up: Writing configure.ac |
| 737 |
|
| 738 |
3.1.2 The Autoconf Language |
| 739 |
--------------------------- |
| 740 |
|
| 741 |
The Autoconf language is very different from many other computer |
| 742 |
languages because it treats actual code the same as plain text. Whereas |
| 743 |
in C, for instance, data and instructions have very different syntactic |
| 744 |
status, in Autoconf their status is rigorously the same. Therefore, we |
| 745 |
need a means to distinguish literal strings from text to be expanded: |
| 746 |
quotation. |
| 747 |
|
| 748 |
When calling macros that take arguments, there must not be any blank |
| 749 |
space between the macro name and the open parenthesis. Arguments should |
| 750 |
be enclosed within the M4 quote characters ‘[’ and ‘]’, and be separated |
| 751 |
by commas. Any leading spaces in arguments are ignored, unless they are |
| 752 |
quoted. You may safely leave out the quotes when the argument is simple |
| 753 |
text, but _always_ quote complex arguments such as other macro calls. |
| 754 |
This rule applies recursively for every macro call, including macros |
| 755 |
called from other macros. |
| 756 |
|
| 757 |
For instance: |
| 758 |
|
| 759 |
AC_CHECK_HEADER([stdio.h], |
| 760 |
[AC_DEFINE([HAVE_STDIO_H])], |
| 761 |
[AC_MSG_ERROR([Sorry, can't do anything for you])]) |
| 762 |
|
| 763 |
is quoted properly. You may safely simplify its quotation to: |
| 764 |
|
| 765 |
AC_CHECK_HEADER(stdio.h, |
| 766 |
[AC_DEFINE(HAVE_STDIO_H)], |
| 767 |
[AC_MSG_ERROR([Sorry, can't do anything for you])]) |
| 768 |
|
| 769 |
Notice that the argument of ‘AC_MSG_ERROR’ is still quoted; otherwise, |
| 770 |
its comma would have been interpreted as an argument separator. |
| 771 |
|
| 772 |
The following example is wrong and dangerous, as it is underquoted: |
| 773 |
|
| 774 |
AC_CHECK_HEADER(stdio.h, |
| 775 |
AC_DEFINE(HAVE_STDIO_H), |
| 776 |
AC_MSG_ERROR([Sorry, can't do anything for you])) |
| 777 |
|
| 778 |
In other cases, you may have to use text that also resembles a macro |
| 779 |
call. You must quote that text even when it is not passed as a macro |
| 780 |
argument: |
| 781 |
|
| 782 |
echo "Hard rock was here! --[AC_DC]" |
| 783 |
|
| 784 |
which will result in |
| 785 |
|
| 786 |
echo "Hard rock was here! --AC_DC" |
| 787 |
|
| 788 |
When you use the same text in a macro argument, you must therefore have |
| 789 |
an extra quotation level (since one is stripped away by the macro |
| 790 |
substitution). In general, then, it is a good idea to _use double |
| 791 |
quoting for all literal string arguments_: |
| 792 |
|
| 793 |
AC_MSG_WARN([[AC_DC stinks --Iron Maiden]]) |
| 794 |
|
| 795 |
You are now able to understand one of the constructs of Autoconf that |
| 796 |
has been continually misunderstood... The rule of thumb is that |
| 797 |
_whenever you expect macro expansion, expect quote expansion_; i.e., |
| 798 |
expect one level of quotes to be lost. For instance: |
| 799 |
|
| 800 |
AC_COMPILE_IFELSE([char b[10];],, [AC_MSG_ERROR([you lose])]) |
| 801 |
|
| 802 |
is incorrect: here, the first argument of ‘AC_COMPILE_IFELSE’ is ‘char |
| 803 |
b[10];’ and will be expanded once, which results in ‘char b10;’. (There |
| 804 |
was an idiom common in Autoconf's past to address this issue via the M4 |
| 805 |
‘changequote’ primitive, but do not use it!) Let's take a closer look: |
| 806 |
the author meant the first argument to be understood as a literal, and |
| 807 |
therefore it must be quoted twice: |
| 808 |
|
| 809 |
AC_COMPILE_IFELSE([[char b[10];]],, [AC_MSG_ERROR([you lose])]) |
| 810 |
|
| 811 |
Voilà, you actually produce ‘char b[10];’ this time! |
| 812 |
|
| 813 |
The careful reader will notice that, according to these guidelines, |
| 814 |
the "properly" quoted ‘AC_CHECK_HEADER’ example above is actually |
| 815 |
lacking three pairs of quotes! Nevertheless, for the sake of |
| 816 |
readability, double quotation of literals is used only where needed in |
| 817 |
this manual. |
| 818 |
|
| 819 |
Some macros take optional arguments, which this documentation |
| 820 |
represents as [ARG] (not to be confused with the quote characters). You |
| 821 |
may just leave them empty, or use ‘[]’ to make the emptiness of the |
| 822 |
argument explicit, or you may simply omit the trailing commas. The |
| 823 |
three lines below are equivalent: |
| 824 |
|
| 825 |
AC_CHECK_HEADERS(stdio.h, [], [], []) |
| 826 |
AC_CHECK_HEADERS(stdio.h,,,) |
| 827 |
AC_CHECK_HEADERS(stdio.h) |
| 828 |
|
| 829 |
It is best to put each macro call on its own line in ‘configure.ac’. |
| 830 |
Most of the macros don't add extra newlines; they rely on the newline |
| 831 |
after the macro call to terminate the commands. This approach makes the |
| 832 |
generated ‘configure’ script a little easier to read by not inserting |
| 833 |
lots of blank lines. It is generally safe to set shell variables on the |
| 834 |
same line as a macro call, because the shell allows assignments without |
| 835 |
intervening newlines. |
| 836 |
|
| 837 |
You can include comments in ‘configure.ac’ files by starting them |
| 838 |
with the ‘#’. For example, it is helpful to begin ‘configure.ac’ files |
| 839 |
with a line like this: |
| 840 |
|
| 841 |
# Process this file with autoconf to produce a configure script. |
| 842 |
|
| 843 |
|
| 844 |
File: autoconf.info, Node: configure.ac Layout, Prev: Autoconf Language, Up: Writing configure.ac |
| 845 |
|
| 846 |
3.1.3 Standard ‘configure.ac’ Layout |
| 847 |
------------------------------------ |
| 848 |
|
| 849 |
The order in which ‘configure.ac’ calls the Autoconf macros is not |
| 850 |
important, with a few exceptions. Every ‘configure.ac’ must contain a |
| 851 |
call to ‘AC_INIT’ before the checks, and a call to ‘AC_OUTPUT’ at the |
| 852 |
end (*note Output::). Additionally, some macros rely on other macros |
| 853 |
having been called first, because they check previously set values of |
| 854 |
some variables to decide what to do. These macros are noted in the |
| 855 |
individual descriptions (*note Existing Tests::), and they also warn you |
| 856 |
when ‘configure’ is created if they are called out of order. |
| 857 |
|
| 858 |
To encourage consistency, here is a suggested order for calling the |
| 859 |
Autoconf macros. Generally speaking, the things near the end of this |
| 860 |
list are those that could depend on things earlier in it. For example, |
| 861 |
library functions could be affected by types and libraries. |
| 862 |
|
| 863 |
Autoconf requirements |
| 864 |
‘AC_INIT(PACKAGE, VERSION, BUG-REPORT-ADDRESS)’ |
| 865 |
information on the package |
| 866 |
checks for programs |
| 867 |
checks for libraries |
| 868 |
checks for header files |
| 869 |
checks for types |
| 870 |
checks for structures |
| 871 |
checks for compiler characteristics |
| 872 |
checks for library functions |
| 873 |
checks for system services |
| 874 |
‘AC_CONFIG_FILES([FILE...])’ |
| 875 |
‘AC_OUTPUT’ |
| 876 |
|
| 877 |
|
| 878 |
File: autoconf.info, Node: autoscan Invocation, Next: ifnames Invocation, Prev: Writing configure.ac, Up: Making configure Scripts |
| 879 |
|
| 880 |
3.2 Using ‘autoscan’ to Create ‘configure.ac’ |
| 881 |
============================================= |
| 882 |
|
| 883 |
The ‘autoscan’ program can help you create and/or maintain a |
| 884 |
‘configure.ac’ file for a software package. ‘autoscan’ examines source |
| 885 |
files in the directory tree rooted at a directory given as a command |
| 886 |
line argument, or the current directory if none is given. It searches |
| 887 |
the source files for common portability problems and creates a file |
| 888 |
‘configure.scan’ which is a preliminary ‘configure.ac’ for that package, |
| 889 |
and checks a possibly existing ‘configure.ac’ for completeness. |
| 890 |
|
| 891 |
When using ‘autoscan’ to create a ‘configure.ac’, you should manually |
| 892 |
examine ‘configure.scan’ before renaming it to ‘configure.ac’; it will |
| 893 |
probably need some adjustments. Occasionally, ‘autoscan’ outputs a |
| 894 |
macro in the wrong order relative to another macro, so that ‘autoconf’ |
| 895 |
produces a warning; you need to move such macros manually. Also, if you |
| 896 |
want the package to use a configuration header file, you must add a call |
| 897 |
to ‘AC_CONFIG_HEADERS’ (*note Configuration Headers::). You might also |
| 898 |
have to change or add some ‘#if’ directives to your program in order to |
| 899 |
make it work with Autoconf (*note ifnames Invocation::, for information |
| 900 |
about a program that can help with that job). |
| 901 |
|
| 902 |
When using ‘autoscan’ to maintain a ‘configure.ac’, simply consider |
| 903 |
adding its suggestions. The file ‘autoscan.log’ will contain detailed |
| 904 |
information on why a macro is requested. |
| 905 |
|
| 906 |
‘autoscan’ uses several data files (installed along with Autoconf) to |
| 907 |
determine which macros to output when it finds particular symbols in a |
| 908 |
package's source files. These data files all have the same format: each |
| 909 |
line consists of a symbol, whitespace, and the Autoconf macro to output |
| 910 |
if that symbol is encountered. Lines starting with ‘#’ are comments. |
| 911 |
|
| 912 |
‘autoscan’ is only installed if you already have Perl installed. |
| 913 |
‘autoscan’ accepts the following options: |
| 914 |
|
| 915 |
‘--help’ |
| 916 |
‘-h’ |
| 917 |
Print a summary of the command line options and exit. |
| 918 |
|
| 919 |
‘--version’ |
| 920 |
‘-V’ |
| 921 |
Print the version number of Autoconf and exit. |
| 922 |
|
| 923 |
‘--verbose’ |
| 924 |
‘-v’ |
| 925 |
Print the names of the files it examines and the potentially |
| 926 |
interesting symbols it finds in them. This output can be |
| 927 |
voluminous. |
| 928 |
|
| 929 |
‘--autoconf-dir=DIR’ |
| 930 |
‘-A DIR’ |
| 931 |
Override the location where the installed Autoconf data files are |
| 932 |
looked for. You can also set the ‘AC_MACRODIR’ environment |
| 933 |
variable to a directory; this option overrides the environment |
| 934 |
variable. |
| 935 |
|
| 936 |
This option is rarely needed and dangerous; it is only used when |
| 937 |
one plays with different versions of Autoconf simultaneously. |
| 938 |
|
| 939 |
|
| 940 |
File: autoconf.info, Node: ifnames Invocation, Next: autoconf Invocation, Prev: autoscan Invocation, Up: Making configure Scripts |
| 941 |
|
| 942 |
3.3 Using ‘ifnames’ to List Conditionals |
| 943 |
======================================== |
| 944 |
|
| 945 |
‘ifnames’ can help you write ‘configure.ac’ for a software package. It |
| 946 |
prints the identifiers that the package already uses in C preprocessor |
| 947 |
conditionals. If a package has already been set up to have some |
| 948 |
portability, ‘ifnames’ can thus help you figure out what its ‘configure’ |
| 949 |
needs to check for. It may help fill in some gaps in a ‘configure.ac’ |
| 950 |
generated by ‘autoscan’ (*note autoscan Invocation::). |
| 951 |
|
| 952 |
‘ifnames’ scans all of the C source files named on the command line |
| 953 |
(or the standard input, if none are given) and writes to the standard |
| 954 |
output a sorted list of all the identifiers that appear in those files |
| 955 |
in ‘#if’, ‘#elif’, ‘#ifdef’, or ‘#ifndef’ directives. It prints each |
| 956 |
identifier on a line, followed by a space-separated list of the files in |
| 957 |
which that identifier occurs. |
| 958 |
|
| 959 |
‘ifnames’ accepts the following options: |
| 960 |
|
| 961 |
‘--help’ |
| 962 |
‘-h’ |
| 963 |
Print a summary of the command line options and exit. |
| 964 |
|
| 965 |
‘--version’ |
| 966 |
‘-V’ |
| 967 |
Print the version number of Autoconf and exit. |
| 968 |
|
| 969 |
|
| 970 |
File: autoconf.info, Node: autoconf Invocation, Next: autoreconf Invocation, Prev: ifnames Invocation, Up: Making configure Scripts |
| 971 |
|
| 972 |
3.4 Using ‘autoconf’ to Create ‘configure’ |
| 973 |
========================================== |
| 974 |
|
| 975 |
To create ‘configure’ from ‘configure.ac’, run the ‘autoconf’ program |
| 976 |
with no arguments. ‘autoconf’ processes ‘configure.ac’ with the ‘m4’ |
| 977 |
macro processor, using the Autoconf macros. If you give ‘autoconf’ an |
| 978 |
argument, it reads that file instead of ‘configure.ac’ and writes the |
| 979 |
configuration script to the standard output instead of to ‘configure’. |
| 980 |
If you give ‘autoconf’ the argument ‘-’, it reads from the standard |
| 981 |
input instead of ‘configure.ac’ and writes the configuration script to |
| 982 |
the standard output. |
| 983 |
|
| 984 |
The Autoconf macros are defined in several files. Some of the files |
| 985 |
are distributed with Autoconf; ‘autoconf’ reads them first. Then it |
| 986 |
looks for the optional file ‘acsite.m4’ in the directory that contains |
| 987 |
the distributed Autoconf macro files, and for the optional file |
| 988 |
‘aclocal.m4’ in the current directory. Those files can contain your |
| 989 |
site's or the package's own Autoconf macro definitions (*note Writing |
| 990 |
Autoconf Macros::, for more information). If a macro is defined in more |
| 991 |
than one of the files that ‘autoconf’ reads, the last definition it |
| 992 |
reads overrides the earlier ones. |
| 993 |
|
| 994 |
‘autoconf’ accepts the following options: |
| 995 |
|
| 996 |
‘--help’ |
| 997 |
‘-h’ |
| 998 |
Print a summary of the command line options and exit. |
| 999 |
|
| 1000 |
‘--version’ |
| 1001 |
‘-V’ |
| 1002 |
Print the version number of Autoconf and exit. |
| 1003 |
|
| 1004 |
‘--verbose’ |
| 1005 |
‘-v’ |
| 1006 |
Report processing steps. |
| 1007 |
|
| 1008 |
‘--debug’ |
| 1009 |
‘-d’ |
| 1010 |
Don't remove the temporary files. |
| 1011 |
|
| 1012 |
‘--autoconf-dir=DIR’ |
| 1013 |
‘-A DIR’ |
| 1014 |
Override the location where the installed Autoconf data files are |
| 1015 |
looked for. You can also set the ‘AC_MACRODIR’ environment |
| 1016 |
variable to a directory; this option overrides the environment |
| 1017 |
variable. |
| 1018 |
|
| 1019 |
This option is rarely needed and dangerous; it is only used when |
| 1020 |
one plays with different versions of Autoconf simultaneously. |
| 1021 |
|
| 1022 |
‘--localdir=DIR’ |
| 1023 |
‘-l DIR’ |
| 1024 |
Look for the package file ‘aclocal.m4’ in directory DIR instead of |
| 1025 |
in the current directory. |
| 1026 |
|
| 1027 |
‘--output=FILE’ |
| 1028 |
‘-o FILE’ |
| 1029 |
Save output (script or trace) to FILE. The file ‘-’ stands for the |
| 1030 |
standard output. |
| 1031 |
|
| 1032 |
‘--warnings=CATEGORY’ |
| 1033 |
‘-W CATEGORY’ |
| 1034 |
Report the warnings related to CATEGORY (which can actually be a |
| 1035 |
comma separated list). *Note Reporting Messages::, macro |
| 1036 |
‘AC_DIAGNOSE’, for a comprehensive list of categories. Special |
| 1037 |
values include: |
| 1038 |
|
| 1039 |
‘all’ |
| 1040 |
report all the warnings |
| 1041 |
|
| 1042 |
‘none’ |
| 1043 |
report none |
| 1044 |
|
| 1045 |
‘error’ |
| 1046 |
treats warnings as errors |
| 1047 |
|
| 1048 |
‘no-CATEGORY’ |
| 1049 |
disable warnings falling into CATEGORY |
| 1050 |
|
| 1051 |
Warnings about ‘syntax’ are enabled by default, and the environment |
| 1052 |
variable ‘WARNINGS’, a comma separated list of categories, is |
| 1053 |
honored. ‘autoconf -W CATEGORY’ will actually behave as if you had |
| 1054 |
run: |
| 1055 |
|
| 1056 |
autoconf --warnings=syntax,$WARNINGS,CATEGORY |
| 1057 |
|
| 1058 |
If you want to disable ‘autoconf’'s defaults and ‘WARNINGS’, but |
| 1059 |
(for example) enable the warnings about obsolete constructs, you |
| 1060 |
would use ‘-W none,obsolete’. |
| 1061 |
|
| 1062 |
‘autoconf’ displays a back trace for errors, but not for warnings; |
| 1063 |
if you want them, just pass ‘-W error’. For instance, on this |
| 1064 |
‘configure.ac’: |
| 1065 |
|
| 1066 |
AC_DEFUN([INNER], |
| 1067 |
[AC_TRY_RUN([true])]) |
| 1068 |
|
| 1069 |
AC_DEFUN([OUTER], |
| 1070 |
[INNER]) |
| 1071 |
|
| 1072 |
AC_INIT |
| 1073 |
OUTER |
| 1074 |
|
| 1075 |
you get: |
| 1076 |
|
| 1077 |
$ autoconf -Wcross |
| 1078 |
configure.ac:8: warning: AC_TRY_RUN called without default \ |
| 1079 |
to allow cross compiling |
| 1080 |
$ autoconf -Wcross,error |
| 1081 |
configure.ac:8: error: AC_TRY_RUN called without default \ |
| 1082 |
to allow cross compiling |
| 1083 |
acgeneral.m4:3044: AC_TRY_RUN is expanded from... |
| 1084 |
configure.ac:2: INNER is expanded from... |
| 1085 |
configure.ac:5: OUTER is expanded from... |
| 1086 |
configure.ac:8: the top level |
| 1087 |
|
| 1088 |
‘--trace=MACRO[:FORMAT]’ |
| 1089 |
‘-t MACRO[:FORMAT]’ |
| 1090 |
Do not create the ‘configure’ script, but list the calls to MACRO |
| 1091 |
according to the FORMAT. Multiple ‘--trace’ arguments can be used |
| 1092 |
to list several macros. Multiple ‘--trace’ arguments for a single |
| 1093 |
macro are not cumulative; instead, you should just make FORMAT as |
| 1094 |
long as needed. |
| 1095 |
|
| 1096 |
The FORMAT is a regular string, with newlines if desired, and |
| 1097 |
several special escape codes. It defaults to ‘$f:$l:$n:$%’; see |
| 1098 |
below for details on the FORMAT. |
| 1099 |
|
| 1100 |
‘--initialization’ |
| 1101 |
‘-i’ |
| 1102 |
By default, ‘--trace’ does not trace the initialization of the |
| 1103 |
Autoconf macros (typically the ‘AC_DEFUN’ definitions). This |
| 1104 |
results in a noticeable speedup, but can be disabled by this |
| 1105 |
option. |
| 1106 |
|
| 1107 |
It is often necessary to check the content of a ‘configure.ac’ file, |
| 1108 |
but parsing it yourself is extremely fragile and error-prone. It is |
| 1109 |
suggested that you rely upon ‘--trace’ to scan ‘configure.ac’. |
| 1110 |
|
| 1111 |
The FORMAT of ‘--trace’ can use the following special escapes: |
| 1112 |
|
| 1113 |
‘$$’ |
| 1114 |
The character ‘$’. |
| 1115 |
|
| 1116 |
‘$f’ |
| 1117 |
The filename from which MACRO is called. |
| 1118 |
|
| 1119 |
‘$l’ |
| 1120 |
The line number from which MACRO is called. |
| 1121 |
|
| 1122 |
‘$d’ |
| 1123 |
The depth of the MACRO call. This is an M4 technical detail that |
| 1124 |
you probably don't want to know about. |
| 1125 |
|
| 1126 |
‘$n’ |
| 1127 |
The name of the MACRO. |
| 1128 |
|
| 1129 |
‘$NUM’ |
| 1130 |
The NUMth argument of the call to MACRO. |
| 1131 |
|
| 1132 |
‘$@’ |
| 1133 |
‘$SEP@’ |
| 1134 |
‘${SEPARATOR}@’ |
| 1135 |
All the arguments passed to MACRO, separated by the character SEP |
| 1136 |
or the string SEPARATOR (‘,’ by default). Each argument is quoted, |
| 1137 |
i.e. enclosed in a pair of square brackets. |
| 1138 |
|
| 1139 |
‘$*’ |
| 1140 |
‘$SEP*’ |
| 1141 |
‘${SEPARATOR}*’ |
| 1142 |
As above, but the arguments are not quoted. |
| 1143 |
|
| 1144 |
‘$%’ |
| 1145 |
‘$SEP%’ |
| 1146 |
‘${SEPARATOR}%’ |
| 1147 |
As above, but the arguments are not quoted, all new line characters |
| 1148 |
in the arguments are smashed, and the default separator is ‘:’. |
| 1149 |
|
| 1150 |
The escape ‘$%’ produces single-line trace outputs (unless you put |
| 1151 |
newlines in the ‘separator’), while ‘$@’ and ‘$*’ do not. |
| 1152 |
|
| 1153 |
For instance, to find the list of variables that are substituted, |
| 1154 |
use: |
| 1155 |
|
| 1156 |
$ autoconf -t AC_SUBST |
| 1157 |
configure.ac:2:AC_SUBST:ECHO_C |
| 1158 |
configure.ac:2:AC_SUBST:ECHO_N |
| 1159 |
configure.ac:2:AC_SUBST:ECHO_T |
| 1160 |
More traces deleted |
| 1161 |
|
| 1162 |
The example below highlights the difference between ‘$@’, ‘$*’, and |
| 1163 |
*$%*. |
| 1164 |
|
| 1165 |
$ cat configure.ac |
| 1166 |
AC_DEFINE(This, is, [an |
| 1167 |
[example]]) |
| 1168 |
$ autoconf -t 'AC_DEFINE:@: $@ |
| 1169 |
*: $* |
| 1170 |
$: $%' |
| 1171 |
@: [This],[is],[an |
| 1172 |
[example]] |
| 1173 |
*: This,is,an |
| 1174 |
[example] |
| 1175 |
$: This:is:an [example] |
| 1176 |
|
| 1177 |
The FORMAT gives you a lot of freedom: |
| 1178 |
|
| 1179 |
$ autoconf -t 'AC_SUBST:$$ac_subst{"$1"} = "$f:$l";' |
| 1180 |
$ac_subst{"ECHO_C"} = "configure.ac:2"; |
| 1181 |
$ac_subst{"ECHO_N"} = "configure.ac:2"; |
| 1182 |
$ac_subst{"ECHO_T"} = "configure.ac:2"; |
| 1183 |
More traces deleted |
| 1184 |
|
| 1185 |
A long SEPARATOR can be used to improve the readability of complex |
| 1186 |
structures, and to ease its parsing (for instance when no single |
| 1187 |
character is suitable as a separator)): |
| 1188 |
|
| 1189 |
$ autoconf -t 'AM_MISSING_PROG:${|:::::|}*' |
| 1190 |
AUTOCONF|:::::|autoconf|:::::|$missing_dir |
| 1191 |
More traces deleted |
| 1192 |
|
| 1193 |
|
| 1194 |
File: autoconf.info, Node: autoreconf Invocation, Prev: autoconf Invocation, Up: Making configure Scripts |
| 1195 |
|
| 1196 |
3.5 Using ‘autoreconf’ to Update ‘configure’ Scripts |
| 1197 |
==================================================== |
| 1198 |
|
| 1199 |
If you have a lot of Autoconf-generated ‘configure’ scripts, the |
| 1200 |
‘autoreconf’ program can save you some work. It runs ‘autoconf’ (and |
| 1201 |
‘autoheader’, where appropriate) repeatedly to remake the Autoconf |
| 1202 |
‘configure’ scripts and configuration header templates in the directory |
| 1203 |
tree rooted at the current directory. By default, it only remakes those |
| 1204 |
files that are older than their ‘configure.ac’ or (if present) |
| 1205 |
‘aclocal.m4’. Since ‘autoheader’ does not change the timestamp of its |
| 1206 |
output file if the file wouldn't be changing, this is not necessarily |
| 1207 |
the minimum amount of work. If you install a new version of Autoconf, |
| 1208 |
you can make ‘autoreconf’ remake _all_ of the files by giving it the |
| 1209 |
‘--force’ option. |
| 1210 |
|
| 1211 |
If you give ‘autoreconf’ the ‘--autoconf-dir=DIR’ or ‘--localdir=DIR’ |
| 1212 |
options, it passes them down to ‘autoconf’ and ‘autoheader’ (with |
| 1213 |
relative paths adjusted properly). |
| 1214 |
|
| 1215 |
‘autoreconf’ does not support having, in the same directory tree, |
| 1216 |
both directories that are parts of a larger package (sharing |
| 1217 |
‘aclocal.m4’ and ‘acconfig.h’) and directories that are independent |
| 1218 |
packages (each with their own ‘aclocal.m4’ and ‘acconfig.h’). It |
| 1219 |
assumes that they are all part of the same package if you use |
| 1220 |
‘--localdir’, or that each directory is a separate package if you don't |
| 1221 |
use it. This restriction may be removed in the future. |
| 1222 |
|
| 1223 |
*Note Automatic Remaking::, for ‘Makefile’ rules to automatically |
| 1224 |
remake ‘configure’ scripts when their source files change. That method |
| 1225 |
handles the timestamps of configuration header templates properly, but |
| 1226 |
does not pass ‘--autoconf-dir=DIR’ or ‘--localdir=DIR’. |
| 1227 |
|
| 1228 |
‘autoreconf’ accepts the following options: |
| 1229 |
|
| 1230 |
‘--help’ |
| 1231 |
‘-h’ |
| 1232 |
Print a summary of the command line options and exit. |
| 1233 |
|
| 1234 |
‘--version’ |
| 1235 |
‘-V’ |
| 1236 |
Print the version number of Autoconf and exit. |
| 1237 |
|
| 1238 |
‘--verbose’ |
| 1239 |
Print the name of each directory where ‘autoreconf’ runs ‘autoconf’ |
| 1240 |
(and ‘autoheader’, if appropriate). |
| 1241 |
|
| 1242 |
‘--debug’ |
| 1243 |
‘-d’ |
| 1244 |
Don't remove the temporary files. |
| 1245 |
|
| 1246 |
‘--force’ |
| 1247 |
‘-f’ |
| 1248 |
Remake even ‘configure’ scripts and configuration headers that are |
| 1249 |
newer than their input files (‘configure.ac’ and, if present, |
| 1250 |
‘aclocal.m4’). |
| 1251 |
|
| 1252 |
‘--install’ |
| 1253 |
‘-i’ |
| 1254 |
Copy missing auxiliary files. This option is similar to the option |
| 1255 |
‘--add-missing’ in other tools. |
| 1256 |
|
| 1257 |
‘--symlink’ |
| 1258 |
‘-s’ |
| 1259 |
Instead of copying missing auxiliary files, install symbolic links. |
| 1260 |
|
| 1261 |
‘--localdir=DIR’ |
| 1262 |
‘-l DIR’ |
| 1263 |
Have ‘autoconf’ and ‘autoheader’ look for the package files |
| 1264 |
‘aclocal.m4’ and (‘autoheader’ only) ‘acconfig.h’ (but not |
| 1265 |
‘FILE.top’ and ‘FILE.bot’) in directory DIR instead of in the |
| 1266 |
directory containing each ‘configure.ac’. |
| 1267 |
|
| 1268 |
‘--autoconf-dir=DIR’ |
| 1269 |
‘-A DIR’ |
| 1270 |
Override the location where the installed Autoconf data files are |
| 1271 |
looked for. You can also set the ‘AC_MACRODIR’ environment |
| 1272 |
variable to a directory; this option overrides the environment |
| 1273 |
variable. |
| 1274 |
|
| 1275 |
This option is rarely needed and dangerous; it is only used when |
| 1276 |
one plays with different versions of Autoconf simultaneously. |
| 1277 |
|
| 1278 |
‘--m4dir=DIR’ |
| 1279 |
‘-M DIR’ |
| 1280 |
Specify location of additional macro files (‘m4’ by default). |
| 1281 |
|
| 1282 |
|
| 1283 |
File: autoconf.info, Node: Setup, Next: Existing Tests, Prev: Making configure Scripts, Up: Top |
| 1284 |
|
| 1285 |
4 Initialization and Output Files |
| 1286 |
********************************* |
| 1287 |
|
| 1288 |
Autoconf-generated ‘configure’ scripts need some information about how |
| 1289 |
to initialize, such as how to find the package's source files; and about |
| 1290 |
the output files to produce. The following sections describe |
| 1291 |
initialization and the creation of output files. |
| 1292 |
|
| 1293 |
* Menu: |
| 1294 |
|
| 1295 |
* Notices:: Copyright, version numbers in ‘configure’ |
| 1296 |
* Input:: Where Autoconf should find files |
| 1297 |
* Output:: Outputting results from the configuration |
| 1298 |
* Configuration Actions:: Preparing the output based on results |
| 1299 |
* Configuration Files:: Creating output files |
| 1300 |
* Makefile Substitutions:: Using output variables in ‘Makefile’s |
| 1301 |
* Configuration Headers:: Creating a configuration header file |
| 1302 |
* Configuration Commands:: Running arbitrary instantiation commands |
| 1303 |
* Configuration Links:: Links depending from the configuration |
| 1304 |
* Subdirectories:: Configuring independent packages together |
| 1305 |
* Default Prefix:: Changing the default installation prefix |
| 1306 |
|
| 1307 |
|
| 1308 |
File: autoconf.info, Node: Notices, Next: Input, Prev: Setup, Up: Setup |
| 1309 |
|
| 1310 |
4.1 Notices in ‘configure’ |
| 1311 |
========================== |
| 1312 |
|
| 1313 |
The following macros manage version numbers for ‘configure’ scripts. |
| 1314 |
Using them is optional. |
| 1315 |
|
| 1316 |
-- Macro: AC_PREREQ (VERSION) |
| 1317 |
Ensure that a recent enough version of Autoconf is being used. If |
| 1318 |
the version of Autoconf being used to create ‘configure’ is earlier |
| 1319 |
than VERSION, print an error message to the standard error output |
| 1320 |
and do not create ‘configure’. For example: |
| 1321 |
|
| 1322 |
AC_PREREQ(2.52.20260412) |
| 1323 |
|
| 1324 |
This macro is the only macro that may be used before ‘AC_INIT’, but |
| 1325 |
for consistency, you are invited not to do so. |
| 1326 |
|
| 1327 |
-- Macro: AC_COPYRIGHT (COPYRIGHT-NOTICE) |
| 1328 |
State that, in addition to the Free Software Foundation's copyright |
| 1329 |
on the Autoconf macros, parts of your ‘configure’ are covered by |
| 1330 |
the COPYRIGHT-NOTICE. |
| 1331 |
|
| 1332 |
The COPYRIGHT-NOTICE will show up in both the head of ‘configure’ |
| 1333 |
and in ‘configure --version’. |
| 1334 |
|
| 1335 |
-- Macro: AC_REVISION (REVISION-INFO) |
| 1336 |
Copy revision stamp REVISION-INFO into the ‘configure’ script, with |
| 1337 |
any dollar signs or double-quotes removed. This macro lets you put |
| 1338 |
a revision stamp from ‘configure.ac’ into ‘configure’ without RCS |
| 1339 |
or ‘cvs’ changing it when you check in ‘configure’. That way, you |
| 1340 |
can determine easily which revision of ‘configure.ac’ a particular |
| 1341 |
‘configure’ corresponds to. |
| 1342 |
|
| 1343 |
For example, this line in ‘configure.ac’: |
| 1344 |
|
| 1345 |
AC_REVISION($Revision: 1.86 $) |
| 1346 |
|
| 1347 |
produces this in ‘configure’: |
| 1348 |
|
| 1349 |
#! /bin/sh |
| 1350 |
# From configure.ac Revision: 1.30 |
| 1351 |
|
| 1352 |
|
| 1353 |
File: autoconf.info, Node: Input, Next: Output, Prev: Notices, Up: Setup |
| 1354 |
|
| 1355 |
4.2 Finding ‘configure’ Input |
| 1356 |
============================= |
| 1357 |
|
| 1358 |
Every ‘configure’ script must call ‘AC_INIT’ before doing anything else. |
| 1359 |
The only other required macro is ‘AC_OUTPUT’ (*note Output::). |
| 1360 |
|
| 1361 |
-- Macro: AC_INIT (PACKAGE, VERSION, [BUG-REPORT-ADDRESS]) |
| 1362 |
Process any command-line arguments and perform various |
| 1363 |
initializations and verifications. Set the name of the PACKAGE and |
| 1364 |
its VERSION. The optional argument BUG-REPORT-ADDRESS should be |
| 1365 |
the email to which users should send bug reports. |
| 1366 |
|
| 1367 |
-- Macro: AC_CONFIG_SRCDIR (UNIQUE-FILE-IN-SOURCE-DIR) |
| 1368 |
UNIQUE-FILE-IN-SOURCE-DIR is some file that is in the package's |
| 1369 |
source directory; ‘configure’ checks for this file's existence to |
| 1370 |
make sure that the directory that it is told contains the source |
| 1371 |
code in fact does. Occasionally people accidentally specify the |
| 1372 |
wrong directory with ‘--srcdir’; this is a safety check. *Note |
| 1373 |
configure Invocation::, for more information. |
| 1374 |
|
| 1375 |
Packages that do manual configuration or use the ‘install’ program |
| 1376 |
might need to tell ‘configure’ where to find some other shell scripts by |
| 1377 |
calling ‘AC_CONFIG_AUX_DIR’, though the default places it looks are |
| 1378 |
correct for most cases. |
| 1379 |
|
| 1380 |
-- Macro: AC_CONFIG_AUX_DIR (DIR) |
| 1381 |
Use the auxiliary build tools (e.g., ‘install-sh’, ‘config.sub’, |
| 1382 |
‘config.guess’, Cygnus ‘configure’, Automake and Libtool scripts |
| 1383 |
etc.) that are in directory DIR. These are auxiliary files used |
| 1384 |
in configuration. DIR can be either absolute or relative to |
| 1385 |
‘SRCDIR’. The default is ‘SRCDIR’ or ‘SRCDIR/..’ or |
| 1386 |
‘SRCDIR/../..’, whichever is the first that contains ‘install-sh’. |
| 1387 |
The other files are not checked for, so that using |
| 1388 |
‘AC_PROG_INSTALL’ does not automatically require distributing the |
| 1389 |
other auxiliary files. It checks for ‘install.sh’ also, but that |
| 1390 |
name is obsolete because some ‘make’ have a rule that creates |
| 1391 |
‘install’ from it if there is no ‘Makefile’. |
| 1392 |
|
| 1393 |
|
| 1394 |
File: autoconf.info, Node: Output, Next: Configuration Actions, Prev: Input, Up: Setup |
| 1395 |
|
| 1396 |
4.3 Outputting Files |
| 1397 |
==================== |
| 1398 |
|
| 1399 |
Every Autoconf-generated ‘configure’ script must finish by calling |
| 1400 |
‘AC_OUTPUT’. It is the macro that generates ‘config.status’, which will |
| 1401 |
create the ‘Makefile’s and any other files resulting from configuration. |
| 1402 |
The only other required macro is ‘AC_INIT’ (*note Input::). |
| 1403 |
|
| 1404 |
-- Macro: AC_OUTPUT |
| 1405 |
Generate ‘config.status’ and launch it. Call this macro once, at |
| 1406 |
the end of ‘configure.ac’. |
| 1407 |
|
| 1408 |
‘config.status’ will take all the configuration actions: all the |
| 1409 |
output files (see *note Configuration Files::, macro |
| 1410 |
‘AC_CONFIG_FILES’), header files (see *note Configuration |
| 1411 |
Headers::, macro ‘AC_CONFIG_HEADERS’), commands (see *note |
| 1412 |
Configuration Commands::, macro ‘AC_CONFIG_COMMANDS’), links (see |
| 1413 |
*note Configuration Links::, macro ‘AC_CONFIG_LINKS’), |
| 1414 |
subdirectories to configure (see *note Subdirectories::, macro |
| 1415 |
‘AC_CONFIG_SUBDIRS’) are honored. |
| 1416 |
|
| 1417 |
Historically, the usage of ‘AC_OUTPUT’ was somewhat different. *Note |
| 1418 |
Obsolete Macros::, for a description of the arguments that ‘AC_OUTPUT’ |
| 1419 |
used to support. |
| 1420 |
|
| 1421 |
If you run ‘make’ on subdirectories, you should run it using the |
| 1422 |
‘make’ variable ‘MAKE’. Most versions of ‘make’ set ‘MAKE’ to the name |
| 1423 |
of the ‘make’ program plus any options it was given. (But many do not |
| 1424 |
include in it the values of any variables set on the command line, so |
| 1425 |
those are not passed on automatically.) Some old versions of ‘make’ do |
| 1426 |
not set this variable. The following macro allows you to use it even |
| 1427 |
with those versions. |
| 1428 |
|
| 1429 |
-- Macro: AC_PROG_MAKE_SET |
| 1430 |
If ‘make’ predefines the variable ‘MAKE’, define output variable |
| 1431 |
‘SET_MAKE’ to be empty. Otherwise, define ‘SET_MAKE’ to contain |
| 1432 |
‘MAKE=make’. Calls ‘AC_SUBST’ for ‘SET_MAKE’. |
| 1433 |
|
| 1434 |
To use this macro, place a line like this in each ‘Makefile.in’ that |
| 1435 |
runs ‘MAKE’ on other directories: |
| 1436 |
|
| 1437 |
@SET_MAKE@ |
| 1438 |
|
| 1439 |
|
| 1440 |
File: autoconf.info, Node: Configuration Actions, Next: Configuration Files, Prev: Output, Up: Setup |
| 1441 |
|
| 1442 |
4.4 Taking Configuration Actions |
| 1443 |
================================ |
| 1444 |
|
| 1445 |
‘configure’ is designed so that it appears to do everything itself, but |
| 1446 |
there is actually a hidden slave: ‘config.status’. ‘configure’ is in |
| 1447 |
charge of examining your system, but it is ‘config.status’ that actually |
| 1448 |
takes the proper actions based on the results of ‘configure’. The most |
| 1449 |
typical task of ‘config.status’ is to _instantiate_ files. |
| 1450 |
|
| 1451 |
This section describes the common behavior of the four standard |
| 1452 |
instantiating macros: ‘AC_CONFIG_FILES’, ‘AC_CONFIG_HEADERS’, |
| 1453 |
‘AC_CONFIG_COMMANDS’ and ‘AC_CONFIG_LINKS’. They all have this |
| 1454 |
prototype: |
| 1455 |
|
| 1456 |
AC_CONFIG_FOOS(TAG..., [COMMANDS], [INIT-CMDS]) |
| 1457 |
|
| 1458 |
where the arguments are: |
| 1459 |
|
| 1460 |
TAG... |
| 1461 |
A whitespace-separated list of tags, which are typically the names |
| 1462 |
of the files to instantiate. |
| 1463 |
|
| 1464 |
COMMANDS |
| 1465 |
Shell commands output literally into ‘config.status’, and |
| 1466 |
associated with a tag that the user can use to tell ‘config.status’ |
| 1467 |
which the commands to run. The commands are run each time a TAG |
| 1468 |
request is given to ‘config.status’; typically, each time the file |
| 1469 |
‘TAG’ is created. |
| 1470 |
|
| 1471 |
INIT-CMDS |
| 1472 |
Shell commands output _unquoted_ near the beginning of |
| 1473 |
‘config.status’, and executed each time ‘config.status’ runs |
| 1474 |
(regardless of the tag). Because they are unquoted, for example, |
| 1475 |
‘$var’ will be output as the value of ‘var’. INIT-CMDS is |
| 1476 |
typically used by ‘configure’ to give ‘config.status’ some |
| 1477 |
variables it needs to run the COMMANDS. |
| 1478 |
|
| 1479 |
All these macros can be called multiple times, with different TAGs, |
| 1480 |
of course! |
| 1481 |
|
| 1482 |
You are encouraged to use literals as TAGS. In particular, you |
| 1483 |
should avoid |
| 1484 |
|
| 1485 |
... && my_foos="$my_foos fooo" |
| 1486 |
... && my_foos="$my_foos foooo" |
| 1487 |
AC_CONFIG_FOOS($my_foos) |
| 1488 |
|
| 1489 |
and use this instead: |
| 1490 |
|
| 1491 |
... && AC_CONFIG_FOOS(fooo) |
| 1492 |
... && AC_CONFIG_FOOS(foooo) |
| 1493 |
|
| 1494 |
The macro ‘AC_CONFIG_FILES’ and ‘AC_CONFIG_HEADERS’ use specials |
| 1495 |
TAGs: they may have the form ‘OUTPUT’ or ‘OUTPUT:INPUTS’. The file |
| 1496 |
OUTPUT is instantiated from its templates, INPUTS if specified, |
| 1497 |
defaulting to ‘OUTPUT.in’. |
| 1498 |
|
| 1499 |
For instance ‘AC_CONFIG_FILES(Makefile:boiler/top.mk:boiler/bot.mk)’ |
| 1500 |
asks for the creation of ‘Makefile’ that will be the expansion of the |
| 1501 |
output variables in the concatenation of ‘boiler/top.mk’ and |
| 1502 |
‘boiler/bot.mk’. |
| 1503 |
|
| 1504 |
The special value ‘-’ might be used to denote the standard output |
| 1505 |
when used in OUTPUT, or the standard input when used in the INPUTS. You |
| 1506 |
most probably don't need to use this in ‘configure.ac’, but it is |
| 1507 |
convenient when using the command line interface of ‘./config.status’, |
| 1508 |
see *note config.status Invocation::, for more details. |
| 1509 |
|
| 1510 |
The INPUTS may be absolute or relative filenames. In the latter case |
| 1511 |
they are first looked for in the build tree, and then in the source |
| 1512 |
tree. |
| 1513 |
|
| 1514 |
|
| 1515 |
File: autoconf.info, Node: Configuration Files, Next: Makefile Substitutions, Prev: Configuration Actions, Up: Setup |
| 1516 |
|
| 1517 |
4.5 Creating Configuration Files |
| 1518 |
================================ |
| 1519 |
|
| 1520 |
Be sure to read the previous section, *note Configuration Actions::. |
| 1521 |
|
| 1522 |
-- Macro: AC_CONFIG_FILES (FILE..., [CMDS], [INIT-CMDS]) |
| 1523 |
Make ‘AC_OUTPUT’ create each ‘FILE’ by copying an input file (by |
| 1524 |
default ‘FILE.in’), substituting the output variable values. This |
| 1525 |
macro is one of the instantiating macros, see *note Configuration |
| 1526 |
Actions::. *Note Makefile Substitutions::, for more information on |
| 1527 |
using output variables. *Note Setting Output Variables::, for more |
| 1528 |
information on creating them. This macro creates the directory |
| 1529 |
that the file is in if it doesn't exist. Usually, ‘Makefile’s are |
| 1530 |
created this way, but other files, such as ‘.gdbinit’, can be |
| 1531 |
specified as well. |
| 1532 |
|
| 1533 |
Typical calls to ‘AC_CONFIG_FILES’ look like this: |
| 1534 |
|
| 1535 |
AC_CONFIG_FILES(Makefile src/Makefile man/Makefile X/Imakefile) |
| 1536 |
AC_CONFIG_FILES(autoconf, chmod +x autoconf) |
| 1537 |
|
| 1538 |
You can override an input file name by appending to FILE a |
| 1539 |
colon-separated list of input files. Examples: |
| 1540 |
|
| 1541 |
AC_CONFIG_FILES(Makefile:boiler/top.mk:boiler/bot.mk |
| 1542 |
lib/Makefile:boiler/lib.mk) |
| 1543 |
|
| 1544 |
Doing this allows you to keep your file names acceptable to MS-DOS, |
| 1545 |
or to prepend and/or append boilerplate to the file. |
| 1546 |
|
| 1547 |
|
| 1548 |
File: autoconf.info, Node: Makefile Substitutions, Next: Configuration Headers, Prev: Configuration Files, Up: Setup |
| 1549 |
|
| 1550 |
4.6 Substitutions in Makefiles |
| 1551 |
============================== |
| 1552 |
|
| 1553 |
Each subdirectory in a distribution that contains something to be |
| 1554 |
compiled or installed should come with a file ‘Makefile.in’, from which |
| 1555 |
‘configure’ will create a ‘Makefile’ in that directory. To create a |
| 1556 |
‘Makefile’, ‘configure’ performs a simple variable substitution, |
| 1557 |
replacing occurrences of ‘@VARIABLE@’ in ‘Makefile.in’ with the value |
| 1558 |
that ‘configure’ has determined for that variable. Variables that are |
| 1559 |
substituted into output files in this way are called “output variables”. |
| 1560 |
They are ordinary shell variables that are set in ‘configure’. To make |
| 1561 |
‘configure’ substitute a particular variable into the output files, the |
| 1562 |
macro ‘AC_SUBST’ must be called with that variable name as an argument. |
| 1563 |
Any occurrences of ‘@VARIABLE@’ for other variables are left unchanged. |
| 1564 |
*Note Setting Output Variables::, for more information on creating |
| 1565 |
output variables with ‘AC_SUBST’. |
| 1566 |
|
| 1567 |
A software package that uses a ‘configure’ script should be |
| 1568 |
distributed with a file ‘Makefile.in’, but no ‘Makefile’; that way, the |
| 1569 |
user has to properly configure the package for the local system before |
| 1570 |
compiling it. |
| 1571 |
|
| 1572 |
*Note Makefile Conventions: (standards)Makefile Conventions, for more |
| 1573 |
information on what to put in ‘Makefile’s. |
| 1574 |
|
| 1575 |
* Menu: |
| 1576 |
|
| 1577 |
* Preset Output Variables:: Output variables that are always set |
| 1578 |
* Installation Directory Variables:: Other preset output variables |
| 1579 |
* Build Directories:: Supporting multiple concurrent compiles |
| 1580 |
* Automatic Remaking:: Makefile rules for configuring |
| 1581 |
|
| 1582 |
|
| 1583 |
File: autoconf.info, Node: Preset Output Variables, Next: Installation Directory Variables, Prev: Makefile Substitutions, Up: Makefile Substitutions |
| 1584 |
|
| 1585 |
4.6.1 Preset Output Variables |
| 1586 |
----------------------------- |
| 1587 |
|
| 1588 |
Some output variables are preset by the Autoconf macros. Some of the |
| 1589 |
Autoconf macros set additional output variables, which are mentioned in |
| 1590 |
the descriptions for those macros. *Note Output Variable Index::, for a |
| 1591 |
complete list of output variables. *Note Installation Directory |
| 1592 |
Variables::, for the list of the preset ones related to installation |
| 1593 |
directories. Below are listed the other preset ones. They all are |
| 1594 |
precious variables (*note Setting Output Variables::, ‘AC_ARG_VAR’). |
| 1595 |
|
| 1596 |
-- Variable: CFLAGS |
| 1597 |
Debugging and optimization options for the C compiler. If it is |
| 1598 |
not set in the environment when ‘configure’ runs, the default value |
| 1599 |
is set when you call ‘AC_PROG_CC’ (or empty if you don't). |
| 1600 |
‘configure’ uses this variable when compiling programs to test for |
| 1601 |
C features. |
| 1602 |
|
| 1603 |
-- Variable: configure_input |
| 1604 |
A comment saying that the file was generated automatically by |
| 1605 |
‘configure’ and giving the name of the input file. ‘AC_OUTPUT’ |
| 1606 |
adds a comment line containing this variable to the top of every |
| 1607 |
‘Makefile’ it creates. For other files, you should reference this |
| 1608 |
variable in a comment at the top of each input file. For example, |
| 1609 |
an input shell script should begin like this: |
| 1610 |
|
| 1611 |
#! /bin/sh |
| 1612 |
# @configure_input@ |
| 1613 |
|
| 1614 |
The presence of that line also reminds people editing the file that |
| 1615 |
it needs to be processed by ‘configure’ in order to be used. |
| 1616 |
|
| 1617 |
-- Variable: CPPFLAGS |
| 1618 |
Header file search directory (‘-IDIR’) and any other miscellaneous |
| 1619 |
options for the C and C++ preprocessors and compilers. If it is |
| 1620 |
not set in the environment when ‘configure’ runs, the default value |
| 1621 |
is empty. ‘configure’ uses this variable when compiling or |
| 1622 |
preprocessing programs to test for C and C++ features. |
| 1623 |
|
| 1624 |
-- Variable: CXXFLAGS |
| 1625 |
Debugging and optimization options for the C++ compiler. If it is |
| 1626 |
not set in the environment when ‘configure’ runs, the default value |
| 1627 |
is set when you call ‘AC_PROG_CXX’ (or empty if you don't). |
| 1628 |
‘configure’ uses this variable when compiling programs to test for |
| 1629 |
C++ features. |
| 1630 |
|
| 1631 |
-- Variable: DEFS |
| 1632 |
‘-D’ options to pass to the C compiler. If ‘AC_CONFIG_HEADERS’ is |
| 1633 |
called, ‘configure’ replaces ‘@DEFS@’ with ‘-DHAVE_CONFIG_H’ |
| 1634 |
instead (*note Configuration Headers::). This variable is not |
| 1635 |
defined while ‘configure’ is performing its tests, only when |
| 1636 |
creating the output files. *Note Setting Output Variables::, for |
| 1637 |
how to check the results of previous tests. |
| 1638 |
|
| 1639 |
-- Variable: ECHO_C |
| 1640 |
-- Variable: ECHO_N |
| 1641 |
-- Variable: ECHO_T |
| 1642 |
How does one suppress the trailing newline from ‘echo’ for |
| 1643 |
question-answer message pairs? These variables provide a way: |
| 1644 |
|
| 1645 |
echo $ECHO_N "And the winner is... $ECHO_C" |
| 1646 |
sleep 100000000000 |
| 1647 |
echo "${ECHO_T}dead." |
| 1648 |
|
| 1649 |
Some old and uncommon ‘echo’ implementations offer no means to |
| 1650 |
achieve this, in which case ‘ECHO_T’ is set to tab. You might not |
| 1651 |
want to use it. |
| 1652 |
|
| 1653 |
-- Variable: FFLAGS |
| 1654 |
Debugging and optimization options for the Fortran 77 compiler. If |
| 1655 |
it is not set in the environment when ‘configure’ runs, the default |
| 1656 |
value is set when you call ‘AC_PROG_F77’ (or empty if you don't). |
| 1657 |
‘configure’ uses this variable when compiling programs to test for |
| 1658 |
Fortran 77 features. |
| 1659 |
|
| 1660 |
-- Variable: LDFLAGS |
| 1661 |
Stripping (‘-s’), path (‘-L’), and any other miscellaneous options |
| 1662 |
for the linker. Don't use this variable to pass library names |
| 1663 |
(‘-l’) to the linker, use ‘LIBS’ instead. If it is not set in the |
| 1664 |
environment when ‘configure’ runs, the default value is empty. |
| 1665 |
‘configure’ uses this variable when linking programs to test for C, |
| 1666 |
C++ and Fortran 77 features. |
| 1667 |
|
| 1668 |
-- Variable: LIBS |
| 1669 |
‘-l’ options to pass to the linker. The default value is empty, |
| 1670 |
but some Autoconf macros may prepend extra libraries to this |
| 1671 |
variable if those libraries are found and provide necessary |
| 1672 |
functions, see *note Libraries::. ‘configure’ uses this variable |
| 1673 |
when linking programs to test for C, C++ and Fortran 77 features. |
| 1674 |
|
| 1675 |
-- Variable: srcdir |
| 1676 |
The directory that contains the source code for that ‘Makefile’. |
| 1677 |
|
| 1678 |
-- Variable: top_srcdir |
| 1679 |
The top-level source code directory for the package. In the |
| 1680 |
top-level directory, this is the same as ‘srcdir’. |
| 1681 |
|
| 1682 |
|
| 1683 |
File: autoconf.info, Node: Installation Directory Variables, Next: Build Directories, Prev: Preset Output Variables, Up: Makefile Substitutions |
| 1684 |
|
| 1685 |
4.6.2 Installation Directory Variables |
| 1686 |
-------------------------------------- |
| 1687 |
|
| 1688 |
The following variables specify the directories where the package will |
| 1689 |
be installed, see *note Variables for Installation Directories: |
| 1690 |
(standards)Directory Variables, for more information. See the end of |
| 1691 |
this section for details on when and how to use these variables. |
| 1692 |
|
| 1693 |
-- Variable: bindir |
| 1694 |
The directory for installing executables that users run. |
| 1695 |
|
| 1696 |
-- Variable: datadir |
| 1697 |
The directory for installing read-only architecture-independent |
| 1698 |
data. |
| 1699 |
|
| 1700 |
-- Variable: exec_prefix |
| 1701 |
The installation prefix for architecture-dependent files. By |
| 1702 |
default it's the same as PREFIX. You should avoid installing |
| 1703 |
anything directly to EXEC_PREFIX. However, the default value for |
| 1704 |
directories containing architecture-dependent files should be |
| 1705 |
relative to EXEC_PREFIX. |
| 1706 |
|
| 1707 |
-- Variable: includedir |
| 1708 |
The directory for installing C header files. |
| 1709 |
|
| 1710 |
-- Variable: infodir |
| 1711 |
The directory for installing documentation in Info format. |
| 1712 |
|
| 1713 |
-- Variable: libdir |
| 1714 |
The directory for installing object code libraries. |
| 1715 |
|
| 1716 |
-- Variable: libexecdir |
| 1717 |
The directory for installing executables that other programs run. |
| 1718 |
|
| 1719 |
-- Variable: localstatedir |
| 1720 |
The directory for installing modifiable single-machine data. |
| 1721 |
|
| 1722 |
-- Variable: mandir |
| 1723 |
The top-level directory for installing documentation in man format. |
| 1724 |
|
| 1725 |
-- Variable: oldincludedir |
| 1726 |
The directory for installing C header files for non-gcc compilers. |
| 1727 |
|
| 1728 |
-- Variable: prefix |
| 1729 |
The common installation prefix for all files. If EXEC_PREFIX is |
| 1730 |
defined to a different value, PREFIX is used only for |
| 1731 |
architecture-independent files. |
| 1732 |
|
| 1733 |
-- Variable: sbindir |
| 1734 |
The directory for installing executables that system administrators |
| 1735 |
run. |
| 1736 |
|
| 1737 |
-- Variable: sharedstatedir |
| 1738 |
The directory for installing modifiable architecture-independent |
| 1739 |
data. |
| 1740 |
|
| 1741 |
-- Variable: sysconfdir |
| 1742 |
The directory for installing read-only single-machine data. |
| 1743 |
|
| 1744 |
Most of these variables have values that rely on ‘prefix’ or |
| 1745 |
‘exec_prefix’. It is on purpose that the directory output variables |
| 1746 |
keep them unexpanded: typically ‘@datadir@’ will be replaced by |
| 1747 |
‘${prefix}/share’, not ‘/usr/local/share’. |
| 1748 |
|
| 1749 |
This behavior is mandated by the GNU coding standards, so that when |
| 1750 |
the user runs: |
| 1751 |
|
| 1752 |
‘make’ |
| 1753 |
she can still specify a different prefix from the one specified to |
| 1754 |
‘configure’, in which case, if needed, the package shall hard code |
| 1755 |
dependencies to her late desires. |
| 1756 |
|
| 1757 |
‘make install’ |
| 1758 |
she can specify a different installation location, in which case |
| 1759 |
the package _must_ still depend on the location which was compiled |
| 1760 |
in (i.e., never recompile when ‘make install’ is run). This is an |
| 1761 |
extremely important feature, as many people may decide to install |
| 1762 |
all the files of a package grouped together, and then install links |
| 1763 |
from the final locations to there. |
| 1764 |
|
| 1765 |
In order to support these features, it is essential that ‘datadir’ |
| 1766 |
remains being defined as ‘${prefix}/share’ to depend upon the current |
| 1767 |
value of ‘prefix’. |
| 1768 |
|
| 1769 |
A corollary is that you should not use these variables but in |
| 1770 |
Makefiles. For instance, instead of trying to evaluate ‘datadir’ in |
| 1771 |
‘configure’ and hardcoding it in Makefiles using e.g. |
| 1772 |
‘AC_DEFINE_UNQUOTED(DATADIR, "$datadir")’, you should add |
| 1773 |
‘-DDATADIR="$(datadir)"’ to your ‘CPPFLAGS’. |
| 1774 |
|
| 1775 |
Similarly you should not rely on ‘AC_OUTPUT_FILES’ to replace |
| 1776 |
‘datadir’ and friends in your shell scripts and other files, rather let |
| 1777 |
‘make’ manage their replacement. For instance Autoconf ships templates |
| 1778 |
of its shell scripts ending with ‘.sh’, and uses this Makefile snippet: |
| 1779 |
|
| 1780 |
.sh: |
| 1781 |
rm -f $@ [email protected] |
| 1782 |
sed 's,@datadir\@,$(pkgdatadir),g' $< >[email protected] |
| 1783 |
chmod +x [email protected] |
| 1784 |
mv [email protected] $@ |
| 1785 |
|
| 1786 |
Three things are noteworthy: |
| 1787 |
|
| 1788 |
‘@datadir\@’ |
| 1789 |
The backslash prevents ‘configure’ from replacing ‘@datadir@’ in |
| 1790 |
the sed expression itself. |
| 1791 |
|
| 1792 |
‘$(pkgdatadir)’ |
| 1793 |
Don't use ‘@pkgdatadir@’! Use the matching makefile variable |
| 1794 |
instead. |
| 1795 |
|
| 1796 |
‘,’ |
| 1797 |
Don't use ‘/’ in the sed expression(s) since most probably the |
| 1798 |
variables you use, such as ‘$(pkgdatadir)’, will contain some. |
| 1799 |
|
| 1800 |
|
| 1801 |
File: autoconf.info, Node: Build Directories, Next: Automatic Remaking, Prev: Installation Directory Variables, Up: Makefile Substitutions |
| 1802 |
|
| 1803 |
4.6.3 Build Directories |
| 1804 |
----------------------- |
| 1805 |
|
| 1806 |
You can support compiling a software package for several architectures |
| 1807 |
simultaneously from the same copy of the source code. The object files |
| 1808 |
for each architecture are kept in their own directory. |
| 1809 |
|
| 1810 |
To support doing this, ‘make’ uses the ‘VPATH’ variable to find the |
| 1811 |
files that are in the source directory. GNU ‘make’ and most other |
| 1812 |
recent ‘make’ programs can do this. Older ‘make’ programs do not |
| 1813 |
support ‘VPATH’; when using them, the source code must be in the same |
| 1814 |
directory as the object files. |
| 1815 |
|
| 1816 |
To support ‘VPATH’, each ‘Makefile.in’ should contain two lines that |
| 1817 |
look like: |
| 1818 |
|
| 1819 |
srcdir = @srcdir@ |
| 1820 |
VPATH = @srcdir@ |
| 1821 |
|
| 1822 |
Do not set ‘VPATH’ to the value of another variable, for example |
| 1823 |
‘VPATH = $(srcdir)’, because some versions of ‘make’ do not do variable |
| 1824 |
substitutions on the value of ‘VPATH’. |
| 1825 |
|
| 1826 |
‘configure’ substitutes in the correct value for ‘srcdir’ when it |
| 1827 |
produces ‘Makefile’. |
| 1828 |
|
| 1829 |
Do not use the ‘make’ variable ‘$<’, which expands to the file name |
| 1830 |
of the file in the source directory (found with ‘VPATH’), except in |
| 1831 |
implicit rules. (An implicit rule is one such as ‘.c.o’, which tells |
| 1832 |
how to create a ‘.o’ file from a ‘.c’ file.) Some versions of ‘make’ do |
| 1833 |
not set ‘$<’ in explicit rules; they expand it to an empty value. |
| 1834 |
|
| 1835 |
Instead, ‘Makefile’ command lines should always refer to source files |
| 1836 |
by prefixing them with ‘$(srcdir)/’. For example: |
| 1837 |
|
| 1838 |
time.info: time.texinfo |
| 1839 |
$(MAKEINFO) $(srcdir)/time.texinfo |
| 1840 |
|
| 1841 |
|
| 1842 |
File: autoconf.info, Node: Automatic Remaking, Prev: Build Directories, Up: Makefile Substitutions |
| 1843 |
|
| 1844 |
4.6.4 Automatic Remaking |
| 1845 |
------------------------ |
| 1846 |
|
| 1847 |
You can put rules like the following in the top-level ‘Makefile.in’ for |
| 1848 |
a package to automatically update the configuration information when you |
| 1849 |
change the configuration files. This example includes all of the |
| 1850 |
optional files, such as ‘aclocal.m4’ and those related to configuration |
| 1851 |
header files. Omit from the ‘Makefile.in’ rules for any of these files |
| 1852 |
that your package does not use. |
| 1853 |
|
| 1854 |
The ‘$(srcdir)/’ prefix is included because of limitations in the |
| 1855 |
‘VPATH’ mechanism. |
| 1856 |
|
| 1857 |
The ‘stamp-’ files are necessary because the timestamps of |
| 1858 |
‘config.h.in’ and ‘config.h’ will not be changed if remaking them does |
| 1859 |
not change their contents. This feature avoids unnecessary |
| 1860 |
recompilation. You should include the file ‘stamp-h.in’ your package's |
| 1861 |
distribution, so ‘make’ will consider ‘config.h.in’ up to date. Don't |
| 1862 |
use ‘touch’ (*note Limitations of Usual Tools::), rather use ‘echo’ |
| 1863 |
(using ‘date’ would cause needless differences, hence CVS conflicts |
| 1864 |
etc.). |
| 1865 |
|
| 1866 |
$(srcdir)/configure: configure.ac aclocal.m4 |
| 1867 |
cd $(srcdir) && autoconf |
| 1868 |
|
| 1869 |
# autoheader might not change config.h.in, so touch a stamp file. |
| 1870 |
$(srcdir)/config.h.in: stamp-h.in |
| 1871 |
$(srcdir)/stamp-h.in: configure.ac aclocal.m4 |
| 1872 |
cd $(srcdir) && autoheader |
| 1873 |
echo timestamp > $(srcdir)/stamp-h.in |
| 1874 |
|
| 1875 |
config.h: stamp-h |
| 1876 |
stamp-h: config.h.in config.status |
| 1877 |
./config.status |
| 1878 |
|
| 1879 |
Makefile: Makefile.in config.status |
| 1880 |
./config.status |
| 1881 |
|
| 1882 |
config.status: configure |
| 1883 |
./config.status --recheck |
| 1884 |
|
| 1885 |
(Be careful if you copy these lines directly into your Makefile, as you |
| 1886 |
will need to convert the indented lines to start with the tab |
| 1887 |
character.) |
| 1888 |
|
| 1889 |
In addition, you should use ‘AC_CONFIG_FILES(stamp-h, echo timestamp |
| 1890 |
> stamp-h)’ so ‘config.status’ will ensure that ‘config.h’ is considered |
| 1891 |
up to date. *Note Output::, for more information about ‘AC_OUTPUT’. |
| 1892 |
|
| 1893 |
*Note config.status Invocation::, for more examples of handling |
| 1894 |
configuration-related dependencies. |
| 1895 |
|
| 1896 |
|
| 1897 |
File: autoconf.info, Node: Configuration Headers, Next: Configuration Commands, Prev: Makefile Substitutions, Up: Setup |
| 1898 |
|
| 1899 |
4.7 Configuration Header Files |
| 1900 |
============================== |
| 1901 |
|
| 1902 |
When a package tests more than a few C preprocessor symbols, the command |
| 1903 |
lines to pass ‘-D’ options to the compiler can get quite long. This |
| 1904 |
causes two problems. One is that the ‘make’ output is hard to visually |
| 1905 |
scan for errors. More seriously, the command lines can exceed the |
| 1906 |
length limits of some operating systems. As an alternative to passing |
| 1907 |
‘-D’ options to the compiler, ‘configure’ scripts can create a C header |
| 1908 |
file containing ‘#define’ directives. The ‘AC_CONFIG_HEADERS’ macro |
| 1909 |
selects this kind of output. It should be called right after ‘AC_INIT’. |
| 1910 |
|
| 1911 |
The package should ‘#include’ the configuration header file before |
| 1912 |
any other header files, to prevent inconsistencies in declarations (for |
| 1913 |
example, if it redefines ‘const’). Use ‘#include <config.h>’ instead of |
| 1914 |
‘#include "config.h"’, and pass the C compiler a ‘-I.’ option (or |
| 1915 |
‘-I..’; whichever directory contains ‘config.h’). That way, even if the |
| 1916 |
source directory is configured itself (perhaps to make a distribution), |
| 1917 |
other build directories can also be configured without finding the |
| 1918 |
‘config.h’ from the source directory. |
| 1919 |
|
| 1920 |
-- Macro: AC_CONFIG_HEADERS (HEADER ..., [CMDS], [INIT-CMDS]) |
| 1921 |
This macro is one of the instantiating macros, see *note |
| 1922 |
Configuration Actions::. Make ‘AC_OUTPUT’ create the file(s) in |
| 1923 |
the whitespace-separated list HEADER containing C preprocessor |
| 1924 |
‘#define’ statements, and replace ‘@DEFS@’ in generated files with |
| 1925 |
‘-DHAVE_CONFIG_H’ instead of the value of ‘DEFS’. The usual name |
| 1926 |
for HEADER is ‘config.h’. |
| 1927 |
|
| 1928 |
If HEADER already exists and its contents are identical to what |
| 1929 |
‘AC_OUTPUT’ would put in it, it is left alone. Doing this allows |
| 1930 |
some changes in configuration without needlessly causing object |
| 1931 |
files that depend on the header file to be recompiled. |
| 1932 |
|
| 1933 |
Usually the input file is named ‘HEADER.in’; however, you can |
| 1934 |
override the input file name by appending to HEADER, a |
| 1935 |
colon-separated list of input files. Examples: |
| 1936 |
|
| 1937 |
AC_CONFIG_HEADERS(config.h:config.hin) |
| 1938 |
AC_CONFIG_HEADERS(defines.h:defs.pre:defines.h.in:defs.post) |
| 1939 |
|
| 1940 |
Doing this allows you to keep your file names acceptable to MS-DOS, |
| 1941 |
or to prepend and/or append boilerplate to the file. |
| 1942 |
|
| 1943 |
*Note Configuration Actions::, for more details on HEADER. |
| 1944 |
|
| 1945 |
* Menu: |
| 1946 |
|
| 1947 |
* Header Templates:: Input for the configuration headers |
| 1948 |
* autoheader Invocation:: How to create configuration templates |
| 1949 |
* Autoheader Macros:: How to specify CPP templates |
| 1950 |
|
| 1951 |
|
| 1952 |
File: autoconf.info, Node: Header Templates, Next: autoheader Invocation, Prev: Configuration Headers, Up: Configuration Headers |
| 1953 |
|
| 1954 |
4.7.1 Configuration Header Templates |
| 1955 |
------------------------------------ |
| 1956 |
|
| 1957 |
Your distribution should contain a template file that looks as you want |
| 1958 |
the final header file to look, including comments, with ‘#undef’ |
| 1959 |
statements which are used as hooks. For example, suppose your |
| 1960 |
‘configure.ac’ makes these calls: |
| 1961 |
|
| 1962 |
AC_CONFIG_HEADERS(conf.h) |
| 1963 |
AC_CHECK_HEADERS(unistd.h) |
| 1964 |
|
| 1965 |
Then you could have code like the following in ‘conf.h.in’. On systems |
| 1966 |
that have ‘unistd.h’, ‘configure’ will ‘#define’ ‘HAVE_UNISTD_H’ to 1. |
| 1967 |
On other systems, the whole line will be commented out (in case the |
| 1968 |
system predefines that symbol). |
| 1969 |
|
| 1970 |
/* Define as 1 if you have unistd.h. */ |
| 1971 |
#undef HAVE_UNISTD_H |
| 1972 |
|
| 1973 |
You can then decode the configuration header using the preprocessor |
| 1974 |
directives: |
| 1975 |
|
| 1976 |
#include <conf.h> |
| 1977 |
|
| 1978 |
#if HAVE_UNISTD_H |
| 1979 |
# include <unistd.h> |
| 1980 |
#else |
| 1981 |
/* We are in trouble. */ |
| 1982 |
#endif |
| 1983 |
|
| 1984 |
The use of old form templates, with ‘#define’ instead of ‘#undef’ is |
| 1985 |
strongly discouraged. |
| 1986 |
|
| 1987 |
Since it is a tedious task to keep a template header up to date, you |
| 1988 |
may use ‘autoheader’ to generate it, see *note autoheader Invocation::. |
| 1989 |
|
| 1990 |
|
| 1991 |
File: autoconf.info, Node: autoheader Invocation, Next: Autoheader Macros, Prev: Header Templates, Up: Configuration Headers |
| 1992 |
|
| 1993 |
4.7.2 Using ‘autoheader’ to Create ‘config.h.in’ |
| 1994 |
------------------------------------------------ |
| 1995 |
|
| 1996 |
The ‘autoheader’ program can create a template file of C ‘#define’ |
| 1997 |
statements for ‘configure’ to use. If ‘configure.ac’ invokes |
| 1998 |
‘AC_CONFIG_HEADERS(FILE)’, ‘autoheader’ creates ‘FILE.in’; if multiple |
| 1999 |
file arguments are given, the first one is used. Otherwise, |
| 2000 |
‘autoheader’ creates ‘config.h.in’. |
| 2001 |
|
| 2002 |
In order to do its job, ‘autoheader’ needs you to document all of the |
| 2003 |
symbols that you might use; i.e., there must be at least one ‘AC_DEFINE’ |
| 2004 |
or one ‘AC_DEFINE_UNQUOTED’ using its third argument for each symbol |
| 2005 |
(*note Defining Symbols::). An additional constraint is that the first |
| 2006 |
argument of ‘AC_DEFINE’ must be a literal. Note that all symbols |
| 2007 |
defined by Autoconf's built-in tests are already documented properly; |
| 2008 |
you only need to document those that you define yourself. |
| 2009 |
|
| 2010 |
You might wonder why ‘autoheader’ is needed: after all, why would |
| 2011 |
‘configure’ need to "patch" a ‘config.h.in’ to produce a ‘config.h’ |
| 2012 |
instead of just creating ‘config.h’ from scratch? Well, when everything |
| 2013 |
rocks, the answer is just that we are wasting our time maintaining |
| 2014 |
‘autoheader’: generating ‘config.h’ directly is all that is needed. |
| 2015 |
When things go wrong, however, you'll be thankful for the existence of |
| 2016 |
‘autoheader’. |
| 2017 |
|
| 2018 |
The fact that the symbols are documented is important in order to |
| 2019 |
_check_ that ‘config.h’ makes sense. The fact that there is a well |
| 2020 |
defined list of symbols that should be ‘#define’'d (or not) is also |
| 2021 |
important for people who are porting packages to environments where |
| 2022 |
‘configure’ cannot be run: they just have to _fill in the blanks_. |
| 2023 |
|
| 2024 |
But let's come back to the point: ‘autoheader’'s invocation... |
| 2025 |
|
| 2026 |
If you give ‘autoheader’ an argument, it uses that file instead of |
| 2027 |
‘configure.ac’ and writes the header file to the standard output instead |
| 2028 |
of to ‘config.h.in’. If you give ‘autoheader’ an argument of ‘-’, it |
| 2029 |
reads the standard input instead of ‘configure.ac’ and writes the header |
| 2030 |
file to the standard output. |
| 2031 |
|
| 2032 |
‘autoheader’ accepts the following options: |
| 2033 |
|
| 2034 |
‘--help’ |
| 2035 |
‘-h’ |
| 2036 |
Print a summary of the command line options and exit. |
| 2037 |
|
| 2038 |
‘--version’ |
| 2039 |
‘-V’ |
| 2040 |
Print the version number of Autoconf and exit. |
| 2041 |
|
| 2042 |
‘--debug’ |
| 2043 |
‘-d’ |
| 2044 |
Don't remove the temporary files. |
| 2045 |
|
| 2046 |
‘--verbose’ |
| 2047 |
‘-v’ |
| 2048 |
Report processing steps. |
| 2049 |
|
| 2050 |
‘--autoconf-dir=DIR’ |
| 2051 |
‘-A DIR’ |
| 2052 |
Override the location where the installed Autoconf data files are |
| 2053 |
looked for. You can also set the ‘AC_MACRODIR’ environment |
| 2054 |
variable to a directory; this option overrides the environment |
| 2055 |
variable. |
| 2056 |
|
| 2057 |
This option is rarely needed and dangerous; it is only used when |
| 2058 |
one plays with different versions of Autoconf simultaneously. |
| 2059 |
|
| 2060 |
‘--localdir=DIR’ |
| 2061 |
‘-l DIR’ |
| 2062 |
Look for the package files ‘aclocal.m4’ and ‘acconfig.h’ (but not |
| 2063 |
‘FILE.top’ and ‘FILE.bot’) in directory DIR instead of in the |
| 2064 |
current directory. |
| 2065 |
|
| 2066 |
‘--warnings=CATEGORY’ |
| 2067 |
‘-W CATEGORY’ |
| 2068 |
Report the warnings related to CATEGORY (which can actually be a |
| 2069 |
comma separated list). Current categories include: |
| 2070 |
|
| 2071 |
‘obsolete’ |
| 2072 |
report the uses of obsolete constructs |
| 2073 |
|
| 2074 |
‘all’ |
| 2075 |
report all the warnings |
| 2076 |
|
| 2077 |
‘none’ |
| 2078 |
report none |
| 2079 |
|
| 2080 |
‘error’ |
| 2081 |
treats warnings as errors |
| 2082 |
|
| 2083 |
‘no-CATEGORY’ |
| 2084 |
disable warnings falling into CATEGORY |
| 2085 |
|
| 2086 |
|
| 2087 |
File: autoconf.info, Node: Autoheader Macros, Prev: autoheader Invocation, Up: Configuration Headers |
| 2088 |
|
| 2089 |
4.7.3 Autoheader Macros |
| 2090 |
----------------------- |
| 2091 |
|
| 2092 |
‘autoheader’ scans ‘configure.ac’ and figures out which C preprocessor |
| 2093 |
symbols it might define. It knows how to generate templates for symbols |
| 2094 |
defined by ‘AC_CHECK_HEADERS’, ‘AC_CHECK_FUNCS’ etc., but if you |
| 2095 |
‘AC_DEFINE’ any additional symbol, you must define a template for it. |
| 2096 |
If there are missing templates, ‘autoheader’ fails with an error |
| 2097 |
message. |
| 2098 |
|
| 2099 |
The simplest way to create a template for a SYMBOL is to supply the |
| 2100 |
DESCRIPTION argument to an ‘AC_DEFINE(SYMBOL)’; see *note Defining |
| 2101 |
Symbols::. You may also use one of the following macros. |
| 2102 |
|
| 2103 |
-- Macro: AH_VERBATIM (KEY, TEMPLATE) |
| 2104 |
Tell ‘autoheader’ to include the TEMPLATE as-is in the header |
| 2105 |
template file. This TEMPLATE is associated with the KEY, which is |
| 2106 |
used to sort all the different templates and guarantee their |
| 2107 |
uniqueness. It should be the symbol that can be ‘AC_DEFINE’'d. |
| 2108 |
|
| 2109 |
For example: |
| 2110 |
|
| 2111 |
AH_VERBATIM([_GNU_SOURCE], |
| 2112 |
[/* Enable GNU extensions on systems that have them. */ |
| 2113 |
#ifndef _GNU_SOURCE |
| 2114 |
# define _GNU_SOURCE |
| 2115 |
#endif]) |
| 2116 |
|
| 2117 |
-- Macro: AH_TEMPLATE (KEY, DESCRIPTION) |
| 2118 |
Tell ‘autoheader’ to generate a template for KEY. This macro |
| 2119 |
generates standard templates just like ‘AC_DEFINE’ when a |
| 2120 |
DESCRIPTION is given. |
| 2121 |
|
| 2122 |
For example: |
| 2123 |
|
| 2124 |
AH_TEMPLATE([CRAY_STACKSEG_END], |
| 2125 |
[Define to one of _getb67, GETB67, getb67 |
| 2126 |
for Cray-2 and Cray-YMP systems. This |
| 2127 |
function is required for alloca.c support |
| 2128 |
on those systems.]) |
| 2129 |
|
| 2130 |
will generate the following template, with the description properly |
| 2131 |
justified. |
| 2132 |
|
| 2133 |
/* Define to one of _getb67, GETB67, getb67 for Cray-2 and |
| 2134 |
Cray-YMP systems. This function is required for alloca.c |
| 2135 |
support on those systems. */ |
| 2136 |
#undef CRAY_STACKSEG_END |
| 2137 |
|
| 2138 |
-- Macro: AH_TOP (TEXT) |
| 2139 |
Include TEXT at the top of the header template file. |
| 2140 |
|
| 2141 |
-- Macro: AH_BOTTOM (TEXT) |
| 2142 |
Include TEXT at the bottom of the header template file. |
| 2143 |
|
| 2144 |
|
| 2145 |
File: autoconf.info, Node: Configuration Commands, Next: Configuration Links, Prev: Configuration Headers, Up: Setup |
| 2146 |
|
| 2147 |
4.8 Running Arbitrary Configuration Commands |
| 2148 |
============================================ |
| 2149 |
|
| 2150 |
You execute arbitrary commands either before, during and after |
| 2151 |
‘config.status’ is run. The three following macros accumulate the |
| 2152 |
commands to run when they are called multiple times. |
| 2153 |
‘AC_CONFIG_COMMANDS’ replaces the obsolete macro ‘AC_OUTPUT_COMMANDS’, |
| 2154 |
see *note Obsolete Macros::, for details. |
| 2155 |
|
| 2156 |
-- Macro: AC_CONFIG_COMMANDS (TAG..., [CMDS], [INIT-CMDS]) |
| 2157 |
Specify additional shell commands to run at the end of |
| 2158 |
‘config.status’, and shell commands to initialize any variables |
| 2159 |
from ‘configure’. Associate the commands to the TAG. Since |
| 2160 |
typically the CMDS create a file, TAG should naturally be the name |
| 2161 |
of that file. This macro is one of the instantiating macros, see |
| 2162 |
*note Configuration Actions::. |
| 2163 |
|
| 2164 |
Here is an unrealistic example: |
| 2165 |
fubar=42 |
| 2166 |
AC_CONFIG_COMMANDS(fubar, |
| 2167 |
[echo this is extra $fubar, and so on.], |
| 2168 |
[fubar=$fubar]) |
| 2169 |
|
| 2170 |
Here is a better one: |
| 2171 |
AC_CONFIG_COMMANDS(time-stamp, [date >time-stamp]) |
| 2172 |
|
| 2173 |
-- Macro: AC_CONFIG_COMMANDS_PRE (CMDS) |
| 2174 |
Execute the CMDS right before creating ‘config.status’. A typical |
| 2175 |
use is computing values derived from variables built during the |
| 2176 |
execution of ‘configure’: |
| 2177 |
|
| 2178 |
AC_CONFIG_COMMANDS_PRE( |
| 2179 |
[LTLIBOBJS=`echo $LIBOBJS | sed 's/\.o/\.lo/g'` |
| 2180 |
AC_SUBST(LTLIBOBJS)]) |
| 2181 |
|
| 2182 |
-- Macro: AC_CONFIG_COMMANDS_POST (CMDS) |
| 2183 |
Execute the CMDS right after creating ‘config.status’. |
| 2184 |
|
| 2185 |
|
| 2186 |
File: autoconf.info, Node: Configuration Links, Next: Subdirectories, Prev: Configuration Commands, Up: Setup |
| 2187 |
|
| 2188 |
4.9 Creating Configuration Links |
| 2189 |
================================ |
| 2190 |
|
| 2191 |
You may find it convenient to create links whose destinations depend |
| 2192 |
upon results of tests. One can use ‘AC_CONFIG_COMMANDS’ but the |
| 2193 |
creation of relative symbolic links can be delicate when the package is |
| 2194 |
built in another directory than its sources. |
| 2195 |
|
| 2196 |
-- Macro: AC_CONFIG_LINKS (DEST:SOURCE..., [CMDS], [INIT-CMDS]) |
| 2197 |
Make ‘AC_OUTPUT’ link each of the existing files SOURCE to the |
| 2198 |
corresponding link name DEST. Makes a symbolic link if possible, |
| 2199 |
otherwise a hard link. The DEST and SOURCE names should be |
| 2200 |
relative to the top level source or build directory. This macro is |
| 2201 |
one of the instantiating macros, see *note Configuration Actions::. |
| 2202 |
|
| 2203 |
For example, this call: |
| 2204 |
|
| 2205 |
AC_CONFIG_LINKS(host.h:config/$machine.h |
| 2206 |
object.h:config/$obj_format.h) |
| 2207 |
|
| 2208 |
creates in the current directory ‘host.h’ as a link to |
| 2209 |
‘SRCDIR/config/$machine.h’, and ‘object.h’ as a link to |
| 2210 |
‘SRCDIR/config/$obj_format.h’. |
| 2211 |
|
| 2212 |
The tempting value ‘.’ for DEST is invalid: it makes it impossible |
| 2213 |
for ‘config.status’ to guess the links to establish. |
| 2214 |
|
| 2215 |
One can then run: |
| 2216 |
./config.status host.h object.h |
| 2217 |
to create the links. |
| 2218 |
|
| 2219 |
|
| 2220 |
File: autoconf.info, Node: Subdirectories, Next: Default Prefix, Prev: Configuration Links, Up: Setup |
| 2221 |
|
| 2222 |
4.10 Configuring Other Packages in Subdirectories |
| 2223 |
================================================= |
| 2224 |
|
| 2225 |
In most situations, calling ‘AC_OUTPUT’ is sufficient to produce |
| 2226 |
‘Makefile’s in subdirectories. However, ‘configure’ scripts that |
| 2227 |
control more than one independent package can use ‘AC_CONFIG_SUBDIRS’ to |
| 2228 |
run ‘configure’ scripts for other packages in subdirectories. |
| 2229 |
|
| 2230 |
-- Macro: AC_CONFIG_SUBDIRS (DIR ...) |
| 2231 |
Make ‘AC_OUTPUT’ run ‘configure’ in each subdirectory DIR in the |
| 2232 |
given whitespace-separated list. Each DIR should be a literal, |
| 2233 |
i.e., please do not use: |
| 2234 |
|
| 2235 |
if test "$package_foo_enabled" = yes; then |
| 2236 |
$my_subdirs="$my_subdirs foo" |
| 2237 |
fi |
| 2238 |
AC_CONFIG_SUBDIRS($my_subdirs) |
| 2239 |
|
| 2240 |
because this prevents ‘./configure --help=recursive’ from |
| 2241 |
displaying the options of the package ‘foo’. Rather, you should |
| 2242 |
write: |
| 2243 |
|
| 2244 |
if test "$package_foo_enabled" = yes then; |
| 2245 |
AC_CONFIG_SUBDIRS(foo) |
| 2246 |
fi |
| 2247 |
|
| 2248 |
If a given DIR is not found, no error is reported, so a ‘configure’ |
| 2249 |
script can configure whichever parts of a large source tree are |
| 2250 |
present. If a given DIR contains ‘configure.gnu’, it is run |
| 2251 |
instead of ‘configure’. This is for packages that might use a |
| 2252 |
non-autoconf script ‘Configure’, which can't be called through a |
| 2253 |
wrapper ‘configure’ since it would be the same file on |
| 2254 |
case-insensitive filesystems. Likewise, if a DIR contains |
| 2255 |
‘configure.ac’ but no ‘configure’, the Cygnus ‘configure’ script |
| 2256 |
found by ‘AC_CONFIG_AUX_DIR’ is used. |
| 2257 |
|
| 2258 |
The subdirectory ‘configure’ scripts are given the same command |
| 2259 |
line options that were given to this ‘configure’ script, with minor |
| 2260 |
changes if needed (e.g., to adjust a relative path for the cache |
| 2261 |
file or source directory). This macro also sets the output |
| 2262 |
variable ‘subdirs’ to the list of directories ‘DIR ...’. |
| 2263 |
‘Makefile’ rules can use this variable to determine which |
| 2264 |
subdirectories to recurse into. This macro may be called multiple |
| 2265 |
times. |
| 2266 |
|
| 2267 |
|
| 2268 |
File: autoconf.info, Node: Default Prefix, Prev: Subdirectories, Up: Setup |
| 2269 |
|
| 2270 |
4.11 Default Prefix |
| 2271 |
=================== |
| 2272 |
|
| 2273 |
By default, ‘configure’ sets the prefix for files it installs to |
| 2274 |
‘/usr/local’. The user of ‘configure’ can select a different prefix |
| 2275 |
using the ‘--prefix’ and ‘--exec-prefix’ options. There are two ways to |
| 2276 |
change the default: when creating ‘configure’, and when running it. |
| 2277 |
|
| 2278 |
Some software packages might want to install in a directory besides |
| 2279 |
‘/usr/local’ by default. To accomplish that, use the |
| 2280 |
‘AC_PREFIX_DEFAULT’ macro. |
| 2281 |
|
| 2282 |
-- Macro: AC_PREFIX_DEFAULT (PREFIX) |
| 2283 |
Set the default installation prefix to PREFIX instead of |
| 2284 |
‘/usr/local’. |
| 2285 |
|
| 2286 |
It may be convenient for users to have ‘configure’ guess the |
| 2287 |
installation prefix from the location of a related program that they |
| 2288 |
have already installed. If you wish to do that, you can call |
| 2289 |
‘AC_PREFIX_PROGRAM’. |
| 2290 |
|
| 2291 |
-- Macro: AC_PREFIX_PROGRAM (PROGRAM) |
| 2292 |
If the user did not specify an installation prefix (using the |
| 2293 |
‘--prefix’ option), guess a value for it by looking for PROGRAM in |
| 2294 |
‘PATH’, the way the shell does. If PROGRAM is found, set the |
| 2295 |
prefix to the parent of the directory containing PROGRAM; otherwise |
| 2296 |
leave the prefix specified in ‘Makefile.in’ unchanged. For |
| 2297 |
example, if PROGRAM is ‘gcc’ and the ‘PATH’ contains |
| 2298 |
‘/usr/local/gnu/bin/gcc’, set the prefix to ‘/usr/local/gnu’. |
| 2299 |
|
| 2300 |
|
| 2301 |
File: autoconf.info, Node: Existing Tests, Next: Writing Tests, Prev: Setup, Up: Top |
| 2302 |
|
| 2303 |
5 Existing Tests |
| 2304 |
**************** |
| 2305 |
|
| 2306 |
These macros test for particular system features that packages might |
| 2307 |
need or want to use. If you need to test for a kind of feature that |
| 2308 |
none of these macros check for, you can probably do it by calling |
| 2309 |
primitive test macros with appropriate arguments (*note Writing |
| 2310 |
Tests::). |
| 2311 |
|
| 2312 |
These tests print messages telling the user which feature they're |
| 2313 |
checking for, and what they find. They cache their results for future |
| 2314 |
‘configure’ runs (*note Caching Results::). |
| 2315 |
|
| 2316 |
Some of these macros set output variables. *Note Makefile |
| 2317 |
Substitutions::, for how to get their values. The phrase "define NAME" |
| 2318 |
is used below as a shorthand to mean "define C preprocessor symbol NAME |
| 2319 |
to the value 1". *Note Defining Symbols::, for how to get those symbol |
| 2320 |
definitions into your program. |
| 2321 |
|
| 2322 |
* Menu: |
| 2323 |
|
| 2324 |
* Common Behavior:: Macros' standard schemes |
| 2325 |
* Alternative Programs:: Selecting between alternative programs |
| 2326 |
* Files:: Checking for the existence of files |
| 2327 |
* Libraries:: Library archives that might be missing |
| 2328 |
* Library Functions:: C library functions that might be missing |
| 2329 |
* Header Files:: Header files that might be missing |
| 2330 |
* Declarations:: Declarations that may be missing |
| 2331 |
* Structures:: Structures or members that might be missing |
| 2332 |
* Types:: Types that might be missing |
| 2333 |
* Compilers and Preprocessors:: Checking for compiling programs |
| 2334 |
* System Services:: Operating system services |
| 2335 |
* UNIX Variants:: Special kludges for specific UNIX variants |
| 2336 |
|
| 2337 |
|
| 2338 |
File: autoconf.info, Node: Common Behavior, Next: Alternative Programs, Prev: Existing Tests, Up: Existing Tests |
| 2339 |
|
| 2340 |
5.1 Common Behavior |
| 2341 |
=================== |
| 2342 |
|
| 2343 |
Much effort has been expended to make Autoconf easy to learn. The most |
| 2344 |
obvious way to reach this goal is simply to enforce standard interfaces |
| 2345 |
and behaviors, avoiding exceptions as much as possible. Because of |
| 2346 |
history and inertia, unfortunately, there are still too many exceptions |
| 2347 |
in Autoconf; nevertheless, this section describes some of the common |
| 2348 |
rules. |
| 2349 |
|
| 2350 |
* Menu: |
| 2351 |
|
| 2352 |
* Standard Symbols:: Symbols defined by the macros |
| 2353 |
* Default Includes:: Includes used by the generic macros |
| 2354 |
|
| 2355 |
|
| 2356 |
File: autoconf.info, Node: Standard Symbols, Next: Default Includes, Prev: Common Behavior, Up: Common Behavior |
| 2357 |
|
| 2358 |
5.1.1 Standard Symbols |
| 2359 |
---------------------- |
| 2360 |
|
| 2361 |
All the generic macros that ‘AC_DEFINE’ a symbol as a result of their |
| 2362 |
test transform their ARGUMENTs to a standard alphabet. First, ARGUMENT |
| 2363 |
is converted to upper case and any asterisks (‘*’) are each converted to |
| 2364 |
‘P’. Any remaining characters that are not alphanumeric are converted |
| 2365 |
to underscores. |
| 2366 |
|
| 2367 |
For instance, |
| 2368 |
|
| 2369 |
AC_CHECK_TYPES(struct $Expensive*) |
| 2370 |
|
| 2371 |
will define the symbol ‘HAVE_STRUCT__EXPENSIVEP’ if the check succeeds. |
| 2372 |
|
| 2373 |
|
| 2374 |
File: autoconf.info, Node: Default Includes, Prev: Standard Symbols, Up: Common Behavior |
| 2375 |
|
| 2376 |
5.1.2 Default Includes |
| 2377 |
---------------------- |
| 2378 |
|
| 2379 |
Several tests depend upon a set of header files. Since these headers |
| 2380 |
are not universally available, tests actually have to provide a set of |
| 2381 |
protected includes, such as: |
| 2382 |
|
| 2383 |
#if TIME_WITH_SYS_TIME |
| 2384 |
# include <sys/time.h> |
| 2385 |
# include <time.h> |
| 2386 |
#else |
| 2387 |
# if HAVE_SYS_TIME_H |
| 2388 |
# include <sys/time.h> |
| 2389 |
# else |
| 2390 |
# include <time.h> |
| 2391 |
# endif |
| 2392 |
#endif |
| 2393 |
|
| 2394 |
Unless you know exactly what you are doing, you should avoid using |
| 2395 |
unconditional includes, and check the existence of the headers you |
| 2396 |
include beforehand (*note Header Files::). |
| 2397 |
|
| 2398 |
Most generic macros provide the following default set of includes: |
| 2399 |
|
| 2400 |
#include <stdio.h> |
| 2401 |
#if HAVE_SYS_TYPES_H |
| 2402 |
# include <sys/types.h> |
| 2403 |
#endif |
| 2404 |
#if HAVE_SYS_STAT_H |
| 2405 |
# include <sys/stat.h> |
| 2406 |
#endif |
| 2407 |
#if STDC_HEADERS |
| 2408 |
# include <stdlib.h> |
| 2409 |
# include <stddef.h> |
| 2410 |
#else |
| 2411 |
# if HAVE_STDLIB_H |
| 2412 |
# include <stdlib.h> |
| 2413 |
# endif |
| 2414 |
#endif |
| 2415 |
#if HAVE_STRING_H |
| 2416 |
# if !STDC_HEADERS && HAVE_MEMORY_H |
| 2417 |
# include <memory.h> |
| 2418 |
# endif |
| 2419 |
# include <string.h> |
| 2420 |
#endif |
| 2421 |
#if HAVE_STRINGS_H |
| 2422 |
# include <strings.h> |
| 2423 |
#endif |
| 2424 |
#if HAVE_INTTYPES_H |
| 2425 |
# include <inttypes.h> |
| 2426 |
#else |
| 2427 |
# if HAVE_STDINT_H |
| 2428 |
# include <stdint.h> |
| 2429 |
# endif |
| 2430 |
#endif |
| 2431 |
#if HAVE_UNISTD_H |
| 2432 |
# include <unistd.h> |
| 2433 |
#endif |
| 2434 |
|
| 2435 |
If the default includes are used, then Autoconf will automatically |
| 2436 |
check for the presence of these headers and their compatibility, i.e., |
| 2437 |
you don't need to run ‘AC_HEADERS_STDC’, nor check for ‘stdlib.h’ etc. |
| 2438 |
|
| 2439 |
These headers are checked for in the same order as they are included. |
| 2440 |
For instance, on some systems ‘string.h’ and ‘strings.h’ both exist, but |
| 2441 |
conflict. Then ‘HAVE_STRING_H’ will be defined, but ‘HAVE_STRINGS_H’ |
| 2442 |
won't. |
| 2443 |
|
| 2444 |
|
| 2445 |
File: autoconf.info, Node: Alternative Programs, Next: Files, Prev: Common Behavior, Up: Existing Tests |
| 2446 |
|
| 2447 |
5.2 Alternative Programs |
| 2448 |
======================== |
| 2449 |
|
| 2450 |
These macros check for the presence or behavior of particular programs. |
| 2451 |
They are used to choose between several alternative programs and to |
| 2452 |
decide what to do once one has been chosen. If there is no macro |
| 2453 |
specifically defined to check for a program you need, and you don't need |
| 2454 |
to check for any special properties of it, then you can use one of the |
| 2455 |
general program-check macros. |
| 2456 |
|
| 2457 |
* Menu: |
| 2458 |
|
| 2459 |
* Particular Programs:: Special handling to find certain programs |
| 2460 |
* Generic Programs:: How to find other programs |
| 2461 |
|
| 2462 |
|
| 2463 |
File: autoconf.info, Node: Particular Programs, Next: Generic Programs, Prev: Alternative Programs, Up: Alternative Programs |
| 2464 |
|
| 2465 |
5.2.1 Particular Program Checks |
| 2466 |
------------------------------- |
| 2467 |
|
| 2468 |
These macros check for particular programs--whether they exist, and in |
| 2469 |
some cases whether they support certain features. |
| 2470 |
|
| 2471 |
-- Macro: AC_PROG_AWK |
| 2472 |
Check for ‘mawk’, ‘gawk’, ‘nawk’, and ‘awk’, in that order, and set |
| 2473 |
output variable ‘AWK’ to the first one that is found. It tries |
| 2474 |
‘mawk’ first because that is reported to be the fastest |
| 2475 |
implementation. |
| 2476 |
|
| 2477 |
-- Macro: AC_PROG_EGREP |
| 2478 |
Check for ‘grep -E’, ‘egrep’ in that order, and set output variable |
| 2479 |
‘EGREP’ to the first one that is found. |
| 2480 |
|
| 2481 |
-- Macro: AC_PROG_FGREP |
| 2482 |
Check for ‘grep -F’, ‘fgrep’ in that order, and set output variable |
| 2483 |
‘FGREP’ to the first one that is found. |
| 2484 |
|
| 2485 |
-- Macro: AC_PROG_GREP |
| 2486 |
Check for ‘grep’, ‘ggrep’ in that order, and set output variable |
| 2487 |
‘GREP’ to the first one that is found. |
| 2488 |
|
| 2489 |
-- Macro: AC_PROG_INSTALL |
| 2490 |
Set output variable ‘INSTALL’ to the path of a BSD compatible |
| 2491 |
‘install’ program, if one is found in the current ‘PATH’. |
| 2492 |
Otherwise, set ‘INSTALL’ to ‘DIR/install-sh -c’, checking the |
| 2493 |
directories specified to ‘AC_CONFIG_AUX_DIR’ (or its default |
| 2494 |
directories) to determine DIR (*note Output::). Also set the |
| 2495 |
variables ‘INSTALL_PROGRAM’ and ‘INSTALL_SCRIPT’ to ‘${INSTALL}’ |
| 2496 |
and ‘INSTALL_DATA’ to ‘${INSTALL} -m 644’. |
| 2497 |
|
| 2498 |
This macro screens out various instances of ‘install’ known not to |
| 2499 |
work. It prefers to find a C program rather than a shell script, |
| 2500 |
for speed. Instead of ‘install-sh’, it can also use ‘install.sh’, |
| 2501 |
but that name is obsolete because some ‘make’ programs have a rule |
| 2502 |
that creates ‘install’ from it if there is no ‘Makefile’. |
| 2503 |
|
| 2504 |
Autoconf comes with a copy of ‘install-sh’ that you can use. If |
| 2505 |
you use ‘AC_PROG_INSTALL’, you must include either ‘install-sh’ or |
| 2506 |
‘install.sh’ in your distribution, or ‘configure’ will produce an |
| 2507 |
error message saying it can't find them--even if the system you're |
| 2508 |
on has a good ‘install’ program. This check is a safety measure to |
| 2509 |
prevent you from accidentally leaving that file out, which would |
| 2510 |
prevent your package from installing on systems that don't have a |
| 2511 |
BSD-compatible ‘install’ program. |
| 2512 |
|
| 2513 |
If you need to use your own installation program because it has |
| 2514 |
features not found in standard ‘install’ programs, there is no |
| 2515 |
reason to use ‘AC_PROG_INSTALL’; just put the file name of your |
| 2516 |
program into your ‘Makefile.in’ files. |
| 2517 |
|
| 2518 |
-- Macro: AC_PROG_LEX |
| 2519 |
If ‘flex’ is found, set output variable ‘LEX’ to ‘flex’ and |
| 2520 |
‘LEXLIB’ to ‘-lfl’, if that library is in a standard place. |
| 2521 |
Otherwise set ‘LEX’ to ‘lex’ and ‘LEXLIB’ to ‘-ll’. |
| 2522 |
|
| 2523 |
Define ‘YYTEXT_POINTER’ if ‘yytext’ is a ‘char *’ instead of a |
| 2524 |
‘char []’. Also set output variable ‘LEX_OUTPUT_ROOT’ to the base |
| 2525 |
of the file name that the lexer generates; usually ‘lex.yy’, but |
| 2526 |
sometimes something else. These results vary according to whether |
| 2527 |
‘lex’ or ‘flex’ is being used. |
| 2528 |
|
| 2529 |
You are encouraged to use Flex in your sources, since it is both |
| 2530 |
more pleasant to use than plain Lex and the C source it produces is |
| 2531 |
portable. In order to ensure portability, however, you must either |
| 2532 |
provide a function ‘yywrap’ or, if you don't use it (e.g., your |
| 2533 |
scanner has no ‘#include’-like feature), simply include a |
| 2534 |
‘%noyywrap’ statement in the scanner's source. Once this done, the |
| 2535 |
scanner is portable (unless _you_ felt free to use nonportable |
| 2536 |
constructs) and does not depend on any library. In this case, and |
| 2537 |
in this case only, it is suggested that you use this Autoconf |
| 2538 |
snippet: |
| 2539 |
|
| 2540 |
AC_PROG_LEX |
| 2541 |
if test "$LEX" != flex; then |
| 2542 |
LEX="$SHELL $missing_dir/missing flex" |
| 2543 |
AC_SUBST(LEX_OUTPUT_ROOT, lex.yy) |
| 2544 |
AC_SUBST(LEXLIB, '') |
| 2545 |
fi |
| 2546 |
|
| 2547 |
The shell script ‘missing’ can be found in the Automake |
| 2548 |
distribution. |
| 2549 |
|
| 2550 |
To ensure backward compatibility, Automake's ‘AM_PROG_LEX’ invokes |
| 2551 |
(indirectly) this macro twice, which will cause an annoying but |
| 2552 |
benign "‘AC_PROG_LEX’ invoked multiple times" warning. Future |
| 2553 |
versions of Automake will fix this issue, meanwhile, just ignore |
| 2554 |
this message. |
| 2555 |
|
| 2556 |
-- Macro: AC_PROG_LN_S |
| 2557 |
If ‘ln -s’ works on the current file system (the operating system |
| 2558 |
and file system support symbolic links), set the output variable |
| 2559 |
‘LN_S’ to ‘ln -s’; otherwise, if ‘ln’ works, set ‘LN_S’ to ‘ln’ and |
| 2560 |
otherwise set it to ‘cp -p’. |
| 2561 |
|
| 2562 |
If you make a link a directory other than the current directory, |
| 2563 |
its meaning depends on whether ‘ln’ or ‘ln -s’ is used. To safely |
| 2564 |
create links using ‘$(LN_S)’, either find out which form is used |
| 2565 |
and adjust the arguments, or always invoke ‘ln’ in the directory |
| 2566 |
where the link is to be created. |
| 2567 |
|
| 2568 |
In other words, it does not work to do: |
| 2569 |
$(LN_S) foo /x/bar |
| 2570 |
|
| 2571 |
Instead, do: |
| 2572 |
|
| 2573 |
(cd /x && $(LN_S) foo bar) |
| 2574 |
|
| 2575 |
-- Macro: AC_PROG_RANLIB |
| 2576 |
Set output variable ‘RANLIB’ to ‘ranlib’ if ‘ranlib’ is found, and |
| 2577 |
otherwise to ‘:’ (do nothing). |
| 2578 |
|
| 2579 |
-- Macro: AC_PROG_YACC |
| 2580 |
If ‘byacc’ is found, set ‘YACC’ to ‘byacc’. Otherwise, if ‘bison’ |
| 2581 |
is found, set output variable ‘YACC’ to ‘bison -y’. Finally, if |
| 2582 |
neither ‘byacc’ or ‘bison’ is found, set ‘YACC’ to ‘yacc’. |
| 2583 |
|
| 2584 |
|
| 2585 |
File: autoconf.info, Node: Generic Programs, Prev: Particular Programs, Up: Alternative Programs |
| 2586 |
|
| 2587 |
5.2.2 Generic Program and File Checks |
| 2588 |
------------------------------------- |
| 2589 |
|
| 2590 |
These macros are used to find programs not covered by the "particular" |
| 2591 |
test macros. If you need to check the behavior of a program as well as |
| 2592 |
find out whether it is present, you have to write your own test for it |
| 2593 |
(*note Writing Tests::). By default, these macros use the environment |
| 2594 |
variable ‘PATH’. If you need to check for a program that might not be |
| 2595 |
in the user's ‘PATH’, you can pass a modified path to use instead, like |
| 2596 |
this: |
| 2597 |
|
| 2598 |
AC_PATH_PROG(INETD, inetd, /usr/libexec/inetd, |
| 2599 |
$PATH:/usr/libexec:/usr/sbin:/usr/etc:etc) |
| 2600 |
|
| 2601 |
You are strongly encouraged to declare the VARIABLE passed to |
| 2602 |
‘AC_CHECK_PROG’ etc. as precious, *Note Setting Output Variables::, |
| 2603 |
‘AC_ARG_VAR’, for more details. |
| 2604 |
|
| 2605 |
-- Macro: AC_CHECK_PROG (VARIABLE, PROG-TO-CHECK-FOR, VALUE-IF-FOUND, |
| 2606 |
[VALUE-IF-NOT-FOUND], [PATH], [REJECT]) |
| 2607 |
Check whether program PROG-TO-CHECK-FOR exists in ‘PATH’. If it is |
| 2608 |
found, set VARIABLE to VALUE-IF-FOUND, otherwise to |
| 2609 |
VALUE-IF-NOT-FOUND, if given. Always pass over REJECT (an absolute |
| 2610 |
file name) even if it is the first found in the search path; in |
| 2611 |
that case, set VARIABLE using the absolute file name of the |
| 2612 |
PROG-TO-CHECK-FOR found that is not REJECT. If VARIABLE was |
| 2613 |
already set, do nothing. Calls ‘AC_SUBST’ for VARIABLE. |
| 2614 |
|
| 2615 |
-- Macro: AC_CHECK_PROGS (VARIABLE, PROGS-TO-CHECK-FOR, |
| 2616 |
[VALUE-IF-NOT-FOUND], [PATH]) |
| 2617 |
Check for each program in the whitespace-separated list |
| 2618 |
PROGS-TO-CHECK-FOR exists on the ‘PATH’. If it is found, set |
| 2619 |
VARIABLE to the name of that program. Otherwise, continue checking |
| 2620 |
the next program in the list. If none of the programs in the list |
| 2621 |
are found, set VARIABLE to VALUE-IF-NOT-FOUND; if |
| 2622 |
VALUE-IF-NOT-FOUND is not specified, the value of VARIABLE is not |
| 2623 |
changed. Calls ‘AC_SUBST’ for VARIABLE. |
| 2624 |
|
| 2625 |
-- Macro: AC_CHECK_TOOL (VARIABLE, PROG-TO-CHECK-FOR, |
| 2626 |
[VALUE-IF-NOT-FOUND], [PATH]) |
| 2627 |
Like ‘AC_CHECK_PROG’, but first looks for PROG-TO-CHECK-FOR with a |
| 2628 |
prefix of the host type as determined by ‘AC_CANONICAL_HOST’, |
| 2629 |
followed by a dash (*note Canonicalizing::). For example, if the |
| 2630 |
user runs ‘configure --host=i386-gnu’, then this call: |
| 2631 |
AC_CHECK_TOOL(RANLIB, ranlib, :) |
| 2632 |
sets ‘RANLIB’ to ‘i386-gnu-ranlib’ if that program exists in |
| 2633 |
‘PATH’, or otherwise to ‘ranlib’ if that program exists in ‘PATH’, |
| 2634 |
or to ‘:’ if neither program exists. |
| 2635 |
|
| 2636 |
-- Macro: AC_CHECK_TOOLS (VARIABLE, PROGS-TO-CHECK-FOR, |
| 2637 |
[VALUE-IF-NOT-FOUND], [PATH]) |
| 2638 |
Like ‘AC_CHECK_TOOL’, each of the tools in the list |
| 2639 |
PROGS-TO-CHECK-FOR are checked with a prefix of the host type as |
| 2640 |
determined by ‘AC_CANONICAL_HOST’, followed by a dash (*note |
| 2641 |
Canonicalizing::). If none of the tools can be found with a |
| 2642 |
prefix, then the first one without a prefix is used. If a tool is |
| 2643 |
found, set VARIABLE to the name of that program. If none of the |
| 2644 |
tools in the list are found, set VARIABLE to VALUE-IF-NOT-FOUND; if |
| 2645 |
VALUE-IF-NOT-FOUND is not specified, the value of VARIABLE is not |
| 2646 |
changed. Calls ‘AC_SUBST’ for VARIABLE. |
| 2647 |
|
| 2648 |
-- Macro: AC_PATH_PROG (VARIABLE, PROG-TO-CHECK-FOR, |
| 2649 |
[VALUE-IF-NOT-FOUND], [PATH]) |
| 2650 |
Like ‘AC_CHECK_PROG’, but set VARIABLE to the entire path of |
| 2651 |
PROG-TO-CHECK-FOR if found. |
| 2652 |
|
| 2653 |
-- Macro: AC_PATH_PROGS (VARIABLE, PROGS-TO-CHECK-FOR, |
| 2654 |
[VALUE-IF-NOT-FOUND], [PATH]) |
| 2655 |
Like ‘AC_CHECK_PROGS’, but if any of PROGS-TO-CHECK-FOR are found, |
| 2656 |
set VARIABLE to the entire path of the program found. |
| 2657 |
|
| 2658 |
-- Macro: AC_PATH_TOOL (VARIABLE, PROG-TO-CHECK-FOR, |
| 2659 |
[VALUE-IF-NOT-FOUND], [PATH]) |
| 2660 |
Like ‘AC_CHECK_TOOL’, but set VARIABLE to the entire path of the |
| 2661 |
program if it is found. |
| 2662 |
|
| 2663 |
|
| 2664 |
File: autoconf.info, Node: Files, Next: Libraries, Prev: Alternative Programs, Up: Existing Tests |
| 2665 |
|
| 2666 |
5.3 Files |
| 2667 |
========= |
| 2668 |
|
| 2669 |
You might also need to check for the existence of files. Before using |
| 2670 |
these macros, ask yourself whether a run time test might not be a better |
| 2671 |
solution. Be aware that, like most Autoconf macros, they test a feature |
| 2672 |
of the host machine, and therefore, they die when cross-compiling. |
| 2673 |
|
| 2674 |
-- Macro: AC_CHECK_FILE (FILE, [ACTION-IF-FOUND], |
| 2675 |
[ACTION-IF-NOT-FOUND]) |
| 2676 |
Check whether file FILE exists on the native system. If it is |
| 2677 |
found, execute ACTION-IF-FOUND, otherwise do ACTION-IF-NOT-FOUND, |
| 2678 |
if given. |
| 2679 |
|
| 2680 |
-- Macro: AC_CHECK_FILES (FILES, [ACTION-IF-FOUND], |
| 2681 |
[ACTION-IF-NOT-FOUND]) |
| 2682 |
Executes ‘AC_CHECK_FILE’ once for each file listed in FILES. |
| 2683 |
Additionally, defines ‘HAVE_FILE’ (*note Standard Symbols::) for |
| 2684 |
each file found. |
| 2685 |
|
| 2686 |
|
| 2687 |
File: autoconf.info, Node: Libraries, Next: Library Functions, Prev: Files, Up: Existing Tests |
| 2688 |
|
| 2689 |
5.4 Library Files |
| 2690 |
================= |
| 2691 |
|
| 2692 |
The following macros check for the presence of certain C, C++ or Fortran |
| 2693 |
77 library archive files. |
| 2694 |
|
| 2695 |
-- Macro: AC_CHECK_LIB (LIBRARY, FUNCTION, [ACTION-IF-FOUND], |
| 2696 |
[ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES]) |
| 2697 |
Depending on the current language(*note Language Choice::), try to |
| 2698 |
ensure that the C, C++, or Fortran 77 function FUNCTION is |
| 2699 |
available by checking whether a test program can be linked with the |
| 2700 |
library LIBRARY to get the function. LIBRARY is the base name of |
| 2701 |
the library; e.g., to check for ‘-lmp’, use ‘mp’ as the LIBRARY |
| 2702 |
argument. |
| 2703 |
|
| 2704 |
ACTION-IF-FOUND is a list of shell commands to run if the link with |
| 2705 |
the library succeeds; ACTION-IF-NOT-FOUND is a list of shell |
| 2706 |
commands to run if the link fails. If ACTION-IF-FOUND is not |
| 2707 |
specified, the default action will prepend ‘-lLIBRARY’ to ‘LIBS’ |
| 2708 |
and define ‘HAVE_LIBLIBRARY’ (in all capitals). This macro is |
| 2709 |
intended to support building of ‘LIBS’ in a right-to-left |
| 2710 |
(least-dependent to most-dependent) fashion such that library |
| 2711 |
dependencies are satisfied as a natural side-effect of consecutive |
| 2712 |
tests. Some linkers are very sensitive to library ordering so the |
| 2713 |
order in which ‘LIBS’ is generated is important to reliable |
| 2714 |
detection of libraries. |
| 2715 |
|
| 2716 |
If linking with LIBRARY results in unresolved symbols that would be |
| 2717 |
resolved by linking with additional libraries, give those libraries |
| 2718 |
as the OTHER-LIBRARIES argument, separated by spaces: e.g. ‘-lXt |
| 2719 |
-lX11’. Otherwise, this macro will fail to detect that LIBRARY is |
| 2720 |
present, because linking the test program will always fail with |
| 2721 |
unresolved symbols. The OTHER-LIBRARIES argument should be limited |
| 2722 |
to cases where it is desirable to test for one library in the |
| 2723 |
presence of another that is not already in ‘LIBS’. |
| 2724 |
|
| 2725 |
-- Macro: AC_SEARCH_LIBS (FUNCTION, SEARCH-LIBS, [ACTION-IF-FOUND], |
| 2726 |
[ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES]) |
| 2727 |
Search for a library defining FUNCTION if it's not already |
| 2728 |
available. This equates to calling ‘AC_TRY_LINK_FUNC’ first with |
| 2729 |
no libraries, then for each library listed in SEARCH-LIBS. |
| 2730 |
|
| 2731 |
Add ‘-lLIBRARY’ to ‘LIBS’ for the first library found to contain |
| 2732 |
FUNCTION, and run ACTION-IF-FOUND. If the function is not found, |
| 2733 |
run ACTION-IF-NOT-FOUND. |
| 2734 |
|
| 2735 |
If linking with LIBRARY results in unresolved symbols that would be |
| 2736 |
resolved by linking with additional libraries, give those libraries |
| 2737 |
as the OTHER-LIBRARIES argument, separated by spaces: e.g. ‘-lXt |
| 2738 |
-lX11’. Otherwise, this macro will fail to detect that FUNCTION is |
| 2739 |
present, because linking the test program will always fail with |
| 2740 |
unresolved symbols. |
| 2741 |
|
| 2742 |
|
| 2743 |
File: autoconf.info, Node: Library Functions, Next: Header Files, Prev: Libraries, Up: Existing Tests |
| 2744 |
|
| 2745 |
5.5 Library Functions |
| 2746 |
===================== |
| 2747 |
|
| 2748 |
The following macros check for particular C library functions. If there |
| 2749 |
is no macro specifically defined to check for a function you need, and |
| 2750 |
you don't need to check for any special properties of it, then you can |
| 2751 |
use one of the general function-check macros. |
| 2752 |
|
| 2753 |
* Menu: |
| 2754 |
|
| 2755 |
* Function Portability:: Pitfalls with usual functions |
| 2756 |
* Particular Functions:: Special handling to find certain functions |
| 2757 |
* Generic Functions:: How to find other functions |
| 2758 |
|
| 2759 |
|
| 2760 |
File: autoconf.info, Node: Function Portability, Next: Particular Functions, Prev: Library Functions, Up: Library Functions |
| 2761 |
|
| 2762 |
5.5.1 Portability of Classical Functions |
| 2763 |
---------------------------------------- |
| 2764 |
|
| 2765 |
Most usual functions can either be missing, or be buggy, or be limited |
| 2766 |
on some architectures. This section tries to make an inventory of these |
| 2767 |
portability issues. By definition, this list will always require |
| 2768 |
additions, please help us keeping it as complete as possible |
| 2769 |
|
| 2770 |
‘unlink’ |
| 2771 |
The POSIX spec says that ‘unlink’ causes the given files to be |
| 2772 |
removed only after there are no more open file handles for it. Not |
| 2773 |
all OS's support this behaviour though. So even on systems that |
| 2774 |
provide ‘unlink’, you cannot portably assume it is OK to call it on |
| 2775 |
files that are open. For example, on Windows 9x and ME, such a |
| 2776 |
call would fail; on DOS it could even lead to file system |
| 2777 |
corruption, as the file might end up being written to after the OS |
| 2778 |
has removed it. |
| 2779 |
|
| 2780 |
|
| 2781 |
File: autoconf.info, Node: Particular Functions, Next: Generic Functions, Prev: Function Portability, Up: Library Functions |
| 2782 |
|
| 2783 |
5.5.2 Particular Function Checks |
| 2784 |
-------------------------------- |
| 2785 |
|
| 2786 |
These macros check for particular C functions--whether they exist, and |
| 2787 |
in some cases how they respond when given certain arguments. |
| 2788 |
|
| 2789 |
-- Macro: AC_FUNC_ALLOCA |
| 2790 |
Check how to get ‘alloca’. Tries to get a builtin version by |
| 2791 |
checking for ‘alloca.h’ or the predefined C preprocessor macros |
| 2792 |
‘__GNUC__’ and ‘_AIX’. If this macro finds ‘alloca.h’, it defines |
| 2793 |
‘HAVE_ALLOCA_H’. |
| 2794 |
|
| 2795 |
If those attempts fail, it looks for the function in the standard C |
| 2796 |
library. If any of those methods succeed, it defines |
| 2797 |
‘HAVE_ALLOCA’. Otherwise, it sets the output variable ‘ALLOCA’ to |
| 2798 |
‘alloca.o’ and defines ‘C_ALLOCA’ (so programs can periodically |
| 2799 |
call ‘alloca(0)’ to garbage collect). This variable is separate |
| 2800 |
from ‘LIBOBJS’ so multiple programs can share the value of ‘ALLOCA’ |
| 2801 |
without needing to create an actual library, in case only some of |
| 2802 |
them use the code in ‘LIBOBJS’. |
| 2803 |
|
| 2804 |
This macro does not try to get ‘alloca’ from the System V R3 |
| 2805 |
‘libPW’ or the System V R4 ‘libucb’ because those libraries contain |
| 2806 |
some incompatible functions that cause trouble. Some versions do |
| 2807 |
not even contain ‘alloca’ or contain a buggy version. If you still |
| 2808 |
want to use their ‘alloca’, use ‘ar’ to extract ‘alloca.o’ from |
| 2809 |
them instead of compiling ‘alloca.c’. |
| 2810 |
|
| 2811 |
Source files that use ‘alloca’ should start with a piece of code |
| 2812 |
like the following, to declare it properly. In some versions of |
| 2813 |
AIX, the declaration of ‘alloca’ must precede everything else |
| 2814 |
except for comments and preprocessor directives. The ‘#pragma’ |
| 2815 |
directive is indented so that pre-ANSI C compilers will ignore it, |
| 2816 |
rather than choke on it. |
| 2817 |
|
| 2818 |
/* AIX requires this to be the first thing in the file. */ |
| 2819 |
#ifndef __GNUC__ |
| 2820 |
# if HAVE_ALLOCA_H |
| 2821 |
# include <alloca.h> |
| 2822 |
# else |
| 2823 |
# ifdef _AIX |
| 2824 |
#pragma alloca |
| 2825 |
# else |
| 2826 |
# ifndef alloca /* predefined by HP cc +Olibcalls */ |
| 2827 |
char *alloca (); |
| 2828 |
# endif |
| 2829 |
# endif |
| 2830 |
# endif |
| 2831 |
#endif |
| 2832 |
|
| 2833 |
-- Macro: AC_FUNC_CHOWN |
| 2834 |
If the ‘chown’ function is available and works (in particular, it |
| 2835 |
should accept ‘-1’ for ‘uid’ and ‘gid’), define ‘HAVE_CHOWN’. |
| 2836 |
|
| 2837 |
-- Macro: AC_FUNC_CLOSEDIR_VOID |
| 2838 |
If the ‘closedir’ function does not return a meaningful value, |
| 2839 |
define ‘CLOSEDIR_VOID’. Otherwise, callers ought to check its |
| 2840 |
return value for an error indicator. |
| 2841 |
|
| 2842 |
-- Macro: AC_FUNC_ERROR_AT_LINE |
| 2843 |
If the ‘error_at_line’ function is not found, require an |
| 2844 |
‘AC_LIBOBJ’ replacement of ‘error’. |
| 2845 |
|
| 2846 |
-- Macro: AC_FUNC_FNMATCH |
| 2847 |
If the ‘fnmatch’ function is available and works (unlike the one on |
| 2848 |
Solaris 2.4), define ‘HAVE_FNMATCH’. |
| 2849 |
|
| 2850 |
-- Macro: AC_FUNC_FORK |
| 2851 |
This macro checks for the ‘fork’ and ‘vfork’ functions. If a |
| 2852 |
working ‘fork’ is found, define ‘HAVE_WORKING_FORK’. This macro |
| 2853 |
checks whether ‘fork’ is just a stub by trying to run it. |
| 2854 |
|
| 2855 |
If ‘vfork.h’ is found, define ‘HAVE_VFORK_H’. If a working ‘vfork’ |
| 2856 |
is found, define ‘HAVE_WORKING_VFORK’. Otherwise, define ‘vfork’ |
| 2857 |
to be ‘fork’ for backward compatibility with previous versions of |
| 2858 |
‘autoconf’. This macro checks for several known errors in |
| 2859 |
implementations of ‘vfork’ and considers the system to not have a |
| 2860 |
working ‘vfork’ if it detects any of them. It is not considered to |
| 2861 |
be an implementation error if a child's invocation of ‘signal’ |
| 2862 |
modifies the parent's signal handler, since child processes rarely |
| 2863 |
change their signal handlers. |
| 2864 |
|
| 2865 |
Since this macro defines ‘vfork’ only for backward compatibility |
| 2866 |
with previous versions of ‘autoconf’ you're encouraged to define it |
| 2867 |
yourself in new code: |
| 2868 |
#if !HAVE_WORKING_VFORK |
| 2869 |
# define vfork fork |
| 2870 |
#endif |
| 2871 |
|
| 2872 |
-- Macro: AC_FUNC_FSEEKO |
| 2873 |
If the ‘fseeko’ function is available, define ‘HAVE_FSEEKO’. |
| 2874 |
Define ‘_LARGEFILE_SOURCE’ if necessary. |
| 2875 |
|
| 2876 |
-- Macro: AC_FUNC_GETGROUPS |
| 2877 |
If the ‘getgroups’ function is available and works (unlike on |
| 2878 |
Ultrix 4.3, where ‘getgroups (0, 0)’ always fails), define |
| 2879 |
‘HAVE_GETGROUPS’. Set ‘GETGROUPS_LIBS’ to any libraries needed to |
| 2880 |
get that function. This macro runs ‘AC_TYPE_GETGROUPS’. |
| 2881 |
|
| 2882 |
-- Macro: AC_FUNC_GETLOADAVG |
| 2883 |
Check how to get the system load averages. If the system has the |
| 2884 |
‘getloadavg’ function, define ‘HAVE_GETLOADAVG’, and set |
| 2885 |
‘GETLOADAVG_LIBS’ to any libraries needed to get that function. |
| 2886 |
Also add ‘GETLOADAVG_LIBS’ to ‘LIBS’. |
| 2887 |
|
| 2888 |
Otherwise, require an ‘AC_LIBOBJ’ replacement (‘getloadavg.c’) of |
| 2889 |
‘getloadavg’, and possibly define several other C preprocessor |
| 2890 |
macros and output variables: |
| 2891 |
|
| 2892 |
1. Define ‘C_GETLOADAVG’. |
| 2893 |
|
| 2894 |
2. Define ‘SVR4’, ‘DGUX’, ‘UMAX’, or ‘UMAX4_3’ if on those |
| 2895 |
systems. |
| 2896 |
|
| 2897 |
3. If ‘nlist.h’ is found, define ‘NLIST_STRUCT’. |
| 2898 |
|
| 2899 |
4. If ‘struct nlist’ has an ‘n_un.n_name’ member, define |
| 2900 |
‘HAVE_STRUCT_NLIST_N_UN_N_NAME’. The obsolete symbol |
| 2901 |
‘NLIST_NAME_UNION’ is still defined, but do not depend upon |
| 2902 |
it. |
| 2903 |
|
| 2904 |
5. Programs may need to be installed setgid (or setuid) for |
| 2905 |
‘getloadavg’ to work. In this case, define |
| 2906 |
‘GETLOADAVG_PRIVILEGED’, set the output variable ‘NEED_SETGID’ |
| 2907 |
to ‘true’ (and otherwise to ‘false’), and set ‘KMEM_GROUP’ to |
| 2908 |
the name of the group that should own the installed program. |
| 2909 |
|
| 2910 |
-- Macro: AC_FUNC_GETMNTENT |
| 2911 |
Check for ‘getmntent’ in the ‘sun’, ‘seq’, and ‘gen’ libraries, for |
| 2912 |
Irix 4, PTX, and Unixware, respectively. Then, if ‘getmntent’ is |
| 2913 |
available, define ‘HAVE_GETMNTENT’. |
| 2914 |
|
| 2915 |
-- Macro: AC_FUNC_GETPGRP |
| 2916 |
If ‘getpgrp’ takes no argument (the POSIX.1 version), define |
| 2917 |
‘GETPGRP_VOID’. Otherwise, it is the BSD version, which takes a |
| 2918 |
process ID as an argument. This macro does not check whether |
| 2919 |
‘getpgrp’ exists at all; if you need to work in that situation, |
| 2920 |
first call ‘AC_CHECK_FUNC’ for ‘getpgrp’. |
| 2921 |
|
| 2922 |
-- Macro: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK |
| 2923 |
If ‘link’ is a symbolic link, then ‘lstat’ should treat ‘link/’ the |
| 2924 |
same as ‘link/.’. However, many older ‘lstat’ implementations |
| 2925 |
incorrectly ignore trailing slashes. |
| 2926 |
|
| 2927 |
It is safe to assume that if ‘lstat’ incorrectly ignores trailing |
| 2928 |
slashes, then other symbolic-link-aware functions like ‘unlink’ and |
| 2929 |
‘unlink’ also incorrectly ignore trailing slashes. |
| 2930 |
|
| 2931 |
If ‘lstat’ behaves properly, define |
| 2932 |
‘LSTAT_FOLLOWS_SLASHED_SYMLINK’, otherwise require an ‘AC_LIBOBJ’ |
| 2933 |
replacement of ‘lstat’. |
| 2934 |
|
| 2935 |
-- Macro: AC_FUNC_MALLOC |
| 2936 |
If the ‘malloc’ works correctly (‘malloc (0)’ returns a valid |
| 2937 |
pointer), define ‘HAVE_MALLOC’. |
| 2938 |
|
| 2939 |
-- Macro: AC_FUNC_MEMCMP |
| 2940 |
If the ‘memcmp’ function is not available, or does not work on |
| 2941 |
8-bit data (like the one on SunOS 4.1.3), or fails when comparing |
| 2942 |
16 bytes or more and with at least one buffer not starting on a |
| 2943 |
4-byte boundary (such as the one on NeXT x86 OpenStep), require an |
| 2944 |
‘AC_LIBOBJ’ replacement for ‘memcmp’. |
| 2945 |
|
| 2946 |
-- Macro: AC_FUNC_MKTIME |
| 2947 |
If the ‘mktime’ function is not available, or does not work |
| 2948 |
correctly, require an ‘AC_LIBOBJ’ replacement for ‘mktime’. |
| 2949 |
|
| 2950 |
-- Macro: AC_FUNC_MMAP |
| 2951 |
If the ‘mmap’ function exists and works correctly, define |
| 2952 |
‘HAVE_MMAP’. Only checks private fixed mapping of already-mapped |
| 2953 |
memory. |
| 2954 |
|
| 2955 |
-- Macro: AC_FUNC_OBSTACK |
| 2956 |
If the obstacks are found, define ‘HAVE_OBSTACK’, else require an |
| 2957 |
‘AC_LIBOBJ’ replacement for ‘obstack’. |
| 2958 |
|
| 2959 |
-- Macro: AC_FUNC_SELECT_ARGTYPES |
| 2960 |
Determines the correct type to be passed for each of the ‘select’ |
| 2961 |
function's arguments, and defines those types in |
| 2962 |
‘SELECT_TYPE_ARG1’, ‘SELECT_TYPE_ARG234’, and ‘SELECT_TYPE_ARG5’ |
| 2963 |
respectively. ‘SELECT_TYPE_ARG1’ defaults to ‘int’, |
| 2964 |
‘SELECT_TYPE_ARG234’ defaults to ‘int *’, and ‘SELECT_TYPE_ARG5’ |
| 2965 |
defaults to ‘struct timeval *’. |
| 2966 |
|
| 2967 |
-- Macro: AC_FUNC_SETPGRP |
| 2968 |
If ‘setpgrp’ takes no argument (the POSIX.1 version), define |
| 2969 |
‘SETPGRP_VOID’. Otherwise, it is the BSD version, which takes two |
| 2970 |
process IDs as arguments. This macro does not check whether |
| 2971 |
‘setpgrp’ exists at all; if you need to work in that situation, |
| 2972 |
first call ‘AC_CHECK_FUNC’ for ‘setpgrp’. |
| 2973 |
|
| 2974 |
-- Macro: AC_FUNC_STAT |
| 2975 |
-- Macro: AC_FUNC_LSTAT |
| 2976 |
Determine whether ‘stat’ or ‘lstat’ have the bug that it succeeds |
| 2977 |
when given the zero-length file name argument. The ‘stat’ and |
| 2978 |
‘lstat’ from SunOS 4.1.4 and the Hurd (as of 1998-11-01) do this. |
| 2979 |
|
| 2980 |
If it does, then define ‘HAVE_STAT_EMPTY_STRING_BUG’ (or |
| 2981 |
‘HAVE_LSTAT_EMPTY_STRING_BUG’) and ask for an ‘AC_LIBOBJ’ |
| 2982 |
replacement of it. |
| 2983 |
|
| 2984 |
-- Macro: AC_FUNC_SETVBUF_REVERSED |
| 2985 |
If ‘setvbuf’ takes the buffering type as its second argument and |
| 2986 |
the buffer pointer as the third, instead of the other way around, |
| 2987 |
define ‘SETVBUF_REVERSED’. |
| 2988 |
|
| 2989 |
-- Macro: AC_FUNC_STRCOLL |
| 2990 |
If the ‘strcoll’ function exists and works correctly, define |
| 2991 |
‘HAVE_STRCOLL’. This does a bit more than |
| 2992 |
‘AC_CHECK_FUNCS(strcoll)’, because some systems have incorrect |
| 2993 |
definitions of ‘strcoll’ that should not be used. |
| 2994 |
|
| 2995 |
-- Macro: AC_FUNC_STRTOD |
| 2996 |
If the ‘strtod’ function does not exist or doesn't work correctly, |
| 2997 |
ask for an ‘AC_LIBOBJ’ replacement of ‘strtod’. In this case, |
| 2998 |
because ‘strtod.c’ is likely to need ‘pow’, set the output variable |
| 2999 |
‘POW_LIB’ to the extra library needed. |
| 3000 |
|
| 3001 |
-- Macro: AC_FUNC_STRERROR_R |
| 3002 |
If ‘strerror_r’ is available, define ‘HAVE_STRERROR_R’. If its |
| 3003 |
implementation correctly returns a ‘char *’, define |
| 3004 |
‘HAVE_WORKING_STRERROR_R’. On at least DEC UNIX 4.0[A-D] and HP-UX |
| 3005 |
B.10.20, ‘strerror_r’ returns ‘int’. Actually, this tests only |
| 3006 |
whether it returns a scalar or an array, but that should be enough. |
| 3007 |
This is used by the common ‘error.c’. |
| 3008 |
|
| 3009 |
-- Macro: AC_FUNC_STRFTIME |
| 3010 |
Check for ‘strftime’ in the ‘intl’ library, for SCO UNIX. Then, if |
| 3011 |
‘strftime’ is available, define ‘HAVE_STRFTIME’. |
| 3012 |
|
| 3013 |
-- Macro: AC_FUNC_UTIME_NULL |
| 3014 |
If ‘utime(FILE, NULL)’ sets FILE's timestamp to the present, define |
| 3015 |
‘HAVE_UTIME_NULL’. |
| 3016 |
|
| 3017 |
-- Macro: AC_FUNC_VPRINTF |
| 3018 |
If ‘vprintf’ is found, define ‘HAVE_VPRINTF’. Otherwise, if |
| 3019 |
‘_doprnt’ is found, define ‘HAVE_DOPRNT’. (If ‘vprintf’ is |
| 3020 |
available, you may assume that ‘vfprintf’ and ‘vsprintf’ are also |
| 3021 |
available.) |
| 3022 |
|
| 3023 |
|
| 3024 |
File: autoconf.info, Node: Generic Functions, Prev: Particular Functions, Up: Library Functions |
| 3025 |
|
| 3026 |
5.5.3 Generic Function Checks |
| 3027 |
----------------------------- |
| 3028 |
|
| 3029 |
These macros are used to find functions not covered by the "particular" |
| 3030 |
test macros. If the functions might be in libraries other than the |
| 3031 |
default C library, first call ‘AC_CHECK_LIB’ for those libraries. If |
| 3032 |
you need to check the behavior of a function as well as find out whether |
| 3033 |
it is present, you have to write your own test for it (*note Writing |
| 3034 |
Tests::). |
| 3035 |
|
| 3036 |
-- Macro: AC_CHECK_FUNC (FUNCTION, [ACTION-IF-FOUND], |
| 3037 |
[ACTION-IF-NOT-FOUND]) |
| 3038 |
If C function FUNCTION is available, run shell commands |
| 3039 |
ACTION-IF-FOUND, otherwise ACTION-IF-NOT-FOUND. If you just want |
| 3040 |
to define a symbol if the function is available, consider using |
| 3041 |
‘AC_CHECK_FUNCS’ instead. This macro checks for functions with C |
| 3042 |
linkage even when ‘AC_LANG(C++)’ has been called, since C is more |
| 3043 |
standardized than C++. (*note Language Choice::, for more |
| 3044 |
information about selecting the language for checks.) |
| 3045 |
|
| 3046 |
-- Macro: AC_CHECK_FUNCS (FUNCTION..., [ACTION-IF-FOUND], |
| 3047 |
[ACTION-IF-NOT-FOUND]) |
| 3048 |
For each FUNCTION in the whitespace-separated argument list, define |
| 3049 |
‘HAVE_FUNCTION’ (in all capitals) if it is available. If |
| 3050 |
ACTION-IF-FOUND is given, it is additional shell code to execute |
| 3051 |
when one of the functions is found. You can give it a value of |
| 3052 |
‘break’ to break out of the loop on the first match. If |
| 3053 |
ACTION-IF-NOT-FOUND is given, it is executed when one of the |
| 3054 |
functions is not found. |
| 3055 |
|
| 3056 |
Autoconf follows a philosophy that was formed over the years by those |
| 3057 |
who have struggled for portability: isolate the portability issues in |
| 3058 |
specific files, and then program as if you were in a POSIX environment. |
| 3059 |
Some functions may be missing or unfixable, and your package must be |
| 3060 |
ready to replace them. |
| 3061 |
|
| 3062 |
Use the first three of the following macros to specify a function to |
| 3063 |
be replaced, and the last one (‘AC_REPLACE_FUNCS’) to check for and |
| 3064 |
replace the function if needed. |
| 3065 |
|
| 3066 |
-- Macro: AC_LIBOBJ (FUNCTION) |
| 3067 |
Specify that ‘FUNCTION.c’ must be included in the executables to |
| 3068 |
replace a missing or broken implementation of FUNCTION. |
| 3069 |
|
| 3070 |
Technically, it adds ‘FUNCTION.$ac_objext’ to the output variable |
| 3071 |
‘LIBOBJS’ and calls ‘AC_LIBSOURCE’ for ‘FUNCTION.c’. You should |
| 3072 |
not directly change ‘LIBOBJS’, since this is not traceable. |
| 3073 |
|
| 3074 |
-- Macro: AC_LIBSOURCE (FILE) |
| 3075 |
Specify that FILE might be needed to compile the project. If you |
| 3076 |
need to know what files might be needed by a ‘configure.ac’, you |
| 3077 |
should trace ‘AC_LIBSOURCE’. FILE must be a literal. |
| 3078 |
|
| 3079 |
This macro is called automatically from ‘AC_LIBOBJ’, but you must |
| 3080 |
call it explicitly if you pass a shell variable to ‘AC_LIBOBJ’. In |
| 3081 |
that case, since shell variables cannot be traced statically, you |
| 3082 |
must pass to ‘AC_LIBSOURCE’ any possible files that the shell |
| 3083 |
variable might cause ‘AC_LIBOBJ’ to need. For example, if you want |
| 3084 |
to pass a variable ‘$foo_or_bar’ to ‘AC_LIBOBJ’ that holds either |
| 3085 |
‘"foo"’ or ‘"bar"’, you should do: |
| 3086 |
|
| 3087 |
AC_LIBSOURCE(foo.c) |
| 3088 |
AC_LIBSOURCE(bar.c) |
| 3089 |
AC_LIBOBJ($foo_or_bar) |
| 3090 |
|
| 3091 |
There is usually a way to avoid this, however, and you are |
| 3092 |
encouraged to simply call ‘AC_LIBOBJ’ with literal arguments. |
| 3093 |
|
| 3094 |
Note that this macro replaces the obsolete ‘AC_LIBOBJ_DECL’, with |
| 3095 |
slightly different semantics: the old macro took the function name, |
| 3096 |
e.g. ‘foo’, as its argument rather than the file name. |
| 3097 |
|
| 3098 |
-- Macro: AC_LIBSOURCES (FILES) |
| 3099 |
Like ‘AC_LIBSOURCE’, but accepts one or more FILES in a |
| 3100 |
comma-separated M4 list. Thus, the above example might be |
| 3101 |
rewritten: |
| 3102 |
|
| 3103 |
AC_LIBSOURCES([foo.c, bar.c]) |
| 3104 |
AC_LIBOBJ($foo_or_bar) |
| 3105 |
|
| 3106 |
-- Macro: AC_REPLACE_FUNCS (FUNCTION...) |
| 3107 |
Like ‘AC_CHECK_FUNCS’, but uses ‘AC_LIBOBJ(FUNCTION)’ as |
| 3108 |
ACTION-IF-NOT-FOUND. You can declare your replacement function by |
| 3109 |
enclosing the prototype in ‘#if !HAVE_FUNCTION’. If the system has |
| 3110 |
the function, it probably declares it in a header file you should |
| 3111 |
be including, so you shouldn't redeclare it lest your declaration |
| 3112 |
conflict. |
| 3113 |
|
| 3114 |
|
| 3115 |
File: autoconf.info, Node: Header Files, Next: Declarations, Prev: Library Functions, Up: Existing Tests |
| 3116 |
|
| 3117 |
5.6 Header Files |
| 3118 |
================ |
| 3119 |
|
| 3120 |
The following macros check for the presence of certain C header files. |
| 3121 |
If there is no macro specifically defined to check for a header file you |
| 3122 |
need, and you don't need to check for any special properties of it, then |
| 3123 |
you can use one of the general header-file check macros. |
| 3124 |
|
| 3125 |
* Menu: |
| 3126 |
|
| 3127 |
* Particular Headers:: Special handling to find certain headers |
| 3128 |
* Generic Headers:: How to find other headers |
| 3129 |
|
| 3130 |
|
| 3131 |
File: autoconf.info, Node: Particular Headers, Next: Generic Headers, Prev: Header Files, Up: Header Files |
| 3132 |
|
| 3133 |
5.6.1 Particular Header Checks |
| 3134 |
------------------------------ |
| 3135 |
|
| 3136 |
These macros check for particular system header files--whether they |
| 3137 |
exist, and in some cases whether they declare certain symbols. |
| 3138 |
|
| 3139 |
-- Macro: AC_HEADER_DIRENT |
| 3140 |
Check for the following header files. For the first one that is |
| 3141 |
found and defines ‘DIR’, define the listed C preprocessor macro: |
| 3142 |
|
| 3143 |
‘dirent.h’ ‘HAVE_DIRENT_H’ |
| 3144 |
‘sys/ndir.h’ ‘HAVE_SYS_NDIR_H’ |
| 3145 |
‘sys/dir.h’ ‘HAVE_SYS_DIR_H’ |
| 3146 |
‘ndir.h’ ‘HAVE_NDIR_H’ |
| 3147 |
|
| 3148 |
The directory-library declarations in your source code should look |
| 3149 |
something like the following: |
| 3150 |
|
| 3151 |
#if HAVE_DIRENT_H |
| 3152 |
# include <dirent.h> |
| 3153 |
# define NAMLEN(dirent) strlen((dirent)->d_name) |
| 3154 |
#else |
| 3155 |
# define dirent direct |
| 3156 |
# define NAMLEN(dirent) (dirent)->d_namlen |
| 3157 |
# if HAVE_SYS_NDIR_H |
| 3158 |
# include <sys/ndir.h> |
| 3159 |
# endif |
| 3160 |
# if HAVE_SYS_DIR_H |
| 3161 |
# include <sys/dir.h> |
| 3162 |
# endif |
| 3163 |
# if HAVE_NDIR_H |
| 3164 |
# include <ndir.h> |
| 3165 |
# endif |
| 3166 |
#endif |
| 3167 |
|
| 3168 |
Using the above declarations, the program would declare variables |
| 3169 |
to be of type ‘struct dirent’, not ‘struct direct’, and would |
| 3170 |
access the length of a directory entry name by passing a pointer to |
| 3171 |
a ‘struct dirent’ to the ‘NAMLEN’ macro. |
| 3172 |
|
| 3173 |
This macro also checks for the SCO Xenix ‘dir’ and ‘x’ libraries. |
| 3174 |
|
| 3175 |
-- Macro: AC_HEADER_MAJOR |
| 3176 |
If ‘sys/types.h’ does not define ‘major’, ‘minor’, and ‘makedev’, |
| 3177 |
but ‘sys/mkdev.h’ does, define ‘MAJOR_IN_MKDEV’; otherwise, if |
| 3178 |
‘sys/sysmacros.h’ does, define ‘MAJOR_IN_SYSMACROS’. |
| 3179 |
|
| 3180 |
-- Macro: AC_HEADER_STAT |
| 3181 |
If the macros ‘S_ISDIR’, ‘S_ISREG’ et al. defined in ‘sys/stat.h’ |
| 3182 |
do not work properly (returning false positives), define |
| 3183 |
‘STAT_MACROS_BROKEN’. This is the case on Tektronix UTekV, Amdahl |
| 3184 |
UTS and Motorola System V/88. |
| 3185 |
|
| 3186 |
-- Macro: AC_HEADER_STDC |
| 3187 |
Define ‘STDC_HEADERS’ if the system has ANSI C header files. |
| 3188 |
Specifically, this macro checks for ‘stdlib.h’, ‘stdarg.h’, |
| 3189 |
‘string.h’, and ‘float.h’; if the system has those, it probably has |
| 3190 |
the rest of the ANSI C header files. This macro also checks |
| 3191 |
whether ‘string.h’ declares ‘memchr’ (and thus presumably the other |
| 3192 |
‘mem’ functions), whether ‘stdlib.h’ declare ‘free’ (and thus |
| 3193 |
presumably ‘malloc’ and other related functions), and whether the |
| 3194 |
‘ctype.h’ macros work on characters with the high bit set, as ANSI |
| 3195 |
C requires. |
| 3196 |
|
| 3197 |
Use ‘STDC_HEADERS’ instead of ‘__STDC__’ to determine whether the |
| 3198 |
system has ANSI-compliant header files (and probably C library |
| 3199 |
functions) because many systems that have GCC do not have ANSI C |
| 3200 |
header files. |
| 3201 |
|
| 3202 |
On systems without ANSI C headers, there is so much variation that |
| 3203 |
it is probably easier to declare the functions you use than to |
| 3204 |
figure out exactly what the system header files declare. Some |
| 3205 |
systems contain a mix of functions ANSI and BSD; some are mostly |
| 3206 |
ANSI but lack ‘memmove’; some define the BSD functions as macros in |
| 3207 |
‘string.h’ or ‘strings.h’; some have only the BSD functions but |
| 3208 |
‘string.h’; some declare the memory functions in ‘memory.h’, some |
| 3209 |
in ‘string.h’; etc. It is probably sufficient to check for one |
| 3210 |
string function and one memory function; if the library has the |
| 3211 |
ANSI versions of those then it probably has most of the others. If |
| 3212 |
you put the following in ‘configure.ac’: |
| 3213 |
|
| 3214 |
AC_HEADER_STDC |
| 3215 |
AC_CHECK_FUNCS(strchr memcpy) |
| 3216 |
|
| 3217 |
then, in your code, you can put declarations like this: |
| 3218 |
|
| 3219 |
#if STDC_HEADERS |
| 3220 |
# include <string.h> |
| 3221 |
#else |
| 3222 |
# if !HAVE_STRCHR |
| 3223 |
# define strchr index |
| 3224 |
# define strrchr rindex |
| 3225 |
# endif |
| 3226 |
char *strchr (), *strrchr (); |
| 3227 |
# if !HAVE_MEMCPY |
| 3228 |
# define memcpy(d, s, n) bcopy ((s), (d), (n)) |
| 3229 |
# define memmove(d, s, n) bcopy ((s), (d), (n)) |
| 3230 |
# endif |
| 3231 |
#endif |
| 3232 |
|
| 3233 |
If you use a function like ‘memchr’, ‘memset’, ‘strtok’, or |
| 3234 |
‘strspn’, which have no BSD equivalent, then macros won't suffice; |
| 3235 |
you must provide an implementation of each function. An easy way |
| 3236 |
to incorporate your implementations only when needed (since the |
| 3237 |
ones in system C libraries may be hand optimized) is to, taking |
| 3238 |
‘memchr’ for example, put it in ‘memchr.c’ and use |
| 3239 |
‘AC_REPLACE_FUNCS(memchr)’. |
| 3240 |
|
| 3241 |
-- Macro: AC_HEADER_SYS_WAIT |
| 3242 |
If ‘sys/wait.h’ exists and is compatible with POSIX.1, define |
| 3243 |
‘HAVE_SYS_WAIT_H’. Incompatibility can occur if ‘sys/wait.h’ does |
| 3244 |
not exist, or if it uses the old BSD ‘union wait’ instead of ‘int’ |
| 3245 |
to store a status value. If ‘sys/wait.h’ is not POSIX.1 |
| 3246 |
compatible, then instead of including it, define the POSIX.1 macros |
| 3247 |
with their usual interpretations. Here is an example: |
| 3248 |
|
| 3249 |
#include <sys/types.h> |
| 3250 |
#if HAVE_SYS_WAIT_H |
| 3251 |
# include <sys/wait.h> |
| 3252 |
#endif |
| 3253 |
#ifndef WEXITSTATUS |
| 3254 |
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) |
| 3255 |
#endif |
| 3256 |
#ifndef WIFEXITED |
| 3257 |
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0) |
| 3258 |
#endif |
| 3259 |
|
| 3260 |
‘_POSIX_VERSION’ is defined when ‘unistd.h’ is included on POSIX.1 |
| 3261 |
systems. If there is no ‘unistd.h’, it is definitely not a POSIX.1 |
| 3262 |
system. However, some non-POSIX.1 systems do have ‘unistd.h’. |
| 3263 |
|
| 3264 |
The way to check if the system supports POSIX.1 is: |
| 3265 |
|
| 3266 |
#if HAVE_UNISTD_H |
| 3267 |
# include <sys/types.h> |
| 3268 |
# include <unistd.h> |
| 3269 |
#endif |
| 3270 |
|
| 3271 |
#ifdef _POSIX_VERSION |
| 3272 |
/* Code for POSIX.1 systems. */ |
| 3273 |
#endif |
| 3274 |
|
| 3275 |
-- Macro: AC_HEADER_TIME |
| 3276 |
If a program may include both ‘time.h’ and ‘sys/time.h’, define |
| 3277 |
‘TIME_WITH_SYS_TIME’. On some older systems, ‘sys/time.h’ includes |
| 3278 |
‘time.h’, but ‘time.h’ is not protected against multiple inclusion, |
| 3279 |
so programs should not explicitly include both files. This macro |
| 3280 |
is useful in programs that use, for example, ‘struct timeval’ or |
| 3281 |
‘struct timezone’ as well as ‘struct tm’. It is best used in |
| 3282 |
conjunction with ‘HAVE_SYS_TIME_H’, which can be checked for using |
| 3283 |
‘AC_CHECK_HEADERS(sys/time.h)’. |
| 3284 |
|
| 3285 |
#if TIME_WITH_SYS_TIME |
| 3286 |
# include <sys/time.h> |
| 3287 |
# include <time.h> |
| 3288 |
#else |
| 3289 |
# if HAVE_SYS_TIME_H |
| 3290 |
# include <sys/time.h> |
| 3291 |
# else |
| 3292 |
# include <time.h> |
| 3293 |
# endif |
| 3294 |
#endif |
| 3295 |
|
| 3296 |
-- Macro: AC_HEADER_TIOCGWINSZ |
| 3297 |
If the use of ‘TIOCGWINSZ’ requires ‘<sys/ioctl.h>’, then define |
| 3298 |
‘GWINSZ_IN_SYS_IOCTL’. Otherwise ‘TIOCGWINSZ’ can be found in |
| 3299 |
‘<termios.h>’. |
| 3300 |
|
| 3301 |
Use: |
| 3302 |
|
| 3303 |
#if HAVE_TERMIOS_H |
| 3304 |
# include <termios.h> |
| 3305 |
#endif |
| 3306 |
|
| 3307 |
#if GWINSZ_IN_SYS_IOCTL |
| 3308 |
# include <sys/ioctl.h> |
| 3309 |
#endif |
| 3310 |
|
| 3311 |
|
| 3312 |
File: autoconf.info, Node: Generic Headers, Prev: Particular Headers, Up: Header Files |
| 3313 |
|
| 3314 |
5.6.2 Generic Header Checks |
| 3315 |
--------------------------- |
| 3316 |
|
| 3317 |
These macros are used to find system header files not covered by the |
| 3318 |
"particular" test macros. If you need to check the contents of a header |
| 3319 |
as well as find out whether it is present, you have to write your own |
| 3320 |
test for it (*note Writing Tests::). |
| 3321 |
|
| 3322 |
-- Macro: AC_CHECK_HEADER (HEADER-FILE, [ACTION-IF-FOUND], |
| 3323 |
[ACTION-IF-NOT-FOUND], [INCLUDES]) |
| 3324 |
If the system header file HEADER-FILE is usable, execute shell |
| 3325 |
commands ACTION-IF-FOUND, otherwise execute ACTION-IF-NOT-FOUND. |
| 3326 |
If you just want to define a symbol if the header file is |
| 3327 |
available, consider using ‘AC_CHECK_HEADERS’ instead. |
| 3328 |
|
| 3329 |
The meaning of "usable" depends upon the content of INCLUDES: |
| 3330 |
|
| 3331 |
if INCLUDES is empty |
| 3332 |
check whether |
| 3333 |
|
| 3334 |
HEADER-FILE |
| 3335 |
|
| 3336 |
can be _preprocessed_ without error. |
| 3337 |
|
| 3338 |
if INCLUDE is set |
| 3339 |
Check whether |
| 3340 |
|
| 3341 |
INCLUDES |
| 3342 |
#include <HEADER-FILE> |
| 3343 |
|
| 3344 |
can be _compiled_ without error. You may use |
| 3345 |
‘AC_CHECK_HEADER’ (and ‘AC_CHECK_HEADERS’) to check whether |
| 3346 |
two headers are compatible. |
| 3347 |
|
| 3348 |
You may pass any kind of dummy content for INCLUDES, such as a |
| 3349 |
single space, a comment, to check whether HEADER-FILE compiles with |
| 3350 |
success. |
| 3351 |
|
| 3352 |
-- Macro: AC_CHECK_HEADERS (HEADER-FILE..., [ACTION-IF-FOUND], |
| 3353 |
[ACTION-IF-NOT-FOUND], [INCLUDES]) |
| 3354 |
For each given system header file HEADER-FILE in the |
| 3355 |
whitespace-separated argument list that exists, define |
| 3356 |
‘HAVE_HEADER-FILE’ (in all capitals). If ACTION-IF-FOUND is given, |
| 3357 |
it is additional shell code to execute when one of the header files |
| 3358 |
is found. You can give it a value of ‘break’ to break out of the |
| 3359 |
loop on the first match. If ACTION-IF-NOT-FOUND is given, it is |
| 3360 |
executed when one of the header files is not found. |
| 3361 |
|
| 3362 |
Be sure to read the documentation of ‘AC_CHECK_HEADER’ to |
| 3363 |
understand the influence of INCLUDES. |
| 3364 |
|
| 3365 |
|
| 3366 |
File: autoconf.info, Node: Declarations, Next: Structures, Prev: Header Files, Up: Existing Tests |
| 3367 |
|
| 3368 |
5.7 Declarations |
| 3369 |
================ |
| 3370 |
|
| 3371 |
The following macros check for the declaration of variables and |
| 3372 |
functions. If there is no macro specifically defined to check for a |
| 3373 |
symbol you need, then you can use the general macros (*note Generic |
| 3374 |
Declarations::) or, for more complex tests, you may use ‘AC_TRY_COMPILE’ |
| 3375 |
(*note Examining Syntax::). |
| 3376 |
|
| 3377 |
* Menu: |
| 3378 |
|
| 3379 |
* Particular Declarations:: Macros to check for certain declarations |
| 3380 |
* Generic Declarations:: How to find other declarations |
| 3381 |
|
| 3382 |
|
| 3383 |
File: autoconf.info, Node: Particular Declarations, Next: Generic Declarations, Prev: Declarations, Up: Declarations |
| 3384 |
|
| 3385 |
5.7.1 Particular Declaration Checks |
| 3386 |
----------------------------------- |
| 3387 |
|
| 3388 |
The following macros check for certain declarations. |
| 3389 |
|
| 3390 |
-- Macro: AC_DECL_SYS_SIGLIST |
| 3391 |
Define ‘SYS_SIGLIST_DECLARED’ if the variable ‘sys_siglist’ is |
| 3392 |
declared in a system header file, either ‘signal.h’ or ‘unistd.h’. |
| 3393 |
|
| 3394 |
|
| 3395 |
File: autoconf.info, Node: Generic Declarations, Prev: Particular Declarations, Up: Declarations |
| 3396 |
|
| 3397 |
5.7.2 Generic Declaration Checks |
| 3398 |
-------------------------------- |
| 3399 |
|
| 3400 |
These macros are used to find declarations not covered by the |
| 3401 |
"particular" test macros. |
| 3402 |
|
| 3403 |
-- Macro: AC_CHECK_DECL (SYMBOL, [ACTION-IF-FOUND], |
| 3404 |
[ACTION-IF-NOT-FOUND], [INCLUDES]) |
| 3405 |
If SYMBOL (a function or a variable) is not declared in INCLUDES |
| 3406 |
and a declaration is needed, run the shell commands |
| 3407 |
ACTION-IF-NOT-FOUND, otherwise ACTION-IF-FOUND. If no INCLUDES are |
| 3408 |
specified, the default includes are used (*note Default |
| 3409 |
Includes::). |
| 3410 |
|
| 3411 |
This macro actually tests whether it is valid to use SYMBOL as an |
| 3412 |
r-value, not if it is really declared, because it is much safer to |
| 3413 |
avoid introducing extra declarations when they are not needed. |
| 3414 |
|
| 3415 |
-- Macro: AC_CHECK_DECLS (SYMBOLS, [ACTION-IF-FOUND], |
| 3416 |
[ACTION-IF-NOT-FOUND], [INCLUDES]) |
| 3417 |
For each of the SYMBOLS (_comma_-separated list), define |
| 3418 |
‘HAVE_DECL_SYMBOL’ (in all capitals) to ‘1’ if SYMBOL is declared, |
| 3419 |
otherwise to ‘0’. If ACTION-IF-NOT-FOUND is given, it is |
| 3420 |
additional shell code to execute when one of the function |
| 3421 |
declarations is needed, otherwise ACTION-IF-FOUND is executed. |
| 3422 |
|
| 3423 |
This macro uses an m4 list as first argument: |
| 3424 |
AC_CHECK_DECLS(strdup) |
| 3425 |
AC_CHECK_DECLS([strlen]) |
| 3426 |
AC_CHECK_DECLS([malloc, realloc, calloc, free]) |
| 3427 |
|
| 3428 |
Unlike the other ‘AC_CHECK_*S’ macros, when a SYMBOL is not |
| 3429 |
declared, ‘HAVE_DECL_SYMBOL’ is defined to ‘0’ instead of leaving |
| 3430 |
‘HAVE_DECL_SYMBOL’ undeclared. When you are _sure_ that the check |
| 3431 |
was performed, use ‘HAVE_DECL_SYMBOL’ just like any other result of |
| 3432 |
Autoconf: |
| 3433 |
|
| 3434 |
#if !HAVE_DECL_SYMBOL |
| 3435 |
extern char *symbol; |
| 3436 |
#endif |
| 3437 |
|
| 3438 |
If the test may have not been performed, however, because it is |
| 3439 |
safer _not_ to declare a symbol than to use a declaration that |
| 3440 |
conflicts with the system's one, you should use: |
| 3441 |
|
| 3442 |
#if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC |
| 3443 |
char *malloc (size_t *s); |
| 3444 |
#endif |
| 3445 |
|
| 3446 |
You fall into the second category only in extreme situations: |
| 3447 |
either your files may be used without being configured, or they are |
| 3448 |
used during the configuration. In most cases the traditional |
| 3449 |
approach is enough. |
| 3450 |
|
| 3451 |
|
| 3452 |
File: autoconf.info, Node: Structures, Next: Types, Prev: Declarations, Up: Existing Tests |
| 3453 |
|
| 3454 |
5.8 Structures |
| 3455 |
============== |
| 3456 |
|
| 3457 |
The following macros check for the presence of certain members in C |
| 3458 |
structures. If there is no macro specifically defined to check for a |
| 3459 |
member you need, then you can use the general structure-member macro |
| 3460 |
(*note Generic Structures::) or, for more complex tests, you may use |
| 3461 |
‘AC_TRY_COMPILE’ (*note Examining Syntax::). |
| 3462 |
|
| 3463 |
* Menu: |
| 3464 |
|
| 3465 |
* Particular Structures:: Macros to check for certain structure members |
| 3466 |
* Generic Structures:: How to find other structure members |
| 3467 |
|
| 3468 |
|
| 3469 |
File: autoconf.info, Node: Particular Structures, Next: Generic Structures, Prev: Structures, Up: Structures |
| 3470 |
|
| 3471 |
5.8.1 Particular Structure Checks |
| 3472 |
--------------------------------- |
| 3473 |
|
| 3474 |
The following macros check for certain structures or structure members. |
| 3475 |
|
| 3476 |
-- Macro: AC_STRUCT_ST_BLKSIZE |
| 3477 |
If ‘struct stat’ contains an ‘st_blksize’ member, define |
| 3478 |
‘HAVE_STRUCT_STAT_ST_BLKSIZE’. The former name, ‘HAVE_ST_BLKSIZE’ |
| 3479 |
is to be avoided, as its support will cease in the future. This |
| 3480 |
macro is obsoleted, and should be replaced by |
| 3481 |
|
| 3482 |
AC_CHECK_MEMBERS([struct stat.st_blksize]) |
| 3483 |
|
| 3484 |
-- Macro: AC_STRUCT_ST_BLOCKS |
| 3485 |
If ‘struct stat’ contains an ‘st_blocks’ member, define |
| 3486 |
‘HAVE_STRUCT STAT_ST_BLOCKS’. Otherwise, require an ‘AC_LIBOBJ’ |
| 3487 |
replacement of ‘fileblocks’. The former name, ‘HAVE_ST_BLOCKS’ is |
| 3488 |
to be avoided, as its support will cease in the future. |
| 3489 |
|
| 3490 |
-- Macro: AC_STRUCT_ST_RDEV |
| 3491 |
If ‘struct stat’ contains an ‘st_rdev’ member, define |
| 3492 |
‘HAVE_STRUCT_STAT_ST_RDEV’. The former name for this macro, |
| 3493 |
‘HAVE_ST_RDEV’, is to be avoided as it will cease to be supported |
| 3494 |
in the future. Actually, even the new macro is obsolete, and |
| 3495 |
should be replaced by: |
| 3496 |
AC_CHECK_MEMBERS([struct stat.st_rdev]) |
| 3497 |
|
| 3498 |
-- Macro: AC_STRUCT_TM |
| 3499 |
If ‘time.h’ does not define ‘struct tm’, define ‘TM_IN_SYS_TIME’, |
| 3500 |
which means that including ‘sys/time.h’ had better define ‘struct |
| 3501 |
tm’. |
| 3502 |
|
| 3503 |
-- Macro: AC_STRUCT_TIMEZONE |
| 3504 |
Figure out how to get the current timezone. If ‘struct tm’ has a |
| 3505 |
‘tm_zone’ member, define ‘HAVE_STRUCT_TM_TM_ZONE’ (and the |
| 3506 |
obsoleted ‘HAVE_TM_ZONE’). Otherwise, if the external array |
| 3507 |
‘tzname’ is found, define ‘HAVE_TZNAME’. |
| 3508 |
|
| 3509 |
|
| 3510 |
File: autoconf.info, Node: Generic Structures, Prev: Particular Structures, Up: Structures |
| 3511 |
|
| 3512 |
5.8.2 Generic Structure Checks |
| 3513 |
------------------------------ |
| 3514 |
|
| 3515 |
These macros are used to find structure members not covered by the |
| 3516 |
"particular" test macros. |
| 3517 |
|
| 3518 |
-- Macro: AC_CHECK_MEMBER (AGGREGATE.MEMBER, [ACTION-IF-FOUND], |
| 3519 |
[ACTION-IF-NOT-FOUND], [INCLUDES]) |
| 3520 |
Check whether MEMBER is a member of the aggregate AGGREGATE. If no |
| 3521 |
INCLUDES are specified, the default includes are used (*note |
| 3522 |
Default Includes::). |
| 3523 |
|
| 3524 |
AC_CHECK_MEMBER(struct passwd.pw_gecos,, |
| 3525 |
[AC_MSG_ERROR([We need `passwd.pw_gecos'!])], |
| 3526 |
[#include <pwd.h>]) |
| 3527 |
|
| 3528 |
You can use this macro for sub-members: |
| 3529 |
|
| 3530 |
AC_CHECK_MEMBER(struct top.middle.bot) |
| 3531 |
|
| 3532 |
-- Macro: AC_CHECK_MEMBERS (MEMBERS, [ACTION-IF-FOUND], |
| 3533 |
[ACTION-IF-NOT-FOUND], [INCLUDES]) |
| 3534 |
Check for the existence of each ‘AGGREGATE.MEMBER’ of MEMBERS using |
| 3535 |
the previous macro. When MEMBER belongs to AGGREGATE, define |
| 3536 |
‘HAVE_AGGREGATE_MEMBER’ (in all capitals, with spaces and dots |
| 3537 |
replaced by underscores). |
| 3538 |
|
| 3539 |
This macro uses m4 lists: |
| 3540 |
AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize]) |
| 3541 |
|
| 3542 |
|
| 3543 |
File: autoconf.info, Node: Types, Next: Compilers and Preprocessors, Prev: Structures, Up: Existing Tests |
| 3544 |
|
| 3545 |
5.9 Types |
| 3546 |
========= |
| 3547 |
|
| 3548 |
The following macros check for C types, either builtin or typedefs. If |
| 3549 |
there is no macro specifically defined to check for a type you need, and |
| 3550 |
you don't need to check for any special properties of it, then you can |
| 3551 |
use a general type-check macro. |
| 3552 |
|
| 3553 |
* Menu: |
| 3554 |
|
| 3555 |
* Particular Types:: Special handling to find certain types |
| 3556 |
* Generic Types:: How to find other types |
| 3557 |
|
| 3558 |
|
| 3559 |
File: autoconf.info, Node: Particular Types, Next: Generic Types, Prev: Types, Up: Types |
| 3560 |
|
| 3561 |
5.9.1 Particular Type Checks |
| 3562 |
---------------------------- |
| 3563 |
|
| 3564 |
These macros check for particular C types in ‘sys/types.h’, ‘stdlib.h’ |
| 3565 |
and others, if they exist. |
| 3566 |
|
| 3567 |
-- Macro: AC_TYPE_GETGROUPS |
| 3568 |
Define ‘GETGROUPS_T’ to be whichever of ‘gid_t’ or ‘int’ is the |
| 3569 |
base type of the array argument to ‘getgroups’. |
| 3570 |
|
| 3571 |
-- Macro: AC_TYPE_MODE_T |
| 3572 |
Equivalent to ‘AC_CHECK_TYPE(mode_t, int)’. |
| 3573 |
|
| 3574 |
-- Macro: AC_TYPE_OFF_T |
| 3575 |
Equivalent to ‘AC_CHECK_TYPE(off_t, long)’. |
| 3576 |
|
| 3577 |
-- Macro: AC_TYPE_PID_T |
| 3578 |
Equivalent to ‘AC_CHECK_TYPE(pid_t, int)’. |
| 3579 |
|
| 3580 |
-- Macro: AC_TYPE_SIGNAL |
| 3581 |
If ‘signal.h’ declares ‘signal’ as returning a pointer to a |
| 3582 |
function returning ‘void’, define ‘RETSIGTYPE’ to be ‘void’; |
| 3583 |
otherwise, define it to be ‘int’. |
| 3584 |
|
| 3585 |
Define signal handlers as returning type ‘RETSIGTYPE’: |
| 3586 |
|
| 3587 |
RETSIGTYPE |
| 3588 |
hup_handler () |
| 3589 |
{ |
| 3590 |
... |
| 3591 |
} |
| 3592 |
|
| 3593 |
-- Macro: AC_TYPE_SIZE_T |
| 3594 |
Equivalent to ‘AC_CHECK_TYPE(size_t, unsigned)’. |
| 3595 |
|
| 3596 |
-- Macro: AC_TYPE_UID_T |
| 3597 |
If ‘uid_t’ is not defined, define ‘uid_t’ to be ‘int’ and ‘gid_t’ |
| 3598 |
to be ‘int’. |
| 3599 |
|
| 3600 |
|
| 3601 |
File: autoconf.info, Node: Generic Types, Prev: Particular Types, Up: Types |
| 3602 |
|
| 3603 |
5.9.2 Generic Type Checks |
| 3604 |
------------------------- |
| 3605 |
|
| 3606 |
These macros are used to check for types not covered by the "particular" |
| 3607 |
test macros. |
| 3608 |
|
| 3609 |
-- Macro: AC_CHECK_TYPE (TYPE, [ACTION-IF-FOUND], |
| 3610 |
[ACTION-IF-NOT-FOUND], [INCLUDES]) |
| 3611 |
Check whether TYPE is defined. It may be a compiler builtin type |
| 3612 |
or defined by the [INCLUDES] (*note Default Includes::). |
| 3613 |
|
| 3614 |
-- Macro: AC_CHECK_TYPES (TYPES, [ACTION-IF-FOUND], |
| 3615 |
[ACTION-IF-NOT-FOUND], [INCLUDES]) |
| 3616 |
For each TYPE of the TYPES that is defined, define ‘HAVE_TYPE’ (in |
| 3617 |
all capitals). If no INCLUDES are specified, the default includes |
| 3618 |
are used (*note Default Includes::). If ACTION-IF-FOUND is given, |
| 3619 |
it is additional shell code to execute when one of the types is |
| 3620 |
found. If ACTION-IF-NOT-FOUND is given, it is executed when one of |
| 3621 |
the types is not found. |
| 3622 |
|
| 3623 |
This macro uses m4 lists: |
| 3624 |
AC_CHECK_TYPES(ptrdiff_t) |
| 3625 |
AC_CHECK_TYPES([unsigned long long, uintmax_t]) |
| 3626 |
|
| 3627 |
Autoconf, up to 2.13, used to provide to another version of |
| 3628 |
‘AC_CHECK_TYPE’, broken by design. In order to keep backward |
| 3629 |
compatibility, a simple heuristics, quite safe but not totally, is |
| 3630 |
implemented. In case of doubt, read the documentation of the former |
| 3631 |
‘AC_CHECK_TYPE’, see *note Obsolete Macros::. |
| 3632 |
|
| 3633 |
|
| 3634 |
File: autoconf.info, Node: Compilers and Preprocessors, Next: System Services, Prev: Types, Up: Existing Tests |
| 3635 |
|
| 3636 |
5.10 Compilers and Preprocessors |
| 3637 |
================================ |
| 3638 |
|
| 3639 |
All the tests for compilers (‘AC_PROG_CC’, ‘AC_PROG_CXX’, ‘AC_PROG_F77’) |
| 3640 |
define the output variable ‘EXEEXT’ based on the output of the compiler, |
| 3641 |
typically to the empty string if Unix and ‘.exe’ if Win32 or OS/2. |
| 3642 |
|
| 3643 |
They also define the output variable ‘OBJEXT’ based on the output of |
| 3644 |
the compiler, after .c files have been excluded, typically to ‘o’ if |
| 3645 |
Unix, ‘obj’ if Win32. |
| 3646 |
|
| 3647 |
If the compiler being used does not produce executables, they fail. |
| 3648 |
If the executables can't be run, and cross-compilation is not enabled, |
| 3649 |
they fail too. *Note Manual Configuration::, for more on support for |
| 3650 |
cross compiling. |
| 3651 |
|
| 3652 |
* Menu: |
| 3653 |
|
| 3654 |
* Generic Compiler Characteristics:: Language independent tests |
| 3655 |
* C Compiler:: Checking its characteristics |
| 3656 |
* C++ Compiler:: Likewise |
| 3657 |
* Fortran 77 Compiler:: Likewise |
| 3658 |
|
| 3659 |
|
| 3660 |
File: autoconf.info, Node: Generic Compiler Characteristics, Next: C Compiler, Prev: Compilers and Preprocessors, Up: Compilers and Preprocessors |
| 3661 |
|
| 3662 |
5.10.1 Generic Compiler Characteristics |
| 3663 |
--------------------------------------- |
| 3664 |
|
| 3665 |
-- Macro: AC_CHECK_SIZEOF (TYPE, [UNUSED], [INCLUDES]) |
| 3666 |
Define ‘SIZEOF_TYPE’ (*note Standard Symbols::) to be the size in |
| 3667 |
bytes of TYPE. If ‘type’ is unknown, it gets a size of 0. If no |
| 3668 |
INCLUDES are specified, the default includes are used (*note |
| 3669 |
Default Includes::). If you provide INCLUDE, make sure to include |
| 3670 |
‘stdio.h’ which is required for this macro to run. |
| 3671 |
|
| 3672 |
This macro now works even when cross-compiling. The UNUSED |
| 3673 |
argument was used when cross-compiling. |
| 3674 |
|
| 3675 |
For example, the call |
| 3676 |
|
| 3677 |
AC_CHECK_SIZEOF(int *) |
| 3678 |
|
| 3679 |
defines ‘SIZEOF_INT_P’ to be 8 on DEC Alpha AXP systems. |
| 3680 |
|
| 3681 |
|
| 3682 |
File: autoconf.info, Node: C Compiler, Next: C++ Compiler, Prev: Generic Compiler Characteristics, Up: Compilers and Preprocessors |
| 3683 |
|
| 3684 |
5.10.2 C Compiler Characteristics |
| 3685 |
--------------------------------- |
| 3686 |
|
| 3687 |
-- Macro: AC_PROG_CC ([COMPILER-SEARCH-LIST]) |
| 3688 |
Determine a C compiler to use. If ‘CC’ is not already set in the |
| 3689 |
environment, check for ‘gcc’ and ‘cc’, then for other C compilers. |
| 3690 |
Set output variable ‘CC’ to the name of the compiler found. |
| 3691 |
|
| 3692 |
This macro may, however, be invoked with an optional first argument |
| 3693 |
which, if specified, must be a space separated list of C compilers |
| 3694 |
to search for. This just gives the user an opportunity to specify |
| 3695 |
an alternative search list for the C compiler. For example, if you |
| 3696 |
didn't like the default order, then you could invoke ‘AC_PROG_CC’ |
| 3697 |
like this: |
| 3698 |
|
| 3699 |
AC_PROG_CC(cl egcs gcc cc) |
| 3700 |
|
| 3701 |
If using the GNU C compiler, set shell variable ‘GCC’ to ‘yes’. If |
| 3702 |
output variable ‘CFLAGS’ was not already set, set it to ‘-g -O2’ |
| 3703 |
for the GNU C compiler (‘-O2’ on systems where GCC does not accept |
| 3704 |
‘-g’), or ‘-g’ for other compilers. |
| 3705 |
|
| 3706 |
-- Macro: AC_PROG_CC_C_O |
| 3707 |
If the C compiler does not accept the ‘-c’ and ‘-o’ options |
| 3708 |
simultaneously, define ‘NO_MINUS_C_MINUS_O’. This macro actually |
| 3709 |
tests both the compiler found by ‘AC_PROG_CC’, and, if different, |
| 3710 |
the first ‘cc’ in the path. The test fails if one fails. This |
| 3711 |
macro was created for GNU Make to choose the default C compilation |
| 3712 |
rule. |
| 3713 |
|
| 3714 |
-- Macro: AC_PROG_CC_STDC |
| 3715 |
If the C compiler is not in ANSI C mode by default, try to add an |
| 3716 |
option to output variable ‘CC’ to make it so. This macro tries |
| 3717 |
various options that select ANSI C on some system or another. It |
| 3718 |
considers the compiler to be in ANSI C mode if it handles function |
| 3719 |
prototypes correctly. |
| 3720 |
|
| 3721 |
If you use this macro, you should check after calling it whether |
| 3722 |
the C compiler has been set to accept ANSI C; if not, the shell |
| 3723 |
variable ‘ac_cv_prog_cc_stdc’ is set to ‘no’. If you wrote your |
| 3724 |
source code in ANSI C, you can make an un-ANSIfied copy of it by |
| 3725 |
using the program ‘ansi2knr’, which comes with Automake. |
| 3726 |
|
| 3727 |
-- Macro: AC_PROG_CPP |
| 3728 |
Set output variable ‘CPP’ to a command that runs the C |
| 3729 |
preprocessor. If ‘$CC -E’ doesn't work, ‘/lib/cpp’ is used. It is |
| 3730 |
only portable to run ‘CPP’ on files with a ‘.c’ extension. |
| 3731 |
|
| 3732 |
If the current language is C (*note Language Choice::), many of the |
| 3733 |
specific test macros use the value of ‘CPP’ indirectly by calling |
| 3734 |
‘AC_TRY_CPP’, ‘AC_CHECK_HEADER’, ‘AC_EGREP_HEADER’, or |
| 3735 |
‘AC_EGREP_CPP’. |
| 3736 |
|
| 3737 |
Some preprocessors don't indicate missing include files by the |
| 3738 |
error status. For such preprocessors an internal variable is set |
| 3739 |
that causes other macros to check the standard error from the |
| 3740 |
preprocessor and consider the test failed if any warnings have been |
| 3741 |
reported. |
| 3742 |
|
| 3743 |
The following macros check for C compiler or machine architecture |
| 3744 |
features. To check for characteristics not listed here, use |
| 3745 |
‘AC_TRY_COMPILE’ (*note Examining Syntax::) or ‘AC_TRY_RUN’ (*note Run |
| 3746 |
Time::) |
| 3747 |
|
| 3748 |
-- Macro: AC_C_BIGENDIAN |
| 3749 |
If words are stored with the most significant byte first (like |
| 3750 |
Motorola and SPARC, but not Intel and VAX, CPUs), define |
| 3751 |
‘WORDS_BIGENDIAN’. |
| 3752 |
|
| 3753 |
-- Macro: AC_C_CONST |
| 3754 |
If the C compiler does not fully support the ANSI C qualifier |
| 3755 |
‘const’, define ‘const’ to be empty. Some C compilers that do not |
| 3756 |
define ‘__STDC__’ do support ‘const’; some compilers that define |
| 3757 |
‘__STDC__’ do not completely support ‘const’. Programs can simply |
| 3758 |
use ‘const’ as if every C compiler supported it; for those that |
| 3759 |
don't, the ‘Makefile’ or configuration header file will define it |
| 3760 |
as empty. |
| 3761 |
|
| 3762 |
Occasionally installers use a C++ compiler to compile C code, |
| 3763 |
typically because they lack a C compiler. This causes problems |
| 3764 |
with ‘const’, because C and C++ treat ‘const’ differently. For |
| 3765 |
example: |
| 3766 |
|
| 3767 |
const int foo; |
| 3768 |
|
| 3769 |
is valid in C but not in C++. These differences unfortunately |
| 3770 |
cannot be papered over by defining ‘const’ to be empty. |
| 3771 |
|
| 3772 |
If ‘autoconf’ detects this situation, it leaves ‘const’ alone, as |
| 3773 |
this generally yields better results in practice. However, using a |
| 3774 |
C++ compiler to compile C code is not recommended or supported, and |
| 3775 |
installers who run into trouble in this area should get a C |
| 3776 |
compiler like GCC to compile their C code. |
| 3777 |
|
| 3778 |
-- Macro: AC_C_VOLATILE |
| 3779 |
If the C compiler does not understand the keyword ‘volatile’, |
| 3780 |
define ‘volatile’ to be empty. Programs can simply use ‘volatile’ |
| 3781 |
as if every C compiler supported it; for those that do not, the |
| 3782 |
‘Makefile’ or configuration header will define it as empty. |
| 3783 |
|
| 3784 |
If the correctness of your program depends on the semantics of |
| 3785 |
‘volatile’, simply defining it to be empty does, in a sense, break |
| 3786 |
your code. However, given that the compiler does not support |
| 3787 |
‘volatile’, you are at its mercy anyway. At least your program |
| 3788 |
will compile, when it wouldn't before. |
| 3789 |
|
| 3790 |
In general, the ‘volatile’ keyword is a feature of ANSI C, so you |
| 3791 |
might expect that ‘volatile’ is available only when ‘__STDC__’ is |
| 3792 |
defined. However, Ultrix 4.3's native compiler does support |
| 3793 |
volatile, but does not defined ‘__STDC__’. |
| 3794 |
|
| 3795 |
-- Macro: AC_C_INLINE |
| 3796 |
If the C compiler supports the keyword ‘inline’, do nothing. |
| 3797 |
Otherwise define ‘inline’ to ‘__inline__’ or ‘__inline’ if it |
| 3798 |
accepts one of those, otherwise define ‘inline’ to be empty. |
| 3799 |
|
| 3800 |
-- Macro: AC_C_CHAR_UNSIGNED |
| 3801 |
If the C type ‘char’ is unsigned, define ‘__CHAR_UNSIGNED__’, |
| 3802 |
unless the C compiler predefines it. |
| 3803 |
|
| 3804 |
-- Macro: AC_C_LONG_DOUBLE |
| 3805 |
If the C compiler supports the ‘long double’ type, define |
| 3806 |
‘HAVE_LONG_DOUBLE’. Some C compilers that do not define ‘__STDC__’ |
| 3807 |
do support the ‘long double’ type; some compilers that define |
| 3808 |
‘__STDC__’ do not support ‘long double’. |
| 3809 |
|
| 3810 |
-- Macro: AC_C_STRINGIZE |
| 3811 |
If the C preprocessor supports the stringizing operator, define |
| 3812 |
‘HAVE_STRINGIZE’. The stringizing operator is ‘#’ and is found in |
| 3813 |
macros such as this: |
| 3814 |
|
| 3815 |
#define x(y) #y |
| 3816 |
|
| 3817 |
-- Macro: AC_C_PROTOTYPES |
| 3818 |
Check to see if function prototypes are understood by the compiler. |
| 3819 |
If so, define ‘PROTOTYPES’. In the case the compiler does not |
| 3820 |
handle prototypes, you should use ‘ansi2knr’, which comes with the |
| 3821 |
Automake distribution, to unprotoize function definitions. For |
| 3822 |
function prototypes, you should first define ‘PARAMS’: |
| 3823 |
|
| 3824 |
#ifndef PARAMS |
| 3825 |
# if PROTOTYPES |
| 3826 |
# define PARAMS(protos) protos |
| 3827 |
# else /* no PROTOTYPES */ |
| 3828 |
# define PARAMS(protos) () |
| 3829 |
# endif /* no PROTOTYPES */ |
| 3830 |
#endif |
| 3831 |
|
| 3832 |
then use it this way: |
| 3833 |
|
| 3834 |
size_t my_strlen PARAMS ((const char *)); |
| 3835 |
|
| 3836 |
-- Macro: AC_PROG_GCC_TRADITIONAL |
| 3837 |
Add ‘-traditional’ to output variable ‘CC’ if using the GNU C |
| 3838 |
compiler and ‘ioctl’ does not work properly without ‘-traditional’. |
| 3839 |
That usually happens when the fixed header files have not been |
| 3840 |
installed on an old system. Since recent versions of the GNU C |
| 3841 |
compiler fix the header files automatically when installed, this is |
| 3842 |
becoming a less prevalent problem. |
| 3843 |
|
| 3844 |
|
| 3845 |
File: autoconf.info, Node: C++ Compiler, Next: Fortran 77 Compiler, Prev: C Compiler, Up: Compilers and Preprocessors |
| 3846 |
|
| 3847 |
5.10.3 C++ Compiler Characteristics |
| 3848 |
----------------------------------- |
| 3849 |
|
| 3850 |
-- Macro: AC_PROG_CXX ([COMPILER-SEARCH-LIST]) |
| 3851 |
Determine a C++ compiler to use. Check if the environment variable |
| 3852 |
‘CXX’ or ‘CCC’ (in that order) is set; if so, then set output |
| 3853 |
variable ‘CXX’ to its value. |
| 3854 |
|
| 3855 |
Otherwise, if the macro is invoked without an argument, then search |
| 3856 |
for a C++ compiler under the likely names (first ‘g++’ and ‘c++’ |
| 3857 |
then other names). If none of those checks succeed, then as a last |
| 3858 |
resort set ‘CXX’ to ‘g++’. |
| 3859 |
|
| 3860 |
This macro may, however, be invoked with an optional first argument |
| 3861 |
which, if specified, must be a space separated list of C++ |
| 3862 |
compilers to search for. This just gives the user an opportunity |
| 3863 |
to specify an alternative search list for the C++ compiler. For |
| 3864 |
example, if you didn't like the default order, then you could |
| 3865 |
invoke ‘AC_PROG_CXX’ like this: |
| 3866 |
|
| 3867 |
AC_PROG_CXX(cl KCC CC cxx cc++ xlC aCC c++ g++ egcs gcc) |
| 3868 |
|
| 3869 |
If using the GNU C++ compiler, set shell variable ‘GXX’ to ‘yes’. |
| 3870 |
If output variable ‘CXXFLAGS’ was not already set, set it to ‘-g |
| 3871 |
-O2’ for the GNU C++ compiler (‘-O2’ on systems where G++ does not |
| 3872 |
accept ‘-g’), or ‘-g’ for other compilers. |
| 3873 |
|
| 3874 |
-- Macro: AC_PROG_CXXCPP |
| 3875 |
Set output variable ‘CXXCPP’ to a command that runs the C++ |
| 3876 |
preprocessor. If ‘$CXX -E’ doesn't work, ‘/lib/cpp’ is used. It |
| 3877 |
is only portable to run ‘CXXCPP’ on files with a ‘.c’, ‘.C’, or |
| 3878 |
‘.cc’ extension. |
| 3879 |
|
| 3880 |
If the current language is C++ (*note Language Choice::), many of |
| 3881 |
the specific test macros use the value of ‘CXXCPP’ indirectly by |
| 3882 |
calling ‘AC_TRY_CPP’, ‘AC_CHECK_HEADER’, ‘AC_EGREP_HEADER’, or |
| 3883 |
‘AC_EGREP_CPP’. |
| 3884 |
|
| 3885 |
Some preprocessors don't indicate missing include files by the |
| 3886 |
error status. For such preprocessors an internal variable is set |
| 3887 |
that causes other macros to check the standard error from the |
| 3888 |
preprocessor and consider the test failed if any warnings have been |
| 3889 |
reported. However, it is not known whether such broken |
| 3890 |
preprocessors exist for C++. |
| 3891 |
|
| 3892 |
|
| 3893 |
File: autoconf.info, Node: Fortran 77 Compiler, Prev: C++ Compiler, Up: Compilers and Preprocessors |
| 3894 |
|
| 3895 |
5.10.4 Fortran 77 Compiler Characteristics |
| 3896 |
------------------------------------------ |
| 3897 |
|
| 3898 |
-- Macro: AC_PROG_F77 ([COMPILER-SEARCH-LIST]) |
| 3899 |
Determine a Fortran 77 compiler to use. If ‘F77’ is not already |
| 3900 |
set in the environment, then check for ‘g77’ and ‘f77’, and then |
| 3901 |
some other names. Set the output variable ‘F77’ to the name of the |
| 3902 |
compiler found. |
| 3903 |
|
| 3904 |
This macro may, however, be invoked with an optional first argument |
| 3905 |
which, if specified, must be a space separated list of Fortran 77 |
| 3906 |
compilers to search for. This just gives the user an opportunity |
| 3907 |
to specify an alternative search list for the Fortran 77 compiler. |
| 3908 |
For example, if you didn't like the default order, then you could |
| 3909 |
invoke ‘AC_PROG_F77’ like this: |
| 3910 |
|
| 3911 |
AC_PROG_F77(fl32 f77 fort77 xlf cf77 g77 f90 xlf90) |
| 3912 |
|
| 3913 |
If using ‘g77’ (the GNU Fortran 77 compiler), then ‘AC_PROG_F77’ |
| 3914 |
will set the shell variable ‘G77’ to ‘yes’. If the output variable |
| 3915 |
‘FFLAGS’ was not already set in the environment, then set it to ‘-g |
| 3916 |
-02’ for ‘g77’ (or ‘-O2’ where ‘g77’ does not accept ‘-g’). |
| 3917 |
Otherwise, set ‘FFLAGS’ to ‘-g’ for all other Fortran 77 compilers. |
| 3918 |
|
| 3919 |
-- Macro: AC_PROG_F77_C_O |
| 3920 |
Test if the Fortran 77 compiler accepts the options ‘-c’ and ‘-o’ |
| 3921 |
simultaneously, and define ‘F77_NO_MINUS_C_MINUS_O’ if it does not. |
| 3922 |
|
| 3923 |
The following macros check for Fortran 77 compiler characteristics. |
| 3924 |
To check for characteristics not listed here, use ‘AC_TRY_COMPILE’ |
| 3925 |
(*note Examining Syntax::) or ‘AC_TRY_RUN’ (*note Run Time::), making |
| 3926 |
sure to first set the current language to Fortran 77 ‘AC_LANG(Fortran |
| 3927 |
77)’ (*note Language Choice::). |
| 3928 |
|
| 3929 |
-- Macro: AC_F77_LIBRARY_LDFLAGS |
| 3930 |
Determine the linker flags (e.g. ‘-L’ and ‘-l’) for the “Fortran |
| 3931 |
77 intrinsic and run-time libraries” that are required to |
| 3932 |
successfully link a Fortran 77 program or shared library. The |
| 3933 |
output variable ‘FLIBS’ is set to these flags. |
| 3934 |
|
| 3935 |
This macro is intended to be used in those situations when it is |
| 3936 |
necessary to mix, e.g. C++ and Fortran 77 source code into a |
| 3937 |
single program or shared library (*note (automake)Mixing Fortran 77 |
| 3938 |
With C and C++::). |
| 3939 |
|
| 3940 |
For example, if object files from a C++ and Fortran 77 compiler |
| 3941 |
must be linked together, then the C++ compiler/linker must be used |
| 3942 |
for linking (since special C++-ish things need to happen at link |
| 3943 |
time like calling global constructors, instantiating templates, |
| 3944 |
enabling exception support, etc.). |
| 3945 |
|
| 3946 |
However, the Fortran 77 intrinsic and run-time libraries must be |
| 3947 |
linked in as well, but the C++ compiler/linker doesn't know by |
| 3948 |
default how to add these Fortran 77 libraries. Hence, the macro |
| 3949 |
‘AC_F77_LIBRARY_LDFLAGS’ was created to determine these Fortran 77 |
| 3950 |
libraries. |
| 3951 |
|
| 3952 |
The macro ‘AC_F77_DUMMY_MAIN’ or ‘AC_F77_MAIN’ will probably also |
| 3953 |
be necessary to link C/C++ with Fortran; see below. |
| 3954 |
|
| 3955 |
-- Macro: AC_F77_DUMMY_MAIN ([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
| 3956 |
With many compilers, the Fortran libraries detected by |
| 3957 |
‘AC_F77_LIBRARY_LDFLAGS’ provide their own ‘main’ entry function |
| 3958 |
that initializes things like Fortran I/O, and which then calls a |
| 3959 |
user-provided entry function named e.g. ‘MAIN__’ to run the user's |
| 3960 |
program. The ‘AC_F77_DUMMY_MAIN’ or ‘AC_F77_MAIN’ macro figures |
| 3961 |
out how to deal with this interaction. |
| 3962 |
|
| 3963 |
When using Fortran for purely numerical functions (no I/O, |
| 3964 |
etcetera), users often prefer to provide their own ‘main’ and skip |
| 3965 |
the Fortran library initializations. In this case, however, one |
| 3966 |
may still need to provide a dummy ‘MAIN__’ routine in order to |
| 3967 |
prevent linking errors on some systems. ‘AC_F77_DUMMY_MAIN’ |
| 3968 |
detects whether any such routine is _required_ for linking, and |
| 3969 |
what its name is; the shell variable ‘F77_DUMMY_MAIN’ holds this |
| 3970 |
name, ‘unknown’ when no solution was found, and ‘none’ when no such |
| 3971 |
dummy main is needed. |
| 3972 |
|
| 3973 |
By default, ACTION-IF-FOUND defines ‘F77_DUMMY_MAIN’ to the name of |
| 3974 |
this routine (e.g. ‘MAIN__’) _if_ it is required. |
| 3975 |
[ACTION-IF-NOT-FOUND] defaults to exiting with an error. |
| 3976 |
|
| 3977 |
In order to link with Fortran routines, the user's C/C++ program |
| 3978 |
should then include the following code to define the dummy main if |
| 3979 |
it is needed: |
| 3980 |
|
| 3981 |
#ifdef F77_DUMMY_MAIN |
| 3982 |
# ifdef __cplusplus |
| 3983 |
extern "C" |
| 3984 |
# endif |
| 3985 |
int F77_DUMMY_MAIN() { return 1; } |
| 3986 |
#endif |
| 3987 |
|
| 3988 |
Note that ‘AC_F77_DUMMY_MAIN’ is called automatically from |
| 3989 |
‘AC_F77_WRAPPERS’; there is generally no need to call it explicitly |
| 3990 |
unless one wants to change the default actions. |
| 3991 |
|
| 3992 |
-- Macro: AC_F77_MAIN |
| 3993 |
As discussed above for ‘AC_F77_DUMMY_MAIN’, many Fortran libraries |
| 3994 |
allow you to provide an entry point called e.g. ‘MAIN__’ instead |
| 3995 |
of the usual ‘main’, which is then called by a ‘main’ function in |
| 3996 |
the Fortran libraries that initializes things like Fortran I/O. The |
| 3997 |
‘AC_F77_MAIN’ macro detects whether it is _possible_ to utilize |
| 3998 |
such an alternate main function, and defines ‘F77_MAIN’ to the name |
| 3999 |
of the function. (If no alternate main function name is found, |
| 4000 |
‘F77_MAIN’ is simply defined to ‘main’.) |
| 4001 |
|
| 4002 |
Thus, when calling Fortran routines from C that perform things like |
| 4003 |
I/O, one should use this macro and name the "main" function |
| 4004 |
‘F77_MAIN’ instead of ‘main’. |
| 4005 |
|
| 4006 |
-- Macro: AC_F77_WRAPPERS |
| 4007 |
Defines C macros ‘F77_FUNC(name,NAME)’ and ‘F77_FUNC_(name,NAME)’ |
| 4008 |
to properly mangle the names of C/C++ identifiers, and identifiers |
| 4009 |
with underscores, respectively, so that they match the |
| 4010 |
name-mangling scheme used by the Fortran 77 compiler. |
| 4011 |
|
| 4012 |
Fortran 77 is case-insensitive, and in order to achieve this the |
| 4013 |
Fortran 77 compiler converts all identifiers into a canonical case |
| 4014 |
and format. To call a Fortran 77 subroutine from C or to write a C |
| 4015 |
function that is callable from Fortran 77, the C program must |
| 4016 |
explicitly use identifiers in the format expected by the Fortran 77 |
| 4017 |
compiler. In order to do this, one simply wraps all C identifiers |
| 4018 |
in one of the macros provided by ‘AC_F77_WRAPPERS’. For example, |
| 4019 |
suppose you have the following Fortran 77 subroutine: |
| 4020 |
|
| 4021 |
subroutine foobar(x,y) |
| 4022 |
double precision x, y |
| 4023 |
y = 3.14159 * x |
| 4024 |
return |
| 4025 |
end |
| 4026 |
|
| 4027 |
You would then declare its prototype in C or C++ as: |
| 4028 |
|
| 4029 |
#define FOOBAR_F77 F77_FUNC(foobar,FOOBAR) |
| 4030 |
#ifdef __cplusplus |
| 4031 |
extern "C" /* prevent C++ name mangling */ |
| 4032 |
#endif |
| 4033 |
void FOOBAR_F77(double *x, double *y); |
| 4034 |
|
| 4035 |
Note that we pass both the lowercase and uppercase versions of the |
| 4036 |
function name to ‘F77_FUNC’ so that it can select the right one. |
| 4037 |
Note also that all parameters to Fortran 77 routines are passed as |
| 4038 |
pointers (*note (automake)Mixing Fortran 77 With C and C++::). |
| 4039 |
|
| 4040 |
Although Autoconf tries to be intelligent about detecting the |
| 4041 |
name-mangling scheme of the Fortran 77 compiler, there may be |
| 4042 |
Fortran 77 compilers that it doesn't support yet. In this case, |
| 4043 |
the above code will generate a compile-time error, but some other |
| 4044 |
behavior (e.g. disabling Fortran-related features) can be induced |
| 4045 |
by checking whether the ‘F77_FUNC’ macro is defined. |
| 4046 |
|
| 4047 |
Now, to call that routine from a C program, we would do something |
| 4048 |
like: |
| 4049 |
|
| 4050 |
{ |
| 4051 |
double x = 2.7183, y; |
| 4052 |
FOOBAR_F77(&x, &y); |
| 4053 |
} |
| 4054 |
|
| 4055 |
If the Fortran 77 identifier contains an underscore (e.g. |
| 4056 |
‘foo_bar’), you should use ‘F77_FUNC_’ instead of ‘F77_FUNC’ (with |
| 4057 |
the same arguments). This is because some Fortran 77 compilers |
| 4058 |
mangle names differently if they contain an underscore. |
| 4059 |
|
| 4060 |
-- Macro: AC_F77_FUNC (NAME, [SHELLVAR]) |
| 4061 |
Given an identifier NAME, set the shell variable SHELLVAR to hold |
| 4062 |
the mangled version NAME according to the rules of the Fortran 77 |
| 4063 |
linker (see also ‘AC_F77_WRAPPERS’). SHELLVAR is optional; if it |
| 4064 |
is not supplied, the shell variable will be simply NAME. The |
| 4065 |
purpose of this macro is to give the caller a way to access the |
| 4066 |
name-mangling information other than through the C preprocessor as |
| 4067 |
above; for example, to call Fortran routines from some language |
| 4068 |
other than C/C++. |
| 4069 |
|
| 4070 |
|
| 4071 |
File: autoconf.info, Node: System Services, Next: UNIX Variants, Prev: Compilers and Preprocessors, Up: Existing Tests |
| 4072 |
|
| 4073 |
5.11 System Services |
| 4074 |
==================== |
| 4075 |
|
| 4076 |
The following macros check for operating system services or |
| 4077 |
capabilities. |
| 4078 |
|
| 4079 |
-- Macro: AC_PATH_X |
| 4080 |
Try to locate the X Window System include files and libraries. If |
| 4081 |
the user gave the command line options ‘--x-includes=DIR’ and |
| 4082 |
‘--x-libraries=DIR’, use those directories. If either or both were |
| 4083 |
not given, get the missing values by running ‘xmkmf’ on a trivial |
| 4084 |
‘Imakefile’ and examining the ‘Makefile’ that it produces. If that |
| 4085 |
fails (such as if ‘xmkmf’ is not present), look for them in several |
| 4086 |
directories where they often reside. If either method is |
| 4087 |
successful, set the shell variables ‘x_includes’ and ‘x_libraries’ |
| 4088 |
to their locations, unless they are in directories the compiler |
| 4089 |
searches by default. |
| 4090 |
|
| 4091 |
If both methods fail, or the user gave the command line option |
| 4092 |
‘--without-x’, set the shell variable ‘no_x’ to ‘yes’; otherwise |
| 4093 |
set it to the empty string. |
| 4094 |
|
| 4095 |
-- Macro: AC_PATH_XTRA |
| 4096 |
An enhanced version of ‘AC_PATH_X’. It adds the C compiler flags |
| 4097 |
that X needs to output variable ‘X_CFLAGS’, and the X linker flags |
| 4098 |
to ‘X_LIBS’. Define ‘X_DISPLAY_MISSING’ if X is not available. |
| 4099 |
|
| 4100 |
This macro also checks for special libraries that some systems need |
| 4101 |
in order to compile X programs. It adds any that the system needs |
| 4102 |
to output variable ‘X_EXTRA_LIBS’. And it checks for special X11R6 |
| 4103 |
libraries that need to be linked with before ‘-lX11’, and adds any |
| 4104 |
found to the output variable ‘X_PRE_LIBS’. |
| 4105 |
|
| 4106 |
-- Macro: AC_SYS_INTERPRETER |
| 4107 |
Check whether the system supports starting scripts with a line of |
| 4108 |
the form ‘#! /bin/csh’ to select the interpreter to use for the |
| 4109 |
script. After running this macro, shell code in ‘configure.ac’ can |
| 4110 |
check the shell variable ‘interpval’; it will be set to ‘yes’ if |
| 4111 |
the system supports ‘#!’, ‘no’ if not. |
| 4112 |
|
| 4113 |
-- Macro: AC_SYS_LARGEFILE |
| 4114 |
Arrange for large-file support(1). On some hosts, one must use |
| 4115 |
special compiler options to build programs that can access large |
| 4116 |
files. Append any such options to the output variable ‘CC’. |
| 4117 |
Define ‘_FILE_OFFSET_BITS’ and ‘_LARGE_FILES’ if necessary. |
| 4118 |
|
| 4119 |
Large-file support can be disabled by configuring with the |
| 4120 |
‘--disable-largefile’ option. |
| 4121 |
|
| 4122 |
If you use this macro, check that your program works even when |
| 4123 |
‘off_t’ is longer than ‘long’, since this is common when large-file |
| 4124 |
support is enabled. For example, it is not correct to print an |
| 4125 |
arbitrary ‘off_t’ value ‘X’ with ‘printf ("%ld", (long) X)’. |
| 4126 |
|
| 4127 |
-- Macro: AC_SYS_LONG_FILE_NAMES |
| 4128 |
If the system supports file names longer than 14 characters, define |
| 4129 |
‘HAVE_LONG_FILE_NAMES’. |
| 4130 |
|
| 4131 |
-- Macro: AC_SYS_POSIX_TERMIOS |
| 4132 |
Check to see if POSIX termios headers and functions are available |
| 4133 |
on the system. If so, set the shell variable |
| 4134 |
‘am_cv_sys_posix_termios’ to ‘yes’. If not, set the variable to |
| 4135 |
‘no’. |
| 4136 |
|
| 4137 |
---------- Footnotes ---------- |
| 4138 |
|
| 4139 |
(1) large-file support, |
| 4140 |
<http://www.sas.com/standards/large.file/x_open.20Mar96.html>. |
| 4141 |
|
| 4142 |
|
| 4143 |
File: autoconf.info, Node: UNIX Variants, Prev: System Services, Up: Existing Tests |
| 4144 |
|
| 4145 |
5.12 UNIX Variants |
| 4146 |
================== |
| 4147 |
|
| 4148 |
The following macros check for certain operating systems that need |
| 4149 |
special treatment for some programs, due to exceptional oddities in |
| 4150 |
their header files or libraries. These macros are warts; they will be |
| 4151 |
replaced by a more systematic approach, based on the functions they make |
| 4152 |
available or the environments they provide. |
| 4153 |
|
| 4154 |
-- Macro: AC_AIX |
| 4155 |
If on AIX, define ‘_ALL_SOURCE’. Allows the use of some BSD |
| 4156 |
functions. Should be called before any macros that run the C |
| 4157 |
compiler. |
| 4158 |
|
| 4159 |
-- Macro: AC_ISC_POSIX |
| 4160 |
If on a POSIXized ISC UNIX, define ‘_POSIX_SOURCE’ and add ‘-posix’ |
| 4161 |
(for the GNU C compiler) or ‘-Xp’ (for other C compilers) to output |
| 4162 |
variable ‘CC’. This allows the use of POSIX facilities. Must be |
| 4163 |
called after ‘AC_PROG_CC’ and before any other macros that run the |
| 4164 |
C compiler. |
| 4165 |
|
| 4166 |
-- Macro: AC_MINIX |
| 4167 |
If on Minix, define ‘_MINIX’ and ‘_POSIX_SOURCE’ and define |
| 4168 |
‘_POSIX_1_SOURCE’ to be 2. This allows the use of POSIX |
| 4169 |
facilities. Should be called before any macros that run the C |
| 4170 |
compiler. |
| 4171 |
|
| 4172 |
|
| 4173 |
File: autoconf.info, Node: Writing Tests, Next: Results, Prev: Existing Tests, Up: Top |
| 4174 |
|
| 4175 |
6 Writing Tests |
| 4176 |
*************** |
| 4177 |
|
| 4178 |
If the existing feature tests don't do something you need, you have to |
| 4179 |
write new ones. These macros are the building blocks. They provide |
| 4180 |
ways for other macros to check whether various kinds of features are |
| 4181 |
available and report the results. |
| 4182 |
|
| 4183 |
This chapter contains some suggestions and some of the reasons why |
| 4184 |
the existing tests are written the way they are. You can also learn a |
| 4185 |
lot about how to write Autoconf tests by looking at the existing ones. |
| 4186 |
If something goes wrong in one or more of the Autoconf tests, this |
| 4187 |
information can help you understand the assumptions behind them, which |
| 4188 |
might help you figure out how to best solve the problem. |
| 4189 |
|
| 4190 |
These macros check the output of the C compiler system. They do not |
| 4191 |
cache the results of their tests for future use (*note Caching |
| 4192 |
Results::), because they don't know enough about the information they |
| 4193 |
are checking for to generate a cache variable name. They also do not |
| 4194 |
print any messages, for the same reason. The checks for particular |
| 4195 |
kinds of C features call these macros and do cache their results and |
| 4196 |
print messages about what they're checking for. |
| 4197 |
|
| 4198 |
When you write a feature test that could be applicable to more than |
| 4199 |
one software package, the best thing to do is encapsulate it in a new |
| 4200 |
macro. *Note Writing Autoconf Macros::, for how to do that. |
| 4201 |
|
| 4202 |
* Menu: |
| 4203 |
|
| 4204 |
* Examining Declarations:: Detecting header files and declarations |
| 4205 |
* Examining Syntax:: Detecting language syntax features |
| 4206 |
* Examining Libraries:: Detecting functions and global variables |
| 4207 |
* Run Time:: Testing for run-time features |
| 4208 |
* Systemology:: A zoology of operating systems |
| 4209 |
* Multiple Cases:: Tests for several possible values |
| 4210 |
* Language Choice:: Selecting which language to use for testing |
| 4211 |
|
| 4212 |
|
| 4213 |
File: autoconf.info, Node: Examining Declarations, Next: Examining Syntax, Prev: Writing Tests, Up: Writing Tests |
| 4214 |
|
| 4215 |
6.1 Examining Declarations |
| 4216 |
========================== |
| 4217 |
|
| 4218 |
The macro ‘AC_TRY_CPP’ is used to check whether particular header files |
| 4219 |
exist. You can check for one at a time, or more than one if you need |
| 4220 |
several header files to all exist for some purpose. |
| 4221 |
|
| 4222 |
-- Macro: AC_TRY_CPP (INCLUDES, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) |
| 4223 |
INCLUDES is C or C++ ‘#include’ statements and declarations, on |
| 4224 |
which shell variable, back quote, and backslash substitutions are |
| 4225 |
performed. (Actually, it can be any C program, but other |
| 4226 |
statements are probably not useful.) If the preprocessor produces |
| 4227 |
no error messages while processing it, run shell commands |
| 4228 |
ACTION-IF-TRUE. Otherwise run shell commands ACTION-IF-FALSE. |
| 4229 |
|
| 4230 |
This macro uses ‘CPPFLAGS’, but not ‘CFLAGS’, because ‘-g’, ‘-O’, |
| 4231 |
etc. are not valid options to many C preprocessors. |
| 4232 |
|
| 4233 |
Here is how to find out whether a header file contains a particular |
| 4234 |
declaration, such as a typedef, a structure, a structure member, or a |
| 4235 |
function. Use ‘AC_EGREP_HEADER’ instead of running ‘grep’ directly on |
| 4236 |
the header file; on some systems the symbol might be defined in another |
| 4237 |
header file that the file you are checking ‘#include’s. |
| 4238 |
|
| 4239 |
-- Macro: AC_EGREP_HEADER (PATTERN, HEADER-FILE, ACTION-IF-FOUND, |
| 4240 |
[ACTION-IF-NOT-FOUND]) |
| 4241 |
If the output of running the preprocessor on the system header file |
| 4242 |
HEADER-FILE matches the ‘egrep’ regular expression PATTERN, execute |
| 4243 |
shell commands ACTION-IF-FOUND, otherwise execute |
| 4244 |
ACTION-IF-NOT-FOUND. |
| 4245 |
|
| 4246 |
To check for C preprocessor symbols, either defined by header files |
| 4247 |
or predefined by the C preprocessor, use ‘AC_EGREP_CPP’. Here is an |
| 4248 |
example of the latter: |
| 4249 |
|
| 4250 |
AC_EGREP_CPP(yes, |
| 4251 |
[#ifdef _AIX |
| 4252 |
yes |
| 4253 |
#endif |
| 4254 |
], is_aix=yes, is_aix=no) |
| 4255 |
|
| 4256 |
-- Macro: AC_EGREP_CPP (PATTERN, PROGRAM, [ACTION-IF-FOUND], |
| 4257 |
[ACTION-IF-NOT-FOUND]) |
| 4258 |
PROGRAM is the text of a C or C++ program, on which shell variable, |
| 4259 |
back quote, and backslash substitutions are performed. If the |
| 4260 |
output of running the preprocessor on PROGRAM matches the ‘egrep’ |
| 4261 |
regular expression PATTERN, execute shell commands ACTION-IF-FOUND, |
| 4262 |
otherwise execute ACTION-IF-NOT-FOUND. |
| 4263 |
|
| 4264 |
This macro calls ‘AC_PROG_CPP’ or ‘AC_PROG_CXXCPP’ (depending on |
| 4265 |
which language is current, *note Language Choice::), if it hasn't |
| 4266 |
been called already. |
| 4267 |
|
| 4268 |
|
| 4269 |
File: autoconf.info, Node: Examining Syntax, Next: Examining Libraries, Prev: Examining Declarations, Up: Writing Tests |
| 4270 |
|
| 4271 |
6.2 Examining Syntax |
| 4272 |
==================== |
| 4273 |
|
| 4274 |
To check for a syntax feature of the C, C++ or Fortran 77 compiler, such |
| 4275 |
as whether it recognizes a certain keyword, use ‘AC_TRY_COMPILE’ to try |
| 4276 |
to compile a small program that uses that feature. You can also use it |
| 4277 |
to check for structures and structure members that are not present on |
| 4278 |
all systems. |
| 4279 |
|
| 4280 |
-- Macro: AC_TRY_COMPILE (INCLUDES, FUNCTION-BODY, [ACTION-IF-FOUND], |
| 4281 |
[ACTION-IF-NOT-FOUND]) |
| 4282 |
Create a C, C++ or Fortran 77 test program (depending on which |
| 4283 |
language is current, *note Language Choice::), to see whether a |
| 4284 |
function whose body consists of FUNCTION-BODY can be compiled. |
| 4285 |
|
| 4286 |
For C and C++, INCLUDES is any ‘#include’ statements needed by the |
| 4287 |
code in FUNCTION-BODY (INCLUDES will be ignored if the currently |
| 4288 |
selected language is Fortran 77). This macro also uses ‘CFLAGS’ or |
| 4289 |
‘CXXFLAGS’ if either C or C++ is the currently selected language, |
| 4290 |
as well as ‘CPPFLAGS’, when compiling. If Fortran 77 is the |
| 4291 |
currently selected language then ‘FFLAGS’ will be used when |
| 4292 |
compiling. |
| 4293 |
|
| 4294 |
If the file compiles successfully, run shell commands |
| 4295 |
ACTION-IF-FOUND, otherwise run ACTION-IF-NOT-FOUND. |
| 4296 |
|
| 4297 |
This macro does not try to link; use ‘AC_TRY_LINK’ if you need to |
| 4298 |
do that (*note Examining Libraries::). |
| 4299 |
|
| 4300 |
|
| 4301 |
File: autoconf.info, Node: Examining Libraries, Next: Run Time, Prev: Examining Syntax, Up: Writing Tests |
| 4302 |
|
| 4303 |
6.3 Examining Libraries |
| 4304 |
======================= |
| 4305 |
|
| 4306 |
To check for a library, a function, or a global variable, Autoconf |
| 4307 |
‘configure’ scripts try to compile and link a small program that uses |
| 4308 |
it. This is unlike Metaconfig, which by default uses ‘nm’ or ‘ar’ on |
| 4309 |
the C library to try to figure out which functions are available. |
| 4310 |
Trying to link with the function is usually a more reliable approach |
| 4311 |
because it avoids dealing with the variations in the options and output |
| 4312 |
formats of ‘nm’ and ‘ar’ and in the location of the standard libraries. |
| 4313 |
It also allows configuring for cross-compilation or checking a |
| 4314 |
function's runtime behavior if needed. On the other hand, it can be |
| 4315 |
slower than scanning the libraries once. |
| 4316 |
|
| 4317 |
A few systems have linkers that do not return a failure exit status |
| 4318 |
when there are unresolved functions in the link. This bug makes the |
| 4319 |
configuration scripts produced by Autoconf unusable on those systems. |
| 4320 |
However, some of them can be given options that make the exit status |
| 4321 |
correct. This is a problem that Autoconf does not currently handle |
| 4322 |
automatically. If users encounter this problem, they might be able to |
| 4323 |
solve it by setting ‘LDFLAGS’ in the environment to pass whatever |
| 4324 |
options the linker needs (for example, ‘-Wl,-dn’ on MIPS RISC/OS). |
| 4325 |
|
| 4326 |
‘AC_TRY_LINK’ is used to compile test programs to test for functions |
| 4327 |
and global variables. It is also used by ‘AC_CHECK_LIB’ to check for |
| 4328 |
libraries (*note Libraries::), by adding the library being checked for |
| 4329 |
to ‘LIBS’ temporarily and trying to link a small program. |
| 4330 |
|
| 4331 |
-- Macro: AC_TRY_LINK (INCLUDES, FUNCTION-BODY, [ACTION-IF-FOUND], |
| 4332 |
[ACTION-IF-NOT-FOUND]) |
| 4333 |
Depending on the current language (*note Language Choice::), create |
| 4334 |
a test program to see whether a function whose body consists of |
| 4335 |
FUNCTION-BODY can be compiled and linked. |
| 4336 |
|
| 4337 |
For C and C++, INCLUDES is any ‘#include’ statements needed by the |
| 4338 |
code in FUNCTION-BODY (INCLUDES will be ignored if the currently |
| 4339 |
selected language is Fortran 77). This macro also uses ‘CFLAGS’ or |
| 4340 |
‘CXXFLAGS’ if either C or C++ is the currently selected language, |
| 4341 |
as well as ‘CPPFLAGS’, when compiling. If Fortran 77 is the |
| 4342 |
currently selected language then ‘FFLAGS’ will be used when |
| 4343 |
compiling. However, both ‘LDFLAGS’ and ‘LIBS’ will be used during |
| 4344 |
linking in all cases. |
| 4345 |
|
| 4346 |
If the file compiles and links successfully, run shell commands |
| 4347 |
ACTION-IF-FOUND, otherwise run ACTION-IF-NOT-FOUND. |
| 4348 |
|
| 4349 |
-- Macro: AC_TRY_LINK_FUNC (FUNCTION, [ACTION-IF-FOUND], |
| 4350 |
[ACTION-IF-NOT-FOUND]) |
| 4351 |
Depending on the current language (*note Language Choice::), create |
| 4352 |
a test program to see whether a program whose body consists of a |
| 4353 |
prototype of and a call to FUNCTION can be compiled and linked. |
| 4354 |
|
| 4355 |
If the file compiles and links successfully, run shell commands |
| 4356 |
ACTION-IF-FOUND, otherwise run ACTION-IF-NOT-FOUND. |
| 4357 |
|
| 4358 |
|
| 4359 |
File: autoconf.info, Node: Run Time, Next: Systemology, Prev: Examining Libraries, Up: Writing Tests |
| 4360 |
|
| 4361 |
6.4 Checking Run Time Behavior |
| 4362 |
============================== |
| 4363 |
|
| 4364 |
Sometimes you need to find out how a system performs at run time, such |
| 4365 |
as whether a given function has a certain capability or bug. If you |
| 4366 |
can, make such checks when your program runs instead of when it is |
| 4367 |
configured. You can check for things like the machine's endianness when |
| 4368 |
your program initializes itself. |
| 4369 |
|
| 4370 |
If you really need to test for a run-time behavior while configuring, |
| 4371 |
you can write a test program to determine the result, and compile and |
| 4372 |
run it using ‘AC_TRY_RUN’. Avoid running test programs if possible, |
| 4373 |
because this prevents people from configuring your package for |
| 4374 |
cross-compiling. |
| 4375 |
|
| 4376 |
* Menu: |
| 4377 |
|
| 4378 |
* Test Programs:: Running test programs |
| 4379 |
* Guidelines:: General rules for writing test programs |
| 4380 |
* Test Functions:: Avoiding pitfalls in test programs |
| 4381 |
|
| 4382 |
|
| 4383 |
File: autoconf.info, Node: Test Programs, Next: Guidelines, Prev: Run Time, Up: Run Time |
| 4384 |
|
| 4385 |
6.4.1 Running Test Programs |
| 4386 |
--------------------------- |
| 4387 |
|
| 4388 |
Use the following macro if you need to test run-time behavior of the |
| 4389 |
system while configuring. |
| 4390 |
|
| 4391 |
-- Macro: AC_TRY_RUN (PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE], |
| 4392 |
[ACTION-IF-CROSS-COMPILING]) |
| 4393 |
PROGRAM is the text of a C program, on which shell variable and |
| 4394 |
back quote substitutions are performed. If it compiles and links |
| 4395 |
successfully and returns an exit status of 0 when executed, run |
| 4396 |
shell commands ACTION-IF-TRUE. Otherwise, run shell commands |
| 4397 |
ACTION-IF-FALSE; the exit status of the program is available in the |
| 4398 |
shell variable ‘$?’. This macro uses ‘CFLAGS’ or ‘CXXFLAGS’, |
| 4399 |
‘CPPFLAGS’, ‘LDFLAGS’, and ‘LIBS’ when compiling. |
| 4400 |
|
| 4401 |
If the C compiler being used does not produce executables that run |
| 4402 |
on the system where ‘configure’ is being run, then the test program |
| 4403 |
is not run. If the optional shell commands |
| 4404 |
ACTION-IF-CROSS-COMPILING are given, they are run instead. |
| 4405 |
Otherwise, ‘configure’ prints an error message and exits. |
| 4406 |
|
| 4407 |
Try to provide a pessimistic default value to use when |
| 4408 |
cross-compiling makes run-time tests impossible. You do this by passing |
| 4409 |
the optional last argument to ‘AC_TRY_RUN’. ‘autoconf’ prints a warning |
| 4410 |
message when creating ‘configure’ each time it encounters a call to |
| 4411 |
‘AC_TRY_RUN’ with no ACTION-IF-CROSS-COMPILING argument given. You may |
| 4412 |
ignore the warning, though users will not be able to configure your |
| 4413 |
package for cross-compiling. A few of the macros distributed with |
| 4414 |
Autoconf produce this warning message. |
| 4415 |
|
| 4416 |
To configure for cross-compiling you can also choose a value for |
| 4417 |
those parameters based on the canonical system name (*note Manual |
| 4418 |
Configuration::). Alternatively, set up a test results cache file with |
| 4419 |
the correct values for the host system (*note Caching Results::). |
| 4420 |
|
| 4421 |
To provide a default for calls of ‘AC_TRY_RUN’ that are embedded in |
| 4422 |
other macros, including a few of the ones that come with Autoconf, you |
| 4423 |
can call ‘AC_PROG_CC’ before running them. Then, if the shell variable |
| 4424 |
‘cross_compiling’ is set to ‘yes’, use an alternate method to get the |
| 4425 |
results instead of calling the macros. |
| 4426 |
|
| 4427 |
|
| 4428 |
File: autoconf.info, Node: Guidelines, Next: Test Functions, Prev: Test Programs, Up: Run Time |
| 4429 |
|
| 4430 |
6.4.2 Guidelines for Test Programs |
| 4431 |
---------------------------------- |
| 4432 |
|
| 4433 |
Test programs should not write anything to the standard output. They |
| 4434 |
should return 0 if the test succeeds, nonzero otherwise, so that success |
| 4435 |
can be distinguished easily from a core dump or other failure; |
| 4436 |
segmentation violations and other failures produce a nonzero exit |
| 4437 |
status. Test programs should ‘exit’, not ‘return’, from ‘main’, because |
| 4438 |
on some systems (old Suns, at least) the argument to ‘return’ in ‘main’ |
| 4439 |
is ignored. |
| 4440 |
|
| 4441 |
Test programs can use ‘#if’ or ‘#ifdef’ to check the values of |
| 4442 |
preprocessor macros defined by tests that have already run. For |
| 4443 |
example, if you call ‘AC_HEADER_STDC’, then later on in ‘configure.ac’ |
| 4444 |
you can have a test program that includes an ANSI C header file |
| 4445 |
conditionally: |
| 4446 |
|
| 4447 |
#if STDC_HEADERS |
| 4448 |
# include <stdlib.h> |
| 4449 |
#endif |
| 4450 |
|
| 4451 |
If a test program needs to use or create a data file, give it a name |
| 4452 |
that starts with ‘conftest’, such as ‘conftest.data’. The ‘configure’ |
| 4453 |
script cleans up by running ‘rm -rf conftest*’ after running test |
| 4454 |
programs and if the script is interrupted. |
| 4455 |
|
| 4456 |
|
| 4457 |
File: autoconf.info, Node: Test Functions, Prev: Guidelines, Up: Run Time |
| 4458 |
|
| 4459 |
6.4.3 Test Functions |
| 4460 |
-------------------- |
| 4461 |
|
| 4462 |
Function declarations in test programs should have a prototype |
| 4463 |
conditionalized for C++. In practice, though, test programs rarely need |
| 4464 |
functions that take arguments. |
| 4465 |
|
| 4466 |
#ifdef __cplusplus |
| 4467 |
foo (int i) |
| 4468 |
#else |
| 4469 |
foo (i) int i; |
| 4470 |
#endif |
| 4471 |
|
| 4472 |
Functions that test programs declare should also be conditionalized |
| 4473 |
for C++, which requires ‘extern "C"’ prototypes. Make sure to not |
| 4474 |
include any header files containing clashing prototypes. |
| 4475 |
|
| 4476 |
#ifdef __cplusplus |
| 4477 |
extern "C" void *malloc (size_t); |
| 4478 |
#else |
| 4479 |
char *malloc (); |
| 4480 |
#endif |
| 4481 |
|
| 4482 |
If a test program calls a function with invalid parameters (just to |
| 4483 |
see whether it exists), organize the program to ensure that it never |
| 4484 |
invokes that function. You can do this by calling it in another |
| 4485 |
function that is never invoked. You can't do it by putting it after a |
| 4486 |
call to ‘exit’, because GCC version 2 knows that ‘exit’ never returns |
| 4487 |
and optimizes out any code that follows it in the same block. |
| 4488 |
|
| 4489 |
If you include any header files, make sure to call the functions |
| 4490 |
relevant to them with the correct number of arguments, even if they are |
| 4491 |
just 0, to avoid compilation errors due to prototypes. GCC version 2 |
| 4492 |
has internal prototypes for several functions that it automatically |
| 4493 |
inlines; for example, ‘memcpy’. To avoid errors when checking for them, |
| 4494 |
either pass them the correct number of arguments or redeclare them with |
| 4495 |
a different return type (such as ‘char’). |
| 4496 |
|
| 4497 |
|
| 4498 |
File: autoconf.info, Node: Systemology, Next: Multiple Cases, Prev: Run Time, Up: Writing Tests |
| 4499 |
|
| 4500 |
6.5 Systemology |
| 4501 |
=============== |
| 4502 |
|
| 4503 |
This section aims at presenting some systems and pointers to |
| 4504 |
documentation. It may help you addressing particular problems reported |
| 4505 |
by users. |
| 4506 |
|
| 4507 |
QNX 4.25 |
| 4508 |
QNX is a realtime operating system running on Intel architecture |
| 4509 |
meant to be scalable from the small embedded systems to hundred |
| 4510 |
processor super-computer. It claims to be POSIX certified. More |
| 4511 |
information is available on the QNX home page(1), including the QNX |
| 4512 |
man pages(2). |
| 4513 |
|
| 4514 |
---------- Footnotes ---------- |
| 4515 |
|
| 4516 |
(1) QNX home page, <www.qnx.com>. |
| 4517 |
|
| 4518 |
(2) QNX man pages, <http://support.qnx.com/support/docs/qnx4/>. |
| 4519 |
|
| 4520 |
|
| 4521 |
File: autoconf.info, Node: Multiple Cases, Next: Language Choice, Prev: Systemology, Up: Writing Tests |
| 4522 |
|
| 4523 |
6.6 Multiple Cases |
| 4524 |
================== |
| 4525 |
|
| 4526 |
Some operations are accomplished in several possible ways, depending on |
| 4527 |
the UNIX variant. Checking for them essentially requires a "case |
| 4528 |
statement". Autoconf does not directly provide one; however, it is easy |
| 4529 |
to simulate by using a shell variable to keep track of whether a way to |
| 4530 |
perform the operation has been found yet. |
| 4531 |
|
| 4532 |
Here is an example that uses the shell variable ‘fstype’ to keep |
| 4533 |
track of whether the remaining cases need to be checked. |
| 4534 |
|
| 4535 |
AC_MSG_CHECKING([how to get file system type]) |
| 4536 |
fstype=no |
| 4537 |
# The order of these tests is important. |
| 4538 |
AC_TRY_CPP([#include <sys/statvfs.h> |
| 4539 |
#include <sys/fstyp.h>], |
| 4540 |
[AC_DEFINE(FSTYPE_STATVFS) fstype=SVR4]) |
| 4541 |
if test $fstype = no; then |
| 4542 |
AC_TRY_CPP([#include <sys/statfs.h> |
| 4543 |
#include <sys/fstyp.h>], |
| 4544 |
[AC_DEFINE(FSTYPE_USG_STATFS) fstype=SVR3]) |
| 4545 |
fi |
| 4546 |
if test $fstype = no; then |
| 4547 |
AC_TRY_CPP([#include <sys/statfs.h> |
| 4548 |
#include <sys/vmount.h>], |
| 4549 |
[AC_DEFINE(FSTYPE_AIX_STATFS) fstype=AIX]) |
| 4550 |
fi |
| 4551 |
# (more cases omitted here) |
| 4552 |
AC_MSG_RESULT([$fstype]) |
| 4553 |
|
| 4554 |
|
| 4555 |
File: autoconf.info, Node: Language Choice, Prev: Multiple Cases, Up: Writing Tests |
| 4556 |
|
| 4557 |
6.7 Language Choice |
| 4558 |
=================== |
| 4559 |
|
| 4560 |
Autoconf-generated ‘configure’ scripts check for the C compiler and its |
| 4561 |
features by default. Packages that use other programming languages |
| 4562 |
(maybe more than one, e.g. C and C++) need to test features of the |
| 4563 |
compilers for the respective languages. The following macros determine |
| 4564 |
which programming language is used in the subsequent tests in |
| 4565 |
‘configure.ac’. |
| 4566 |
|
| 4567 |
-- Macro: AC_LANG (LANGUAGE) |
| 4568 |
Do compilation tests using the compiler, preprocessor and file |
| 4569 |
extensions for the specified LANGUAGE. |
| 4570 |
|
| 4571 |
Supported languages are: |
| 4572 |
|
| 4573 |
‘C’ |
| 4574 |
Do compilation tests using ‘CC’ and ‘CPP’ and use extension |
| 4575 |
‘.c’ for test programs. |
| 4576 |
|
| 4577 |
‘C++’ |
| 4578 |
Do compilation tests using ‘CXX’ and ‘CXXCPP’ and use |
| 4579 |
extension ‘.C’ for test programs. |
| 4580 |
|
| 4581 |
‘Fortran 77’ |
| 4582 |
Do compilation tests using ‘F77’ and use extension ‘.f’ for |
| 4583 |
test programs. |
| 4584 |
|
| 4585 |
-- Macro: AC_LANG_PUSH (LANGUAGE) |
| 4586 |
Remember the current language (as set by ‘AC_LANG’) on a stack, and |
| 4587 |
then select the LANGUAGE. Use this macro and ‘AC_LANG_POP’ in |
| 4588 |
macros that need to temporarily switch to a particular language. |
| 4589 |
|
| 4590 |
-- Macro: AC_LANG_POP ([LANGUAGE]) |
| 4591 |
Select the language that is saved on the top of the stack, as set |
| 4592 |
by ‘AC_LANG_PUSH’, and remove it from the stack. |
| 4593 |
|
| 4594 |
If given, LANGUAGE specifies the language we just _quit_. It is a |
| 4595 |
good idea to specify it when it's known (which should be the |
| 4596 |
case...), since Autoconf will detect inconsistencies. |
| 4597 |
|
| 4598 |
AC_LANG_PUSH(Fortran 77) |
| 4599 |
# Perform some tests on Fortran 77. |
| 4600 |
# ... |
| 4601 |
AC_LANG_POP(Fortran 77) |
| 4602 |
|
| 4603 |
-- Macro: AC_REQUIRE_CPP |
| 4604 |
Ensure that whichever preprocessor would currently be used for |
| 4605 |
tests has been found. Calls ‘AC_REQUIRE’ (*note Prerequisite |
| 4606 |
Macros::) with an argument of either ‘AC_PROG_CPP’ or |
| 4607 |
‘AC_PROG_CXXCPP’, depending on which language is current. |
| 4608 |
|
| 4609 |
|
| 4610 |
File: autoconf.info, Node: Results, Next: Programming in M4, Prev: Writing Tests, Up: Top |
| 4611 |
|
| 4612 |
7 Results of Tests |
| 4613 |
****************** |
| 4614 |
|
| 4615 |
Once ‘configure’ has determined whether a feature exists, what can it do |
| 4616 |
to record that information? There are four sorts of things it can do: |
| 4617 |
define a C preprocessor symbol, set a variable in the output files, save |
| 4618 |
the result in a cache file for future ‘configure’ runs, and print a |
| 4619 |
message letting the user know the result of the test. |
| 4620 |
|
| 4621 |
* Menu: |
| 4622 |
|
| 4623 |
* Defining Symbols:: Defining C preprocessor symbols |
| 4624 |
* Setting Output Variables:: Replacing variables in output files |
| 4625 |
* Caching Results:: Speeding up subsequent ‘configure’ runs |
| 4626 |
* Printing Messages:: Notifying ‘configure’ users |
| 4627 |
|
| 4628 |
|
| 4629 |
File: autoconf.info, Node: Defining Symbols, Next: Setting Output Variables, Prev: Results, Up: Results |
| 4630 |
|
| 4631 |
7.1 Defining C Preprocessor Symbols |
| 4632 |
=================================== |
| 4633 |
|
| 4634 |
A common action to take in response to a feature test is to define a C |
| 4635 |
preprocessor symbol indicating the results of the test. That is done by |
| 4636 |
calling ‘AC_DEFINE’ or ‘AC_DEFINE_UNQUOTED’. |
| 4637 |
|
| 4638 |
By default, ‘AC_OUTPUT’ places the symbols defined by these macros |
| 4639 |
into the output variable ‘DEFS’, which contains an option |
| 4640 |
‘-DSYMBOL=VALUE’ for each symbol defined. Unlike in Autoconf version 1, |
| 4641 |
there is no variable ‘DEFS’ defined while ‘configure’ is running. To |
| 4642 |
check whether Autoconf macros have already defined a certain C |
| 4643 |
preprocessor symbol, test the value of the appropriate cache variable, |
| 4644 |
as in this example: |
| 4645 |
|
| 4646 |
AC_CHECK_FUNC(vprintf, [AC_DEFINE(HAVE_VPRINTF)]) |
| 4647 |
if test "$ac_cv_func_vprintf" != yes; then |
| 4648 |
AC_CHECK_FUNC(_doprnt, [AC_DEFINE(HAVE_DOPRNT)]) |
| 4649 |
fi |
| 4650 |
|
| 4651 |
If ‘AC_CONFIG_HEADERS’ has been called, then instead of creating |
| 4652 |
‘DEFS’, ‘AC_OUTPUT’ creates a header file by substituting the correct |
| 4653 |
values into ‘#define’ statements in a template file. *Note |
| 4654 |
Configuration Headers::, for more information about this kind of output. |
| 4655 |
|
| 4656 |
-- Macro: AC_DEFINE (VARIABLE, [VALUE], [DESCRIPTION]) |
| 4657 |
Define C preprocessor variable VARIABLE. If VALUE is given, set |
| 4658 |
VARIABLE to that value (verbatim), otherwise set it to 1. VALUE |
| 4659 |
should not contain literal newlines, and if you are not using |
| 4660 |
‘AC_CONFIG_HEADERS’ it should not contain any ‘#’ characters, as |
| 4661 |
‘make’ tends to eat them. To use a shell variable (which you need |
| 4662 |
to do in order to define a value containing the M4 quote characters |
| 4663 |
‘[’ or ‘]’), use ‘AC_DEFINE_UNQUOTED’ instead. DESCRIPTION is only |
| 4664 |
useful if you are using ‘AC_CONFIG_HEADERS’. In this case, |
| 4665 |
DESCRIPTION is put into the generated ‘config.h.in’ as the comment |
| 4666 |
before the macro define. The following example defines the C |
| 4667 |
preprocessor variable ‘EQUATION’ to be the string constant ‘"$a > |
| 4668 |
$b"’: |
| 4669 |
|
| 4670 |
AC_DEFINE(EQUATION, "$a > $b") |
| 4671 |
|
| 4672 |
-- Macro: AC_DEFINE_UNQUOTED (VARIABLE, [VALUE], [DESCRIPTION]) |
| 4673 |
Like ‘AC_DEFINE’, but three shell expansions are |
| 4674 |
performed--once--on VARIABLE and VALUE: variable expansion (‘$’), |
| 4675 |
command substitution (‘`’), and backslash escaping (‘\’). Single |
| 4676 |
and double quote characters in the value have no special meaning. |
| 4677 |
Use this macro instead of ‘AC_DEFINE’ when VARIABLE or VALUE is a |
| 4678 |
shell variable. Examples: |
| 4679 |
|
| 4680 |
AC_DEFINE_UNQUOTED(config_machfile, "$machfile") |
| 4681 |
AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups) |
| 4682 |
AC_DEFINE_UNQUOTED($ac_tr_hdr) |
| 4683 |
|
| 4684 |
Due to the syntactical bizarreness of the Bourne shell, do not use |
| 4685 |
semicolons to separate ‘AC_DEFINE’ or ‘AC_DEFINE_UNQUOTED’ calls from |
| 4686 |
other macro calls or shell code; that can cause syntax errors in the |
| 4687 |
resulting ‘configure’ script. Use either spaces or newlines. That is, |
| 4688 |
do this: |
| 4689 |
|
| 4690 |
AC_CHECK_HEADER(elf.h, [AC_DEFINE(SVR4) LIBS="$LIBS -lelf"]) |
| 4691 |
|
| 4692 |
or this: |
| 4693 |
|
| 4694 |
AC_CHECK_HEADER(elf.h, |
| 4695 |
[AC_DEFINE(SVR4) |
| 4696 |
LIBS="$LIBS -lelf"]) |
| 4697 |
|
| 4698 |
instead of this: |
| 4699 |
|
| 4700 |
AC_CHECK_HEADER(elf.h, [AC_DEFINE(SVR4); LIBS="$LIBS -lelf"]) |
| 4701 |
|
| 4702 |
|
| 4703 |
File: autoconf.info, Node: Setting Output Variables, Next: Caching Results, Prev: Defining Symbols, Up: Results |
| 4704 |
|
| 4705 |
7.2 Setting Output Variables |
| 4706 |
============================ |
| 4707 |
|
| 4708 |
Another way to record the results of tests is to set “output variables”, |
| 4709 |
which are shell variables whose values are substituted into files that |
| 4710 |
‘configure’ outputs. The two macros below create new output variables. |
| 4711 |
*Note Preset Output Variables::, for a list of output variables that are |
| 4712 |
always available. |
| 4713 |
|
| 4714 |
-- Macro: AC_SUBST (VARIABLE, [VALUE]) |
| 4715 |
Create an output variable from a shell variable. Make ‘AC_OUTPUT’ |
| 4716 |
substitute the variable VARIABLE into output files (typically one |
| 4717 |
or more ‘Makefile’s). This means that ‘AC_OUTPUT’ will replace |
| 4718 |
instances of ‘@VARIABLE@’ in input files with the value that the |
| 4719 |
shell variable VARIABLE has when ‘AC_OUTPUT’ is called. This value |
| 4720 |
of VARIABLE should not contain literal newlines. |
| 4721 |
|
| 4722 |
If VALUE is given, in addition assign it to ‘variable’. |
| 4723 |
|
| 4724 |
-- Macro: AC_SUBST_FILE (VARIABLE) |
| 4725 |
Another way to create an output variable from a shell variable. |
| 4726 |
Make ‘AC_OUTPUT’ insert (without substitutions) the contents of the |
| 4727 |
file named by shell variable VARIABLE into output files. This |
| 4728 |
means that ‘AC_OUTPUT’ will replace instances of ‘@VARIABLE@’ in |
| 4729 |
output files (such as ‘Makefile.in’) with the contents of the file |
| 4730 |
that the shell variable VARIABLE names when ‘AC_OUTPUT’ is called. |
| 4731 |
Set the variable to ‘/dev/null’ for cases that do not have a file |
| 4732 |
to insert. |
| 4733 |
|
| 4734 |
This macro is useful for inserting ‘Makefile’ fragments containing |
| 4735 |
special dependencies or other ‘make’ directives for particular host |
| 4736 |
or target types into ‘Makefile’s. For example, ‘configure.ac’ |
| 4737 |
could contain: |
| 4738 |
|
| 4739 |
AC_SUBST_FILE(host_frag) |
| 4740 |
host_frag=$srcdir/conf/sun4.mh |
| 4741 |
|
| 4742 |
and then a ‘Makefile.in’ could contain: |
| 4743 |
|
| 4744 |
@host_frag@ |
| 4745 |
|
| 4746 |
Running ‘configure’ in different environments can be extremely |
| 4747 |
dangerous. If for instance the user runs ‘CC=bizarre-cc ./configure’, |
| 4748 |
then the cache, ‘config.h’ and many other output files will depend upon |
| 4749 |
‘bizarre-cc’ being the C compiler. If for some reason the user runs |
| 4750 |
‘/configure’ again, or if it is run via ‘./config.status --recheck’, |
| 4751 |
(*Note Automatic Remaking::, and *note config.status Invocation::), then |
| 4752 |
the configuration can be inconsistent, composed of results depending |
| 4753 |
upon two different compilers. |
| 4754 |
|
| 4755 |
Such variables are named “precious variables”, and can be declared as |
| 4756 |
such by ‘AC_ARG_VAR’. |
| 4757 |
|
| 4758 |
-- Macro: AC_ARG_VAR (VARIABLE, DESCRIPTION) |
| 4759 |
Declare VARIABLE is a precious variable, and include its |
| 4760 |
DESCRIPTION in the variable section of ‘./configure --help’. |
| 4761 |
|
| 4762 |
Being precious means that |
| 4763 |
− VARIABLE is ‘AC_SUBST’'d. |
| 4764 |
|
| 4765 |
− VARIABLE is kept in the cache including if it was not |
| 4766 |
specified on the ‘./configure’ command line. Indeed, while |
| 4767 |
‘configure’ can notice the definition of ‘CC’ in ‘./configure |
| 4768 |
CC=bizarre-cc’, it is impossible to notice it in |
| 4769 |
‘CC=bizarre-cc ./configure’, which, unfortunately, is what |
| 4770 |
most users do. |
| 4771 |
|
| 4772 |
− VARIABLE is checked for consistency between two ‘configure’ |
| 4773 |
runs. For instance: |
| 4774 |
|
| 4775 |
$ ./configure --silent --config-cache |
| 4776 |
$ CC=cc ./configure --silent --config-cache |
| 4777 |
configure: error: `CC' was not set in the previous run |
| 4778 |
configure: error: changes in the environment can compromise \ |
| 4779 |
the build |
| 4780 |
configure: error: run `make distclean' and/or \ |
| 4781 |
`rm config.cache' and start over |
| 4782 |
|
| 4783 |
and similarly if the variable is unset, or if its content is |
| 4784 |
changed. |
| 4785 |
|
| 4786 |
− VARIABLE is kept during automatic reconfiguration (*note |
| 4787 |
config.status Invocation::) as if it had been passed as a |
| 4788 |
command line argument, including when no cache is used: |
| 4789 |
|
| 4790 |
$ CC=/usr/bin/cc ./configure undeclared_var=raboof --silent |
| 4791 |
$ ./config.status --recheck |
| 4792 |
running /bin/sh ./configure undeclared_var=raboof --silent \ |
| 4793 |
CC=/usr/bin/cc --no-create --no-recursion |
| 4794 |
|
| 4795 |
|
| 4796 |
File: autoconf.info, Node: Caching Results, Next: Printing Messages, Prev: Setting Output Variables, Up: Results |
| 4797 |
|
| 4798 |
7.3 Caching Results |
| 4799 |
=================== |
| 4800 |
|
| 4801 |
To avoid checking for the same features repeatedly in various |
| 4802 |
‘configure’ scripts (or in repeated runs of one script), ‘configure’ can |
| 4803 |
optionally save the results of many checks in a “cache file” (*note |
| 4804 |
Cache Files::). If a ‘configure’ script runs with caching enabled and |
| 4805 |
finds a cache file, it reads the results of previous runs from the cache |
| 4806 |
and avoids rerunning those checks. As a result, ‘configure’ can then |
| 4807 |
run much faster than if it had to perform all of the checks every time. |
| 4808 |
|
| 4809 |
-- Macro: AC_CACHE_VAL (CACHE-ID, COMMANDS-TO-SET-IT) |
| 4810 |
Ensure that the results of the check identified by CACHE-ID are |
| 4811 |
available. If the results of the check were in the cache file that |
| 4812 |
was read, and ‘configure’ was not given the ‘--quiet’ or ‘--silent’ |
| 4813 |
option, print a message saying that the result was cached; |
| 4814 |
otherwise, run the shell commands COMMANDS-TO-SET-IT. If the shell |
| 4815 |
commands are run to determine the value, the value will be saved in |
| 4816 |
the cache file just before ‘configure’ creates its output files. |
| 4817 |
*Note Cache Variable Names::, for how to choose the name of the |
| 4818 |
CACHE-ID variable. |
| 4819 |
|
| 4820 |
The COMMANDS-TO-SET-IT _must have no side effects_ except for |
| 4821 |
setting the variable CACHE-ID, see below. |
| 4822 |
|
| 4823 |
-- Macro: AC_CACHE_CHECK (MESSAGE, CACHE-ID, COMMANDS-TO-SET-IT) |
| 4824 |
A wrapper for ‘AC_CACHE_VAL’ that takes care of printing the |
| 4825 |
messages. This macro provides a convenient shorthand for the most |
| 4826 |
common way to use these macros. It calls ‘AC_MSG_CHECKING’ for |
| 4827 |
MESSAGE, then ‘AC_CACHE_VAL’ with the CACHE-ID and COMMANDS |
| 4828 |
arguments, and ‘AC_MSG_RESULT’ with CACHE-ID. |
| 4829 |
|
| 4830 |
The COMMANDS-TO-SET-IT _must have no side effects_ except for |
| 4831 |
setting the variable CACHE-ID, see below. |
| 4832 |
|
| 4833 |
It is very common to find buggy macros using ‘AC_CACHE_VAL’ or |
| 4834 |
‘AC_CACHE_CHECK’, because people are tempted to call ‘AC_DEFINE’ in the |
| 4835 |
COMMANDS-TO-SET-IT. Instead, the code that _follows_ the call to |
| 4836 |
‘AC_CACHE_VAL’ should call ‘AC_DEFINE’, by examining the value of the |
| 4837 |
cache variable. For instance, the following macro is broken: |
| 4838 |
|
| 4839 |
AC_DEFUN([AC_SHELL_TRUE], |
| 4840 |
[AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works], |
| 4841 |
[ac_cv_shell_true_works=no |
| 4842 |
true && ac_cv_shell_true_works=yes |
| 4843 |
if test $ac_cv_shell_true_works = yes; then |
| 4844 |
AC_DEFINE([TRUE_WORKS], 1 |
| 4845 |
[Define if `true(1)' works properly.]) |
| 4846 |
fi]) |
| 4847 |
]) |
| 4848 |
|
| 4849 |
This fails if the cache is enabled: the second time this macro is run, |
| 4850 |
‘TRUE_WORKS’ _will not be defined_. The proper implementation is: |
| 4851 |
|
| 4852 |
AC_DEFUN([AC_SHELL_TRUE], |
| 4853 |
[AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works], |
| 4854 |
[ac_cv_shell_true_works=no |
| 4855 |
true && ac_cv_shell_true_works=yes]) |
| 4856 |
if test $ac_cv_shell_true_works = yes; then |
| 4857 |
AC_DEFINE([TRUE_WORKS], 1 |
| 4858 |
[Define if `true(1)' works properly.]) |
| 4859 |
fi |
| 4860 |
]) |
| 4861 |
|
| 4862 |
Also, COMMANDS-TO-SET-IT should not print any messages, for example |
| 4863 |
with ‘AC_MSG_CHECKING’; do that before calling ‘AC_CACHE_VAL’, so the |
| 4864 |
messages are printed regardless of whether the results of the check are |
| 4865 |
retrieved from the cache or determined by running the shell commands. |
| 4866 |
|
| 4867 |
* Menu: |
| 4868 |
|
| 4869 |
* Cache Variable Names:: Shell variables used in caches |
| 4870 |
* Cache Files:: Files ‘configure’ uses for caching |
| 4871 |
* Cache Checkpointing:: Loading and saving the cache file |
| 4872 |
|
| 4873 |
|
| 4874 |
File: autoconf.info, Node: Cache Variable Names, Next: Cache Files, Prev: Caching Results, Up: Caching Results |
| 4875 |
|
| 4876 |
7.3.1 Cache Variable Names |
| 4877 |
-------------------------- |
| 4878 |
|
| 4879 |
The names of cache variables should have the following format: |
| 4880 |
|
| 4881 |
PACKAGE-PREFIX_cv_VALUE-TYPE_SPECIFIC-VALUE_[ADDITIONAL-OPTIONS] |
| 4882 |
|
| 4883 |
for example, ‘ac_cv_header_stat_broken’ or ‘ac_cv_prog_gcc_traditional’. |
| 4884 |
The parts of the variable name are: |
| 4885 |
|
| 4886 |
PACKAGE-PREFIX |
| 4887 |
An abbreviation for your package or organization; the same prefix |
| 4888 |
you begin local Autoconf macros with, except lowercase by |
| 4889 |
convention. For cache values used by the distributed Autoconf |
| 4890 |
macros, this value is ‘ac’. |
| 4891 |
|
| 4892 |
‘_cv_’ |
| 4893 |
Indicates that this shell variable is a cache value. This string |
| 4894 |
_must_ be present in the variable name, including the leading |
| 4895 |
underscore. |
| 4896 |
|
| 4897 |
VALUE-TYPE |
| 4898 |
A convention for classifying cache values, to produce a rational |
| 4899 |
naming system. The values used in Autoconf are listed in *note |
| 4900 |
Macro Names::. |
| 4901 |
|
| 4902 |
SPECIFIC-VALUE |
| 4903 |
Which member of the class of cache values this test applies to. |
| 4904 |
For example, which function (‘alloca’), program (‘gcc’), or output |
| 4905 |
variable (‘INSTALL’). |
| 4906 |
|
| 4907 |
ADDITIONAL-OPTIONS |
| 4908 |
Any particular behavior of the specific member that this test |
| 4909 |
applies to. For example, ‘broken’ or ‘set’. This part of the name |
| 4910 |
may be omitted if it does not apply. |
| 4911 |
|
| 4912 |
The values assigned to cache variables may not contain newlines. |
| 4913 |
Usually, their values will be boolean (‘yes’ or ‘no’) or the names of |
| 4914 |
files or functions; so this is not an important restriction. |
| 4915 |
|
| 4916 |
|
| 4917 |
File: autoconf.info, Node: Cache Files, Next: Cache Checkpointing, Prev: Cache Variable Names, Up: Caching Results |
| 4918 |
|
| 4919 |
7.3.2 Cache Files |
| 4920 |
----------------- |
| 4921 |
|
| 4922 |
A cache file is a shell script that caches the results of configure |
| 4923 |
tests run on one system so they can be shared between configure scripts |
| 4924 |
and configure runs. It is not useful on other systems. If its contents |
| 4925 |
are invalid for some reason, the user may delete or edit it. |
| 4926 |
|
| 4927 |
By default, ‘configure’ uses no cache file (technically, it uses |
| 4928 |
‘--cache-file=/dev/null’), to avoid problems caused by accidental use of |
| 4929 |
stale cache files. |
| 4930 |
|
| 4931 |
To enable caching, ‘configure’ accepts ‘--config-cache’ (or ‘-C’) to |
| 4932 |
cache results in the file ‘config.cache’. Alternatively, |
| 4933 |
‘--cache-file=FILE’ specifies that FILE be the cache file. The cache |
| 4934 |
file is created if it does not exist already. When ‘configure’ calls |
| 4935 |
‘configure’ scripts in subdirectories, it uses the ‘--cache-file’ |
| 4936 |
argument so that they share the same cache. *Note Subdirectories::, for |
| 4937 |
information on configuring subdirectories with the ‘AC_CONFIG_SUBDIRS’ |
| 4938 |
macro. |
| 4939 |
|
| 4940 |
‘config.status’ only pays attention to the cache file if it is given |
| 4941 |
the ‘--recheck’ option, which makes it rerun ‘configure’. |
| 4942 |
|
| 4943 |
It is wrong to try to distribute cache files for particular system |
| 4944 |
types. There is too much room for error in doing that, and too much |
| 4945 |
administrative overhead in maintaining them. For any features that |
| 4946 |
can't be guessed automatically, use the standard method of the canonical |
| 4947 |
system type and linking files (*note Manual Configuration::). |
| 4948 |
|
| 4949 |
The site initialization script can specify a site-wide cache file to |
| 4950 |
use, instead of the usual per-program cache. In this case, the cache |
| 4951 |
file will gradually accumulate information whenever someone runs a new |
| 4952 |
‘configure’ script. (Running ‘configure’ merges the new cache results |
| 4953 |
with the existing cache file.) This may cause problems, however, if the |
| 4954 |
system configuration (e.g. the installed libraries or compilers) |
| 4955 |
changes and the stale cache file is not deleted. |
| 4956 |
|
| 4957 |
|
| 4958 |
File: autoconf.info, Node: Cache Checkpointing, Prev: Cache Files, Up: Caching Results |
| 4959 |
|
| 4960 |
7.3.3 Cache Checkpointing |
| 4961 |
------------------------- |
| 4962 |
|
| 4963 |
If your configure script, or a macro called from configure.ac, happens |
| 4964 |
to abort the configure process, it may be useful to checkpoint the cache |
| 4965 |
a few times at key points using ‘AC_CACHE_SAVE’. Doing so will reduce |
| 4966 |
the amount of time it takes to re-run the configure script with |
| 4967 |
(hopefully) the error that caused the previous abort corrected. |
| 4968 |
|
| 4969 |
-- Macro: AC_CACHE_LOAD |
| 4970 |
Loads values from existing cache file, or creates a new cache file |
| 4971 |
if a cache file is not found. Called automatically from ‘AC_INIT’. |
| 4972 |
|
| 4973 |
-- Macro: AC_CACHE_SAVE |
| 4974 |
Flushes all cached values to the cache file. Called automatically |
| 4975 |
from ‘AC_OUTPUT’, but it can be quite useful to call |
| 4976 |
‘AC_CACHE_SAVE’ at key points in configure.ac. |
| 4977 |
|
| 4978 |
For instance: |
| 4979 |
|
| 4980 |
... AC_INIT, etc. ... |
| 4981 |
# Checks for programs. |
| 4982 |
AC_PROG_CC |
| 4983 |
AC_PROG_GCC_TRADITIONAL |
| 4984 |
... more program checks ... |
| 4985 |
AC_CACHE_SAVE |
| 4986 |
|
| 4987 |
# Checks for libraries. |
| 4988 |
AC_CHECK_LIB(nsl, gethostbyname) |
| 4989 |
AC_CHECK_LIB(socket, connect) |
| 4990 |
... more lib checks ... |
| 4991 |
AC_CACHE_SAVE |
| 4992 |
|
| 4993 |
# Might abort... |
| 4994 |
AM_PATH_GTK(1.0.2,, (exit 1); exit) |
| 4995 |
AM_PATH_GTKMM(0.9.5,, (exit 1); exit) |
| 4996 |
... AC_OUTPUT, etc. ... |
| 4997 |
|
| 4998 |
|
| 4999 |
File: autoconf.info, Node: Printing Messages, Prev: Caching Results, Up: Results |
| 5000 |
|
| 5001 |
7.4 Printing Messages |
| 5002 |
===================== |
| 5003 |
|
| 5004 |
‘configure’ scripts need to give users running them several kinds of |
| 5005 |
information. The following macros print messages in ways appropriate |
| 5006 |
for each kind. The arguments to all of them get enclosed in shell |
| 5007 |
double quotes, so the shell performs variable and back-quote |
| 5008 |
substitution on them. |
| 5009 |
|
| 5010 |
These macros are all wrappers around the ‘echo’ shell command. |
| 5011 |
‘configure’ scripts should rarely need to run ‘echo’ directly to print |
| 5012 |
messages for the user. Using these macros makes it easy to change how |
| 5013 |
and when each kind of message is printed; such changes need only be made |
| 5014 |
to the macro definitions and all of the callers will change |
| 5015 |
automatically. |
| 5016 |
|
| 5017 |
To diagnose static issues, i.e., when ‘autoconf’ is run, see *note |
| 5018 |
Reporting Messages::. |
| 5019 |
|
| 5020 |
-- Macro: AC_MSG_CHECKING (FEATURE-DESCRIPTION) |
| 5021 |
Notify the user that ‘configure’ is checking for a particular |
| 5022 |
feature. This macro prints a message that starts with ‘checking ’ |
| 5023 |
and ends with ‘...’ and no newline. It must be followed by a call |
| 5024 |
to ‘AC_MSG_RESULT’ to print the result of the check and the |
| 5025 |
newline. The FEATURE-DESCRIPTION should be something like ‘whether |
| 5026 |
the Fortran compiler accepts C++ comments’ or ‘for c89’. |
| 5027 |
|
| 5028 |
This macro prints nothing if ‘configure’ is run with the ‘--quiet’ |
| 5029 |
or ‘--silent’ option. |
| 5030 |
|
| 5031 |
-- Macro: AC_MSG_RESULT (RESULT-DESCRIPTION) |
| 5032 |
Notify the user of the results of a check. RESULT-DESCRIPTION is |
| 5033 |
almost always the value of the cache variable for the check, |
| 5034 |
typically ‘yes’, ‘no’, or a file name. This macro should follow a |
| 5035 |
call to ‘AC_MSG_CHECKING’, and the RESULT-DESCRIPTION should be the |
| 5036 |
completion of the message printed by the call to ‘AC_MSG_CHECKING’. |
| 5037 |
|
| 5038 |
This macro prints nothing if ‘configure’ is run with the ‘--quiet’ |
| 5039 |
or ‘--silent’ option. |
| 5040 |
|
| 5041 |
-- Macro: AC_MSG_NOTICE (MESSAGE) |
| 5042 |
Deliver the MESSAGE to the user. It is useful mainly to print a |
| 5043 |
general description of the overall purpose of a group of feature |
| 5044 |
checks, e.g., |
| 5045 |
|
| 5046 |
AC_MSG_NOTICE([checking if stack overflow is detectable]) |
| 5047 |
|
| 5048 |
This macro prints nothing if ‘configure’ is run with the ‘--quiet’ |
| 5049 |
or ‘--silent’ option. |
| 5050 |
|
| 5051 |
-- Macro: AC_MSG_ERROR (ERROR-DESCRIPTION, [EXIT-STATUS]) |
| 5052 |
Notify the user of an error that prevents ‘configure’ from |
| 5053 |
completing. This macro prints an error message to the standard |
| 5054 |
error output and exits ‘configure’ with EXIT-STATUS (1 by default). |
| 5055 |
ERROR-DESCRIPTION should be something like ‘invalid value $HOME for |
| 5056 |
\$HOME’. |
| 5057 |
|
| 5058 |
The ERROR-DESCRIPTION should start with a lower-case letter, and |
| 5059 |
"cannot" is preferred to "can't". |
| 5060 |
|
| 5061 |
-- Macro: AC_MSG_WARN (PROBLEM-DESCRIPTION) |
| 5062 |
Notify the ‘configure’ user of a possible problem. This macro |
| 5063 |
prints the message to the standard error output; ‘configure’ |
| 5064 |
continues running afterward, so macros that call ‘AC_MSG_WARN’ |
| 5065 |
should provide a default (back-up) behavior for the situations they |
| 5066 |
warn about. PROBLEM-DESCRIPTION should be something like ‘ln -s |
| 5067 |
seems to make hard links’. |
| 5068 |
|
| 5069 |
|
| 5070 |
File: autoconf.info, Node: Programming in M4, Next: Writing Autoconf Macros, Prev: Results, Up: Top |
| 5071 |
|
| 5072 |
8 Programming in M4 |
| 5073 |
******************* |
| 5074 |
|
| 5075 |
Autoconf is written on top of two layers: “M4sugar”, which provides |
| 5076 |
convenient macros for pure M4 programming, and “M4sh”, which provides |
| 5077 |
macros dedicated to shell script generation. |
| 5078 |
|
| 5079 |
As of this version of Autoconf, these two layers are still |
| 5080 |
experimental, and their interface might change in the future. As a |
| 5081 |
matter of fact, _anything that is not documented must not be used_. |
| 5082 |
|
| 5083 |
* Menu: |
| 5084 |
|
| 5085 |
* M4 Quotation:: Protecting macros from unwanted expansion |
| 5086 |
* Programming in M4sugar:: Convenient pure M4 macros |
| 5087 |
|
| 5088 |
|
| 5089 |
File: autoconf.info, Node: M4 Quotation, Next: Programming in M4sugar, Prev: Programming in M4, Up: Programming in M4 |
| 5090 |
|
| 5091 |
8.1 M4 Quotation |
| 5092 |
================ |
| 5093 |
|
| 5094 |
The most common brokenness of existing macros is an improper quotation. |
| 5095 |
This section, which users of Autoconf can skip, but which macro writers |
| 5096 |
_must_ read, first justifies the quotation scheme that was chosen for |
| 5097 |
Autoconf and then ends with a rule of thumb. Understanding the former |
| 5098 |
helps one to follow the latter. |
| 5099 |
|
| 5100 |
* Menu: |
| 5101 |
|
| 5102 |
* Active Characters:: Characters that change the behavior of m4 |
| 5103 |
* One Macro Call:: Quotation and one macro call |
| 5104 |
* Quotation and Nested Macros:: Macros calling macros |
| 5105 |
* Quadrigraphs:: Another way to escape special characters |
| 5106 |
* Quotation Rule Of Thumb:: One parenthesis, one quote |
| 5107 |
|
| 5108 |
|
| 5109 |
File: autoconf.info, Node: Active Characters, Next: One Macro Call, Prev: M4 Quotation, Up: M4 Quotation |
| 5110 |
|
| 5111 |
8.1.1 Active Characters |
| 5112 |
----------------------- |
| 5113 |
|
| 5114 |
To fully understand where proper quotation is important, you first need |
| 5115 |
to know what are the special characters in Autoconf: ‘#’ introduces a |
| 5116 |
comment inside which no macro expansion is performed, ‘,’ separates |
| 5117 |
arguments, ‘[’ and ‘]’ are the quotes themselves, and finally ‘(’ and |
| 5118 |
‘)’ (which ‘m4’ tries to match by pairs). |
| 5119 |
|
| 5120 |
In order to understand the delicate case of macro calls, we first |
| 5121 |
have to present some obvious failures. Below they are "obvious-ified", |
| 5122 |
although you find them in real life, they are usually in disguise. |
| 5123 |
|
| 5124 |
Comments, introduced by a hash and running up to the newline, are |
| 5125 |
opaque tokens to the top level: active characters are turned off, and |
| 5126 |
there is no macro expansion: |
| 5127 |
|
| 5128 |
# define([def], ine) |
| 5129 |
⇒# define([def], ine) |
| 5130 |
|
| 5131 |
Each time there can be a macro expansion, there is a quotation |
| 5132 |
expansion; i.e., one level of quotes is stripped: |
| 5133 |
|
| 5134 |
int tab[10]; |
| 5135 |
⇒int tab10; |
| 5136 |
[int tab[10];] |
| 5137 |
⇒int tab[10]; |
| 5138 |
|
| 5139 |
Without this in mind, the reader will try hopelessly to use her macro |
| 5140 |
‘array’: |
| 5141 |
|
| 5142 |
define([array], [int tab[10];]) |
| 5143 |
array |
| 5144 |
⇒int tab10; |
| 5145 |
[array] |
| 5146 |
⇒array |
| 5147 |
|
| 5148 |
How can you correctly output the intended results(1)? |
| 5149 |
|
| 5150 |
---------- Footnotes ---------- |
| 5151 |
|
| 5152 |
(1) Using ‘defn’. |
| 5153 |
|
| 5154 |
|
| 5155 |
File: autoconf.info, Node: One Macro Call, Next: Quotation and Nested Macros, Prev: Active Characters, Up: M4 Quotation |
| 5156 |
|
| 5157 |
8.1.2 One Macro Call |
| 5158 |
-------------------- |
| 5159 |
|
| 5160 |
Let's proceed on the interaction between active characters and macros |
| 5161 |
with this small macro, which just returns its first argument: |
| 5162 |
|
| 5163 |
define([car], [$1]) |
| 5164 |
|
| 5165 |
The two pairs of quotes above are not part of the arguments of ‘define’; |
| 5166 |
rather, they are understood by the top level when it tries to find the |
| 5167 |
arguments of ‘define’. Therefore, it is equivalent to write: |
| 5168 |
|
| 5169 |
define(car, $1) |
| 5170 |
|
| 5171 |
But, while it is acceptable for a ‘configure.ac’ to avoid unneeded |
| 5172 |
quotes, it is bad practice for Autoconf macros which must both be more |
| 5173 |
robust and also advocate perfect style. |
| 5174 |
|
| 5175 |
At the top level, there are only two possible quotings: either you |
| 5176 |
quote or you don't: |
| 5177 |
|
| 5178 |
car(foo, bar, baz) |
| 5179 |
⇒foo |
| 5180 |
[car(foo, bar, baz)] |
| 5181 |
⇒car(foo, bar, baz) |
| 5182 |
|
| 5183 |
Let's pay attention to the special characters: |
| 5184 |
|
| 5185 |
car(#) |
| 5186 |
error→EOF in argument list |
| 5187 |
|
| 5188 |
The closing parenthesis is hidden in the comment; with a hypothetical |
| 5189 |
quoting, the top level understood it this way: |
| 5190 |
|
| 5191 |
car([#)] |
| 5192 |
|
| 5193 |
Proper quotation, of course, fixes the problem: |
| 5194 |
|
| 5195 |
car([#]) |
| 5196 |
⇒# |
| 5197 |
|
| 5198 |
The reader will easily understand the following examples: |
| 5199 |
|
| 5200 |
car(foo, bar) |
| 5201 |
⇒foo |
| 5202 |
car([foo, bar]) |
| 5203 |
⇒foo, bar |
| 5204 |
car((foo, bar)) |
| 5205 |
⇒(foo, bar) |
| 5206 |
car([(foo], [bar)]) |
| 5207 |
⇒(foo |
| 5208 |
car([], []) |
| 5209 |
⇒ |
| 5210 |
car([[]], [[]]) |
| 5211 |
⇒[] |
| 5212 |
|
| 5213 |
With this in mind, we can explore the cases where macros invoke |
| 5214 |
macros... |
| 5215 |
|
| 5216 |
|
| 5217 |
File: autoconf.info, Node: Quotation and Nested Macros, Next: Quadrigraphs, Prev: One Macro Call, Up: M4 Quotation |
| 5218 |
|
| 5219 |
8.1.3 Quotation and Nested Macros |
| 5220 |
--------------------------------- |
| 5221 |
|
| 5222 |
The examples below use the following macros: |
| 5223 |
|
| 5224 |
define([car], [$1]) |
| 5225 |
define([active], [ACT, IVE]) |
| 5226 |
define([array], [int tab[10]]) |
| 5227 |
|
| 5228 |
Each additional embedded macro call introduces other possible |
| 5229 |
interesting quotations: |
| 5230 |
|
| 5231 |
car(active) |
| 5232 |
⇒ACT |
| 5233 |
car([active]) |
| 5234 |
⇒ACT, IVE |
| 5235 |
car([[active]]) |
| 5236 |
⇒active |
| 5237 |
|
| 5238 |
In the first case, the top level looks for the arguments of ‘car’, |
| 5239 |
and finds ‘active’. Because ‘m4’ evaluates its arguments before |
| 5240 |
applying the macro, ‘active’ is expanded, which results in: |
| 5241 |
|
| 5242 |
car(ACT, IVE) |
| 5243 |
⇒ACT |
| 5244 |
|
| 5245 |
In the second case, the top level gives ‘active’ as first and only |
| 5246 |
argument of ‘car’, which results in: |
| 5247 |
|
| 5248 |
active |
| 5249 |
⇒ACT, IVE |
| 5250 |
|
| 5251 |
i.e., the argument is evaluated _after_ the macro that invokes it. In |
| 5252 |
the third case, ‘car’ receives ‘[active]’, which results in: |
| 5253 |
|
| 5254 |
[active] |
| 5255 |
⇒active |
| 5256 |
|
| 5257 |
exactly as we already saw above. |
| 5258 |
|
| 5259 |
The example above, applied to a more realistic example, gives: |
| 5260 |
|
| 5261 |
car(int tab[10];) |
| 5262 |
⇒int tab10; |
| 5263 |
car([int tab[10];]) |
| 5264 |
⇒int tab10; |
| 5265 |
car([[int tab[10];]]) |
| 5266 |
⇒int tab[10]; |
| 5267 |
|
| 5268 |
Huh? The first case is easily understood, but why is the second wrong, |
| 5269 |
and the third right? To understand that, you must know that after ‘m4’ |
| 5270 |
expands a macro, the resulting text is immediately subjected to macro |
| 5271 |
expansion and quote removal. This means that the quote removal occurs |
| 5272 |
twice--first before the argument is passed to the ‘car’ macro, and |
| 5273 |
second after the ‘car’ macro expands to the first argument. |
| 5274 |
|
| 5275 |
As the author of the Autoconf macro ‘car’, you then consider it to be |
| 5276 |
incorrect that your users have to double-quote the arguments of ‘car’, |
| 5277 |
so you "fix" your macro. Let's call it ‘qar’ for quoted car: |
| 5278 |
|
| 5279 |
define([qar], [[$1]]) |
| 5280 |
|
| 5281 |
and check that ‘qar’ is properly fixed: |
| 5282 |
|
| 5283 |
qar([int tab[10];]) |
| 5284 |
⇒int tab[10]; |
| 5285 |
|
| 5286 |
Ahhh! That's much better. |
| 5287 |
|
| 5288 |
But note what you've done: now that the arguments are literal |
| 5289 |
strings, if the user wants to use the results of expansions as |
| 5290 |
arguments, she has to use an _unquoted_ macro call: |
| 5291 |
|
| 5292 |
qar(active) |
| 5293 |
⇒ACT |
| 5294 |
|
| 5295 |
where she wanted to reproduce what she used to do with ‘car’: |
| 5296 |
|
| 5297 |
car([active]) |
| 5298 |
⇒ACT, IVE |
| 5299 |
|
| 5300 |
Worse yet: she wants to use a macro that produces a set of ‘cpp’ macros: |
| 5301 |
|
| 5302 |
define([my_includes], [#include <stdio.h>]) |
| 5303 |
car([my_includes]) |
| 5304 |
⇒#include <stdio.h> |
| 5305 |
qar(my_includes) |
| 5306 |
error→EOF in argument list |
| 5307 |
|
| 5308 |
This macro, ‘qar’, because it double quotes its arguments, forces its |
| 5309 |
users to leave their macro calls unquoted, which is dangerous. Commas |
| 5310 |
and other active symbols are interpreted by ‘m4’ before they are given |
| 5311 |
to the macro, often not in the way the users expect. Also, because |
| 5312 |
‘qar’ behaves differently from the other macros, it's an exception that |
| 5313 |
should be avoided in Autoconf. |
| 5314 |
|
| 5315 |
|
| 5316 |
File: autoconf.info, Node: Quadrigraphs, Next: Quotation Rule Of Thumb, Prev: Quotation and Nested Macros, Up: M4 Quotation |
| 5317 |
|
| 5318 |
8.1.4 Quadrigraphs |
| 5319 |
------------------ |
| 5320 |
|
| 5321 |
When writing an autoconf macro you may occasionally need to generate |
| 5322 |
special characters that are difficult to express with the standard |
| 5323 |
autoconf quoting rules. For example, you may need to output the regular |
| 5324 |
expression ‘[^[]’, which matches any character other than ‘[’. This |
| 5325 |
expression contains unbalanced brackets so it cannot be put easily into |
| 5326 |
an M4 macro. |
| 5327 |
|
| 5328 |
You can work around this problem by using one of the following |
| 5329 |
“quadrigraphs”: |
| 5330 |
|
| 5331 |
‘@<:@’ |
| 5332 |
‘[’ |
| 5333 |
‘@:>@’ |
| 5334 |
‘]’ |
| 5335 |
‘@S|@’ |
| 5336 |
‘$’ |
| 5337 |
‘@%:@’ |
| 5338 |
‘#’ |
| 5339 |
|
| 5340 |
Quadrigraphs are replaced at a late stage of the translation process, |
| 5341 |
after ‘m4’ is run, so they do not get in the way of M4 quoting. For |
| 5342 |
example, the string ‘[^@<:@]’, if properly quoted, will appear as ‘[^[]’ |
| 5343 |
in the ‘configure’ script. |
| 5344 |
|
| 5345 |
|
| 5346 |
File: autoconf.info, Node: Quotation Rule Of Thumb, Prev: Quadrigraphs, Up: M4 Quotation |
| 5347 |
|
| 5348 |
8.1.5 Quotation Rule Of Thumb |
| 5349 |
----------------------------- |
| 5350 |
|
| 5351 |
To conclude, the quotation rule of thumb is: |
| 5352 |
|
| 5353 |
_One pair of quotes per pair of parentheses._ |
| 5354 |
|
| 5355 |
Never over-quote, never under-quote, in particular in the definition |
| 5356 |
of macros. In the few places where the macros need to use brackets |
| 5357 |
(usually in C program text or regular expressions), properly quote _the |
| 5358 |
arguments_! |
| 5359 |
|
| 5360 |
It is common to read Autoconf programs with snippets like: |
| 5361 |
|
| 5362 |
AC_TRY_LINK( |
| 5363 |
changequote(<<, >>)dnl |
| 5364 |
<<#include <time.h> |
| 5365 |
#ifndef tzname /* For SGI. */ |
| 5366 |
extern char *tzname[]; /* RS6000 and others reject char **tzname. */ |
| 5367 |
#endif>>, |
| 5368 |
changequote([, ])dnl |
| 5369 |
[atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no) |
| 5370 |
|
| 5371 |
which is incredibly useless since ‘AC_TRY_LINK’ is _already_ double |
| 5372 |
quoting, so you just need: |
| 5373 |
|
| 5374 |
AC_TRY_LINK( |
| 5375 |
[#include <time.h> |
| 5376 |
#ifndef tzname /* For SGI. */ |
| 5377 |
extern char *tzname[]; /* RS6000 and others reject char **tzname. */ |
| 5378 |
#endif], |
| 5379 |
[atoi (*tzname);], |
| 5380 |
[ac_cv_var_tzname=yes], |
| 5381 |
[ac_cv_var_tzname=no]) |
| 5382 |
|
| 5383 |
The M4-fluent reader will note that these two examples are rigorously |
| 5384 |
equivalent, since ‘m4’ swallows both the ‘changequote(<<, >>)’ and ‘<<’ |
| 5385 |
‘>>’ when it “collects” the arguments: these quotes are not part of the |
| 5386 |
arguments! |
| 5387 |
|
| 5388 |
Simplified, the example above is just doing this: |
| 5389 |
|
| 5390 |
changequote(<<, >>)dnl |
| 5391 |
<<[]>> |
| 5392 |
changequote([, ])dnl |
| 5393 |
|
| 5394 |
instead of simply: |
| 5395 |
|
| 5396 |
[[]] |
| 5397 |
|
| 5398 |
With macros that do not double quote their arguments (which is the |
| 5399 |
rule), double-quote the (risky) literals: |
| 5400 |
|
| 5401 |
AC_LINK_IFELSE([AC_LANG_PROGRAM( |
| 5402 |
[[#include <time.h> |
| 5403 |
#ifndef tzname /* For SGI. */ |
| 5404 |
extern char *tzname[]; /* RS6000 and others reject char **tzname. */ |
| 5405 |
#endif]], |
| 5406 |
[atoi (*tzname);])], |
| 5407 |
[ac_cv_var_tzname=yes], |
| 5408 |
[ac_cv_var_tzname=no]) |
| 5409 |
|
| 5410 |
See *Note Quadrigraphs::, for what to do if you run into a hopeless |
| 5411 |
case where quoting does not suffice. |
| 5412 |
|
| 5413 |
When you create a ‘configure’ script using newly written macros, |
| 5414 |
examine it carefully to check whether you need to add more quotes in |
| 5415 |
your macros. If one or more words have disappeared in the ‘m4’ output, |
| 5416 |
you need more quotes. When in doubt, quote. |
| 5417 |
|
| 5418 |
However, it's also possible to put on too many layers of quotes. If |
| 5419 |
this happens, the resulting ‘configure’ script will contain unexpanded |
| 5420 |
macros. The ‘autoconf’ program checks for this problem by doing ‘grep |
| 5421 |
AC_ configure’. |
| 5422 |
|
| 5423 |
|
| 5424 |
File: autoconf.info, Node: Programming in M4sugar, Prev: M4 Quotation, Up: Programming in M4 |
| 5425 |
|
| 5426 |
8.2 Programming in M4sugar |
| 5427 |
========================== |
| 5428 |
|
| 5429 |
M4 by itself provides only a small, but sufficient, set of all-purpose |
| 5430 |
macros. M4sugar introduces additional generic macros. Its name was |
| 5431 |
coined by Lars J. Aas: "Readability And Greater Understanding Stands 4 |
| 5432 |
M4sugar". |
| 5433 |
|
| 5434 |
* Menu: |
| 5435 |
|
| 5436 |
* Redefined M4 Macros:: M4 builtins changed in M4sugar |
| 5437 |
* Forbidden Patterns:: Catching unexpanded macros |
| 5438 |
|
| 5439 |
|
| 5440 |
File: autoconf.info, Node: Redefined M4 Macros, Next: Forbidden Patterns, Prev: Programming in M4sugar, Up: Programming in M4sugar |
| 5441 |
|
| 5442 |
8.2.1 Redefined M4 Macros |
| 5443 |
------------------------- |
| 5444 |
|
| 5445 |
All the M4 native macros are moved in the ‘m4_’ pseudo-namespace, e.g., |
| 5446 |
M4sugar renames ‘define’ as ‘m4_define’ etc. There is one exception: |
| 5447 |
‘dnl’ kept its original name, and no ‘m4_dnl’ is defined. |
| 5448 |
|
| 5449 |
M4sugar redefines some M4 macros, and made them slightly incompatible |
| 5450 |
with their native equivalent. |
| 5451 |
|
| 5452 |
-- Macro: m4_defn (MACRO) |
| 5453 |
Contrary to the M4 builtin, this macro fails if MACRO is not |
| 5454 |
defined. See ‘m4_undefine’. |
| 5455 |
|
| 5456 |
-- Macro: m4_undefine (MACRO) |
| 5457 |
Contrary to the M4 builtin, this macro fails if MACRO is not |
| 5458 |
defined. Use |
| 5459 |
|
| 5460 |
m4_ifdef([MACRO], [m4_undefine([MACRO])]) |
| 5461 |
|
| 5462 |
to recover the behavior of the builtin. |
| 5463 |
|
| 5464 |
-- Macro: m4_popdef (MACRO) |
| 5465 |
Contrary to the M4 builtin, this macro fails if MACRO is not |
| 5466 |
defined. See ‘m4_undefine’. |
| 5467 |
|
| 5468 |
|
| 5469 |
File: autoconf.info, Node: Forbidden Patterns, Prev: Redefined M4 Macros, Up: Programming in M4sugar |
| 5470 |
|
| 5471 |
8.2.2 Forbidden Patterns |
| 5472 |
------------------------ |
| 5473 |
|
| 5474 |
M4sugar provides a means to define suspicious patterns, patterns |
| 5475 |
describing tokens which should not be found in the output. For |
| 5476 |
instance, if an Autoconf ‘configure’ script includes tokens such as |
| 5477 |
‘AC_DEFINE’, or ‘dnl’, then most probably something went wrong |
| 5478 |
(typically a macro was not evaluated because of over quotation). |
| 5479 |
|
| 5480 |
M4sugar forbids all the tokens matching ‘^m4_’ and ‘^dnl$’. |
| 5481 |
|
| 5482 |
-- Macro: m4_pattern_forbid (PATTERN) |
| 5483 |
Declare no token matching PATTERN must be found in the output. |
| 5484 |
Comments are not checked; this can be a problem if, for instance, |
| 5485 |
you have some macro left unexpanded after an ‘#include’. No |
| 5486 |
consensus is currently found in the Autoconf community, as some |
| 5487 |
people consider it should be valid to name macros in comments |
| 5488 |
(which doesn't makes sense to the author of this documentation, as |
| 5489 |
‘#’-comments should document the output, not the input, documented |
| 5490 |
vy ‘dnl’-comments). |
| 5491 |
|
| 5492 |
Of course, you might encounter exceptions to these generic rules, for |
| 5493 |
instance you might have to refer to ‘$m4_flags’. |
| 5494 |
|
| 5495 |
-- Macro: m4_pattern_allow (PATTERN) |
| 5496 |
Any token matching PATTERN is allowed, including if it matches an |
| 5497 |
‘m4_pattern_forbid’ pattern. |
| 5498 |
|
| 5499 |
|
| 5500 |
File: autoconf.info, Node: Writing Autoconf Macros, Next: Portable Shell, Prev: Programming in M4, Up: Top |
| 5501 |
|
| 5502 |
9 Writing Autoconf Macros |
| 5503 |
************************* |
| 5504 |
|
| 5505 |
When you write a feature test that could be applicable to more than one |
| 5506 |
software package, the best thing to do is encapsulate it in a new macro. |
| 5507 |
Here are some instructions and guidelines for writing Autoconf macros. |
| 5508 |
|
| 5509 |
* Menu: |
| 5510 |
|
| 5511 |
* Macro Definitions:: Basic format of an Autoconf macro |
| 5512 |
* Macro Names:: What to call your new macros |
| 5513 |
* Reporting Messages:: Notifying ‘autoconf’ users |
| 5514 |
* Dependencies Between Macros:: What to do when macros depend on other macros |
| 5515 |
* Obsoleting Macros:: Warning about old ways of doing things |
| 5516 |
* Coding Style:: Writing Autoconf macros à la Autoconf |
| 5517 |
|
| 5518 |
|
| 5519 |
File: autoconf.info, Node: Macro Definitions, Next: Macro Names, Prev: Writing Autoconf Macros, Up: Writing Autoconf Macros |
| 5520 |
|
| 5521 |
9.1 Macro Definitions |
| 5522 |
===================== |
| 5523 |
|
| 5524 |
Autoconf macros are defined using the ‘AC_DEFUN’ macro, which is similar |
| 5525 |
to the M4 builtin ‘define’ macro. In addition to defining a macro, |
| 5526 |
‘AC_DEFUN’ adds to it some code that is used to constrain the order in |
| 5527 |
which macros are called (*note Prerequisite Macros::). |
| 5528 |
|
| 5529 |
An Autoconf macro definition looks like this: |
| 5530 |
|
| 5531 |
AC_DEFUN(MACRO-NAME, MACRO-BODY) |
| 5532 |
|
| 5533 |
You can refer to any arguments passed to the macro as ‘$1’, ‘$2’, |
| 5534 |
etc. *Note How to define new macros: (m4.info)Definitions, for more |
| 5535 |
complete information on writing M4 macros. |
| 5536 |
|
| 5537 |
Be sure to properly quote both the MACRO-BODY _and_ the MACRO-NAME to |
| 5538 |
avoid any problems if the macro happens to have been previously defined. |
| 5539 |
|
| 5540 |
Each macro should have a header comment that gives its prototype, and |
| 5541 |
a brief description. When arguments have default values, display them |
| 5542 |
in the prototype. For example: |
| 5543 |
|
| 5544 |
# AC_MSG_ERROR(ERROR, [EXIT-STATUS = 1]) |
| 5545 |
# -------------------------------------- |
| 5546 |
define([AC_MSG_ERROR], |
| 5547 |
[{ _AC_ECHO([configure: error: $1], 2); exit m4_default([$2], 1); }]) |
| 5548 |
|
| 5549 |
Comments about the macro should be left in the header comment. Most |
| 5550 |
other comments will make their way into ‘configure’, so just keep using |
| 5551 |
‘#’ to introduce comments. |
| 5552 |
|
| 5553 |
If you have some very special comments about pure M4 code, comments |
| 5554 |
that make no sense in ‘configure’ and in the header comment, then use |
| 5555 |
the builtin ‘dnl’: it causes ‘m4’ to discard the text through the next |
| 5556 |
newline. |
| 5557 |
|
| 5558 |
Keep in mind that ‘dnl’ is rarely needed to introduce comments; ‘dnl’ |
| 5559 |
is more useful to get rid of the newlines following macros that produce |
| 5560 |
no output, such as ‘AC_REQUIRE’. |
| 5561 |
|
| 5562 |
|
| 5563 |
File: autoconf.info, Node: Macro Names, Next: Reporting Messages, Prev: Macro Definitions, Up: Writing Autoconf Macros |
| 5564 |
|
| 5565 |
9.2 Macro Names |
| 5566 |
=============== |
| 5567 |
|
| 5568 |
All of the Autoconf macros have all-uppercase names starting with ‘AC_’ |
| 5569 |
to prevent them from accidentally conflicting with other text. All |
| 5570 |
shell variables that they use for internal purposes have |
| 5571 |
mostly-lowercase names starting with ‘ac_’. To ensure that your macros |
| 5572 |
don't conflict with present or future Autoconf macros, you should prefix |
| 5573 |
your own macro names and any shell variables they use with some other |
| 5574 |
sequence. Possibilities include your initials, or an abbreviation for |
| 5575 |
the name of your organization or software package. |
| 5576 |
|
| 5577 |
Most of the Autoconf macros' names follow a structured naming |
| 5578 |
convention that indicates the kind of feature check by the name. The |
| 5579 |
macro names consist of several words, separated by underscores, going |
| 5580 |
from most general to most specific. The names of their cache variables |
| 5581 |
use the same convention (*note Cache Variable Names::, for more |
| 5582 |
information on them). |
| 5583 |
|
| 5584 |
The first word of the name after ‘AC_’ usually tells the category of |
| 5585 |
feature being tested. Here are the categories used in Autoconf for |
| 5586 |
specific test macros, the kind of macro that you are more likely to |
| 5587 |
write. They are also used for cache variables, in all-lowercase. Use |
| 5588 |
them where applicable; where they're not, invent your own categories. |
| 5589 |
|
| 5590 |
‘C’ |
| 5591 |
C language builtin features. |
| 5592 |
‘DECL’ |
| 5593 |
Declarations of C variables in header files. |
| 5594 |
‘FUNC’ |
| 5595 |
Functions in libraries. |
| 5596 |
‘GROUP’ |
| 5597 |
UNIX group owners of files. |
| 5598 |
‘HEADER’ |
| 5599 |
Header files. |
| 5600 |
‘LIB’ |
| 5601 |
C libraries. |
| 5602 |
‘PATH’ |
| 5603 |
The full path names to files, including programs. |
| 5604 |
‘PROG’ |
| 5605 |
The base names of programs. |
| 5606 |
‘MEMBER’ |
| 5607 |
Members of aggregates. |
| 5608 |
‘SYS’ |
| 5609 |
Operating system features. |
| 5610 |
‘TYPE’ |
| 5611 |
C builtin or declared types. |
| 5612 |
‘VAR’ |
| 5613 |
C variables in libraries. |
| 5614 |
|
| 5615 |
After the category comes the name of the particular feature being |
| 5616 |
tested. Any further words in the macro name indicate particular aspects |
| 5617 |
of the feature. For example, ‘AC_FUNC_UTIME_NULL’ checks the behavior |
| 5618 |
of the ‘utime’ function when called with a ‘NULL’ pointer. |
| 5619 |
|
| 5620 |
An internal macro should have a name that starts with an underscore; |
| 5621 |
Autoconf internals should therefore start with ‘_AC_’. Additionally, a |
| 5622 |
macro that is an internal subroutine of another macro should have a name |
| 5623 |
that starts with an underscore and the name of that other macro, |
| 5624 |
followed by one or more words saying what the internal macro does. For |
| 5625 |
example, ‘AC_PATH_X’ has internal macros ‘_AC_PATH_X_XMKMF’ and |
| 5626 |
‘_AC_PATH_X_DIRECT’. |
| 5627 |
|
| 5628 |
|
| 5629 |
File: autoconf.info, Node: Reporting Messages, Next: Dependencies Between Macros, Prev: Macro Names, Up: Writing Autoconf Macros |
| 5630 |
|
| 5631 |
9.3 Reporting Messages |
| 5632 |
====================== |
| 5633 |
|
| 5634 |
When macros statically diagnose abnormal situations, benign or fatal, |
| 5635 |
they should report them using these macros. For dynamic issues, i.e., |
| 5636 |
when ‘configure’ is run, see *note Printing Messages::. |
| 5637 |
|
| 5638 |
-- Macro: AC_DIAGNOSE (CATEGORY, MESSAGE) |
| 5639 |
Report MESSAGE as a warning (or as an error if requested by the |
| 5640 |
user) if it falls into the CATEGORY. You are encouraged to use |
| 5641 |
standard categories, which currently include: |
| 5642 |
|
| 5643 |
‘all’ |
| 5644 |
messages that don't fall into one of the following category. |
| 5645 |
Use of an empty CATEGORY is equivalent. |
| 5646 |
|
| 5647 |
‘cross’ |
| 5648 |
related to cross compilation issues. |
| 5649 |
|
| 5650 |
‘obsolete’ |
| 5651 |
use of an obsolete construct. |
| 5652 |
|
| 5653 |
‘syntax’ |
| 5654 |
dubious syntactic constructs, incorrectly ordered macro calls. |
| 5655 |
|
| 5656 |
-- Macro: AC_WARNING (MESSAGE) |
| 5657 |
Equivalent to ‘AC_DIAGNOSE([syntax], MESSAGE)’, but you are |
| 5658 |
strongly encouraged to use a finer grained category. |
| 5659 |
|
| 5660 |
-- Macro: AC_FATAL (MESSAGE) |
| 5661 |
Report a severe error MESSAGE, and have ‘autoconf’ die. |
| 5662 |
|
| 5663 |
When the user runs ‘autoconf -W error’, warnings from ‘AC_DIAGNOSE’ |
| 5664 |
and ‘AC_WARNING’ are reported as error, see *note autoconf Invocation::. |
| 5665 |
|
| 5666 |
|
| 5667 |
File: autoconf.info, Node: Dependencies Between Macros, Next: Obsoleting Macros, Prev: Reporting Messages, Up: Writing Autoconf Macros |
| 5668 |
|
| 5669 |
9.4 Dependencies Between Macros |
| 5670 |
=============================== |
| 5671 |
|
| 5672 |
Some Autoconf macros depend on other macros having been called first in |
| 5673 |
order to work correctly. Autoconf provides a way to ensure that certain |
| 5674 |
macros are called if needed and a way to warn the user if macros are |
| 5675 |
called in an order that might cause incorrect operation. |
| 5676 |
|
| 5677 |
* Menu: |
| 5678 |
|
| 5679 |
* Prerequisite Macros:: Ensuring required information |
| 5680 |
* Suggested Ordering:: Warning about possible ordering problems |
| 5681 |
|
| 5682 |
|
| 5683 |
File: autoconf.info, Node: Prerequisite Macros, Next: Suggested Ordering, Prev: Dependencies Between Macros, Up: Dependencies Between Macros |
| 5684 |
|
| 5685 |
9.4.1 Prerequisite Macros |
| 5686 |
------------------------- |
| 5687 |
|
| 5688 |
A macro that you write might need to use values that have previously |
| 5689 |
been computed by other macros. For example, ‘AC_DECL_YYTEXT’ examines |
| 5690 |
the output of ‘flex’ or ‘lex’, so it depends on ‘AC_PROG_LEX’ having |
| 5691 |
been called first to set the shell variable ‘LEX’. |
| 5692 |
|
| 5693 |
Rather than forcing the user of the macros to keep track of the |
| 5694 |
dependencies between them, you can use the ‘AC_REQUIRE’ macro to do it |
| 5695 |
automatically. ‘AC_REQUIRE’ can ensure that a macro is only called if |
| 5696 |
it is needed, and only called once. |
| 5697 |
|
| 5698 |
-- Macro: AC_REQUIRE (MACRO-NAME) |
| 5699 |
If the M4 macro MACRO-NAME has not already been called, call it |
| 5700 |
(without any arguments). Make sure to quote MACRO-NAME with square |
| 5701 |
brackets. MACRO-NAME must have been defined using ‘AC_DEFUN’ or |
| 5702 |
else contain a call to ‘AC_PROVIDE’ to indicate that it has been |
| 5703 |
called. |
| 5704 |
|
| 5705 |
‘AC_REQUIRE’ must be used inside an ‘AC_DEFUN’'d macro; it must not |
| 5706 |
be called from the top level. |
| 5707 |
|
| 5708 |
‘AC_REQUIRE’ is often misunderstood. It really implements |
| 5709 |
dependencies between macros in the sense that if one macro depends upon |
| 5710 |
another, the latter will be expanded _before_ the body of the former. |
| 5711 |
In particular, ‘AC_REQUIRE(FOO)’ is not replaced with the body of ‘FOO’. |
| 5712 |
For instance, this definition of macros: |
| 5713 |
|
| 5714 |
AC_DEFUN([TRAVOLTA], |
| 5715 |
[test "$body_temparature_in_celsius" -gt "38" && |
| 5716 |
dance_floor=occupied]) |
| 5717 |
AC_DEFUN([NEWTON_JOHN], |
| 5718 |
[test "$hair_style" = "curly" && |
| 5719 |
dance_floor=occupied]) |
| 5720 |
|
| 5721 |
AC_DEFUN([RESERVE_DANCE_FLOOR], |
| 5722 |
[if date | grep '^Sat.*pm' >/dev/null 2>&1; then |
| 5723 |
AC_REQUIRE([TRAVOLTA]) |
| 5724 |
AC_REQUIRE([NEWTON_JOHN]) |
| 5725 |
fi]) |
| 5726 |
|
| 5727 |
with this ‘configure.ac’ |
| 5728 |
|
| 5729 |
AC_INIT |
| 5730 |
RESERVE_DANCE_FLOOR |
| 5731 |
if test "$dance_floor" = occupied; then |
| 5732 |
AC_MSG_ERROR([cannot pick up here, let's move]) |
| 5733 |
fi |
| 5734 |
|
| 5735 |
will not leave you with a better chance to meet a kindred soul at other |
| 5736 |
times than Saturday night since it expands into: |
| 5737 |
|
| 5738 |
test "$body_temperature_in_Celsius" -gt "38" && |
| 5739 |
dance_floor=occupied |
| 5740 |
test "$hair_style" = "curly" && |
| 5741 |
dance_floor=occupied |
| 5742 |
fi |
| 5743 |
if date | grep '^Sat.*pm' >/dev/null 2>&1; then |
| 5744 |
|
| 5745 |
|
| 5746 |
fi |
| 5747 |
|
| 5748 |
This behavior was chosen on purpose: (i) it prevents messages in |
| 5749 |
required macros from interrupting the messages in the requiring macros; |
| 5750 |
(ii) it avoids bad surprises when shell conditionals are used, as in: |
| 5751 |
|
| 5752 |
if ...; then |
| 5753 |
AC_REQUIRE([SOME_CHECK]) |
| 5754 |
fi |
| 5755 |
... |
| 5756 |
SOME_CHECK |
| 5757 |
|
| 5758 |
You are encouraged to put all ‘AC_REQUIRE’s at the beginning of a |
| 5759 |
macro. You can use ‘dnl’ to avoid the empty lines they leave. |
| 5760 |
|
| 5761 |
|
| 5762 |
File: autoconf.info, Node: Suggested Ordering, Prev: Prerequisite Macros, Up: Dependencies Between Macros |
| 5763 |
|
| 5764 |
9.4.2 Suggested Ordering |
| 5765 |
------------------------ |
| 5766 |
|
| 5767 |
Some macros should be run before another macro if both are called, but |
| 5768 |
neither _requires_ that the other be called. For example, a macro that |
| 5769 |
changes the behavior of the C compiler should be called before any |
| 5770 |
macros that run the C compiler. Many of these dependencies are noted in |
| 5771 |
the documentation. |
| 5772 |
|
| 5773 |
Autoconf provides the ‘AC_BEFORE’ macro to warn users when macros |
| 5774 |
with this kind of dependency appear out of order in a ‘configure.ac’ |
| 5775 |
file. The warning occurs when creating ‘configure’ from ‘configure.ac’, |
| 5776 |
not when running ‘configure’. |
| 5777 |
|
| 5778 |
For example, ‘AC_PROG_CPP’ checks whether the C compiler can run the |
| 5779 |
C preprocessor when given the ‘-E’ option. It should therefore be |
| 5780 |
called after any macros that change which C compiler is being used, such |
| 5781 |
as ‘AC_PROG_CC’. So ‘AC_PROG_CC’ contains: |
| 5782 |
|
| 5783 |
AC_BEFORE([$0], [AC_PROG_CPP])dnl |
| 5784 |
|
| 5785 |
This warns the user if a call to ‘AC_PROG_CPP’ has already occurred when |
| 5786 |
‘AC_PROG_CC’ is called. |
| 5787 |
|
| 5788 |
-- Macro: AC_BEFORE (THIS-MACRO-NAME, CALLED-MACRO-NAME) |
| 5789 |
Make ‘m4’ print a warning message to the standard error output if |
| 5790 |
CALLED-MACRO-NAME has already been called. THIS-MACRO-NAME should |
| 5791 |
be the name of the macro that is calling ‘AC_BEFORE’. The macro |
| 5792 |
CALLED-MACRO-NAME must have been defined using ‘AC_DEFUN’ or else |
| 5793 |
contain a call to ‘AC_PROVIDE’ to indicate that it has been called. |
| 5794 |
|
| 5795 |
|
| 5796 |
File: autoconf.info, Node: Obsoleting Macros, Next: Coding Style, Prev: Dependencies Between Macros, Up: Writing Autoconf Macros |
| 5797 |
|
| 5798 |
9.5 Obsoleting Macros |
| 5799 |
===================== |
| 5800 |
|
| 5801 |
Configuration and portability technology has evolved over the years. |
| 5802 |
Often better ways of solving a particular problem are developed, or |
| 5803 |
ad-hoc approaches are systematized. This process has occurred in many |
| 5804 |
parts of Autoconf. One result is that some of the macros are now |
| 5805 |
considered “obsolete”; they still work, but are no longer considered the |
| 5806 |
best thing to do, hence they should be replaced with more modern macros. |
| 5807 |
Ideally, ‘autoupdate’ should substitute the old macro calls with their |
| 5808 |
modern implementation. |
| 5809 |
|
| 5810 |
Autoconf provides a simple means to obsolete a macro. |
| 5811 |
|
| 5812 |
-- Macro: AU_DEFUN (OLD-MACRO, IMPLEMENTATION, [MESSAGE]) |
| 5813 |
Define OLD-MACRO as IMPLEMENTATION. The only difference with |
| 5814 |
‘AC_DEFUN’ is that the user will be warned that OLD-MACRO is now |
| 5815 |
obsolete. |
| 5816 |
|
| 5817 |
If she then uses ‘autoupdate’, the call to OLD-MACRO will be |
| 5818 |
replaced by the modern IMPLEMENTATION. The additional MESSAGE is |
| 5819 |
then printed. |
| 5820 |
|
| 5821 |
|
| 5822 |
File: autoconf.info, Node: Coding Style, Prev: Obsoleting Macros, Up: Writing Autoconf Macros |
| 5823 |
|
| 5824 |
9.6 Coding Style |
| 5825 |
================ |
| 5826 |
|
| 5827 |
The Autoconf macros follow a strict coding style. You are encouraged to |
| 5828 |
follow this style, especially if you intend to distribute your macro, |
| 5829 |
either by contributing it to Autoconf itself, or via other means. |
| 5830 |
|
| 5831 |
The first requirement is to pay great attention to the quotation, for |
| 5832 |
more details, see *note Autoconf Language::, and *note M4 Quotation::. |
| 5833 |
|
| 5834 |
Do not try to invent new interfaces. It is likely that there is a |
| 5835 |
macro in Autoconf that resembles the macro you are defining: try to |
| 5836 |
stick to this existing interface (order of arguments, default values, |
| 5837 |
etc.). We _are_ conscious that some of these interfaces are not |
| 5838 |
perfect; nevertheless, when harmless, homogeneity should be preferred |
| 5839 |
over creativity. |
| 5840 |
|
| 5841 |
Be careful about clashes both between M4 symbols and between shell |
| 5842 |
variables. |
| 5843 |
|
| 5844 |
If you stick to the suggested M4 naming scheme (*note Macro Names::), |
| 5845 |
you are unlikely to generate conflicts. Nevertheless, when you need to |
| 5846 |
set a special value, _avoid using a regular macro name_; rather, use an |
| 5847 |
"impossible" name. For instance, up to version 2.13, the macro |
| 5848 |
‘AC_SUBST’ used to remember what SYMBOLs were already defined by setting |
| 5849 |
‘AC_SUBST_SYMBOL’, which is a regular macro name. But since there is a |
| 5850 |
macro named ‘AC_SUBST_FILE’, it was just impossible to ‘AC_SUBST(FILE)’! |
| 5851 |
In this case, ‘AC_SUBST(SYMBOL)’ or ‘_AC_SUBST(SYMBOL)’ should have been |
| 5852 |
used (yes, with the parentheses)...or better yet, high-level macros such |
| 5853 |
as ‘AC_EXPAND_ONCE’. |
| 5854 |
|
| 5855 |
No Autoconf macro should ever enter the user-variable name space; |
| 5856 |
i.e., except for the variables that are the actual result of running the |
| 5857 |
macro, all shell variables should start with ‘ac_’. In addition, small |
| 5858 |
macros or any macro that is likely to be embedded in other macros should |
| 5859 |
be careful not to use obvious names. |
| 5860 |
|
| 5861 |
Do not use ‘dnl’ to introduce comments: most of the comments you are |
| 5862 |
likely to write are either header comments which are not output anyway, |
| 5863 |
or comments that should make their way into ‘configure’. There are |
| 5864 |
exceptional cases where you do want to comment special M4 constructs, in |
| 5865 |
which case ‘dnl’ is right, but keep in mind that it is unlikely. |
| 5866 |
|
| 5867 |
M4 ignores the leading spaces before each argument, use this feature |
| 5868 |
to indent in such a way that arguments are (more or less) aligned with |
| 5869 |
the opening parenthesis of the macro being called. For instance, |
| 5870 |
instead of |
| 5871 |
|
| 5872 |
AC_CACHE_CHECK(for EMX OS/2 environment, |
| 5873 |
ac_cv_emxos2, |
| 5874 |
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __EMX__;])], |
| 5875 |
[ac_cv_emxos2=yes], [ac_cv_emxos2=no])]) |
| 5876 |
|
| 5877 |
write |
| 5878 |
|
| 5879 |
AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2], |
| 5880 |
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])], |
| 5881 |
[ac_cv_emxos2=yes], |
| 5882 |
[ac_cv_emxos2=no])]) |
| 5883 |
|
| 5884 |
or even |
| 5885 |
|
| 5886 |
AC_CACHE_CHECK([for EMX OS/2 environment], |
| 5887 |
[ac_cv_emxos2], |
| 5888 |
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], |
| 5889 |
[return __EMX__;])], |
| 5890 |
[ac_cv_emxos2=yes], |
| 5891 |
[ac_cv_emxos2=no])]) |
| 5892 |
|
| 5893 |
When using ‘AC_TRY_RUN’ or any macro that cannot work when |
| 5894 |
cross-compiling, provide a pessimistic value (typically ‘no’). |
| 5895 |
|
| 5896 |
Feel free to use various tricks to prevent auxiliary tools, such as |
| 5897 |
syntax-highlighting editors, from behaving improperly. For instance, |
| 5898 |
instead of: |
| 5899 |
|
| 5900 |
patsubst([$1], [$"]) |
| 5901 |
|
| 5902 |
use |
| 5903 |
|
| 5904 |
patsubst([$1], [$""]) |
| 5905 |
|
| 5906 |
so that Emacsen do not open a endless "string" at the first quote. For |
| 5907 |
the same reasons, avoid: |
| 5908 |
|
| 5909 |
test $[#] != 0 |
| 5910 |
|
| 5911 |
and use: |
| 5912 |
|
| 5913 |
test $[@%:@] != 0 |
| 5914 |
|
| 5915 |
Otherwise, the closing bracket would be hidden inside a ‘#’-comment, |
| 5916 |
breaking the bracket-matching highlighting from Emacsen. Note the |
| 5917 |
preferred style to escape from M4: ‘$[1]’, ‘$[@]’, etc. Do not escape |
| 5918 |
when it is unneeded. Common examples of useless quotation are ‘[$]$1’ |
| 5919 |
(write ‘$$1’), ‘[$]var’ (use ‘$var’), etc. If you add portability |
| 5920 |
issues to the picture, you'll prefer ‘${1+"$[@]"}’ to ‘"[$]@"’, and |
| 5921 |
you'll prefer do something better than hacking Autoconf ‘:-)’. |
| 5922 |
|
| 5923 |
When using ‘sed’, don't use ‘-e’ except for indenting purpose. With |
| 5924 |
the ‘s’ command, the preferred separator is ‘/’ unless ‘/’ itself is |
| 5925 |
used in the command, in which case you should use ‘,’. |
| 5926 |
|
| 5927 |
*Note Macro Definitions::, for details on how to define a macro. If |
| 5928 |
a macro doesn't use ‘AC_REQUIRE’ and it is expected to never be the |
| 5929 |
object of an ‘AC_REQUIRE’ directive, then use ‘define’. In case of |
| 5930 |
doubt, use ‘AC_DEFUN’. All the ‘AC_REQUIRE’ statements should be at the |
| 5931 |
beginning of the macro, ‘dnl’'ed. |
| 5932 |
|
| 5933 |
You should not rely on the number of arguments: instead of checking |
| 5934 |
whether an argument is missing, test that it is not empty. It provides |
| 5935 |
both a simpler and a more predictable interface to the user, and saves |
| 5936 |
room for further arguments. |
| 5937 |
|
| 5938 |
Unless the macro is short, try to leave the closing ‘])’ at the |
| 5939 |
beginning of a line, followed by a comment that repeats the name of the |
| 5940 |
macro being defined. This introduces an additional newline in |
| 5941 |
‘configure’; normally, that is not a problem, but if you want to remove |
| 5942 |
it you can use ‘[]dnl’ on the last line. You can similarly use ‘[]dnl’ |
| 5943 |
after a macro call to remove its newline. ‘[]dnl’ is recommended |
| 5944 |
instead of ‘dnl’ to ensure that M4 does not interpret the ‘dnl’ as being |
| 5945 |
attached to the preceding text or macro output. For example, instead |
| 5946 |
of: |
| 5947 |
|
| 5948 |
AC_DEFUN([AC_PATH_X], |
| 5949 |
[AC_MSG_CHECKING([for X]) |
| 5950 |
AC_REQUIRE_CPP() |
| 5951 |
# ...omitted... |
| 5952 |
AC_MSG_RESULT([libraries $x_libraries, headers $x_includes]) |
| 5953 |
fi]) |
| 5954 |
|
| 5955 |
you would write: |
| 5956 |
|
| 5957 |
AC_DEFUN([AC_PATH_X], |
| 5958 |
[AC_REQUIRE_CPP()[]dnl |
| 5959 |
AC_MSG_CHECKING([for X]) |
| 5960 |
# ...omitted... |
| 5961 |
AC_MSG_RESULT([libraries $x_libraries, headers $x_includes]) |
| 5962 |
fi[]dnl |
| 5963 |
])# AC_PATH_X |
| 5964 |
|
| 5965 |
If the macro is long, try to split it into logical chunks. |
| 5966 |
Typically, macros that check for a bug in a function and prepare its |
| 5967 |
‘AC_LIBOBJ’ replacement should have an auxiliary macro to perform this |
| 5968 |
setup. Do not hesitate to introduce auxiliary macros to factor your |
| 5969 |
code. |
| 5970 |
|
| 5971 |
In order to highlight the recommended coding style, here is a macro |
| 5972 |
written the old way: |
| 5973 |
|
| 5974 |
dnl Check for EMX on OS/2. |
| 5975 |
dnl _AC_EMXOS2 |
| 5976 |
AC_DEFUN(_AC_EMXOS2, |
| 5977 |
[AC_CACHE_CHECK(for EMX OS/2 environment, ac_cv_emxos2, |
| 5978 |
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return __EMX__;)], |
| 5979 |
ac_cv_emxos2=yes, ac_cv_emxos2=no)]) |
| 5980 |
test "$ac_cv_emxos2" = yes && EMXOS2=yes]) |
| 5981 |
|
| 5982 |
and the new way: |
| 5983 |
|
| 5984 |
# _AC_EMXOS2 |
| 5985 |
# ---------- |
| 5986 |
# Check for EMX on OS/2. |
| 5987 |
define([_AC_EMXOS2], |
| 5988 |
[AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2], |
| 5989 |
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])], |
| 5990 |
[ac_cv_emxos2=yes], |
| 5991 |
[ac_cv_emxos2=no])]) |
| 5992 |
test "$ac_cv_emxos2" = yes && EMXOS2=yes[]dnl |
| 5993 |
])# _AC_EMXOS2 |
| 5994 |
|
| 5995 |
|
| 5996 |
File: autoconf.info, Node: Portable Shell, Next: Manual Configuration, Prev: Writing Autoconf Macros, Up: Top |
| 5997 |
|
| 5998 |
10 Portable Shell Programming |
| 5999 |
***************************** |
| 6000 |
|
| 6001 |
When writing your own checks, there are some shell-script programming |
| 6002 |
techniques you should avoid in order to make your code portable. The |
| 6003 |
Bourne shell and upward-compatible shells like the Korn shell and Bash |
| 6004 |
have evolved over the years, but to prevent trouble, do not take |
| 6005 |
advantage of features that were added after UNIX version 7, circa 1977. |
| 6006 |
You should not use shell functions, aliases, negated character classes, |
| 6007 |
or other features that are not found in all Bourne-compatible shells; |
| 6008 |
restrict yourself to the lowest common denominator. Even ‘unset’ is not |
| 6009 |
supported by all shells! Also, include a space after the exclamation |
| 6010 |
point in interpreter specifications, like this: |
| 6011 |
|
| 6012 |
#! /usr/bin/perl |
| 6013 |
|
| 6014 |
If you omit the space before the path, then 4.2BSD based systems (such |
| 6015 |
as Sequent DYNIX) will ignore the line, because they interpret ‘#! /’ as |
| 6016 |
a 4-byte magic number. |
| 6017 |
|
| 6018 |
The set of external programs you should run in a ‘configure’ script |
| 6019 |
is fairly small. *Note Utilities in Makefiles: (standards)Utilities in |
| 6020 |
Makefiles, for the list. This restriction allows users to start out |
| 6021 |
with a fairly small set of programs and build the rest, avoiding too |
| 6022 |
many interdependencies between packages. |
| 6023 |
|
| 6024 |
Some of these external utilities have a portable subset of features; |
| 6025 |
see *note Limitations of Usual Tools::. |
| 6026 |
|
| 6027 |
* Menu: |
| 6028 |
|
| 6029 |
* Shellology:: A zoology of shells |
| 6030 |
* Here-Documents:: Quirks and tricks |
| 6031 |
* File Descriptors:: FDs and redirections |
| 6032 |
* File System Conventions:: File- and pathnames |
| 6033 |
* Shell Substitutions:: Variable and command expansions |
| 6034 |
* Assignments:: Varying side effects of assignments |
| 6035 |
* Special Shell Variables:: Variables you should not change |
| 6036 |
* Limitations of Builtins:: Portable use of not so portable /bin/sh |
| 6037 |
* Limitations of Usual Tools:: Portable use of portable tools |
| 6038 |
* Limitations of Make:: Portable Makefiles |
| 6039 |
|
| 6040 |
|
| 6041 |
File: autoconf.info, Node: Shellology, Next: Here-Documents, Prev: Portable Shell, Up: Portable Shell |
| 6042 |
|
| 6043 |
10.1 Shellology |
| 6044 |
=============== |
| 6045 |
|
| 6046 |
There are several families of shells, most prominently the Bourne family |
| 6047 |
and the C shell family which are deeply incompatible. If you want to |
| 6048 |
write portable shell scripts, avoid members of the C shell family. |
| 6049 |
|
| 6050 |
Below we describe some of the members of the Bourne shell family. |
| 6051 |
|
| 6052 |
Ash |
| 6053 |
‘ash’ is often used on GNU/Linux and BSD systems as a light-weight |
| 6054 |
Bourne-compatible shell. Ash 0.2 has some bugs that are fixed in |
| 6055 |
the 0.3.x series, but portable shell scripts should workaround |
| 6056 |
them, since version 0.2 is still shipped with many GNU/Linux |
| 6057 |
distributions. |
| 6058 |
|
| 6059 |
To be compatible with Ash 0.2: |
| 6060 |
|
| 6061 |
− don't use ‘$?’ after expanding empty or unset variables: |
| 6062 |
|
| 6063 |
foo= |
| 6064 |
false |
| 6065 |
$foo |
| 6066 |
echo "Don't use it: $?" |
| 6067 |
|
| 6068 |
− don't use command substitution within variable expansion: |
| 6069 |
|
| 6070 |
cat ${FOO=`bar`} |
| 6071 |
|
| 6072 |
− beware that single builtin substitutions are not performed by |
| 6073 |
a sub shell, hence their effect applies to the current shell! |
| 6074 |
*Note Shell Substitutions::, item "Command Substitution". |
| 6075 |
|
| 6076 |
Bash |
| 6077 |
To detect whether you are running ‘bash’, test if ‘BASH_VERSION’ is |
| 6078 |
set. To disable its extensions and require POSIX compatibility, |
| 6079 |
run ‘set -o posix’. *Note Bash POSIX Mode: (bash)Bash POSIX Mode, |
| 6080 |
for details. |
| 6081 |
|
| 6082 |
‘/usr/xpg4/bin/sh’ on Solaris |
| 6083 |
The POSIX-compliant Bourne shell on a Solaris system is |
| 6084 |
‘/usr/xpg4/bin/sh’ and is part of an extra optional package. There |
| 6085 |
is no extra charge for this package, but it is also not part of a |
| 6086 |
minimal OS install and therefore some folks may not have it. |
| 6087 |
|
| 6088 |
Zsh |
| 6089 |
To detect whether you are running ‘zsh’, test if ‘ZSH_VERSION’ is |
| 6090 |
set. By default ‘zsh’ is _not_ compatible with the Bourne shell: |
| 6091 |
you have to run ‘emulate sh’ and set ‘NULLCMD’ to ‘:’. *Note |
| 6092 |
Compatibility: (zsh)Compatibility, for details. |
| 6093 |
|
| 6094 |
Zsh 3.0.8 is the native ‘/bin/sh’ on Mac OS X 10.0.3. |
| 6095 |
|
| 6096 |
The following discussion between Russ Allbery and Robert Lipe is |
| 6097 |
worth reading: |
| 6098 |
|
| 6099 |
Russ Allbery: |
| 6100 |
|
| 6101 |
The GNU assumption that ‘/bin/sh’ is the one and only shell leads |
| 6102 |
to a permanent deadlock. Vendors don't want to break user's |
| 6103 |
existent shell scripts, and there are some corner cases in the |
| 6104 |
Bourne shell that are not completely compatible with a POSIX shell. |
| 6105 |
Thus, vendors who have taken this route will _never_ (OK..."never |
| 6106 |
say never") replace the Bourne shell (as ‘/bin/sh’) with a POSIX |
| 6107 |
shell. |
| 6108 |
|
| 6109 |
Robert Lipe: |
| 6110 |
|
| 6111 |
This is exactly the problem. While most (at least most System V's) |
| 6112 |
do have a bourne shell that accepts shell functions most vendor |
| 6113 |
‘/bin/sh’ programs are not the POSIX shell. |
| 6114 |
|
| 6115 |
So while most modern systems do have a shell _somewhere_ that meets |
| 6116 |
the POSIX standard, the challenge is to find it. |
| 6117 |
|
| 6118 |
|
| 6119 |
File: autoconf.info, Node: Here-Documents, Next: File Descriptors, Prev: Shellology, Up: Portable Shell |
| 6120 |
|
| 6121 |
10.2 Here-Documents |
| 6122 |
=================== |
| 6123 |
|
| 6124 |
Don't rely on ‘\’ being preserved just because it has no special meaning |
| 6125 |
together with the next symbol. in the native ‘/bin/sh’ on OpenBSD 2.7 |
| 6126 |
‘\"’ expands to ‘"’ in here-documents with unquoted delimiter. As a |
| 6127 |
general rule, if ‘\\’ expands to ‘\’ use ‘\\’ to get ‘\’. |
| 6128 |
|
| 6129 |
With OpenBSD 2.7's ‘/bin/sh’ |
| 6130 |
|
| 6131 |
$ cat <<EOF |
| 6132 |
> \" \\ |
| 6133 |
> EOF |
| 6134 |
" \ |
| 6135 |
|
| 6136 |
and with Bash: |
| 6137 |
|
| 6138 |
bash-2.04$ cat <<EOF |
| 6139 |
> \" \\ |
| 6140 |
> EOF |
| 6141 |
\" \ |
| 6142 |
|
| 6143 |
Many older shells (including the Bourne shell) implement |
| 6144 |
here-documents inefficiently. Users can generally speed things up by |
| 6145 |
using a faster shell, e.g., by using the command ‘bash ./configure’ |
| 6146 |
rather than plain ‘./configure’. |
| 6147 |
|
| 6148 |
Some shells can be extremely inefficient when there are a lot of |
| 6149 |
here-documents inside a single statement. For instance if your |
| 6150 |
‘configure.ac’ includes something like: |
| 6151 |
|
| 6152 |
if <cross_compiling>; then |
| 6153 |
assume this and that |
| 6154 |
else |
| 6155 |
check this |
| 6156 |
check that |
| 6157 |
check something else |
| 6158 |
... |
| 6159 |
on and on forever |
| 6160 |
... |
| 6161 |
fi |
| 6162 |
|
| 6163 |
A shell parses the whole ‘if’/‘fi’ construct, creating temporary |
| 6164 |
files for each here document in it. Some shells create links for such |
| 6165 |
here-documents on every ‘fork’, so that the clean-up code they had |
| 6166 |
installed correctly removes them. It is creating the links that the |
| 6167 |
shell can take forever. |
| 6168 |
|
| 6169 |
Moving the tests out of the ‘if’/‘fi’, or creating multiple ‘if’/‘fi’ |
| 6170 |
constructs, would improve the performance significantly. Anyway, this |
| 6171 |
kind of construct is not exactly the typical use of Autoconf. In fact, |
| 6172 |
it's even not recommended, because M4 macros can't look into shell |
| 6173 |
conditionals, so we may fail to expand a macro when it was expanded |
| 6174 |
before in a conditional path, and the condition turned out to be false |
| 6175 |
at run-time, and we end up not executing the macro at all. |
| 6176 |
|
| 6177 |
|
| 6178 |
File: autoconf.info, Node: File Descriptors, Next: File System Conventions, Prev: Here-Documents, Up: Portable Shell |
| 6179 |
|
| 6180 |
10.3 File Descriptors |
| 6181 |
===================== |
| 6182 |
|
| 6183 |
Some file descriptors shall not be used, since some systems, admittedly |
| 6184 |
arcane, use them for special purpose: |
| 6185 |
|
| 6186 |
3 |
| 6187 |
some systems may open it to ‘/dev/tty’. |
| 6188 |
|
| 6189 |
4 |
| 6190 |
used on the Kubota Titan. |
| 6191 |
|
| 6192 |
Don't redirect several times the same file descriptor, as you are |
| 6193 |
doomed to failure under Ultrix. |
| 6194 |
|
| 6195 |
ULTRIX V4.4 (Rev. 69) System #31: Thu Aug 10 19:42:23 GMT 1995 |
| 6196 |
UWS V4.4 (Rev. 11) |
| 6197 |
$ eval 'echo matter >fullness' >void |
| 6198 |
illegal io |
| 6199 |
$ eval '(echo matter >fullness)' >void |
| 6200 |
illegal io |
| 6201 |
$ (eval '(echo matter >fullness)') >void |
| 6202 |
Ambiguous output redirect. |
| 6203 |
|
| 6204 |
In each case the expected result is of course ‘fullness’ containing |
| 6205 |
‘matter’ and ‘void’ being empty. |
| 6206 |
|
| 6207 |
Don't try to redirect the standard error of a command substitution: |
| 6208 |
it must be done _inside_ the command substitution: when running ‘: `cd |
| 6209 |
/zorglub` 2>/dev/null’ expect the error message to escape, while ‘: `cd |
| 6210 |
/zorglub 2>/dev/null`’ works properly. |
| 6211 |
|
| 6212 |
It is worth noting that Zsh (but not Ash nor Bash) makes it possible |
| 6213 |
in assignments though: ‘foo=`cd /zorglub` 2>/dev/null’. |
| 6214 |
|
| 6215 |
Most shells, if not all (including Bash, Zsh, Ash), output traces on |
| 6216 |
stderr, even for sub-shells. This might result in undesired content if |
| 6217 |
you meant to capture the standard-error output of the inner command: |
| 6218 |
|
| 6219 |
$ ash -x -c '(eval "echo foo >&2") 2>stderr' |
| 6220 |
$ cat stderr |
| 6221 |
+ eval echo foo >&2 |
| 6222 |
+ echo foo |
| 6223 |
foo |
| 6224 |
$ bash -x -c '(eval "echo foo >&2") 2>stderr' |
| 6225 |
$ cat stderr |
| 6226 |
+ eval 'echo foo >&2' |
| 6227 |
++ echo foo |
| 6228 |
foo |
| 6229 |
$ zsh -x -c '(eval "echo foo >&2") 2>stderr' |
| 6230 |
# Traces on startup files deleted here. |
| 6231 |
$ cat stderr |
| 6232 |
+zsh:1> eval echo foo >&2 |
| 6233 |
+zsh:1> echo foo |
| 6234 |
foo |
| 6235 |
|
| 6236 |
You'll appreciate the various levels of detail... |
| 6237 |
|
| 6238 |
One workaround is to grep out uninteresting lines, hoping not to |
| 6239 |
remove good ones... |
| 6240 |
|
| 6241 |
|
| 6242 |
File: autoconf.info, Node: File System Conventions, Next: Shell Substitutions, Prev: File Descriptors, Up: Portable Shell |
| 6243 |
|
| 6244 |
10.4 File System Conventions |
| 6245 |
============================ |
| 6246 |
|
| 6247 |
While ‘autoconf’ and friends will usually be run on some Unix variety, |
| 6248 |
it can and will be used on other systems, most notably DOS variants. |
| 6249 |
This impacts several assumptions regarding file and path names. |
| 6250 |
|
| 6251 |
For example, the following code: |
| 6252 |
|
| 6253 |
case $foo_dir in |
| 6254 |
/*) # Absolute |
| 6255 |
;; |
| 6256 |
*) |
| 6257 |
foo_dir=$dots$foo_dir ;; |
| 6258 |
esac |
| 6259 |
|
| 6260 |
will fail to properly detect absolute paths on those systems, because |
| 6261 |
they can use a drivespec, and will usually use a backslash as directory |
| 6262 |
separator. The canonical way to check for absolute paths is: |
| 6263 |
|
| 6264 |
case $foo_dir in |
| 6265 |
[\\/]* | ?:[\\/]* ) # Absolute |
| 6266 |
;; |
| 6267 |
*) |
| 6268 |
foo_dir=$dots$foo_dir ;; |
| 6269 |
esac |
| 6270 |
|
| 6271 |
Make sure you quote the brackets if appropriate and keep the backslash |
| 6272 |
as first character (*note Limitations of Builtins::). |
| 6273 |
|
| 6274 |
Also, because the colon is used as part of a drivespec, these systems |
| 6275 |
don't use it as path separator. When creating or accessing paths, use |
| 6276 |
‘$ac_path_separator’ instead (or the ‘PATH_SEPARATOR’ output variable). |
| 6277 |
‘autoconf’ sets this to the appropriate value (‘:’ or ‘;’) when it |
| 6278 |
starts up. |
| 6279 |
|
| 6280 |
File names need extra care as well. While DOS-based environments |
| 6281 |
that are Unixy enough to run ‘autoconf’ (such as DJGPP) will usually be |
| 6282 |
able to handle long file names properly, there are still limitations |
| 6283 |
that can seriously break packages. Several of these issues can be |
| 6284 |
easily detected by the doschk(1) package. |
| 6285 |
|
| 6286 |
A short overview follows; problems are marked with SFN/LFN to |
| 6287 |
indicate where they apply: SFN means the issues are only relevant to |
| 6288 |
plain DOS, not to DOS boxes under Windows, while LFN identifies problems |
| 6289 |
that exist even under Windows. |
| 6290 |
|
| 6291 |
No multiple dots (SFN) |
| 6292 |
DOS cannot handle multiple dots in filenames. This is an |
| 6293 |
especially important thing to remember when building a portable |
| 6294 |
configure script, as ‘autoconf’ uses a .in suffix for template |
| 6295 |
files. |
| 6296 |
|
| 6297 |
This is perfectly OK on Unices: |
| 6298 |
|
| 6299 |
AC_CONFIG_HEADER(config.h) |
| 6300 |
AC_CONFIG_FILES([source.c foo.bar]) |
| 6301 |
AC_OUTPUT |
| 6302 |
|
| 6303 |
but it causes problems on DOS, as it requires ‘config.h.in’, |
| 6304 |
‘source.c.in’ and ‘foo.bar.in’. To make your package more portable |
| 6305 |
to DOS-based environments, you should use this instead: |
| 6306 |
|
| 6307 |
AC_CONFIG_HEADER(config.h:config.hin) |
| 6308 |
AC_CONFIG_FILES([source.c:source.cin foo.bar:foobar.in]) |
| 6309 |
AC_OUTPUT |
| 6310 |
|
| 6311 |
No leading dot (SFN) |
| 6312 |
DOS cannot handle filenames that start with a dot. This is usually |
| 6313 |
not a very important issue for ‘autoconf’. |
| 6314 |
|
| 6315 |
Case insensitivity (LFN) |
| 6316 |
DOS is case insensitive, so you cannot, for example, have both a |
| 6317 |
file called ‘INSTALL’ and a directory called ‘install’. This also |
| 6318 |
affects ‘make’; if there's a file called ‘INSTALL’ in the |
| 6319 |
directory, ‘make install’ will do nothing (unless the ‘install’ |
| 6320 |
target is marked as PHONY). |
| 6321 |
|
| 6322 |
The 8+3 limit (SFN) |
| 6323 |
Because the DOS file system only stores the first 8 characters of |
| 6324 |
the filename and the first 3 of the extension, those must be |
| 6325 |
unique. That means that ‘foobar-part1.c’, ‘foobar-part2.c’ and |
| 6326 |
‘foobar-prettybird.c’ all resolve to the same filename |
| 6327 |
(‘FOOBAR-P.C’). The same goes for ‘foo.bar’ and ‘foo.bartender’. |
| 6328 |
|
| 6329 |
Note: This is not usually a problem under Windows, as it uses |
| 6330 |
numeric tails in the short version of filenames to make them |
| 6331 |
unique. However, a registry setting can turn this behaviour off. |
| 6332 |
While this makes it possible to share file trees containing long |
| 6333 |
file names between SFN and LFN environments, it also means the |
| 6334 |
above problem applies there as well. |
| 6335 |
|
| 6336 |
Invalid characters |
| 6337 |
Some characters are invalid in DOS filenames, and should therefore |
| 6338 |
be avoided. In a LFN environment, these are ‘/’, ‘\’, ‘?’, ‘*’, |
| 6339 |
‘:’, ‘<’, ‘>’, ‘|’ and ‘"’. In a SFN environment, other characters |
| 6340 |
are also invalid. These include ‘+’, ‘,’, ‘[’ and ‘]’. |
| 6341 |
|
| 6342 |
---------- Footnotes ---------- |
| 6343 |
|
| 6344 |
(1) doschk, <ftp://ftp.gnu.org/gnu/non-gnu/doschk/doschk-1.1.tar.gz>. |
| 6345 |
|
| 6346 |
|
| 6347 |
File: autoconf.info, Node: Shell Substitutions, Next: Assignments, Prev: File System Conventions, Up: Portable Shell |
| 6348 |
|
| 6349 |
10.5 Shell Substitutions |
| 6350 |
======================== |
| 6351 |
|
| 6352 |
Contrary to a persistent urban legend, the Bourne shell does not |
| 6353 |
systematically split variables and backquoted expressions, in particular |
| 6354 |
on the right-hand side of assignments and in the argument of ‘case’. |
| 6355 |
For instance, the following code: |
| 6356 |
|
| 6357 |
case "$given_srcdir" in |
| 6358 |
.) top_srcdir="`echo "$dots" | sed 's,/$,,'`" |
| 6359 |
*) top_srcdir="$dots$given_srcdir" ;; |
| 6360 |
esac |
| 6361 |
|
| 6362 |
is more readable when written as: |
| 6363 |
|
| 6364 |
case $given_srcdir in |
| 6365 |
.) top_srcdir=`echo "$dots" | sed 's,/$,,'` |
| 6366 |
*) top_srcdir=$dots$given_srcdir ;; |
| 6367 |
esac |
| 6368 |
|
| 6369 |
and in fact it is even _more_ portable: in the first case of the first |
| 6370 |
attempt, the computation of ‘top_srcdir’ is not portable, since not all |
| 6371 |
shells properly understand ‘"`..."..."...`"’. Worse yet, not all shells |
| 6372 |
understand ‘"`...\"...\"...`"’ the same way. There is just no portable |
| 6373 |
way to use double-quoted strings inside double-quoted backquoted |
| 6374 |
expressions (pfew!). |
| 6375 |
|
| 6376 |
‘$@’ |
| 6377 |
One of the most famous shell-portability issues is related to |
| 6378 |
‘"$@"’: when there are no positional arguments, it is supposed to |
| 6379 |
be equivalent to nothing. But some shells, for instance under |
| 6380 |
Digital Unix 4.0 and 5.0, will then replace it with an empty |
| 6381 |
argument. To be portable, use ‘${1+"$@"}’. |
| 6382 |
|
| 6383 |
‘${VAR:-VALUE}’ |
| 6384 |
Old BSD shells, including the Ultrix ‘sh’, don't accept the colon |
| 6385 |
for any shell substitution, and complain and die. |
| 6386 |
|
| 6387 |
‘${VAR=LITERAL}’ |
| 6388 |
Be sure to quote: |
| 6389 |
|
| 6390 |
: ${var='Some words'} |
| 6391 |
|
| 6392 |
otherwise some shells, such as on Digital Unix V 5.0, will die |
| 6393 |
because of a "bad substitution". |
| 6394 |
|
| 6395 |
Solaris' ‘/bin/sh’ has a frightening bug in its interpretation of |
| 6396 |
this. Imagine you need set a variable to a string containing ‘}’. |
| 6397 |
This ‘}’ character confuses Solaris' ‘/bin/sh’ when the affected |
| 6398 |
variable was already set. This bug can be exercised by running: |
| 6399 |
|
| 6400 |
$ unset foo |
| 6401 |
$ foo=${foo='}'} |
| 6402 |
$ echo $foo |
| 6403 |
} |
| 6404 |
$ foo=${foo='}' # no error; this hints to what the bug is |
| 6405 |
$ echo $foo |
| 6406 |
} |
| 6407 |
$ foo=${foo='}'} |
| 6408 |
$ echo $foo |
| 6409 |
}} |
| 6410 |
^ ugh! |
| 6411 |
|
| 6412 |
It seems that ‘}’ is interpreted as matching ‘${’, even though it |
| 6413 |
is enclosed in single quotes. The problem doesn't happen using |
| 6414 |
double quotes. |
| 6415 |
|
| 6416 |
‘${VAR=EXPANDED-VALUE}’ |
| 6417 |
On Ultrix, running |
| 6418 |
|
| 6419 |
default="yu,yaa" |
| 6420 |
: ${var="$default"} |
| 6421 |
|
| 6422 |
will set VAR to ‘M-yM-uM-,M-yM-aM-a’, i.e., the 8th bit of each |
| 6423 |
char will be set. You won't observe the phenomenon using a simple |
| 6424 |
‘echo $var’ since apparently the shell resets the 8th bit when it |
| 6425 |
expands $var. Here are two means to make this shell confess its |
| 6426 |
sins: |
| 6427 |
|
| 6428 |
$ cat -v <<EOF |
| 6429 |
$var |
| 6430 |
EOF |
| 6431 |
|
| 6432 |
and |
| 6433 |
|
| 6434 |
$ set | grep '^var=' | cat -v |
| 6435 |
|
| 6436 |
One classic incarnation of this bug is: |
| 6437 |
|
| 6438 |
default="a b c" |
| 6439 |
: ${list="$default"} |
| 6440 |
for c in $list; do |
| 6441 |
echo $c |
| 6442 |
done |
| 6443 |
|
| 6444 |
You'll get ‘a b c’ on a single line. Why? Because there are no |
| 6445 |
spaces in ‘$list’: there are ‘M- ’, i.e., spaces with the 8th bit |
| 6446 |
set, hence no IFS splitting is performed!!! |
| 6447 |
|
| 6448 |
One piece of good news is that Ultrix works fine with ‘: |
| 6449 |
${list=$default}’; i.e., if you _don't_ quote. The bad news is |
| 6450 |
then that QNX 4.25 then sets LIST to the _last_ item of DEFAULT! |
| 6451 |
|
| 6452 |
The portable way out consists in using a double assignment, to |
| 6453 |
switch the 8th bit twice on Ultrix: |
| 6454 |
|
| 6455 |
list=${list="$default"} |
| 6456 |
|
| 6457 |
...but beware of the ‘}’ bug from Solaris (see above). For safety, |
| 6458 |
use: |
| 6459 |
|
| 6460 |
test "${var+set}" = set || var={VALUE} |
| 6461 |
|
| 6462 |
‘`COMMANDS`’ |
| 6463 |
While in general it makes no sense, do not substitute a single |
| 6464 |
builtin with side effects as Ash 0.2, trying to optimize, does not |
| 6465 |
fork a sub-shell to perform the command. |
| 6466 |
|
| 6467 |
For instance, if you wanted to check that ‘cd’ is silent, do not |
| 6468 |
use ‘test -z "`cd /`"’ because the following can happen: |
| 6469 |
|
| 6470 |
$ pwd |
| 6471 |
/tmp |
| 6472 |
$ test -n "`cd /`" && pwd |
| 6473 |
/ |
| 6474 |
|
| 6475 |
The result of ‘foo=`exit 1`’ is left as an exercise to the reader. |
| 6476 |
|
| 6477 |
‘$(COMMANDS)’ |
| 6478 |
This construct is meant to replace ‘`COMMANDS`’; they can be nested |
| 6479 |
while this is impossible to do portably with back quotes. |
| 6480 |
Unfortunately it is not yet widely supported. Most notably, even |
| 6481 |
recent releases of Solaris don't support it: |
| 6482 |
|
| 6483 |
$ showrev -c /bin/sh | grep version |
| 6484 |
Command version: SunOS 5.8 Generic 109324-02 February 2001 |
| 6485 |
$ echo $(echo blah) |
| 6486 |
syntax error: `(' unexpected |
| 6487 |
|
| 6488 |
nor does IRIX 6.5's Bourne shell: |
| 6489 |
$ uname -a |
| 6490 |
IRIX firebird-image 6.5 07151432 IP22 |
| 6491 |
$ echo $(echo blah) |
| 6492 |
$(echo blah) |
| 6493 |
|
| 6494 |
|
| 6495 |
File: autoconf.info, Node: Assignments, Next: Special Shell Variables, Prev: Shell Substitutions, Up: Portable Shell |
| 6496 |
|
| 6497 |
10.6 Assignments |
| 6498 |
================ |
| 6499 |
|
| 6500 |
When setting several variables in a row, be aware that the order of the |
| 6501 |
evaluation is undefined. For instance ‘foo=1 foo=2; echo $foo’ gives |
| 6502 |
‘1’ with sh on Solaris, but ‘2’ with Bash. You must use ‘;’ to enforce |
| 6503 |
the order: ‘foo=1; foo=2; echo $foo’. |
| 6504 |
|
| 6505 |
Don't rely on the exit status of an assignment: Ash 0.2 does not |
| 6506 |
change the status and propagates that of the last statement: |
| 6507 |
|
| 6508 |
$ false || foo=bar; echo $? |
| 6509 |
1 |
| 6510 |
$ false || foo=`:`; echo $? |
| 6511 |
0 |
| 6512 |
|
| 6513 |
and to make things even worse, QNX 4.25 just sets the exit status to 0 |
| 6514 |
in any case: |
| 6515 |
|
| 6516 |
$ foo=`exit 1`; echo $? |
| 6517 |
0 |
| 6518 |
|
| 6519 |
To assign default values, follow this algorithm: |
| 6520 |
|
| 6521 |
1. If the default value is a literal and does not contain any closing |
| 6522 |
brace, use: |
| 6523 |
|
| 6524 |
: ${var='my literal'} |
| 6525 |
|
| 6526 |
2. If the default value contains no closing brace, has to be expanded, |
| 6527 |
and the variable being initialized will never be IFS-split (i.e., |
| 6528 |
it's not a list), then use: |
| 6529 |
|
| 6530 |
: ${var="$default"} |
| 6531 |
|
| 6532 |
3. If the default value contains no closing brace, has to be expanded, |
| 6533 |
and the variable being initialized will be IFS-split (i.e., it's a |
| 6534 |
list), then use: |
| 6535 |
|
| 6536 |
var=${var="$default"} |
| 6537 |
|
| 6538 |
4. If the default value contains a closing brace, then use: |
| 6539 |
|
| 6540 |
test "${var+set}" = set || var='${indirection}' |
| 6541 |
|
| 6542 |
In most cases ‘var=${var="$default"}’ is fine, but in case of doubt, |
| 6543 |
just use the latter. *Note Shell Substitutions::, items ‘${VAR:-VALUE}’ |
| 6544 |
and ‘${VAR=VALUE}’ for the rationale. |
| 6545 |
|
| 6546 |
|
| 6547 |
File: autoconf.info, Node: Special Shell Variables, Next: Limitations of Builtins, Prev: Assignments, Up: Portable Shell |
| 6548 |
|
| 6549 |
10.7 Special Shell Variables |
| 6550 |
============================ |
| 6551 |
|
| 6552 |
Some shell variables should not be used, since they can have a deep |
| 6553 |
influence on the behavior of the shell. In order to recover a sane |
| 6554 |
behavior from the shell, some variables should be unset, but ‘unset’ is |
| 6555 |
not portable (*note Limitations of Builtins::) and a fallback value is |
| 6556 |
needed. We list these values below. |
| 6557 |
|
| 6558 |
‘CDPATH’ |
| 6559 |
When this variable is set ‘cd’ is verbose, so idioms such as |
| 6560 |
‘abs=`cd $rel && pwd`’ break because ‘abs’ receives the path twice. |
| 6561 |
|
| 6562 |
Setting ‘CDPATH’ to the empty value is not enough for most shells. |
| 6563 |
A simple colon is enough except for ‘zsh’, which prefers a leading |
| 6564 |
dot: |
| 6565 |
|
| 6566 |
zsh-3.1.6 % mkdir foo && (CDPATH=: cd foo) |
| 6567 |
/tmp/foo |
| 6568 |
zsh-3.1.6 % (CDPATH=:. cd foo) |
| 6569 |
/tmp/foo |
| 6570 |
zsh-3.1.6 % (CDPATH=.: cd foo) |
| 6571 |
zsh-3.1.6 % |
| 6572 |
|
| 6573 |
(of course we could just ‘unset’ ‘CDPATH’, since it also behaves |
| 6574 |
properly if set to the empty string). |
| 6575 |
|
| 6576 |
Life wouldn't be so much fun if ‘bash’ and ‘zsh’ had the same |
| 6577 |
behavior: |
| 6578 |
|
| 6579 |
bash-2.02 % (CDPATH=:. cd foo) |
| 6580 |
bash-2.02 % (CDPATH=.: cd foo) |
| 6581 |
/tmp/foo |
| 6582 |
|
| 6583 |
Therefore, a portable solution to neutralize ‘CDPATH’ is |
| 6584 |
|
| 6585 |
CDPATH=${ZSH_VERSION+.}: |
| 6586 |
|
| 6587 |
Note that since ‘zsh’ supports ‘unset’, you may unset ‘CDPATH’ |
| 6588 |
using ‘:’ as a fallback, see *note Limitations of Builtins::. |
| 6589 |
|
| 6590 |
‘IFS’ |
| 6591 |
Don't set the first character of ‘IFS’ to backslash. Indeed, |
| 6592 |
Bourne shells use the first character (backslash) when joining the |
| 6593 |
components in ‘"$@"’ and some shells then re-interpret (!) the |
| 6594 |
backslash escapes, so you can end up with backspace and other |
| 6595 |
strange characters. |
| 6596 |
|
| 6597 |
‘LANG’ |
| 6598 |
‘LC_ALL’ |
| 6599 |
‘LC_TIME’ |
| 6600 |
‘LC_CTYPE’ |
| 6601 |
‘LANGUAGE’ |
| 6602 |
‘LC_COLLATE’ |
| 6603 |
‘LC_NUMERIC’ |
| 6604 |
‘LC_MESSAGES’ |
| 6605 |
|
| 6606 |
These must not be set unconditionally because not all systems |
| 6607 |
understand e.g. ‘LANG=C’ (notably SCO). Fixing ‘LC_MESSAGES’ |
| 6608 |
prevents Solaris ‘sh’ from translating var values in ‘set’! Non-C |
| 6609 |
‘LC_CTYPE’ values break the ctype check. Fixing ‘LC_COLLATE’ makes |
| 6610 |
scripts more portable in some cases. For example, it causes the |
| 6611 |
regular expression ‘[a-z]’ to match only lower-case letters on |
| 6612 |
ASCII platforms. However, ‘[a-z]’ does not work in general even |
| 6613 |
when ‘LC_COLLATE’ is fixed; for example, it does not work for |
| 6614 |
EBCDIC platforms. For maximum portability, you should use regular |
| 6615 |
expressions like ‘[abcdefghijklmnopqrstuvwxyz]’ that list |
| 6616 |
characters explicitly instead of relying on ranges. |
| 6617 |
|
| 6618 |
_If_ one of these variables is set, you should try to unset it, |
| 6619 |
using ‘C’ as a fall back value. see *note Limitations of |
| 6620 |
Builtins::, builtin ‘unset’, for more details. |
| 6621 |
|
| 6622 |
‘NULLCMD’ |
| 6623 |
When executing the command ‘>foo’, ‘zsh’ executes ‘$NULLCMD >foo’. |
| 6624 |
The Bourne shell considers ‘NULLCMD’ is ‘:’, while ‘zsh’, even in |
| 6625 |
Bourne shell compatibility mode, sets ‘NULLCMD’ to ‘cat’. If you |
| 6626 |
forgot to set ‘NULLCMD’, your script might be suspended waiting for |
| 6627 |
data on its standard input. |
| 6628 |
|
| 6629 |
‘status’ |
| 6630 |
This variable is an alias to ‘$?’ for ‘zsh’ (at least 3.1.6), hence |
| 6631 |
read-only. Do not use it. |
| 6632 |
|
| 6633 |
‘PATH_SEPARATOR’ |
| 6634 |
On DJGPP systems, the ‘PATH_SEPARATOR’ variable can be set to |
| 6635 |
either ‘:’ or ‘;’ to control the path separator ‘bash’ uses to set |
| 6636 |
up certain environment variables (such as ‘PATH’). Since this only |
| 6637 |
works inside bash, you want autoconf to detect the regular DOS path |
| 6638 |
separator ‘;’, so it can be safely substituted in files that may |
| 6639 |
not support ‘;’ as path separator. So either unset this variable |
| 6640 |
or set it to ‘;’. |
| 6641 |
|
| 6642 |
‘RANDOM’ |
| 6643 |
Many shells provide ‘RANDOM’, a variable that returns a different |
| 6644 |
integer when used. Most of the time, its value does not change |
| 6645 |
when it is not used, but on IRIX 6.5 the value changes all the |
| 6646 |
time. This can be observed by using ‘set’. |
| 6647 |
|
| 6648 |
|
| 6649 |
File: autoconf.info, Node: Limitations of Builtins, Next: Limitations of Usual Tools, Prev: Special Shell Variables, Up: Portable Shell |
| 6650 |
|
| 6651 |
10.8 Limitations of Shell Builtins |
| 6652 |
================================== |
| 6653 |
|
| 6654 |
No, no, we are serious: some shells do have limitations! :) |
| 6655 |
|
| 6656 |
You should always keep in mind that any built-in or command may |
| 6657 |
support options, and therefore have a very different behavior with |
| 6658 |
arguments starting with a dash. For instance, the innocent ‘echo |
| 6659 |
"$word"’ can give unexpected results when ‘word’ starts with a dash. It |
| 6660 |
is often possible to avoid this problem using ‘echo "x$word"’, taking |
| 6661 |
the ‘x’ into account later in the pipe. |
| 6662 |
|
| 6663 |
‘!’ |
| 6664 |
You can't use ‘!’, you'll have to rewrite your code. |
| 6665 |
|
| 6666 |
‘break’ |
| 6667 |
The use of ‘break 2’, etcetera, is safe. |
| 6668 |
|
| 6669 |
‘case’ |
| 6670 |
You don't need to quote the argument; no splitting is performed. |
| 6671 |
|
| 6672 |
You don't need the final ‘;;’, but you should use it. |
| 6673 |
|
| 6674 |
Because of a bug in its ‘fnmatch’, ‘bash’ fails to properly handle |
| 6675 |
backslashes in character classes: |
| 6676 |
|
| 6677 |
bash-2.02$ case /tmp in [/\\]*) echo OK;; esac |
| 6678 |
bash-2.02$ |
| 6679 |
|
| 6680 |
This is extremely unfortunate, since you are likely to use this |
| 6681 |
code to handle UNIX or MS-DOS absolute paths. To work around this |
| 6682 |
bug, always put the backslash first: |
| 6683 |
|
| 6684 |
bash-2.02$ case '\TMP' in [\\/]*) echo OK;; esac |
| 6685 |
OK |
| 6686 |
bash-2.02$ case /tmp in [\\/]*) echo OK;; esac |
| 6687 |
OK |
| 6688 |
|
| 6689 |
‘echo’ |
| 6690 |
The simple ‘echo’ is probably the most surprising source of |
| 6691 |
portability troubles. It is not possible to use ‘echo’ portably |
| 6692 |
unless both options and escape sequences are omitted. New |
| 6693 |
applications which are not aiming at portability should use |
| 6694 |
‘printf’ instead of ‘echo’. |
| 6695 |
|
| 6696 |
Don't expect any option. *Note Preset Output Variables::, ‘ECHO_N’ |
| 6697 |
etc. for a means to simulate ‘-c’. |
| 6698 |
|
| 6699 |
Do not use backslashes in the arguments, as there is no consensus |
| 6700 |
on their handling. On ‘echo '\n' | wc -l’, the ‘sh’ of Digital |
| 6701 |
Unix 4.0, MIPS RISC/OS 4.52, answer 2, but the Solaris' ‘sh’, Bash |
| 6702 |
and Zsh (in ‘sh’ emulation mode) report 1. Please note that the |
| 6703 |
problem is truly ‘echo’: all the shells understand ‘'\n'’ as the |
| 6704 |
string composed of a backslash and an ‘n’. |
| 6705 |
|
| 6706 |
Because of these problems, do not pass a string containing |
| 6707 |
arbitrary characters to ‘echo’. For example, ‘echo "$foo"’ is safe |
| 6708 |
if you know that FOO's value cannot contain backslashes and cannot |
| 6709 |
start with ‘-’, but otherwise you should use a here-document like |
| 6710 |
this: |
| 6711 |
|
| 6712 |
cat <<EOF |
| 6713 |
$foo |
| 6714 |
EOF |
| 6715 |
|
| 6716 |
‘exit’ |
| 6717 |
The default value of ‘exit’ is supposed to be ‘$?’; unfortunately, |
| 6718 |
some shells, such as the DJGPP port of Bash 2.04, just perform |
| 6719 |
‘exit 0’. |
| 6720 |
|
| 6721 |
bash-2.04$ foo=`exit 1` || echo fail |
| 6722 |
fail |
| 6723 |
bash-2.04$ foo=`(exit 1)` || echo fail |
| 6724 |
fail |
| 6725 |
bash-2.04$ foo=`(exit 1); exit` || echo fail |
| 6726 |
bash-2.04$ |
| 6727 |
|
| 6728 |
Using ‘exit $?’ restores the expected behavior. |
| 6729 |
|
| 6730 |
Some shell scripts, such as those generated by ‘autoconf’, use a |
| 6731 |
trap to clean up before exiting. If the last shell command exited |
| 6732 |
with nonzero status, the trap also exits with nonzero status so |
| 6733 |
that the invoker can tell that an error occurred. |
| 6734 |
|
| 6735 |
Unfortunately, in some shells, such as Solaris 8 ‘sh’, an exit trap |
| 6736 |
ignores the ‘exit’ command's status. In these shells, a trap |
| 6737 |
cannot determine whether it was invoked by plain ‘exit’ or by ‘exit |
| 6738 |
1’. Instead of calling ‘exit’ directly, use the ‘AC_MSG_ERROR’ |
| 6739 |
macro that has a workaround for this problem. |
| 6740 |
|
| 6741 |
‘export’ |
| 6742 |
The builtin ‘export’ dubs “environment variable” a shell variable. |
| 6743 |
Each update of exported variables corresponds to an update of the |
| 6744 |
environment variables. Conversely, each environment variable |
| 6745 |
received by the shell when it is launched should be imported as a |
| 6746 |
shell variable marked as exported. |
| 6747 |
|
| 6748 |
Alas, many shells, such as Solaris 2.5, IRIX 6.3, IRIX 5.2, AIX |
| 6749 |
4.1.5 and DU 4.0, forget to ‘export’ the environment variables they |
| 6750 |
receive. As a result, two variables are coexisting: the |
| 6751 |
environment variable and the shell variable. The following code |
| 6752 |
demonstrates this failure: |
| 6753 |
|
| 6754 |
#! /bin/sh |
| 6755 |
echo $FOO |
| 6756 |
FOO=bar |
| 6757 |
echo $FOO |
| 6758 |
exec /bin/sh $0 |
| 6759 |
|
| 6760 |
when run with ‘FOO=foo’ in the environment, these shells will print |
| 6761 |
alternately ‘foo’ and ‘bar’, although it should only print ‘foo’ |
| 6762 |
and then a sequence of ‘bar’s. |
| 6763 |
|
| 6764 |
Therefore you should ‘export’ again each environment variable that |
| 6765 |
you update. |
| 6766 |
|
| 6767 |
‘false’ |
| 6768 |
Don't expect ‘false’ to exit with status 1: in the native Bourne |
| 6769 |
shell of Solaris 8, it exits with status 255. |
| 6770 |
|
| 6771 |
‘for’ |
| 6772 |
To loop over positional arguments, use: |
| 6773 |
|
| 6774 |
for arg |
| 6775 |
do |
| 6776 |
echo "$arg" |
| 6777 |
done |
| 6778 |
|
| 6779 |
You may _not_ leave the ‘do’ on the same line as ‘for’, since some |
| 6780 |
shells improperly grok: |
| 6781 |
|
| 6782 |
for arg; do |
| 6783 |
echo "$arg" |
| 6784 |
done |
| 6785 |
|
| 6786 |
If you want to explicitly refer to the positional arguments, given |
| 6787 |
the ‘$@’ bug (*note Shell Substitutions::), use: |
| 6788 |
|
| 6789 |
for arg in ${1+"$@"}; do |
| 6790 |
echo "$arg" |
| 6791 |
done |
| 6792 |
|
| 6793 |
‘if’ |
| 6794 |
Using ‘!’ is not portable. Instead of: |
| 6795 |
|
| 6796 |
if ! cmp -s file file.new; then |
| 6797 |
mv file.new file |
| 6798 |
fi |
| 6799 |
|
| 6800 |
use: |
| 6801 |
|
| 6802 |
if cmp -s file file.new; then :; else |
| 6803 |
mv file.new file |
| 6804 |
fi |
| 6805 |
|
| 6806 |
There are shells that do not reset the exit status from an ‘if’: |
| 6807 |
|
| 6808 |
$ if (exit 42); then true; fi; echo $? |
| 6809 |
42 |
| 6810 |
|
| 6811 |
whereas a proper shell should have printed ‘0’. This is especially |
| 6812 |
bad in Makefiles since it produces false failures. This is why |
| 6813 |
properly written Makefiles, such as Automake's, have such hairy |
| 6814 |
constructs: |
| 6815 |
|
| 6816 |
if test -f "$file"; then |
| 6817 |
install "$file" "$dest" |
| 6818 |
else |
| 6819 |
: |
| 6820 |
fi |
| 6821 |
|
| 6822 |
‘set’ |
| 6823 |
This builtin faces the usual problem with arguments starting with a |
| 6824 |
dash. Modern shells such as Bash or Zsh understand ‘--’ to specify |
| 6825 |
the end of the options (any argument after ‘--’ is a parameters, |
| 6826 |
even ‘-x’ for instance), but most shells simply stop the option |
| 6827 |
processing as soon as a non-option argument is found. Therefore, |
| 6828 |
use ‘dummy’ or simply ‘x’ to end the option processing, and use |
| 6829 |
‘shift’ to pop it out: |
| 6830 |
|
| 6831 |
set x $my_list; shift |
| 6832 |
|
| 6833 |
‘shift’ |
| 6834 |
Not only is ‘shift’ing a bad idea when there is nothing left to |
| 6835 |
shift, but in addition it is not portable: the shell of MIPS |
| 6836 |
RISC/OS 4.52 refuses to do it. |
| 6837 |
|
| 6838 |
‘test’ |
| 6839 |
The ‘test’ program is the way to perform many file and string |
| 6840 |
tests. It is often invoked by the alternate name ‘[’, but using |
| 6841 |
that name in Autoconf code is asking for trouble since it is an M4 |
| 6842 |
quote character. |
| 6843 |
|
| 6844 |
If you need to make multiple checks using ‘test’, combine them with |
| 6845 |
the shell operators ‘&&’ and ‘||’ instead of using the ‘test’ |
| 6846 |
operators ‘-a’ and ‘-o’. On System V, the precedence of ‘-a’ and |
| 6847 |
‘-o’ is wrong relative to the unary operators; consequently, POSIX |
| 6848 |
does not specify them, so using them is nonportable. If you |
| 6849 |
combine ‘&&’ and ‘||’ in the same statement, keep in mind that they |
| 6850 |
have equal precedence. |
| 6851 |
|
| 6852 |
You may use ‘!’ with ‘test’, but not with ‘if’: ‘test ! -r foo || |
| 6853 |
exit 1’. |
| 6854 |
|
| 6855 |
‘test’ (files) |
| 6856 |
To enable ‘configure’ scripts to support cross-compilation, they |
| 6857 |
shouldn't do anything that tests features of the build system |
| 6858 |
instead of the host system. But occasionally you may find it |
| 6859 |
necessary to check whether some arbitrary file exists. To do so, |
| 6860 |
use ‘test -f’ or ‘test -r’. Do not use ‘test -x’, because 4.3BSD |
| 6861 |
does not have it. Do not use ‘test -e’ either, because Solaris 2.5 |
| 6862 |
does not have it. |
| 6863 |
|
| 6864 |
‘test’ (strings) |
| 6865 |
Avoid ‘test "STRING"’, in particular if STRING might start with a |
| 6866 |
dash, since ‘test’ might interpret its argument as an option (e.g., |
| 6867 |
‘STRING = "-n"’). |
| 6868 |
|
| 6869 |
Contrary to a common belief, ‘test -n STRING’ and ‘test -z STRING’ |
| 6870 |
*are* portable, nevertheless many shells (such as Solaris 2.5, AIX |
| 6871 |
3.2, UNICOS 10.0.0.6, Digital Unix 4 etc.) have bizarre precedence |
| 6872 |
and may be confused if STRING looks like an operator: |
| 6873 |
|
| 6874 |
$ test -n = |
| 6875 |
test: argument expected |
| 6876 |
|
| 6877 |
If there are risks, use ‘test "xSTRING" = x’ or ‘test "xSTRING" != |
| 6878 |
x’ instead. |
| 6879 |
|
| 6880 |
It is frequent to find variations of the following idiom: |
| 6881 |
|
| 6882 |
test -n "`echo $ac_feature | sed 's/[-a-zA-Z0-9_]//g'`" && |
| 6883 |
ACTION |
| 6884 |
|
| 6885 |
to take an action when a token matches a given pattern. Such |
| 6886 |
constructs should always be avoided by using: |
| 6887 |
|
| 6888 |
echo "$ac_feature" | grep '[^-a-zA-Z0-9_]' >/dev/null 2>&1 && |
| 6889 |
ACTION |
| 6890 |
|
| 6891 |
Use ‘case’ where possible since it is faster, being a shell |
| 6892 |
builtin: |
| 6893 |
|
| 6894 |
case $ac_feature in |
| 6895 |
*[!-a-zA-Z0-9_]*) ACTION;; |
| 6896 |
esac |
| 6897 |
|
| 6898 |
Alas, negated character classes are probably not portable, although |
| 6899 |
no shell is known to not support the POSIX.2 syntax ‘[!...]’ (when |
| 6900 |
in interactive mode, ‘zsh’ is confused by the ‘[!...]’ syntax and |
| 6901 |
looks for an event in its history because of ‘!’). Many shells do |
| 6902 |
not support the alternative syntax ‘[^...]’ (Solaris, Digital Unix, |
| 6903 |
etc.). |
| 6904 |
|
| 6905 |
One solution can be: |
| 6906 |
|
| 6907 |
expr "$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null && |
| 6908 |
ACTION |
| 6909 |
|
| 6910 |
or better yet |
| 6911 |
|
| 6912 |
expr "x$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null && |
| 6913 |
ACTION |
| 6914 |
|
| 6915 |
‘expr "XFOO" : "XBAR"’ is more robust than ‘echo "XFOO" | grep |
| 6916 |
"^XBAR"’, because it avoids problems when ‘FOO’ contains |
| 6917 |
backslashes. |
| 6918 |
|
| 6919 |
‘trap’ |
| 6920 |
It is safe to trap at least the signals 1, 2, 13 and 15. You can |
| 6921 |
also trap 0, i.e., have the ‘trap’ run when the script ends (either |
| 6922 |
via an explicit ‘exit’, or the end of the script). |
| 6923 |
|
| 6924 |
Although POSIX is not absolutely clear on this point, it is widely |
| 6925 |
admitted that when entering the trap ‘$?’ should be set to the exit |
| 6926 |
status of the last command run before the trap. The ambiguity can |
| 6927 |
be summarized as: "when the trap is launched by an ‘exit’, what is |
| 6928 |
the _last_ command run: that before ‘exit’, or ‘exit’ itself?" |
| 6929 |
|
| 6930 |
Bash considers ‘exit’ to be the last command, while Zsh and Solaris |
| 6931 |
8 ‘sh’ consider that when the trap is run it is _still_ in the |
| 6932 |
‘exit’, hence it is the previous exit status that the trap |
| 6933 |
receives: |
| 6934 |
|
| 6935 |
$ cat trap.sh |
| 6936 |
trap 'echo $?' 0 |
| 6937 |
(exit 42); exit 0 |
| 6938 |
$ zsh trap.sh |
| 6939 |
42 |
| 6940 |
$ bash trap.sh |
| 6941 |
0 |
| 6942 |
|
| 6943 |
The portable solution is then simple: when you want to ‘exit 42’, |
| 6944 |
run ‘(exit 42); exit 42’, the first ‘exit’ being used to set the |
| 6945 |
exit status to 42 for Zsh, and the second to trigger the trap and |
| 6946 |
pass 42 as exit status for Bash. |
| 6947 |
|
| 6948 |
The shell in FreeBSD 4.0 has the following bug: ‘$?’ is reset to 0 |
| 6949 |
by empty lines if the code is inside ‘trap’. |
| 6950 |
|
| 6951 |
$ trap 'false |
| 6952 |
|
| 6953 |
echo $?' 0 |
| 6954 |
$ exit |
| 6955 |
0 |
| 6956 |
|
| 6957 |
Fortunately, this bug only affects ‘trap’. |
| 6958 |
|
| 6959 |
‘true’ |
| 6960 |
Don't worry: as far as we know ‘true’ is portable. Nevertheless, |
| 6961 |
it's not always a builtin (e.g., Bash 1.x), and the portable shell |
| 6962 |
community tends to prefer using ‘:’. This has a funny side effect: |
| 6963 |
when asked whether ‘false’ is more portable than ‘true’ Alexandre |
| 6964 |
Oliva answered: |
| 6965 |
|
| 6966 |
In a sense, yes, because if it doesn't exist, the shell will |
| 6967 |
produce an exit status of failure, which is correct for |
| 6968 |
‘false’, but not for ‘true’. |
| 6969 |
|
| 6970 |
‘unset’ |
| 6971 |
You cannot assume the support of ‘unset’, nevertheless, because it |
| 6972 |
is extremely useful to disable embarrassing variables such as |
| 6973 |
‘CDPATH’ or ‘LANG’, you can test for its existence and use it |
| 6974 |
_provided_ you give a neutralizing value when ‘unset’ is not |
| 6975 |
supported: |
| 6976 |
|
| 6977 |
if (unset FOO) >/dev/null 2>&1; then |
| 6978 |
unset=unset |
| 6979 |
else |
| 6980 |
unset=false |
| 6981 |
fi |
| 6982 |
$unset CDPATH || CDPATH=: |
| 6983 |
|
| 6984 |
*Note Special Shell Variables::, for some neutralizing values. |
| 6985 |
Also, see *note Limitations of Builtins::, documentation of |
| 6986 |
‘export’, for the case of environment variables. |
| 6987 |
|
| 6988 |
|
| 6989 |
File: autoconf.info, Node: Limitations of Usual Tools, Next: Limitations of Make, Prev: Limitations of Builtins, Up: Portable Shell |
| 6990 |
|
| 6991 |
10.9 Limitations of Usual Tools |
| 6992 |
=============================== |
| 6993 |
|
| 6994 |
The small set of tools you can expect to find on any machine can still |
| 6995 |
include some limitations you should be aware of. |
| 6996 |
|
| 6997 |
‘awk’ |
| 6998 |
Don't leave white spaces before the parentheses in user functions |
| 6999 |
calls, GNU awk will reject it: |
| 7000 |
|
| 7001 |
$ gawk 'function die () { print "Aaaaarg!" } |
| 7002 |
BEGIN { die () }' |
| 7003 |
gawk: cmd. line:2: BEGIN { die () } |
| 7004 |
gawk: cmd. line:2: ^ parse error |
| 7005 |
$ gawk 'function die () { print "Aaaaarg!" } |
| 7006 |
BEGIN { die() }' |
| 7007 |
Aaaaarg! |
| 7008 |
|
| 7009 |
If you want your program to be deterministic, don't depend on ‘for’ |
| 7010 |
on arrays: |
| 7011 |
|
| 7012 |
$ cat for.awk |
| 7013 |
END { |
| 7014 |
arr["foo"] = 1 |
| 7015 |
arr["bar"] = 1 |
| 7016 |
for (i in arr) |
| 7017 |
print i |
| 7018 |
} |
| 7019 |
$ gawk -f for.awk </dev/null |
| 7020 |
foo |
| 7021 |
bar |
| 7022 |
$ nawk -f for.awk </dev/null |
| 7023 |
bar |
| 7024 |
foo |
| 7025 |
|
| 7026 |
Some AWK, such as HPUX 11.0's native one, have regex engines |
| 7027 |
fragile to inner anchors: |
| 7028 |
|
| 7029 |
$ echo xfoo | $AWK '/foo|^bar/ { print }' |
| 7030 |
$ echo bar | $AWK '/foo|^bar/ { print }' |
| 7031 |
bar |
| 7032 |
$ echo xfoo | $AWK '/^bar|foo/ { print }' |
| 7033 |
xfoo |
| 7034 |
$ echo bar | $AWK '/^bar|foo/ { print }' |
| 7035 |
bar |
| 7036 |
|
| 7037 |
Either do not depend on such patterns (i.e., use ‘/^(.*foo|bar)/’, |
| 7038 |
or use a simple test to reject such AWK. |
| 7039 |
|
| 7040 |
‘cat’ |
| 7041 |
Don't rely on any option. The option ‘-v’, which displays |
| 7042 |
non-printing characters, _seems_ portable, though. |
| 7043 |
|
| 7044 |
‘cc’ |
| 7045 |
When a compilation such as ‘cc foo.c -o foo’ fails, some compilers |
| 7046 |
(such as CDS on Reliant UNIX) leave a ‘foo.o’. |
| 7047 |
|
| 7048 |
‘cmp’ |
| 7049 |
‘cmp’ performs a raw data comparison of two files, while ‘diff’ |
| 7050 |
compares two text files. Therefore, if you might compare DOS |
| 7051 |
files, even if only checking whether two files are different, use |
| 7052 |
‘diff’ to avoid spurious differences due to differences of newline |
| 7053 |
encoding. |
| 7054 |
|
| 7055 |
‘cp’ |
| 7056 |
SunOS ‘cp’ does not support ‘-f’, although its ‘mv’ does. It's |
| 7057 |
possible to deduce why ‘mv’ and ‘cp’ are different with respect to |
| 7058 |
‘-f’. ‘mv’ prompts by default before overwriting a read-only file. |
| 7059 |
‘cp’ does not. Therefore, ‘mv’ requires a ‘-f’ option, but ‘cp’ |
| 7060 |
does not. ‘mv’ and ‘cp’ behave differently with respect to |
| 7061 |
read-only files because the simplest form of ‘cp’ cannot overwrite |
| 7062 |
a read-only file, but the simplest form of ‘mv’ can. This is |
| 7063 |
because ‘cp’ opens the target for write access, whereas ‘mv’ simply |
| 7064 |
calls ‘link’ (or, in newer systems, ‘rename’). |
| 7065 |
|
| 7066 |
‘diff’ |
| 7067 |
Option ‘-u’ is nonportable. |
| 7068 |
|
| 7069 |
Some implementations, such as Tru64's, fail when comparing to |
| 7070 |
‘/dev/null’. Use an empty file instead. |
| 7071 |
|
| 7072 |
‘dirname’ |
| 7073 |
Not all hosts have ‘dirname’, but it is reasonably easy to emulate, |
| 7074 |
e.g.: |
| 7075 |
|
| 7076 |
dir=`expr "x$file" : 'x\(.*\)/[^/]*' \| |
| 7077 |
'.' : '.' |
| 7078 |
|
| 7079 |
But there are a few subtilities, e.g., under UN*X, should ‘//1’ |
| 7080 |
give ‘/’? Paul Eggert answers: |
| 7081 |
|
| 7082 |
No, under some older flavors of Unix, leading ‘//’ is a |
| 7083 |
special path name: it refers to a "super-root" and is used to |
| 7084 |
access other machines' files. Leading ‘///’, ‘////’, etc. |
| 7085 |
are equivalent to ‘/’; but leading ‘//’ is special. I think |
| 7086 |
this tradition started with Apollo Domain/OS, an OS that is |
| 7087 |
still in use on some older hosts. |
| 7088 |
|
| 7089 |
POSIX.2 allows but does not require the special treatment for |
| 7090 |
‘//’. It says that the behavior of dirname on path names of |
| 7091 |
the form ‘//([^/]+/*)?’ is implementation defined. In these |
| 7092 |
cases, GNU ‘dirname’ returns ‘/’, but it's more portable to |
| 7093 |
return ‘//’ as this works even on those older flavors of Unix. |
| 7094 |
|
| 7095 |
I have heard rumors that this special treatment of ‘//’ may be |
| 7096 |
dropped in future versions of POSIX, but for now it's still |
| 7097 |
the standard. |
| 7098 |
|
| 7099 |
‘egrep’ |
| 7100 |
The empty alternative is not portable, use ‘?’ instead. For |
| 7101 |
instance with Digital Unix v5.0: |
| 7102 |
|
| 7103 |
> printf "foo\n|foo\n" | egrep '^(|foo|bar)$' |
| 7104 |
|foo |
| 7105 |
> printf "bar\nbar|\n" | egrep '^(foo|bar|)$' |
| 7106 |
bar| |
| 7107 |
> printf "foo\nfoo|\n|bar\nbar\n" | egrep '^(foo||bar)$' |
| 7108 |
foo |
| 7109 |
|bar |
| 7110 |
|
| 7111 |
‘egrep’ also suffers the limitations of ‘grep’. |
| 7112 |
|
| 7113 |
‘expr’ |
| 7114 |
No ‘expr’ keyword starts with ‘x’, so use ‘expr x"WORD" : 'xREGEX'’ |
| 7115 |
to keep ‘expr’ from misinterpreting WORD. |
| 7116 |
|
| 7117 |
Don't use ‘length’, ‘substr’, ‘match’ and ‘index’. |
| 7118 |
|
| 7119 |
‘expr’ (‘|’) |
| 7120 |
You can use ‘|’. Although POSIX does require that ‘expr ''’ return |
| 7121 |
the empty string, it does not specify the result when you ‘|’ |
| 7122 |
together the empty string (or zero) with the empty string. For |
| 7123 |
example: |
| 7124 |
|
| 7125 |
expr '' \| '' |
| 7126 |
|
| 7127 |
GNU/Linux and POSIX.2-1992 return the empty string for this case, |
| 7128 |
but traditional Unix returns ‘0’ (Solaris is one such example). In |
| 7129 |
the latest POSIX draft, the specification has been changed to match |
| 7130 |
traditional Unix's behavior (which is bizarre, but it's too late to |
| 7131 |
fix this). Please note that the same problem does arise when the |
| 7132 |
empty string results from a computation, as in: |
| 7133 |
|
| 7134 |
expr bar : foo \| foo : bar |
| 7135 |
|
| 7136 |
Avoid this portability problem by avoiding the empty string. |
| 7137 |
|
| 7138 |
‘expr’ (‘:’) |
| 7139 |
Don't use ‘\?’, ‘\+’ and ‘\|’ in patterns, they are not supported |
| 7140 |
on Solaris. |
| 7141 |
|
| 7142 |
The POSIX.2-1992 standard is ambiguous as to whether ‘expr a : b’ |
| 7143 |
(and ‘expr 'a' : '\(b\)'’) output ‘0’ or the empty string. In |
| 7144 |
practice, it outputs the empty string on most platforms, but |
| 7145 |
portable scripts should not assume this. For instance, the QNX |
| 7146 |
4.25 native ‘expr’ returns ‘0’. |
| 7147 |
|
| 7148 |
You may believe that one means to get a uniform behavior would be |
| 7149 |
to use the empty string as a default value: |
| 7150 |
|
| 7151 |
expr a : b \| '' |
| 7152 |
|
| 7153 |
unfortunately this behaves exactly as the original expression, see |
| 7154 |
the ‘‘expr’ (‘:’)’ entry for more information. |
| 7155 |
|
| 7156 |
Older ‘expr’ implementations (e.g. SunOS 4 ‘expr’ and Solaris 8 |
| 7157 |
‘/usr/ucb/expr’) have a silly length limit that causes ‘expr’ to |
| 7158 |
fail if the matched substring is longer than 120 bytes. In this |
| 7159 |
case, you might want to fall back on ‘echo|sed’ if ‘expr’ fails. |
| 7160 |
|
| 7161 |
Don't leave, there is some more! |
| 7162 |
|
| 7163 |
The QNX 4.25 ‘expr’, in addition of preferring ‘0’ to the empty |
| 7164 |
string, has a funny behavior in its exit status: it's always 1 when |
| 7165 |
parentheses are used! |
| 7166 |
|
| 7167 |
$ val=`expr 'a' : 'a'`; echo "$?: $val" |
| 7168 |
0: 1 |
| 7169 |
$ val=`expr 'a' : 'b'`; echo "$?: $val" |
| 7170 |
1: 0 |
| 7171 |
|
| 7172 |
$ val=`expr 'a' : '\(a\)'`; echo "?: $val" |
| 7173 |
1: a |
| 7174 |
$ val=`expr 'a' : '\(b\)'`; echo "?: $val" |
| 7175 |
1: 0 |
| 7176 |
|
| 7177 |
In practice this can be a big problem if you are ready to catch |
| 7178 |
failures of ‘expr’ programs with some other method (such as using |
| 7179 |
‘sed’), since you may get twice the result. For instance |
| 7180 |
|
| 7181 |
$ expr 'a' : '\(a\)' || echo 'a' | sed 's/^\(a\)$/\1/' |
| 7182 |
|
| 7183 |
will output ‘a’ on most hosts, but ‘aa’ on QNX 4.25. A simple work |
| 7184 |
around consists in testing ‘expr’ and use a variable set to ‘expr’ |
| 7185 |
or to ‘false’ according to the result. |
| 7186 |
|
| 7187 |
‘find’ |
| 7188 |
The option ‘-maxdepth’ seems to be GNU specific. Tru64 v5.1, |
| 7189 |
NetBSD 1.5 and Solaris 2.5 ‘find’ commands do not understand it. |
| 7190 |
|
| 7191 |
‘grep’ |
| 7192 |
Don't use ‘grep -s’ to suppress output, because ‘grep -s’ on System |
| 7193 |
V does not suppress output, only error messages. Instead, redirect |
| 7194 |
the standard output and standard error (in case the file doesn't |
| 7195 |
exist) of ‘grep’ to ‘/dev/null’. Check the exit status of ‘grep’ |
| 7196 |
to determine whether it found a match. |
| 7197 |
|
| 7198 |
Don't use multiple regexps with ‘-e’, as some ‘grep’ will only |
| 7199 |
honor the last pattern (eg., IRIX 6.5 and Solaris 2.5.1). Anyway, |
| 7200 |
Stardent Vistra SVR4 ‘grep’ lacks ‘-e’... Instead, use alternation |
| 7201 |
and ‘egrep’. |
| 7202 |
|
| 7203 |
‘ln’ |
| 7204 |
Don't rely on ‘ln’ having a ‘-f’ option. Symbolic links are not |
| 7205 |
available on old systems, use ‘ln’ as a fall back. |
| 7206 |
|
| 7207 |
For versions of the DJGPP before 2.04, ‘ln’ emulates soft links for |
| 7208 |
executables by generating a stub that in turn calls the real |
| 7209 |
program. This feature also works with nonexistent files like in |
| 7210 |
the Unix spec. So ‘ln -s file link’ will generate ‘link.exe’, |
| 7211 |
which will attempt to call ‘file.exe’ if run. But this feature |
| 7212 |
only works for executables, so ‘cp -p’ is used instead for these |
| 7213 |
systems. DJGPP versions 2.04 and later have full symlink support. |
| 7214 |
|
| 7215 |
‘mv’ |
| 7216 |
The only portable options are ‘-f’ and ‘-i’. |
| 7217 |
|
| 7218 |
Moving individual files between file systems is portable (it was in |
| 7219 |
V6), but it is not always atomic: when doing ‘mv new existing’, |
| 7220 |
there's a critical section where neither the old nor the new |
| 7221 |
version of ‘existing’ actually exists. |
| 7222 |
|
| 7223 |
Moving directories across mount points is not portable, use ‘cp’ |
| 7224 |
and ‘rm’. |
| 7225 |
|
| 7226 |
‘sed’ |
| 7227 |
Patterns should not include the separator (unless escaped), even as |
| 7228 |
part of a character class. In conformance with POSIX, the Cray |
| 7229 |
‘sed’ will reject ‘s/[^/]*$//’: use ‘s,[^/]*$,,’. |
| 7230 |
|
| 7231 |
Sed scripts should not use branch labels longer than 8 characters |
| 7232 |
and should not contain comments. |
| 7233 |
|
| 7234 |
Don't include extra ‘;’, as some ‘sed’, such as NetBSD 1.4.2's, try |
| 7235 |
to interpret the second as a command: |
| 7236 |
|
| 7237 |
$ echo a | sed 's/x/x/;;s/x/x/' |
| 7238 |
sed: 1: "s/x/x/;;s/x/x/": invalid command code ; |
| 7239 |
|
| 7240 |
Input should have reasonably long lines, since some ‘sed’ have an |
| 7241 |
input buffer limited to 4000 bytes. |
| 7242 |
|
| 7243 |
Alternation, ‘\|’, is common but not portable. Anchors (‘^’ and |
| 7244 |
‘$’) inside groups are not portable. |
| 7245 |
|
| 7246 |
Nested groups are extremely portable, but there is at least one |
| 7247 |
‘sed’ (System V/68 Base Operating System R3V7.1) that does not |
| 7248 |
support it. |
| 7249 |
|
| 7250 |
Of course the option ‘-e’ is portable, but it is not needed. No |
| 7251 |
valid Sed program can start with a dash, so it does not help |
| 7252 |
disambiguating. Its sole usefulness is helping enforcing indenting |
| 7253 |
as in: |
| 7254 |
|
| 7255 |
sed -e INSTRUCTION-1 \ |
| 7256 |
-e INSTRUCTION-2 |
| 7257 |
|
| 7258 |
as opposed to |
| 7259 |
|
| 7260 |
sed INSTRUCTION-1;INSTRUCTION-2 |
| 7261 |
|
| 7262 |
Contrary to yet another urban legend, you may portably use ‘&’ in |
| 7263 |
the replacement part of the ‘s’ command to mean "what was matched". |
| 7264 |
|
| 7265 |
‘sed’ (‘t’) |
| 7266 |
Some old systems have ‘sed’ that "forget" to reset their ‘t’ flag |
| 7267 |
when starting a new cycle. For instance on MIPS RISC/OS, and on |
| 7268 |
IRIX 5.3, if you run the following ‘sed’ script (the line numbers |
| 7269 |
are not actual part of the texts): |
| 7270 |
|
| 7271 |
s/keep me/kept/g # a |
| 7272 |
t end # b |
| 7273 |
s/.*/deleted/g # c |
| 7274 |
: end # d |
| 7275 |
|
| 7276 |
on |
| 7277 |
|
| 7278 |
delete me # 1 |
| 7279 |
delete me # 2 |
| 7280 |
keep me # 3 |
| 7281 |
delete me # 4 |
| 7282 |
|
| 7283 |
you get |
| 7284 |
|
| 7285 |
deleted |
| 7286 |
delete me |
| 7287 |
kept |
| 7288 |
deleted |
| 7289 |
|
| 7290 |
instead of |
| 7291 |
|
| 7292 |
deleted |
| 7293 |
deleted |
| 7294 |
kept |
| 7295 |
deleted |
| 7296 |
|
| 7297 |
Why? When processing 1, a matches, therefore sets the t flag, b |
| 7298 |
jumps to d, and the output is produced. When processing line 2, |
| 7299 |
the t flag is still set (this is the bug). Line a fails to match, |
| 7300 |
but ‘sed’ is not supposed to clear the t flag when a substitution |
| 7301 |
fails. Line b sees that the flag is set, therefore it clears it, |
| 7302 |
and jumps to d, hence you get ‘delete me’ instead of ‘deleted’. |
| 7303 |
When processing 3 t is clear, a matches, so the flag is set, hence |
| 7304 |
b clears the flags and jumps. Finally, since the flag is clear, 4 |
| 7305 |
is processed properly. |
| 7306 |
|
| 7307 |
There are two things one should remind about ‘t’ in ‘sed’. |
| 7308 |
Firstly, always remember that ‘t’ jumps if _some_ substitution |
| 7309 |
succeeded, not only the immediately preceding substitution, |
| 7310 |
therefore, always use a fake ‘t clear; : clear’ to reset the t flag |
| 7311 |
where indeed. |
| 7312 |
|
| 7313 |
Secondly, you cannot rely on ‘sed’ to clear the flag at each new |
| 7314 |
cycle. |
| 7315 |
|
| 7316 |
One portable implementation of the script above is: |
| 7317 |
|
| 7318 |
t clear |
| 7319 |
: clear |
| 7320 |
s/keep me/kept/g |
| 7321 |
t end |
| 7322 |
s/.*/deleted/g |
| 7323 |
: end |
| 7324 |
|
| 7325 |
‘touch’ |
| 7326 |
On some old BSD systems, ‘touch’ or any command that results in an |
| 7327 |
empty file does not update the timestamps, so use a command like |
| 7328 |
‘echo’ as a workaround. |
| 7329 |
|
| 7330 |
GNU ‘touch’ 3.16r (and presumably all before that) fails to work on |
| 7331 |
SunOS 4.1.3 when the empty file is on an NFS-mounted 4.2 volume. |
| 7332 |
|
| 7333 |
|
| 7334 |
File: autoconf.info, Node: Limitations of Make, Prev: Limitations of Usual Tools, Up: Portable Shell |
| 7335 |
|
| 7336 |
10.10 Limitations of Make |
| 7337 |
========================= |
| 7338 |
|
| 7339 |
Make itself suffers a great number of limitations, only a few of which |
| 7340 |
being listed here. First of all, remember that since commands are |
| 7341 |
executed by the shell, all its weaknesses are inherited... |
| 7342 |
|
| 7343 |
Leading underscore in macro names |
| 7344 |
Some Make don't support leading underscores in macro names, such as |
| 7345 |
on NEWS-OS 4.2R. |
| 7346 |
|
| 7347 |
$ cat Makefile |
| 7348 |
_am_include = # |
| 7349 |
_am_quote = |
| 7350 |
all:; @echo this is test |
| 7351 |
|
| 7352 |
% make |
| 7353 |
Make: Must be a separator on rules line 2. Stop. |
| 7354 |
|
| 7355 |
$ cat Makefile2 |
| 7356 |
am_include = # |
| 7357 |
am_quote = |
| 7358 |
all:; @echo this is test |
| 7359 |
|
| 7360 |
$ make -f Makefile2 |
| 7361 |
this is test |
| 7362 |
|
| 7363 |
‘VPATH’ |
| 7364 |
Don't use it! For instance any assignment to ‘VPATH’ causes Sun |
| 7365 |
‘make’ to only execute the first set of double-colon rules. |
| 7366 |
|
| 7367 |
|
| 7368 |
File: autoconf.info, Node: Manual Configuration, Next: Site Configuration, Prev: Portable Shell, Up: Top |
| 7369 |
|
| 7370 |
11 Manual Configuration |
| 7371 |
*********************** |
| 7372 |
|
| 7373 |
A few kinds of features can't be guessed automatically by running test |
| 7374 |
programs. For example, the details of the object-file format, or |
| 7375 |
special options that need to be passed to the compiler or linker. You |
| 7376 |
can check for such features using ad-hoc means, such as having |
| 7377 |
‘configure’ check the output of the ‘uname’ program, or looking for |
| 7378 |
libraries that are unique to particular systems. However, Autoconf |
| 7379 |
provides a uniform method for handling unguessable features. |
| 7380 |
|
| 7381 |
* Menu: |
| 7382 |
|
| 7383 |
* Specifying Names:: Specifying the system type |
| 7384 |
* Canonicalizing:: Getting the canonical system type |
| 7385 |
* Using System Type:: What to do with the system type |
| 7386 |
|
| 7387 |
|
| 7388 |
File: autoconf.info, Node: Specifying Names, Next: Canonicalizing, Prev: Manual Configuration, Up: Manual Configuration |
| 7389 |
|
| 7390 |
11.1 Specifying the System Type |
| 7391 |
=============================== |
| 7392 |
|
| 7393 |
Like other GNU ‘configure’ scripts, Autoconf-generated ‘configure’ |
| 7394 |
scripts can make decisions based on a canonical name for the system |
| 7395 |
type, which has the form: ‘CPU-VENDOR-OS’, where OS can be ‘SYSTEM’ or |
| 7396 |
‘KERNEL-SYSTEM’ |
| 7397 |
|
| 7398 |
‘configure’ can usually guess the canonical name for the type of |
| 7399 |
system it's running on. To do so it runs a script called |
| 7400 |
‘config.guess’, which infers the name using the ‘uname’ command or |
| 7401 |
symbols predefined by the C preprocessor. |
| 7402 |
|
| 7403 |
Alternately, the user can specify the system type with command line |
| 7404 |
arguments to ‘configure’. Doing so is necessary when cross-compiling. |
| 7405 |
In the most complex case of cross-compiling, three system types are |
| 7406 |
involved. The options to specify them are(1): |
| 7407 |
|
| 7408 |
‘--build=BUILD-TYPE’ |
| 7409 |
the type of system on which the package is being configured and |
| 7410 |
compiled. |
| 7411 |
|
| 7412 |
‘--host=HOST-TYPE’ |
| 7413 |
the type of system on which the package will run. |
| 7414 |
|
| 7415 |
‘--target=TARGET-TYPE’ |
| 7416 |
the type of system for which any compiler tools in the package will |
| 7417 |
produce code (rarely needed). By default, it is the same as host. |
| 7418 |
|
| 7419 |
They all default to the result of running ‘config.guess’, unless you |
| 7420 |
specify either ‘--build’ or ‘--host’. In this case, the default becomes |
| 7421 |
the system type you specified. If you specify both, and they're |
| 7422 |
different, ‘configure’ will enter cross compilation mode, so it won't |
| 7423 |
run any tests that require execution. |
| 7424 |
|
| 7425 |
Hint: if you mean to override the result of ‘config.guess’, prefer |
| 7426 |
‘--build’ over ‘--host’. In the future, ‘--host’ will not override the |
| 7427 |
name of the build system type. Also, if you specify ‘--host’, but not |
| 7428 |
‘--build’, when ‘configure’ performs the first compiler test it will try |
| 7429 |
to run an executable produced by the compiler. If the execution fails, |
| 7430 |
it will enter cross-compilation mode. Note, however, that it won't |
| 7431 |
guess the build-system type, since this may require running test |
| 7432 |
programs. Moreover, by the time the compiler test is performed, it may |
| 7433 |
be too late to modify the build-system type: other tests may have |
| 7434 |
already been performed. Therefore, whenever you specify ‘--host’, be |
| 7435 |
sure to specify ‘--build’ too. |
| 7436 |
|
| 7437 |
./configure --build=i686-pc-linux-gnu --host=m68k-coff |
| 7438 |
|
| 7439 |
will enter cross-compilation mode, but ‘configure’ will fail if it can't |
| 7440 |
run the code generated by the specified compiler if you configure as |
| 7441 |
follows: |
| 7442 |
|
| 7443 |
./configure CC=m68k-coff-gcc |
| 7444 |
|
| 7445 |
‘configure’ recognizes short aliases for many system types; for |
| 7446 |
example, ‘decstation’ can be used instead of ‘mips-dec-ultrix4.2’. |
| 7447 |
‘configure’ runs a script called ‘config.sub’ to canonicalize system |
| 7448 |
type aliases. |
| 7449 |
|
| 7450 |
---------- Footnotes ---------- |
| 7451 |
|
| 7452 |
(1) For backward compatibility, ‘configure’ will accept a system type |
| 7453 |
as an option by itself. Such an option will override the defaults for |
| 7454 |
build, host and target system types. The following configure statement |
| 7455 |
will configure a cross toolchain that will run on NetBSD/alpha but |
| 7456 |
generate code for GNU Hurd/sparc, which is also the build platform. |
| 7457 |
|
| 7458 |
./configure --host=alpha-netbsd sparc-gnu |
| 7459 |
|
| 7460 |
|
| 7461 |
File: autoconf.info, Node: Canonicalizing, Next: Using System Type, Prev: Specifying Names, Up: Manual Configuration |
| 7462 |
|
| 7463 |
11.2 Getting the Canonical System Type |
| 7464 |
====================================== |
| 7465 |
|
| 7466 |
The following macros make the system type available to ‘configure’ |
| 7467 |
scripts. |
| 7468 |
|
| 7469 |
The variables ‘build_alias’, ‘host_alias’, and ‘target_alias’ are |
| 7470 |
always exactly the arguments of ‘--build’, ‘--host’, and ‘--target’; in |
| 7471 |
particular, they are left empty if the user did not use them, even if |
| 7472 |
the corresponding ‘AC_CANONICAL’ macro was run. Any configure script |
| 7473 |
may use these variables anywhere. These are the variables that should |
| 7474 |
be used when in interaction with the user. |
| 7475 |
|
| 7476 |
If you need to recognize some special environments based on their |
| 7477 |
system type, run the following macros to get canonical system names. |
| 7478 |
These variables are not set before the macro call. |
| 7479 |
|
| 7480 |
If you use these macros, you must distribute ‘config.guess’ and |
| 7481 |
‘config.sub’ along with your source code. *Note Output::, for |
| 7482 |
information about the ‘AC_CONFIG_AUX_DIR’ macro which you can use to |
| 7483 |
control in which directory ‘configure’ looks for those scripts. |
| 7484 |
|
| 7485 |
-- Macro: AC_CANONICAL_BUILD |
| 7486 |
Compute the canonical build-system type variable, ‘build’, and its |
| 7487 |
three individual parts ‘build_cpu’, ‘build_vendor’, and ‘build_os’. |
| 7488 |
|
| 7489 |
If ‘--build’ was specified, then ‘build’ is the canonicalization of |
| 7490 |
‘build_alias’ by ‘config.sub’, otherwise it is determined by the |
| 7491 |
shell script ‘config.guess’. |
| 7492 |
|
| 7493 |
-- Macro: AC_CANONICAL_HOST |
| 7494 |
Compute the canonical host-system type variable, ‘host’, and its |
| 7495 |
three individual parts ‘host_cpu’, ‘host_vendor’, and ‘host_os’. |
| 7496 |
|
| 7497 |
If ‘--host’ was specified, then ‘host’ is the canonicalization of |
| 7498 |
‘host_alias’ by ‘config.sub’, otherwise it defaults to ‘build’. |
| 7499 |
|
| 7500 |
For temporary backward-compatibility, when ‘--host’ is specified by |
| 7501 |
‘--build’ isn't, the build system will be assumed to be the same as |
| 7502 |
‘--host’, and ‘build_alias’ will be set to that value. Eventually, |
| 7503 |
this historically incorrect behavior will go away. |
| 7504 |
|
| 7505 |
-- Macro: AC_CANONICAL_TARGET |
| 7506 |
Compute the canonical target-system type variable, ‘target’, and |
| 7507 |
its three individual parts ‘target_cpu’, ‘target_vendor’, and |
| 7508 |
‘target_os’. |
| 7509 |
|
| 7510 |
If ‘--target’ was specified, then ‘target’ is the canonicalization |
| 7511 |
of ‘target_alias’ by ‘config.sub’, otherwise it defaults to ‘host’. |
| 7512 |
|
| 7513 |
|
| 7514 |
File: autoconf.info, Node: Using System Type, Prev: Canonicalizing, Up: Manual Configuration |
| 7515 |
|
| 7516 |
11.3 Using the System Type |
| 7517 |
========================== |
| 7518 |
|
| 7519 |
How do you use a canonical system type? Usually, you use it in one or |
| 7520 |
more ‘case’ statements in ‘configure.ac’ to select system-specific C |
| 7521 |
files. Then, using ‘AC_CONFIG_LINKS’, link those files which have names |
| 7522 |
based on the system name, to generic names, such as ‘host.h’ or |
| 7523 |
‘target.c’ (*note Configuration Links::). The ‘case’ statement patterns |
| 7524 |
can use shell wild cards to group several cases together, like in this |
| 7525 |
fragment: |
| 7526 |
|
| 7527 |
case "$target" in |
| 7528 |
i386-*-mach* | i386-*-gnu*) |
| 7529 |
obj_format=aout emulation=mach bfd_gas=yes ;; |
| 7530 |
i960-*-bout) obj_format=bout ;; |
| 7531 |
esac |
| 7532 |
|
| 7533 |
and in ‘configure.ac’, use: |
| 7534 |
|
| 7535 |
AC_CONFIG_LINKS(host.h:config/$machine.h |
| 7536 |
object.h:config/$obj_format.h) |
| 7537 |
|
| 7538 |
You can also use the host system type to find cross-compilation |
| 7539 |
tools. *Note Generic Programs::, for information about the |
| 7540 |
‘AC_CHECK_TOOL’ macro which does that. |
| 7541 |
|
| 7542 |
|
| 7543 |
File: autoconf.info, Node: Site Configuration, Next: Running configure scripts, Prev: Manual Configuration, Up: Top |
| 7544 |
|
| 7545 |
12 Site Configuration |
| 7546 |
********************* |
| 7547 |
|
| 7548 |
‘configure’ scripts support several kinds of local configuration |
| 7549 |
decisions. There are ways for users to specify where external software |
| 7550 |
packages are, include or exclude optional features, install programs |
| 7551 |
under modified names, and set default values for ‘configure’ options. |
| 7552 |
|
| 7553 |
* Menu: |
| 7554 |
|
| 7555 |
* External Software:: Working with other optional software |
| 7556 |
* Package Options:: Selecting optional features |
| 7557 |
* Pretty Help Strings:: Formatting help string |
| 7558 |
* Site Details:: Configuring site details |
| 7559 |
* Transforming Names:: Changing program names when installing |
| 7560 |
* Site Defaults:: Giving ‘configure’ local defaults |
| 7561 |
|
| 7562 |
|
| 7563 |
File: autoconf.info, Node: External Software, Next: Package Options, Prev: Site Configuration, Up: Site Configuration |
| 7564 |
|
| 7565 |
12.1 Working With External Software |
| 7566 |
=================================== |
| 7567 |
|
| 7568 |
Some packages require, or can optionally use, other software packages |
| 7569 |
that are already installed. The user can give ‘configure’ command line |
| 7570 |
options to specify which such external software to use. The options |
| 7571 |
have one of these forms: |
| 7572 |
|
| 7573 |
--with-PACKAGE=[ARG] |
| 7574 |
--without-PACKAGE |
| 7575 |
|
| 7576 |
For example, ‘--with-gnu-ld’ means work with the GNU linker instead |
| 7577 |
of some other linker. ‘--with-x’ means work with The X Window System. |
| 7578 |
|
| 7579 |
The user can give an argument by following the package name with ‘=’ |
| 7580 |
and the argument. Giving an argument of ‘no’ is for packages that are |
| 7581 |
used by default; it says to _not_ use the package. An argument that is |
| 7582 |
neither ‘yes’ nor ‘no’ could include a name or number of a version of |
| 7583 |
the other package, to specify more precisely which other package this |
| 7584 |
program is supposed to work with. If no argument is given, it defaults |
| 7585 |
to ‘yes’. ‘--without-PACKAGE’ is equivalent to ‘--with-PACKAGE=no’. |
| 7586 |
|
| 7587 |
‘configure’ scripts do not complain about ‘--with-PACKAGE’ options |
| 7588 |
that they do not support. This behavior permits configuring a source |
| 7589 |
tree containing multiple packages with a top-level ‘configure’ script |
| 7590 |
when the packages support different options, without spurious error |
| 7591 |
messages about options that some of the packages support. An |
| 7592 |
unfortunate side effect is that option spelling errors are not |
| 7593 |
diagnosed. No better approach to this problem has been suggested so |
| 7594 |
far. |
| 7595 |
|
| 7596 |
For each external software package that may be used, ‘configure.ac’ |
| 7597 |
should call ‘AC_ARG_WITH’ to detect whether the ‘configure’ user asked |
| 7598 |
to use it. Whether each package is used or not by default, and which |
| 7599 |
arguments are valid, is up to you. |
| 7600 |
|
| 7601 |
-- Macro: AC_ARG_WITH (PACKAGE, HELP-STRING, [ACTION-IF-GIVEN], |
| 7602 |
[ACTION-IF-NOT-GIVEN]) |
| 7603 |
If the user gave ‘configure’ the option ‘--with-PACKAGE’ or |
| 7604 |
‘--without-PACKAGE’, run shell commands ACTION-IF-GIVEN. If |
| 7605 |
neither option was given, run shell commands ACTION-IF-NOT-GIVEN. |
| 7606 |
The name PACKAGE indicates another software package that this |
| 7607 |
program should work with. It should consist only of alphanumeric |
| 7608 |
characters and dashes. |
| 7609 |
|
| 7610 |
The option's argument is available to the shell commands |
| 7611 |
ACTION-IF-GIVEN in the shell variable ‘withval’, which is actually |
| 7612 |
just the value of the shell variable ‘with_PACKAGE’, with any ‘-’ |
| 7613 |
characters changed into ‘_’. You may use that variable instead, if |
| 7614 |
you wish. |
| 7615 |
|
| 7616 |
The argument HELP-STRING is a description of the option that looks |
| 7617 |
like this: |
| 7618 |
--with-readline support fancy command line editing |
| 7619 |
|
| 7620 |
HELP-STRING may be more than one line long, if more detail is |
| 7621 |
needed. Just make sure the columns line up in ‘configure --help’. |
| 7622 |
Avoid tabs in the help string. You'll need to enclose it in ‘[’ |
| 7623 |
and ‘]’ in order to produce the leading spaces. |
| 7624 |
|
| 7625 |
You should format your HELP-STRING with the macro ‘AS_HELP_STRING’ |
| 7626 |
(*note Pretty Help Strings::). |
| 7627 |
|
| 7628 |
-- Macro: AC_WITH (PACKAGE, ACTION-IF-GIVEN, [ACTION-IF-NOT-GIVEN]) |
| 7629 |
This is an obsolete version of ‘AC_ARG_WITH’ that does not support |
| 7630 |
providing a help string. |
| 7631 |
|
| 7632 |
|
| 7633 |
File: autoconf.info, Node: Package Options, Next: Pretty Help Strings, Prev: External Software, Up: Site Configuration |
| 7634 |
|
| 7635 |
12.2 Choosing Package Options |
| 7636 |
============================= |
| 7637 |
|
| 7638 |
If a software package has optional compile-time features, the user can |
| 7639 |
give ‘configure’ command line options to specify whether to compile |
| 7640 |
them. The options have one of these forms: |
| 7641 |
|
| 7642 |
--enable-FEATURE=[ARG] |
| 7643 |
--disable-FEATURE |
| 7644 |
|
| 7645 |
These options allow users to choose which optional features to build |
| 7646 |
and install. ‘--enable-FEATURE’ options should never make a feature |
| 7647 |
behave differently or cause one feature to replace another. They should |
| 7648 |
only cause parts of the program to be built rather than left out. |
| 7649 |
|
| 7650 |
The user can give an argument by following the feature name with ‘=’ |
| 7651 |
and the argument. Giving an argument of ‘no’ requests that the feature |
| 7652 |
_not_ be made available. A feature with an argument looks like |
| 7653 |
‘--enable-debug=stabs’. If no argument is given, it defaults to ‘yes’. |
| 7654 |
‘--disable-FEATURE’ is equivalent to ‘--enable-FEATURE=no’. |
| 7655 |
|
| 7656 |
‘configure’ scripts do not complain about ‘--enable-FEATURE’ options |
| 7657 |
that they do not support. This behavior permits configuring a source |
| 7658 |
tree containing multiple packages with a top-level ‘configure’ script |
| 7659 |
when the packages support different options, without spurious error |
| 7660 |
messages about options that some of the packages support. An |
| 7661 |
unfortunate side effect is that option spelling errors are not |
| 7662 |
diagnosed. No better approach to this problem has been suggested so |
| 7663 |
far. |
| 7664 |
|
| 7665 |
For each optional feature, ‘configure.ac’ should call ‘AC_ARG_ENABLE’ |
| 7666 |
to detect whether the ‘configure’ user asked to include it. Whether |
| 7667 |
each feature is included or not by default, and which arguments are |
| 7668 |
valid, is up to you. |
| 7669 |
|
| 7670 |
-- Macro: AC_ARG_ENABLE (FEATURE, HELP-STRING, [ACTION-IF-GIVEN], |
| 7671 |
[ACTION-IF-NOT-GIVEN]) |
| 7672 |
If the user gave ‘configure’ the option ‘--enable-FEATURE’ or |
| 7673 |
‘--disable-FEATURE’, run shell commands ACTION-IF-GIVEN. If |
| 7674 |
neither option was given, run shell commands ACTION-IF-NOT-GIVEN. |
| 7675 |
The name FEATURE indicates an optional user-level facility. It |
| 7676 |
should consist only of alphanumeric characters and dashes. |
| 7677 |
|
| 7678 |
The option's argument is available to the shell commands |
| 7679 |
ACTION-IF-GIVEN in the shell variable ‘enableval’, which is |
| 7680 |
actually just the value of the shell variable ‘enable_FEATURE’, |
| 7681 |
with any ‘-’ characters changed into ‘_’. You may use that |
| 7682 |
variable instead, if you wish. The HELP-STRING argument is like |
| 7683 |
that of ‘AC_ARG_WITH’ (*note External Software::). |
| 7684 |
|
| 7685 |
You should format your HELP-STRING with the macro ‘AS_HELP_STRING’ |
| 7686 |
(*note Pretty Help Strings::). |
| 7687 |
|
| 7688 |
-- Macro: AC_ENABLE (FEATURE, ACTION-IF-GIVEN, [ACTION-IF-NOT-GIVEN]) |
| 7689 |
This is an obsolete version of ‘AC_ARG_ENABLE’ that does not |
| 7690 |
support providing a help string. |
| 7691 |
|
| 7692 |
|
| 7693 |
File: autoconf.info, Node: Pretty Help Strings, Next: Site Details, Prev: Package Options, Up: Site Configuration |
| 7694 |
|
| 7695 |
12.3 Making Your Help Strings Look Pretty |
| 7696 |
========================================= |
| 7697 |
|
| 7698 |
Properly formatting the ‘help strings’ which are used in ‘AC_ARG_WITH’ |
| 7699 |
(*note External Software::) and ‘AC_ARG_ENABLE’ (*note Package |
| 7700 |
Options::) can be challenging. Specifically, you want your own ‘help |
| 7701 |
strings’ to line up in the appropriate columns of ‘configure --help’ |
| 7702 |
just like the standard Autoconf ‘help strings’ do. This is the purpose |
| 7703 |
of the ‘AS_HELP_STRING’ macro. |
| 7704 |
|
| 7705 |
-- Macro: AS_HELP_STRING (LEFT-HAND-SIDE, RIGHT-HAND-SIDE) |
| 7706 |
|
| 7707 |
Expands into an help string that looks pretty when the user |
| 7708 |
executes ‘configure --help’. It is typically used in ‘AC_ARG_WITH’ |
| 7709 |
(*note External Software::) or ‘AC_ARG_ENABLE’ (*note Package |
| 7710 |
Options::). The following example will make this clearer. |
| 7711 |
|
| 7712 |
AC_DEFUN(TEST_MACRO, |
| 7713 |
[AC_ARG_WITH(foo, |
| 7714 |
AS_HELP_STRING([--with-foo], |
| 7715 |
[use foo (default is NO)]), |
| 7716 |
ac_cv_use_foo=$withval, ac_cv_use_foo=no), |
| 7717 |
AC_CACHE_CHECK(whether to use foo, |
| 7718 |
ac_cv_use_foo, ac_cv_use_foo=no)]) |
| 7719 |
|
| 7720 |
Please note that the call to ‘AS_HELP_STRING’ is *unquoted*. Then |
| 7721 |
the last few lines of ‘configure --help’ will appear like this: |
| 7722 |
|
| 7723 |
--enable and --with options recognized: |
| 7724 |
--with-foo use foo (default is NO) |
| 7725 |
|
| 7726 |
The ‘AS_HELP_STRING’ macro is particularly helpful when the |
| 7727 |
LEFT-HAND-SIDE and/or RIGHT-HAND-SIDE are composed of macro |
| 7728 |
arguments, as shown in the following example. |
| 7729 |
|
| 7730 |
AC_DEFUN(MY_ARG_WITH, |
| 7731 |
[AC_ARG_WITH([$1], |
| 7732 |
AS_HELP_STRING([--with-$1], [use $1 (default is $2)]), |
| 7733 |
ac_cv_use_$1=$withval, ac_cv_use_$1=no), |
| 7734 |
AC_CACHE_CHECK(whether to use $1, ac_cv_use_$1, ac_cv_use_$1=$2)]) |
| 7735 |
|
| 7736 |
|
| 7737 |
File: autoconf.info, Node: Site Details, Next: Transforming Names, Prev: Pretty Help Strings, Up: Site Configuration |
| 7738 |
|
| 7739 |
12.4 Configuring Site Details |
| 7740 |
============================= |
| 7741 |
|
| 7742 |
Some software packages require complex site-specific information. Some |
| 7743 |
examples are host names to use for certain services, company names, and |
| 7744 |
email addresses to contact. Since some configuration scripts generated |
| 7745 |
by Metaconfig ask for such information interactively, people sometimes |
| 7746 |
wonder how to get that information in Autoconf-generated configuration |
| 7747 |
scripts, which aren't interactive. |
| 7748 |
|
| 7749 |
Such site configuration information should be put in a file that is |
| 7750 |
edited _only by users_, not by programs. The location of the file can |
| 7751 |
either be based on the ‘prefix’ variable, or be a standard location such |
| 7752 |
as the user's home directory. It could even be specified by an |
| 7753 |
environment variable. The programs should examine that file at run |
| 7754 |
time, rather than at compile time. Run time configuration is more |
| 7755 |
convenient for users and makes the configuration process simpler than |
| 7756 |
getting the information while configuring. *Note Variables for |
| 7757 |
Installation Directories: (standards)Directory Variables, for more |
| 7758 |
information on where to put data files. |
| 7759 |
|
| 7760 |
|
| 7761 |
File: autoconf.info, Node: Transforming Names, Next: Site Defaults, Prev: Site Details, Up: Site Configuration |
| 7762 |
|
| 7763 |
12.5 Transforming Program Names When Installing |
| 7764 |
=============================================== |
| 7765 |
|
| 7766 |
Autoconf supports changing the names of programs when installing them. |
| 7767 |
In order to use these transformations, ‘configure.ac’ must call the |
| 7768 |
macro ‘AC_ARG_PROGRAM’. |
| 7769 |
|
| 7770 |
-- Macro: AC_ARG_PROGRAM |
| 7771 |
Place in output variable ‘program_transform_name’ a sequence of |
| 7772 |
‘sed’ commands for changing the names of installed programs. |
| 7773 |
|
| 7774 |
If any of the options described below are given to ‘configure’, |
| 7775 |
program names are transformed accordingly. Otherwise, if |
| 7776 |
‘AC_CANONICAL_TARGET’ has been called and a ‘--target’ value is |
| 7777 |
given that differs from the host type (specified with ‘--host’), |
| 7778 |
the target type followed by a dash is used as a prefix. Otherwise, |
| 7779 |
no program name transformation is done. |
| 7780 |
|
| 7781 |
* Menu: |
| 7782 |
|
| 7783 |
* Transformation Options:: ‘configure’ options to transform names |
| 7784 |
* Transformation Examples:: Sample uses of transforming names |
| 7785 |
* Transformation Rules:: ‘Makefile’ uses of transforming names |
| 7786 |
|
| 7787 |
|
| 7788 |
File: autoconf.info, Node: Transformation Options, Next: Transformation Examples, Prev: Transforming Names, Up: Transforming Names |
| 7789 |
|
| 7790 |
12.5.1 Transformation Options |
| 7791 |
----------------------------- |
| 7792 |
|
| 7793 |
You can specify name transformations by giving ‘configure’ these command |
| 7794 |
line options: |
| 7795 |
|
| 7796 |
‘--program-prefix=PREFIX’ |
| 7797 |
prepend PREFIX to the names; |
| 7798 |
|
| 7799 |
‘--program-suffix=SUFFIX’ |
| 7800 |
append SUFFIX to the names; |
| 7801 |
|
| 7802 |
‘--program-transform-name=EXPRESSION’ |
| 7803 |
perform ‘sed’ substitution EXPRESSION on the names. |
| 7804 |
|
| 7805 |
|
| 7806 |
File: autoconf.info, Node: Transformation Examples, Next: Transformation Rules, Prev: Transformation Options, Up: Transforming Names |
| 7807 |
|
| 7808 |
12.5.2 Transformation Examples |
| 7809 |
------------------------------ |
| 7810 |
|
| 7811 |
These transformations are useful with programs that can be part of a |
| 7812 |
cross-compilation development environment. For example, a |
| 7813 |
cross-assembler running on a Sun 4 configured with |
| 7814 |
‘--target=i960-vxworks’ is normally installed as ‘i960-vxworks-as’, |
| 7815 |
rather than ‘as’, which could be confused with a native Sun 4 assembler. |
| 7816 |
|
| 7817 |
You can force a program name to begin with ‘g’, if you don't want GNU |
| 7818 |
programs installed on your system to shadow other programs with the same |
| 7819 |
name. For example, if you configure GNU ‘diff’ with |
| 7820 |
‘--program-prefix=g’, then when you run ‘make install’ it is installed |
| 7821 |
as ‘/usr/local/bin/gdiff’. |
| 7822 |
|
| 7823 |
As a more sophisticated example, you could use |
| 7824 |
|
| 7825 |
--program-transform-name='s/^/g/; s/^gg/g/; s/^gless/less/' |
| 7826 |
|
| 7827 |
to prepend ‘g’ to most of the program names in a source tree, |
| 7828 |
excepting those like ‘gdb’ that already have one and those like ‘less’ |
| 7829 |
and ‘lesskey’ that aren't GNU programs. (That is assuming that you have |
| 7830 |
a source tree containing those programs that is set up to use this |
| 7831 |
feature.) |
| 7832 |
|
| 7833 |
One way to install multiple versions of some programs simultaneously |
| 7834 |
is to append a version number to the name of one or both. For example, |
| 7835 |
if you want to keep Autoconf version 1 around for awhile, you can |
| 7836 |
configure Autoconf version 2 using ‘--program-suffix=2’ to install the |
| 7837 |
programs as ‘/usr/local/bin/autoconf2’, ‘/usr/local/bin/autoheader2’, |
| 7838 |
etc. Nevertheless, pay attention that only the binaries are renamed, |
| 7839 |
therefore you'd have problems with the library files which might |
| 7840 |
overlap. |
| 7841 |
|
| 7842 |
|
| 7843 |
File: autoconf.info, Node: Transformation Rules, Prev: Transformation Examples, Up: Transforming Names |
| 7844 |
|
| 7845 |
12.5.3 Transformation Rules |
| 7846 |
--------------------------- |
| 7847 |
|
| 7848 |
Here is how to use the variable ‘program_transform_name’ in a |
| 7849 |
‘Makefile.in’: |
| 7850 |
|
| 7851 |
transform = @program_transform_name@ |
| 7852 |
install: all |
| 7853 |
$(INSTALL_PROGRAM) myprog $(bindir)/`echo myprog | \ |
| 7854 |
sed '$(transform)'` |
| 7855 |
|
| 7856 |
uninstall: |
| 7857 |
rm -f $(bindir)/`echo myprog | sed '$(transform)'` |
| 7858 |
|
| 7859 |
If you have more than one program to install, you can do it in a loop: |
| 7860 |
|
| 7861 |
PROGRAMS = cp ls rm |
| 7862 |
install: |
| 7863 |
for p in $(PROGRAMS); do \ |
| 7864 |
$(INSTALL_PROGRAM) $$p $(bindir)/`echo $$p | \ |
| 7865 |
sed '$(transform)'`; \ |
| 7866 |
done |
| 7867 |
|
| 7868 |
uninstall: |
| 7869 |
for p in $(PROGRAMS); do \ |
| 7870 |
rm -f $(bindir)/`echo $$p | sed '$(transform)'`; \ |
| 7871 |
done |
| 7872 |
|
| 7873 |
It is guaranteed that ‘program_transform_name’ is never empty, and |
| 7874 |
that there are no useless separators. Therefore you may safely embed |
| 7875 |
‘program_transform_name’ within a sed program using ‘;’: |
| 7876 |
|
| 7877 |
transform = @program_transform_name@ |
| 7878 |
transform_exe = s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/ |
| 7879 |
|
| 7880 |
Whether to do the transformations on documentation files (Texinfo or |
| 7881 |
‘man’) is a tricky question; there seems to be no perfect answer, due to |
| 7882 |
the several reasons for name transforming. Documentation is not usually |
| 7883 |
particular to a specific architecture, and Texinfo files do not conflict |
| 7884 |
with system documentation. But they might conflict with earlier |
| 7885 |
versions of the same files, and ‘man’ pages sometimes do conflict with |
| 7886 |
system documentation. As a compromise, it is probably best to do name |
| 7887 |
transformations on ‘man’ pages but not on Texinfo manuals. |
| 7888 |
|
| 7889 |
|
| 7890 |
File: autoconf.info, Node: Site Defaults, Prev: Transforming Names, Up: Site Configuration |
| 7891 |
|
| 7892 |
12.6 Setting Site Defaults |
| 7893 |
========================== |
| 7894 |
|
| 7895 |
Autoconf-generated ‘configure’ scripts allow your site to provide |
| 7896 |
default values for some configuration values. You do this by creating |
| 7897 |
site- and system-wide initialization files. |
| 7898 |
|
| 7899 |
If the environment variable ‘CONFIG_SITE’ is set, ‘configure’ uses |
| 7900 |
its value as the name of a shell script to read. Otherwise, it reads |
| 7901 |
the shell script ‘PREFIX/share/config.site’ if it exists, then |
| 7902 |
‘PREFIX/etc/config.site’ if it exists. Thus, settings in |
| 7903 |
machine-specific files override those in machine-independent ones in |
| 7904 |
case of conflict. |
| 7905 |
|
| 7906 |
Site files can be arbitrary shell scripts, but only certain kinds of |
| 7907 |
code are really appropriate to be in them. Because ‘configure’ reads |
| 7908 |
any cache file after it has read any site files, a site file can define |
| 7909 |
a default cache file to be shared between all Autoconf-generated |
| 7910 |
‘configure’ scripts run on that system (*note Cache Files::). If you |
| 7911 |
set a default cache file in a site file, it is a good idea to also set |
| 7912 |
the output variable ‘CC’ in that site file, because the cache file is |
| 7913 |
only valid for a particular compiler, but many systems have several |
| 7914 |
available. |
| 7915 |
|
| 7916 |
You can examine or override the value set by a command line option to |
| 7917 |
‘configure’ in a site file; options set shell variables that have the |
| 7918 |
same names as the options, with any dashes turned into underscores. The |
| 7919 |
exceptions are that ‘--without-’ and ‘--disable-’ options are like |
| 7920 |
giving the corresponding ‘--with-’ or ‘--enable-’ option and the value |
| 7921 |
‘no’. Thus, ‘--cache-file=localcache’ sets the variable ‘cache_file’ to |
| 7922 |
the value ‘localcache’; ‘--enable-warnings=no’ or ‘--disable-warnings’ |
| 7923 |
sets the variable ‘enable_warnings’ to the value ‘no’; ‘--prefix=/usr’ |
| 7924 |
sets the variable ‘prefix’ to the value ‘/usr’; etc. |
| 7925 |
|
| 7926 |
Site files are also good places to set default values for other |
| 7927 |
output variables, such as ‘CFLAGS’, if you need to give them non-default |
| 7928 |
values: anything you would normally do, repetitively, on the command |
| 7929 |
line. If you use non-default values for PREFIX or EXEC_PREFIX (wherever |
| 7930 |
you locate the site file), you can set them in the site file if you |
| 7931 |
specify it with the ‘CONFIG_SITE’ environment variable. |
| 7932 |
|
| 7933 |
You can set some cache values in the site file itself. Doing this is |
| 7934 |
useful if you are cross-compiling, so it is impossible to check features |
| 7935 |
that require running a test program. You could "prime the cache" by |
| 7936 |
setting those values correctly for that system in |
| 7937 |
‘PREFIX/etc/config.site’. To find out the names of the cache variables |
| 7938 |
you need to set, look for shell variables with ‘_cv_’ in their names in |
| 7939 |
the affected ‘configure’ scripts, or in the Autoconf M4 source code for |
| 7940 |
those macros. |
| 7941 |
|
| 7942 |
The cache file is careful to not override any variables set in the |
| 7943 |
site files. Similarly, you should not override command-line options in |
| 7944 |
the site files. Your code should check that variables such as ‘prefix’ |
| 7945 |
and ‘cache_file’ have their default values (as set near the top of |
| 7946 |
‘configure’) before changing them. |
| 7947 |
|
| 7948 |
Here is a sample file ‘/usr/share/local/gnu/share/config.site’. The |
| 7949 |
command ‘configure --prefix=/usr/share/local/gnu’ would read this file |
| 7950 |
(if ‘CONFIG_SITE’ is not set to a different file). |
| 7951 |
|
| 7952 |
# config.site for configure |
| 7953 |
# |
| 7954 |
# Change some defaults. |
| 7955 |
test "$prefix" = NONE && prefix=/usr/share/local/gnu |
| 7956 |
test "$exec_prefix" = NONE && exec_prefix=/usr/local/gnu |
| 7957 |
test "$sharedstatedir" = '$prefix/com' && sharedstatedir=/var |
| 7958 |
test "$localstatedir" = '$prefix/var' && localstatedir=/var |
| 7959 |
|
| 7960 |
# Give Autoconf 2.x generated configure scripts a shared default |
| 7961 |
# cache file for feature test results, architecture-specific. |
| 7962 |
if test "$cache_file" = /dev/null; then |
| 7963 |
cache_file="$prefix/var/config.cache" |
| 7964 |
# A cache file is only valid for one C compiler. |
| 7965 |
CC=gcc |
| 7966 |
fi |
| 7967 |
|
| 7968 |
|
| 7969 |
File: autoconf.info, Node: Running configure scripts, Next: config.status Invocation, Prev: Site Configuration, Up: Top |
| 7970 |
|
| 7971 |
13 Running ‘configure’ Scripts |
| 7972 |
****************************** |
| 7973 |
|
| 7974 |
Below are instructions on how to configure a package that uses a |
| 7975 |
‘configure’ script, suitable for inclusion as an ‘INSTALL’ file in the |
| 7976 |
package. A plain-text version of ‘INSTALL’ which you may use comes with |
| 7977 |
Autoconf. |
| 7978 |
|
| 7979 |
* Menu: |
| 7980 |
|
| 7981 |
* Basic Installation:: Instructions for typical cases |
| 7982 |
* Compilers and Options:: Selecting compilers and optimization |
| 7983 |
* Multiple Architectures:: Compiling for multiple architectures at once |
| 7984 |
* Installation Names:: Installing in different directories |
| 7985 |
* Optional Features:: Selecting optional features |
| 7986 |
* System Type:: Specifying the system type |
| 7987 |
* Sharing Defaults:: Setting site-wide defaults for ‘configure’ |
| 7988 |
* Environment Variables:: Defining environment variables. |
| 7989 |
* configure Invocation:: Changing how ‘configure’ runs |
| 7990 |
|
| 7991 |
|
| 7992 |
File: autoconf.info, Node: Basic Installation, Next: Compilers and Options, Up: Running configure scripts |
| 7993 |
|
| 7994 |
13.1 Basic Installation |
| 7995 |
======================= |
| 7996 |
|
| 7997 |
These are generic installation instructions. |
| 7998 |
|
| 7999 |
The ‘configure’ shell script attempts to guess correct values for |
| 8000 |
various system-dependent variables used during compilation. It uses |
| 8001 |
those values to create a ‘Makefile’ in each directory of the package. |
| 8002 |
It may also create one or more ‘.h’ files containing system-dependent |
| 8003 |
definitions. Finally, it creates a shell script ‘config.status’ that |
| 8004 |
you can run in the future to recreate the current configuration, and a |
| 8005 |
file ‘config.log’ containing compiler output (useful mainly for |
| 8006 |
debugging ‘configure’). |
| 8007 |
|
| 8008 |
It can also use an optional file (typically called ‘config.cache’ and |
| 8009 |
enabled with ‘--cache-file=config.cache’ or simply ‘-C’) that saves the |
| 8010 |
results of its tests to speed up reconfiguring. (Caching is disabled by |
| 8011 |
default to prevent problems with accidental use of stale cache files.) |
| 8012 |
|
| 8013 |
If you need to do unusual things to compile the package, please try |
| 8014 |
to figure out how ‘configure’ could check whether to do them, and mail |
| 8015 |
diffs or instructions to the address given in the ‘README’ so they can |
| 8016 |
be considered for the next release. If you are using the cache, and at |
| 8017 |
some point ‘config.cache’ contains results you don't want to keep, you |
| 8018 |
may remove or edit it. |
| 8019 |
|
| 8020 |
The file ‘configure.ac’ (or ‘configure.in’) is used to create |
| 8021 |
‘configure’ by a program called ‘autoconf’. You only need |
| 8022 |
‘configure.ac’ if you want to change it or regenerate ‘configure’ using |
| 8023 |
a newer version of ‘autoconf’. |
| 8024 |
|
| 8025 |
The simplest way to compile this package is: |
| 8026 |
|
| 8027 |
1. ‘cd’ to the directory containing the package's source code and type |
| 8028 |
‘./configure’ to configure the package for your system. If you're |
| 8029 |
using ‘csh’ on an old version of System V, you might need to type |
| 8030 |
‘sh ./configure’ instead to prevent ‘csh’ from trying to execute |
| 8031 |
‘configure’ itself. |
| 8032 |
|
| 8033 |
Running ‘configure’ takes awhile. While running, it prints some |
| 8034 |
messages telling which features it is checking for. |
| 8035 |
|
| 8036 |
2. Type ‘make’ to compile the package. |
| 8037 |
|
| 8038 |
3. Optionally, type ‘make check’ to run any self-tests that come with |
| 8039 |
the package. |
| 8040 |
|
| 8041 |
4. Type ‘make install’ to install the programs and any data files and |
| 8042 |
documentation. |
| 8043 |
|
| 8044 |
5. You can remove the program binaries and object files from the |
| 8045 |
source code directory by typing ‘make clean’. To also remove the |
| 8046 |
files that ‘configure’ created (so you can compile the package for |
| 8047 |
a different kind of computer), type ‘make distclean’. There is |
| 8048 |
also a ‘make maintainer-clean’ target, but that is intended mainly |
| 8049 |
for the package's developers. If you use it, you may have to get |
| 8050 |
all sorts of other programs in order to regenerate files that came |
| 8051 |
with the distribution. |
| 8052 |
|
| 8053 |
|
| 8054 |
File: autoconf.info, Node: Compilers and Options, Next: Multiple Architectures, Prev: Basic Installation, Up: Running configure scripts |
| 8055 |
|
| 8056 |
13.2 Compilers and Options |
| 8057 |
========================== |
| 8058 |
|
| 8059 |
Some systems require unusual options for compilation or linking that the |
| 8060 |
‘configure’ script does not know about. Run ‘./configure --help’ for |
| 8061 |
details on some of the pertinent environment variables. |
| 8062 |
|
| 8063 |
You can give ‘configure’ initial values for variables by setting them |
| 8064 |
in the environment. You can do that on the command line like this: |
| 8065 |
|
| 8066 |
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix |
| 8067 |
|
| 8068 |
*Note Environment Variables::, for more details. |
| 8069 |
|
| 8070 |
|
| 8071 |
File: autoconf.info, Node: Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Running configure scripts |
| 8072 |
|
| 8073 |
13.3 Compiling For Multiple Architectures |
| 8074 |
========================================= |
| 8075 |
|
| 8076 |
You can compile the package for more than one kind of computer at the |
| 8077 |
same time, by placing the object files for each architecture in their |
| 8078 |
own directory. To do this, you must use a version of ‘make’ that |
| 8079 |
supports the ‘VPATH’ variable, such as GNU ‘make’. ‘cd’ to the |
| 8080 |
directory where you want the object files and executables to go and run |
| 8081 |
the ‘configure’ script. ‘configure’ automatically checks for the source |
| 8082 |
code in the directory that ‘configure’ is in and in ‘..’. |
| 8083 |
|
| 8084 |
If you have to use a ‘make’ that does not support the ‘VPATH’ |
| 8085 |
variable, you have to compile the package for one architecture at a time |
| 8086 |
in the source code directory. After you have installed the package for |
| 8087 |
one architecture, use ‘make distclean’ before reconfiguring for another |
| 8088 |
architecture. |
| 8089 |
|
| 8090 |
|
| 8091 |
File: autoconf.info, Node: Installation Names, Next: Optional Features, Prev: Multiple Architectures, Up: Running configure scripts |
| 8092 |
|
| 8093 |
13.4 Installation Names |
| 8094 |
======================= |
| 8095 |
|
| 8096 |
By default, ‘make install’ will install the package's files in |
| 8097 |
‘/usr/local/bin’, ‘/usr/local/man’, etc. You can specify an |
| 8098 |
installation prefix other than ‘/usr/local’ by giving ‘configure’ the |
| 8099 |
option ‘--prefix=PATH’. |
| 8100 |
|
| 8101 |
You can specify separate installation prefixes for |
| 8102 |
architecture-specific files and architecture-independent files. If you |
| 8103 |
give ‘configure’ the option ‘--exec-prefix=PATH’, the package will use |
| 8104 |
PATH as the prefix for installing programs and libraries. Documentation |
| 8105 |
and other data files will still use the regular prefix. |
| 8106 |
|
| 8107 |
In addition, if you use an unusual directory layout you can give |
| 8108 |
options like ‘--bindir=PATH’ to specify different values for particular |
| 8109 |
kinds of files. Run ‘configure --help’ for a list of the directories |
| 8110 |
you can set and what kinds of files go in them. |
| 8111 |
|
| 8112 |
If the package supports it, you can cause programs to be installed |
| 8113 |
with an extra prefix or suffix on their names by giving ‘configure’ the |
| 8114 |
option ‘--program-prefix=PREFIX’ or ‘--program-suffix=SUFFIX’. |
| 8115 |
|
| 8116 |
|
| 8117 |
File: autoconf.info, Node: Optional Features, Next: System Type, Prev: Installation Names, Up: Running configure scripts |
| 8118 |
|
| 8119 |
13.5 Optional Features |
| 8120 |
====================== |
| 8121 |
|
| 8122 |
Some packages pay attention to ‘--enable-FEATURE’ options to |
| 8123 |
‘configure’, where FEATURE indicates an optional part of the package. |
| 8124 |
They may also pay attention to ‘--with-PACKAGE’ options, where PACKAGE |
| 8125 |
is something like ‘gnu-as’ or ‘x’ (for the X Window System). The |
| 8126 |
‘README’ should mention any ‘--enable-’ and ‘--with-’ options that the |
| 8127 |
package recognizes. |
| 8128 |
|
| 8129 |
For packages that use the X Window System, ‘configure’ can usually |
| 8130 |
find the X include and library files automatically, but if it doesn't, |
| 8131 |
you can use the ‘configure’ options ‘--x-includes=DIR’ and |
| 8132 |
‘--x-libraries=DIR’ to specify their locations. |
| 8133 |
|
| 8134 |
|
| 8135 |
File: autoconf.info, Node: System Type, Next: Sharing Defaults, Prev: Optional Features, Up: Running configure scripts |
| 8136 |
|
| 8137 |
13.6 Specifying the System Type |
| 8138 |
=============================== |
| 8139 |
|
| 8140 |
There may be some features ‘configure’ cannot figure out automatically, |
| 8141 |
but needs to determine by the type of host the package will run on. |
| 8142 |
Usually ‘configure’ can figure that out, but if it prints a message |
| 8143 |
saying it cannot guess the host type, give it the ‘--build=TYPE’ option. |
| 8144 |
TYPE can either be a short name for the system type, such as ‘sun4’, or |
| 8145 |
a canonical name which has the form: |
| 8146 |
|
| 8147 |
CPU-COMPANY-SYSTEM |
| 8148 |
|
| 8149 |
where SYSTEM can have one of these forms: |
| 8150 |
|
| 8151 |
OS |
| 8152 |
KERNEL-OS |
| 8153 |
|
| 8154 |
See the file ‘config.sub’ for the possible values of each field. If |
| 8155 |
‘config.sub’ isn't included in this package, then this package doesn't |
| 8156 |
need to know the host type. |
| 8157 |
|
| 8158 |
If you are _building_ compiler tools for cross-compiling, you should |
| 8159 |
use the ‘--target=TYPE’ option to select the type of system they will |
| 8160 |
produce code for. |
| 8161 |
|
| 8162 |
If you want to _use_ a cross compiler, that generates code for a |
| 8163 |
platform different from the build platform, you should specify the host |
| 8164 |
platform (i.e., that on which the generated programs will eventually be |
| 8165 |
run) with ‘--host=TYPE’. In this case, you should also specify the |
| 8166 |
build platform with ‘--build=TYPE’, because, in this case, it may not be |
| 8167 |
possible to guess the build platform (it sometimes involves compiling |
| 8168 |
and running simple test programs, and this can't be done if the compiler |
| 8169 |
is a cross compiler). |
| 8170 |
|
| 8171 |
|
| 8172 |
File: autoconf.info, Node: Sharing Defaults, Next: Environment Variables, Prev: System Type, Up: Running configure scripts |
| 8173 |
|
| 8174 |
13.7 Sharing Defaults |
| 8175 |
===================== |
| 8176 |
|
| 8177 |
If you want to set default values for ‘configure’ scripts to share, you |
| 8178 |
can create a site shell script called ‘config.site’ that gives default |
| 8179 |
values for variables like ‘CC’, ‘cache_file’, and ‘prefix’. ‘configure’ |
| 8180 |
looks for ‘PREFIX/share/config.site’ if it exists, then |
| 8181 |
‘PREFIX/etc/config.site’ if it exists. Or, you can set the |
| 8182 |
‘CONFIG_SITE’ environment variable to the location of the site script. |
| 8183 |
A warning: not all ‘configure’ scripts look for a site script. |
| 8184 |
|
| 8185 |
|
| 8186 |
File: autoconf.info, Node: Environment Variables, Next: configure Invocation, Prev: Sharing Defaults, Up: Running configure scripts |
| 8187 |
|
| 8188 |
13.8 Environment Variables |
| 8189 |
========================== |
| 8190 |
|
| 8191 |
Variables not defined in a site shell script can be set in the |
| 8192 |
environment passed to configure. However, some packages may run |
| 8193 |
configure again during the build, and the customized values of these |
| 8194 |
variables may be lost. In order to avoid this problem, you should set |
| 8195 |
them in the ‘configure’ command line, using ‘VAR=value’. For example: |
| 8196 |
|
| 8197 |
./configure CC=/usr/local2/bin/gcc |
| 8198 |
|
| 8199 |
will cause the specified gcc to be used as the C compiler (unless it is |
| 8200 |
overridden in the site shell script). |
| 8201 |
|
| 8202 |
|
| 8203 |
File: autoconf.info, Node: configure Invocation, Prev: Environment Variables, Up: Running configure scripts |
| 8204 |
|
| 8205 |
13.9 ‘configure’ Invocation |
| 8206 |
=========================== |
| 8207 |
|
| 8208 |
‘configure’ recognizes the following options to control how it operates. |
| 8209 |
|
| 8210 |
‘--help’ |
| 8211 |
‘-h’ |
| 8212 |
Print a summary of the options to ‘configure’, and exit. |
| 8213 |
|
| 8214 |
‘--version’ |
| 8215 |
‘-V’ |
| 8216 |
Print the version of Autoconf used to generate the ‘configure’ |
| 8217 |
script, and exit. |
| 8218 |
|
| 8219 |
‘--cache-file=FILE’ |
| 8220 |
Enable the cache: use and save the results of the tests in FILE, |
| 8221 |
traditionally ‘config.cache’. FILE defaults to ‘/dev/null’ to |
| 8222 |
disable caching. |
| 8223 |
|
| 8224 |
‘--config-cache’ |
| 8225 |
‘-C’ |
| 8226 |
Alias for ‘--cache-file=config.cache’. |
| 8227 |
|
| 8228 |
‘--quiet’ |
| 8229 |
‘--silent’ |
| 8230 |
‘-q’ |
| 8231 |
Do not print messages saying which checks are being made. To |
| 8232 |
suppress all normal output, redirect it to ‘/dev/null’ (any error |
| 8233 |
messages will still be shown). |
| 8234 |
|
| 8235 |
‘--srcdir=DIR’ |
| 8236 |
Look for the package's source code in directory DIR. Usually |
| 8237 |
‘configure’ can determine that directory automatically. |
| 8238 |
|
| 8239 |
‘configure’ also accepts some other, not widely useful, options. Run |
| 8240 |
‘configure --help’ for more details. |
| 8241 |
|
| 8242 |
|
| 8243 |
File: autoconf.info, Node: config.status Invocation, Next: Obsolete Constructs, Prev: Running configure scripts, Up: Top |
| 8244 |
|
| 8245 |
14 Recreating a Configuration |
| 8246 |
***************************** |
| 8247 |
|
| 8248 |
The ‘configure’ script creates a file named ‘config.status’, which |
| 8249 |
actually configures, “instantiates”, the template files. It also |
| 8250 |
records the configuration options that were specified when the package |
| 8251 |
was last configured in case reconfiguring is needed. |
| 8252 |
|
| 8253 |
Synopsis: |
| 8254 |
./config.status OPTION... [FILE...] |
| 8255 |
|
| 8256 |
It configures the FILES, if none are specified, all the templates are |
| 8257 |
instantiated. The files must be specified without their dependencies, |
| 8258 |
as in |
| 8259 |
|
| 8260 |
./config.status foobar |
| 8261 |
|
| 8262 |
not |
| 8263 |
|
| 8264 |
./config.status foobar:foo.in:bar.in |
| 8265 |
|
| 8266 |
The supported OPTIONs are: |
| 8267 |
|
| 8268 |
‘--help’ |
| 8269 |
‘-h’ |
| 8270 |
Print a summary of the command line options, the list of the |
| 8271 |
template files and exit. |
| 8272 |
|
| 8273 |
‘--version’ |
| 8274 |
‘-V’ |
| 8275 |
Print the version number of Autoconf and exit. |
| 8276 |
|
| 8277 |
‘--debug’ |
| 8278 |
‘-d’ |
| 8279 |
Don't remove the temporary files. |
| 8280 |
|
| 8281 |
‘--file=FILE[:TEMPLATE]’ |
| 8282 |
Require that FILE be instantiated as if |
| 8283 |
‘AC_CONFIG_FILES(FILE:TEMPLATE)’ was used. Both FILE and TEMPLATE |
| 8284 |
may be ‘-’ in which case the standard output and/or standard input, |
| 8285 |
respectively, is used. If a TEMPLATE filename is relative, it is |
| 8286 |
first looked for in the build tree, and then in the source tree. |
| 8287 |
*Note Configuration Actions::, for more details. |
| 8288 |
|
| 8289 |
This option and the following ones provide one way for separately |
| 8290 |
distributed packages to share the values computed by ‘configure’. |
| 8291 |
Doing so can be useful if some of the packages need a superset of |
| 8292 |
the features that one of them, perhaps a common library, does. |
| 8293 |
These options allow a ‘config.status’ file to create files other |
| 8294 |
than the ones that its ‘configure.ac’ specifies, so it can be used |
| 8295 |
for a different package. |
| 8296 |
|
| 8297 |
‘--header=FILE[:TEMPLATE]’ |
| 8298 |
Same as ‘--file’ above, but with ‘AC_CONFIG_HEADERS’. |
| 8299 |
|
| 8300 |
‘--recheck’ |
| 8301 |
Ask ‘config.status’ to update itself and exit (no instantiation). |
| 8302 |
This option is useful if you change ‘configure’, so that the |
| 8303 |
results of some tests might be different from the previous run. |
| 8304 |
The ‘--recheck’ option re-runs ‘configure’ with the same arguments |
| 8305 |
you used before, plus the ‘--no-create’ option, which prevents |
| 8306 |
‘configure’ from running ‘config.status’ and creating ‘Makefile’ |
| 8307 |
and other files, and the ‘--no-recursion’ option, which prevents |
| 8308 |
‘configure’ from running other ‘configure’ scripts in |
| 8309 |
subdirectories. (This is so other ‘Makefile’ rules can run |
| 8310 |
‘config.status’ when it changes; *note Automatic Remaking::, for an |
| 8311 |
example). |
| 8312 |
|
| 8313 |
‘config.status’ checks several optional environment variables that |
| 8314 |
can alter its behavior: |
| 8315 |
|
| 8316 |
-- Variable: CONFIG_SHELL |
| 8317 |
The shell with which to run ‘configure’ for the ‘--recheck’ option. |
| 8318 |
It must be Bourne-compatible. The default is ‘/bin/sh’. |
| 8319 |
|
| 8320 |
-- Variable: CONFIG_STATUS |
| 8321 |
The file name to use for the shell script that records the |
| 8322 |
configuration. The default is ‘./config.status’. This variable is |
| 8323 |
useful when one package uses parts of another and the ‘configure’ |
| 8324 |
scripts shouldn't be merged because they are maintained separately. |
| 8325 |
|
| 8326 |
You can use ‘./config.status’ in your Makefiles. For example, in the |
| 8327 |
dependencies given above (*note Automatic Remaking::), ‘config.status’ |
| 8328 |
is run twice when ‘configure.ac’ has changed. If that bothers you, you |
| 8329 |
can make each run only regenerate the files for that rule: |
| 8330 |
config.h: stamp-h |
| 8331 |
stamp-h: config.h.in config.status |
| 8332 |
./config.status config.h |
| 8333 |
echo > stamp-h |
| 8334 |
|
| 8335 |
Makefile: Makefile.in config.status |
| 8336 |
./config.status Makefile |
| 8337 |
|
| 8338 |
The calling convention of ‘config.status’ has changed, see *note |
| 8339 |
Obsolete config.status Use::, for details. |
| 8340 |
|
| 8341 |
|
| 8342 |
File: autoconf.info, Node: Obsolete Constructs, Next: Questions, Prev: config.status Invocation, Up: Top |
| 8343 |
|
| 8344 |
15 Obsolete Constructs |
| 8345 |
********************** |
| 8346 |
|
| 8347 |
Autoconf changes, and throughout the years some constructs are |
| 8348 |
obsoleted. Most of the changes involve the macros, but the tools |
| 8349 |
themselves, or even some concepts, are now considered obsolete. |
| 8350 |
|
| 8351 |
You may completely skip this chapter if you are new to Autoconf, its |
| 8352 |
intention is mainly to help maintainers updating their packages by |
| 8353 |
understanding how to move to more modern constructs. |
| 8354 |
|
| 8355 |
* Menu: |
| 8356 |
|
| 8357 |
* Obsolete config.status Use:: Different calling convention |
| 8358 |
* acconfig.h:: Additional entries in ‘config.h.in’ |
| 8359 |
* autoupdate Invocation:: Automatic update of ‘configure.ac’ |
| 8360 |
* Obsolete Macros:: Backward compatibility macros |
| 8361 |
* Autoconf 1:: Tips for upgrading your files |
| 8362 |
* Autoconf 2.13:: Some fresher tips |
| 8363 |
|
| 8364 |
|
| 8365 |
File: autoconf.info, Node: Obsolete config.status Use, Next: acconfig.h, Prev: Obsolete Constructs, Up: Obsolete Constructs |
| 8366 |
|
| 8367 |
15.1 Obsolete ‘config.status’ Invocation |
| 8368 |
======================================== |
| 8369 |
|
| 8370 |
‘config.status’ now supports arguments to specify the files to |
| 8371 |
instantiate, see *note config.status Invocation::, for more details. |
| 8372 |
Before, environment variables had to be used. |
| 8373 |
|
| 8374 |
-- Variable: CONFIG_COMMANDS |
| 8375 |
The tags of the commands to execute. The default is the arguments |
| 8376 |
given to ‘AC_OUTPUT’ and ‘AC_CONFIG_COMMANDS’ in ‘configure.ac’. |
| 8377 |
|
| 8378 |
-- Variable: CONFIG_FILES |
| 8379 |
The files in which to perform ‘@VARIABLE@’ substitutions. The |
| 8380 |
default is the arguments given to ‘AC_OUTPUT’ and ‘AC_CONFIG_FILES’ |
| 8381 |
in ‘configure.ac’. |
| 8382 |
|
| 8383 |
-- Variable: CONFIG_HEADERS |
| 8384 |
The files in which to substitute C ‘#define’ statements. The |
| 8385 |
default is the arguments given to ‘AC_CONFIG_HEADERS’; if that |
| 8386 |
macro was not called, ‘config.status’ ignores this variable. |
| 8387 |
|
| 8388 |
-- Variable: CONFIG_LINKS |
| 8389 |
The symbolic links to establish. The default is the arguments |
| 8390 |
given to ‘AC_CONFIG_LINKS’; if that macro was not called, |
| 8391 |
‘config.status’ ignores this variable. |
| 8392 |
|
| 8393 |
In *note config.status Invocation::, using this old interface, the |
| 8394 |
example would be: |
| 8395 |
|
| 8396 |
config.h: stamp-h |
| 8397 |
stamp-h: config.h.in config.status |
| 8398 |
CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_FILES= \ |
| 8399 |
CONFIG_HEADERS=config.h ./config.status |
| 8400 |
echo > stamp-h |
| 8401 |
|
| 8402 |
Makefile: Makefile.in config.status |
| 8403 |
CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_HEADERS= \ |
| 8404 |
CONFIG_FILES=Makefile ./config.status |
| 8405 |
|
| 8406 |
(If ‘configure.ac’ does not call ‘AC_CONFIG_HEADERS’, there is no need |
| 8407 |
to set ‘CONFIG_HEADERS’ in the ‘make’ rules, equally for |
| 8408 |
‘CONFIG_COMMANDS’ etc.) |
| 8409 |
|
| 8410 |
|
| 8411 |
File: autoconf.info, Node: acconfig.h, Next: autoupdate Invocation, Prev: Obsolete config.status Use, Up: Obsolete Constructs |
| 8412 |
|
| 8413 |
15.2 ‘acconfig.h’ |
| 8414 |
================= |
| 8415 |
|
| 8416 |
In order to produce ‘config.h.in’, ‘autoheader’ needs to build or to |
| 8417 |
find templates for each symbol. Modern releases of Autoconf use |
| 8418 |
‘AH_VERBATIM’ and ‘AH_TEMPLATE’ (*note Autoheader Macros::), but in |
| 8419 |
older releases a file, ‘acconfig.h’, contained the list of needed |
| 8420 |
templates. ‘autoheader’ copies comments and ‘#define’ and ‘#undef’ |
| 8421 |
statements from ‘acconfig.h’ in the current directory, if present. This |
| 8422 |
file used to be mandatory if you ‘AC_DEFINE’ any additional symbols. |
| 8423 |
|
| 8424 |
Modern releases of Autoconf also provide ‘AH_TOP’ and ‘AH_BOTTOM’ if |
| 8425 |
you need to prepend/append some information to ‘config.h.in’. Ancient |
| 8426 |
versions of Autoconf had a similar feature: if ‘./acconfig.h’ contains |
| 8427 |
the string ‘@TOP@’, ‘autoheader’ copies the lines before the line |
| 8428 |
containing ‘@TOP@’ into the top of the file that it generates. |
| 8429 |
Similarly, if ‘./acconfig.h’ contains the string ‘@BOTTOM@’, |
| 8430 |
‘autoheader’ copies the lines after that line to the end of the file it |
| 8431 |
generates. Either or both of those strings may be omitted. An even |
| 8432 |
older alternate way to produce the same effect in jurasik versions of |
| 8433 |
Autoconf is to create the files ‘FILE.top’ (typically ‘config.h.top’) |
| 8434 |
and/or ‘FILE.bot’ in the current directory. If they exist, ‘autoheader’ |
| 8435 |
copies them to the beginning and end, respectively, of its output. |
| 8436 |
|
| 8437 |
In former versions of Autoconf, the files used in preparing a |
| 8438 |
software package for distribution were: |
| 8439 |
configure.ac --. .------> autoconf* -----> configure |
| 8440 |
+---+ |
| 8441 |
[aclocal.m4] --+ `---. |
| 8442 |
[acsite.m4] ---' | |
| 8443 |
+--> [autoheader*] -> [config.h.in] |
| 8444 |
[acconfig.h] ----. | |
| 8445 |
+-----' |
| 8446 |
[config.h.top] --+ |
| 8447 |
[config.h.bot] --' |
| 8448 |
|
| 8449 |
Use only the ‘AH_’ macros, ‘configure.ac’ should be self-contained, |
| 8450 |
and should not depend upon ‘acconfig.h’ etc. |
| 8451 |
|
| 8452 |
|
| 8453 |
File: autoconf.info, Node: autoupdate Invocation, Next: Obsolete Macros, Prev: acconfig.h, Up: Obsolete Constructs |
| 8454 |
|
| 8455 |
15.3 Using ‘autoupdate’ to Modernize ‘configure.ac’ |
| 8456 |
=================================================== |
| 8457 |
|
| 8458 |
The ‘autoupdate’ program updates a ‘configure.ac’ file that calls |
| 8459 |
Autoconf macros by their old names to use the current macro names. In |
| 8460 |
version 2 of Autoconf, most of the macros were renamed to use a more |
| 8461 |
uniform and descriptive naming scheme. *Note Macro Names::, for a |
| 8462 |
description of the new scheme. Although the old names still work (*note |
| 8463 |
Obsolete Macros::, for a list of the old macros and the corresponding |
| 8464 |
new names), you can make your ‘configure.ac’ files more readable and |
| 8465 |
make it easier to use the current Autoconf documentation if you update |
| 8466 |
them to use the new macro names. |
| 8467 |
|
| 8468 |
If given no arguments, ‘autoupdate’ updates ‘configure.ac’, backing |
| 8469 |
up the original version with the suffix ‘~’ (or the value of the |
| 8470 |
environment variable ‘SIMPLE_BACKUP_SUFFIX’, if that is set). If you |
| 8471 |
give ‘autoupdate’ an argument, it reads that file instead of |
| 8472 |
‘configure.ac’ and writes the updated file to the standard output. |
| 8473 |
|
| 8474 |
‘autoupdate’ accepts the following options: |
| 8475 |
|
| 8476 |
‘--help’ |
| 8477 |
‘-h’ |
| 8478 |
Print a summary of the command line options and exit. |
| 8479 |
|
| 8480 |
‘--version’ |
| 8481 |
‘-V’ |
| 8482 |
Print the version number of Autoconf and exit. |
| 8483 |
|
| 8484 |
‘--verbose’ |
| 8485 |
‘-v’ |
| 8486 |
Report processing steps. |
| 8487 |
|
| 8488 |
‘--debug’ |
| 8489 |
‘-d’ |
| 8490 |
Don't remove the temporary files. |
| 8491 |
|
| 8492 |
‘--autoconf-dir=DIR’ |
| 8493 |
‘-A DIR’ |
| 8494 |
Override the location where the installed Autoconf data files are |
| 8495 |
looked for. You can also set the ‘AC_MACRODIR’ environment |
| 8496 |
variable to a directory; this option overrides the environment |
| 8497 |
variable. |
| 8498 |
|
| 8499 |
This option is rarely needed and dangerous; it is only used when |
| 8500 |
one plays with different versions of Autoconf simultaneously. |
| 8501 |
|
| 8502 |
‘--localdir=DIR’ |
| 8503 |
‘-l DIR’ |
| 8504 |
Look for the package file ‘aclocal.m4’ in directory DIR instead of |
| 8505 |
in the current directory. |
| 8506 |
|
| 8507 |
|
| 8508 |
File: autoconf.info, Node: Obsolete Macros, Next: Autoconf 1, Prev: autoupdate Invocation, Up: Obsolete Constructs |
| 8509 |
|
| 8510 |
15.4 Obsolete Macros |
| 8511 |
==================== |
| 8512 |
|
| 8513 |
Several macros are obsoleted in Autoconf, for various reasons (typically |
| 8514 |
they failed to quote properly, couldn't be extended for more recent |
| 8515 |
issues etc.). They are still supported, but deprecated: their use |
| 8516 |
should be avoided. |
| 8517 |
|
| 8518 |
During the jump from Autoconf version 1 to version 2, most of the |
| 8519 |
macros were renamed to use a more uniform and descriptive naming scheme, |
| 8520 |
but their signature did not change. *Note Macro Names::, for a |
| 8521 |
description of the new naming scheme. Below, there is just the mapping |
| 8522 |
from old names to new names for these macros, the reader is invited to |
| 8523 |
refer to the definition of the new macro for the signature and the |
| 8524 |
description. |
| 8525 |
|
| 8526 |
-- Macro: AC_ALLOCA |
| 8527 |
‘AC_FUNC_ALLOCA’ |
| 8528 |
|
| 8529 |
-- Macro: AC_ARG_ARRAY |
| 8530 |
removed because of limited usefulness |
| 8531 |
|
| 8532 |
-- Macro: AC_C_CROSS |
| 8533 |
This macro is obsolete; it does nothing. |
| 8534 |
|
| 8535 |
-- Macro: AC_CANONICAL_SYSTEM |
| 8536 |
Determine the system type and set output variables to the names of |
| 8537 |
the canonical system types. *Note Canonicalizing::, for details |
| 8538 |
about the variables this macro sets. |
| 8539 |
|
| 8540 |
The user is encouraged to use either ‘AC_CANONICAL_BUILD’, or |
| 8541 |
‘AC_CANONICAL_HOST’, or ‘AC_CANONICAL_TARGET’, depending on the |
| 8542 |
needs. Using ‘AC_CANONICAL_TARGET’ is enough to run the two other |
| 8543 |
macros. |
| 8544 |
|
| 8545 |
-- Macro: AC_CHAR_UNSIGNED |
| 8546 |
‘AC_C_CHAR_UNSIGNED’ |
| 8547 |
|
| 8548 |
-- Macro: AC_CHECK_TYPE (TYPE, DEFAULT) |
| 8549 |
Autoconf, up to 2.13, used to provide this version of |
| 8550 |
‘AC_CHECK_TYPE’, deprecated because of its flaws. Firstly, |
| 8551 |
although it is a member of the ‘CHECK’ clan, singular sub-family, |
| 8552 |
it does more than just checking. Second, missing types are not |
| 8553 |
‘typedef’'d, they are ‘#define’'d, which can lead to incompatible |
| 8554 |
code in the case of pointer types. |
| 8555 |
|
| 8556 |
This use of ‘AC_CHECK_TYPE’ is obsolete and discouraged, see *note |
| 8557 |
Generic Types::, for the description of the current macro. |
| 8558 |
|
| 8559 |
If the type TYPE is not defined, define it to be the C (or C++) |
| 8560 |
builtin type DEFAULT; e.g., ‘short’ or ‘unsigned’. |
| 8561 |
|
| 8562 |
This macro is equivalent to: |
| 8563 |
|
| 8564 |
AC_CHECK_TYPE([TYPE], |
| 8565 |
[AC_DEFINE([TYPE], [DEFAULT], |
| 8566 |
[Define to `DEFAULT' if <sys/types.h> |
| 8567 |
does not define.])]) |
| 8568 |
|
| 8569 |
In order to keep backward compatibility, the two versions of |
| 8570 |
‘AC_CHECK_TYPE’ are implemented, selected by a simple heuristics: |
| 8571 |
|
| 8572 |
1. If there are three or four arguments, the modern version is |
| 8573 |
used. |
| 8574 |
|
| 8575 |
2. If the second argument appears to be a C or C++ type, then the |
| 8576 |
obsolete version is used. This happens if the argument is a C |
| 8577 |
or C++ _builtin_ type or a C identifier ending in ‘_t’, |
| 8578 |
optionally followed by one of ‘[(* ’ and then by a string of |
| 8579 |
zero or more characters taken from the set ‘[]()* _a-zA-Z0-9’. |
| 8580 |
|
| 8581 |
3. If the second argument is spelled with the alphabet of valid C |
| 8582 |
and C++ types, the user is warned and the modern version is |
| 8583 |
used. |
| 8584 |
|
| 8585 |
4. Otherwise, the modern version is used. |
| 8586 |
|
| 8587 |
You are encouraged either to use a valid builtin type, or to use |
| 8588 |
the equivalent modern code (see above), or better yet, to use |
| 8589 |
‘AC_CHECK_TYPES’ together with |
| 8590 |
|
| 8591 |
#if !HAVE_LOFF_T |
| 8592 |
typedef loff_t off_t; |
| 8593 |
#endif |
| 8594 |
|
| 8595 |
-- Macro: AC_CHECKING (FEATURE-DESCRIPTION) |
| 8596 |
Same as ‘AC_MSG_NOTICE([checking FEATURE-DESCRIPTION...]’. |
| 8597 |
|
| 8598 |
-- Macro: AC_COMPILE_CHECK (ECHO-TEXT, INCLUDES, FUNCTION-BODY, |
| 8599 |
ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]) |
| 8600 |
This is an obsolete version of ‘AC_TRY_LINK’ (*note Examining |
| 8601 |
Libraries::), with the addition that it prints ‘checking for |
| 8602 |
ECHO-TEXT’ to the standard output first, if ECHO-TEXT is non-empty. |
| 8603 |
Use ‘AC_MSG_CHECKING’ and ‘AC_MSG_RESULT’ instead to print messages |
| 8604 |
(*note Printing Messages::). |
| 8605 |
|
| 8606 |
-- Macro: AC_CONST |
| 8607 |
‘AC_C_CONST’ |
| 8608 |
|
| 8609 |
-- Macro: AC_CROSS_CHECK |
| 8610 |
Same as ‘AC_C_CROSS’, which is obsolete too, and does nothing |
| 8611 |
‘:-)’. |
| 8612 |
|
| 8613 |
-- Macro: AC_CYGWIN |
| 8614 |
Check for the Cygwin environment in which case the shell variable |
| 8615 |
‘CYGWIN’ is set to ‘yes’. Don't use this macro, the dignified |
| 8616 |
means to check the nature of the host is using ‘AC_CANONICAL_HOST’. |
| 8617 |
As a matter of fact this macro is defined as: |
| 8618 |
|
| 8619 |
AC_REQUIRE([AC_CANONICAL_HOST])[]dnl |
| 8620 |
case $host_os in |
| 8621 |
*cygwin* ) CYGWIN=yes;; |
| 8622 |
* ) CYGWIN=no;; |
| 8623 |
esac |
| 8624 |
|
| 8625 |
Beware that the variable ‘CYGWIN’ has a very special meaning when |
| 8626 |
running CygWin32, and should not be changed. That's yet another |
| 8627 |
reason not to use this macro. |
| 8628 |
|
| 8629 |
-- Macro: AC_DECL_YYTEXT |
| 8630 |
Does nothing, now integrated in ‘AC_PROG_LEX’. |
| 8631 |
|
| 8632 |
-- Macro: AC_DIR_HEADER |
| 8633 |
Like calling ‘AC_FUNC_CLOSEDIR_VOID’ and‘AC_HEADER_DIRENT’, but |
| 8634 |
defines a different set of C preprocessor macros to indicate which |
| 8635 |
header file is found: |
| 8636 |
|
| 8637 |
Header Old Symbol New Symbol |
| 8638 |
‘dirent.h’ ‘DIRENT’ ‘HAVE_DIRENT_H’ |
| 8639 |
‘sys/ndir.h’ ‘SYSNDIR’ ‘HAVE_SYS_NDIR_H’ |
| 8640 |
‘sys/dir.h’ ‘SYSDIR’ ‘HAVE_SYS_DIR_H’ |
| 8641 |
‘ndir.h’ ‘NDIR’ ‘HAVE_NDIR_H’ |
| 8642 |
|
| 8643 |
-- Macro: AC_DYNIX_SEQ |
| 8644 |
If on Dynix/PTX (Sequent UNIX), add ‘-lseq’ to output variable |
| 8645 |
‘LIBS’. This macro used to be defined as |
| 8646 |
|
| 8647 |
AC_CHECK_LIB(seq, getmntent, LIBS="-lseq $LIBS") |
| 8648 |
|
| 8649 |
now it is just ‘AC_FUNC_GETMNTENT’. |
| 8650 |
|
| 8651 |
-- Macro: AC_EXEEXT |
| 8652 |
Defined the output variable ‘EXEEXT’ based on the output of the |
| 8653 |
compiler, which is now done automatically. Typically set to empty |
| 8654 |
string if Unix and ‘.exe’ if Win32 or OS/2. |
| 8655 |
|
| 8656 |
-- Macro: AC_EMXOS2 |
| 8657 |
Similar to ‘AC_CYGWIN’ but checks for the EMX environment on OS/2 |
| 8658 |
and sets ‘EMXOS2’. |
| 8659 |
|
| 8660 |
-- Macro: AC_ERROR |
| 8661 |
‘AC_MSG_ERROR’ |
| 8662 |
|
| 8663 |
-- Macro: AC_FIND_X |
| 8664 |
‘AC_PATH_X’ |
| 8665 |
|
| 8666 |
-- Macro: AC_FIND_XTRA |
| 8667 |
‘AC_PATH_XTRA’ |
| 8668 |
|
| 8669 |
-- Macro: AC_FUNC_CHECK |
| 8670 |
‘AC_CHECK_FUNC’ |
| 8671 |
|
| 8672 |
-- Macro: AC_FUNC_WAIT3 |
| 8673 |
If ‘wait3’ is found and fills in the contents of its third argument |
| 8674 |
(a ‘struct rusage *’), which HP-UX does not do, define |
| 8675 |
‘HAVE_WAIT3’. |
| 8676 |
|
| 8677 |
These days portable programs should use ‘waitpid’, not ‘wait3’, as |
| 8678 |
‘wait3’ is being removed from the Open Group standards, and will |
| 8679 |
not appear in the next revision of POSIX. |
| 8680 |
|
| 8681 |
-- Macro: AC_GCC_TRADITIONAL |
| 8682 |
‘AC_PROG_GCC_TRADITIONAL’ |
| 8683 |
|
| 8684 |
-- Macro: AC_GETGROUPS_T |
| 8685 |
‘AC_TYPE_GETGROUPS’ |
| 8686 |
|
| 8687 |
-- Macro: AC_GETLOADAVG |
| 8688 |
‘AC_FUNC_GETLOADAVG’ |
| 8689 |
|
| 8690 |
-- Macro: AC_HAVE_FUNCS |
| 8691 |
‘AC_CHECK_FUNCS’ |
| 8692 |
|
| 8693 |
-- Macro: AC_HAVE_HEADERS |
| 8694 |
‘AC_CHECK_HEADERS’ |
| 8695 |
|
| 8696 |
-- Macro: AC_HAVE_LIBRARY (LIBRARY, [ACTION-IF-FOUND], |
| 8697 |
[ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES]) |
| 8698 |
This macro is equivalent to calling ‘AC_CHECK_LIB’ with a FUNCTION |
| 8699 |
argument of ‘main’. In addition, LIBRARY can be written as any of |
| 8700 |
‘foo’, ‘-lfoo’, or ‘libfoo.a’. In all of those cases, the compiler |
| 8701 |
is passed ‘-lfoo’. However, LIBRARY cannot be a shell variable; it |
| 8702 |
must be a literal name. |
| 8703 |
|
| 8704 |
-- Macro: AC_HAVE_POUNDBANG |
| 8705 |
‘AC_SYS_INTERPRETER’ (different calling convention) |
| 8706 |
|
| 8707 |
-- Macro: AC_HEADER_CHECK |
| 8708 |
‘AC_CHECK_HEADER’ |
| 8709 |
|
| 8710 |
-- Macro: AC_HEADER_EGREP |
| 8711 |
‘AC_EGREP_HEADER’ |
| 8712 |
|
| 8713 |
-- Macro: AC_HELP_STRING |
| 8714 |
‘AS_HELP_STRING’ |
| 8715 |
|
| 8716 |
-- Macro: AC_INIT (UNIQUE-FILE-IN-SOURCE-DIR) |
| 8717 |
Formerly ‘AC_INIT’ used to have a single argument, and was |
| 8718 |
equivalent to: |
| 8719 |
|
| 8720 |
AC_INIT |
| 8721 |
AC_CONFIG_SRCDIR(UNIQUE-FILE-IN-SOURCE-DIR) |
| 8722 |
|
| 8723 |
-- Macro: AC_INLINE |
| 8724 |
‘AC_C_INLINE’ |
| 8725 |
|
| 8726 |
-- Macro: AC_INT_16_BITS |
| 8727 |
If the C type ‘int’ is 16 bits wide, define ‘INT_16_BITS’. Use |
| 8728 |
‘AC_CHECK_SIZEOF(int)’ instead. |
| 8729 |
|
| 8730 |
-- Macro: AC_IRIX_SUN |
| 8731 |
If on IRIX (Silicon Graphics UNIX), add ‘-lsun’ to output ‘LIBS’. |
| 8732 |
If you were using it to get ‘getmntent’, use ‘AC_FUNC_GETMNTENT’ |
| 8733 |
instead. If you used it for the NIS versions of the password and |
| 8734 |
group functions, use ‘AC_CHECK_LIB(sun, getpwnam)’. Up to Autoconf |
| 8735 |
2.13, it used to be |
| 8736 |
|
| 8737 |
AC_CHECK_LIB(sun, getmntent, LIBS="-lsun $LIBS") |
| 8738 |
|
| 8739 |
now it is defined as |
| 8740 |
|
| 8741 |
AC_FUNC_GETMNTENT |
| 8742 |
AC_CHECK_LIB(sun, getpwnam) |
| 8743 |
|
| 8744 |
-- Macro: AC_LANG_C |
| 8745 |
Same as ‘AC_LANG(C)’. |
| 8746 |
|
| 8747 |
-- Macro: AC_LANG_CPLUSPLUS |
| 8748 |
Same as ‘AC_LANG(C++)’. |
| 8749 |
|
| 8750 |
-- Macro: AC_LANG_FORTRAN77 |
| 8751 |
Same as ‘AC_LANG(Fortran 77)’. |
| 8752 |
|
| 8753 |
-- Macro: AC_LANG_RESTORE |
| 8754 |
Select the LANGUAGE that is saved on the top of the stack, as set |
| 8755 |
by ‘AC_LANG_SAVE’, remove it from the stack, and call |
| 8756 |
‘AC_LANG(LANGUAGE)’. |
| 8757 |
|
| 8758 |
-- Macro: AC_LANG_SAVE |
| 8759 |
Remember the current language (as set by ‘AC_LANG’) on a stack. |
| 8760 |
The current language does not change. ‘AC_LANG_PUSH’ is preferred. |
| 8761 |
|
| 8762 |
-- Macro: AC_LINK_FILES (SOURCE..., DEST...) |
| 8763 |
This is an obsolete version of ‘AC_CONFIG_LINKS’. An updated |
| 8764 |
version of: |
| 8765 |
|
| 8766 |
AC_LINK_FILES(config/$machine.h config/$obj_format.h, |
| 8767 |
host.h object.h) |
| 8768 |
|
| 8769 |
is: |
| 8770 |
|
| 8771 |
AC_CONFIG_LINKS(host.h:config/$machine.h |
| 8772 |
object.h:config/$obj_format.h) |
| 8773 |
|
| 8774 |
-- Macro: AC_LN_S |
| 8775 |
‘AC_PROG_LN_S’ |
| 8776 |
|
| 8777 |
-- Macro: AC_LONG_64_BITS |
| 8778 |
Define ‘LONG_64_BITS’ if the C type ‘long int’ is 64 bits wide. |
| 8779 |
Use the generic macro ‘AC_CHECK_SIZEOF([long int])’ instead. |
| 8780 |
|
| 8781 |
-- Macro: AC_LONG_DOUBLE |
| 8782 |
‘AC_C_LONG_DOUBLE’ |
| 8783 |
|
| 8784 |
-- Macro: AC_LONG_FILE_NAMES |
| 8785 |
‘AC_SYS_LONG_FILE_NAMES’ |
| 8786 |
|
| 8787 |
-- Macro: AC_MAJOR_HEADER |
| 8788 |
‘AC_HEADER_MAJOR’ |
| 8789 |
|
| 8790 |
-- Macro: AC_MEMORY_H |
| 8791 |
Used to define ‘NEED_MEMORY_H’ if the ‘mem’ functions were defined |
| 8792 |
in ‘memory.h’. Today it is equivalent to |
| 8793 |
‘AC_CHECK_HEADERS(memory.h)’. Adjust your code to depend upon |
| 8794 |
‘HAVE_MEMORY_H’, not ‘NEED_MEMORY_H’, see *Note Standard Symbols::. |
| 8795 |
|
| 8796 |
-- Macro: AC_MINGW32 |
| 8797 |
Similar to ‘AC_CYGWIN’ but checks for the MingW32 compiler |
| 8798 |
environment and sets ‘MINGW32’. |
| 8799 |
|
| 8800 |
-- Macro: AC_MINUS_C_MINUS_O |
| 8801 |
‘AC_PROG_CC_C_O’ |
| 8802 |
|
| 8803 |
-- Macro: AC_MMAP |
| 8804 |
‘AC_FUNC_MMAP’ |
| 8805 |
|
| 8806 |
-- Macro: AC_MODE_T |
| 8807 |
‘AC_TYPE_MODE_T’ |
| 8808 |
|
| 8809 |
-- Macro: AC_OBJEXT |
| 8810 |
Defined the output variable ‘OBJEXT’ based on the output of the |
| 8811 |
compiler, after .c files have been excluded. Typically set to ‘o’ |
| 8812 |
if Unix, ‘obj’ if Win32. Now the compiler checking macros handle |
| 8813 |
this automatically. |
| 8814 |
|
| 8815 |
-- Macro: AC_OBSOLETE (THIS-MACRO-NAME, [SUGGESTION]) |
| 8816 |
Make ‘m4’ print a message to the standard error output warning that |
| 8817 |
THIS-MACRO-NAME is obsolete, and giving the file and line number |
| 8818 |
where it was called. THIS-MACRO-NAME should be the name of the |
| 8819 |
macro that is calling ‘AC_OBSOLETE’. If SUGGESTION is given, it is |
| 8820 |
printed at the end of the warning message; for example, it can be a |
| 8821 |
suggestion for what to use instead of THIS-MACRO-NAME. |
| 8822 |
|
| 8823 |
For instance |
| 8824 |
|
| 8825 |
AC_OBSOLETE([$0], [; use AC_CHECK_HEADERS(unistd.h) instead])dnl |
| 8826 |
|
| 8827 |
You are encouraged to use ‘AU_DEFUN’ instead, since it gives better |
| 8828 |
services to the user. |
| 8829 |
|
| 8830 |
-- Macro: AC_OFF_T |
| 8831 |
‘AC_TYPE_OFF_T’ |
| 8832 |
|
| 8833 |
-- Macro: AC_OUTPUT ([FILE]..., [EXTRA-CMDS], [INIT-CMDS], [SAVE-DEFS]) |
| 8834 |
The use of ‘AC_OUTPUT’ with argument is deprecated, this obsoleted |
| 8835 |
interface is equivalent to: |
| 8836 |
|
| 8837 |
AC_CONFIG_FILES(FILE...) |
| 8838 |
AC_CONFIG_COMMANDS([default], |
| 8839 |
EXTRA-CMDS, INIT-CMDS) |
| 8840 |
AC_SETUP_DEFS(SAVE-DEFS) |
| 8841 |
AC_OUTPUT |
| 8842 |
|
| 8843 |
If you specify SAVE-DEFS, autoconf will save the ‘#define’s in a |
| 8844 |
different form, for use in the files specified in |
| 8845 |
‘AC_CONFIG_HEADERS’. In this case, autoconf substitutes the |
| 8846 |
C-style ‘#define’s where it finds ‘@DEFS@’. This runs faster, and |
| 8847 |
is simpler to maintain than building a file of ‘#undef’s, since |
| 8848 |
autoconf will automatically generate a ‘#define’ for each |
| 8849 |
‘AC_DEFINE’ that you execute in the ‘configure’ script. The value |
| 8850 |
for SAVE-DEFS should be either ‘cat’, or ‘sort’; this value is used |
| 8851 |
to filter the list of ‘#define’s before editing. Sorted lists are |
| 8852 |
easier to read, but you may wish to see the definitions in the |
| 8853 |
order that they were processed. |
| 8854 |
|
| 8855 |
-- Macro: AC_OUTPUT_COMMANDS (EXTRA-CMDS, [INIT-CMDS]) |
| 8856 |
Specify additional shell commands to run at the end of |
| 8857 |
‘config.status’, and shell commands to initialize any variables |
| 8858 |
from ‘configure’. This macro may be called multiple times. It is |
| 8859 |
obsolete, replaced by ‘AC_CONFIG_COMMANDS’. |
| 8860 |
|
| 8861 |
Here is an unrealistic example: |
| 8862 |
|
| 8863 |
fubar=27 |
| 8864 |
AC_OUTPUT_COMMANDS([echo this is extra $fubar, and so on.], |
| 8865 |
fubar=$fubar) |
| 8866 |
AC_OUTPUT_COMMANDS([echo this is another, extra, bit], |
| 8867 |
[echo init bit]) |
| 8868 |
|
| 8869 |
Aside from the fact that ‘AC_CONFIG_COMMANDS’ requires an |
| 8870 |
additional key, an important difference is that |
| 8871 |
‘AC_OUTPUT_COMMANDS’ is quoting its arguments twice, while |
| 8872 |
‘AC_CONFIG_COMMANDS’. This means that ‘AC_CONFIG_COMMANDS’ can |
| 8873 |
safely be given macro calls as arguments: |
| 8874 |
|
| 8875 |
AC_CONFIG_COMMANDS(foo, [my_FOO()]) |
| 8876 |
|
| 8877 |
conversely, where one level of quoting was enough for literal |
| 8878 |
strings with ‘AC_OUTPUT_COMMANDS’, you need two with |
| 8879 |
‘AC_CONFIG_COMMANDS’. The following lines are equivalent: |
| 8880 |
|
| 8881 |
AC_OUTPUT_COMMANDS([echo "Square brackets: []"]) |
| 8882 |
AC_CONFIG_COMMANDS(default, [[echo "Square brackets: []"]]) |
| 8883 |
|
| 8884 |
-- Macro: AC_PID_T |
| 8885 |
‘AC_TYPE_PID_T’ |
| 8886 |
|
| 8887 |
-- Macro: AC_PREFIX |
| 8888 |
‘AC_PREFIX_PROGRAM’ |
| 8889 |
|
| 8890 |
-- Macro: AC_PROGRAMS_CHECK |
| 8891 |
‘AC_CHECK_PROGS’ |
| 8892 |
|
| 8893 |
-- Macro: AC_PROGRAMS_PATH |
| 8894 |
‘AC_PATH_PROGS’ |
| 8895 |
|
| 8896 |
-- Macro: AC_PROGRAM_CHECK |
| 8897 |
‘AC_CHECK_PROG’ |
| 8898 |
|
| 8899 |
-- Macro: AC_PROGRAM_EGREP |
| 8900 |
‘AC_EGREP_CPP’ |
| 8901 |
|
| 8902 |
-- Macro: AC_PROGRAM_PATH |
| 8903 |
‘AC_PATH_PROG’ |
| 8904 |
|
| 8905 |
-- Macro: AC_REMOTE_TAPE |
| 8906 |
removed because of limited usefulness |
| 8907 |
|
| 8908 |
-- Macro: AC_RESTARTABLE_SYSCALLS |
| 8909 |
‘AC_SYS_RESTARTABLE_SYSCALLS’ |
| 8910 |
|
| 8911 |
-- Macro: AC_RETSIGTYPE |
| 8912 |
‘AC_TYPE_SIGNAL’ |
| 8913 |
|
| 8914 |
-- Macro: AC_RSH |
| 8915 |
Removed because of limited usefulness. |
| 8916 |
|
| 8917 |
-- Macro: AC_SCO_INTL |
| 8918 |
If on SCO UNIX, add ‘-lintl’ to output variable ‘LIBS’. This macro |
| 8919 |
used to |
| 8920 |
|
| 8921 |
AC_CHECK_LIB(intl, strftime, LIBS="-lintl $LIBS") |
| 8922 |
|
| 8923 |
now it just calls ‘AC_FUNC_STRFTIME’ instead. |
| 8924 |
|
| 8925 |
-- Macro: AC_SETVBUF_REVERSED |
| 8926 |
‘AC_FUNC_SETVBUF_REVERSED’ |
| 8927 |
|
| 8928 |
-- Macro: AC_SET_MAKE |
| 8929 |
‘AC_PROG_MAKE_SET’ |
| 8930 |
|
| 8931 |
-- Macro: AC_SIZEOF_TYPE |
| 8932 |
‘AC_CHECK_SIZEOF’ |
| 8933 |
|
| 8934 |
-- Macro: AC_SIZE_T |
| 8935 |
‘AC_TYPE_SIZE_T’ |
| 8936 |
|
| 8937 |
-- Macro: AC_STAT_MACROS_BROKEN |
| 8938 |
‘AC_HEADER_STAT’ |
| 8939 |
|
| 8940 |
-- Macro: AC_STDC_HEADERS |
| 8941 |
‘AC_HEADER_STDC’ |
| 8942 |
|
| 8943 |
-- Macro: AC_STRCOLL |
| 8944 |
‘AC_FUNC_STRCOLL’ |
| 8945 |
|
| 8946 |
-- Macro: AC_ST_BLKSIZE |
| 8947 |
‘AC_STRUCT_ST_BLKSIZE’ |
| 8948 |
|
| 8949 |
-- Macro: AC_ST_BLOCKS |
| 8950 |
‘AC_STRUCT_ST_BLOCKS’ |
| 8951 |
|
| 8952 |
-- Macro: AC_ST_RDEV |
| 8953 |
‘AC_STRUCT_ST_RDEV’ |
| 8954 |
|
| 8955 |
-- Macro: AC_SYS_RESTARTABLE_SYSCALLS |
| 8956 |
If the system automatically restarts a system call that is |
| 8957 |
interrupted by a signal, define ‘HAVE_RESTARTABLE_SYSCALLS’. This |
| 8958 |
macro does not check if system calls are restarted in general-it |
| 8959 |
tests whether a signal handler installed with ‘signal’ (but not |
| 8960 |
‘sigaction’) causes system calls to be restarted. It does not test |
| 8961 |
if system calls can be restarted when interrupted by signals that |
| 8962 |
have no handler. |
| 8963 |
|
| 8964 |
These days portable programs should use ‘sigaction’ with |
| 8965 |
‘SA_RESTART’ if they want restartable system calls. They should |
| 8966 |
not rely on ‘HAVE_RESTARTABLE_SYSCALLS’, since nowadays whether a |
| 8967 |
system call is restartable is a dynamic issue, not a |
| 8968 |
configuration-time issue. |
| 8969 |
|
| 8970 |
-- Macro: AC_SYS_SIGLIST_DECLARED |
| 8971 |
‘AC_DECL_SYS_SIGLIST’ |
| 8972 |
|
| 8973 |
-- Macro: AC_TEST_CPP |
| 8974 |
‘AC_TRY_CPP’ |
| 8975 |
|
| 8976 |
-- Macro: AC_TEST_PROGRAM |
| 8977 |
‘AC_TRY_RUN’ |
| 8978 |
|
| 8979 |
-- Macro: AC_TIMEZONE |
| 8980 |
‘AC_STRUCT_TIMEZONE’ |
| 8981 |
|
| 8982 |
-- Macro: AC_TIME_WITH_SYS_TIME |
| 8983 |
‘AC_HEADER_TIME’ |
| 8984 |
|
| 8985 |
-- Macro: AC_UID_T |
| 8986 |
‘AC_TYPE_UID_T’ |
| 8987 |
|
| 8988 |
-- Macro: AC_UNISTD_H |
| 8989 |
Same as ‘AC_CHECK_HEADERS(unistd.h)’. |
| 8990 |
|
| 8991 |
-- Macro: AC_USG |
| 8992 |
Define ‘USG’ if the BSD string functions are defined in |
| 8993 |
‘strings.h’. You should no longer depend upon ‘USG’, but on |
| 8994 |
‘HAVE_STRING_H’, see *Note Standard Symbols::. |
| 8995 |
|
| 8996 |
-- Macro: AC_UTIME_NULL |
| 8997 |
‘AC_FUNC_UTIME_NULL’ |
| 8998 |
|
| 8999 |
-- Macro: AC_VALIDATE_CACHED_SYSTEM_TUPLE ([CMD]) |
| 9000 |
If the cache file is inconsistent with the current host, target and |
| 9001 |
build system types, it used to execute CMD or print a default error |
| 9002 |
message. |
| 9003 |
|
| 9004 |
This is now handled by default. |
| 9005 |
|
| 9006 |
-- Macro: AC_VERBOSE (RESULT-DESCRIPTION) |
| 9007 |
‘AC_MSG_RESULT’. |
| 9008 |
|
| 9009 |
-- Macro: AC_VFORK |
| 9010 |
‘AC_FUNC_VFORK’ |
| 9011 |
|
| 9012 |
-- Macro: AC_VPRINTF |
| 9013 |
‘AC_FUNC_VPRINTF’ |
| 9014 |
|
| 9015 |
-- Macro: AC_WAIT3 |
| 9016 |
‘AC_FUNC_WAIT3’ |
| 9017 |
|
| 9018 |
-- Macro: AC_WARN |
| 9019 |
‘AC_MSG_WARN’ |
| 9020 |
|
| 9021 |
-- Macro: AC_WORDS_BIGENDIAN |
| 9022 |
‘AC_C_BIGENDIAN’ |
| 9023 |
|
| 9024 |
-- Macro: AC_XENIX_DIR |
| 9025 |
This macro used to add ‘-lx’ to output variable ‘LIBS’ if on Xenix. |
| 9026 |
Also, if ‘dirent.h’ is being checked for, added ‘-ldir’ to ‘LIBS’. |
| 9027 |
Now it is merely an alias of ‘AC_HEADER_DIRENT’ instead, plus some |
| 9028 |
code to detect whether running XENIX on which you should not |
| 9029 |
depend: |
| 9030 |
|
| 9031 |
AC_MSG_CHECKING([for Xenix]) |
| 9032 |
AC_EGREP_CPP(yes, |
| 9033 |
[#if defined M_XENIX && !defined M_UNIX |
| 9034 |
yes |
| 9035 |
#endif], |
| 9036 |
[AC_MSG_RESULT([yes]); XENIX=yes], |
| 9037 |
[AC_MSG_RESULT([no]); XENIX=]) |
| 9038 |
|
| 9039 |
-- Macro: AC_YYTEXT_POINTER |
| 9040 |
‘AC_DECL_YYTEXT’ |
| 9041 |
|
| 9042 |
|
| 9043 |
File: autoconf.info, Node: Autoconf 1, Next: Autoconf 2.13, Prev: Obsolete Macros, Up: Obsolete Constructs |
| 9044 |
|
| 9045 |
15.5 Upgrading From Version 1 |
| 9046 |
============================= |
| 9047 |
|
| 9048 |
Autoconf version 2 is mostly backward compatible with version 1. |
| 9049 |
However, it introduces better ways to do some things, and doesn't |
| 9050 |
support some of the ugly things in version 1. So, depending on how |
| 9051 |
sophisticated your ‘configure.ac’ files are, you might have to do some |
| 9052 |
manual work in order to upgrade to version 2. This chapter points out |
| 9053 |
some problems to watch for when upgrading. Also, perhaps your |
| 9054 |
‘configure’ scripts could benefit from some of the new features in |
| 9055 |
version 2; the changes are summarized in the file ‘NEWS’ in the Autoconf |
| 9056 |
distribution. |
| 9057 |
|
| 9058 |
* Menu: |
| 9059 |
|
| 9060 |
* Changed File Names:: Files you might rename |
| 9061 |
* Changed Makefiles:: New things to put in ‘Makefile.in’ |
| 9062 |
* Changed Macros:: Macro calls you might replace |
| 9063 |
* Changed Results:: Changes in how to check test results |
| 9064 |
* Changed Macro Writing:: Better ways to write your own macros |
| 9065 |
|
| 9066 |
|
| 9067 |
File: autoconf.info, Node: Changed File Names, Next: Changed Makefiles, Prev: Autoconf 1, Up: Autoconf 1 |
| 9068 |
|
| 9069 |
15.5.1 Changed File Names |
| 9070 |
------------------------- |
| 9071 |
|
| 9072 |
If you have an ‘aclocal.m4’ installed with Autoconf (as opposed to in a |
| 9073 |
particular package's source directory), you must rename it to |
| 9074 |
‘acsite.m4’. *Note autoconf Invocation::. |
| 9075 |
|
| 9076 |
If you distribute ‘install.sh’ with your package, rename it to |
| 9077 |
‘install-sh’ so ‘make’ builtin rules won't inadvertently create a file |
| 9078 |
called ‘install’ from it. ‘AC_PROG_INSTALL’ looks for the script under |
| 9079 |
both names, but it is best to use the new name. |
| 9080 |
|
| 9081 |
If you were using ‘config.h.top’, ‘config.h.bot’, or ‘acconfig.h’, |
| 9082 |
you still can, but you will have less clutter if you use the ‘AH_’ |
| 9083 |
macros. *Note Autoheader Macros::. |
| 9084 |
|
| 9085 |
|
| 9086 |
File: autoconf.info, Node: Changed Makefiles, Next: Changed Macros, Prev: Changed File Names, Up: Autoconf 1 |
| 9087 |
|
| 9088 |
15.5.2 Changed Makefiles |
| 9089 |
------------------------ |
| 9090 |
|
| 9091 |
Add ‘@CFLAGS@’, ‘@CPPFLAGS@’, and ‘@LDFLAGS@’ in your ‘Makefile.in’ |
| 9092 |
files, so they can take advantage of the values of those variables in |
| 9093 |
the environment when ‘configure’ is run. Doing this isn't necessary, |
| 9094 |
but it's a convenience for users. |
| 9095 |
|
| 9096 |
Also add ‘@configure_input@’ in a comment to each input file for |
| 9097 |
‘AC_OUTPUT’, so that the output files will contain a comment saying they |
| 9098 |
were produced by ‘configure’. Automatically selecting the right comment |
| 9099 |
syntax for all the kinds of files that people call ‘AC_OUTPUT’ on became |
| 9100 |
too much work. |
| 9101 |
|
| 9102 |
Add ‘config.log’ and ‘config.cache’ to the list of files you remove |
| 9103 |
in ‘distclean’ targets. |
| 9104 |
|
| 9105 |
If you have the following in ‘Makefile.in’: |
| 9106 |
|
| 9107 |
prefix = /usr/local |
| 9108 |
exec_prefix = $(prefix) |
| 9109 |
|
| 9110 |
you must change it to: |
| 9111 |
|
| 9112 |
prefix = @prefix@ |
| 9113 |
exec_prefix = @exec_prefix@ |
| 9114 |
|
| 9115 |
The old behavior of replacing those variables without ‘@’ characters |
| 9116 |
around them has been removed. |
| 9117 |
|
| 9118 |
|
| 9119 |
File: autoconf.info, Node: Changed Macros, Next: Changed Results, Prev: Changed Makefiles, Up: Autoconf 1 |
| 9120 |
|
| 9121 |
15.5.3 Changed Macros |
| 9122 |
--------------------- |
| 9123 |
|
| 9124 |
Many of the macros were renamed in Autoconf version 2. You can still |
| 9125 |
use the old names, but the new ones are clearer, and it's easier to find |
| 9126 |
the documentation for them. *Note Obsolete Macros::, for a table |
| 9127 |
showing the new names for the old macros. Use the ‘autoupdate’ program |
| 9128 |
to convert your ‘configure.ac’ to using the new macro names. *Note |
| 9129 |
autoupdate Invocation::. |
| 9130 |
|
| 9131 |
Some macros have been superseded by similar ones that do the job |
| 9132 |
better, but are not call-compatible. If you get warnings about calling |
| 9133 |
obsolete macros while running ‘autoconf’, you may safely ignore them, |
| 9134 |
but your ‘configure’ script will generally work better if you follow the |
| 9135 |
advice it prints about what to replace the obsolete macros with. In |
| 9136 |
particular, the mechanism for reporting the results of tests has |
| 9137 |
changed. If you were using ‘echo’ or ‘AC_VERBOSE’ (perhaps via |
| 9138 |
‘AC_COMPILE_CHECK’), your ‘configure’ script's output will look better |
| 9139 |
if you switch to ‘AC_MSG_CHECKING’ and ‘AC_MSG_RESULT’. *Note Printing |
| 9140 |
Messages::. Those macros work best in conjunction with cache variables. |
| 9141 |
*Note Caching Results::. |
| 9142 |
|
| 9143 |
|
| 9144 |
File: autoconf.info, Node: Changed Results, Next: Changed Macro Writing, Prev: Changed Macros, Up: Autoconf 1 |
| 9145 |
|
| 9146 |
15.5.4 Changed Results |
| 9147 |
---------------------- |
| 9148 |
|
| 9149 |
If you were checking the results of previous tests by examining the |
| 9150 |
shell variable ‘DEFS’, you need to switch to checking the values of the |
| 9151 |
cache variables for those tests. ‘DEFS’ no longer exists while |
| 9152 |
‘configure’ is running; it is only created when generating output files. |
| 9153 |
This difference from version 1 is because properly quoting the contents |
| 9154 |
of that variable turned out to be too cumbersome and inefficient to do |
| 9155 |
every time ‘AC_DEFINE’ is called. *Note Cache Variable Names::. |
| 9156 |
|
| 9157 |
For example, here is a ‘configure.ac’ fragment written for Autoconf |
| 9158 |
version 1: |
| 9159 |
|
| 9160 |
AC_HAVE_FUNCS(syslog) |
| 9161 |
case "$DEFS" in |
| 9162 |
*-DHAVE_SYSLOG*) ;; |
| 9163 |
*) # syslog is not in the default libraries. See if it's in some other. |
| 9164 |
saved_LIBS="$LIBS" |
| 9165 |
for lib in bsd socket inet; do |
| 9166 |
AC_CHECKING(for syslog in -l$lib) |
| 9167 |
LIBS="$saved_LIBS -l$lib" |
| 9168 |
AC_HAVE_FUNCS(syslog) |
| 9169 |
case "$DEFS" in |
| 9170 |
*-DHAVE_SYSLOG*) break ;; |
| 9171 |
*) ;; |
| 9172 |
esac |
| 9173 |
LIBS="$saved_LIBS" |
| 9174 |
done ;; |
| 9175 |
esac |
| 9176 |
|
| 9177 |
Here is a way to write it for version 2: |
| 9178 |
|
| 9179 |
AC_CHECK_FUNCS(syslog) |
| 9180 |
if test $ac_cv_func_syslog = no; then |
| 9181 |
# syslog is not in the default libraries. See if it's in some other. |
| 9182 |
for lib in bsd socket inet; do |
| 9183 |
AC_CHECK_LIB($lib, syslog, [AC_DEFINE(HAVE_SYSLOG) |
| 9184 |
LIBS="$LIBS -l$lib"; break]) |
| 9185 |
done |
| 9186 |
fi |
| 9187 |
|
| 9188 |
If you were working around bugs in ‘AC_DEFINE_UNQUOTED’ by adding |
| 9189 |
backslashes before quotes, you need to remove them. It now works |
| 9190 |
predictably, and does not treat quotes (except back quotes) specially. |
| 9191 |
*Note Setting Output Variables::. |
| 9192 |
|
| 9193 |
All of the boolean shell variables set by Autoconf macros now use |
| 9194 |
‘yes’ for the true value. Most of them use ‘no’ for false, though for |
| 9195 |
backward compatibility some use the empty string instead. If you were |
| 9196 |
relying on a shell variable being set to something like 1 or ‘t’ for |
| 9197 |
true, you need to change your tests. |
| 9198 |
|
| 9199 |
|
| 9200 |
File: autoconf.info, Node: Changed Macro Writing, Prev: Changed Results, Up: Autoconf 1 |
| 9201 |
|
| 9202 |
15.5.5 Changed Macro Writing |
| 9203 |
---------------------------- |
| 9204 |
|
| 9205 |
When defining your own macros, you should now use ‘AC_DEFUN’ instead of |
| 9206 |
‘define’. ‘AC_DEFUN’ automatically calls ‘AC_PROVIDE’ and ensures that |
| 9207 |
macros called via ‘AC_REQUIRE’ do not interrupt other macros, to prevent |
| 9208 |
nested ‘checking...’ messages on the screen. There's no actual harm in |
| 9209 |
continuing to use the older way, but it's less convenient and |
| 9210 |
attractive. *Note Macro Definitions::. |
| 9211 |
|
| 9212 |
You probably looked at the macros that came with Autoconf as a guide |
| 9213 |
for how to do things. It would be a good idea to take a look at the new |
| 9214 |
versions of them, as the style is somewhat improved and they take |
| 9215 |
advantage of some new features. |
| 9216 |
|
| 9217 |
If you were doing tricky things with undocumented Autoconf internals |
| 9218 |
(macros, variables, diversions), check whether you need to change |
| 9219 |
anything to account for changes that have been made. Perhaps you can |
| 9220 |
even use an officially supported technique in version 2 instead of |
| 9221 |
kludging. Or perhaps not. |
| 9222 |
|
| 9223 |
To speed up your locally written feature tests, add caching to them. |
| 9224 |
See whether any of your tests are of general enough usefulness to |
| 9225 |
encapsulate into macros that you can share. |
| 9226 |
|
| 9227 |
|
| 9228 |
File: autoconf.info, Node: Autoconf 2.13, Prev: Autoconf 1, Up: Obsolete Constructs |
| 9229 |
|
| 9230 |
15.6 Upgrading From Version 2.13 |
| 9231 |
================================ |
| 9232 |
|
| 9233 |
The introduction of the previous section (*note Autoconf 1::) perfectly |
| 9234 |
suits this section... |
| 9235 |
|
| 9236 |
Autoconf version 2.50 is mostly backward compatible with version |
| 9237 |
2.13. However, it introduces better ways to do some things, and |
| 9238 |
doesn't support some of the ugly things in version 2.13. So, |
| 9239 |
depending on how sophisticated your ‘configure.ac’ files are, you |
| 9240 |
might have to do some manual work in order to upgrade to version |
| 9241 |
2.50. This chapter points out some problems to watch for when |
| 9242 |
upgrading. Also, perhaps your ‘configure’ scripts could benefit |
| 9243 |
from some of the new features in version 2.50; the changes are |
| 9244 |
summarized in the file ‘NEWS’ in the Autoconf distribution. |
| 9245 |
|
| 9246 |
* Menu: |
| 9247 |
|
| 9248 |
* Changed Quotation:: Broken code which used to work |
| 9249 |
* New Macros:: Interaction with foreign macros |
| 9250 |
|
| 9251 |
|
| 9252 |
File: autoconf.info, Node: Changed Quotation, Next: New Macros, Prev: Autoconf 2.13, Up: Autoconf 2.13 |
| 9253 |
|
| 9254 |
15.6.1 Changed Quotation |
| 9255 |
------------------------ |
| 9256 |
|
| 9257 |
The most important changes are invisible to you: the implementation of |
| 9258 |
most macros have completely changed. This allowed more factorization of |
| 9259 |
the code, better error messages, a higher uniformity of the user's |
| 9260 |
interface etc. Unfortunately, as a side effect, some construct which |
| 9261 |
used to (miraculously) work might break starting with Autoconf 2.50. |
| 9262 |
The most common culprit is bad quotation. |
| 9263 |
|
| 9264 |
For instance, in the following example, the message is not properly |
| 9265 |
quoted: |
| 9266 |
|
| 9267 |
AC_INIT |
| 9268 |
AC_CHECK_HEADERS(foo.h,, |
| 9269 |
AC_MSG_ERROR(cannot find foo.h, bailing out)) |
| 9270 |
AC_OUTPUT |
| 9271 |
|
| 9272 |
Autoconf 2.13 simply ignores it: |
| 9273 |
|
| 9274 |
$ autoconf-2.13; ./configure --silent |
| 9275 |
creating cache ./config.cache |
| 9276 |
configure: error: cannot find foo.h |
| 9277 |
$ |
| 9278 |
|
| 9279 |
while Autoconf 2.50 will produce a broken ‘configure’: |
| 9280 |
|
| 9281 |
$ autoconf-2.50; ./configure --silent |
| 9282 |
configure: error: cannot find foo.h |
| 9283 |
./configure: exit: bad non-numeric arg `bailing' |
| 9284 |
./configure: exit: bad non-numeric arg `bailing' |
| 9285 |
$ |
| 9286 |
|
| 9287 |
The message needs to be quoted, and the ‘AC_MSG_ERROR’ invocation |
| 9288 |
too! |
| 9289 |
|
| 9290 |
AC_INIT |
| 9291 |
AC_CHECK_HEADERS(foo.h,, |
| 9292 |
[AC_MSG_ERROR([cannot find foo.h, bailing out])]) |
| 9293 |
AC_OUTPUT |
| 9294 |
|
| 9295 |
Many many (and many more) Autoconf macros were lacking proper |
| 9296 |
quotation, including no less than... ‘AC_DEFUN’ itself! |
| 9297 |
|
| 9298 |
$ cat configure.in |
| 9299 |
AC_DEFUN([AC_PROG_INSTALL], |
| 9300 |
[# My own much better version |
| 9301 |
]) |
| 9302 |
AC_INIT |
| 9303 |
AC_PROG_INSTALL |
| 9304 |
AC_OUTPUT |
| 9305 |
$ autoconf-2.13 |
| 9306 |
autoconf: Undefined macros: |
| 9307 |
***BUG in Autoconf--please report*** AC_FD_MSG |
| 9308 |
***BUG in Autoconf--please report*** AC_EPI |
| 9309 |
configure.in:1:AC_DEFUN([AC_PROG_INSTALL], |
| 9310 |
configure.in:5:AC_PROG_INSTALL |
| 9311 |
$ autoconf-2.50 |
| 9312 |
$ |
| 9313 |
|
| 9314 |
|
| 9315 |
File: autoconf.info, Node: New Macros, Prev: Changed Quotation, Up: Autoconf 2.13 |
| 9316 |
|
| 9317 |
15.6.2 New Macros |
| 9318 |
----------------- |
| 9319 |
|
| 9320 |
Because Autoconf has been dormant for years, Automake provided |
| 9321 |
Autoconf-like macros for a while. Autoconf 2.50 now provides better |
| 9322 |
versions of these macros, integrated in the ‘AC_’ namespace, instead of |
| 9323 |
‘AM_’. But in order to ease the upgrading via ‘autoupdate’, bindings to |
| 9324 |
such ‘AM_’ macros are provided. |
| 9325 |
|
| 9326 |
Unfortunately Automake did not quote the name of these macros! |
| 9327 |
Therefore, when ‘m4’ find in ‘aclocal.m4’ something like |
| 9328 |
‘AC_DEFUN(AM_TYPE_PTRDIFF_T, ...)’, ‘AM_TYPE_PTRDIFF_T’ is expanded, |
| 9329 |
replaced with its Autoconf definition. |
| 9330 |
|
| 9331 |
Fortunately Autoconf catches pre-‘AC_INIT’ expansions, and will |
| 9332 |
complain, in its own words: |
| 9333 |
|
| 9334 |
$ cat configure.in |
| 9335 |
AC_INIT |
| 9336 |
AM_TYPE_PTRDIFF_T |
| 9337 |
$ aclocal-1.4 |
| 9338 |
$ autoconf |
| 9339 |
./aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversion |
| 9340 |
actypes.m4:289: AM_TYPE_PTRDIFF_T is expanded from... |
| 9341 |
./aclocal.m4:17: the top level |
| 9342 |
$ |
| 9343 |
|
| 9344 |
Future versions of Automake will simply no longer define most of |
| 9345 |
these macros, and will properly quote the names of the remaining macros. |
| 9346 |
But you don't have to wait for it to happen to do the right thing right |
| 9347 |
now: do not depend upon macros from Automake as it is simply not its job |
| 9348 |
to provide macros (but the one it requires by itself): |
| 9349 |
|
| 9350 |
$ cat configure.in |
| 9351 |
AC_INIT |
| 9352 |
AM_TYPE_PTRDIFF_T |
| 9353 |
$ rm aclocal.m4 |
| 9354 |
$ autoupdate |
| 9355 |
autoupdate: `configure.in' is updated |
| 9356 |
$ cat configure.in |
| 9357 |
AC_INIT |
| 9358 |
AC_CHECK_TYPES([ptrdiff_t]) |
| 9359 |
$ aclocal-1.4 |
| 9360 |
$ autoconf |
| 9361 |
$ |
| 9362 |
|
| 9363 |
|
| 9364 |
File: autoconf.info, Node: Questions, Next: History, Prev: Obsolete Constructs, Up: Top |
| 9365 |
|
| 9366 |
16 Questions About Autoconf |
| 9367 |
*************************** |
| 9368 |
|
| 9369 |
Several questions about Autoconf come up occasionally. Here some of |
| 9370 |
them are addressed. |
| 9371 |
|
| 9372 |
* Menu: |
| 9373 |
|
| 9374 |
* Distributing:: Distributing ‘configure’ scripts |
| 9375 |
* Why GNU m4:: Why not use the standard M4? |
| 9376 |
* Bootstrapping:: Autoconf and GNU M4 require each other? |
| 9377 |
* Why Not Imake:: Why GNU uses ‘configure’ instead of Imake |
| 9378 |
|
| 9379 |
|
| 9380 |
File: autoconf.info, Node: Distributing, Next: Why GNU m4, Prev: Questions, Up: Questions |
| 9381 |
|
| 9382 |
16.1 Distributing ‘configure’ Scripts |
| 9383 |
===================================== |
| 9384 |
|
| 9385 |
What are the restrictions on distributing ‘configure’ |
| 9386 |
scripts that Autoconf generates? How does that affect my |
| 9387 |
programs that use them? |
| 9388 |
|
| 9389 |
There are no restrictions on how the configuration scripts that |
| 9390 |
Autoconf produces may be distributed or used. In Autoconf version 1, |
| 9391 |
they were covered by the GNU General Public License. We still encourage |
| 9392 |
software authors to distribute their work under terms like those of the |
| 9393 |
GPL, but doing so is not required to use Autoconf. |
| 9394 |
|
| 9395 |
Of the other files that might be used with ‘configure’, ‘config.h.in’ |
| 9396 |
is under whatever copyright you use for your ‘configure.ac’. |
| 9397 |
‘config.sub’ and ‘config.guess’ have an exception to the GPL when they |
| 9398 |
are used with an Autoconf-generated ‘configure’ script, which permits |
| 9399 |
you to distribute them under the same terms as the rest of your package. |
| 9400 |
‘install-sh’ is from the X Consortium and is not copyrighted. |
| 9401 |
|
| 9402 |
|
| 9403 |
File: autoconf.info, Node: Why GNU m4, Next: Bootstrapping, Prev: Distributing, Up: Questions |
| 9404 |
|
| 9405 |
16.2 Why Require GNU M4? |
| 9406 |
======================== |
| 9407 |
|
| 9408 |
Why does Autoconf require GNU M4? |
| 9409 |
|
| 9410 |
Many M4 implementations have hard-coded limitations on the size and |
| 9411 |
number of macros that Autoconf exceeds. They also lack several builtin |
| 9412 |
macros that it would be difficult to get along without in a |
| 9413 |
sophisticated application like Autoconf, including: |
| 9414 |
|
| 9415 |
builtin |
| 9416 |
indir |
| 9417 |
patsubst |
| 9418 |
__file__ |
| 9419 |
__line__ |
| 9420 |
|
| 9421 |
Autoconf requires version 1.4 or above of GNU M4 because it uses |
| 9422 |
frozen state files. |
| 9423 |
|
| 9424 |
Since only software maintainers need to use Autoconf, and since GNU |
| 9425 |
M4 is simple to configure and install, it seems reasonable to require |
| 9426 |
GNU M4 to be installed also. Many maintainers of GNU and other free |
| 9427 |
software already have most of the GNU utilities installed, since they |
| 9428 |
prefer them. |
| 9429 |
|
| 9430 |
|
| 9431 |
File: autoconf.info, Node: Bootstrapping, Next: Why Not Imake, Prev: Why GNU m4, Up: Questions |
| 9432 |
|
| 9433 |
16.3 How Can I Bootstrap? |
| 9434 |
========================= |
| 9435 |
|
| 9436 |
If Autoconf requires GNU M4 and GNU M4 has an Autoconf |
| 9437 |
‘configure’ script, how do I bootstrap? It seems like a chicken |
| 9438 |
and egg problem! |
| 9439 |
|
| 9440 |
This is a misunderstanding. Although GNU M4 does come with a |
| 9441 |
‘configure’ script produced by Autoconf, Autoconf is not required in |
| 9442 |
order to run the script and install GNU M4. Autoconf is only required |
| 9443 |
if you want to change the M4 ‘configure’ script, which few people have |
| 9444 |
to do (mainly its maintainer). |
| 9445 |
|
| 9446 |
|
| 9447 |
File: autoconf.info, Node: Why Not Imake, Prev: Bootstrapping, Up: Questions |
| 9448 |
|
| 9449 |
16.4 Why Not Imake? |
| 9450 |
=================== |
| 9451 |
|
| 9452 |
Why not use Imake instead of ‘configure’ scripts? |
| 9453 |
|
| 9454 |
Several people have written addressing this question, so I include |
| 9455 |
adaptations of their explanations here. |
| 9456 |
|
| 9457 |
The following answer is based on one written by Richard Pixley: |
| 9458 |
|
| 9459 |
Autoconf generated scripts frequently work on machines that it has |
| 9460 |
never been set up to handle before. That is, it does a good job of |
| 9461 |
inferring a configuration for a new system. Imake cannot do this. |
| 9462 |
|
| 9463 |
Imake uses a common database of host specific data. For X11, this |
| 9464 |
makes sense because the distribution is made as a collection of |
| 9465 |
tools, by one central authority who has control over the database. |
| 9466 |
|
| 9467 |
GNU tools are not released this way. Each GNU tool has a |
| 9468 |
maintainer; these maintainers are scattered across the world. |
| 9469 |
Using a common database would be a maintenance nightmare. Autoconf |
| 9470 |
may appear to be this kind of database, but in fact it is not. |
| 9471 |
Instead of listing host dependencies, it lists program |
| 9472 |
requirements. |
| 9473 |
|
| 9474 |
If you view the GNU suite as a collection of native tools, then the |
| 9475 |
problems are similar. But the GNU development tools can be |
| 9476 |
configured as cross tools in almost any host+target permutation. |
| 9477 |
All of these configurations can be installed concurrently. They |
| 9478 |
can even be configured to share host independent files across |
| 9479 |
hosts. Imake doesn't address these issues. |
| 9480 |
|
| 9481 |
Imake templates are a form of standardization. The GNU coding |
| 9482 |
standards address the same issues without necessarily imposing the |
| 9483 |
same restrictions. |
| 9484 |
|
| 9485 |
Here is some further explanation, written by Per Bothner: |
| 9486 |
|
| 9487 |
One of the advantages of Imake is that it easy to generate large |
| 9488 |
Makefiles using ‘cpp’'s ‘#include’ and macro mechanisms. However, |
| 9489 |
‘cpp’ is not programmable: it has limited conditional facilities, |
| 9490 |
and no looping. And ‘cpp’ cannot inspect its environment. |
| 9491 |
|
| 9492 |
All of these problems are solved by using ‘sh’ instead of ‘cpp’. |
| 9493 |
The shell is fully programmable, has macro substitution, can |
| 9494 |
execute (or source) other shell scripts, and can inspect its |
| 9495 |
environment. |
| 9496 |
|
| 9497 |
Paul Eggert elaborates more: |
| 9498 |
|
| 9499 |
With Autoconf, installers need not assume that Imake itself is |
| 9500 |
already installed and working well. This may not seem like much of |
| 9501 |
an advantage to people who are accustomed to Imake. But on many |
| 9502 |
hosts Imake is not installed or the default installation is not |
| 9503 |
working well, and requiring Imake to install a package hinders the |
| 9504 |
acceptance of that package on those hosts. For example, the Imake |
| 9505 |
template and configuration files might not be installed properly on |
| 9506 |
a host, or the Imake build procedure might wrongly assume that all |
| 9507 |
source files are in one big directory tree, or the Imake |
| 9508 |
configuration might assume one compiler whereas the package or the |
| 9509 |
installer needs to use another, or there might be a version |
| 9510 |
mismatch between the Imake expected by the package and the Imake |
| 9511 |
supported by the host. These problems are much rarer with |
| 9512 |
Autoconf, where each package comes with its own independent |
| 9513 |
configuration processor. |
| 9514 |
|
| 9515 |
Also, Imake often suffers from unexpected interactions between |
| 9516 |
‘make’ and the installer's C preprocessor. The fundamental problem |
| 9517 |
here is that the C preprocessor was designed to preprocess C |
| 9518 |
programs, not ‘Makefile’s. This is much less of a problem with |
| 9519 |
Autoconf, which uses the general-purpose preprocessor ‘m4’, and |
| 9520 |
where the package's author (rather than the installer) does the |
| 9521 |
preprocessing in a standard way. |
| 9522 |
|
| 9523 |
Finally, Mark Eichin notes: |
| 9524 |
|
| 9525 |
Imake isn't all that extensible, either. In order to add new |
| 9526 |
features to Imake, you need to provide your own project template, |
| 9527 |
and duplicate most of the features of the existing one. This means |
| 9528 |
that for a sophisticated project, using the vendor-provided Imake |
| 9529 |
templates fails to provide any leverage--since they don't cover |
| 9530 |
anything that your own project needs (unless it is an X11 program). |
| 9531 |
|
| 9532 |
On the other side, though: |
| 9533 |
|
| 9534 |
The one advantage that Imake has over ‘configure’: ‘Imakefile’s |
| 9535 |
tend to be much shorter (likewise, less redundant) than |
| 9536 |
‘Makefile.in’s. There is a fix to this, however--at least for the |
| 9537 |
Kerberos V5 tree, we've modified things to call in common ‘post.in’ |
| 9538 |
and ‘pre.in’ ‘Makefile’ fragments for the entire tree. This means |
| 9539 |
that a lot of common things don't have to be duplicated, even |
| 9540 |
though they normally are in ‘configure’ setups. |
| 9541 |
|
| 9542 |
|
| 9543 |
File: autoconf.info, Node: History, Next: Environment Variable Index, Prev: Questions, Up: Top |
| 9544 |
|
| 9545 |
17 History of Autoconf |
| 9546 |
********************** |
| 9547 |
|
| 9548 |
You may be wondering, Why was Autoconf originally written? How did it |
| 9549 |
get into its present form? (Why does it look like gorilla spit?) If |
| 9550 |
you're not wondering, then this chapter contains no information useful |
| 9551 |
to you, and you might as well skip it. If you _are_ wondering, then let |
| 9552 |
there be light... |
| 9553 |
|
| 9554 |
* Menu: |
| 9555 |
|
| 9556 |
* Genesis:: Prehistory and naming of ‘configure’ |
| 9557 |
* Exodus:: The plagues of M4 and Perl |
| 9558 |
* Leviticus:: The priestly code of portability arrives |
| 9559 |
* Numbers:: Growth and contributors |
| 9560 |
* Deuteronomy:: Approaching the promises of easy configuration |
| 9561 |
|
| 9562 |
|
| 9563 |
File: autoconf.info, Node: Genesis, Next: Exodus, Prev: History, Up: History |
| 9564 |
|
| 9565 |
17.1 Genesis |
| 9566 |
============ |
| 9567 |
|
| 9568 |
In June 1991 I was maintaining many of the GNU utilities for the Free |
| 9569 |
Software Foundation. As they were ported to more platforms and more |
| 9570 |
programs were added, the number of ‘-D’ options that users had to select |
| 9571 |
in the ‘Makefile’ (around 20) became burdensome. Especially for me--I |
| 9572 |
had to test each new release on a bunch of different systems. So I |
| 9573 |
wrote a little shell script to guess some of the correct settings for |
| 9574 |
the fileutils package, and released it as part of fileutils 2.0. That |
| 9575 |
‘configure’ script worked well enough that the next month I adapted it |
| 9576 |
(by hand) to create similar ‘configure’ scripts for several other GNU |
| 9577 |
utilities packages. Brian Berliner also adapted one of my scripts for |
| 9578 |
his CVS revision control system. |
| 9579 |
|
| 9580 |
Later that summer, I learned that Richard Stallman and Richard Pixley |
| 9581 |
were developing similar scripts to use in the GNU compiler tools; so I |
| 9582 |
adapted my ‘configure’ scripts to support their evolving interface: |
| 9583 |
using the file name ‘Makefile.in’ as the templates; adding ‘+srcdir’, |
| 9584 |
the first option (of many); and creating ‘config.status’ files. |
| 9585 |
|
| 9586 |
|
| 9587 |
File: autoconf.info, Node: Exodus, Next: Leviticus, Prev: Genesis, Up: History |
| 9588 |
|
| 9589 |
17.2 Exodus |
| 9590 |
=========== |
| 9591 |
|
| 9592 |
As I got feedback from users, I incorporated many improvements, using |
| 9593 |
Emacs to search and replace, cut and paste, similar changes in each of |
| 9594 |
the scripts. As I adapted more GNU utilities packages to use |
| 9595 |
‘configure’ scripts, updating them all by hand became impractical. Rich |
| 9596 |
Murphey, the maintainer of the GNU graphics utilities, sent me mail |
| 9597 |
saying that the ‘configure’ scripts were great, and asking if I had a |
| 9598 |
tool for generating them that I could send him. No, I thought, but I |
| 9599 |
should! So I started to work out how to generate them. And the journey |
| 9600 |
from the slavery of hand-written ‘configure’ scripts to the abundance |
| 9601 |
and ease of Autoconf began. |
| 9602 |
|
| 9603 |
Cygnus ‘configure’, which was being developed at around that time, is |
| 9604 |
table driven; it is meant to deal mainly with a discrete number of |
| 9605 |
system types with a small number of mainly unguessable features (such as |
| 9606 |
details of the object file format). The automatic configuration system |
| 9607 |
that Brian Fox had developed for Bash takes a similar approach. For |
| 9608 |
general use, it seems to me a hopeless cause to try to maintain an |
| 9609 |
up-to-date database of which features each variant of each operating |
| 9610 |
system has. It's easier and more reliable to check for most features on |
| 9611 |
the fly--especially on hybrid systems that people have hacked on locally |
| 9612 |
or that have patches from vendors installed. |
| 9613 |
|
| 9614 |
I considered using an architecture similar to that of Cygnus |
| 9615 |
‘configure’, where there is a single ‘configure’ script that reads |
| 9616 |
pieces of ‘configure.in’ when run. But I didn't want to have to |
| 9617 |
distribute all of the feature tests with every package, so I settled on |
| 9618 |
having a different ‘configure’ made from each ‘configure.in’ by a |
| 9619 |
preprocessor. That approach also offered more control and flexibility. |
| 9620 |
|
| 9621 |
I looked briefly into using the Metaconfig package, by Larry Wall, |
| 9622 |
Harlan Stenn, and Raphael Manfredi, but I decided not to for several |
| 9623 |
reasons. The ‘Configure’ scripts it produces are interactive, which I |
| 9624 |
find quite inconvenient; I didn't like the ways it checked for some |
| 9625 |
features (such as library functions); I didn't know that it was still |
| 9626 |
being maintained, and the ‘Configure’ scripts I had seen didn't work on |
| 9627 |
many modern systems (such as System V R4 and NeXT); it wasn't very |
| 9628 |
flexible in what it could do in response to a feature's presence or |
| 9629 |
absence; I found it confusing to learn; and it was too big and complex |
| 9630 |
for my needs (I didn't realize then how much Autoconf would eventually |
| 9631 |
have to grow). |
| 9632 |
|
| 9633 |
I considered using Perl to generate my style of ‘configure’ scripts, |
| 9634 |
but decided that M4 was better suited to the job of simple textual |
| 9635 |
substitutions: it gets in the way less, because output is implicit. |
| 9636 |
Plus, everyone already has it. (Initially I didn't rely on the GNU |
| 9637 |
extensions to M4.) Also, some of my friends at the University of |
| 9638 |
Maryland had recently been putting M4 front ends on several programs, |
| 9639 |
including ‘tvtwm’, and I was interested in trying out a new language. |
| 9640 |
|
| 9641 |
|
| 9642 |
File: autoconf.info, Node: Leviticus, Next: Numbers, Prev: Exodus, Up: History |
| 9643 |
|
| 9644 |
17.3 Leviticus |
| 9645 |
============== |
| 9646 |
|
| 9647 |
Since my ‘configure’ scripts determine the system's capabilities |
| 9648 |
automatically, with no interactive user intervention, I decided to call |
| 9649 |
the program that generates them Autoconfig. But with a version number |
| 9650 |
tacked on, that name would be too long for old UNIX file systems, so I |
| 9651 |
shortened it to Autoconf. |
| 9652 |
|
| 9653 |
In the fall of 1991 I called together a group of fellow questers |
| 9654 |
after the Holy Grail of portability (er, that is, alpha testers) to give |
| 9655 |
me feedback as I encapsulated pieces of my handwritten scripts in M4 |
| 9656 |
macros and continued to add features and improve the techniques used in |
| 9657 |
the checks. Prominent among the testers were François Pinard, who came |
| 9658 |
up with the idea of making an ‘autoconf’ shell script to run ‘m4’ and |
| 9659 |
check for unresolved macro calls; Richard Pixley, who suggested running |
| 9660 |
the compiler instead of searching the file system to find include files |
| 9661 |
and symbols, for more accurate results; Karl Berry, who got Autoconf to |
| 9662 |
configure TeX and added the macro index to the documentation; and Ian |
| 9663 |
Lance Taylor, who added support for creating a C header file as an |
| 9664 |
alternative to putting ‘-D’ options in a ‘Makefile’, so he could use |
| 9665 |
Autoconf for his UUCP package. The alpha testers cheerfully adjusted |
| 9666 |
their files again and again as the names and calling conventions of the |
| 9667 |
Autoconf macros changed from release to release. They all contributed |
| 9668 |
many specific checks, great ideas, and bug fixes. |
| 9669 |
|
| 9670 |
|
| 9671 |
File: autoconf.info, Node: Numbers, Next: Deuteronomy, Prev: Leviticus, Up: History |
| 9672 |
|
| 9673 |
17.4 Numbers |
| 9674 |
============ |
| 9675 |
|
| 9676 |
In July 1992, after months of alpha testing, I released Autoconf 1.0, |
| 9677 |
and converted many GNU packages to use it. I was surprised by how |
| 9678 |
positive the reaction to it was. More people started using it than I |
| 9679 |
could keep track of, including people working on software that wasn't |
| 9680 |
part of the GNU Project (such as TCL, FSP, and Kerberos V5). Autoconf |
| 9681 |
continued to improve rapidly, as many people using the ‘configure’ |
| 9682 |
scripts reported problems they encountered. |
| 9683 |
|
| 9684 |
Autoconf turned out to be a good torture test for M4 implementations. |
| 9685 |
UNIX ‘m4’ started to dump core because of the length of the macros that |
| 9686 |
Autoconf defined, and several bugs showed up in GNU ‘m4’ as well. |
| 9687 |
Eventually, we realized that we needed to use some features that only |
| 9688 |
GNU M4 has. 4.3BSD ‘m4’, in particular, has an impoverished set of |
| 9689 |
builtin macros; the System V version is better, but still doesn't |
| 9690 |
provide everything we need. |
| 9691 |
|
| 9692 |
More development occurred as people put Autoconf under more stresses |
| 9693 |
(and to uses I hadn't anticipated). Karl Berry added checks for X11. |
| 9694 |
david zuhn contributed C++ support. François Pinard made it diagnose |
| 9695 |
invalid arguments. Jim Blandy bravely coerced it into configuring GNU |
| 9696 |
Emacs, laying the groundwork for several later improvements. Roland |
| 9697 |
McGrath got it to configure the GNU C Library, wrote the ‘autoheader’ |
| 9698 |
script to automate the creation of C header file templates, and added a |
| 9699 |
‘--verbose’ option to ‘configure’. Noah Friedman added the |
| 9700 |
‘--autoconf-dir’ option and ‘AC_MACRODIR’ environment variable. (He |
| 9701 |
also coined the term “autoconfiscate” to mean "adapt a software package |
| 9702 |
to use Autoconf".) Roland and Noah improved the quoting protection in |
| 9703 |
‘AC_DEFINE’ and fixed many bugs, especially when I got sick of dealing |
| 9704 |
with portability problems from February through June, 1993. |
| 9705 |
|
| 9706 |
|
| 9707 |
File: autoconf.info, Node: Deuteronomy, Prev: Numbers, Up: History |
| 9708 |
|
| 9709 |
17.5 Deuteronomy |
| 9710 |
================ |
| 9711 |
|
| 9712 |
A long wish list for major features had accumulated, and the effect of |
| 9713 |
several years of patching by various people had left some residual |
| 9714 |
cruft. In April 1994, while working for Cygnus Support, I began a major |
| 9715 |
revision of Autoconf. I added most of the features of the Cygnus |
| 9716 |
‘configure’ that Autoconf had lacked, largely by adapting the relevant |
| 9717 |
parts of Cygnus ‘configure’ with the help of david zuhn and Ken Raeburn. |
| 9718 |
These features include support for using ‘config.sub’, ‘config.guess’, |
| 9719 |
‘--host’, and ‘--target’; making links to files; and running ‘configure’ |
| 9720 |
scripts in subdirectories. Adding these features enabled Ken to convert |
| 9721 |
GNU ‘as’, and Rob Savoye to convert DejaGNU, to using Autoconf. |
| 9722 |
|
| 9723 |
I added more features in response to other peoples' requests. Many |
| 9724 |
people had asked for ‘configure’ scripts to share the results of the |
| 9725 |
checks between runs, because (particularly when configuring a large |
| 9726 |
source tree, like Cygnus does) they were frustratingly slow. Mike |
| 9727 |
Haertel suggested adding site-specific initialization scripts. People |
| 9728 |
distributing software that had to unpack on MS-DOS asked for a way to |
| 9729 |
override the ‘.in’ extension on the file names, which produced file |
| 9730 |
names like ‘config.h.in’ containing two dots. Jim Avera did an |
| 9731 |
extensive examination of the problems with quoting in ‘AC_DEFINE’ and |
| 9732 |
‘AC_SUBST’; his insights led to significant improvements. Richard |
| 9733 |
Stallman asked that compiler output be sent to ‘config.log’ instead of |
| 9734 |
‘/dev/null’, to help people debug the Emacs ‘configure’ script. |
| 9735 |
|
| 9736 |
I made some other changes because of my dissatisfaction with the |
| 9737 |
quality of the program. I made the messages showing results of the |
| 9738 |
checks less ambiguous, always printing a result. I regularized the |
| 9739 |
names of the macros and cleaned up coding style inconsistencies. I |
| 9740 |
added some auxiliary utilities that I had developed to help convert |
| 9741 |
source code packages to use Autoconf. With the help of François Pinard, |
| 9742 |
I made the macros not interrupt each others' messages. (That feature |
| 9743 |
revealed some performance bottlenecks in GNU ‘m4’, which he hastily |
| 9744 |
corrected!) I reorganized the documentation around problems people want |
| 9745 |
to solve. And I began a test suite, because experience had shown that |
| 9746 |
Autoconf has a pronounced tendency to regress when we change it. |
| 9747 |
|
| 9748 |
Again, several alpha testers gave invaluable feedback, especially |
| 9749 |
François Pinard, Jim Meyering, Karl Berry, Rob Savoye, Ken Raeburn, and |
| 9750 |
Mark Eichin. |
| 9751 |
|
| 9752 |
Finally, version 2.0 was ready. And there was much rejoicing. (And |
| 9753 |
I have free time again. I think. Yeah, right.) |
| 9754 |
|
| 9755 |
|
| 9756 |
File: autoconf.info, Node: Environment Variable Index, Next: Output Variable Index, Prev: History, Up: Top |
| 9757 |
|
| 9758 |
Environment Variable Index |
| 9759 |
************************** |
| 9760 |
|
| 9761 |
This is an alphabetical list of the environment variables that Autoconf |
| 9762 |
checks. |
| 9763 |
|
| 9764 |
|