Alternative Programs

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.

Particular Program Checks

These macros check for particular programs--whether they exist, and in some cases whether they support certain features.

AC_PROG_AWK Check for gawk, mawk, nawk, and awk, in that order, and set output variable AWK to the first one that is found. It tries gawk first because that is reported to be the best implementation.

AC_PROG_INSTALL Set output variable INSTALL to the path of a bsd compatible install program, if one is found in the current PATH. Otherwise, set INSTALL to dir/install-sh -c, checking the directories specified to AC_CONFIG_AUX_DIR (or its default directories) to determine dir (the section called “Outputting Files”). Also set the variables INSTALL_PROGRAM and INSTALL_SCRIPT to ${INSTALL} and INSTALL_DATA to ${INSTALL} -m 644.

This macro screens out various instances of install known 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 good install program. 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-compatible install program.

If you need to use your own installation program because it has features not found in standard install programs, there is no reason to use AC_PROG_INSTALL; just put the file name of your program into your Makefile.in files.

AC_PROG_LEX If flex is found, set output variable LEX to flex and LEXLIB to -lfl, if that library is in a standard place. Otherwise set LEX to lex and LEXLIB to -ll.

Define YYTEXT_POINTER if yytext is a char * instead of a char []. Also set output variable LEX_OUTPUT_ROOT to the base of the file name that the lexer generates; usually lex.yy, but sometimes something else. These results vary according to whether lex or flex is 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 yywrap or, 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, '')
fi

The shell script missing can be found in the Automake distribution.

To ensure backward compatibility, Automake's AM_PROG_LEX invokes (indirectly) this macro twice, which will cause an annoying but benign "AC_PROG_LEX invoked multiple times" warning. Future versions of Automake will fix this issue, meanwhile, just ignore this message.

AC_PROG_LN_S If ln -s works on the current file system (the operating system and file system support symbolic links), set the output variable LN_S to ln -s; otherwise, if ln works, set LN_S to ln and otherwise set it to cp -p.

If you make a link 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 ln in the directory where the link is to be created.

In other words, it does not work to do:

$(LN_S) foo /x/bar

Instead, do:

(cd /x  $(LN_S) foo bar)

AC_PROG_RANLIB Set output variable RANLIB to ranlib if ranlib is found, and otherwise to : (do nothing).

AC_PROG_YACC If bison is found, set output variable YACC to bison -y. Otherwise, if byacc is found, set YACC to byacc. Otherwise set YACC to yacc.

Generic Program and File Checks

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 (Chapter 7). 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, the section called “Setting Output Variables”, AC_ARG_VAR, for more details.

AC_CHECK_PROG (variable, prog-to-check-for, value-if-found, [value-if-not-found], [path], [reject]) 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. Calls AC_SUBST for variable.

AC_CHECK_PROGS (variable, progs-to-check-for, [value-if-not-found], [path]) Check for each program in the whitespace-separated list progs-to-check-for exists on the PATH. If it 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. Calls AC_SUBST for variable.

AC_CHECK_TOOL (variable, prog-to-check-for, [value-if-not-found], [path]) Like AC_CHECK_PROG, but first looks for prog-to-check-for with a prefix of the host type as determined by AC_CANONICAL_HOST, followed by a dash (the section called “Getting the Canonical System Type”). For example, if the user runs configure -host=i386-gnu, then this call:

AC_CHECK_TOOL(RANLIB, ranlib, :)

sets RANLIB to i386-gnu-ranlib if that program exists in PATH, or otherwise to ranlib if that program exists in PATH, or to : if neither program exists.

AC_CHECK_TOOLS (variable, progs-to-check-for, [value-if-not-found], [path]) 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 by AC_CANONICAL_HOST, followed by a dash (the section called “Getting the Canonical System Type”). 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. Calls AC_SUBST for variable.

AC_PATH_PROG (variable, prog-to-check-for, [value-if-not-found], [path]) Like AC_CHECK_PROG, but set variable to the entire path of prog-to-check-for if found.

AC_PATH_PROGS (variable, progs-to-check-for, [value-if-not-found], [path]) Like AC_CHECK_PROGS, but if any of progs-to-check-for are found, set variable to the entire path of the program found.

AC_PATH_TOOL (variable, prog-to-check-for, [value-if-not-found], [path]) Like AC_CHECK_TOOL, but set variable to the entire path of the program if it is found.