From 347a3219fe32a7e339fa34cb53b48ec9568486b3 Mon Sep 17 00:00:00 2001
From: Jeong Han Lee <jeonghan.lee@gmail.com>
Date: Tue, 3 Oct 2017 15:49:47 +0200
Subject: [PATCH] add the working require env

---
 .gitmodules                       |  4 ++
 Makefile                          | 87 ++++++++++++++++++++++---------
 README.md                         | 26 ++++++++-
 configure/CONFIG                  |  4 +-
 configure/driver_makefile_conf.m4 | 45 ++++++++++++++++
 configure/require_config          | 11 ----
 e3-env                            |  1 +
 require.Makefile                  |  4 ++
 8 files changed, 144 insertions(+), 38 deletions(-)
 create mode 100644 configure/driver_makefile_conf.m4
 delete mode 100644 configure/require_config
 create mode 160000 e3-env

diff --git a/.gitmodules b/.gitmodules
index d33a28e1..6031cf04 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -2,3 +2,7 @@
 	path = require
 	url = https://github.com/paulscherrerinstitute/require
 	ignore = all
+[submodule "e3-env"]
+	path = e3-env
+	url = https://github.com/icshwi/e3-env
+	ignore = all	
diff --git a/Makefile b/Makefile
index 4b8d6b11..91f8e99d 100644
--- a/Makefile
+++ b/Makefile
@@ -16,18 +16,37 @@
 #
 # Author  : Jeong Han Lee
 # email   : han.lee@esss.se
-# Date    : Tuesday, September 26 17:17:47 CEST 2017
+# Date    : Tuesday, October  3 14:57:53 CEST 2017
 # version : 0.0.1
 #
 
 
 TOP = $(CURDIR)
 
-
 include $(TOP)/configure/CONFIG
 
