Dr W.W. Schulz said:
> the recent debates about compilation cascades did not let me
> rest until I found some solution. Here I want to present a version
> of makefile that goes some way to alleviate the problem.
This looks about as well as one can do with standard make.
(It still has the spurious recompile problem.)
> I will assume in the following that there is one module per file, that
> all procedures (except the PROGRAM) are wrapped inside modules (though
> this can be generalized),
> and that the compiler generates from file.f90 a file.o and a file.mod.
This is certainly a common style of programming, but we need not limit
ourselves to this (see below).
> The principle problem:
>
> .o must always be younger than .f90 files: No problem with make.
> BUT current compilers always generate a .mod file as well.
> I suggest that the -c option of compilers should generate only a .o file
Changing the behaviour of -c would be a pretty bad idea; a better one would
be to add a "-nomod" option to suppress .mod file generation.
> Below I present an example that works fine with the current makefiles
> on my dec alpha station.
I find that it has several minor-ish problems.
The obvious problem is that when a module is changed without the .mod file
altering, it will recompile-and-recompare every time you say "make".
I don't think this can be altered without changing "make".
Some other improvements are:
(1) Add "SHELL = /bin/sh"
(2) Change "diff" to "cmp -s"
(3) Use "@" to suppress excessive output
Here is my altered version for NAGWare f95 (which has the "-M" and "-nomod"
options).
#Begin Makefile
SHELL = /bin/sh
prog.x: prog.o some.o second.o some.mod second.mod
f90 -o prog.x prog.o some.o second.o
prog.o: some.mod
some.o: second.mod
some.mod: second.mod
.SUFFIXES: .f90 .mod .o
F90 = f95
.f90.o:
@echo Compiling $* to produce $*.o
$(F90) -c -nomod $<
.f90.mod:
@echo Compiling $* to produce $*.mod
@if [ -f $*.mod ] ;\
then mv $*.mod temp.mod ;\
$(F90) -M $< ;\
if cmp -s $*.mod temp.mod ;\
then mv temp.mod $*.mod ;\
echo .mod file unchanged ;\
fi ;\
rm -f temp.mod ;\
else $(F90) -M $< ;\
fi
clean:
rm -f *.o *.mod
#End Makefile
I also have a version in which modules SOME and SECOND are in the file
"modules.f90" and there is an additional "sub.f90". This also works roughly
as well as the version above (i.e. it does spurious recompile-and-recompares).
Here is the Makefile:
#Begin Makefile
SHELL = /bin/sh
prog.x: prog.o modules.o sub.o some.mod second.mod
f90 -o prog.x prog.o modules.o sub.o
prog.o: some.mod
sub.o: second.mod
some.mod: second.mod
.SUFFIXES: .f90 .mod .o
F90 = f95
.f90.o:
@echo Compiling $* to produce $*.o
$(F90) -c -nomod $<
second.mod some.mod: modules.f90
@if [ -f some.mod -o -f second.mod ]; then \
echo Rebuilding module files ;\
mv some.mod some.mod.save ;\
mv second.mod second.mod.save ;\
$(F90) -M modules.f90 ;\
if cmp -s some.mod some.mod.save; then \
mv some.mod.save some.mod ;\
else \
echo some.mod updated ;\
fi ;\
if cmp -s second.mod second.mod.save; then \
mv second.mod.save second.mod ;\
else \
echo second.mod updated ;\
fi ;\
else \
echo Building module files ;\
$(F90) -M modules.f90 ;\
fi
clean:
rm -f *.o *.mod
#end Makefile
Cheers,
--
...........................Malcolm Cohen, NAG Ltd., Oxford, U.K.
([log in to unmask])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|