help-make
[Top][All Lists]
Advanced

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

Correct dependency for Fortran .MOD and .O files


From: Tobias Burnus
Subject: Correct dependency for Fortran .MOD and .O files
Date: Thu, 27 Jan 2011 17:28:34 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7

Hello,

I have a Makefile-dependency question regarding Fortran: In Fortran one can have so-called modules. If one compiles such a file, a .mod file is generated which contains the public interface and a .o file which contains the binary.

If one changes the source file (.f90) without modifying the interface, the file should be compiled - and the relinking happening, but no other files should be compiled.

If the source file is changed such that the the interface (.mod file) changes, all source files depending on the .mod file should be recompiled.

The question is how one can squeeze this into a Makefile; what I can tune is whether the .mod file gets "touched" (file modification date changed) or not after modification.

The following is a default dependency file, which in principle nicely works, but I either get a complete recompilation as soon as the date of the .mod file changes.

myprogram: myprogram.o mymodule.o
        $(FC) -o myprogram myprogram.o mymodule.o
mymodule.o mymodule.mod: mymodule.f90
        $(FC) -c mymodule.f90
myprogram.o: myprogram.f90 mymodule.mod
        $(FC) -c myprogram.f90


Assuming the .mod date does not change, the Makefile above will cause a complete recompilation of "mymodule" every time as "mymodule.mod" is always older than "mymodule.f90". I could try the following, but it does not work if one either has the wrong order in the "myprogram:" dependency list or when one calls "make myprogram.o" (assuming that mymodule.f90 has changed such that the interface is different - and that myprogram.f90 needs this change).

Any idea? Is is better for the compiler to change the .mod file modification date or not?

Background: gfortran currently does not, but it causes obviously some problems; cf. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47495

Tobias




reply via email to

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