From 11ae3946cc8a7cf7ab0b384010c6aea9af6f6b38 Mon Sep 17 00:00:00 2001
From: Simon Rose <simon.rose@ess.eu>
Date: Thu, 24 Jun 2021 10:14:25 +0200
Subject: [PATCH] Added check that RULES_SITEMODS is loaded correctly

---
 configure/modules/RULES_CHECKS | 22 ++++++++++++++++++++++
 configure/modules/RULES_E3     | 30 ++++++++++--------------------
 2 files changed, 32 insertions(+), 20 deletions(-)
 create mode 100644 configure/modules/RULES_CHECKS

diff --git a/configure/modules/RULES_CHECKS b/configure/modules/RULES_CHECKS
new file mode 100644
index 00000000..b8992b7d
--- /dev/null
+++ b/configure/modules/RULES_CHECKS
@@ -0,0 +1,22 @@
+.PHONY: consistency_checks
+consistency_checks: module_name_check sitemods_check loc-check
+
+# Check that the module name satisfies a few conditions before we go on.
+module_name_check:
+ifneq ($(shell echo $(E3_MODULE_NAME) | grep -q '^[a-z_][a-z0-9_]*$$' ; echo $$?),0)
+	$(error E3_MODULE_NAME '$(E3_MODULE_NAME)' is not valid. It should consist only of lowercase letters, numbers, and underscores.)
+endif
+
+# Check that a module is including RULES_SITEMODS instead of RULES_SITEAPPS or manually including RULES_E3
+.PHONY: sitemods_check
+sitemods_check:
+ifeq ($(filter RULES_SITEMODS,$(notdir $(MAKEFILE_LIST))),)
+	$(error RULES_E3 should only be loaded from RULES_SITEMODS)
+endif
+
+# Check that e3 wrappers are using EPICS_MODULE_TAG to manage local source mode
+.PHONU: loc-check
+loc-check:
+ifneq (,$(findstring -loc,$(E3_MODULE_SRC_PATH)))
+	$(error DEPRECATED: Local source mode "-loc" has being deprecated. Please comment out the EPICS_MODULE_TAG to use local source mode.)
+endif
diff --git a/configure/modules/RULES_E3 b/configure/modules/RULES_E3
index 83ce7f33..d473c3dc 100644
--- a/configure/modules/RULES_E3
+++ b/configure/modules/RULES_E3
@@ -7,10 +7,10 @@
 
 default: help
 
-# # help is defined in 
+# # help is defined in
 # # https://gist.github.com/rcmachado/af3db315e31383502660
 help:
-	$(info --------------------------------------- ) 
+	$(info --------------------------------------- )
 	$(info Available targets)
 	$(info --------------------------------------- )
 	$(QUIET) awk '/^[a-zA-Z\-\_0-9]+:/ {            \
@@ -23,7 +23,7 @@ help:
 	    print  $$1 "\t" helpMsg;                    \
 	}                                               \
 	{ helpMsg = $$0 }'                              \
-	$(MAKEFILE_LIST) | column -ts: 
+	$(MAKEFILE_LIST) | column -ts:
 
 
 
@@ -63,7 +63,7 @@ db_internal: conf
 	$(QUIET) $(E3_MODULE_MAKE_CMDS) db_internal
 
 ## Clean, build, and install the current module
-rebuild: clean build install 
+rebuild: clean build install
 
 ## Deletes temporary build files
 clean: conf
@@ -73,34 +73,25 @@ clean: conf
 all: init patch rebuild
 
 # Copy $(E3_MODULE_MAKEFILE) into $(E3_MODULE_SRC_PATH)
-conf: module_name_check
+include $(REQUIRE_CONFIG)/RULES_CHECKS
+conf: consistency_checks
 	$(QUIET) install -p -m 644 $(TOP)/$(E3_MODULE_MAKEFILE)  $(E3_MODULE_SRC_PATH)/
 
-# We should check that the module name satisfies a few conditions before we go on.
-module_name_check:
-ifneq ($(shell echo $(E3_MODULE_NAME) | grep -q '^[a-z_][a-z0-9_]*$$' ; echo $$?),0)
-	$(error E3_MODULE_NAME '$(E3_MODULE_NAME)' is not valid. It should consist only of lowercase letters, numbers, and underscores.)
-endif
-
 .PHONY: init git-submodule-sync $(E3_MODULE_SRC_PATH)  checkout
 
 ifeq (,$(strip $(EPICS_MODULE_TAG)))
 E3_LOCAL_SOURCE:=1
 endif
-ifneq (,$(findstring -loc,$(E3_MODULE_SRC_PATH)))
-$(warning DEPRECATED: Local source mode "-loc" is being deprecated. Please comment out the EPICS_MODULE_TAG to use local source mode.)
-E3_LOCAL_SOURCE:=1
-endif
 
 ifeq ($(E3_LOCAL_SOURCE),1)
-init: 
+init:
 	$(QUIET) echo ">> You are in the local source mode."
 	$(QUIET) echo ">> Nothing happens."
 
 checkout:
 
 else
-## Syncs and checks out the tag $(EPICS_MODULE_TAG) for the submodule 
+## Syncs and checks out the tag $(EPICS_MODULE_TAG) for the submodule
 init: git-submodule-sync $(E3_MODULE_SRC_PATH)  checkout
 
 
@@ -108,13 +99,12 @@ git-submodule-sync:
 	$(QUIET) git submodule sync
 
 
-$(E3_MODULE_SRC_PATH): 
+$(E3_MODULE_SRC_PATH):
 	$(QUIET) $(git_update)
 
 
-checkout: 
+checkout:
 	cd $(E3_MODULE_SRC_PATH) && git checkout $(EPICS_MODULE_TAG)
 
 
 endif
-
-- 
GitLab