Re: shell or M4sugar?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 8, 2021 at 6:18 AM Julien ÉLIE <julien@xxxxxxxxxxxxxxx> wrote:
> I have a question about the portability of "very simple" shell commands.
>   Should M4sugar be used whenever it has the functionality?

I wouldn't say "whenever", but the two macros you mention in your
example - AS_CASE and AS_ECHO - are almost always preferable to bare
shell code.

> AS_CASE([$host],
>      [*-openbsd*],
>          [CC_WARNINGS=`echo "$CC_WARNINGS" | sed 's/-Wredundant-decls //'`])

Using AS_CASE means you don't have to write unbalanced parentheses in
your configure.ac or extension .m4 file.  If this is the top level of
configure.ac, it also means the AC_REQUIRE machinery knows not to emit
required macros inside the conditional.

Using AS_ECHO means you don't have to worry about echo interpreting
text to be echoed as options.  Sometimes you know that's not relevant,
but in this example, $CC_WARNINGS is a list of compiler options, so I
would definitely use AS_ECHO.

> Would this mere change to AS_ECHO be better and enough?
>    CC_WARNINGS=`AS_ECHO("$CC_WARNINGS") | sed 's/-Wredundant-decls //'`

AS_ECHO(["$CC_WARNINGS"]) - yes, you need to quote for *both* m4 and
shell - but otherwise yes, that's the preferred form.

> Or the CC_WARNINGS be m4_define'd and then manipulated through m4_append
> & like, and use m4_bpatsubst for doing what sed does?

That won't work here; the value of $host is not yet known when you run
autoconf, only when you run configure.

(This is the difference between the "m4sugar" and "m4sh" layers.  m4_*
macros are fully executed at autoconf time, AS_* macros generate code
that will be executed at configure time.)

> P.-S.:  I really like the new modern display of the Autoconf manual
> (https://www.gnu.org/software/autoconf/manual/autoconf-2.70/autoconf.html)
> compared with the equivalent for 2.69.

Thank you, but all of the credit for this goes to the Texinfo
maintainers and the people responsible for www.gnu.org.  We haven't
done any custom styling.

zw





[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux