This is what we are using. We call it makedepf90. It works for
NAGware on Linux and IRIX 5.3, for SGI F90 on IRIX 6.2, and Sun f90 on
Solaris 2.x. For Sun f90, we generate dummy .kmo files for each
module, and do dependency checks on those, rather than trying to track
which module is in which .o file.
-jack
#!/bin/sh
#
# makedepf90 - Jack Scheible, Jr.
# copyright Sparta, Inc., Apr., 1997
#
##########################################################################
#
# This program is a single-level makedepend for Fortran90 programs.
#
# Nota bene: This program does not yet scan included files for
# include files.
#
# Calling syntax:
# makedepf90 [-Iincludedir] [-fmakefile] [-oobjsuffix]
# [-pobjprefix] sourcefile ...
# This program takes the following arguments:
# -Iincludedir = Search path for include files and modules
# ( default is -I. to which user input is appended )
# -fmakefile = File to which dependency info is written
# ( defaults to makefile, then Makefile )
# -oobjsuffix = suffix of object files ( default is .o )
# -pobjprefix = prefix of object files ( no default )
#
# The arguments may be in any order.
#
##########################################################################
# Set default values
OBJPREFIX=
OBJSUFFIX=.o
OBJDIR=.
INCLUDEDIRS=.
DSTRING="# DO NOT DELETE"
MAKEFILE=makefile
# Determine current operating system
OS=`uname`
if [ "$OS" = "IRIX" ]
then
VERSION=`uname -r`
OS=$OS\_$VERSION
fi
# Determine compiler, based on OS.
if [ "$OS" = "IRIX64" -o "$OS" = "IRIX_6.2" ]
then
COMPILER="SGI"
elif [ "$OS" = "IRIX_5.3" -o "$VERSION" = "Linux" ]
then
COMPILER="NAG"
elif [ "$OS" = "SunOS" ]
then
COMPILER="Sun"
else
echo "Unknown operating system: " $OS
exit
fi
# Set module extension based on compiler
if [ "$COMPILER" = "SGI" -o "$COMPILER" = "Sun" ]
then
MODSUFFIX=".kmo"
elif [ "$COMPILER" = "NAG" ]
then
MODSUFFIX=".mod"
fi
# Find existing makefile
if [ ! -f $MAKEFILE ]
then
MAKEFILE=Makefile
fi
# loop through command parameters
for arg in $*
do
case $arg in
# module directories
-M*) MODULEDIRS=$MODULEDIRS\ `expr "$arg" : "..\(.*\)"` ;;
# includedir
-I*) INCLUDEDIRS=$INCLUDEDIRS\ `expr "$arg" : "..\(.*\)"` ;;
# makefile
-f*) MAKEFILE=`expr "$arg" : "..\(.*\)"` ;;
# Object Suffix
-o*) OBJSUFFIX=`expr "$arg" : "..\(.*\)"` ;;
# Object directory
-p*) OBJDIR=`expr "$arg" : "..\(.*\)"` ;;
# Anything else is a sourcefile
*) SOURCES="$SOURCES $arg" ;;
esac
done
# end loop
# Only SUN has MODULEDIRS, others use INCLUDEDIRS
if [ "$COMPILER" != "Sun" ]
then
MODULEDIRS=$INCLUDEDIRS
fi
# If makefile exists
if [ -f $MAKEFILE ]
then
# search for STRING,
# delete from there to end,
# and put in temporary file
sedcmd=/$DSTRING/,\$d
sed "$sedcmd" $MAKEFILE > tmp$$
# else
else
# Create temporary file
touch tmp$$
fi
#endif
# Write STRING
echo $DSTRING >> tmp$$
############################################################################
#
# Search source files for module definitions
#
############################################################################
# Loop through all source files
for FILE in $SOURCES
do
#--------------------------------------------#
# Build list of targets in this source files #
#--------------------------------------------#
# Determine object file name and make it first target
outfile=`echo $FILE | sed 's/\.[^.]*$//'`
outfile=$OBJDIR$outfile$OBJSUFFIX
TARGETS=$outfile
# Search files for module definitions and append to list of targets
MODDEFS=`grep -i "^ *module " $FILE | awk '{ print $2 }'`
SunModFile=
MODFILES=
for MODULE in $MODDEFS
do
# If compiler is SGI, the module file name is all uppercase
if [ "$COMPILER" = "SGI" ]
then
MODFILE=`echo $MODULE | tr '[a-z]' '[A-Z]'`$MODSUFFIX
TARGETS=`echo $TARGETS $OBJDIR$MODFILE`
# If compiler is NAG, the module file name is all lowercase
elif [ "$COMPILER" = "NAG" ]
then
MODFILE=`echo $MODULE | tr '[A-Z]' '[a-z]'`$MODSUFFIX
TARGETS=`echo $TARGETS $OBJDIR$MODFILE`
# If OS is SunOS, the module file name is the source file name with a
# .M extension. Since SunOS compiler puts all module info for one
# source file, source.f90, into one module file, source.M, we cannot
# know the name of the module file from the name of the module. Thus,
# for each module, we will create a corresponding empty .kmo file (all
# lowercase letters).
elif [ "$COMPILER" = "Sun" ]
then
if [ "$SunModFile" = "" ]
then
SunModFile=`echo $FILE | sed -e 's/90$//' -e 's/\.f$//`.M
fi
MODFILE=`echo $MODULE | tr '[A-Z]' '[a-z]'`$MODSUFFIX
TARGETS=`echo $TARGETS $OBJDIR$MODFILE`
else
echo "Unknown compiler " $COMPILER
exit
fi
MODFILES=`echo $MODFILES $MODFILE`
done
# If there is a SunModFile, add it to the list of targets.
if [ "$SunModFile" != "" ]
then
TARGETS=$TARGETS\ $SunModFile
fi
#--------------------------------------------------#
# Build list of dependencies for this source files #
#--------------------------------------------------#
# Initialize list of dependencies
DEPENDS=$FILE
#-------------------------------------#
# get list of files included in $FILE #
#-------------------------------------#
includes=`grep -i "^ *include" $FILE | \
sed -e 's/^[^"]*"//' -e 's/".*//' -e "s/^[^']*'//" -e "s/'.*//" | \
sort -u`
# loop though all included file names
for include in $includes
do
found=no
# search each include directory for file
for dir in $INCLUDEDIRS
do
if [ "$found" = "no" ]
then
# If include file is in this directory
if [ -f $dir/$include ]
then
# Append to dependency list
DEPENDS=`echo $DEPENDS $dir/$include`
found=yes
fi
fi
done
# end loop of include directories
# If not found, write error message
if [ "$found" = "no" ]
then
echo Error: cannot find file $include included in $FILE
fi
done
# End loop of included files
#------------------------------#
# Get list of all modules used #
#------------------------------#
MODS_USED=`grep -i "^ *use " $FILE | sed 's/,/ /g' | awk '{ print $2 }' | \
tr '[A-Z]' '[a-z]' | sort -u`
# Loop through modules
for MOD in $MODS_USED
do
# Construct module file name
if [ "$COMPILER" = "SGI" ]
then
MOD=`echo $MOD | tr '[a-z]' '[A-Z]'`
MODFILENAME=$MOD$MODSUFFIX
elif [ "$COMPILER" = "NAG" -o "$COMPILER" = "Sun" ]
then
MOD=`echo $MOD | tr '[A-Z]' '[a-z]'`
MODFILENAME=$MOD$MODSUFFIX
else
echo "Unknown compiler: " $COMPILER
exit
fi
# loop through include directories to search for module
found=no
for dir in $MODULEDIRS
do
if [ "$found" = "no" ]
then
# If include file is in this directory
if [ -f $dir/$MODFILENAME ]
then
# Write dependency to temp file
DEPENDS=`echo $DEPENDS $dir/$MODFILENAME`
found=yes
fi
fi
done
# end loop of include directories
# If not found, assume it will be built into the object directory
if [ "$found" = "no" ]
then
DEPENDS=`echo $DEPENDS $OBJDIR$MODFILENAME`
fi
done
# Write targets and dependencies
echo $TARGETS: $DEPENDS >> tmp$$
# If there are modules for targets, we need to write the compilation command
if [ "$MODDEFS" != "" ]
then
# Write compilation command depending on source file type
suffix=`echo $FILE | sed 's/^.*\.//'`
if [ "$suffix" = "for" ]
then
echo " \$(COMPILE.for) \$(FFLAGS) -o $outfile \$(IPATH) $FILE" >>tmp$$
elif [ "$suffix" = "f90" ]
then
echo " \$(COMPILE.f90) \$(FFLAGS) -o $outfile \$(IPATH) $FILE" >>tmp$$
else
echo "Unrecognized file type: " $FILE
fi
# For SunOS, we need to move the real module file to $OBJDIR, and
# create fake ones for SunOS so we can do dependency checking with MAKE.
if [ "$OS" = "SunOS" ]
then
echo " touch $MODFILES" >> tmp$$
echo " mv $SunModFile $OBJDIR" >> tmp$$
fi
# Move module files to $OBJDIR
echo " mv $MODFILES $OBJDIR" >> tmp$$
fi
done
# End loop of source files
# Move temp file to desired output file
mv -f tmp$$ $MAKEFILE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|