From 09c7ae5cfa5b109ac7edc55ffd5b282afa9d692e Mon Sep 17 00:00:00 2001
From: Simon Rose <simon.rose@ess.eu>
Date: Tue, 28 Nov 2023 09:33:39 +0100
Subject: [PATCH] Keep separate list of targets to recurse over

---
 require-ess/tools/driver.makefile | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/require-ess/tools/driver.makefile b/require-ess/tools/driver.makefile
index 81651314..e66e4ebf 100644
--- a/require-ess/tools/driver.makefile
+++ b/require-ess/tools/driver.makefile
@@ -59,6 +59,11 @@ MAKEHOME:=$(dir $(lastword ${MAKEFILE_LIST}))
 # Get the name of the Makefile that included this file.
 USERMAKEFILE:=$(lastword $(filter-out $(lastword ${MAKEFILE_LIST}), ${MAKEFILE_LIST}))
 
+# These are the targets that we will pass through to the next stages of require's
+# recursive build process. For each of these targets we will perform all three
+# of the build runs listed above; for others (e.g. `make clean`) we only perform
+# a single pass.
+RECURSE_TARGETS = install build debug
 
 ##---## In E3, We only use one version of EPICS base when compiling modules.
 ##---## EPICS_LOCATION is (by default) /epics/base-${EPICSVERSION}
@@ -333,7 +338,7 @@ ${INSTALL_META}: ${COMMON_DIR}/${METAFILE}
 	@echo "Installing metadata file $@"
 	$(INSTALL) -d -m444 $< $(@D)
 
-install build debug::
+$(RECURSE_TARGETS)::
 	@echo "MAKING EPICS VERSION ${EPICSVERSION}"
 
 debug::
@@ -355,7 +360,7 @@ define target_rule
 $1-%: | $(COMMON_DIR)
 	$${MAKE} -f $${USERMAKEFILE} T_A=$$* $1
 endef
-$(foreach target,install build debug,$(eval $(call target_rule,$(target))))
+$(foreach target,$(RECURSE_TARGETS),$(eval $(call target_rule,$(target))))
 
 MODULES :=
 REQ :=
@@ -381,7 +386,7 @@ db_internal: $$(addprefix $(COMMON_DIR)/,$$(notdir $$(patsubst %.substitutions,%
 
 # This has to be after .SECONDEXPANSION since BUILD_ARCHS will be modified based on EXCLUDE_ARCHS
 # which is defined _after_ driver.makefile.
-$(foreach target,install build debug,$(eval $(target):: $$$$(foreach arch,$$$${BUILD_ARCHS},$(target)-$$$${arch})))
+$(foreach target,$(RECURSE_TARGETS),$(eval $(target):: $$$$(foreach arch,$$$${BUILD_ARCHS},$(target)-$$$${arch})))
 
 # Create and install the metadata file as the very last step
 build:: ${COMMON_DIR}/${METAFILE}
@@ -453,7 +458,7 @@ else
 install:: build
 	$(if $(wildcard ${MODULE_LOCATION}/lib/${T_A}),$(error ${MODULE_LOCATION}/lib/${T_A} already exists. If you really want to overwrite then uninstall first.))
 
-install build debug:: O.${EPICSVERSION}_${T_A}
+$(RECURSE_TARGETS):: O.${EPICSVERSION}_${T_A}
 	@${MAKE} -C O.${EPICSVERSION}_${T_A} -f ../${USERMAKEFILE} $@
 
 endif
-- 
GitLab