#! /bin/sh
#
#make-all: make all systems afresh
# switches are
#     -noforce	don't delete old databases/images first
#     -clean	delete databases/images after use (leaving Pure)
#     -notest	make databases/images w/o running the examples
#     -noexec	don't execute, just check settings and Makefiles

#Environment variables required:
# ISABELLEBIN: the directory to hold Poly/ML databases or New Jersey ML images
# ISABELLECOMP: the ML compiler
# ISABELLEMAKE: the Makefile to use - "Makefile" or "Makefile.NJ"

# Creates files called make.log on each subdirectory and
# displays the last few lines of these files -- this indicates whether
# the "make" failed (whether it terminated due to an error)

set -e			#fail immediately upon errors

# process command line switches
CLEAN="off";
FORCE="on";
TEST="test";
EXEC="on";
NO="";
for A in $*
do
	case $A in
	-clean) CLEAN="on" ;;
	-noforce) FORCE="off" ;;
	-notest) TEST="" ;;
	-noexec) EXEC="off"
                 NO="-n" ;;
	*)	echo "Bad flag for make-all: $A"
		echo "Usage: make-all [-noforce] [-clean] [-notest] [-noexec]"
		exit ;;
	esac
done

echo Started at `date`
echo force=$FORCE '    ' clean=$CLEAN '    '
echo Compiler=${ISABELLECOMP?'No compiler specified'} 
echo Destination=${ISABELLEBIN?'No destination directory specified'}
echo makefile=${ISABELLEMAKE?'No Makefile specified'}

case $FORCE.$EXEC in
    on.on) (cd $ISABELLEBIN;  rm -f Pure FOL ZF LCF CTT LK Modal HOL Cube)
esac

#the -f prevents errors if the files do not exist
rm -f Pure/make.log FOL/make.log ZF/make.log LCF/make.log CTT/make.log \
	LK/make.log Modal/make.log HOL/make.log Cube/make.log

echo
echo
echo '*****Pure Isabelle*****'
(cd Pure; make $NO -f $ISABELLEMAKE > make.log)
tail Pure/make.log

echo
echo
echo '*****First-Order Logic (FOL)*****'
(cd FOL;  make $NO -f $ISABELLEMAKE $TEST > make.log)
tail FOL/make.log
#cannot delete FOL yet... it is needed for ZF and LCF!

echo
echo
echo '*****Set theory (ZF)*****'
(cd ZF;  make $NO -f $ISABELLEMAKE $TEST > make.log)
tail ZF/make.log
case $CLEAN.$EXEC in
    on.on)	rm $ISABELLEBIN/ZF
esac

echo
echo
echo '*****Domain Theory (LCF)*****'
(cd LCF;  make $NO -f $ISABELLEMAKE $TEST > make.log)
tail LCF/make.log
case $CLEAN.$EXEC in
    on.on)	rm $ISABELLEBIN/FOL $ISABELLEBIN/LCF
esac

echo
echo
echo '*****Constructive Type Theory (CTT)*****'
(cd CTT;  make $NO -f $ISABELLEMAKE $TEST > make.log)
tail CTT/make.log
case $CLEAN.$EXEC in
    on.on)	rm $ISABELLEBIN/CTT
esac

echo
echo
echo '*****Classical Sequent Calculus (LK)*****'
(cd LK;  make $NO -f $ISABELLEMAKE $TEST > make.log)
tail LK/make.log
#cannot delete LK yet... it is needed for Modal!

echo
echo
echo '*****Modal logic (Modal)*****'
(cd Modal;  make $NO -f $ISABELLEMAKE $TEST > make.log)
tail Modal/make.log
case $CLEAN.$EXEC in
    on.on)	rm $ISABELLEBIN/LK $ISABELLEBIN/Modal
esac

echo
echo
echo '*****Higher-Order Logic (HOL)*****'
(cd HOL;  make $NO -f $ISABELLEMAKE $TEST > make.log)
tail HOL/make.log
case $CLEAN.$EXEC in
    on.on)	rm $ISABELLEBIN/HOL
esac

echo
echo
echo '*****The Lambda-Cube (Cube)*****'
(cd Cube;  make $NO -f $ISABELLEMAKE $TEST > make.log)
case $CLEAN.$EXEC in
    on.on)	rm $ISABELLEBIN/Cube
esac
tail Cube/make.log 

case $EXEC in
    on)	echo
        echo '***** Now check the dates on the "test" files *****'
        ls -lt FOL/test ZF/test LCF/test CTT/test LK/test Modal/test \
               HOL/test Cube/test
esac
echo Finished at `date`
