This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Makefile with .mod files


Hi all,

I'm having some problems with a Makefile for a Fortran program, and
I've tracked it down to the fact that .mod files don't have their
timestamp updated when compiling if they don't change. This means that
in my tests at least the files are compiled again when it is
unnecessary or I may have to run "make" a couple of times. Consider the
following test:

$ cat a.f90
MODULE A
USE B
END MODULE A

$ cat b.f90
MODULE B
END MODULE B

$ cat Makefile
all: a.o b.o

a.mod a.o: a.f90 b.mod
        gfortran -c $<

b.mod b.o: b.f90
        gfortran -c $<

$ make
gfortran -c b.f90
gfortran -c a.f90

$ touch *.f90

$ make
gfortran -c b.f90
gfortran -c a.f90 [alright, both f90 files were "changed"]

$ make
gfortran -c b.f90 [duh!]

This happens because the b.mod file is still older than b.f90, so it is
"rebuilt".

I also tried to split the rules, but then this happens:

$ rm -f *.o *.mod

$ cat Makefile
all: a.o b.o

a.o: a.f90 b.mod
        gfortran -c $<
a.mod: | a.f90 b.mod
        gfortran -c a.f90

b.o: b.f90
        gfortran -c $<
b.mod: | b.f90
        gfortran -c b.f90

$ make
gfortran -c b.f90
gfortran -c a.f90

[now modify b.f90 so that:]
$ cat b.f90
MODULE B
INTEGER :: i
END MODULE B

$ make
gfortran -c b.f90

$ make
gfortran -c a.f90 [duh!]

Now I have to run "make" twice, I guess it's because make does not know
b.mod can change due to a change in b.f90, as it is an order-only
dependency...

So, is there a solution for this? In my program, a single .f90 file can
generate several .mod files with different names, in case that matters.
I'm using GNU make 3.81 and gfortran 4.3.0 20070930.

Thanks

Ignacio


      ___________________________________________________________ 
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  http://uk.promotions.yahoo.com/forgood/environment.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]