#! /bin/csh -f
# No data file

# compile <directory>  <out file> <resultfile>:
#             <directory> is the directory containing the assignment submissions
#             <outfile> is the name of the output file 
#             <resutlfile> is the name of the new file to contain 
#                        the results of the compilation if there were errors
# for example:  compile MP1 ray result.txt
# where:  MP1 is one directory up, where all the students' directories are
#         ray is the renamed executable
#



if ($#argv < 3) then
   echo ""
   echo "compile <directory> <out file> <result file>"
   echo ""
   exit
endif

cd $1
   set class = *
   foreach student ($class)
      if (-d $student) then
         cd $student
         echo -n "   compiling program for $student..."
         echo "--- results for $student ---" > $argv[$#argv]
         echo " " >> $argv[$#argv]
         if ($#argv > 2) then
            set last = $#argv
            set ofile = $2
	    		if (-f $ofile) then
					make clean
	        		make -o $ofile
	    		else
	       		echo " *********  file not found:" >> $argv[$#argv]
          	endif
            echo " " >> $argv[$#argv]
      	endif
         echo "done"
         cd ..
      endif
end

