Luka Djigas <
ldi...@at.gmail.com> wrote:
(snip, I wrote)
>>But if you want to, you can do something like:
>>if exist %9.obj (
>>echo nine
(snip of eight more cases)
> Actually wrote it similar to that, in the end. Was hoping for a more
> elegant solution though.
CMD isn't as powerful as unix shells, though a little better than
the COMMAND processor for DOS.
I think you can do loops, but I didn't try last night.
(snip on makefiles)
> True. But they got one disadvantage compared to .bat files. You have to
> make a .makefile for every program/project you're building. Which, if
> you're writing a lot of small programs that you keep all in one
> directory, is really not all that practical.
The idea is that the command all go into one makefile for all those
programs.
> With batch scripts (I have one for command line programs, one for
> DISLIN, one for ...) I can just call
> build-dislin first.f90 second.f90 third.f90 ... and off it goes.
> You probably understand what I'm getting at.
Sometimes I make the .cmd file to run make, as it saves just a few
characters of typing.
> Maybe I'm just not familiar with .makefiles. Can something similar be
> accomplished with them too? Also, can they be named differently for
> every program you're building - not just .makefile?
You can name it anything, and use the -f option.
make -f someothermakefile
Note, though, that in the usual case you don't need to do much.
Make knows how to compile programs without any help.
As a test, (on a linux system) I make a file, this.f, and, without
any makefile said
make this
f77 this.f -o this
make: f77: Command not found
make: *** [this] Error 127
So, make figured out how to compile and link the program, but I don't
have f77.
make FC=gfortran this
will do it.
If I make a Makefile with just one line:
FC=gfortran
I can now compile and link any single Fortran file.
There are default rules for that case.
But there is no way that make could know if more files were needed.
Now, add the line:
this: this.o that.o
which tells make to link this.o and that.o to generate that. Or, for DOS:
this.exe: this.obj that.obj
Now make knows to compile both this.f and that.f, but it fails at
link time because it doesn't know that they are gfortran .o files.
If I add
CC=gfortran
So that my Makefile now says:
FC=gfortran
CC=gfortran
this: this.o that.o
It will compile this.f and that.f, then link the two .o files.
Strange as it may seem, the gfortran command will compile C programs.
The cc command will compile, but not successfully link, Fortran
programs.
Anyway, so all you need to add to the Makefile is the dependency
in object files and make will figure out the rest.
Well, you might also need the dependencey for MOD files.
You can set FFLAGS to any compiler options, in the makefile, on
the make command line, or as an environment variable.
-- glen