autoconf: should I always use AS_IF over if and m4_if?
Asked Answered
T

2

6

The autoconf manual suggest using AS_IF instead of if, but it doesn't mention m4_if. Should AS_IF also be preferred over m4_if?

The "Limitations of Builtins" section of the manual says to use AS_IF for it's portability, but the AC_REQUIRE description says to use it to expand required macros.

Should I always use AS_IF? The answer seems to be yes, but then again I see if and m4_if being used in other macros. When is it ok not to use AS_IF?

Tehuantepec answered 6/1, 2013 at 21:46 Comment(0)
T
4

I was confused about this because I didn't realize the fundamental difference between if/AS_IF and m4_if. The normal if and AS_IF have their conditionals evaluated when the user runs the script, i.e. configure. Conversely, m4_if has its conditional evaluated during macro expansion, i.e. autoreconf.

if/AS_IF affects the flow of the script. m4_if affects the contents of the script.

This seems obvious now, but I didn't get it at first. Hopefully this helps someone else.

Tehuantepec answered 14/1, 2013 at 1:54 Comment(2)
That doesn't say when to use if and when AS_IF.Karaganda
I think the consensus is to always use AS_IF over if, because you get better quoting, etc.Tehuantepec
C
2

The other benefit of AS_IF is that when it expands, any macros that are required by macros in the branches are expanded before the test.

See the manual.

Christoperchristoph answered 8/1, 2013 at 0:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.