[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CFLAGS and other flag variables
From: |
Paul Smith |
Subject: |
Re: CFLAGS and other flag variables |
Date: |
Tue, 16 Jul 2024 10:16:27 -0400 |
User-agent: |
Evolution 3.52.3 (by Flathub.org) |
On Tue, 2024-07-16 at 15:37 +0200, Alejandro Colomar wrote:
> However, I think this is not standard practise. Is there any
> standard (or de-facto standard) practice regarding these variables?
Generally users who want to have more sophisticated build systems don't
try to re-use the built-in recipes. Instead they replace those with
their own pattern rules. This allows them to use separate variables
(as Sébastien suggests).
For example, if you examine automake which implements the GNU standards
for writing makefiles, they suggest that CFLAGS have a simple default
value, typically:
CFLAGS = -g -O2
But be reserved for users to set on the command line:
make CFLAGS=-g
which means that CFLAGS should never contain any critical flags.
Instead these standards recommend creating your own pattern rules to
avoid being limited to only the default settings; for example:
EXTRA_CFLAGS := $(shell pkgconf --cflags somedep)
%.o : %.c
$(CC) $(EXTRA_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
$(OUTPUT_OPTION) $<
(you can simplify this if you prefer of course, this reuses what the
default rule implements).