Reputation: 113
The document says
Macro: AS_IF (test1, [run-if-true1], ..., [run-if-false])
Run shell code test1. If test1 exits with a zero status then run shell code run-if-true1, else examine further tests. If no test exits with a zero status, run shell code run-if-false, with simplifications if either run-if-true1 or run-if-false is empty.
The configure.ac file contains
AS_IF([test "$have_hdf5" != "no"], [AC_DEFINE([HAVE_HDF5], [], [we have HDF5 library + headers])])
But when I type in the run shell code test1, i.e. test "$have_hdf5" != "no"
, nothing appeared. No matter what I entered (such as test $have_hdf5
), I got nothing. But it actually works when I ./configure
. So how does the AS_IF
and the test1
shell code work? Is it testing some environment variables?
Upvotes: 4
Views: 6302
Reputation:
The test
utility doesn't have visible output unless you supply an erroneous expression.
test
will exit with a 0 status if the expression was true and a nonzero exit status indicates the expression was false (or invalid).
AS_IF
tests the exit status of the expression you supply as its first parameter.
If it was 0 (true), the associated block of code is executed. If not, it moves on to the next test expression and performs with the same behavior.
This happens until the macro runs out of tests. Once all tests are found false, it executes the last parameter's contents if the last parameter was supplied.
Edit
Naturally if you don't have "have_hdf5" defined in your current shell, it won't be true when you execute your test
expression alone, but if it is true in the configure script, it will do what it is meant to. In any case, output will not happen unless you use an output statement.
Upvotes: 2
Reputation: 16315
The AS_IF
M4sh macro will expand out to a portable Bourne shell if
statement (when processed by autoconf
in the process of writing configure
), something like:
if test1 ; then run-if-true1 ... else run-if-false fi
where the interior tests and actions are wrapped in an elif ... ; then ...
.
Every other parameter starting from the 0th is tested. Usually these are some kind of variable test (e.g. test "$have_hdf5" != "no"
), but don't necessarily need to be.
Upvotes: 0