diff mbox series

[BOOT-WRAPPER,1/3] Makefile: rework test-dtc-option

Message ID 20240729143116.1804615-2-mark.rutland@arm.com (mailing list archive)
State New, archived
Headers show
Series Allow use of bare-metal toolchains | expand

Commit Message

Mark Rutland July 29, 2024, 2:31 p.m. UTC
Currently we have the test-dtc-option helepr to check whether dtc
supports an option. In subsequent patches we'll want similar for ld, and
it seems likely that we'll want this for other commands in future.

This patch adds a new test-cmd helper that can be used to check whether
a command succeeds (based on its return value), and can be used to
choose between a value if the comand succeeds and a value if the command
fails.

The existing test-dtc-option helper is reworked to use test-cmd. The
helpers are added near the start of the file so that they'll be defined
prior to usage whetever they're used within the file. This is purely for
human comprehension as Make itself does not care about their location
within the Makefile.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Andre Przywara <andre.przywara@arm.com>
Cc: Akos Denke <akos.denke@arm.com>
Cc: Luca Fancellu <luca.fancellu@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
---
 Makefile.am | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/Makefile.am b/Makefile.am
index 6ebece2..6ab5cfd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,6 +9,16 @@ 
 
 SCRIPT_DIR	:= $(top_srcdir)/scripts
 
+# test-cmd cmd,val-if-success,val-if-success,val-if-failure
+define test-cmd
+$(if $(shell { $(1); } >/dev/null 2>&1 && echo "success"),$(2),$(3))
+endef
+
+# Run dtc with an given command line option to check support for it.
+define test-dtc-option
+$(call test-cmd,echo "/dts-v1/;/{};" | $(DTC) $(1) -o /dev/null,$(1),)
+endef
+
 # VE
 PHYS_OFFSET	:= $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findmem.pl $(KERNEL_DTB))
 UART_BASE	:= $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,pl011')
@@ -162,11 +172,6 @@  $(COMMON_SRC):
 model.lds: $(LD_SCRIPT) Makefile
 	$(CPP) $(CPPFLAGS) -ansi -DPHYS_OFFSET=$(PHYS_OFFSET) -DMBOX_OFFSET=$(MBOX_OFFSET) -DKERNEL_OFFSET=$(KERNEL_OFFSET) -DFDT_OFFSET=$(FDT_OFFSET) -DFS_OFFSET=$(FS_OFFSET) $(XEN) -DXEN_OFFSET=$(XEN_OFFSET) -DKERNEL=$(KERNEL_IMAGE) -DFILESYSTEM=$(FILESYSTEM) -DTEXT_LIMIT=$(TEXT_LIMIT) -P -C -o $@ $<
 
-# Run dtc with an given command line option to check support for it.
-define test-dtc-option
-$(if $(shell echo "/dts-v1/;/{};" | $(DTC) $(1) -o /dev/null 2>&1),,$(1))
-endef
-
 DTC_NOWARN  = $(call test-dtc-option,-Wno-clocks_property)
 DTC_NOWARN += $(call test-dtc-option,-Wno-gpios_property)