问题
I'm having a bit of a mystery in a autoconf script, specifically AS_IF
.
Here's the relevant code:
AC_CHECK_FUNCS([eventfd], [AC_DEFINE([NN_HAVE_EVENTFD])])
AC_CHECK_FUNCS([pipe], [AC_DEFINE([NN_HAVE_PIPE])])
AC_CHECK_FUNCS([pipe2], [
AC_DEFINE([NN_HAVE_PIPE2])
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
])
AC_SEARCH_LIBS([socketpair], [], [AC_DEFINE([NN_HAVE_SOCKETPAIR])])
i.e. checking for their existance. These work correctly and define the correct symbols. In this case, only NN_HAVE_PIPE
and NN_HAVE_SOCKETPAIR
gets defined, which is correct as this is a HP-UX system.
Now to the mystery part. Later in the configure.ac, there's a conditional referring to these symbols:
echo "ac_cv_func_eventfd: $ac_cv_func_eventfd"
AS_IF([test x"$ac_cv_func_eventfd"=xyes], [
AC_DEFINE([NN_USE_EVENTFD])], [
AS_IF([test x"$ac_cv_func_pipe"=xyes], [
AC_DEFINE([NN_USE_PIPE])], [
AS_IF([test x"$ac_cv_func_socketpair"=xyes], [
AC_DEFINE([NN_USE_SOCKETPAIR])], [
AC_MSG_ERROR([No signaling supported])
])
])
])
Even though ac_cv_func_eventfd
has value no
(I added the echo line to make sure), NN_USE_EVENTFD
gets defined anyway!
As the AS_IF
macro is defined as such:
AS_IF (test1, [run-if-true1], ..., [run-if-false])
To me, the code seems quite correct, no? Is there anyone that can shed some light on this behavior?
Autoconf version is 2.67. The OS is HP-UX 11.31 ia64.
回答1:
Not quite correct. You must fix your AS_IF
test from:
test x"$ac_cv_func_eventfd"=xyes
to
test x"$ac_cv_func_eventfd" = xyes
Note the insertion of spaces around the =
. Same goes for the other tests in the other AS_IF
s.
To verify this you can try seeing this at the command line:
if test x"no"=xyes; then echo "yes"; else echo "no"; fi
vs.
if test x"no" = xyes; then echo "yes"; else echo "no"; fi
来源:https://stackoverflow.com/questions/18889558/autoconf-as-if-doesnt-execute-correct-branch