Discussion:
m4_set_contains cannot find key
Petre Pircalabu
2016-03-18 11:39:50 UTC
Permalink
Please disregard this question. The m4 preprocessing is done before
"configure", so the m4 preprocessor has no way of knowing about the
variable.

Many thanks,
Petre
Hello,
I'm getting a false negative when trying to test if a set contains a key.
The key is specified as a variable in configure.ac.
Can you please take a look at the following code snippet?
m4_set_add([food], [fish])
m4_set_add([food], [steak])
m4_set_add([food], [junk])
meal=junk
AC_MSG_CHECKING([whether we have junk food for dinner])
m4_set_contains([food], [$meal], [VAL="yes"], [VAL="no"])
AC_MSG_RESULT([${VAL}])
Unfortunately is says that I will be eating healthy food tonight and I
really don't know why.
Many thanks,
Petre
Eric Blake
2016-03-18 15:02:34 UTC
Permalink
Post by Petre Pircalabu
Please disregard this question. The m4 preprocessing is done before
"configure", so the m4 preprocessor has no way of knowing about the
variable.
Correct - you were mixing two languages (m4 and shell), and which gets
run when.
Post by Petre Pircalabu
m4_set_add([food], [fish])
m4_set_add([food], [steak])
m4_set_add([food], [junk])
meal=junk
AC_MSG_CHECKING([whether we have junk food for dinner])
m4_set_contains([food], [$meal], [VAL="yes"], [VAL="no"])
The literal string '$meal' (at m4-time) is NOT in the set, so the m4
result of the expansion is always going to trigger the 'VAL="no"'
branch. If you want to see if the contents of a shell variable are in a
shell set, then m4_set_* is not the right construct to be using.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Loading...