Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compiling fortran module files in disorder 1

Status
Not open for further replies.

ya0037

Programmer
Oct 7, 2010
30
DE

Hi,

I have one serious question that is bothering me for a while and I could not find the solution.

I have written a general Makefile that can compile different types of files automatically, but when I use it for FORTRAN files and I have Module in my files I have to consider the order of files and this will cause my Makefile not working properly as I had to change the order by hand.

So I'm wondering if anybody knows the option that can solve this problem and all the files could be compiled without considering their orders.


Thank you very much.

Best Regards,
ya0037
 
Did you write your makefile by hand ?

If yes then you must take into account *.mod dependencies. Let us consider two source files module.f90 (a FORTRAN module) and test.f90 (the main program), the file test.f90 containing a "USE module" inside. The makefile must be something like :

Code:
module.o module.mod : module.f90
  gfortran -c module.f90

test.o : test.f90 module.mod
  gfortran -c test.f90

test.exe : test.o module.o
  gfortran -o test.exe test.o module.o

For a big application, makefiles are often written by scripts. The script sfmakedepend (easy to find with google) is useful to construct dependencies.

There are other alternatives associated to specific compilers. The Lahey Fortran has is own technique for instance.

SCons is a python tool I have tested in the past with more or less success.

I have seen people using "ant", designed originally for Java program but which may be used for other languages as well.

Another possibility still under development : my own experimental tool which works without makefile and is able to generate an executable program from source files written in C and FORTRAN. It does not use makefiles but a rather simple configuration file instead.

 

Thank you very much.
The things you described is exactly my problem.

Yes I wrote my makefile. and I want it to be some kind of automatic makefile. I mean I just want to give some filenames to the Java interface or my script and it will be put in the makefile. But as you said if I have modules it would be disasters and I have to correct the files in the orders.

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.

Again thank you very much.

Regards,


 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top