#! /bin/sh
# 
# This script builds the Fortran interface files for the directory given as 
# the argument.
# The full format is:
# mkfort toolsdirectory directorytoprocess
#
# It is intended that this is called by buildfrt; it is not user-friendly.
#
#echo $2
TOOLS="$1"
DIR="$2"
WARN="$3"
if [ -r "$DIR/comtype" ]; then 
EXT=`cat $DIR/comtype`
else
exit 0
fi
HASMAKE=`test -r $DIR/makefile`
if [ -r $DIR/makefile ]; then
    OK=dummy
else
    exit 0
fi
#
# Get mansec; we use this to find some special cases
if [ -r $DIR/mansec ] ; then 
    MANSEC=`cat $DIR/mansec`
else
    MANSEC=""
fi
#
# Finally, some systems don't support X; we check for that case here
if [ "$TOOLSNOX" = "YES" ] ; then
    if [ -r $DIR/mansec ] ; then
        if [ $MANSEC = "x" ] ; then
            exit 0
        fi
    fi
fi

CFORTHEAD=$TOOLS/c2fort/bfort
# Because sh doesn't discard patterns that don't match any file name,
# we do that here
FILE=`echo $DIR/*.[ch]`
if [ "$FILE" = "$DIR/*.[ch]" ]; then
    # did not expand the name
    OK=dummy
else
    # The "-nomsgs" suppresses comments about routines/macros not being
    # convertable to Fortran.
    $CFORTHEAD $WARN -dir fort -I $DIR/pubinc $DIR/*.[ch]  
fi
