2

I have about 39 Fortran F90 source files and 35 Fortran 77 Lapack related files. I am using include statement in my main program to connect all these files.

I have created a batch file make.bat with command ifort "MDL HydroD.F90" which compiles my code and generates the mdlhydrod.exe file. In the process the Fortran compiler creates many .mod and .obj build files which makes it difficult to manage. I would like to put my source files under a directory Source and lapack library files in a directory lapack and build files in a directory Debug.

Could anyone help me modify my make.bat file so that ifort looks at Source directory and build in Debug directory.

Thank you for help.

Currently using make.bat has only one line of command:

File Name: make.bat

ifort  "MDL HydroD.F90"

Working on a make file to be used with nmake (incomplete):

File Name: make.mak:

#Make File for MDL HydroD
# Compiler options
FC          :=  ifort
VPATH       :=  src
BINDIR      :=  bin

$(BINDIR):
    mkdir -p $(BINDIR)

clean:
@rm -rf $(BINDIR)
davidism
  • 121,510
  • 29
  • 395
  • 339
Amitava
  • 431
  • 2
  • 6
  • 21
  • Are you actually using a make tool in this process or is your script just called make.bat? – Etan Reisner Mar 31 '14 at 16:42
  • It's just my file `make.bat`. Compile time is not too high, so though a simple batch file should be enough. – Amitava Mar 31 '14 at 16:47
  • I am also trying to write a simple `makefile.mak` which can be used with the `nmake` command line tool. But I am very new to this and couldn't find any good tutorial for Windows OS yet. It would be helpful if you can direct me towards the right path. – Amitava Mar 31 '14 at 19:36
  • 1
    How do you want a help if you do not show the script? – Vladimir F Героям слава Mar 31 '14 at 19:39
  • 1
    Showing the script might be a good start (especially if it involves more than just that simple `ifort` command). If the question is how to tell `ifort` where to find sources and libraries then that sounds like something the `ifort` documentation or help output should be able to tell you. – Etan Reisner Mar 31 '14 at 19:40
  • Edited my question with my `make.bat` and `make.mak` file. My apologies for not posting them earlier. I don't know how to write `make` scripts and trying to get it together from snippets from different web pages. Thank you for your help. – Amitava Mar 31 '14 at 20:10
  • you ought to edit the question (title) to reflect you are asking for help with make. Question really has nothing to do with specifically with intel fortran. – agentp Apr 01 '14 at 13:31

1 Answers1

1

Because you are using a strange way of working with source files, which you showed in your other question, it will be very difficult to change this.

For recapitulation, you include everything in a single source file using the include statement. This looks pretty unfortunate to me and I commented on that there. If you have one source file, you are forced to build it with one command, there is no place for any fine control. This is not the issue of a bash or bat script vs. Makefile.

You can probably still keep some files included in some groups that are logically similar, if you need no finer control on that, but I see not much reason for that.

Remove the includes or at least the relevant ones. Then you can just do

ifort Source/the_source_file1 -c Output/name_of_obj1 -module the_directory_for_modules -I the_directory_for_modules  -other_flags

for every file. And then in the end:

ifort Output/name_of_obj1 Output/name_of_obj2 Output/name_of_obj3 .... -o the_result

In Scons (which I would use) it would be like this (tested on couple of dummy files). The file Sconstruct:

import os

env = Environment(tools=['default','ifort'])

env.Append(ENV = {'PATH' : os.environ['PATH']})
try:
  env.Append(ENV = {'LIBRARY_PATH' : os.environ['LIBRARY_PATH']})
except:
  pass

env.Append(F90FLAGS='-g -fast') #whatever flags you need
env.Append(FORTRANFLAGS='-g -fast') #whatever flags you need

outdir = "Output/"

srcdir = "Sources/"

lapackdir = "lapack/"


objs = []
for file in os.listdir(srcdir):
  objs += env.Object(target=outdir+os.path.splitext(file)[0], source=srcdir+file)

for file in os.listdir(lapackdir):
  objs += env.Object(target=outdir+os.path.splitext(file)[0], source=lapackdir+file)

env.Append(FORTRANMODDIR = outdir)

objs = filter(lambda o: str(o)[-4:] != '.mod', objs)

prg = env.Program(target="bin/result.exe", source= objs)

Default(prg)
Community
  • 1
  • 1
  • Thank you @vladimir-f for your response in both my posts. From your response, I understand I should write `ifort` command for each Fortran code in appropriate order to create the `Object` files and then link them to create `.exe` file. I was wondering if a make file such as [this](http://stackoverflow.com/questions/7004702/how-can-i-create-a-makefile-for-c-projects-with-src-obj-and-bin-subdirectories) can be made which will automatically search for all source files inside `src` directory, or its not possible since there is an order of dependence between the codes? – Amitava Apr 01 '14 at 18:52
  • With Fortran modules, you have to care for he correct order and dependency. This is not something `make` is good at doing automatically. I no longer personally use `make` for Fortran, because http://stackoverflow.com/questions/tagged/scons is so much better. – Vladimir F Героям слава Apr 01 '14 at 19:42
  • Thank you for introducing me to SCons. I will learn and implement it in my code later. For immediate purpose I think your idea of multiple `ifort` command written in a batch file will work. – Amitava Apr 01 '14 at 20:00