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

#----------- if no /tmp/config.current create it ----------------------
if test -f /tmp/config.current;
then
   X=Y
else
   touch /tmp/config.current
fi
$KIXCLS
echo "                Target Directory for the Executables       $DATEVAR"
echo " "
echo " "
echo " "
echo " "
echo " "
echo "    The Default Target Directory for the Executables is \$UNIKIX/local/bin:"
echo " "
echo " > $UNIKIX/local/bin <"
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo "--------------------------------------------------------------------------------"
echo "Press Return to select the Default \$UNIKIX/local/bin Directory"
echo "      or "
echo "Enter a directory pathname to specify a different Target Directory"
read BINDIR
BINTARGET=`echo $BINDIR`+
if [ $BINTARGET = + ]
then
  BINDIR='${UNIKIX}/local/bin'
else
  BINDIR=`eval echo $BINDIR`
fi
echo "" >> $LOGFILE
echo "Building Configuration File at `date`" >> $LOGFILE
echo "BINDIR=$BINDIR" >> $LOGFILE

#Defining the Default Source Directory
curr_dir=`pwd`
cd $UNIKIX/src
kixsrc_dir=`pwd`
cd $curr_dir
if [ "$kixsrc_dir" = "`pwd`" ]
then
  # We are under $UNIKIX/src  : this is the default
  DEFAULT_SRC_DIR=$UNIKIX/src
  DEFAULT_SRC_DIR_STRING="\$UNIKIX/src"
else
  # We are under a different Sun MTP source Directory : this is the default
  DEFAULT_SRC_DIR=`pwd`
  DEFAULT_SRC_DIR_STRING=""
fi
#**********************************************************************
# Target dir configuration 
#**********************************************************************
$KIXCLS
echo "                    Target Source Directory                $DATEVAR"
echo " "
echo " "
echo " "
echo " "
echo " "
echo "            The Default Source Directory is $DEFAULT_SRC_DIR_STRING"
echo " "
echo " > $DEFAULT_SRC_DIR <"
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo "--------------------------------------------------------------------------------"
echo "Press Return to use the Default $DEFAULT_SRC_DIR_STRING Source Directory"
echo "      or "
echo "Enter a directory pathname to specify a different Target Source Directory"
read TARGET_DIR
TARGET=`echo $TARGET_DIR`+
if [ $TARGET = + ]
then
  TARGET_DIR=$DEFAULT_SRC_DIR
fi
TARGET_DIR=`eval echo $TARGET_DIR`;export TARGET_DIR
echo "TARGET_DIR=$TARGET_DIR" >> $LOGFILE
if [ ! -d $TARGET_DIR ] ;then
  echo "#"
  echo "# ERROR. Target Directory = $TARGET_DIR does not exist"
  echo "#"
  TARGET_DIR="none";export TARGET_DIR
else
  if [ $TARGET = + ]
  then
    echo ""
  else
    echo "Copying Files to Target Source Directory ...."
    cd $UNIKIX/src
    if [ "+$SKILLED" = "+" ]
    then
      echo "Copying Files to Target Source Directory $TARGET_DIR" >> $LOGFILE
      find . -print | cpio -pvdm $TARGET_DIR >> $LOGFILE 2>&1  
    else
      find . -print | cpio -pvdm $TARGET_DIR 2>&1
    fi
  fi
  echo "s%BINDIR=\(.*\)%BINDIR=$BINDIR%" >>/tmp/config.current
  USERSRCDIR=$TARGET_DIR;export USERSRCDIR
  USERSRCDIR=`eval echo $USERSRCDIR`
  echo "s%USERSRCDIR=\(.*\)%USERSRCDIR=$USERSRCDIR%" >>/tmp/config.current

  #
  # This script is invoked only for COBOL i.e. ACUCOBOL or MFCOBOL
  #

  #
  # if ACUCOBOL-GT then change the target executables to acucob and return
  #

  if [ "$appl_lang_cob_acu" = "$SELECTED" ]
  then
      echo "s%COBOL_EXT=nocob%COBOL_EXT=acucob%" >>/tmp/config.current
#ACUCOBOL is used in kxusrexits.c to call kxcobload 
      echo "s%CFLAGS=%CFLAGS=-DACUCOBOL %" >>/tmp/config.current
  else

    # if Micro Focus then change the target executables to mfcob
    echo "s%COBOL_EXT=nocob%COBOL_EXT=mfcob%" >>/tmp/config.current

    # ---------------------------------------------------------------------
    #  Set the cobol flags
    #  cobver location changes between object cobol and ServerExpress
    # ---------------------------------------------------------------------
    # grep in the cobver for the version strings
    # case 727x ? reverse check to insure Server Express is picked up 
    if [ -f $COBDIR/etc/cobver ]
    then
      X=`grep cobol $COBDIR/etc/cobver | cut -c8-10`
      X1=`grep cobol $COBDIR/etc/cobver | cut -c8`
      X2=`grep cobol $COBDIR/etc/cobver | cut -c10`
      case $X in
      1.0)
          # ServerExpress 1.0
          echo "s%RDBMSFLAG=%RDBMSFLAG= -DKX_SERVER_EXPRESS %" >>/tmp/config.current
          ;;
    *)
          # ServerExpress
          echo "s%RDBMSFLAG=%RDBMSFLAG= -DKX_SERVER_EXPRESS %" >>/tmp/config.current
          ;;
      esac
      # need to check on the server express version number
      # to see if we can use remote animation. If we can't
      # we need to include the stubs to allow the load to work.
      # Requires v2.0.11 SP1 or later
      NOREMOTE=0
      X=`grep cobol $COBDIR/etc/cobver | cut -c8`
      case $X in
      1) NOREMOTE=1;;
      2) X=`grep cobol $COBDIR/etc/cobver | cut -c10`
         case $X in
         0) X=`grep cobol $COBDIR/etc/cobver | cut -c12-13`
            case $X in
            [0-9]|10) NOREMOTE=1;;
            11) X=`grep PTI $COBDIR/etc/cobver | cut -c5-6`
                if [ $X ]
                then
                  if test $X = SP
                  then
                     X=`grep PTI $COBDIR/etc/cobver | cut -c7`
                     case $X in
                     0) NOREMOTE=1;;
                     [1-9]) NOREMOTE=0;;
                     *) NOREMOTE=1;;
                     esac
                  else
                     NOREMOTE=1
                  fi
                else
                  NOREMOTE=1
                fi;;
            esac
         esac
      esac
      if test $NOREMOTE = 0
      then
        echo "s%RANIMSTUB=\$(USERTRANS)/kxnoranim.o%RANIMSTUB=%" >>/tmp/config.current
      fi
    else
      X=`grep cobol $COBDIR/cobver | cut -c8-10`
      X1=`grep cobol $COBDIR/cobver | cut -c8`
      X2=`grep cobol $COBDIR/cobver | cut -c10`
      case $X in
      3.2)
          # Micro Focus 3.2
          echo "s%RDBMSFLAG=%RDBMSFLAG= -DMFCOBOL32 %" >>/tmp/config.current
          ;;
      3.1)
          # Micro Focus 3.1
          ;;
      *)
          case $X1 in
          4)
            # Micro Focus 4.0 or greater
            echo "s%RDBMSFLAG=%RDBMSFLAG= -DMFCOBOL32 %" >>/tmp/config.current
            ;;
          *)
            ;;
        esac
        ;;
      esac
    fi
  fi
 fi