+E3_ENV_SRC=$(TOP)/e3-env/e3-env
+
+ifneq ($(wildcard $(E3_ENV_SRC)),)
+include $(E3_ENV_SRC)
+endif
+
+
 M_DIRS:=$(sort $(dir $(wildcard $(TOP)/*/.)))
 
+
+M_OPTIONS := -C $(EPICS_MODULE_SRC_PATH)
+M_OPTIONS += -f $(ESS_MODULE_MAKEFILE)
+M_OPTIONS += LIBVERSION="$(REQUIRE_VERSION)"
+M_OPTIONS += PROJECT="$(EPICS_MODULE_NAME)"
+M_OPTIONS += EPICS_MODULES="$(EPICS_MODULES)"
+M_OPTIONS += EPICS_LOCATION="$(EPICS_LOCATION)"
+M_OPTIONS += DEFAULT_EPICS_VERSIONS="$(DEFAULT_EPICS_VERSIONS)"
+
+unexport BUILDCLASSES
+
+
+
 # help is defined in 
 # https://gist.github.com/rcmachado/af3db315e31383502660
 help:
@@ -49,28 +68,37 @@ help:
 default: help
 
 #
-## Install  "Require" EPICS Module in order to use it
+## Install "Require" Module in order to use it
 install:
-	sudo -E bash -c 'make -C $(EPICS_MODULE_SRC_PATH) -f $(ESS_MODULE_MAKEFILE) LIBVERSION=$(LIBVERSION) PROJECT=$(EPICS_MODULE_NAME) install'
+	sudo -E bash -c 'make $(M_OPTIONS) install'
+	@sudo install -d -m 755  $(REQUIRE_TOOLS)
+	@sudo install -m 644 $(EPICS_MODULE_SRC_PATH)/App/tools/driver.makefile $(REQUIRE_TOOLS)/
+	@sudo install -m 755 $(EPICS_MODULE_SRC_PATH)/App/tools/*.tcl           $(REQUIRE_TOOLS)/
+	@sudo -E bash -c 'm4 -D_DEFAULT_EPICS_VERSIONS="$(DEFAULT_EPICS_VERSIONS)" -D_EPICS_MODULES="$(EPICS_MODULES)" -D_EPICS_LOCATION="$(EPICS_LOCATION)"  $(TOP)/configure/driver_makefile_conf.m4  > $(REQUIRE_TOOLS)/conf'
+	@sudo install -d -m 755 $(REQUIRE_BIN)
+	@sudo install -m 755 $(EPICS_MODULE_SRC_PATH)/iocsh $(REQUIRE_BIN)/
 
+#
+## Uninstall "Require" Module in order not to use it
+uninstall:
+	sudo -E bash -c 'make $(M_OPTIONS) uninstall'
 
 
-## Build     EPICS Module in order to use it with EEE
+## Build the EPICS Module
 build: conf
-	make -C $(EPICS_MODULE_SRC_PATH) -f $(ESS_MODULE_MAKEFILE) LIBVERSION=$(LIBVERSION) PROJECT=$(EPICS_MODULE_NAME)
+	make $(M_OPTIONS)
 
-## Clean     EPICS Module in terms of EEE Makefile (module.Makefile)
+## Clean the EPICS Module
 clean:
-	make -C $(EPICS_MODULE_SRC_PATH) -f $(ESS_MODULE_MAKEFILE) LIBVERSION=$(LIBVERSION) PROJECT=$(EPICS_MODULE_NAME) clean
+	make $(M_OPTIONS) clean
 
 
-## Distclean EPICS Module in terms of EEE Makefile (module.Makefile)
-distclean:
-	make -C $(EPICS_MODULE_SRC_PATH) -f $(ESS_MODULE_MAKEFILE) LIBVERSION=$(LIBVERSION) PROJECT=$(EPICS_MODULE_NAME) distclean
+## Initialize all environments
+init: e3-env mo-init
 
 
-## Get      EPICS Module, and change its $(EPICS_MODULE_TAG)
-init:
+## Get EPICS Module, and change its $(EPICS_MODULE_TAG)
+mo-init: 
 	@git submodule deinit -f $(EPICS_MODULE_NAME)/
 	git submodule deinit -f $(EPICS_MODULE_NAME)/	
 	git submodule init $(EPICS_MODULE_NAME)/
@@ -78,10 +106,9 @@ init:
 	cd $(EPICS_MODULE_NAME) && git checkout tags/$(EPICS_MODULE_TAG)
 
 
-## Print ENV variables
+## Print EPICS and ESS EPICS Environment variables
 env:
 	@echo ""
-	@echo "EPICS_BASE             : "$(EPICS_BASE)
 
 	@echo "EPICS_MODULE_NAME      : "$(EPICS_MODULE_NAME)
 	@echo "EPICS_MODULE_TAG       : "$(EPICS_MODULE_TAG)
@@ -91,10 +118,15 @@ env:
 	@echo "LIBVERSION             : "$(LIBVERSION)
 
 	@echo ""
-	@echo "EPICS_BASES_PATH       : "$(EPICS_BASES_PATH)
-	@echo "EPICS_MODULES_PATH     : "$(EPICS_MODULES_PATH)
-	@echo "EPICS_HOST_ARCH        : "$(EPICS_HOST_ARCH)
-	@echo "EPICS_ENV_PATH         : "$(EPICS_ENV_PATH)
+	@echo ">>>> ESS EPICS Environment <<<< "
+	@echo ""
+	@echo "EPICS_LOCATION         : "$(EPICS_LOCATION)
+	@echo "EPICS_MODULES          : "$(EPICS_MODULES)
+	@echo "DEFAULT_EPICS_VERSIONS : "$(DEFAULT_EPICS_VERSIONS)
+	@echo "REQUIRE_VERSION        : "$(REQUIRE_VERSION)
+	@echo "REQUIRE_PATH           : "$(REQUIRE_PATH)
+	@echo "REQUIRE_TOOLS          : "$(REQUIRE_TOOLS)
+	@echo "REQUIRE_BIN            : "$(REQUIRE_BIN)
 	@echo ""
 
 
@@ -103,11 +135,16 @@ dirs:
 	@echo $(M_DIRS) || true
 
 conf:
+	@install -m 644 $(TOP)/$(ESS_MODULE_MAKEFILE)  $(EPICS_MODULE_SRC_PATH)/
+
+#
+#
+e3-env:
+	@git submodule deinit -f $(E3_ENV)/
+	git submodule deinit -f $(E3_ENV)/	
+	git submodule init $(E3_ENV)/
+	git submodule update --init --remote --recursive $(E3_ENV)/.
+#	cd $(E3_ENV) && git checkout tags/$(E3_ENV_TAG)
 
-	@install -m 664 $(TOP)/configure/require_config $(EPICS_MODULE_SRC_PATH)/App/tools/config
-	@install -m 644 $(TOP)/$(ESS_MODULE_MAKEFILE)   $(EPICS_MODULE_SRC_PATH)/
-#	@sudo install -d -m 755 /ioc/tools/
-#	@sudo install -m 755 $(TOP)/App/tools/* /ioc/tools/*
-#	@sudo install -m 664 $(TOP)/configure/require_config  /ioc/tools/config
 
-.PHONY: install build clean distclean init env dirs conf
+.PHONY: install build clean distclean mo-init e3-env init env dirs conf
diff --git a/README.md b/README.md
index 0cee0d11..2c3c56d7 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,25 @@
-# e3-require
\ No newline at end of file
+# e3-require
+
+This is the pilot project in order to build the reliable and easy-to-understand approach for ESS EPICS environment. The golden rule is to keep any other EPICS base, and modules sources intact. Still, ESS EPICS environment needs more resource to maintain the additional work load, however, we don't need to maintain different and synced (not well maintain) almost same repositories for entire EPICS community resouces.
+
+
+## Dependency
+
+* e3-base
+* e3-env
+
+## Setup
+
+```
+make init
+make build
+make install
+```
+
+## Execute iocsh
+
+``
+cd e3-env
+. setE3env.bash
+iocsh
+```
diff --git a/configure/CONFIG b/configure/CONFIG
index 32b1e322..c0502e60 100644
--- a/configure/CONFIG
+++ b/configure/CONFIG
@@ -39,7 +39,7 @@ export PROJECT:=$(EPICS_MODULE_NAME)
 # as the epics module version, and it will be used in the iocsh script 
 # with the require commands, for example
 # require $(PROJECT),$(LIBVERSION)
-export LIBVERSION:=2.5.3
+# export LIBVERSION:=2.5.3
 
 
 # It may be the sole reason why we have so many troubles related with
@@ -49,3 +49,5 @@ export LIBVERSION:=2.5.3
 
 
 
+E3_ENV:=e3-env
+E3_ENV_TAG:=master
diff --git a/configure/driver_makefile_conf.m4 b/configure/driver_makefile_conf.m4
new file mode 100644
index 00000000..6f22c648
--- /dev/null
+++ b/configure/driver_makefile_conf.m4
@@ -0,0 +1,45 @@
+dnl   Global ESS EPICS configration for driver.makefile
+dnl   per $(REQUIRE)/$(REQIRE_VERSION)
+dnl   
+dnl   It is installed via make install
+dnl
+dnl   conf file is loaded in driver.makefile
+dnl   to override the default environment in driver.makefile 
+
+dnl $  m4  config_site.m4
+dnl    CROSS_COMPILER_TARGET_ARCHS = 
+
+dnl    CROSS_COMPILER_HOST_ARCHS = 
+dnl    CROSS_COMPILER_RUNTEST_ARCHS = 
+dnl    SHARED_LIBRARIES = YES
+dnl    STATIC_BUILD = NO
+dnl    HOST_OPT = YES
+dnl    CROSS_OPT = YES
+dnl    HOST_WARN = YES
+dnl    CROSS_WARN = YES
+dnl    #INSTALL_LOCATIOIN = 
+dnl    USE_POSIX_THREAD_PRIORITY_SCHEDULING = YES
+dnl    EPICS_SITE_VERSION =
+dnl    GCC_PIPE = NO
+dnl    LINKER_USE_RPATH = YES
+
+dnl   Set the cross compiler target archs
+dnl   $ m4  -D_CROSS_COMPILER_TARGET_ARCHS=linux-ppc64e6500 config_site.m4
+dnl     CROSS_COMPILER_TARGET_ARCHS = linux-ppc64e6500
+dnl
+dnl
+ifdef(`_DEFAULT_EPICS_VERSIONS',
+	`DEFAULT_EPICS_VERSIONS = _DEFAULT_EPICS_VERSIONS',
+	`DEFAULT_EPICS_VERSIONS = ')
+	
+ifdef(`_BUILDCLASSES',
+	`BUILDCLASSES = _BUILDCLASSES',
+	`BUILDCLASSES = ')
+	
+ifdef(`_EPICS_MODULES',
+	`EPICS_MODULES = _EPICS_MODULES',
+	`EPICS_MODULES = ')
+
+ifdef(`_EPICS_LOCATION',
+	`EPICS_LOCATION = _EPICS_LOCATION',
+	`EPICS_LOCATION =')
diff --git a/configure/require_config b/configure/require_config
deleted file mode 100644
index 45f74d22..00000000
--- a/configure/require_config
+++ /dev/null
@@ -1,11 +0,0 @@
-# PROJECT and LIBVERSION should be defined in the makefile arguments
-# * this conf file should be in require/App/tools in order to override the default envs for driver.makefile
-# * selected EPICS VERSIONS should be defined
-# * each BASE should has startup dir and  EpicsHostArch.pl
-# * EPICS_MODULES is the target location of the epics modules (dynamically updated)
-# * EPICS_LOCATION is the target location of the epics bases  (dynamically updated)
-DEFAULT_EPICS_VERSIONS = 3.15.4 3.15.5
-BUILDCLASSES = 
-EPICS_MODULES = /eee/modules
-MODULE_LOCATION = ${EPICS_MODULES}/$(or ${PRJ},$(error PRJ not defined))/$(or ${LIBVERSION},$(error LIBVERSION not defined))
-EPICS_LOCATION = /eee/bases
diff --git a/e3-env b/e3-env
new file mode 160000
index 00000000..eafc0d8b
--- /dev/null
+++ b/e3-env
@@ -0,0 +1 @@
+Subproject commit eafc0d8b83e82b2be6d9531482e72a174ee947ac
diff --git a/require.Makefile b/require.Makefile
index 097cc120..c5ef927e 100644
--- a/require.Makefile
+++ b/require.Makefile
@@ -1,4 +1,8 @@
 
+# This is the one time path in order to compile and install
+# require within EPICS Environment. After the installation
+# include $(REQUIRE_TOOLS)/driver.makefile should be used
+#
 where_am_I := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
 
 include ${where_am_I}/App/tools/driver.makefile
-- 
GitLab