From dd5d5877e749ad123433af3dfd9a1dea1bdf9ca4 Mon Sep 17 00:00:00 2001
From: Simon Rose <simon.rose@ess.eu>
Date: Wed, 27 Jan 2021 14:48:49 +0100
Subject: [PATCH] Fixed patch_site to not display error text if there is no
 patch file

---
 configure/modules/CONFIG     |  1 +
 configure/modules/DEFINES_FT | 27 ++++++++++++++++++---------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/configure/modules/CONFIG b/configure/modules/CONFIG
index eb39ed9e..31571ac1 100644
--- a/configure/modules/CONFIG
+++ b/configure/modules/CONFIG
@@ -1,5 +1,6 @@
 # -*- mode: Makefile;-*-
 
+# Update the module version (for numeric versions) with a build number of 0 if none is specified
 E3_MODULE_VERSION:=$(E3_MODULE_VERSION)$(shell [[ "$(E3_MODULE_VERSION)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$$ ]] && echo +0)
 
 include $(EPICS_BASE)/configure/CONFIG_BASE_VERSION
diff --git a/configure/modules/DEFINES_FT b/configure/modules/DEFINES_FT
index e81b52d9..c3337cb4 100644
--- a/configure/modules/DEFINES_FT
+++ b/configure/modules/DEFINES_FT
@@ -16,19 +16,28 @@ git submodule update --remote --merge $@/
 endef
 
 define patch_site
-for i in $(shell ls $(TOP)/patch/Site/$(E3_MODULE_VERSION)-+([a-zA-Z])*.p0.patch); do\
-	printf "\nPatching %s with the file : %s\n" "$(E3_MODULE_SRC_PATH)" "$$i"; \
-	git apply --directory=$(E3_MODULE_SRC_PATH) --ignore-whitespace -p0 $$i;\
-done
+patches=$$(ls $(TOP)/patch/Site/$(E3_MODULE_VERSION)-*.p0.patch 2> /dev/null); \
+if [ -n "$$patches" ]; then \
+  for i in $$patches; do \
+    printf "\nPatching %s with the file : %s\n" "$(E3_MODULE_SRC_PATH)" "$$i"; \
+    git apply --directory=$(E3_MODULE_SRC_PATH) --ignore-whitespace -p0 $$i; \
+  done; \
+else \
+  echo ">>> No patches to apply" >&2; \
+fi
 endef
 
 
 define patch_revert_site
-for i in $(shell ls $(TOP)/patch/Site/$(E3_MODULE_VERSION)-+([a-zA-Z])*.p0.patch); do\
-	printf "\nReverting applied patch %s with the file : %s\n" "$(E3_MODULE_SRC_PATH)" "$$i"; \
-	git apply -R --directory=$(E3_MODULE_SRC_PATH) --ignore-whitespace -p0 $$i;\
-done
-
+patches=$$(ls $(TOP)/patch/Site/$(E3_MODULE_VERSION)-*.p0.patch 2> /dev/null); \
+if [ -n "$$patches" ]; then \
+  for i in $$patches; do\
+    printf "\nReverting applied patch %s with the file : %s\n" "$(E3_MODULE_SRC_PATH)" "$$i"; \
+    git apply -R --directory=$(E3_MODULE_SRC_PATH) --ignore-whitespace -p0 $$i;\
+  done \
+else \
+  echo ">>> No patches to revert" >&2; \
+fi
 endef
 
 
-- 
GitLab