#!/bin/csh

module purge
module load comp/intel-12.0.4
#module load comp/gcc-5.3
module load comp/gcc-8.2

set logfile=npb-make.log
touch $logfile
set outf=npb-make.out
touch $outf

echo "Date: `date`" >> $logfile
echo "Host: `hostname`" >> $logfile
module list >>& $logfile
echo "" >> $logfile

set cnt=0
set cntf=0

set aps=(bt sp lu lu ua ua)
set spv=(blk blk hp doac au rd)
set c="A"

foreach cf (gcc itc_p pgi)

set bindir=bin/bin_$cf
if ( ! -d $bindir) mkdir -p $bindir
\cp -f config/NAS.samples/make.def_$cf config/make.def
make clean >>& $outf

foreach ap (bt cg ep ft is lu mg sp ua)
   make $ap CLASS=$c >>& $outf
   set pgm=${ap}.${c}.x
   set pgmx=bin/$pgm
   @ cnt++
   if ( -e $pgmx ) then
      \mv $pgmx $bindir
      echo ">>> make $cf/$pgm - successful" | tee -a $logfile
   else
      echo "*** make $cf/$pgm - FAILED" | tee -a $logfile
      @ cntf++
   endif
end

set n=1
while ( $n <= $#aps )
   set ap=$aps[$n]
   set ver=$spv[$n]
   make $ap CLASS=$c VERSION=$ver VEXT=-$ver >>& $outf
   set pgm=${ap}-${ver}.${c}.x
   set pgmx=bin/$pgm
   @ cnt++
   if ( -e $pgmx ) then
      \mv $pgmx $bindir
      echo ">>> make $cf/$pgm - successful" | tee -a $logfile
   else
      echo "*** make $cf/$pgm - FAILED" | tee -a $logfile
      @ cntf++
   endif
   @ n++
end

end

echo "" >> $logfile
echo "Date: `date`" >> $logfile
echo "Total number of cases: $cnt" | tee -a $logfile
echo "Total number of FAILED cases: $cntf" | tee -a $logfile
echo "" >> $logfile

