gg=mpif90
DEPS=matrix.mod
OBJ= main.o sub1.o
main.out: $(OBJ)
$(gg) -o $@ $^
%.mod:%.90 %.o
$(gg) -c -o $@ $^
%.o:%.f90 $(DEPS)
$(gg) -c -o $@ $^
.PHONY: clean
clean:
-rm -f *.o *~
Look. The main program is main.f90
.sub1.f90
will be called by main.f90
. Both will use matrix.f90
which is a module. I know I can directly generate the executable program without compile then link
. But I do not like that way.
The mod
file is only a by-product of compiling %.o
, you shouldn't use -o $@
here, change it to
%.mod: %.90
$(gg) -c $^
This will work for most cases, but not all. That's because the name of mod
file depends only on the module name, it has nothing to do with the source file name. So the safest way is to specify the dependency explictly.
matrix.mod: matrix.f90
$(gg) -c matrix.f90
Sometimes one f90
source file can contain two or more modules.
matrix33.mod matrix99.mod: matrix.f90
$(gg) -c matrix.f90
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With