#!/bin/ksh
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#


# ***********************************************
#* $Date:   17 Nov 2003 13:42:00  $ $Modtime:   17 Nov 2003 13:18:06  $
# ***********************************************

# ***********************************************
# $Workfile:   inst_rtsvsam  $ $Revision:   1.0  $
# ***********************************************

#
# This command should be used to generate the Sun MTP-MBM RUNB command.
#
if [ $# -ge 5 ]
then
  MACHINE=$1;export MACHINE
  EBM_MF_REL=$2;export EBM_MF_REL
  EBM_MF_INX=$3;export EBM_MF_INX
  RUNBDIR="$4";export RUNBDIR
  EBMRTSOBJECTS="$5";export EBMRTSOBJECTS
  DBLINKS="$6";export DBLINKS
  LINKLIBDIR="$7";export LINKLIBDIR   
fi


if [ -z "$EBMMFDATE" ]
then
  EBMMFDATE=" "; export EBMMFDATE
fi
#
# UNIKIXSRC must be set to the $UNIKIX/src directory of the Sun MTP product.
#
UNIKIXSRC="."
RTSVSAM_DIR="./RTSVSAM"

if [ "${EBM_MF_REL}+" = "+" ]
then
#
# UNIKIXSRC must be set to the $UNIKIX/src directory of the Sun MTP product.
#
UNIKIXSRC=".."
RTSVSAM_DIR="."
# Begin statements when not called via kixinstall {
#
# Declare variable for the Oracle archives and objects.
# Note that ORACLELIB must be set prior to executing this command.
#

# ORACLEOBJ="\
#       $ORACLELIB/cobol/lib/invstr.o \
#       $ORACLELIB/cobol/lib/osnttcmf.o \
#       $ORACLELIB/cobol/lib/ttcx2ymf.o \
#       $ORACLELIB/cobol/lib/cobsqlintf.o \
#       $ORACLELIB/rdbms/lib/libsql.a \
#       $ORACLELIB/rdbms/lib/osntab.o \
#       $ORACLELIB/rdbms/lib/libsqlnet.a \
#       $ORACLELIB/rdbms/lib/libora.a \
#       $ORACLELIB/rdbms/lib/libocic.a \
#       `cat $ORACLELIB/rdbms/lib/sysliblist` \
#       "
#or
#ORACLEOBJ="\
#        $ORACLELIB/cobol/lib/cobsqlintf.o \
#        $ORACLELIB/rdbms/lib/libsql.a \
#        $ORACLELIB/rdbms/lib/osntab.o \
#        $ORACLELIB/rdbms/lib/libsqlnet.a \
#        $ORACLELIB/rdbms/lib/libora.a \
#        $ORACLELIB/rdbms/lib/libocic.a \
#        "

#
# Declare variable for the Sybase archives and objects.
# Note that SYBASELIB must be set prior to executing this command.
#

#SYBASEOBJ="\
#       $SYBASELIB/libblk.a \
#       $SYBASELIB/libcobct.a \
#       $SYBASELIB/libcomn.a \
#       $SYBASELIB/libcs.a \
#       $SYBASELIB/libct.a \
#       $SYBASELIB/libintl.a \
#       $SYBASELIB/libsybdb.a \
#       $SYBASELIB/libtcl.a \
#       $SYBASELIB/libtli.a \
#	-lm \
#       "

#
# Declare variable for the Ingres archives and objects.
# Note that INGRESLIB must be set prior to executing this command.
#

#INGRESOBJ="\
#       $INGRESLIB/iimfdata.o \
#       $INGRESLIB/iimflibq.o \
#       $INGRESLIB/libingres.a \
#	-lc -lm \
#       "

#
# Declare variable for the Informix archives and objects.
# Note that INFORMIXLIB must be set prior to executing this command.
#

# INFORMIXOBJ="\
#       $INFORMIXLIB/esql/libecob_mf2.o \
#       $INFORMIXLIB/esql/iqcs0.o \
#       $INFORMIXLIB/netlib.a \
#       "

#
# Informix may need a set of link libraries
# Try:
#    -lnsl_s -lV3 -lm
#

#
# Declare the system modified modules plus user modules
# Note that these modules must be generated prior to execute this command.
#
#	$UNIKIXSRC/KXINFSRV.o \
#	$UNIKIXSRC/KXORACLE.o \
#	$UNIKIXSRC/KXSYBASE.o \
#


KXUSEROBJ="\
	$UNIKIXSRC/trans/kxusrexit.o \
	$UNIKIXSRC/convert/cvlwrupr.o \
	$UNIKIXSRC/convert/kxusrxlt.o \
	$UNIKIXSRC/convert/kxcvtxlt.o \
	$UNIKIXSRC/convert/kxcnvtbl.o \
	"
#
# Declare variable for external security archives
#
# Note that UNICENTER_HOME must be set prior to executing this installation 
# script, whenever CA-Unicenter has been selected to be installed
#
# Security default value : no external security
#

SECURITYOBJECTS=

#
#SECURITYOBJECTS="$UNIKIX/lib/libsecurityCA.a $UNICENTER_HOME/lib/libuni.a"
#
  echo "By default Sun MTP will handle both Relative and Indexed Files"
  echo "Do you access any Micro Focus Relative Files? <y/n>"
  read resp1
  case ${resp1-"n"} in
  y )
	EBM_MF_REL="y"
	;;
  n )
	EBM_MF_REL="n"
	;;
  * )
	echo "Invalid option, command aborted."
	exit 4
	;;
  esac

  echo "Do you access any Micro Focus Indexed Files? <y/n>"
  read resp2
  case ${resp2-"n"} in
  y )
	EBM_MF_INX="y"
	;;
  n )
	EBM_MF_INX="n"
	;;
  * )
	echo "Invalid option, command aborted."
	exit 5
	;;
  esac
