#!/bin/sh
set -u
#######################################################################
#                  zdbiing.ins                                        #
#######################################################################
ingres_manifests()
{
#############################################
# Sun4 Ingres Manifest listing
#############################################
sun4_ing=" ${DBI_SASPATH}/obj/viventry.o \
    ${DBI_SASPATH}/obj/vivc.o \
    ${DBI_SASPATH}/obj/MCN_sasing.o \
    ${DBI_SASPATH}/obj/PCN_sasing.o \
    ${DBI_SASPATH}/obj/ingsql.o \
    ${DBI_SASPATH}/obj/ingtbl.o \
    ${DBI_SASPATH}/obj/vipkludg.o  \
    ${DBI_SASPATH}/olb/wxfer.a \
    ${dbmshome}/ingres/lib/libingres.a  \
    ${DBI_SASPATH}/olb/xvxfer.a "

sun4_ing_b4="ld -o  ${DBI_DEST_DIR}/sasexe/dbi/sasing -r -p -d -dc -X "
sun4_ing_af="-lm /usr/lib/libc.a"

#############################################
# Sol2 Ingres Manifest listing
#############################################
sol2_ing=" ${DBI_SASPATH}/obj/MCN_sasing.o \
    ${DBI_SASPATH}/obj/PCN_sasing.o \
    ${DBI_SASPATH}/obj/ingsql.o \
    ${DBI_SASPATH}/obj/ingtbl.o \
    ${DBI_SASPATH}/obj/vipkludg.o  \
    ${DBI_SASPATH}/olb/wxfer.a \
    ${dbmshome}/ingres/lib/libingres.a  \
    ${DBI_SASPATH}/olb/vxfer.a "

sol2_ing_b4="ld -o  ${DBI_DEST_DIR}/sasexe/dbi/sasing -B static -r -dn"
sol2_ing_af="-lm -lnsl -lsocket -lintl"

#############################################
# Sol2 Ingres Manifest listing (pic)
#############################################
sol2_pic_ing=" ${DBI_SASPATH}/obj/pic_MCN_sasing.o \
    ${DBI_SASPATH}/obj/pic_PCN_sasing.o \
    ${DBI_SASPATH}/obj/ingsql.o \
    ${DBI_SASPATH}/obj/pic_ingtbl.o \
    ${DBI_SASPATH}/obj/vipkludg.o  \
    ${DBI_SASPATH}/olb/wxfer.a \
    ${dbmshome}/ingres/lib/libingres.a  \
    ${DBI_SASPATH}/olb/vxfer.a "

sol2_pic_ing_b4="ld -o  ${DBI_DEST_DIR}/sasexe/dbi/sasing -G -B symbolic -z text -z defs"
sol2_pic_ing_af="-lsocket -lnsl -lm -lintl -lelf -lc"

#############################################
# HP Ingres Manifest listing
#############################################
hp_ing=" ${DBI_SASPATH}/obj/crt.o         \
    ${DBI_SASPATH}/obj/vipkludg.o         \
    ${DBI_SASPATH}/obj/dyncall.o          \
    ${DBI_SASPATH}/obj/MCN_sasing.o       \
    ${DBI_SASPATH}/obj/PCN_sasing.o       \
    ${DBI_SASPATH}/obj/ingsql.o           \
    ${DBI_SASPATH}/obj/ingtbl.o           \
    ${DBI_SASPATH}/olb/wxfer.a            \
    ${dbmshome}/ingres/lib/libingres.a \
    ${DBI_SASPATH}/olb/vxfer.a "

hp_ing_b4="ld -o ${DBI_DEST_DIR}/sasexe/dbi/sasing -e mcn_main "
hp_ing_af=" -R80000 -HF -N -a archive -lm -lc"

#############################################
# AIX Ingres Manifest listing
#############################################
aix_ing=" ${DBI_SASPATH}/obj/MCN_sasing.o \
    ${DBI_SASPATH}/obj/PCN_sasing.o       \
    ${DBI_SASPATH}/obj/ingsql.o           \
    ${DBI_SASPATH}/obj/ingtbl.o           \
    ${DBI_SASPATH}/obj/vzlmmiss.o         \
    ${DBI_SASPATH}/obj/vipkludg.o         \
    ${DBI_SASPATH}/olb/wxfer.a            \
    ${dbmshome}/ingres/lib/libingres.a \
    ${dbmshome}/ingres/lib/libsd.a     \
    ${DBI_SASPATH}/olb/vxfer.a            \
    ${DBI_SASPATH}/olb/vxfer.a            \
    ${DBI_SASPATH}/olb/ptrgl.a            \
    ${DBI_SASPATH}/olb/wxfer.a "

aix_ing_b4="ld -H512  \
   -T512 -b import:/lib/syscalls.exp -b glink:/lib/glink.o \
   -b noloadmap  \
   -b h:4 -o ${DBI_DEST_DIR}/sasexe/dbi/sasing                  \
   -e mcn_main -lbsd"

aix_ing_af=" -lm -lc "

#############################################
# OSF/1 Ingres Manifest listing
#############################################
alx_ing=" ${DBI_SASPATH}/obj/MCN_sasing.o \
    ${DBI_SASPATH}/obj/PCN_sasing.o       \
    ${DBI_SASPATH}/obj/ingsql.o           \
    ${DBI_SASPATH}/obj/ingtbl.o           \
    ${DBI_SASPATH}/obj/vipkludg.o         \
    ${dbmshome}/ingres/lib/libingres.a    \
    ${DBI_SASPATH}/olb/wxfer.a            \
    ${DBI_SASPATH}/olb/vxfer.a "

alx_ing_b4="ld -o ${DBI_DEST_DIR}/sasexe/dbi/sasing -hidden -shared \
        -exported_symbol mcn_main \
        "
alx_ing_af="   -ldnet_stub -lc  -e mcn_main  "



}

