Skip to content

Instantly share code, notes, and snippets.

@AndiH
Last active May 10, 2016 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndiH/384e34924a1fade9cbc83421c0808f21 to your computer and use it in GitHub Desktop.
Save AndiH/384e34924a1fade9cbc83421c0808f21 to your computer and use it in GitHub Desktop.
Fortran Makefile Boilerplate

Fortran Makefile Boilerplate

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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment