Hello,
You posted this message one month ago.
Do you have a similar solution when using libraries (.a),
since .o files are not kept in the directory and cannot be defined
as targets ?
Thanks
Anthony Stone wrote:
>
> There was some discussion on this list recently about the problem of
> unnecessary recompilations. For those who missed that discussion, the
> problem is as follows.
>
> If a subprogram USEs a module, then the makefile has to contain a
> corresponding dependency. That is, if subroutine foo uses module bar,
> then there will be an entry in the makefile of the form
>
> foo.o: bar.M
>
> However this means that if module bar is changed, the compiler will
> produce a new bar.M, and this will cause foo to be recompiled even if
> the new bar.M is the same as the old one, as is frequently the case.
>
> Solutions previously proposed overcame the problem by backing up the
> old .M file and comparing it with the new one. If it was unchanged,
> the old one was reinstated. However the .M file was then always
> apparently out of date, so its parent .f90 file was always recompiled
> whenever make was invoked, even if it hadn't changed.
>
> I believe that I have found a solution to this problem. It requires an
> extra command
>
> make modules
>
> to update the module .o and .M files if necessary, followed by
>
> make
>
> as usual. It works as follows.
>
> First, there must be no .M targets in the makefile. If a module
> depends on another, then its .o file should be declared as depending
> on the other .M file.
>
> Secondly, there must be no .f90.M suffix rule.
>
> Thirdly, the .f90.o suffix rule should be replaced by the following or
> its equivalent. (This is for ksh.) This makes a backup .M file, and if
> the new one is the same as the old, it is replaced by the old one.
>
> # If a .M file exists, rename it as .M.bak; otherwise make a dummy backup.
> # Compile the routine.
> # If the compilation produced a .M file, compare it with the backup and
> # restore the backup if no change.
> # Remove the .M.bak file, if still present; it's either superseded or
> # a dummy.
> .f90.o
> @if [[ -e $*.M ]] ; then mv -f $*.M $*.M.bak ; else echo "dummy" >
> $*.M.bak ; fi
> $(FC) $(FFLAGS) -c $< -o $@
> @-if [[ -e $*.M ]] ; then cmp $*.M $*.M.bak && mv -f $*.M.bak $*.M ; fi
> @rm -f $*.M.bak
>
> Finally, the makefile should include the following or its
> equivalent:
>
> # MODULES is a list of all the module object files. Any modules that
> # are USEd by others should precede them in this list.
> MODULES = bar.o ...
>
> # Invoke a recursive Make to update the modules.
> modules:
> ${MAKE} ${MODULES}
> touch modules
>
> (Actually, I think
> modules: ${MODULES}
> touch modules
> should be sufficient. However the version above forces make to look at
> each module, which in my experience doesn't always happen with the
> simpler form. Also, make doesn't always compile the modules in the
> order that one might expect, whereas the explicit ${MAKE} ${MODULES}
> forces the order that you specify.)
>
> The essence of this approach is that the ages of the .M files are
> never examined. The "make modules" command makes sure that they're all
> there before make considers files that depend on them. It seems to
> work for me (using Gnu make) but I'd be interested to know what others
> think of it, especially if anyone has a better approach.
>
> --
> Anthony Stone
> University Chemical Laboratory, Email: [log in to unmask]
> Lensfield Road, Phone: +44 1223 336375
> Cambridge CB2 1EW Fax: +44 1223 336362
--
+-----------------------------------+-----------------------------+
| Pierre Hugonnet | mail....CGG |
| | 1, rue Leon Migaux |
| Seismic Data Processing R&D | 91341 MASSY cedex |
| | FRANCE |
| COMPAGNIE GENERALE DE GEOPHYSIQUE | phone...(33/0) 164 47 45 59 |
| Massy processing center (France) | fax.....(33/0) 164 47 32 49 |
| | [log in to unmask] |
+-----------------------------------+-----------------------------+
My opinions are not necessarily those of CGG
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|