[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CFLAGS and other flag variables
From: |
Alejandro Colomar |
Subject: |
CFLAGS and other flag variables |
Date: |
Tue, 16 Jul 2024 15:37:31 +0200 |
Hi Paul!
Usual compilation in a makefile is something like
foo.o: foo.c; $(CC) $(CFLAGS) $< -o $@
If a project needs some CFLAGS, I guess it would do the following
CFLAGS ?= $(shell pkgconf --cflags somedep)
But then, a user must not blindly overwrite CFLAGS. Those missing flags
from somedep would probably break compilation. For allowing one to
append instead of overwriting, I added EXTRA_CFLAGS, so that it looks
like
CFLAGS ?= $(shell pkgconf --cflags somedep) $(EXTRA_CFLAGS)
And so one can run `make EXTRA_CFLAGS=-O2` to append to the default
ones.
However, I think this is not standard practise. Is there any standard
(or de-facto standard) practice regarding these variables?
Same question for CPPFLAGS, LDFLAGS, etc.
I've been talking to some distributions, and they seem to want my
Makefile to read from CFLAGS and magically append to CFLAGS, which
sounds at least weird. Has this behavior been always like that? When
did it change? Is it autotools weirdness? Should I follow it?
I've been thinking that I could do it with something like the following:
ifdef CFLAGS
EXTRA_CFLAGS := $(CFLAGS)
endif
CFLAGS := $(shell pkgconf --cflags somedep) $(EXTRA_CFLAGS)
But that looks very weird, at least. (And it doesn't allow overwriting
all CFLAGS, which seems also meh.) I could go even weirder, and use:
ifdef CFLAGS
EXTRA_CFLAGS := $(CFLAGS)
endif
OVR_CFLAGS := $(shell pkgconf --cflags somedep)
CFLAGS := $(OVR_CFLAGS) $(EXTRA_CFLAGS)
Should I?
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature