#! /bin/sh
date

#FXISAM variable controls which version of the ISAM File Manager will be used.
#FXISAM has the following Valid Assignments: 
#
#       isam3=DISAM version 6.11
#       isam7=DISAM version 6.11 - INFORMIX 7.2 locking
#       isam8=DISAM - version 6.12
#       cisam=INFORMIX

FXISAM=cisam
FXISAM=isam7
FXISAM=isam3
FXISAM=isam8
if test "$FXDIR" = ""; then
    echo "FXDIR variable not set"
    exit
fi

mkdir $FXDIR/bin 2> /dev/null
mkdir $FXDIR/lib 2> /dev/null
# Create Informix 7.1 locking compatable version of DISAM library
if test "$FXISAM" = "isam7"; then
   if test ! -d $FXDIR/src/$FXISAM; then
      mkdir $FXDIR/src/$FXISAM
      cd $FXDIR/src/isam3
      rm -f *.o 2> /dev/null
      cp * $FXDIR/src/$FXISAM
      cd $FXDIR/src/$FXISAM
      cp isconfi7.h isconfig.h
      cp islock7.c islock.c
      fi
   fi
mkdir $FXDIR/src/$FXISAM    2> /dev/null
if test "$FXISAM" = "isam3"; then
   if test  -d $FXDIR/src/isam7; then
      cd $FXDIR/src/isam7
      rm -f *.o 2> /dev/null
      fi
   fi
if test "$FXISAM" = "isam7"; then
   if test  -d $FXDIR/src/isam3; then
      cd $FXDIR/src/isam3
      rm -f *.o 2> /dev/null
      fi
   fi

if test "$1" = "-r"; then 
#  ***** ERASE LIBRARIES *****
   cd $FXDIR/lib
   rm -f lib* 2> /dev/null
   touch libisam.a libfx.a
   rm -f *.o 2> /dev/null
   if test "$2" = "-n"; then rm * 2> /dev/null ; fi
#  ***** ERASE  EXECUTABLES *****
   cd $FXDIR/bin
   rm -f fx* *flex* ascheck 2> /dev/null
   if test "$2" = "-n"; then rm * 2> /dev/null ; fi

   cd $FXDIR/src/$FXISAM
   rm -f *.o 2> /dev/null
   cd $FXDIR/src/lib
   rm -f *.o 2> /dev/null
   cd $FXDIR/src/pre
   rm -f *.o 2> /dev/null
   cd $FXDIR/src/more 
   rm -f *.o 2> /dev/null
   cd $FXDIR/demo/bin
   rm -f *.pic 2> /dev/null
   rm -f demoflex 2> /dev/null
   rm -f cwmenu 2> /dev/null
   cd $FXDIR/src/term
   rm -f *.o 2> /dev/null
   cd $FXDIR/src/sql
   rm -f *.o 2> /dev/null
fi

if test "$2" = "-n"; then exit 0;  fi

# ***** MAKE *****
if test "$FXISAM" = "cisam"; then
   rm $FXDIR/lib/libisam.a
   rm $FXDIR/bin/bcheck
   fi
cd $FXDIR/src/$FXISAM
make -f makeisam.unx 
if test $? -ne 0; then exit 1 ; fi

# ***** MAKE *****
cd $FXDIR/src/lib
make -f makelib.unx
if test $? -ne 0; then exit 1; fi
make -f makeobj.unx
if test $? -ne 0; then exit 1; fi
make -f makelibm.unx
if test $? -ne 0; then exit 1; fi

# ***** MAKE *****   
# LIBFX.LIB  MUST EXIST BEFORE THIS IS DONE
cd $FXDIR/src/$FXISAM
make -f makechk.unx 
if test $? -ne 0; then exit 1; fi


# ***** MAKE *****
cd $FXDIR/src/pre
make -f makepre.unx
if test $? -ne 0; then exit 1; fi

# ***** MAKE *****
cd $FXDIR/src/more 
make -f makemore.unx
if test $? -ne 0; then exit 1; fi



# ***** MAKE *****
cd $FXDIR/src/term
make -f maketerm.unx
if test $? -ne 0; then exit 1; fi
make -f makeprnt.unx
if test $? -ne 0; then exit 1; fi

# ***** MAKE *****
cd $FXDIR/src/sql
make -f makesql.unx
if test $? -ne 0; then exit 1; fi
if test ! -r $SQLDIR/bin/xsql; then
   echo "!!!   Unable to copy SQLFLEX to Infoflex-4GL !!!!"
   cp $FXDIR/bin/fxsql2 $FXDIR/bin/fxsql
fi 
if test -r $SQLDIR/bin/xsql; then
   echo "Copying SQLFLEX to Infoflex-4GL"
   cp $SQLDIR/bin/xsql $FXDIR/bin/fxsql
fi 
#if test -r $SQLDIR/bin/xsql64; then
#   echo "Copying SQLFLEX OLD to Infoflex-4GL"
#   cp $SQLDIR/bin/xsql64 $FXDIR/bin/fxsql64
#fi 

# ***** MAKE *****
FXAPDIR=$FXDIR/demo; export FXAPDIR
FXDATA=$FXDIR/demo/demo.dbs; export FXDATA
FXBIN=$FXDIR/demo/bin; export FXBIN
cd $FXDIR/demo/bin
sqldemo
make -f makedemo.unx
if test $? -ne 0; then exit 1; fi




# ***** MAKE *****
#cd $FXDIR/src/pre
#make -f makedb2.unx
#if test $? -ne 0; then exit 1; fi

date


echo 
echo 
echo    INFOFLEX-4GL has successfully been compiled !!!! 
echo 
if test ! -r $SQLDIR/bin/xsql; then
   echo "     (WARNING: OLD SQLFLEX being used)"
fi 
echo
