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 configure.ac 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 Makefile.am. I use it this way: ----8<---- # cause any .$(MOD) files to be output in the f90 bindings directory instead of # the current directory AM_FCFLAGS += $(FCMODOUTFLAG)src/binding/f90 ----8<---- [1] https://trac.mpich.org/projects/mpich/browser/mpich2/trunk/confdb/aclocal_fc.m4?rev=10708#L355 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. [2] https://gist.github.com/4190680 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. -Dave