$NetBSD: patch-ac,v 1.7 1999/12/22 20:22:15 dmcmahill Exp $ Much cleanup of the script. Added various options such as -O for optimization -fPIC for PIC support -Wall for gcc warnings -Wl, for additional linker arguments -v, for verbose output --- fc.orig Fri Apr 16 09:24:46 1999 +++ fc Wed Dec 22 15:15:08 1999 @@ -1,101 +1,125 @@ #!/bin/sh - -# NOTE: you may need to adjust the references to /usr/local/... below -# (or remove them if they're not needed on your system). -# See also the comments starting with ### below. - -PATH=/usr/local/bin:/bin:/usr/bin - +PATH=/bin:/usr/bin:@PREFIX@/bin +#USAGESTART # f77-style shell script to compile and load fortran, C, and assembly codes - -# usage: f77 [options] files [-l library] - +# +# usage: f2c-f77 [options] files [-l library] +# # Options: - -# -o objfile Override default executable name a.out. - +# # -c Do not call linker, leave relocatables in *.o. - +# # -C Check that subscripts are in bounds. - +# +# -D def passed to C compiler (for .c files) +# or to cpp (for .F files) +# +# -fPIC turn on the -fPIC flag to the c compiler +# +# -g produce debugging information. +# +# -I includepath passed to C compiler (for .c files) +# or to cpp (for .F files), and to f2c +# +# -l library (passed to ld). +# +# -L includepath passed to ld. Library include path +# +# -Ntnnn allow nnn entries in table t +# +# -o objfile Override default executable name a.out. +# +# -O turn on the -O flag to the c compiler +# +# -O1 turn on the -O1 flag to the c compiler +# +# -O2 turn on the -O2 flag to the c compiler +# +# -O3 turn on the -O3 flag to the c compiler +# +# -P emit .P files +# # -S leave assembler output on file.s - -# -L libdir (passed to ld) - -# -l library (passed to ld) - +# # -u complain about undeclared variables - +# +# -U def passed to C compiler (for .c files) or to +# cpp (for .F files) to remove def +# +# -v be verbose. Output is produced on the standard +# error output. +# # -w omit all warning messages - +# # -w66 omit Fortran 66 compatibility warning messages - -# files FORTRAN source files ending in .f . +# +# -Wall turn on the -Wall flag to the c compiler +# +# -Wl, Pass options to the linker. For example, +# -Wl,-R/usr/X11R6/lib +# passes "-R/usr/X11R6/lib" to the linker +# +# files FORTRAN source files ending in .f # FORTRAN with cpp preprocessor directives -# ending in .F . -# C source files ending in .c . -# Assembly language files ending in .s . -# efl source files ending in .e . -# RATFOR files ending in .r . -# Object files ending in .o . -# Shared libraries ending in .so . - +# ending in .F +# C source files ending in .c +# Assembly language files ending in .s +# efl source files ending in .e +# RATFOR files ending in .r +# Object files ending in .o +# Shared libraries ending in .so +# # f2c prototype files ending in .P ; such # files only affect subsequent files. -# -D def passed to C compiler (for .c files) -# or to cpp (for .F files) +# if no input arguments, then spit out the help stuff from the beginning +# of this file. +if [ $# = 0 ]; then + cat $0 | awk '$1 == "#USAGESTART", $1 == ""' | tail +2 | sed 's/#//g' +fi -# -I includepath passed to C compiler (for .c files) -# or to cpp (for .F files), and to f2c - -# -Ntnnn allow nnn entries in table t - -# -P emit .P files - -# -U def passed to C compiler (for .c files) -# or to cpp (for .F files) to remove def s=/tmp/stderr_$$ t=/tmp/f77_$$.o -### On some systems (e.g., IRIX), -common prevents complaints -### about multiple definitions of COMMON blocks. -#CC=${CC_f2c:-'cc -common'} -CC=${CC_f2c:-'cc'} +CC=${CC_f2c:-'cc '} EFL=${EFL:-efl} EFLFLAGS=${EFLFLAGS:-'system=portable deltastno=10'} RATFOR=${RATFOR:-ratfor} RFLAGS=${RFLAGS:-'-6&'} -F2C=${F2C:-/usr/local/bin/f2c} -F2CFLAGS=${F2CFLAGS:='-ARw8 -Nn802 -Nq300 -Nx400'} -CPP=${CPP:-/lib/cpp} +F2C=${F2C:-@PREFIX@/bin/f2c} +F2CFLAGS=${F2CFLAGS:='-ARw8 -Nn802 -Nx400'} +CPP=${CPP:-/usr/bin/cpp} rc=0 trap "rm -f $s $t; exit \$rc" 0 OUTF=a.out -OUTO= cOPT=1 -set -- `getopt cCD:gI:L:N:OU:o:Suw6 "$@"` -case $? in 0);; *) rc=$?; exit;; esac -CPPFLAGS=${CPPFLAGS:-'-I/usr/local/include'} -CFLAGSF2C=${CFLAGSF2C:-'-I/usr/local/include'} -OFILES= +ARGS= +CPPFLAGS= +CFLAGS=-I@PREFIX@/include +LIBS= +FLIBS="-L@PREFIX@/lib -lf2c -lm" +VERBOSE=no + while - test X"$1" != X-- + test -n "$1" do case "$1" in - -C) F2CFLAGS="$F2CFLAGS -C" - shift;; - -c) cOPT=0 shift ;; - -D) CPPFLAGS="$CPPFLAGS -D$2" - shift 2 - ;; + -C) F2CFLAGS="$F2CFLAGS -C" + shift;; + + -D*) CPPFLAGS="$CPPFLAGS $1" + shift;; + + -fPIC) CFLAGS="$CFLAGS $1" + shift;; -g) CFLAGS="$CFLAGS -g" F2CFLAGS="$F2CFLAGS -g" + G="-g" shift;; @@ -105,61 +129,97 @@ ;; - -U) CPPFLAGS="$CPPFLAGS -U$2" - shift 2 - ;; + -I*) CFLAGS="$CFLAGS $1" + CPPFLAGS="$CPPFLAGS $1" + F2CFLAGS="$F2CFLAGS $1" + shift 1 + ;; + + -l*) LIBS="$LIBS $1" + shift 1 + ;; + + -L*) LIBS="$LIBS $1" + shift 1 + ;; -o) OUTF=$2 - OUTO=$2 shift 2 ;; - -O) case $2 in -1) O=-O1;; -2) O=-O2;; -3) O=-O3;; *) O=-O;; esac - case $O in -O);; *) shift;; esac - CFLAGS="$CFLAGS $O -Olimit 2000" +# -N) F2CFLAGS="$F2CFLAGS $1""$2" +# shift 2 +# ;; +# can't seem to find out what -N is supposed to do. + + -O|-O1|-O2|-O3) + CFLAGS="$CFLAGS $1" shift ;; - -u) F2CFLAGS="$F2CFLAGS -u" + -P) F2CFLAGS="$F2CFLAGS $1" shift ;; - -w) F2CFLAGS="$F2CFLAGS -w" - case $2 in -6) F2CFLAGS="$F2CFLAGS"66; shift - case $2 in -6) shift;; esac;; esac + + -S) CFLAGS="$CFLAGS -S" + cOPT=0 shift ;; - -L) OFILES="$OFILES $1$2" - shift 2 - case $cOPT in 1) cOPT=2;; esac + -u) F2CFLAGS="$F2CFLAGS -u" + shift ;; - -L*) OFILES="$OFILES $1" + -U*) CPPFLAGS="$CPPFLAGS $1" + shift;; + + -v) VERBOSE=yes shift - case $cOPT in 1) cOPT=2;; esac ;; - -N) F2CFLAGS="$F2CFLAGS $1""$2" - shift 2 + -w) F2CFLAGS="$F2CFLAGS -w" + shift ;; - -P) F2CFLAGS="$F2CFLAGS $1" + -w66) F2CFLAGS="$F2CFLAGS -w66" shift ;; + -Wall) CFLAGS="$CFLAGS -Wall" + shift + ;; - -S) CFLAGS="$CFLAGS -S" - cOPT=0 + -Wl*) CFLAGS="$CFLAGS $1" shift ;; + -*) echo "ERROR: $1 is not a valid option" + exit 1 + ;; + *) - echo "invalid parameter $1" 1>&2 + ARGS="$ARGS $1" shift ;; esac done -shift -case $cOPT in 0) case $OUTO in '');; *) CFLAGS="$CFLAGS -o $OUTO";; esac;; esac + +if test $cOPT = 0; then + if test "$OUTF" != "a.out"; then + CFLAGS="$CFLAGS -o $OUTF" + fi +fi +set -- $ARGS + +if test $VERBOSE = "yes"; then + F2CVER=`$F2C < /dev/null | awk '/.*version/ {print $6" "$7}'` + echo "f2c-f77:" + echo "F2C= $F2C, $F2CVER" + echo "CC= $CC" + echo "CFLAGS= $CFLAGS" + echo "CPPFLAGS= $CPPFLAGS" + echo "FLIBS= $FLIBS" +fi + while test -n "$1" @@ -171,4 +231,7 @@ case "$1" in *.f) b=`basename $1 .f` + if test $VERBOSE = "yes"; then + echo "$F2C $F2CFLAGS $1" + fi $F2C $F2CFLAGS $1 rc=$? @@ -178,4 +241,7 @@ rc=$? case $rc in 0) + if test $VERBOSE="yes"; then + echo "$F2C $F2CFLAGS <$b.i >$b.c" + fi $F2C $F2CFLAGS <$b.i >$b.c rc=$? @@ -185,5 +251,5 @@ esac case $rc in 0);; *) exit;; esac - $CC -c $CFLAGSF2C $CFLAGS $b.c 2>$s + $CC -c $CFLAGS $b.c 2>$s rc=$? sed '/parameter .* is not referenced/d;/warning: too many parameters/d' $s 1>&2 @@ -200,5 +266,5 @@ $F2C $F2CFLAGS $b.f case $? in 0);; *) rc=$?; exit;; esac - $CC -c $CFLAGSF2C $CFLAGS $b.c + $CC -c $CFLAGS $b.c case $? in 0);; *) rc=$?; exit;; esac OFILES="$OFILES $b.o" @@ -213,5 +279,5 @@ $F2C $F2CFLAGS $b.f case $? in 0);; *) rc=$?; exit;; esac - $CC -c $CFLAGSF2C $CFLAGS $b.c + $CC -c $CFLAGS $b.c case $? in 0);; *) rc=$?; exit;; esac OFILES="$OFILES $b.o" @@ -232,5 +298,5 @@ echo $1: 1>&2 OFILE=`basename $1 .c`.o - $CC -c $CFLAGSF2C $CPPFLAGS $CFLAGS $1 + $CC -c $CPPFLAGS $CFLAGS $1 rc=$?; case $rc in 0);; *) rc=$?; exit;; esac OFILES="$OFILES $OFILE" @@ -248,10 +314,10 @@ shift ;; - -[lL]) - OFILES="$OFILES $1$2" + -l) + OFILES="$OFILES -l$2" shift 2 case $cOPT in 1) cOPT=2;; esac ;; - -[lL]*) + -l*) OFILES="$OFILES $1" shift @@ -259,6 +325,5 @@ ;; -o) - case $cOPT in 0) CFLAGS="$CFLAGS -o $2";; *) OUTF=$2;; esac - shift 2;; + OUTF=$2; shift 2;; *.P) F2CFLAGS="$F2CFLAGS $1" @@ -273,9 +338,11 @@ done -### On some (IRIX) systems, -Wl,-dont_warn_unused prevents complaints -### about unnecessary -l options. +case $cOPT +in + 2) $CC $CFLAGS -o $OUTF -u _MAIN__ $OFILES $LIBS $FLIBS + ;; +esac -#case $cOPT in 2) $CC -Wl,-dont_warn_unused -o $OUTF -u MAIN__ -L/usr/local/lib $OFILES -lf2c -lm;; esac -case $cOPT in 2) $CC -o $OUTF -u MAIN__ -L/usr/local/lib $OFILES -lf2c -lm;; esac rc=$? exit $rc +