# End statements when not called via kixinstall }
fi


if [ $EBM_MF_REL = "y" ]
then
	if [ $EBM_MF_INX = "y" ]
	then
		FILE=""
		EBMLSFILE="$RTSVSAM_DIR/ebmlsfile.o"
	else
		FILE="-m ixfile=kxvsam -m ixfilev=kxvsam"
		EBMLSFILE="$RTSVSAM_DIR/ebmlsfileNR.o"
	fi
else
	if [ $EBM_MF_INX = "y" ]
	then
		FILE="-m rlfile=kxvsam -m rlfilev=kxvsam"
		EBMLSFILE="$RTSVSAM_DIR/ebmlsfileNI.o"
	else
		FILE="-m ixfile=kxvsam -m ixfilev=kxvsam -m rlfile=kxvsam -m rlfilev=kxvsam"
		EBMLSFILE=$RTSVSAM_DIR/ebmlsfile.o
	fi
fi

COBOPTS=""

#
# RUNBDIR must point to the RUNB executable.
#
if [ ${RUNBDIR}a = "a" ]
then
	echo "RUNBDIR: ?"
	read risp
	RUNBDIR=`eval echo $risp`
fi
if [ ! -d $RUNBDIR ]
then
	echo RUNBDIR=$RUNBDIR invalid directory 
	exit 1
fi
if [ -f $RUNBDIR/RUNB ]
then
	echo RUNB=$RUNBDIR/RUNB already exists, removed
        rm -f $RUNBDIR/RUNB
fi

RTSVSAM=$RUNBDIR/rtsvsam_${EBM_MF_REL}${EBM_MF_INX}

set -x
rm -f $RTSVSAM

rm -f cobwrap.o $RTSVSAM_DIR/cobwrap.o
cob -xc $RTSVSAM_DIR/cobwrap.cbl
mv cobwrap.o $RTSVSAM_DIR/cobwrap.o
rm -f cobwrap.int cobwrap.idy

rm -f coberror.o $RTSVSAM_DIR/coberror.o
cob -xc $RTSVSAM_DIR/coberror.cbl
mv coberror.o $RTSVSAM_DIR/coberror.o
rm -f coberror.int coberror.idy

rm -f CCFextfh.o $RTSVSAM_DIR/CCFextfh.o
cob -xc $RTSVSAM_DIR/CCFextfh.cbl
mv CCFextfh.o $RTSVSAM_DIR/CCFextfh.o
rm -f CCFextfh.int CCFextfh.idy

rm -f CCFinit.o $RTSVSAM_DIR/CCFinit.o
cob -xc $RTSVSAM_DIR/CCFinit.cbl
mv CCFinit.o $RTSVSAM_DIR/CCFinit.o
rm -f CCFinit.int CCFinit.idy

cob -xD $COBOPTS $LINKLIBDIR -o $RTSVSAM $FILE    \
  $EBMMFDATE \
		$RTSVSAM_DIR/CPR.o $RTSVSAM_DIR/COB.o $RTSVSAM_DIR/CCFinit.o \
		$RTSVSAM_DIR/el_date.o  $RTSVSAM_DIR/lppfserv.o \
		$RTSVSAM_DIR/CCFextfh.o $RTSVSAM_DIR/cobwrap.o \
		$RTSVSAM_DIR/coberror.o \
		$RTSVSAM_DIR/kxpassrem.o $RTSVSAM_DIR/kxpassubs.o \
		$EBMLSFILE $RTSVSAM_DIR/kxcat.o \
		$RTSVSAM_DIR/runb.o \
		$KXUSEROBJ \
		$INGRESOBJ \
		$INFORMIXOBJ \
		$ORACLEOBJ  \
		$SYBASEOBJ  \
		$SECURITYOBJECTS \
		$EBMRTSOBJECTS \
		$DBLINKS

set +x
if [ ! -f $RTSVSAM ]
then
	echo fatal error creating the $RTSVSAM command
	exit 1
fi
chmod 755 $RTSVSAM
ln -s $RTSVSAM $RUNBDIR/RUNB
ln -s $RTSVSAM $RUNBDIR/rtsvsam
if [ ! -f $RUNBDIR/RUNB ]
then
	echo fatal error creating the $RUNBDIR/RUNB command
	exit 1
fi

exit 0
