What the command means: gfortran -c -03 $<

Asked

Viewed 220 times

2

Guys, I’m trying to understand a program here that I’m using in my scientific initiation, but I’m left with a doubt in a make file.

# makefile for code
OBJ1 = main.o derivs.o filter.o

code: $(OBJ1)
    gfortran $(OBJ1) -o prg

.f.o:
    gfortran -c -O3 $<

clean:
    rm *~ *.o *.dat prg

The "code:", ".f.o" and "clean:" are the commands I have to use with make in order to execute the line that is just below them, from what I understood. What does that line mean? gfortran -c -O3 $<

Ahh, and just to see if I’m getting it right, the -o is to compile the code for a file, already the -c does it too, but is used for when we have to join one or more codes that are in different files, this is it?

Thanks in advance for the help.

  • I don’t really like the syntax .f.o in the Makefile. I prefer to use %.o : %.f, which means the target ended in .o depends on a file ending in .f that has the same radical

1 answer

2


Well, this is one Makefile. For more details, the GNU people provide an online manual: https://www.gnu.org/software/make/manual/make.html

Split:

  1. you are using a syntax of implicit rules
  2. it is said that any Fortan file (.f) will be transformed into an object file of same root (.o)
  3. gfortran -c -O3 $< is a command line:
    • gfortran is the name of the command to be executed
    • -c indicates that it is a partial build (output will be an object file .o)
    • -O3 is the build flag indicating the optimization level 3
    • $< is a automatic variable of Makefile; its value is the name of the first dependency of the target called, in case it can be main.f (target main.o), derivs.f (target derivs.o) or filter.f (target filter.o)

EDIT

Note that the option -o is distinct from the option -O. -o (lower case) indicates output file in GCC, and -O is the level of optimization.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.