aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Richardson <alexrichardson@google.com>2021-12-09 10:59:09 +0000
committerTravis Geiselbrecht <travisg@gmail.com>2023-06-01 17:50:50 -0700
commit231f58903b6f86f8c8de33901671101152328ac8 (patch)
treee486a4111f14491807a8a81225147f439ed53442
parent06a206f44e6295695b014fd82c18487e37d6c6e7 (diff)
downloadlk-231f58903b6f86f8c8de33901671101152328ac8.tar.gz
[make][clang] Do not add unsupported warning flags
Currently, clang does not support the -Wno-nonnull-compare and -Wmaybe-uninitialized warning flags so this adds lots of unknown warning flag output for each compile job when not using GCC. This commit adds a makefile macro to check for supported warning flags and only adds them if the compiler actually supports them.
-rw-r--r--engine.mk30
-rw-r--r--external/lib/libm/rules.mk5
-rw-r--r--make/macros.mk14
3 files changed, 36 insertions, 13 deletions
diff --git a/engine.mk b/engine.mk
index 35f7c296..51451e5f 100644
--- a/engine.mk
+++ b/engine.mk
@@ -64,7 +64,7 @@ GLOBAL_INCLUDES := $(BUILDDIR) $(addsuffix /include,$(LKINC))
GLOBAL_OPTFLAGS ?= $(ARCH_OPTFLAGS)
GLOBAL_COMPILEFLAGS := -g -include $(CONFIGHEADER)
GLOBAL_COMPILEFLAGS += -Wextra -Wall -Werror=return-type -Wshadow -Wdouble-promotion
-GLOBAL_COMPILEFLAGS += -Wno-multichar -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wno-nonnull-compare
+GLOBAL_COMPILEFLAGS += -Wno-multichar -Wno-unused-parameter -Wno-unused-function -Wno-unused-label
GLOBAL_COMPILEFLAGS += -fno-common
GLOBAL_CFLAGS := --std=gnu11 -Werror-implicit-function-declaration -Wstrict-prototypes -Wwrite-strings
GLOBAL_CPPFLAGS := --std=c++14 -fno-exceptions -fno-rtti -fno-threadsafe-statics
@@ -181,6 +181,23 @@ ifndef TOOLCHAIN_PREFIX
$(error TOOLCHAIN_PREFIX not set in the arch rules.mk)
endif
+# default to no ccache
+CCACHE ?=
+CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
+LD := $(TOOLCHAIN_PREFIX)ld
+OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
+OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
+CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
+SIZE := $(TOOLCHAIN_PREFIX)size
+NM := $(TOOLCHAIN_PREFIX)nm
+STRIP := $(TOOLCHAIN_PREFIX)strip
+
+# Now that CC is defined we can check if warning flags are supported and add
+# them to GLOBAL_COMPILEFLAGS if they are.
+ifeq ($(call is_warning_flag_supported,-Wnonnull-compare),yes)
+GLOBAL_COMPILEFLAGS += -Wno-nonnull-compare
+endif
+
$(info PROJECT = $(PROJECT))
$(info PLATFORM = $(PLATFORM))
$(info TARGET = $(TARGET))
@@ -230,17 +247,6 @@ ifneq ($(DEFINES),)
$(error DEFINES variable set, please move to GLOBAL_DEFINES: $(DEFINES))
endif
-# default to no ccache
-CCACHE ?=
-CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
-LD := $(TOOLCHAIN_PREFIX)ld
-OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
-OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
-CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
-SIZE := $(TOOLCHAIN_PREFIX)size
-NM := $(TOOLCHAIN_PREFIX)nm
-STRIP := $(TOOLCHAIN_PREFIX)strip
-
# try to have the compiler output colorized error messages if available
export GCC_COLORS ?= 1
diff --git a/external/lib/libm/rules.mk b/external/lib/libm/rules.mk
index ca93ce00..0ee81f5a 100644
--- a/external/lib/libm/rules.mk
+++ b/external/lib/libm/rules.mk
@@ -2,7 +2,10 @@ LOCAL_DIR := $(GET_LOCAL_DIR)
MODULE := $(LOCAL_DIR)
-MODULE_CFLAGS += -Wno-unused-variable -Wno-sign-compare -Wno-parentheses -Wno-double-promotion -Wno-maybe-uninitialized
+MODULE_CFLAGS += -Wno-unused-variable -Wno-sign-compare -Wno-parentheses -Wno-double-promotion
+ifeq ($(call is_warning_flag_supported,-Wmaybe-uninitialized),yes)
+MODULE_CFLAGS += -Wno-maybe-uninitialized
+endif
MODULE_OPTIONS := float
MODULE_SRCS += \
diff --git a/make/macros.mk b/make/macros.mk
index 39ed24a3..62232d9c 100644
--- a/make/macros.mk
+++ b/make/macros.mk
@@ -58,3 +58,17 @@ define MAKECONFIGHEADER
echo $3 >> $1.tmp; \
$(call TESTANDREPLACEFILE,$1.tmp,$1)
endef
+
+check_compiler_flag = $(shell $(CC) -c -xc /dev/null -o /dev/null $(1) 2>/dev/null && echo yes || echo no)
+# Due to GCC's behaviour with regard to unknown warning flags this macro can
+# only be used to detect warning-enable options (-Wfoo) but not for warning
+# disable flags such as -Wno-foo.
+# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#:~:text=When%20an%20unrecognized%20warning%20option%20is%20requested
+is_warning_flag_supported = $(strip \
+ $(if $(findstring -Wno-,$(1)),$(error "Cannot use -Wno- flags here: $(1)"),) \
+ $(if $(CC),,$(error "CC is not set, this macro cannot be used yet!")) \
+ $(if $($(call MAKECVAR,$(1))), \
+ $(info Using cached result for $(1): $($(call MAKECVAR,$(1)))), \
+ $(eval $(call MAKECVAR,$(1)) := $(call check_compiler_flag,-Werror -fsyntax-only $(1))) \
+ $(info Checking if $(1) is supported: $($(call MAKECVAR,$(1)))) \
+ )$($(call MAKECVAR,$(1))))