[PATCH v2] Kbuild: compatibility with make-4.1

12 views
Skip to first unread message

S. Lockwood-Childs

unread,
Nov 26, 2015, 4:09:09 PM11/26/15
to swup...@googlegroups.com
make 4.1 parses MAKEFLAGS later than in make 3.x, which breaks
'?=' assignment on variables with builtin assignments when
MAKEFLAGS adds -R flag

https://savannah.gnu.org/bugs/?45211

Since apparently make does not guarantee results with '-R' flag
unless it is supplied on the command line (rather than later
injected by manipulating MAKEFLAGS), it is safer to stop trying
to inject '-R' and instead deal with possible builtin values.

New custom macro 'set_if_default_or_unset' consistently achieves
the intended behavior for both 3.x and 4.x versions of make:

* if variable is unset,
assign new value
* if variable has builtin default value,
assign new value
* otherwise variable has user-set value (env or command-line),
so leave it alone

Signed-off-by: S. Lockwood-Childs <s...@vctlabs.com>
---
Makefile | 25 ++++++++++++++-----------
scripts/Kbuild.include | 4 ++++
2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 6cf6b7d..4b5a916 100644
--- a/Makefile
+++ b/Makefile
@@ -11,10 +11,10 @@ NAME =
# expect to learn how to build the kernel reading this file.

# Do not:
-# o use make's built-in rules and variables
+# o use make's built-in rules
# (this increases performance and avoids hard-to-debug behaviour);
# o print "Entering directory ...";
-MAKEFLAGS += -rR --no-print-directory
+MAKEFLAGS += -r --no-print-directory


# To put more focus on warnings, be less verbose as default
@@ -169,15 +169,18 @@ include $(srctree)/scripts/Kbuild.include

# Make variables (CC, etc...)

-AS ?= $(CROSS_COMPILE)as
-LD ?= $(CROSS_COMPILE)gcc
-CC ?= $(CROSS_COMPILE)gcc
-CPP ?= $(CC) -E
-AR ?= $(CROSS_COMPILE)ar
-NM ?= $(CROSS_COMPILE)nm
-STRIP ?= $(CROSS_COMPILE)strip
-OBJCOPY ?= $(CROSS_COMPILE)objcopy
-OBJDUMP ?= $(CROSS_COMPILE)objdump
+# this looks a bit horrible, but 'VAR ?= VALUE' preserves builtin values
+# rather than only user-supplied values from env or command-line
+$(call set_if_default_or_unset,AS,$(CROSS_COMPILE)as)
+$(call set_if_default_or_unset,LD,$(CROSS_COMPILE)gcc)
+$(call set_if_default_or_unset,CC,$(CROSS_COMPILE)gcc)
+$(call set_if_default_or_unset,CPP,$(CC) -E)
+$(call set_if_default_or_unset,AR,$(CROSS_COMPILE)ar)
+$(call set_if_default_or_unset,NM,$(CROSS_COMPILE)nm)
+$(call set_if_default_or_unset,STRIP,$(CROSS_COMPILE)strip)
+$(call set_if_default_or_unset,OBJCOPY,$(CROSS_COMPILE)objcopy)
+$(call set_if_default_or_unset,OBJDUMP,$(CROSS_COMPILE)objdump)
+
AWK = awk
INSTALLKERNEL := installkernel
PERL = perl
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index be39cd1..b635171 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -233,6 +233,10 @@ if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \
@set -e; \
$(rule_$(1)))

+# Usage: $(call set_if_default_or_unset,var,value)
+set_if_default_or_unset = $(if $(filter default undefined,$(origin $(1))), \
+ $(eval $(1) = $(2)) )
+
###
# why - tell why a a target got build
# enabled by make V=2
--
2.4.6

Stefano Babic

unread,
Nov 29, 2015, 4:03:23 PM11/29/15
to S. Lockwood-Childs, swup...@googlegroups.com
Applied, thanks !

Best regards,
Stefano Babic


--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================

Jörg Krause

unread,
Mar 9, 2016, 4:57:17 PM3/9/16
to swupdate, s...@dent.vctlabs.com, sba...@denx.de
Hi,

Unfortunatly, this breaks building swupdate in Buildroot, which sets CONFIG_CROSS_COMPILE. The problem is that the value passed to eval is expanded twice; first by the eval function, then the results of that expansion are expanded again when they are parsed as makefile syntax [1]. Variables that should to be expanded after evaluation must be escaped. I'll prepare a patch to fix this issue.
Reply all
Reply to author
Forward
0 new messages