Re: if vs. ifdef in Makefile.am

Jan Engelhardt <[email protected]>
Newsgroups gmane.comp.sysutils.automake.general
Message-ID <[email protected]>
On Wednesday 2023-03-01 19:50, ljh via Discussion list for automake wrote:
>```
>$ make # NDEBUG=1
>$ make NDEBUG=1
>```
>
>Can I have automake.am to define and convey something like this to the output Makefile:
>```
>ifdef NDEBUG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # if vs. ifdef
>CPPFLAGS += -DNDEBUG
>CFLAGS += -O3 # .cpp
>else
>CFLAGS += -g # .cpp
>LDFLAGS += -fsanitize=address
>endif
>```

ifdef is the wrong tool. Because when you issue e.g. `make NDEBUG=0`, it
does not do what a sensible person would want.
Also, CFLAGS and LDFLAGS belong to the user. Don't touch them.


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}}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.