[Top][All Lists]

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

Re: Non-recursive make with Fortran object files

From: Dave Goodell
Subject: Re: Non-recursive make with Fortran object files
Date: Sun, 2 Dec 2012 13:57:36 -0600

On Dec 2, 2012, at 5:19 AM CST, Alexis Praga wrote:

> I am using non-recursive strategy for compiling my Fortran code. At the
> moment, the .mod files are put in the top directory.
> How can I tell automake to put them in the same folder as the source files
> ?
> The subdir-objects option in works only for the .o files.

Automake doesn't do anything to handle the .mod files, unfortunately.  Most 
(all?) modern Fortran compilers have some sort of flag that can be used in 
order to specify the output directory for the .mod files.  For gfortran, for 
example, this flag has the format "-J${outdir}".  You can use the 
PAC_FC_MODULE_OUTFLAG macro here [1] in order to guess the correct module 
output directory flag (you will probably need all three macros invoked in 
PAC_FC_MODULE in that same file).  That macro will AC_SUBST([FCMODOUTFLAG]) for 
you, so you can use $(FCMODOUTFLAG) in your  I use it this way:

# cause any .$(MOD) files to be output in the f90 bindings directory instead of
# the current directory
AM_FCFLAGS += $(FCMODOUTFLAG)src/binding/f90


You will need to write your own rules for .mod files if you wish make to 
capture their dependencies and trigger rebuilds if they are deleted/stale for 
some reason.  Be warned though, make & automake handle this case poorly, since 
this is a situation where more than one output file is created from (typically) 
a single input.  Supporting parallel make ("make -j4", etc.) additionally 
complicates the situation.

Furthermore, almost any attempt to handle .mod dependencies will also require 
you to maintain a certain level of discipline when naming your source files 
placing your modules into source files, since the .mod file is usually named 
based on the MODULE name, not the input file name.  If you have a "MODULE foo" 
statement, that should live in the source file "foo.f90" in order to make it 
easy to derive "foo.mod" with a make implicit rule.  Do not include any other 
modules in "foo.f90".  Here's [2] a sample rule that I've used in the past for 
dealing with this.  It's complex enough that we actually generate this automake 
code with a perl script.


Automake could definitely be doing a lot more to help with Fortran code, 
although I can certainly understand that the intersection between sufficient 
automake knowledge, fortran knowledge, access to a variety of fortran 
environments/programs, and free time is probably the empty set.


reply via email to

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