[kvm-unit-tests PATCH v2 1/4] Makefile: Provide a concept of late CFLAGS

Mathias Krause
2025-09-15T21:54:50Z

Allow architectures to provide CFLAGS that should be added only after
all other optional CFLAGS have been evaluated.

This will be useful for flags that depend on other, generic ones.

To allow 'LATE_CFLAGS' to make use of the $(cc-option ...) helper,
assume it'll be a lazily evaluated variable. To further ensure the
$(cc-option ...) compiler invocation overhead won't be per-use of
$(CFLAGS), enforce its evaluation prior to extending CFLAGS.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
---
Makefile | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Makefile b/Makefile
index 9dc5d2234e2a..0ce0813bf124 100644
--- a/Makefile
+++ b/Makefile
@@ -95,6 +95,10 @@ CFLAGS += $(wmissing_parameter_type)
CFLAGS += $(wold_style_declaration)
CFLAGS += -Woverride-init -Wmissing-prototypes -Wstrict-prototypes

+# Evaluate and add late cflags last -- they may depend on previous flags
+LATE_CFLAGS := $(LATE_CFLAGS)
+CFLAGS += $(LATE_CFLAGS)
+
autodepend-flags = -MMD -MP -MF $(dir $*).$(notdir $*).d

LDFLAGS += -nostdlib $(no_pie) -z noexecstack
--
2.47.3