#!/bin/sh ######################################################################## # # f77bb # # Compiler envelope script to hide platform dependencies. # Torre Wenaus and Doug Wright # # Originally derived from Irwin Sheer's gemf77. # # f77bb myfile.F # run preprocessor to produce myfile.f # f77bb myfile.f # preprocessor is not automatically run # f77bb -link objects # link instead of compiling # # Modifications # # Jan 7, 1997 L. Garren add IRIX64 capabilities # Nov 6, 1996 L. Garren add option to set output file name # Oct 23, 1996 L. Garren add options to set working directory # and/or source directory # remove the -u option for IRIX # May 13, 1996 L. Garren use f77_370 if on fdei01.fnal.gov # Dec 21, 1995 L. Garren Call aix2f77 if vms2f90 is not called for AIX # Nov 20, 1995 T. Wenaus Add vms2f90 to do VMS to F90 structure conversion # in place of the no longer free IBM preprocessor for # sites that don't have it. # 'setenv VMS2F90 yes' to use it # Jan 6, 1995 D. Wright fixed -link option for OSF1 # Oct 25, 1994 D. Wright SunOS use /usr/lib/cpp if /usr/lang/cpp doesn't exist # Oct 6, 1995 D. Wright # added options -stop/-nostop to exit with an error on compilation error # print the source code line that caused the error # using perl (only knows HP syntax at the moment) # check for -c,-F,-o options for compatibility with the # default rule syntax in gmake # Sep 16, 1994 T. Wenaus Add CRAY T3D option # Aug 30, 1994 Fred Kral Add Sun option to allow 100 continuation lines. # Aug 1, 1994 T. Wenaus # If you set the env variable INCPGM to bbsim, meaning 'use includes for # program bbsim', the -I list of include directories will automatically # be generated, using the $HOME/bbsim/.dbxinit (or $BBSIM/.dbxinit if # BBSIM is defined) file which is generated by 'gmake dbx'. This way, # simple standalone compilation ('eg. f77bb mu_hist.F') can be done. # Jun 30 1994 Doug Roberts Made changes to ULTRIX (removed -u and # -C -check_bounds) # # June 8, 1994 Fred Kral Remove Solaris -C check since bombs /GCBANK/LQ. # # May 19 1994 Neil Geddes Add OSF1 # +put mods in historical order # May 9 1994 Fred Kral & Solaris: extended to SunOS 5 # David Wagner # Apr 28 1994 D. Wright -link added # Apr 8 1993 D. Wright AIX: -qflttrap=OV:ZERO:INV:EN # (i.e. floating point error trapping was never turned on!) # man page does not contain the above options see 'info' # Mar 16 1994 -save added # Mar 7 1994 T. Wenaus added -qflttrap to RS6000 to trap floating point # exceptions, which in true IBM style weren't # trapped by default. # Mar 4 1994 D. Wright added -qhalt=E for AIX # .F procedure changed, produces .f and is debuggable # -nodebug added # -noop modified # Nov 27 1993 D. Wright -I added # # ######################################################################## UNAME=`uname` [ -z "$BBSIM" ] && BBSIM=$HOME/bbsim # Kral 5/9/94 - Add major version (for Solaris versus SunOS 4) MAJORVER=` uname -r | tr "." " " | awk '{printf $1}' ` SCRIPT=`basename $0` MACH_NAME=`hostname` F_SRC= CPPOPTS="-D_TYPE_" F77OPTS= DEBUG=1 DLINE=0 NOOP=0 SAVE=0 LINK= #blank means false STOP=1 #blank means false bigF= #blank means false NOCOMP= #blank means false SDIR= #blank means use current directory WDIR= #blank means use current directory OUTFILE= #blank means do not rename output files ##### ##### describe command syntax if no arguments are given ##### if [ -z "$1" ] then echo "$SCRIPT [opts] file" echo 'opts:' echo ' -cpp supplementary cpp options' echo ' -f77 supplementary f77 options' echo ' -sdir source directory if other than current' echo ' -wdir working directory if other than current' echo ' -outfile used to rename output files' echo ' -debug (default) compile for debugging' echo ' -nodebug compile with optimization (nodebugging)' echo ' -stop stop on compilation error' echo ' -nostop (default) do not stop on compilation error' echo ' -dline compile debug lines' echo ' -noop print but do not execute commands' echo ' -save save intermediate file with #includes done' echo ' -link link arguments instead of compiling' echo ' (must be the last f77bb argument on the line)' echo '' echo "$SCRIPT - compile a FORTRAN77 file, chosing options appropriate" echo " for the current host." if [ $UNAME = "AIX" ] then echo " .F files are automatically preprocessed" echo " (the xlf v preprocessor handles STRUCTURES)" else echo " .F files are automatically preprocessed" fi echo " .f files are not preprocessed" echo '' echo "The follwoing (UNIX) system types are supported:" echo "AIX, HP-UX, IRIX, IRIX64, SunOS 4, Solaris, ULTRIX, OSF1" exit fi ##### ##### read command line arguments ##### cpp_opt=0 while test $# -gt 0 do case $1 in -c) ;; # don't remove this, D. Wright -F) NOCOMP=true ;; # preprocess only -o) F77OPTS="$F77OPTS -o $2"; shift;; -cpp) CPPOPTS="$CPPOPTS $2"; cpp_opt=1; shift;; -f77) F77OPTS="$F77OPTS $2"; shift;; -sdir) SDIR="$2"; shift;; -wdir) WDIR="$2"; shift;; -outfile) OUTFILE="$2"; shift;; -debug) DEBUG=1;; -nodebug) DEBUG=0;; -dline) DLINE=1;; -noop) NOOP=1;; -save) SAVE=1;; -link) LINK=true; shift; break;; -nostop) STOP= ;; #blank means false -stop) STOP=1;; -*) echo "$SCRIPT: Unknown option: $1" 1>&2; exit 1;; *) F_SRC=$1;; esac shift done ## set up include file directory list if [ -z "$INCPGM" ] then INCLIST="" else [ "$INCPGM" = "bbsim" ] && IDIRS="`sed \"s?use??\" $BBSIM/.dbxinit`" INCLIST="" [ $cpp_opt = 1 ] && IDIRS= [ -n "$IDIRS" ] && for dirnam in $IDIRS do INCLIST=$INCLIST" -I"$dirnam done CPPOPTS="$CPPOPTS $INCLIST" fi if [ $LINK ] then fp_SRC=$* else # check command line arguments if [ ! "$F_SRC" ]; then echo "$SCRIPT: F_SRC not specified." 1>&2 exit 1 fi # check that source file exists if [ $SDIR ] then if [ ! -r $SDIR/$F_SRC ]; then echo "$SCRIPT: $SDIR/$F_SRC not found." exit 1 fi else if [ ! -r $F_SRC ]; then echo "$SCRIPT: $F_SRC not found." exit 1 fi fi # set the intermediate file names # f_SRC is used by cpp # fp_SRC is used by xlf (AIX only) # f_OUT is used in final compilation # f_SRC=`echo $F_SRC | sed -e 's/\.F/\.f/'` fp_SRC=$f_SRC f_OUT=`echo $F_SRC | sed -e 's/\.F/\.o/'` [ $F_SRC != $f_SRC ] && bigF=true fi ##### ##### machine specific stuff ##### case $UNAME in OSF1) CPP=cpp CPPOPTS="$CPPOPTS -C -P -DOSF1 " if [ $MACH_NAME = "fdei01.fnal.gov" ]; then #### echo " on fdei01" F77=/usr/bin/f77_370 else #### echo " generic OSF1" F77=f77 fi [ $LINK ] || F77OPTS="$F77OPTS -c" F77OPTS="$F77OPTS -assume backslash" [ $DLINE = 1 ] && F77OPTS="$F77OPTS -d_lines" [ $DEBUG = 1 ] && F77OPTS="$F77OPTS -g " || F77OPTS="$F77OPTS -O " ;; HP-UX) CPP=/lib/cpp CPPOPTS="$CPPOPTS -C -P -DHPUX" F77=fort77 [ $LINK ] || F77OPTS="$F77OPTS -c" F77OPTS="$F77OPTS +ppu +T -K" [ $DLINE = 1 ] && F77OPTS="$F77OPTS -D" [ $DEBUG = 1 ] && F77OPTS="$F77OPTS -g" || F77OPTS="$F77OPTS -O" ;; IRIX) CPP=/lib/cpp CPPOPTS="$CPPOPTS -C -P -DIRIX" F77=f77 [ $LINK ] || F77OPTS="$F77OPTS -c" ##### F77OPTS="$F77OPTS -u -trapuv" F77OPTS="$F77OPTS -trapuv" [ $DLINE = 1 ] && F77OPTS="$F77OPTS -d_lines" [ $DEBUG = 1 ] && F77OPTS="$F77OPTS -g -C -check_bounds" || F77OPTS="$F77OPTS -O" ;; IRIX64) CPP=/lib/cpp CPPOPTS="$CPPOPTS -C -P -DIRIX" F77=f77 [ $LINK ] || F77OPTS="$F77OPTS -c" F77OPTS="$F77OPTS -trapuv" [ $DLINE = 1 ] && F77OPTS="$F77OPTS -d_lines" [ $DEBUG = 1 ] && F77OPTS="$F77OPTS -g -C -check_bounds" || F77OPTS="$F77OPTS -O" ;; SunOS) if [ $MAJORVER = "5" ]; then #### echo "Solaris" CPP=/usr/ccs/lib/cpp else #### echo "SunOS 4" CPP=/usr/lang/cpp [ ! -f $CPP ] && CPP=/usr/lib/cpp fi CPPOPTS="$CPPOPTS -C -P -DSunOS" #### Removed -u option (effectively inserts Implicit None) - Kral/Wagner #### Removed -C option (no compile-time array bound checks since also #### makes run-time array bound checks that kill CERNLIB) - Kral #### Add option -Nl101 to allow 100 continuation lines - Kral 8/30/94 F77=f77 [ $LINK ] || F77OPTS="$F77OPTS -c -Nl101" [ $DLINE = 1 ] && F77OPTS="$F77OPTS -xdl" [ $DEBUG = 1 ] && F77OPTS="$F77OPTS -g" || F77OPTS="$F77OPTS -O" ;; ULTRIX) CPP=/lib/cpp CPPOPTS="$CPPOPTS -C -P -DULTRIX" F77=f77 #### Removed -u option - DAR [ $LINK ] || F77OPTS="$F77OPTS -c" F77OPTS="$F77OPTS -automatic" [ $DLINE = 1 ] && F77OPTS="$F77OPTS -d_lines" #### Removed -C -check_bounds options - DAR [ $DEBUG = 1 ] && F77OPTS="$F77OPTS -g" || F77OPTS="$F77OPTS -O" ;; AIX)# IBM is appropriately ass backwards CPP=/lib/cpp CPPOPTS="$CPPOPTS -C -P -DAIX" F77=xlf if [ -n "$bigF" ] then f_OBJ=`echo $F_SRC | sed -e 's/\.F/\.o/'` if [ "$VMS2F90" = "yes" ] then XLFOPTS="-o $f_OBJ" f_SRC=`echo $F_SRC | sed -e 's/\.F/\.f/'` fp_SRC=$f_SRC f90_SRC=`echo $F_SRC | sed -e 's/\.F/\.f90/'` f77_SRC=`echo $F_SRC | sed -e 's/\.F/\.f77/'` else ## fp_SRC=`echo $F_SRC | sed -e 's/\.F/__\.f/'` ###...include preprocessor for VMS Fortran structure handling ## XLFOPTS="-o $f_OBJ -Pv -Wp,-dv,-gv,-o$f_SRC -qextname" XLFOPTS="-o $f_OBJ -qextname" f_SRC=`echo $F_SRC | sed -e 's/\.F/\.f/'` fp_SRC=$f_SRC f90_SRC=`echo $F_SRC | sed -e 's/\.F/\.f90/'` f77_SRC=`echo $F_SRC | sed -e 's/\.F/\.f77/'` fi fi [ $LINK ] || F77OPTS="$F77OPTS -c" [ $DLINE = 1 ] && F77OPTS="$F77OPTS -d_lines" [ $DEBUG = 1 ] && F77OPTS="$F77OPTS -g" || F77OPTS="$F77OPTS -O" # -qhalt=E quit if error occurs in compilation F77OPTS="$F77OPTS $XLFOPTS -qhalt=E -qflttrap=OV:ZERO:INV:EN" ;; sn*)# CRAY T3D - Torre Wenaus CPP=/usr/lib/gpp CPPOPTS="$CPPOPTS -P -DCRAY" F77=cf77 [ $LINK ] || F77OPTS="$F77OPTS -c" [ $DLINE = 1 ] && F77OPTS="$F77OPTS " # not available or not documented [ $DEBUG = 1 ] && F77OPTS="$F77OPTS -g" || F77OPTS="$F77OPTS -O" ;; esac # change output file name if appropriate if [ $OUTFILE ] then f_OUT="$OUTFILE" fi # fixup directories here if appropriate if [ $SDIR ] then F_SRC="$SDIR/$F_SRC" fi if [ $WDIR ] then f_SRC="$WDIR/$f_SRC" fp_SRC="$WDIR/$fp_SRC" f90_SRC="$WDIR/$f90_SRC" f77_SRC="$WDIR/$f77_SRC" f_OUT="$WDIR/$f_OUT" fi [ $NOOP = 1 ] && ECHO=echo ##### ##### cpp step (can't use $ECHO trick because of '>' ##### [ -n "$bigF" ] && if [ $NOOP = 1 ] then echo "$CPP $CPPOPTS $F_SRC > $fp_SRC" else $CPP $CPPOPTS $F_SRC > $fp_SRC if [ "$VMS2F90" = "yes" ] then #cp $fp_SRC $f77_SRC vms2f90 $fp_SRC if test -f $f90_SRC ; then mv $f90_SRC $fp_SRC ; fi elif [ "$UNAME" = "AIX" ] then #cp $fp_SRC $f77_SRC aix2f77 $fp_SRC if test -f $f90_SRC ; then mv $f90_SRC $fp_SRC ; fi fi fi [ $NOCOMP ] && exit ##### ##### f77 step ##### errfile=/tmp/`whoami`$$ $ECHO $F77 $F77OPTS -o $f_OUT $fp_SRC 2> $errfile ##### if compilation fails then exit with an error ##### if [ -z "$LINK" -a $? = 1 ] then ##### ##### If perl exists, use it to print the bad source code lines; ##### otherwise, just print the compiler output. ##### ##### At the moment, the perl program only knows to look for HP type ##### error messages. To add the same functionality for your machine ##### just add another 'elsif' line with the error message and wildcards. ##### The 'pickline' subroutine expects that parameter 1 is the line number ##### of the error and parameter 3 is the part of the error message to ##### echo to the screen. ##### ##### Doug Wright ##### if [ -f /usr/local/bin/perl ] then /usr/local/bin/perl -e 'open (in,"<$ARGV[0]"); while () { if (/Error on line (\w+) (.*): (.*)$/) {&pickline} elsif (/Declaration error on\/above line (\w+) (.*); ((.*); (.*))$/) {&pickline} elsif (/Compiler error line (\w+) (.*): (.*)$/) {&pickline} else {print;} } sub pickline { print "line: $1, $3\n"; open (ftn,"<$ARGV[1]"); while () {print $_ if $. == $1}} ' $errfile $fp_SRC else cat $errfile fi rm $errfile [ $STOP ] && exit 1 else cat $errfile rm $errfile fi # the true is required to keep gmake from seeing $?=1 # if you are not on an IBM # Kral 3/16/94 - option to save the file [ $SAVE = 1 ] && echo $SCRIPT' saved '$fp_SRC && exit ## On AIX, delete the intermediate file if vms2f90 wasn't used if [ ! -z "$VMS2F90" ] then [ -n "$bigF" -a $UNAME = "AIX" ] && $ECHO rm $fp_SRC || true fi