I have a problem writing a Makefile.am that will make autotools compile files in the correct order.
My minimal example is some test.f90 which uses routines from a module mod.f90. By hand, I do the following.
gfortran -c mod.f90
gfortran -c test.f90
gfortran -o test test.o mod.o
This works fine. Now, I have read that autotools does not handle Fortran module dependencies and, according to this post (automake with fortran: order of file) one should just put the dependencies into Makefile.am by hand.
Mine looks like the following.
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = test
test_SOURCES = mod.f90 test.f90
test: test.f90 mod.o
mod.o: mod.f90
While the .mod file for the module is generated each time I run ./configure && make, it is apparently not generated before all the other files, i.e. I still get the error message Fatal Error: Cannot open module file ‘mod.mod’ for reading at (1): No such file or directory.
Running ./configure && make twice in a row allows the programme to be compiled but of course this is not really a satisfying solution. Is there some standard way to deal with this? Can I maybe somehow force mod.o to be compiled before test.o?