help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Makefile with .mod files from gfortran


From: Ignacio Fernández Galván
Subject: Makefile with .mod files from gfortran
Date: Sat, 3 Nov 2007 17:53:48 +0000 (GMT)

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 shouldn't be recompiled]

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! This should have been run with the first run]

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


      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]