Boilerplate example for a simple Fortran program with three object files.
Note: The $(BINARY)
definition is the more boilerplatish one. But it doesn't resolve in my make
command line tab completion.
Tested with GNU Make 3.81.
FC = pgfortran | |
FCFLAGS += -Minfo=all | |
SOURCE=thebinary.F90 | |
# BINARY=$(patsubst %.F90, %.bin, $(SOURCE)) # Alternative: Instead of calling it manually `thebinary.bin`, use $(BINARY). This is not resolved by my command line tab autocompliation, hence I rather not do it | |
DEPENDENCIES=a.o b.o c.o | |
.PHONY: all | |
all: message thebinary.bin | |
thebinary.bin: Makefile $(SOURCE) $(DEPENDENCIES) | |
${FC} ${FCFLAGS} -o $@ $(SOURCE) $(DEPENDENCIES) | |
%.o: %.F90 Makefile | |
${FC} ${FCFLAGS} -c $< | |
%.o: %.mod | |
.PHONY: clean clean_bin clean_mod clean_o | |
clean: clean_bin clean_mod clean_o | |
clean_bin: | |
rm *.bin | |
clean_mod: | |
rm *.mod | |
clean_o: | |
rm *.o | |
.PHONY: run | |
run: thebinary.bin | |
./thebinary.bin | |
.PHONY: message | |
message: | |
@echo "FC: "${FC} | |
@echo "FCFLAGS: "${FCFLAGS} |