From 7ccaf12eee4435845cdef7e542db22d5c6a95d41 Mon Sep 17 00:00:00 2001
From: Dirk Zimoch <dirk.zimoch@psi.ch>
Date: Tue, 22 May 2018 17:51:53 +0200
Subject: [PATCH] fixed problem when CONFIG_BASE_VERSION could not be found

---
 iocsh | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/iocsh b/iocsh
index 0e7f982f..4f469c04 100755
--- a/iocsh
+++ b/iocsh
@@ -139,12 +139,22 @@ then
 fi
 
 # Get actual EPICS revision
-eval $(awk -F '[ \t]*=[ \t]*' '
-    /^[ \t]*EPICS_VERSION[ \t]*=/ {v=$2}
-    /^[ \t]*EPICS_REVISION[ \t]*=/ {r=$2}
-    /^[ \t]*EPICS_MODIFICATION[ \t]*=/ {m=$2+0}
-    END {print "BASE="v"."r"."m";BASECODE="v*10000+r*100+m}
-' < $EPICS_BASE/configure/CONFIG_BASE_VERSION)
+if [ -f $EPICS_BASE/configure/CONFIG_BASE_VERSION ]
+then
+    eval $(awk -F '[ \t]*=[ \t]*' '
+        /^[ \t]*EPICS_VERSION[ \t]*=/ {v=$2}
+        /^[ \t]*EPICS_REVISION[ \t]*=/ {r=$2}
+        /^[ \t]*EPICS_MODIFICATION[ \t]*=/ {m=$2+0}
+        END {print "BASE="v"."r"."m";BASECODE="v*10000+r*100+m}
+    ' < $EPICS_BASE/configure/CONFIG_BASE_VERSION)
+elif [ -f $EPICS_BASE/lib/$EPICS_HOST_ARCH/libCom.so ]
+then
+    eval $(strings $EPICS_BASE/lib/$EPICS_HOST_ARCH/libCom.so | awk -F'[.R-]' '
+        /EPICS R[0-9]/ {print "BASE="$2"."$3"."$4";BASECODE="$2*10000+$3*100+$4 }')
+else
+    echo "Cannot guess EPICS base version." >&2
+    exit 1;
+fi
 
 # IOC name derives from hostname
 # (trailing possible '\r' under cygwin)
@@ -263,7 +273,7 @@ do
         exit 1
        ;;
     ( *.so )
-        if [ $BASECODE -ge 31412 ]
+        if [ "$BASECODE" -ge 31412 ]
         then
             echo "dlload \"$file\""
         else
@@ -299,7 +309,7 @@ do
                 echo "dbLoadDatabase '$file','$DBD','$subst'"
                 ;;
             ( * )
-                if [ $BASECODE -ge 31500 ]
+                if [ "$BASECODE" -ge 31500 ]
                 then
                     echo "iocshLoad '$file','$subst'"
                 else
@@ -341,7 +351,7 @@ else # old driver pool model
     REQUIRE_DBD=$INSTBASE/iocBoot/R$BASE/dbd/$REQUIRE.dbd
 fi
 
-if [ $BASECODE -ge 31412 ]
+if [ "$BASECODE" -ge 31412 ]
 then
     EXE=$EPICS_BASE/bin/$EPICS_HOST_ARCH/softIoc
     ARGS="-D $EPICS_BASE/dbd/softIoc.dbd"
-- 
GitLab