SRC := $(wildcard *.F)
OBJ := $(addsuffix .o, $(basename $(SRC)))
DEP := $(addsuffix .d, $(basename $(SRC)))

FFLAGS += -g -O2 -march=native -fno-f2c -fno-range-check -fno-second-underscore --param=ssp-buffer-size=4 -fno-automatic -std=legacy -ffixed-line-length-72 -fno-backslash -fno-bounds-check -fcommon -fcf-protection -fallow-invalid-boz -fallow-argument-mismatch -fno-align-commons -fno-aggressive-loop-optimizations -fstack-protector -finit-local-zero -fbacktrace

CPPFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2

all: libminicl.a

.PHONY: clean all

libminicl.a: $(OBJ)
	ar rcs $@ $^

clean:
	rm -f *.o *.d *.a

%.d: %.F
	set -e; rm -f $@; $(FC) $(FFLAGS) -M $(CPPFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm -f $@.$$$$

include $(DEP)