########################################################################
# ingres_inst()                                                        #
#  DBI_OSNAME                                                          #
#  DBI_LEVEL                                                           #
#  DBI_SASPATH                                                         #
#  DBI_LOGFILE                                                         #
#  dbname,dbmshome,proceed,manifest,link_b4,link_af                     #
########################################################################
#printenv|grep DBI
dbname=INGRES

# get the menu name
ing_menu=${DBI_OSNAME}Ingres${DBI_LEVEL}

case $DBI_OSNAME in
   HPUX)  ;;
   SUN4)  ;;
   SOL2)  ;;
   AIXR)  ;;
   AOSF)  ;;
#   ULXR)  ;;
#   CNVX)  ;;
#   DGUX)  ;;
#   MABI)  ;;
#   IABI)  ;;
      *) echo "SAS/ACCESS Interface to $dbname not supported for $DBI_OSNAME"
         exit
         ;;
esac

# get the Ingres version number
ing_version=`fmenu  $ing_menu`
if [ $ing_version = 0 ]; then
   exit
fi


dbmshome=${II_SYSTEM-}
assign dbmshome_default "$dbmshome"
assign dbmshome_assigned false
dbmshome=`resolve var dbmshome`

echo ' '
echo "SAS/ACCESS Interface to INGRES for $DBI_OSNAME_LONG  "|tee -a $DBI_LOGFILE
echo "The values you selected:           "|tee -a $DBI_LOGFILE
echo "------------------------           "|tee -a $DBI_LOGFILE
case $ing_version in
   64) echo "Ingres Version:         Release 6.4/03 or later "|tee -a $DBI_LOGFILE
          ;;
   1104) echo "Ingres Version:       CA-OpenIngres Release 1.1/04"|tee -a $DBI_LOGFILE
         ;;
   1200) echo "Ingres Version:       CA-OpenIngres Release 1.2/00"|tee -a $DBI_LOGFILE
         ;;
      *) echo "Ingres Version:         $ing_version"|tee -a $DBI_LOGFILE
         ;;
esac


echo "INGRES root Directory : $dbmshome            "|tee -a $DBI_LOGFILE

proceed=`ask_oneof "Continue? [Y/N]" Y N y n -d Y`
if [ "$proceed" = "N" -o "$proceed" = "n" ]; then
   echo ' '
   echo 'You selected No. Backing up to the Database Selection menu.'|tee -a $DBI_LOGFILE
   exit
fi

# set II_SYSTEM to $dbmshome
II_SYSTEM="$dbmshome"; export II_SYSTEM

ingres_manifests
case $DBI_OSNAME in
   SUN4) manifest=${sun4_ing}
         link_b4=${sun4_ing_b4}
         link_af=${sun4_ing_af}
         ;;

   SOL2) manifest=${sol2_ing}
         link_b4=${sol2_ing_b4}
         link_af=${sol2_ing_af}
         ;;

   HPUX) manifest=${hp_ing}
         link_b4=${hp_ing_b4}
         link_af=${hp_ing_af}
         ;;

   AIXR) manifest=${aix_ing}
         link_b4=${aix_ing_b4}
         link_af=${aix_ing_af}
         ;;
   AOSF) manifest=${alx_ing}
         link_b4=${alx_ing_b4}
         link_af=${alx_ing_af}
         ;;
   ULXR) ;;
   CNVX) ;;
   DGUX) ;;
   MABI) ;;
   IABI) ;;

      *)
       echo "SAS/ACCESS Interface to $dbname not supported for $DBI_OSNAME"
       exit
       ;;

esac

# Copy the object corresponding the version selected
# Since all platforms have the same object files, this done
# independent of the platform
case $ing_version in
"64")
   cp ${DBI_SASPATH}/obj/insql64.o ${DBI_SASPATH}/obj/ingsql.o
   status=$?
   ;;
"1104")
   cp ${DBI_SASPATH}/obj/insql11.o ${DBI_SASPATH}/obj/ingsql.o
   status=$?
   ;;
"1200")
   cp ${DBI_SASPATH}/obj/insql12.o ${DBI_SASPATH}/obj/ingsql.o 
   status=$?
   ;;
"1201")
   cp ${DBI_SASPATH}/obj/pic_insql12.o ${DBI_SASPATH}/obj/ingsql.o
   manifest=${sol2_pic_ing}
   link_b4=${sol2_pic_ing_b4}
   link_af=${sol2_pic_ing_af}
   status=$?
   ;;
 *)
   echo "Unknown Ingres version $ing_version under $DBI_OSNAME"
   exit
   ;;
esac


zdbilink.ins  "$dbname"  "$manifest"   "$link_b4"  "$link_af"


