m4_set_contains cannot find key

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

m4_set_contains cannot find key

Petre Pircalabu
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
_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|

Re: m4_set_contains cannot find key

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.

Many thanks,
Petre

On Fri, Mar 18, 2016 at 2:47 AM, Petre Pircalabu <[hidden email]>
wrote:

> 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
>
_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|

Re: m4_set_contains cannot find key

Eric Blake-3
On 03/18/2016 05:39 AM, Petre Pircalabu wrote:
> 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.

>> 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


_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (617 bytes) Download Attachment