Honour pre-set CFLAGS and LDFLAGS.
Brought to you by:
pfusik
Current Makefile
hard-sets $CFLAGS
and $LDFLAGS
.
Feature request: Do not re-set the flags, but just append options.
The following patch, which does this, is taken from the asap
Arch Linux package:
--- a/Makefile 2021-10-07 21:48:58.204086012 -0700
+++ b/Makefile 2021-10-07 22:14:39.290565502 -0700
@@ -3,9 +3,9 @@
bindir = $(prefix)/bin
libdir = $(prefix)/lib
CC = gcc
-CFLAGS = -O2 -Wall
+CFLAGS += -O2 -Wall
CPPFLAGS =
-LDFLAGS = -s
+LDFLAGS += -s
AR = ar
ARFLAGS = rc
DO_CC = $(DO)$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(if $(filter %.so,$@),-shared -fPIC) $(INCLUDEOPTS) $(filter %.c,$^) $(LDFLAGS)
(Use even
-O3
and not-O2
to achieve even more optimisation. Or not set this at all, so the user can influence this via$CFLAGS
, e.g. can also set-Og
for debug optimisation.)I've seen
CFLAGS =
a lot. Even GNU Coding Standards promotes it. It doesn't stop from overriding the flags on the command line:Why is
+=
superior? I understand it enables environment variables, but why would we want to set flags via an environment variable and not themake
command line?Ahoj,
Ah, OK, I was not aware of that!
In your use case, you can still specify specific CFLAGS that are needed
to build the project correctly (I suppose mainly when you forcefully
need to switch off some optimisations).
In the use case I am referring to, it is helpful with Arch Linux
packaging:
There you can define in a global configuration file standard CFLAGS,
which get passed to the build scripts via environment variable.
This way, they are automatically honoured if the software's build
system honours the envoronment variable.
OK, if this patch is not applied, I can add in the package manually the
inclusion of
$CFLAGS
, or just keep the patch around.Regards!
Last edit: Drei Eck 2023-05-08