This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Makefile with .mod files
- From: Ignacio Fernández Galván <jellby at yahoo dot com>
- To: fortran at gcc dot gnu dot org
- Date: Tue, 30 Oct 2007 18:49:07 +0000 (GMT)
- Subject: Makefile with .mod files
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=RnDEeoXTk/zCFPczNBiQIv7jaJDX8PaKTcRftUIrwC2uoKVwKoNrYJkn4HwDgSmV4wt4vXDn7HKSsIxJ2zETPJJ8syyE6Zv5vit2FP/ePuJjDpflNEqe0EbAbAKkfOIEDIY6XcydkD/cUtD8p/Fphh49BSYO4bVPDr8+KEC4QIM=;
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