From e0fe0bbe57b8d708a18756be5bc289bdaf78d2a8 Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Sun, 2 Aug 2020 00:00:49 +0900
Subject: [PATCH] kbuild: include scripts/Makefile.* only when relevant CONFIG
is enabled
References: bcs#1181862
Patch-mainline: v5.9-rc1
Git-commit: e0fe0bbe57b8d708a18756be5bc289bdaf78d2a8
Currently, the top Makefile includes all of scripts/Makefile.<feature>
even if the associated CONFIG option is disabled.
Do not include unneeded Makefiles in order to slightly optimize the
parse stage.
Include $(include-y), and ignore $(include-).
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Michal Suchanek <msuchanek@suse.de>
---
Makefile | 16 +++++++++-------
scripts/Makefile.kcov | 4 ----
scripts/Makefile.kcsan | 4 ----
scripts/Makefile.ubsan | 3 ---
4 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -715,9 +715,6 @@ endif
# Tell gcc to never replace conditional load with a non-conditional one
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
-include scripts/Makefile.kcov
-include scripts/Makefile.gcc-plugins
-
ifdef CONFIG_READABLE_ASM
# Disable optimizations that make assembler listings hard to read.
# reorder blocks reorders the control in the function
@@ -900,9 +897,14 @@ endif
# use the deterministic mode of AR if available
KBUILD_ARFLAGS := $(call ar-option,D)
-include scripts/Makefile.kasan
-include scripts/Makefile.extrawarn
-include scripts/Makefile.ubsan
+# include additional Makefiles when needed
+include-y := scripts/Makefile.extrawarn
+include-$(CONFIG_KASAN) += scripts/Makefile.kasan
+include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan
+include-$(CONFIG_KCOV) += scripts/Makefile.kcov
+include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
+
+include $(addprefix $(srctree)/, $(include-y))
# Add any arch overrides and user supplied CPPFLAGS, AFLAGS and CFLAGS as the
# last assignments
diff --git a/scripts/Makefile.kcov b/scripts/Makefile.kcov
index 52b113302443..67e8cfe3474b 100644
--- a/scripts/Makefile.kcov
+++ b/scripts/Makefile.kcov
@@ -1,10 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
-ifdef CONFIG_KCOV
-
kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc
kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp
kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) += -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
export CFLAGS_KCOV := $(kcov-flags-y)
-
-endif
diff --git a/scripts/Makefile.ubsan b/scripts/Makefile.ubsan
--- a/scripts/Makefile.ubsan
+++ b/scripts/Makefile.ubsan
@@ -1,5 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
-ifdef CONFIG_UBSAN
CFLAGS_UBSAN += $(call cc-option, -fsanitize=shift)
CFLAGS_UBSAN += $(call cc-option, -fsanitize=integer-divide-by-zero)
CFLAGS_UBSAN += $(call cc-option, -fsanitize=unreachable)
@@ -16,4 +15,3 @@ endif
# -fsanitize=* options makes GCC less smart than usual and
# increase number of 'maybe-uninitialized false-positives
CFLAGS_UBSAN += $(call cc-option, -Wno-maybe-uninitialized)
-endif
--
2.26.2