From c5912e7db37cc0a04696cf081410ec007f8f0be9 Mon Sep 17 00:00:00 2001 From: Markus Mayer Date: Tue, 28 Sep 2021 12:55:33 -0700 Subject: [PATCH] Makefile: set HOST*_NOCCACHE variables only if unset Set HOSTCC_NOCCACHE and HOSTCXX_NOCCACHE only if they are not set. This allows recursive calls to "make" to work as intended in the presence of ccache. Such recursive calls to "make" can for example happen if one calls "make legal-info" from within a post-build script, to integrate some results of the legal-info output into the root filesystem. Without guarding these variables, a recursive invocation of make would re-define HOSTCC_NOCCACHE := $(HOSTCC) and HOSTCXX_NOCCACHE := $(HOSTCXX) at a point in time when HOSTCC and HOSTCXX already point to ccache. It used to work by "accident" until ca6a2907c27c8171336643d1ab41bd5c34ee3794 ("make: support: use `command -v' instead of `which'"), due to how "which" was behaving when invoked with multiple arguments. After switching to "command -v", which behaves different with multiple arguments, this HOSTCC_NOCCACHE redefinition problem surfaced. Even though ca6a2907c27c8171336643d1ab41bd5c34ee3794 has since then been reverted for other reasons, it does make sense to guard the definition of HOSTCC_NOCCACHE and HOSTCXX_NOCCACHE to not rely on a side-effect of using "which". Signed-off-by: Markus Mayer Reviewed-by: Petr Vorel Signed-off-by: Thomas Petazzoni --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 1e0e0927ee..99a34c1600 100644 --- a/Makefile +++ b/Makefile @@ -286,12 +286,16 @@ ifndef HOSTCC HOSTCC := gcc HOSTCC := $(shell which $(HOSTCC) || type -p $(HOSTCC) || echo gcc) endif +ifndef HOSTCC_NOCCACHE HOSTCC_NOCCACHE := $(HOSTCC) +endif ifndef HOSTCXX HOSTCXX := g++ HOSTCXX := $(shell which $(HOSTCXX) || type -p $(HOSTCXX) || echo g++) endif +ifndef HOSTCXX_NOCCACHE HOSTCXX_NOCCACHE := $(HOSTCXX) +endif ifndef HOSTCPP HOSTCPP := cpp endif