So I am wondering if there is anyway that I have not force to correct the files order in the makefile, maybe using an option or something else.
If you want to create the makefile with a Java program, then you need to produce correct dependencies as explained in my short example. As consequence, your Java program has to scan each Fortran source file, to detect the used modules as well as possible include files and to put them in the list of dependencies as well as the source file.
This is not a very complicated task but it needs to be programmed with care.
Your remark is a little bit strange. Hmm.. Finally, I am not sure whether you have really understood the interest of a makefile. So I will give additional explanations. Ignore them if you think that they are useless.
The order of the targets in a makefile has no importance if dependencies are correctly listed (this is the interest of the makefile). For instance :
Code:
test.exe : test.o module.o
gfortran -o test.exe test.o module.o
test.o : test.f90 module.mod
gfortran -c test.f90
module.o module.mod : module.f90
gfortran -c module.f90
I have changed the order of targets but this makefile remains strictly equivalent to the previous one.
For instance, at the first run, the make tool will compile module.f90 first because:
- it cannot build test.exe because test.o and module.o are missing,
- it cannot compile test.f90 because module.mod is missing.
After that it will compile test.f90 to create test.o (the target test.exe needs test.o and must wait for it) and then build the executable program test.exe (all dependencies are there now).
With further runs it will recompile module.f90 only if one of the two files module.o or module.mod is older than the file module.f90. In that case, it will also compile again test.f90 (module.mod is now more recent than test.o) and finally create again the executable program because the two objects files are more recent than test.exe.