From a57b94ec7ca5d201b4d88d54dcc69a53b35ec7c0 Mon Sep 17 00:00:00 2001 From: Chris Kay <chris.kay@arm.com> Date: Tue, 6 Aug 2024 15:32:57 +0000 Subject: [PATCH] build: fix grouped targets on Make <= 4.2 Grouped targets are a feature introduced with GNU Make 4.3 which enable rules with multiple targets to communicate that all of the targets of that rule are built simultaneously, rather than independently. For example, without grouped targets the following rule may be executed twice: a.txt b.txt: touch a.txt b.txt # $ remake -j2 a.txt b.txt # touch a.txt b.txt # touch a.txt b.txt In this example, both `a.txt` and `b.txt` are touched twice, when the rule should only be executed once. Instead, this rule can use a grouped target: a.txt b.txt &: touch a.txt b.txt # $ remake -j2 a.txt b.txt # touch a.txt b.txt # remake: 'b.txt' is up to date. In this case, both `a.txt` and `b.txt` are created once only, as Make now knows that the recipe will create both files. Note that pattern rules with multiple targets always behave this way. Previously, we assumed that the grouped target feature was available, but on systems still packaging Make 4.2, most prominently Ubuntu 20.04, this is not the case. This change adds a check to ensure that we do not use grouped targets if they are unavailable. Change-Id: Ifd9da35421ae11468d7a25d3cbc76f6036921749 Signed-off-by: Chris Kay <chris.kay@arm.com> --- lib/romlib/Makefile | 2 +- make_helpers/utilities.mk | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/romlib/Makefile b/lib/romlib/Makefile index 3d2b85026..4cac75b29 100644 --- a/lib/romlib/Makefile +++ b/lib/romlib/Makefile @@ -73,7 +73,7 @@ $(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i | $$(@D)/ $(s)echo " PRE $@" $(q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $< -$(WRAPPER_SOURCES) &: $(BUILD_DIR)/jmptbl.i | $$(@D)/ +$(WRAPPER_SOURCES) $&: $(BUILD_DIR)/jmptbl.i | $$(@D)/ $(s)echo " WRP $<" $(q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $< diff --git a/make_helpers/utilities.mk b/make_helpers/utilities.mk index efa0ab90a..fcccd2406 100644 --- a/make_helpers/utilities.mk +++ b/make_helpers/utilities.mk @@ -21,6 +21,13 @@ directory-name = $(call decompat-path,$(dir $(call compat-path,$(1)))) escape-shell = '$(subst ','\'',$(1))' +# +# The grouped-target symbol. Grouped targets are not supported on versions of +# GNU Make <= 4.2, which was most recently packaged with Ubuntu 20.04. +# + +& := $(if $(filter grouped-target,$(.FEATURES)),&) + # # Upper-case a string value. #