This manual is for GNU Autoconf (version 2.59, 11 July 2004), a package for creating scripts to configure source code packages using templates and an M4 macro package.
Copyright © 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.”(a) The FSF's Back-Cover Text is: “You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.”
nature of God. “Surely a Physicist,” said the physicist, “because
early in the Creation, God made Light; and you know, Maxwell's
equations, the dual nature of electromagnetic waves, the relativistic
consequences...” “An Engineer!,” said the engineer, “because
before making Light, God split the Chaos into Land and Water; it takes a
hell of an engineer to handle that big amount of mud, and orderly
separation of solids from liquids...” The computer scientist
shouted: “And the Chaos, where do you think it was coming from, hmm?”
—Anonymous
Autoconf is a tool for producing shell scripts that automatically configure software source code packages to adapt to many kinds of unix-like systems. The configuration scripts produced by Autoconf are independent of Autoconf when they are run, so their users do not need to have Autoconf.
The configuration scripts produced by Autoconf require no manual user intervention when run; they do not normally even need an argument specifying the system type. Instead, they individually test for the presence of each feature that the software package they are for might need. (Before each check, they print a one-line message stating what they are checking for, so the user doesn't get too bored while waiting for the script to finish.) As a result, they deal well with systems that are hybrids or customized from the more common unix variants. There is no need to maintain files that list the features supported by each release of each variant of unix.
For each software package that Autoconf is used with, it creates a configuration script from a template file that lists the system features that the package needs or can use. After the shell code to recognize and respond to a system feature has been written, Autoconf allows it to be shared by many software packages that can use (or need) that feature. If it later turns out that the shell code needs adjustment for some reason, it needs to be changed in only one place; all of the configuration scripts can be regenerated automatically to take advantage of the updated code.
The Metaconfig package is similar in purpose to Autoconf, but the scripts it produces require manual user intervention, which is quite inconvenient when configuring large source trees. Unlike Metaconfig scripts, Autoconf scripts can support cross-compiling, if some care is taken in writing them.
Autoconf does not solve all problems related to making portable software packages—for a more complete solution, it should be used in concert with other GNU build tools like Automake and Libtool. These other tools take on jobs like the creation of a portable, recursive Makefile with all of the standard targets, linking of shared libraries, and so on. See The GNU Build System, for more information.
Autoconf imposes some restrictions on the names of macros used with
#if in C programs (see Preprocessor Symbol Index).
Autoconf requires GNU M4 in order to generate the scripts. It uses features that some unix versions of M4, including GNU M4 1.3, do not have. You must use version 1.4 or later of GNU M4.
See Autoconf 1, for information about upgrading from version 1. See History, for the story of Autoconf's development. See FAQ, for answers to some common questions about Autoconf.
See the Autoconf web page for up-to-date information, details on the mailing lists, pointers to a list of known bugs, etc.
Mail suggestions to the Autoconf mailing list.
Bug reports should be preferably submitted to the Autoconf Gnats database, or sent to the Autoconf Bugs mailing list. If possible, first check that your bug is not already solved in current development versions, and that it has not been reported yet. Be sure to include all the needed information and a short configure.ac that demonstrates the problem.
Autoconf's development tree is accessible via CVS; see the Autoconf web page for details. There is also a CVSweb interface to the Autoconf development tree. Patches relative to the current CVS version can be sent for review to the Autoconf Patches mailing list.
Because of its mission, Autoconf includes only a set of often-used macros that have already demonstrated their usefulness. Nevertheless, if you wish to share your macros, or find existing ones, see the Autoconf Macro Archive, which is kindly run by Peter Simons.
Autoconf solves an important problem—reliable discovery of system-specific build and run-time information—but this is only one piece of the puzzle for the development of portable software. To this end, the GNU project has developed a suite of integrated utilities to finish the job Autoconf started: the GNU build system, whose most important components are Autoconf, Automake, and Libtool. In this chapter, we introduce you to those tools, point you to sources of more information, and try to convince you to use the entire GNU build system for your software.
The ubiquity of make means that a Makefile is almost the
only viable way to distribute automatic build rules for software, but
one quickly runs into make's numerous limitations. Its lack of
support for automatic dependency tracking, recursive builds in
subdirectories, reliable timestamps (e.g., for network filesystems), and
so on, mean that developers must painfully (and often incorrectly)
reinvent the wheel for each project. Portability is non-trivial, thanks
to the quirks of make on many systems. On top of all this is the
manual labor required to implement the many standard targets that users
have come to expect (make install, make distclean,
make uninstall, etc.). Since you are, of course, using Autoconf,
you also have to insert repetitive code in your Makefile.in to
recognize @CC@, @CFLAGS@, and other substitutions
provided by configure. Into this mess steps Automake.
Automake allows you to specify your build needs in a Makefile.am
file with a vastly simpler and more powerful syntax than that of a plain
Makefile, and then generates a portable Makefile.in for
use with Autoconf. For example, the Makefile.am to build and
install a simple “Hello world” program might look like:
bin_PROGRAMS = hello
hello_SOURCES = hello.c
The resulting Makefile.in (~400 lines) automatically supports all
the standard targets, the substitutions provided by Autoconf, automatic
dependency tracking, VPATH building, and so on. make will
build the hello program, and make install will install it
in /usr/local/bin (or whatever prefix was given to
configure, if not /usr/local).
The benefits of Automake increase for larger packages (especially ones with subdirectories), but even for small programs the added convenience and portability can be substantial. And that's not all....
Very often, one wants to build not only programs, but libraries, so that
other programs can benefit from the fruits of your labor. Ideally, one
would like to produce shared (dynamically linked) libraries,
which can be used by multiple programs without duplication on disk or in
memory and can be updated independently of the linked programs.
Producing shared libraries portably, however, is the stuff of
nightmares—each system has its own incompatible tools, compiler flags,
and magic incantations. Fortunately, GNU provides a solution:
Libtool.
Libtool handles all the requirements of building shared libraries for
you, and at this time seems to be the only way to do so with any
portability. It also handles many other headaches, such as: the
interaction of Makefile rules with the variable suffixes of
shared libraries, linking reliably with shared libraries before they are
installed by the superuser, and supplying a consistent versioning system
(so that different versions of a library can be installed or upgraded
without breaking binary compatibility). Although Libtool, like
Autoconf, can be used on its own, it is most simply utilized in
conjunction with Automake—there, Libtool is used automatically
whenever shared libraries are needed, and you need not know its syntax.
Developers who are used to the simplicity of make for small projects on a single system might be daunted at the prospect of learning to use Automake and Autoconf. As your software is distributed to more and more users, however, you will otherwise quickly find yourself putting lots of effort into reinventing the services that the GNU build tools provide, and making the same mistakes that they once made and overcame. (Besides, since you're already learning Autoconf, Automake will be a piece of cake.)
There are a number of places that you can go to for more information on the GNU build tools.
See Automake (GNU Automake), for more information on Automake.
The book GNU Autoconf, Automake and Libtool1 describes the complete GNU build environment. You can also find the entire book on-line at “The Goat Book” home page.
The Autoconf Developer Page maintains links to a number of Autoconf/Automake tutorials online, and also links to the Autoconf Macro Archive.
The configuration scripts that Autoconf produces are by convention called configure. When run, configure creates several files, replacing configuration parameters in them with appropriate values. The files that configure creates are:
#define directives (see Configuration Headers);
To create a configure script with Autoconf, you need to write an
Autoconf input file configure.ac (or configure.in) and run
autoconf on it. If you write your own feature tests to
supplement those that come with Autoconf, you might also write files
called aclocal.m4 and acsite.m4. If you use a C header
file to contain #define directives, you might also run
autoheader, and you will distribute the generated file
config.h.in with the package.
Here is a diagram showing how the files that can be used in configuration are produced. Programs that are executed are suffixed by *. Optional files are enclosed in square brackets ([]). autoconf and autoheader also read the installed Autoconf macro files (by reading autoconf.m4).
Files used in preparing a software package for distribution:
your source files --> [autoscan*] --> [configure.scan] --> configure.ac
configure.ac --.
| .------> autoconf* -----> configure
[aclocal.m4] --+---+
| `-----> [autoheader*] --> [config.h.in]
[acsite.m4] ---'
Makefile.in -------------------------------> Makefile.in
Files used in configuring a software package:
.-------------> [config.cache]
configure* ------------+-------------> config.log
|
[config.h.in] -. v .-> [config.h] -.
+--> config.status* -+ +--> make*
Makefile.in ---' `-> Makefile ---'
To produce a configure script for a software package, create a file called configure.ac that contains invocations of the Autoconf macros that test the system features your package needs or can use. Autoconf macros already exist to check for many features; see Existing Tests, for their descriptions. For most other features, you can use Autoconf template macros to produce custom checks; see Writing Tests, for information about them. For especially tricky or specialized features, configure.ac might need to contain some hand-crafted shell commands; see Portable Shell. The autoscan program can give you a good start in writing configure.ac (see autoscan Invocation, for more information).
Previous versions of Autoconf promoted the name configure.in, which is somewhat ambiguous (the tool needed to process this file is not described by its extension), and introduces a slight confusion with config.h.in and so on (for which .in means “to be processed by configure”). Using configure.ac is now preferred.
Just as for any other computer language, in order to properly program configure.ac in Autoconf you must understand what problem the language tries to address and how it does so.
The problem Autoconf addresses is that the world is a mess. After all, you are using Autoconf in order to have your package compile easily on all sorts of different systems, some of them being extremely hostile. Autoconf itself bears the price for these differences: configure must run on all those systems, and thus configure must limit itself to their lowest common denominator of features.
Naturally, you might then think of shell scripts; who needs autoconf? A set of properly written shell functions is enough to make it easy to write configure scripts by hand. Sigh! Unfortunately, shell functions do not belong to the least common denominator; therefore, where you would like to define a function and use it ten times, you would instead need to copy its body ten times.
So, what is really needed is some kind of compiler, autoconf, that takes an Autoconf program, configure.ac, and transforms it into a portable shell script, configure.
How does autoconf perform this task?
There are two obvious possibilities: creating a brand new language or
extending an existing one. The former option is very attractive: all
sorts of optimizations could easily be implemented in the compiler and
many rigorous checks could be performed on the Autoconf program
(e.g., rejecting any non-portable construct). Alternatively, you can
extend an existing language, such as the sh (Bourne shell)
language.
Autoconf does the latter: it is a layer on top of sh. It was
therefore most convenient to implement autoconf as a macro
expander: a program that repeatedly performs macro expansions on
text input, replacing macro calls with macro bodies and producing a pure
sh script in the end. Instead of implementing a dedicated
Autoconf macro expander, it is natural to use an existing
general-purpose macro language, such as M4, and implement the extensions
as a set of M4 macros.
The Autoconf language is very different from many other computer languages because it treats actual code the same as plain text. Whereas in C, for instance, data and instructions have very different syntactic status, in Autoconf their status is rigorously the same. Therefore, we need a means to distinguish literal strings from text to be expanded: quotation.
When calling macros that take arguments, there must not be any blank space between the macro name and the open parenthesis. Arguments should be enclosed within the M4 quote characters [ and ], and be separated by commas. Any leading spaces in arguments are ignored, unless they are quoted. You may safely leave out the quotes when the argument is simple text, but always quote complex arguments such as other macro calls. This rule applies recursively for every macro call, including macros called from other macros.
For instance:
AC_CHECK_HEADER([stdio.h],
[AC_DEFINE([HAVE_STDIO_H])],
[AC_MSG_ERROR([Sorry, can't do anything for you])])
is quoted properly. You may safely simplify its quotation to:
AC_CHECK_HEADER(stdio.h,
[AC_DEFINE(HAVE_STDIO_H)],
[AC_MSG_ERROR([Sorry, can't do anything for you])])
Notice that the argument of AC_MSG_ERROR is still quoted;
otherwise, its comma would have been interpreted as an argument separator.
The following example is wrong and dangerous, as it is underquoted:
AC_CHECK_HEADER(stdio.h,
AC_DEFINE(HAVE_STDIO_H),
AC_MSG_ERROR([Sorry, can't do anything for you]))
In other cases, you may have to use text that also resembles a macro call. You must quote that text even when it is not passed as a macro argument:
echo "Hard rock was here! --[AC_DC]"
which will result in
echo "Hard rock was here! --AC_DC"
When you use the same text in a macro argument, you must therefore have an extra quotation level (since one is stripped away by the macro substitution). In general, then, it is a good idea to use double quoting for all literal string arguments:
AC_MSG_WARN([[AC_DC stinks --Iron Maiden]])
You are now able to understand one of the constructs of Autoconf that has been continually misunderstood... The rule of thumb is that whenever you expect macro expansion, expect quote expansion; i.e., expect one level of quotes to be lost. For instance:
AC_COMPILE_IFELSE([char b[10];],, [AC_MSG_ERROR([you lose])])
is incorrect: here, the first argument of AC_COMPILE_IFELSE is
char b[10]; and will be expanded once, which results in
char b10;. (There was an idiom common in Autoconf's past to
address this issue via the M4 changequote primitive, but do not
use it!) Let's take a closer look: the author meant the first argument
to be understood as a literal, and therefore it must be quoted twice:
AC_COMPILE_IFELSE([[char b[10];]],, [AC_MSG_ERROR([you lose])])
Voilà, you actually produce char b[10]; this time!
The careful reader will notice that, according to these guidelines, the
“properly” quoted AC_CHECK_HEADER example above is actually
lacking three pairs of quotes! Nevertheless, for the sake of readability,
double quotation of literals is used only where needed in this manual.
Some macros take optional arguments, which this documentation represents as [arg] (not to be confused with the quote characters). You may just leave them empty, or use [] to make the emptiness of the argument explicit, or you may simply omit the trailing commas. The three lines below are equivalent:
AC_CHECK_HEADERS(stdio.h, [], [], [])
AC_CHECK_HEADERS(stdio.h,,,)
AC_CHECK_HEADERS(stdio.h)
It is best to put each macro call on its own line in configure.ac. Most of the macros don't add extra newlines; they rely on the newline after the macro call to terminate the commands. This approach makes the generated configure script a little easier to read by not inserting lots of blank lines. It is generally safe to set shell variables on the same line as a macro call, because the shell allows assignments without intervening newlines.
You can include comments in configure.ac files by starting them with the #. For example, it is helpful to begin configure.ac files with a line like this:
# Process this file with autoconf to produce a configure script.
The order in which configure.ac calls the Autoconf macros is not
important, with a few exceptions. Every configure.ac must
contain a call to AC_INIT before the checks, and a call to
AC_OUTPUT at the end (see Output). Additionally, some macros
rely on other macros having been called first, because they check
previously set values of some variables to decide what to do. These
macros are noted in the individual descriptions (see Existing Tests), and they also warn you when configure is created if they
are called out of order.
To encourage consistency, here is a suggested order for calling the Autoconf macros. Generally speaking, the things near the end of this list are those that could depend on things earlier in it. For example, library functions could be affected by types and libraries.
Autoconf requirements
AC_INIT(package, version, bug-report-address)
information on the package
checks for programs
checks for libraries
checks for header files
checks for types
checks for structures
checks for compiler characteristics
checks for library functions
checks for system services
AC_CONFIG_FILES([file...])
AC_OUTPUT
The autoscan program can help you create and/or maintain a configure.ac file for a software package. autoscan examines source files in the directory tree rooted at a directory given as a command line argument, or the current directory if none is given. It searches the source files for common portability problems and creates a file configure.scan which is a preliminary configure.ac for that package, and checks a possibly existing configure.ac for completeness.
When using autoscan to create a configure.ac, you
should manually examine configure.scan before renaming it to
configure.ac; it will probably need some adjustments.
Occasionally, autoscan outputs a macro in the wrong order
relative to another macro, so that autoconf produces a warning;
you need to move such macros manually. Also, if you want the package to
use a configuration header file, you must add a call to
AC_CONFIG_HEADERS (see Configuration Headers). You might
also have to change or add some #if directives to your program in
order to make it work with Autoconf (see ifnames Invocation, for
information about a program that can help with that job).
When using autoscan to maintain a configure.ac, simply consider adding its suggestions. The file autoscan.log will contain detailed information on why a macro is requested.
autoscan uses several data files (installed along with Autoconf) to determine which macros to output when it finds particular symbols in a package's source files. These data files all have the same format: each line consists of a symbol, whitespace, and the Autoconf macro to output if that symbol is encountered. Lines starting with # are comments.
autoscan accepts the following options:
ifnames can help you write configure.ac for a software package. It prints the identifiers that the package already uses in C preprocessor conditionals. If a package has already been set up to have some portability, ifnames can thus help you figure out what its configure needs to check for. It may help fill in some gaps in a configure.ac generated by autoscan (see autoscan Invocation).
ifnames scans all of the C source files named on the command line
(or the standard input, if none are given) and writes to the standard
output a sorted list of all the identifiers that appear in those files
in #if, #elif, #ifdef, or #ifndef
directives. It prints each identifier on a line, followed by a
space-separated list of the files in which that identifier occurs.
ifnames accepts the following options:
To create configure from configure.ac, run the autoconf program with no arguments. autoconf processes configure.ac with the M4 macro processor, using the Autoconf macros. If you give autoconf an argument, it reads that file instead of configure.ac and writes the configuration script to the standard output instead of to configure. If you give autoconf the argument -, it reads from the standard input instead of configure.ac and writes the configuration script to the standard output.
The Autoconf macros are defined in several files. Some of the files are distributed with Autoconf; autoconf reads them first. Then it looks for the optional file acsite.m4 in the directory that contains the distributed Autoconf macro files, and for the optional file aclocal.m4 in the current directory. Those files can contain your site's or the package's own Autoconf macro definitions (see Writing Autoconf Macros, for more information). If a macro is defined in more than one of the files that autoconf reads, the last definition it reads overrides the earlier ones.
autoconf accepts the following options:
AC_DIAGNOSE, for a comprehensive list of categories. Special
values include:
Warnings about syntax are enabled by default, and the environment
variable WARNINGS, a comma separated list of categories, is
honored. Passing -W category will actually behave as if
you had passed --warnings=syntax,$WARNINGS,category. If
you want to disable the defaults and WARNINGS, but (for example)
enable the warnings about obsolete constructs, you would use -W
none,obsolete.
Because autoconf uses autom4te behind the scenes, it
displays a back trace for errors, but not for warnings; if you want
them, just pass -W error. See autom4te Invocation, for some
examples.
The format is a regular string, with newlines if desired, and
several special escape codes. It defaults to $f:$l:$n:$%; see
autom4te Invocation, for details on the format.
AC_DEFUN definitions). This
results in a noticeable speedup, but can be disabled by this option.
It is often necessary to check the content of a configure.ac file, but parsing it yourself is extremely fragile and error-prone. It is suggested that you rely upon --trace to scan configure.ac. For instance, to find the list of variables that are substituted, use:
$ autoconf -t AC_SUBST
configure.ac:2:AC_SUBST:ECHO_C
configure.ac:2:AC_SUBST:ECHO_N
configure.ac:2:AC_SUBST:ECHO_T
More traces deleted
The example below highlights the difference between $@, $*, and $%.
$ cat configure.ac
AC_DEFINE(This, is, [an
[example]])
$ autoconf -t 'AC_DEFINE:@: $@
*: $*
$: $%'
@: [This],[is],[an
[example]]
*: This,is,an
[example]
$: This:is:an [example]
The format gives you a lot of freedom:
$ autoconf -t 'AC_SUBST:$$ac_subst{"$1"} = "$f:$l";'
$ac_subst{"ECHO_C"} = "configure.ac:2";
$ac_subst{"ECHO_N"} = "configure.ac:2";
$ac_subst{"ECHO_T"} = "configure.ac:2";
More traces deleted
A long separator can be used to improve the readability of complex structures, and to ease their parsing (for instance when no single character is suitable as a separator):
$ autoconf -t 'AM_MISSING_PROG:${|:::::|}*'
ACLOCAL|:::::|aclocal|:::::|$missing_dir
AUTOCONF|:::::|autoconf|:::::|$missing_dir
AUTOMAKE|:::::|automake|:::::|$missing_dir
More traces deleted
Installing the various components of the GNU Build System can be tedious: running autopoint for Gettext, automake for Makefile.in etc. in each directory. It may be needed either because some tools such as automake have been updated on your system, or because some of the sources such as configure.ac have been updated, or finally, simply in order to install the GNU Build System in a fresh tree.
autoreconf runs autoconf, autoheader, aclocal, automake, libtoolize, and autopoint (when appropriate) repeatedly to update the GNU Build System in the specified directories and their subdirectories (see Subdirectories). By default, it only remakes those files that are older than their sources.
If you install a new version of some tool, you can make autoreconf remake all of the files by giving it the --force option.
See Automatic Remaking, for Makefile rules to automatically remake configure scripts when their source files change. That method handles the timestamps of configuration header templates properly, but does not pass --autoconf-dir=dir or --localdir=dir.
autoreconf accepts the following options:
This option triggers calls to automake --add-missing,
libtoolize, autopoint, etc.
Warnings about syntax are enabled by default, and the environment
variable WARNINGS, a comma separated list of categories, is
honored. Passing -W category will actually behave as if
you had passed --warnings=syntax,$WARNINGS,category. If
you want to disable the defaults and WARNINGS, but (for example)
enable the warnings about obsolete constructs, you would use -W
none,obsolete.
Autoconf-generated configure scripts need some information about how to initialize, such as how to find the package's source files and about the output files to produce. The following sections describe the initialization and the creation of output files.
Every configure script must call AC_INIT before doing
anything else. The only other required macro is AC_OUTPUT
(see Output).
Process any command-line arguments and perform various initializations and verifications.
Set the name of the package and its version. These are typically used in --version support, including that of configure. The optional argument bug-report should be the email to which users should send bug reports. The package tarname differs from package: the latter designates the full package name (e.g., GNU Autoconf), while the former is meant for distribution tar ball names (e.g., autoconf). It defaults to package with GNU stripped, lower-cased, and all characters other than alphanumerics and underscores are changed to -.
It is preferable that the arguments of
AC_INITbe static, i.e., there should not be any shell computation, but they can be computed by M4.The following M4 macros (e.g.,
AC_PACKAGE_NAME), output variables (e.g.,PACKAGE_NAME), and preprocessor symbols (e.g.,PACKAGE_NAME) are defined byAC_INIT:
The following macros manage version numbers for configure scripts. Using them is optional.
Ensure that a recent enough version of Autoconf is being used. If the version of Autoconf being used to create configure is earlier than version, print an error message to the standard error output and exit with failure (exit status is 63). For example:
AC_PREREQ(2.59)This macro is the only macro that may be used before
AC_INIT, but for consistency, you are invited not to do so.
State that, in addition to the Free Software Foundation's copyright on the Autoconf macros, parts of your configure are covered by the copyright-notice.
The copyright-notice will show up in both the head of configure and in configure --version.
Copy revision stamp revision-info into the configure script, with any dollar signs or double-quotes removed. This macro lets you put a revision stamp from configure.ac into configure without RCS or CVS changing it when you check in configure. That way, you can determine easily which revision of configure.ac a particular configure corresponds to.
For example, this line in configure.ac:
AC_REVISION($Revision: 1.30 $)produces this in configure:
#! /bin/sh # From configure.ac Revision: 1.30
unique-file-in-source-dir is some file that is in the package's source directory; configure checks for this file's existence to make sure that the directory that it is told contains the source code in fact does. Occasionally people accidentally specify the wrong directory with --srcdir; this is a safety check. See configure Invocation, for more information.
Packages that do manual configuration or use the install program
might need to tell configure where to find some other shell
scripts by calling AC_CONFIG_AUX_DIR, though the default places
it looks are correct for most cases.
Use the auxiliary build tools (e.g., install-sh, config.sub, config.guess, Cygnus configure, Automake and Libtool scripts etc.) that are in directory dir. These are auxiliary files used in configuration. dir can be either absolute or relative to srcdir. The default is srcdir or srcdir/.. or srcdir/../.., whichever is the first that contains install-sh. The other files are not checked for, so that using
AC_PROG_INSTALLdoes not automatically require distributing the other auxiliary files. It checks for install.sh also, but that name is obsolete because somemakehave a rule that creates install from it if there is no Makefile.The auxiliary directory should not be named aux for portability to MS-DOS, because the filename aux is reserved under MS-DOS.
Similarly, packages that use aclocal should declare where
local macros can be found using AC_CONFIG_MACRO_DIR.
Future versions of autopoint, libtoolize, aclocal and autoreconf will use directory dir as the location of additional local Autoconf macros. Be sure to call this macro directly from configure.ac so that tools that install macros for aclocal can find the declaration before --trace can be called safely.
Every Autoconf script, e.g., configure.ac, should finish by
calling AC_OUTPUT. That is the macro that generates and runs
config.status, which will create the Makefiles and any
other files resulting from configuration. This is the only required
macro besides AC_INIT (see Input).
Generate config.status and launch it. Call this macro once, at the end of configure.ac.
config.status will perform all the configuration actions: all the output files (see Configuration Files, macro
AC_CONFIG_FILES), header files (see Configuration Headers, macroAC_CONFIG_HEADERS), commands (see Configuration Commands, macroAC_CONFIG_COMMANDS), links (see Configuration Links, macroAC_CONFIG_LINKS), subdirectories to configure (see Subdirectories, macroAC_CONFIG_SUBDIRS) are honored.The location of your
AC_OUTPUTinvocation is the exact point where configuration actions are taken: any code afterwards will be executed byconfigureonce config.status was run. If you want to bind actions to config.status itself (independently of whether configure is being run), see Running Arbitrary Configuration Commands.
Historically, the usage of AC_OUTPUT was somewhat different.
See Obsolete Macros, for a description of the arguments that
AC_OUTPUT used to support.
If you run make in subdirectories, you should run it using the
make variable MAKE. Most versions of make set
MAKE to the name of the make program plus any options it
was given. (But many do not include in it the values of any variables
set on the command line, so those are not passed on automatically.)
Some old versions of make do not set this variable. The
following macro allows you to use it even with those versions.
If make predefines the Make variable
MAKE, define output variableSET_MAKEto be empty. Otherwise, defineSET_MAKEto contain MAKE=make. CallsAC_SUBSTforSET_MAKE.
If you use this macro, place a line like this in each Makefile.in
that runs MAKE on other directories:
@SET_MAKE@
configure is designed so that it appears to do everything itself, but there is actually a hidden slave: config.status. configure is in charge of examining your system, but it is config.status that actually takes the proper actions based on the results of configure. The most typical task of config.status is to instantiate files.
This section describes the common behavior of the four standard
instantiating macros: AC_CONFIG_FILES, AC_CONFIG_HEADERS,
AC_CONFIG_COMMANDS and AC_CONFIG_LINKS. They all
have this prototype:
AC_CONFIG_FOOS(tag..., [commands], [init-cmds])
where the arguments are:
You are encouraged to use literals as tags. In particular, you should avoid
... && my_foos="$my_foos fooo"
... && my_foos="$my_foos foooo"
AC_CONFIG_FOOS($my_foos)
and use this instead:
... && AC_CONFIG_FOOS(fooo)
... && AC_CONFIG_FOOS(foooo)
The macros AC_CONFIG_FILES and AC_CONFIG_HEADERS use
special tags: they may have the form output or
output:inputs. The file output is instantiated
from its templates, inputs (defaulting to output.in).
For instance AC_CONFIG_FILES(Makefile:boiler/top.mk:boiler/bot.mk) asks for the creation of Makefile that will be the expansion of the output variables in the concatenation of boiler/top.mk and boiler/bot.mk.
The special value - might be used to denote the standard output when used in output, or the standard input when used in the inputs. You most probably don't need to use this in configure.ac, but it is convenient when using the command line interface of ./config.status, see config.status Invocation, for more details.
The inputs may be absolute or relative filenames. In the latter
case they are first looked for in the build tree, and then in the source
tree.
The variables set during the execution of configure are not available here: you first need to set them via the init-cmds. Nonetheless the following variables are precomputed:
srcdirac_top_srcdirac_top_builddirac_srcdirThe current directory refers to the directory (or pseudo-directory) containing the input part of tags. For instance, running
AC_CONFIG_COMMANDS([deep/dir/out:in/in.in], [...], [...])
with --srcdir=../package produces the following values:
# Argument of --srcdir
srcdir='../package'
# Reversing deep/dir
ac_top_builddir='../../'
# Concatenation of $ac_top_builddir and srcdir
ac_top_srcdir='../../../package'
# Concatenation of $ac_top_srcdir and deep/dir
ac_srcdir='../../../package/deep/dir'
independently of in/in.in.
var. init-cmds
is typically used by configure to give config.status some
variables it needs to run the commands.
You should be extremely cautious in your variable names: all the init-cmds share the same name space and may overwrite each other in unpredictable ways. Sorry....
All these macros can be called multiple times, with different tags, of course!
Be sure to read the previous section, Configuration Actions.
Make
AC_OUTPUTcreate each file by copying an input file (by default file.in), substituting the output variable values. This macro is one of the instantiating macros; see Configuration Actions. See Makefile Substitutions, for more information on using output variables. See Setting Output Variables, for more information on creating them. This macro creates the directory that the file is in if it doesn't exist. Usually, Makefiles are created this way, but other files, such as .gdbinit, can be specified as well.Typical calls to
AC_CONFIG_FILESlook like this:AC_CONFIG_FILES([Makefile src/Makefile man/Makefile X/Imakefile]) AC_CONFIG_FILES([autoconf], [chmod +x autoconf])You can override an input file name by appending to file a colon-separated list of input files. Examples:
AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk] [lib/Makefile:boiler/lib.mk])Doing this allows you to keep your file names acceptable to MS-DOS, or to prepend and/or append boilerplate to the file.
Each subdirectory in a distribution that contains something to be
compiled or installed should come with a file Makefile.in, from
which configure will create a Makefile in that directory.
To create a Makefile, configure performs a simple variable
substitution, replacing occurrences of @variable@ in
Makefile.in with the value that configure has determined
for that variable. Variables that are substituted into output files in
this way are called output variables. They are ordinary shell
variables that are set in configure. To make configure
substitute a particular variable into the output files, the macro
AC_SUBST must be called with that variable name as an argument.
Any occurrences of @variable@ for other variables are
left unchanged. See Setting Output Variables, for more information
on creating output variables with AC_SUBST.
A software package that uses a configure script should be distributed with a file Makefile.in, but no Makefile; that way, the user has to properly configure the package for the local system before compiling it.
See Makefile Conventions (The GNU Coding Standards), for more information on what to put in Makefiles.
Some output variables are preset by the Autoconf macros. Some of the
Autoconf macros set additional output variables, which are mentioned in
the descriptions for those macros. See Output Variable Index, for a
complete list of output variables. See Installation Directory Variables, for the list of the preset ones related to installation
directories. Below are listed the other preset ones. They all are
precious variables (see Setting Output Variables,
AC_ARG_VAR).
Debugging and optimization options for the C compiler. If it is not set in the environment when configure runs, the default value is set when you call
AC_PROG_CC(or empty if you don't). configure uses this variable when compiling programs to test for C features.
A comment saying that the file was generated automatically by configure and giving the name of the input file.
AC_OUTPUTadds a comment line containing this variable to the top of every Makefile it creates. For other files, you should reference this variable in a comment at the top of each input file. For example, an input shell script should begin like this:#! /bin/sh # @configure_input@The presence of that line also reminds people editing the file that it needs to be processed by configure in order to be used.
Header file search directory (-Idir) and any other miscellaneous options for the C and C++ preprocessors and compilers. If it is not set in the environment when configure runs, the default value is empty. configure uses this variable when compiling or preprocessing programs to test for C and C++ features.
Debugging and optimization options for the C++ compiler. If it is not set in the environment when configure runs, the default value is set when you call
AC_PROG_CXX(or empty if you don't). configure uses this variable when compiling programs to test for C++ features.
-D options to pass to the C compiler. If
AC_CONFIG_HEADERSis called, configure replaces @DEFS@ with -DHAVE_CONFIG_H instead (see Configuration Headers). This variable is not defined while configure is performing its tests, only when creating the output files. See Setting Output Variables, for how to check the results of previous tests.
How does one suppress the trailing newline from
echofor question-answer message pairs? These variables provide a way:echo $ECHO_N "And the winner is... $ECHO_C" sleep 100000000000 echo "${ECHO_T}dead."Some old and uncommon
echoimplementations offer no means to achieve this, in which caseECHO_Tis set to tab. You might not want to use it.
Debugging and optimization options for the Fortran compiler. If it is not set in the environment when configure runs, the default value is set when you call
AC_PROG_FC(or empty if you don't). configure uses this variable when compiling programs to test for Fortran features.
Debugging and optimization options for the Fortran 77 compiler. If it is not set in the environment when configure runs, the default value is set when you call
AC_PROG_F77(or empty if you don't). configure uses this variable when compiling programs to test for Fortran 77 features.
Stripping (-s), path (-L), and any other miscellaneous options for the linker. Don't use this variable to pass library names (-l) to the linker, use
LIBSinstead. If it is not set in the environment when configure runs, the default value is empty. configure uses this variable when linking programs to test for C, C++, and Fortran features.
-l options to pass to the linker. The default value is empty, but some Autoconf macros may prepend extra libraries to this variable if those libraries are found and provide necessary functions, see Libraries. configure uses this variable when linking programs to test for C, C++, and Fortran features.
The relative path to the top-level of the current build tree. In the top-level directory, this is the same as
builddir.
The relative path to the directory that contains the source code for that Makefile.
The relative path to the top-level source code directory for the package. In the top-level directory, this is the same as
srcdir.
The following variables specify the directories where the package will be installed, see Variables for Installation Directories (The GNU Coding Standards), for more information. See the end of this section for details on when and how to use these variables.
The installation prefix for architecture-dependent files. By default it's the same as prefix. You should avoid installing anything directly to exec_prefix. However, the default value for directories containing architecture-dependent files should be relative to exec_prefix.
The common installation prefix for all files. If exec_prefix is defined to a different value, prefix is used only for architecture-independent files.
Most of these variables have values that rely on prefix or
exec_prefix. It is deliberate that the directory output
variables keep them unexpanded: typically @datadir@ will be
replaced by ${prefix}/share, not /usr/local/share.
This behavior is mandated by the GNU coding standards, so that when the user runs:
In order to support these features, it is essential that datadir
remains being defined as ${prefix}/share to depend upon the
current value of prefix.
A corollary is that you should not use these variables except in
Makefiles. For instance, instead of trying to evaluate datadir
in configure and hard-coding it in Makefiles using
e.g., AC_DEFINE_UNQUOTED(DATADIR, "$datadir"), you should add
-DDATADIR="$(datadir)" to your CPPFLAGS.
Similarly you should not rely on AC_OUTPUT_FILES to replace
datadir and friends in your shell scripts and other files, rather
let make manage their replacement. For instance Autoconf
ships templates of its shell scripts ending with .in, and uses a
Makefile snippet similar to:
edit = sed \
-e 's,@datadir\@,$(pkgdatadir),g' \
-e 's,@prefix\@,$(prefix),g'
autoconf: Makefile $(srcdir)/autoconf.in
rm -f autoconf autoconf.tmp
$(edit) $(srcdir)/autoconf.in >autoconf.tmp
chmod +x autoconf.tmp
mv autoconf.tmp autoconf
autoheader: Makefile $(srcdir)/autoheader.in
rm -f autoheader autoheader.tmp
$(edit) $(srcdir)/autoconf.in >autoheader.tmp
chmod +x autoheader.tmp
mv autoheader.tmp autoheader
Some details are noteworthy:
edit uses values that depend on the configuration specific
values (prefix etc.) and not only on VERSION and so forth,
the output depends on Makefile, not configure.ac.
autoconf autoheader: Makefile
.in:
rm -f $@ $@.tmp
$(edit) $< >$@.tmp
chmod +x $@.tmp
mv $@.tmp $@
See Limitations of Make, for details.
You can support compiling a software package for several architectures simultaneously from the same copy of the source code. The object files for each architecture are kept in their own directory.
To support doing this, make uses the VPATH variable to
find the files that are in the source directory. GNU Make
and most other recent make programs can do this. Older
make programs do not support VPATH; when using them, the
source code must be in the same directory as the object files.
To support VPATH, each Makefile.in should contain two
lines that look like:
srcdir = @srcdir@
VPATH = @srcdir@
Do not set VPATH to the value of another variable, for example
VPATH = $(srcdir), because some versions of make do not do
variable substitutions on the value of VPATH.
configure substitutes the correct value for srcdir when
it produces Makefile.
Do not use the make variable $<, which expands to the
file name of the file in the source directory (found with VPATH),
except in implicit rules. (An implicit rule is one such as .c.o,
which tells how to create a .o file from a .c file.) Some
versions of make do not set $< in explicit rules; they
expand it to an empty value.
Instead, Makefile command lines should always refer to source files by prefixing them with $(srcdir)/. For example:
time.info: time.texinfo
$(MAKEINFO) $(srcdir)/time.texinfo
You can put rules like the following in the top-level Makefile.in for a package to automatically update the configuration information when you change the configuration files. This example includes all of the optional files, such as aclocal.m4 and those related to configuration header files. Omit from the Makefile.in rules for any of these files that your package does not use.
The $(srcdir)/ prefix is included because of limitations in the
VPATH mechanism.
The stamp- files are necessary because the timestamps of config.h.in and config.h will not be changed if remaking them does not change their contents. This feature avoids unnecessary recompilation. You should include the file stamp-h.in your package's distribution, so make will consider config.h.in up to date. Don't use touch (see Limitations of Usual Tools), rather use echo (using date would cause needless differences, hence CVS conflicts etc.).
$(srcdir)/configure: configure.ac aclocal.m4
cd $(srcdir) && autoconf
# autoheader might not change config.h.in, so touch a stamp file.
$(srcdir)/config.h.in: stamp-h.in
$(srcdir)/stamp-h.in: configure.ac aclocal.m4
cd $(srcdir) && autoheader
echo timestamp > $(srcdir)/stamp-h.in
config.h: stamp-h
stamp-h: config.h.in config.status
./config.status
Makefile: Makefile.in config.status
./config.status
config.status: configure
./config.status --recheck
(Be careful if you copy these lines directly into your Makefile, as you will need to convert the indented lines to start with the tab character.)
In addition, you should use AC_CONFIG_FILES([stamp-h], [echo
timestamp > stamp-h]) so config.status will ensure that
config.h is considered up to date. See Output, for more
information about AC_OUTPUT.
See config.status Invocation, for more examples of handling configuration-related dependencies.
When a package contains more than a few tests that define C preprocessor
symbols, the command lines to pass -D options to the compiler
can get quite long. This causes two problems. One is that the
make output is hard to visually scan for errors. More
seriously, the command lines can exceed the length limits of some
operating systems. As an alternative to passing -D options to
the compiler, configure scripts can create a C header file
containing #define directives. The AC_CONFIG_HEADERS
macro selects this kind of output. It should be called right after
AC_INIT.
The package should #include the configuration header file before
any other header files, to prevent inconsistencies in declarations (for
example, if it redefines const). Use #include <config.h>
instead of #include "config.h", and pass the C compiler a
-I. option (or -I..; whichever directory contains
config.h). That way, even if the source directory is configured
itself (perhaps to make a distribution), other build directories can
also be configured without finding the config.h from the source
directory.
This macro is one of the instantiating macros; see Configuration Actions. Make
AC_OUTPUTcreate the file(s) in the whitespace-separated list header containing C preprocessor#definestatements, and replace @DEFS@ in generated files with -DHAVE_CONFIG_H instead of the value ofDEFS. The usual name for header is config.h.If header already exists and its contents are identical to what
AC_OUTPUTwould put in it, it is left alone. Doing this allows making some changes in the configuration without needlessly causing object files that depend on the header file to be recompiled.Usually the input file is named header.in; however, you can override the input file name by appending to header a colon-separated list of input files. Examples:
AC_CONFIG_HEADERS([config.h:config.hin]) AC_CONFIG_HEADERS([defines.h:defs.pre:defines.h.in:defs.post])Doing this allows you to keep your file names acceptable to MS-DOS, or to prepend and/or append boilerplate to the file.
See Configuration Actions, for more details on header.
Your distribution should contain a template file that looks as you want
the final header file to look, including comments, with #undef
statements which are used as hooks. For example, suppose your
configure.ac makes these calls:
AC_CONFIG_HEADERS([conf.h])
AC_CHECK_HEADERS([unistd.h])
Then you could have code like the following in conf.h.in. On systems that have unistd.h, configure will #define HAVE_UNISTD_H to 1. On other systems, the whole line will be commented out (in case the system predefines that symbol).
/* Define as 1 if you have unistd.h. */
#undef HAVE_UNISTD_H
Pay attention that #undef is in the first column, and there is nothing behind HAVE_UNISTD_H, not even white spaces. You can then decode the configuration header using the preprocessor directives:
#include <conf.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#else
/* We are in trouble. */
#endif
The use of old form templates, with #define instead of #undef is strongly discouraged. Similarly with old templates with comments on the same line as the #undef. Anyway, putting comments in preprocessor macros has never been a good idea.
Since it is a tedious task to keep a template header up to date, you may use autoheader to generate it, see autoheader Invocation.
The autoheader program can create a template file of C
#define statements for configure to use. If
configure.ac invokes AC_CONFIG_HEADERS(file),
autoheader creates file.in; if multiple file
arguments are given, the first one is used. Otherwise,
autoheader creates config.h.in.
In order to do its job, autoheader needs you to document all
of the symbols that you might use; i.e., there must be at least one
AC_DEFINE or one AC_DEFINE_UNQUOTED call with a third
argument for each symbol (see Defining Symbols). An additional
constraint is that the first argument of AC_DEFINE must be a
literal. Note that all symbols defined by Autoconf's builtin tests are
already documented properly; you only need to document those that you
define yourself.
You might wonder why autoheader is needed: after all, why would configure need to “patch” a config.h.in to produce a config.h instead of just creating config.h from scratch? Well, when everything rocks, the answer is just that we are wasting our time maintaining autoheader: generating config.h directly is all that is needed. When things go wrong, however, you'll be thankful for the existence of autoheader.
The fact that the symbols are documented is important in order to
check that config.h makes sense. The fact that there is a
well-defined list of symbols that should be #define'd (or not) is
also important for people who are porting packages to environments where
configure cannot be run: they just have to fill in the
blanks.
But let's come back to the point: autoheader's invocation...
If you give autoheader an argument, it uses that file instead of configure.ac and writes the header file to the standard output instead of to config.h.in. If you give autoheader an argument of -, it reads the standard input instead of configure.ac and writes the header file to the standard output.
autoheader accepts the following options:
autoheader scans configure.ac and figures out which C
preprocessor symbols it might define. It knows how to generate
templates for symbols defined by AC_CHECK_HEADERS,
AC_CHECK_FUNCS etc., but if you AC_DEFINE any additional
symbol, you must define a template for it. If there are missing
templates, autoheader fails with an error message.
The simplest way to create a template for a symbol is to supply the description argument to an AC_DEFINE(symbol); see Defining Symbols. You may also use one of the following macros.
Tell autoheader to include the template as-is in the header template file. This template is associated with the key, which is used to sort all the different templates and guarantee their uniqueness. It should be a symbol that can be
AC_DEFINE'd.For example:
AH_VERBATIM([_GNU_SOURCE], [/* Enable GNU extensions on systems that have them. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif])
Tell autoheader to generate a template for key. This macro generates standard templates just like
AC_DEFINEwhen a description is given.For example:
AH_TEMPLATE([CRAY_STACKSEG_END], [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. This function is required for alloca.c support on those systems.])will generate the following template, with the description properly justified.
/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. This function is required for alloca.c support on those systems. */ #undef CRAY_STACKSEG_END
You can execute arbitrary commands before, during, and after
config.status is run. The three following macros accumulate the
commands to run when they are called multiple times.
AC_CONFIG_COMMANDS replaces the obsolete macro
AC_OUTPUT_COMMANDS; see Obsolete Macros, for details.
Specify additional shell commands to run at the end of config.status, and shell commands to initialize any variables from configure. Associate the commands with tag. Since typically the cmds create a file, tag should naturally be the name of that file. If needed, the directory hosting tag is created. This macro is one of the instantiating macros; see Configuration Actions.
Here is an unrealistic example:
fubar=42 AC_CONFIG_COMMANDS([fubar], [echo this is extra $fubar, and so on.], [fubar=$fubar])Here is a better one:
AC_CONFIG_COMMANDS([time-stamp], [date >time-stamp])
You may find it convenient to create links whose destinations depend upon
results of tests. One can use AC_CONFIG_COMMANDS but the
creation of relative symbolic links can be delicate when the package is
built in a directory different from the source directory.
Make
AC_OUTPUTlink each of the existing files source to the corresponding link name dest. Makes a symbolic link if possible, otherwise a hard link if possible, otherwise a copy. The dest and source names should be relative to the top level source or build directory. This macro is one of the instantiating macros; see Configuration Actions.For example, this call:
AC_CONFIG_LINKS(host.h:config/$machine.h object.h:config/$obj_format.h)creates in the current directory host.h as a link to srcdir/config/$machine.h, and object.h as a link to srcdir/config/$obj_format.h.
The tempting value . for dest is invalid: it makes it impossible for config.status to guess the links to establish.
One can then run:
./config.status host.h object.hto create the links.
In most situations, calling AC_OUTPUT is sufficient to produce
Makefiles in subdirectories. However, configure scripts
that control more than one independent package can use
AC_CONFIG_SUBDIRS to run configure scripts for other
packages in subdirectories.
Make
AC_OUTPUTrun configure in each subdirectory dir in the given whitespace-separated list. Each dir should be a literal, i.e., please do not use:if test "$package_foo_enabled" = yes; then $my_subdirs="$my_subdirs foo" fi AC_CONFIG_SUBDIRS($my_subdirs)because this prevents ./configure --help=recursive from displaying the options of the package
foo. Rather, you should write:if test "$package_foo_enabled" = yes; then AC_CONFIG_SUBDIRS(foo) fiIf a given dir is not found, an error is reported: if the subdirectory is optional, write:
if test -d $srcdir/foo; then AC_CONFIG_SUBDIRS(foo) fiIf a given dir contains configure.gnu, it is run instead of configure. This is for packages that might use a non-Autoconf script Configure, which can't be called through a wrapper configure since it would be the same file on case-insensitive filesystems. Likewise, if a dir contains configure.in but no configure, the Cygnus configure script found by
AC_CONFIG_AUX_DIRis used.The subdirectory configure scripts are given the same command line options that were given to this configure script, with minor changes if needed, which include:
- adjusting a relative path for the cache file;
- adjusting a relative path for the source directory;
- propagating the current value of
$prefix, including if it was defaulted, and if the default values of the top level and of the subdirectory configure differ.This macro also sets the output variable
subdirsto the list of directories dir .... Makefile rules can use this variable to determine which subdirectories to recurse into.This macro may be called multiple times.
By default, configure sets the prefix for files it installs to /usr/local. The user of configure can select a different prefix using the --prefix and --exec-prefix options. There are two ways to change the default: when creating configure, and when running it.
Some software packages might want to install in a directory other than
/usr/local by default. To accomplish that, use the
AC_PREFIX_DEFAULT macro.
Set the default installation prefix to prefix instead of /usr/local.
It may be convenient for users to have configure guess the
installation prefix from the location of a related program that they
have already installed. If you wish to do that, you can call
AC_PREFIX_PROGRAM.
If the user did not specify an installation prefix (using the --prefix option), guess a value for it by looking for program in
PATH, the way the shell does. If program is found, set the prefix to the parent of the directory containing program, else default the prefix as described above (/usr/local orAC_PREFIX_DEFAULT). For example, if program isgccand thePATHcontains /usr/local/gnu/bin/gcc, set the prefix to /usr/local/gnu.
These macros test for particular system features that packages might need or want to use. If you need to test for a kind of feature that none of these macros check for, you can probably do it by calling primitive test macros with appropriate arguments (see Writing Tests).
These tests print messages telling the user which feature they're checking for, and what they find. They cache their results for future configure runs (see Caching Results).
Some of these macros set output variables. See Makefile Substitutions, for how to get their values. The phrase “define name” is used below as a shorthand to mean “define C preprocessor symbol name to the value 1”. See Defining Symbols, for how to get those symbol definitions into your program.
Much effort has been expended to make Autoconf easy to learn. The most obvious way to reach this goal is simply to enforce standard interfaces and behaviors, avoiding exceptions as much as possible. Because of history and inertia, unfortunately, there are still too many exceptions in Autoconf; nevertheless, this section describes some of the common rules.
All the generic macros that AC_DEFINE a symbol as a result of
their test transform their arguments to a standard alphabet.
First, argument is converted to upper case and any asterisks
(*) are each converted to P. Any remaining characters
that are not alphanumeric are converted to underscores.
For instance,
AC_CHECK_TYPES(struct $Expensive*)
will define the symbol HAVE_STRUCT__EXPENSIVEP if the check succeeds.
Several tests depend upon a set of header files. Since these headers are not universally available, tests actually have to provide a set of protected includes, such as:
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
Unless you know exactly what you are doing, you should avoid using unconditional includes, and check the existence of the headers you include beforehand (see Header Files).
Most generic macros use the following macro to provide the default set of includes:
Expand to include-directives if defined, otherwise to:
#include <stdio.h> #if HAVE_SYS_TYPES_H # include <sys/types.h> #endif #if HAVE_SYS_STAT_H # include <sys/stat.h> #endif #if STDC_HEADERS # include <stdlib.h> # include <stddef.h> #else # if HAVE_STDLIB_H # include <stdlib.h> # endif #endif #if HAVE_STRING_H # if !STDC_HEADERS && HAVE_MEMORY_H # include <memory.h> # endif # include <string.h> #endif #if HAVE_STRINGS_H # include <strings.h> #endif #if HAVE_INTTYPES_H # include <inttypes.h> #else # if HAVE_STDINT_H # include <stdint.h> # endif #endif #if HAVE_UNISTD_H # include <unistd.h> #endifIf the default includes are used, then check for the presence of these headers and their compatibility, i.e., you don't need to run
AC_HEADERS_STDC, nor check for stdlib.h etc.These headers are checked for in the same order as they are included. For instance, on some systems string.h and strings.h both exist, but conflict. Then
HAVE_STRING_Hwill be defined, butHAVE_STRINGS_Hwon't.
These macros check for the presence or behavior of particular programs. They are used to choose between several alternative programs and to decide what to do once one has been chosen. If there is no macro specifically defined to check for a program you need, and you don't need to check for any special properties of it, then you can use one of the general program-check macros.
These macros check for particular programs—whether they exist, and in some cases whether they support certain features.
Check for
gawk,mawk,nawk, andawk, in that order, and set output variableAWKto the first one that is found. It triesgawkfirst because that is reported to be the best implementation.
Check for
grep -Eandegrep, in that order, and set output variableEGREPto the first one that is found.
Check for
grep -Fandfgrep, in that order, and set output variableFGREPto the first one that is found.
Set output variable
INSTALLto the path of a BSD-compatibleinstallprogram, if one is found in the currentPATH. Otherwise, setINSTALLto dir/install-sh -c, checking the directories specified toAC_CONFIG_AUX_DIR(or its default directories) to determine dir (see Output). Also set the variablesINSTALL_PROGRAMandINSTALL_SCRIPTto ${INSTALL} andINSTALL_DATAto ${INSTALL} -m 644.This macro screens out various instances of
installknown not to work. It prefers to find a C program rather than a shell script, for speed. Instead of install-sh, it can also use install.sh, but that name is obsolete because some make programs have a rule that creates install from it if there is no Makefile.Autoconf comes with a copy of install-sh that you can use. If you use
AC_PROG_INSTALL, you must include either install-sh or install.sh in your distribution, or configure will produce an error message saying it can't find them—even if the system you're on has a goodinstallprogram. This check is a safety measure to prevent you from accidentally leaving that file out, which would prevent your package from installing on systems that don't have a BSD-compatibleinstallprogram.If you need to use your own installation program because it has features not found in standard
installprograms, there is no reason to useAC_PROG_INSTALL; just put the file name of your program into your Makefile.in files.
If
flexis found, set output variableLEXto flex andLEXLIBto -lfl, if that library is in a standard place. Otherwise setLEXto lex andLEXLIBto -ll.Define
YYTEXT_POINTERifyytextis a char * instead of a char []. Also set output variableLEX_OUTPUT_ROOTto the base of the file name that the lexer generates; usually lex.yy, but sometimes something else. These results vary according to whetherlexorflexis being used.You are encouraged to use Flex in your sources, since it is both more pleasant to use than plain Lex and the C source it produces is portable. In order to ensure portability, however, you must either provide a function
yywrapor, if you don't use it (e.g., your scanner has no #include-like feature), simply include a %noyywrap statement in the scanner's source. Once this done, the scanner is portable (unless you felt free to use nonportable constructs) and does not depend on any library. In this case, and in this case only, it is suggested that you use this Autoconf snippet:AC_PROG_LEX if test "$LEX" != flex; then LEX="$SHELL $missing_dir/missing flex" AC_SUBST(LEX_OUTPUT_ROOT, lex.yy) AC_SUBST(LEXLIB, '') fiThe shell script missing can be found in the Automake distribution.
To ensure backward compatibility, Automake's
AM_PROG_LEXinvokes (indirectly) this macro twice, which will cause an annoying but benign “AC_PROG_LEXinvoked multiple times” warning. Future versions of Automake will fix this issue; meanwhile, just ignore this message.As part of running the test, this macro may delete any file in the configuration directory named lex.yy.c or lexyy.c.
If ln -s works on the current file system (the operating system and file system support symbolic links), set the output variable
LN_Sto ln -s; otherwise, if ln works, setLN_Sto ln, and otherwise set it to cp -p.If you make a link in a directory other than the current directory, its meaning depends on whether ln or ln -s is used. To safely create links using $(LN_S), either find out which form is used and adjust the arguments, or always invoke
lnin the directory where the link is to be created.In other words, it does not work to do:
$(LN_S) foo /x/barInstead, do:
(cd /x && $(LN_S) foo bar)
Set output variable
RANLIBto ranlib ifranlibis found, and otherwise to : (do nothing).
If
bisonis found, set output variableYACCto bison -y. Otherwise, ifbyaccis found, setYACCto byacc. Otherwise setYACCto yacc.
These macros are used to find programs not covered by the “particular”
test macros. If you need to check the behavior of a program as well as
find out whether it is present, you have to write your own test for it
(see Writing Tests). By default, these macros use the environment
variable PATH. If you need to check for a program that might not
be in the user's PATH, you can pass a modified path to use
instead, like this:
AC_PATH_PROG([INETD], [inetd], [/usr/libexec/inetd],
[$PATH:/usr/libexec:/usr/sbin:/usr/etc:etc])
You are strongly encouraged to declare the variable passed to
AC_CHECK_PROG etc. as precious, See Setting Output Variables,
AC_ARG_VAR, for more details.
Check whether program prog-to-check-for exists in
PATH. If it is found, set variable to value-if-found, otherwise to value-if-not-found, if given. Always pass over reject (an absolute file name) even if it is the first found in the search path; in that case, set variable using the absolute file name of the prog-to-check-for found that is not reject. If variable was already set, do nothing. CallsAC_SUBSTfor variable.
Check for each program in the whitespace-separated list progs-to-check-for existing in the
PATH. If one is found, set variable to the name of that program. Otherwise, continue checking the next program in the list. If none of the programs in the list are found, set variable to value-if-not-found; if value-if-not-found is not specified, the value of variable is not changed. CallsAC_SUBSTfor variable.
Like
AC_CHECK_PROG, but first looks for prog-to-check-for with a prefix of the host type as determined byAC_CANONICAL_HOST, followed by a dash (see Canonicalizing). For example, if the user runs configure --host=i386-gnu, then this call:AC_CHECK_TOOL(RANLIB, ranlib, :)sets
RANLIBto i386-gnu-ranlib if that program exists inPATH, or otherwise to ranlib if that program exists inPATH, or to : if neither program exists.
Like
AC_CHECK_TOOL, each of the tools in the list progs-to-check-for are checked with a prefix of the host type as determined byAC_CANONICAL_HOST, followed by a dash (see Canonicalizing). If none of the tools can be found with a prefix, then the first one without a prefix is used. If a tool is found, set variable to the name of that program. If none of the tools in the list are found, set variable to value-if-not-found; if value-if-not-found is not specified, the value of variable is not changed. CallsAC_SUBSTfor variable.
Like
AC_CHECK_PROG, but set variable to the entire path of prog-to-check-for if found.
Like
AC_CHECK_PROGS, but if any of progs-to-check-for are found, set variable to the entire path of the program found.
Like
AC_CHECK_TOOL, but set variable to the entire path of the program if it is found.
You might also need to check for the existence of files. Before using these macros, ask yourself whether a run-time test might not be a better solution. Be aware that, like most Autoconf macros, they test a feature of the host machine, and therefore, they die when cross-compiling.
Check whether file file exists on the native system. If it is found, execute action-if-found, otherwise do action-if-not-found, if given.
Executes
AC_CHECK_FILEonce for each file listed in files. Additionally, defines HAVE_file (see Standard Symbols) for each file found.
The following macros check for the presence of certain C, C++, or Fortran library archive files.
Depending on the current language(see Language Choice), try to ensure that the C, C++, or Fortran function function is available by checking whether a test program can be linked with the library library to get the function. library is the base name of the library; e.g., to check for -lmp, use mp as the library argument.
action-if-found is a list of shell commands to run if the link with the library succeeds; action-if-not-found is a list of shell commands to run if the link fails. If action-if-found is not specified, the default action will prepend -llibrary to
LIBSand define HAVE_LIBlibrary (in all capitals). This macro is intended to support buildingLIBSin a right-to-left (least-dependent to most-dependent) fashion such that library dependencies are satisfied as a natural side-effect of consecutive tests. Some linkers are very sensitive to library ordering so the order in whichLIBSis generated is important to reliable detection of libraries.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that library is present, because linking the test program will always fail with unresolved symbols. The other-libraries argument should be limited to cases where it is desirable to test for one library in the presence of another that is not already in
LIBS.
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since childthods su">[action-if-found], [action-if-not-found], [other-libraries])
Search for a library defining function if it's not already available. This equates to calling AC_LINK_IFELSE([AC_LANG_CALL([], [function])]) first with no libraries, then for each library listed in search-libs.
Add -llibrary to
LIBSfor the first library found to contain function, and run action-if-found. If the function is not found, run action-if-not-found.If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the other-libraries argument, separated by spaces: e.g., -lXt -lX11. Otherwise, this macro will fail to detect that function is present, because linking the test program will always fail with unresolved symbols.
The following macros check for particular C library functions. If there is no macro specifically defined to check for a function you need, and you don't need to check for any special properties of it, then you can use one of the general function-check macros.
Most usual functions can either be missing, or be buggy, or be limited on some architectures. This section tries to make an inventory of these portability issues. By definition, this list will always require additions. Please help us keeping it as complete as possible.
exitexit returns int?
This is because exit predates void, and there was a long
tradition of it returning int.
putenvputenv puts the given string directly in
environ, but some systems make a copy of it instead (eg.
glibc 2.0, or BSD). And when a copy is made, unsetenv might
not free it, causing a memory leak (eg. FreeBSD 4).
POSIX specifies that putenv("FOO") removes FOO from the
environment, but on some systems (eg. FreeBSD 4) this is not the
case and instead unsetenv must be used.
On MINGW, a call putenv("FOO=") removes FOO from the
environment, rather than inserting it with an empty value.
signal handlersignal takes a handler function with a return type of
void, but some old systems required int instead. Any
actual int value returned is not used, this is only a
difference in the function prototype demanded.
All systems we know of in current use take void. Presumably
int was to support K&R C, where of course void is not
available. AC_TYPE_SIGNAL (see Particular Types) can be
used to establish the correct type in all cases.
snprintfsnprintf and vsnprintf
truncate the output and return the number of bytes that ought to have
been produced. Some older systems return the truncated length (e.g.,
GNU C Library 2.0.x or irix 6.5), some a negative value
(e.g., earlier GNU C Library versions), and some the buffer
length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
older systems ignore the length and overrun the buffer (e.g., 64-bit
Solaris 7).
sprintfsprintf and vsprintf return the
number of bytes written, but on some old systems (SunOS 4 for
instance) they return the buffer pointer instead.
sscanfsscanf requires that its
input string be writable (though it doesn't actually change it). This
can be a problem when using gcc since it normally puts
constant strings in read-only memory
(see Incompatibilities of GCC (Using and Porting the GNU Compiler Collection)). Apparently in some cases even
having format strings read-only can be a problem.
strnlen strnlen ("foobar", 0) = 0
strnlen ("foobar", 1) = 3
strnlen ("foobar", 2) = 2
strnlen ("foobar", 3) = 1
strnlen ("foobar", 4) = 0
strnlen ("foobar", 5) = 6
strnlen ("foobar", 6) = 6
strnlen ("foobar", 7) = 6
strnlen ("foobar", 8) = 6
strnlen ("foobar", 9) = 6
sysconf_SC_PAGESIZE is standard, but some older systems (eg. HP-UX
9) have _SC_PAGE_SIZE instead. This can be tested with
#ifdef.
unlinkunlink causes the given file to be
removed only after there are no more open file handles for it. Not all
OS's support this behavior though. So even on systems that provide
unlink, you cannot portably assume it is OK to call it on files
that are open. For example, on Windows 9x and ME, such a call would fail;
on DOS it could even lead to file system corruption, as the file might end
up being written to after the OS has removed it.
unsetenvunsetenv is not available, but a variable FOO
can be removed with a call putenv("FOO="), as described under
putenv above.
va_copyva_copy for copying
va_list variables. It may be available in older environments
too, though possibly as __va_copy (e.g., gcc in strict
C89 mode). These can be tested with #ifdef. A fallback to
memcpy (&dst, &src, sizeof(va_list)) will give maximum
portability.
va_listva_list is not necessarily just a pointer. It can be a
struct (e.g., gcc on Alpha), which means NULL is
not portable. Or it can be an array (e.g., gcc in some
PowerPC configurations), which means as a function parameter it can be
effectively call-by-reference and library routines might modify the
value back in the caller (e.g., vsnprintf in the GNU C Library
2.1).
>>>> right shift of a signed type replicates the
high bit, giving a so-called “arithmetic” shift. But care should be
taken since the ISO C standard doesn't require that behavior. On those
few processors without a native arithmetic shift (for instance Cray
vector systems) zero bits may be shifted in, the same as a shift of an
unsigned type.
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto alloca.o and definesC_ALLOCA(so programs can periodically call alloca(0) to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS.This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration ofallocamust precede everything else except for comments and preprocessor directives. The#pragmadirective is indented so that pre-ANSI C compilers will ignore it, rather than choke on it./* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ # if HAVE_ALLOCA_H # include <alloca.h> # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of error.
If the
fnmatchfunction conforms to POSIX, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Note that for historical reasons, contrary to the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. SeeAC_REPLACE_FNMATCHbelow.