[PATCH v2 2/4] kbuild: Add hostcc-option macro

From: Matthias Kaehlcke
Date: Tue Jun 13 2017 - 19:10:06 EST


hostcc-option is equivalent to cc-option, but uses the host compiler
and HOSTCFLAGS. Change HOSTCFLAGS to a simple expanded variable to
allow for HOSTCFLAGS += $(call hostcc-option, ...).

Suggested-by: Arnd Bergmann <arnd@xxxxxxxx>
Suggested-by: Masahiro Yamada <yamada.masahiro@xxxxxxxxxxxxx>
Signed-off-by: Matthias Kaehlcke <mka@xxxxxxxxxxxx>
---
Changes in v2:
- Patch added in v2

Makefile | 2 +-
scripts/Kbuild.include | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 83f6d9972cab..b234bba6d652 100644
--- a/Makefile
+++ b/Makefile
@@ -303,7 +303,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \

HOSTCC = gcc
HOSTCXX = g++
-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
+HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
HOSTCXXFLAGS = -O2

ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 6dd0d1a921d6..4965ed92fc1e 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -123,6 +123,10 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
cc-option = $(call cc-option-raw, $(CC), $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),\
$(1), $(2))

+# hostcc-option
+# Usage: HOSTCFLAGS += $(call hostcc-option, -fno-delete-null-pointer-checks,)
+hostcc-option = $(call cc-option-raw, $(HOSTCC), $(HOSTCFLAGS), $(1), $(2))
+
# cc-option-yn
# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
cc-option-yn = $(call try-run,\
--
2.13.1.518.g3df882009-goog