Makefile: avoid compiling Fortran modules for a new folder

I have a Fortran program that uses modules, i.e. creates files at compile time .mod. I also wrote a Makefile, which uses all .f90files from src/puts all created .ofiles in obj/and binaries in the current folder, and everything works fine.

Now I will recompile my program in different folders for different calculations (say, calc1/), i.e. copy Makefilein calc1/, type make allin calc1/, and all it does is link, because the object files already exist. However, if the program includes any modules, the compiler needs the appropriate .modfiles that will be present in calc1/. So far I have recompiled everything ( make clean all), but with the growth of the program it takes too much time!

A possible solution that I came across is to have one specific folder for binaries ( bin/). But this is not a viable option, because I have jobs in the queue that obviously need a stable binary, while I also try new features at the same time.

So I'm looking for a solution that somehow handles .modfiles similar to .o-files, for example. puts them in obj/.

+3
source share
1 answer

I would expect compilers (most?) To specify an option to change the path to the module file. c gfortran, option -Jor -M(from the man page):

-Jdir
-Mdir
       This option specifies where to put .mod files for compiled modules.  It is also
       added to the list of directories to searched by an "USE" statement.

       The default is the current directory.

       -M is deprecated to avoid conflicts with existing GCC options.

I think most compilers look for .mod files in directories included in -I

EDIT

As with gfortran 4.6, it is -Mno longer supported. Use-J

based on one of my configure scripts, a flag -modulefor ifortand pgf90, although I almost never use these compilers these days, so someone else should confirm this ...

+4
source

All Articles