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 1
1
CC ?= gcc
2
2
CFLAGS := -O -g \
3
- -std=c99 -pedantic \
3
+ -std=c99 -pedantic
4
+
5
+ CFLAGS_TO_CHECK := \
4
6
-fwrapv \
5
7
-Wall -Wextra \
6
8
-Wno-unused-but-set-variable \
@@ -14,6 +16,19 @@ CFLAGS := -O -g \
14
16
-Wno-format \
15
17
-Wno-format-pedantic
16
18
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
+
17
32
BUILD_SESSION := .session.mk
18
33
19
34
-include $(BUILD_SESSION )
You can’t perform that action at this time.
0 commit comments