NPROCS = $(shell grep -c 'processor' /proc/cpuinfo)
TEX_PDF_ENGINE=pdflatex

include submission.mk

OUT_DIR = out
SRC_DIR = src

MAKEFLAGS += -j$(NPROCS)
TEX = pandoc
TEX_FLAGS = --pdf-engine=$(TEX_PDF_ENGINE) --template=templates/default.latex -F mermaid-filter --filter pandoc-plot


all: $(SUBMISSION_FILENAME)

loop:
	find -name '*.md' -or -name '*.tex' | entr make all

$(SUBMISSION_FILENAME): .PHONY $(OUT_DIR)
	$(TEX) $(SRC_DIR)/submission.md -o $(OUT_DIR)/$@ $(TEX_FLAGS)
	mv mermaid-filter.err $(OUT_DIR)

$(OUT_DIR):
	mkdir -p $(OUT_DIR)


.PHONY:
clean :
	rm -rf $(OUT_DIR)
