File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11CC ?= gcc
22CFLAGS := -O -g \
3- -std=c99 -pedantic \
3+ -std=c99 -pedantic
4+
5+ CFLAGS_TO_CHECK := \
46 -fwrapv \
57 -Wall -Wextra \
68 -Wno-unused-but-set-variable \
@@ -14,6 +16,19 @@ CFLAGS := -O -g \
1416 -Wno-format \
1517 -Wno-format-pedantic
1618
19+ SUPPORTED_CFLAGS :=
20+ # Check if a specific compiler flag is supported, attempting a dummy compilation
21+ # with flags. If successful, it returns the flag string; otherwise, it returns
22+ # an empty string.
23+ # Usage: $(call check_flag, -some-flag)
24+ check_flag = $(shell $(CC ) $(1 ) -S -o /dev/null -xc /dev/null 2>/dev/null; \
25+ if test $$? -eq 0; then echo "$(1 ) "; fi)
26+
27+ # Iterate through the list of all potential flags, effectively filtering out all
28+ # unsupported flags.
29+ $(foreach flag, $(CFLAGS_TO_CHECK), $(eval SUPPORTED_CFLAGS += $(call check_flag, $(flag))))
30+ CFLAGS += $(SUPPORTED_CFLAGS )
31+
1732BUILD_SESSION := .session.mk
1833
1934-include $(BUILD_SESSION )
You can’t perform that action at this time.
0 commit comments