automake
[Top][All Lists]
Advanced

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

Re: if vs. ifdef in Makefile.am


From: Nick Bowler
Subject: Re: if vs. ifdef in Makefile.am
Date: Wed, 1 Mar 2023 17:31:39 -0500

On 2023-03-01, Jan Engelhardt <jengelh@inai.de> wrote:
> You can utilize the same mechanism behind automake's `make V=1`:
>
> NDEBUG = 0
> my_CPPFLAGS_0 =
> my_CPPFLAGS_1 = -NDEBUG
> my_CFLAGS_0 = -O3
> my_CFLAGS_1 =
> AM_CPPFLAGS = ${my_CPPFLAGS_${NDEBUG}}
> AM_CFLAGS = ${my_CFLAGS_${NDEBUG}}

This syntax is not standard or portable; Automake's silent-rules stuff
is backed by configure tests to ensure the syntax is supported by make.

That being said, with most make implementations it will be "fine", in
that make implementations tend to accept almost any line noise between
the brackets of a variable expansion without complaint, simply expanding
it to the empty string.  Even the original make from V7 UNIX works this
way.  So the flags will be missing but the build should still complete
as these flags are presumably not critical.

One exception is HP-UX, which doesn't match the brackets properly so
you will end up with a stray } in CPPFLAGS and CFLAGS, most likely
causing the build to fail.  You can work around this particular problem
by exploting make's multiple equivalent forms for variable expansion,
for example $(my_CPPFLAGS_${NDEBUG}) should be quite "portable" in
the sense that it will either work or you get the empty string.

But... Autoconf already has the AC_HEADER_ASSERT macro which adds a
--disable-assert configure option that sets NDEBUG... why not just use
that?  The other flags (-O3, -fsanitize=address) will need to be backed
by configure tests anyway as not all C compilers support these options,
so why not just add an --enable-debug or similar to control all this?

Cheers,
  Nick



reply via email to

[Prev in Thread] Current Thread [Next in Thread]