At 16:55 on 26 July, Herbert Fruchtl wrote:
> That's usually not a problem. The argumentation goes about like this:
>
> - .o and .mod files are created at the same time.
> - They are also deleted at the same time ("Make clean" or similar)
> - They become out-of-date at the same time (by changing the source file)
> - If your Makefile is to work on various platforms, you can't be sure
> about the extension of the modules, or whether they are in the current
> directory. This is much less the case for object files.
But they don't become out of date at the same time. A .o file may be
out of date because of changes to the source file that don't affect
the .mod file. (Usually when the code changes but not the declarations
of public objects.) The problem then is that when the file is
recompiled, a new .mod file is generated that is the same as the old
one, and then all .f90 files that USE that module get recompiled --
unnecessarily, because as far as they're concerned nothing has
changed. With a big program this can lead to a cascade of unnecessary
recompilations.
I get around this by the following hack (using gnumake and ksh):
# If a .mod file exists, rename it as .mod.bak; otherwise make a dummy backup.
# Compile the routine.
# If the compilation produced a .mod file, compare it with the backup and
# restore the backup if no change.
# Remove the .mod.bak file, if still present; it's either superseded or a
# dummy.
%.o: %.f90
@if [[ -e $*.mod ]] ; then mv -f $*.mod $*.mod.bak ; else echo "dummy" > $*.mod.bak ; fi
$(FC) $(FFLAGS) $(DEFS) -c $< -o $@
@-if [[ -e $*.mod ]] ; then cmp $*.mod $*.mod.bak > /dev/null && mv -f $*.mod.bak $*.mod ; fi
@-if [[ -e $*.mod.bak ]] ; then rm -f $*.mod.bak ; fi
Dependencies have to be based on the .mod files, not the .o files, for
this to work. Even so it may well not work on other platforms or with
other compilers. (I use the Sun compiler under Solaris.)
--
Anthony Stone http://fandango.ch.cam.ac.uk/
University Chemical Laboratory, Email: [log in to unmask]
Lensfield Road, Phone: +44 1223 336375
Cambridge CB2 1EW Fax: +44 1223 336362
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|