
# UNISRC_ID: @(#)fortsplit.sh	27.3	85/03/10  
#  FILE NAME is 'fortsplit'
#
#  This shell script will go through the directory and do
#  the following...

#        take the .f file and break it up into .f files which
#             each contain only one main, function, or subroutine and which
#             are named with '.f' appended to the routine name
#        generate make files for these .f files which...
#             try to compile each .f file with the -U option on the FORTRAN
#                   compiler
#             if the compilation generates errors, run the Softool AUDITOR
#                   on the file supressing warnings, portability, and
#                   documentation messages
#             try to link all possible .o files 
#        generate a master make file to drive the above make files.
        
        #     use awk to generate an editor script which will break up
        #           the large .f file into a series of files containing
        #           one routine each which are named by concatenating the
        #           routine name with '.f'
        #           edit messages are kept in a log file called fortsplit.log
        #           and error messages are kept in a file called fortsplit.err
        #     at the same time, use awk to generate a makefile for the files
	#     put the source files thus generated into an SCCS directory, 
	#     along with the make files

#  If only one file is given to 'fortsplit', it changes the name of this file
#  to 'file.f'.  Since this file is removed the next time through the script,
#  another copy of it should be kept.
#
#  NOTE:  Fortsplit will fail if the FORTRAN keywords are not uppercase.
#
#  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.

echo "CAUTION:  This script removes the following files from the current"
echo "          directory if they exist:"
echo " "
echo "                file.f, fortsplit.err, fortsplit.log, file.list, compile.err"

rm -f file.f fortsplit.log fortsplit.err file.list compile.err

if [ $# -gt 1 ]
  then
    for i 
      do
         cat $i>> file.f
      done

elif [ $# -eq 0 ]
  then
    echo "usage: fortsplit file1 [file2...]"
    exit 1  

else
  mv $1 file.f
fi

echo "" > fortsplit.log
echo `date`>> fortsplit.log

awk -f /usr/contrib/bin/awk_split file.f | /usr/contrib/bin/exsplit  file.f 1>>fortsplit.log\
   2>>fortsplit.err
ex makefile1 < /usr/contrib/bin/make_edit 1>>fortsplit.log 2>>fortsplit.err
awk -f /usr/contrib/bin/mk_split makefile1 | ex makefile1 1>>fortsplit.log\
   2>>fortsplit.err

echo `date` >>fortsplit.log
ls *.make >> file.list
PROJECTDIR=`pwd`
export PROJECTDIR

if [ ! -d SCCS ]
 then
  mkdir SCCS
fi

echo "entering files into SCCS" >> fortsplit.log

while read i
do
  enter `basename $i`
done < file.list 1>>fortsplit.log 2>>fortsplit.err

enter makefile file.list 1>>fortsplit.log 2>>fortsplit.err
get makefile file.list 1>>fortsplit.log 2>>fortsplit.err

while read i
do
  rm ,`basename $i`
done < file.list 1>>fortsplit.log 2>>fortsplit.err

rm -f ,*
rm -f makefile1

echo "beginning make operation" >>fortsplit.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" >> fortsplit.log

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

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

           done < file.list 1>>fortsplit.log 2>>fortsplit.err
         echo "removing Auditor files" >> fortsplit.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
