
# UNISRC_ID: @(#)f_compile.sh	27.3	85/03/10  
#  FILE NAME is 'f_compile'
#
#  This shell script will perform a make operation using '/usr/contrib/bin/f_create'
#  and, if there are errors in compilation, will run the Softool Auditor on the
#  source code.  If the Auditor is run, its errors are inserted into the 
#  source code which is then delta'd into the SCCS directory.  
#
#  Before it begins operation, it removes the following files:
#
#  make.log, make.err, compile.err, and all '.obj' files which exist.
#
#  If the script was called with the name 'f_comp' it executes in expert
#  mode and doesn't remove the '.obj' files.  In this case, it is up to
#  the user to remove the files necessary for make to execute as expected
#  before the script is run.
#
#  In general, make will only re-make ALL if the '.obj' files are newer than
#  ALL or don't exist.  If a '.obj' file doesn't exist, make goes to the
#  '.o' files and sees if they are up to date with respect to their 
#  associated '.f' files.  If so, they are simply relinked, but if any '.f'
#  file is newer than its '.o' file, that '.o' file is remade.
#
#  By removing all '.obj' files, f_compile causes make to look at each of the
#  '.o'/'.f' file pairs.  At the least, this will cause a relink of all '.o'
#  files to create all the '.obj' files.  In the expert mode, f_compile 
#  assumes that the user has removed the required '.obj' files in order to
#  cause re-making of associated '.o' files from changed '.f' files.
#  Unnecessary re-linking is not performed in this case.  If additional 
#  arguments are given to compit, the script assumes these are files to
#  be removed.
#
#  A log of the make operation and subsequent actions is put into a file 
#  called 'make.log' and any error messages which occur are put into 
#  'make.err'.  If compilation errors occur, the names of routines causing
#  errors are written to a file called 'compile.err'.
#
#  Added capability: 2/27/83
#
#  If the Softool AUDITOR is not present in the system in the default location
#  (/usr/softool/pedir) the long listing compiler option (-L) is used with
#  the FORTRAN compiler. The result is a long listing for each compiled file
#  named with the file basename appended with '.L'. 
#
#  Errors can be found in this listing along with their associated causes. 
#  No modification of the source code is done however, and no deltas are
#  entered into SCCS.

rm -f make.log make.err compile.err

if [ -d SCCS ]
  then
    PROJECTDIR=`pwd`
  else 
    echo {PROJECTDIR:=`pwd`} >> make.log
  fi

export PROJECTDIR

if [ $0 = "f_compile" ]
then
   rm -f *.obj
elif [ $0 = "f_comp" ]
then
   if [ $# -gt 0 ]
     then
       while  [ $1 ]
         do
            rm -f $1
            shift
         done
   fi
else
   echo "usage:  f_compile | f_comp"
   exit 1
fi

if [ ! -r makefile ]
then 
  get makefile 1>>make.log 2>>make.err
fi

if [ ! -r file.list ]
then
  get file.list 1>>make.log 2>>make.err
fi

echo "beginning make operation" >>make.log

if [ -x /usr/softool/pedir/AUDITOR ]
 then

    make -r OPERATION1="OPERATION1=/usr/contrib/bin/f_create" FFLAGS="FFLAGS="\
            ENTRY=start ENDS=/usr/lib/end.o 1>>make.log 2>>make.err

    if test -s compile.err 
      then
         echo "compilation errors - check compile.err for routine names"\
                >>make.err
         echo "entering any Auditor changes into SCCS" >> make.log

         while read i
           do
             get -e -p `basename $i` >/tmp/cmp$$ 2>>make.err

             if cmp -s /tmp/cmp$$ $i
               then
                 rm $PROJECTDIR/SCCS/p.`basename $i`
               else
                 mv $i `pwd`
                 delta -ylater_delta_from_original_source `basename $i`\
                       1>>make.log 2>>make.err
             fi

           done < file.list 1>>make.log 2>>make.err

         echo "removing Auditor files" >> make.log
         rm -f /tmp/cmp*
    fi
 else
    echo "Softool Auditor not available; using FORTRAN compiler option -L."\
            >> fortsplit.log

    make -r FFLAGS='FFLAGS="-c -g -U -L"' LISTING='LISTING="2>&1 > \$$$\*.L"' \
            ENTRY=start ENDS=/usr/lib/end.o\
                1>>make.log 2>>make.err

    echo "Check all .L files of routines which did not compile for errors."
 fi
