1# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13cur_makefile := $(lastword $(MAKEFILE_LIST)) 14 15$(cur_makefile): ; 16 17# ========================================================================== 18# 19# make W=... settings 20# 21# W=1 - warnings that may be relevant and does not occur too often 22# W=2 - warnings that occur quite often but may still be relevant 23# W=3 - the more obscure warnings, can most likely be ignored 24# 25# $(call cc-option, -W...) handles gcc -W.. options which 26# are not supported by all versions of the compiler 27# ========================================================================== 28 29ifeq ("$(origin W)","command line") 30 export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W) 31endif 32 33ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS 34warning- := $(empty) 35 36warning-1 := -Wextra -Wunused -Wno-unused-parameter 37warning-1 += -Wmissing-declarations 38warning-1 += -Wmissing-format-attribute 39warning-1 += -Wmissing-include-dirs 40warning-1 += -Wunused-but-set-variable 41warning-1 += -Wno-missing-field-initializers 42c_warning-1 := -Wmissing-prototypes -Wold-style-definition 43 44warning-2 := -Waggregate-return 45warning-2 += -Wcast-align 46warning-2 += -Wdisabled-optimization 47warning-2 += -Wshadow 48ifneq ($(TOOLCHAIN),armclang) 49warning-2 += $(call cc-options,-Wlogical-op) 50endif 51warning-2 += -Wmissing-field-initializers 52c_warning-2 := -Wnested-externs 53 54warning-3 := -Wcast-qual 55warning-3 += -Wconversion 56warning-3 += -Wpacked 57warning-3 += -Wpadded 58warning-3 += -Wpointer-arith 59warning-3 += -Wredundant-decls 60warning-3 += -Wswitch-default 61warning-3 += -Wpacked-bitfield-compat 62warning-3 += -Wvla 63c_warning-3 := -Wbad-function-cast 64 65warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 66warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 67warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 68 69c_warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 70c_warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 71c_warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 72 73ifeq ("$(strip $(warning) $(c_warning))","") 74 $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown) 75endif 76 77KBUILD_CFLAGS += $(warning) 78C_ONLY_FLAGS += $(c_warning) 79else 80 81ifeq ($(COMPILER),clang) 82KBUILD_CFLAGS += -Wno-initializer-overrides 83KBUILD_CFLAGS += -Wno-unused-value 84KBUILD_CFLAGS += -Wno-format 85KBUILD_CFLAGS += -Wno-unknown-warning-option 86KBUILD_CFLAGS += -Wno-sign-compare) 87KBUILD_CFLAGS += -Wno-format-zero-length 88KBUILD_CFLAGS += -Wno-uninitialized 89endif 90endif 91