configure
scripts need to test properties of many files and
strings. Here are some portability problems to watch out for when doing
those tests.
The test
program is the way to perform many file and string
tests. It is often invoked by the alternate name `[', but using
that name in Autoconf code is asking for trouble since it is an
m4
quote character.
If you need to make multiple checks using test
, combine
them with the shell operators `&&' and `||' instead of using
the test
operators `-a' and `-o'. On System V, the
precedence of `-a' and `-o' is wrong relative to the unary
operators; consequently, POSIX does not specify them, so using them is
nonportable. If you combine `&&' and `||' in the same
statement, keep in mind that they have equal precedence.
To enable configure
scripts to support cross-compilation, they
shouldn't do anything that tests features of the host system instead of
the target system. But occasionally you may find it necessary to check
whether some arbitrary file exists. To do so, use `test -f' or
`test -r'. Do not use `test -x', because 4.3BSD does not have
it.
Another nonportable shell programming construction is
var=${var:-value}
The intent is to set var to value only if it is not already
set, but if var has any value, even the empty string, to leave it
alone. Old BSD shells, including the Ultrix sh
, don't accept
the colon, and complain and die. A portable equivalent is
: ${var=value}
Go to the first, previous, next, last section, table of contents.