[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CFLAGS and other flag variables
From: |
Alejandro Colomar |
Subject: |
Re: CFLAGS and other flag variables |
Date: |
Tue, 16 Jul 2024 16:27:22 +0200 |
Hi Paul,
On Tue, Jul 16, 2024 at 10:16:27AM GMT, Paul Smith wrote:
> 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).
Thanks for the reference to Sébastien's mail; I didn't receive a copy,
but have now checked the archive.
> 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.
Hmm, that makes sense.
>
> 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) $<
Now that I see this, I wonder:
Is there any order preference between CFLAGS and CPPFLAGS? I tend to
have CPPFLAGS first. Probably it doesn't matter, but I'll ask just in
case.
Also: I didn't know about TARGET_ARCH. Is that documented anywhere?
>
> (you can simplify this if you prefer of course, this reuses what the
> default rule implements).
Makes sense. I guess I'll do:
FOO_CFLAGS := -critical -flags
CFLAGS ?=
CFLAGS_ := $(FOO_CFLAGS) $(CFLAGS)
%.o: %.c
$(CC) $(CPPFLAGS_) $(CFLAGS_) ...
Thanks!
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature