OPTIONS = markdown+yaml_metadata_block+smart

NOTES = $(wildcard prelim_notes/*.md)
NOTES_PDFS = $(patsubst %.md,%.pdf,$(NOTES))

THESIS = LaTeX/thesis.tex
THESIS_PDF = thesis.pdf

all: $(THESIS_PDF) $(NOTES_PDFS)

$(NOTES_PDFS): $(NOTES)
	pandoc \
		--variable mainfont="Roboto" \
		--variable monofont="Fira Code" \
		--variable fontsize=11pt \
		--variable geometry:"top=1in, bottom=1in, left=1in, right=1in" \
		--variable geometry:letterpaper \
		-f markdown  $< \
		-o $@

thesis_pdf/:
	mkdir $@

$(THESIS_PDF): $(THESIS) LaTeX/thesis.bib
	mkdir -p temp
	cp -r LaTeX/fig .
	cp -r LaTeX/flowcharts .
	cp -r LaTeX/thesis.tex .
	cp -r LaTeX/macros.tex .
	cp -r LaTeX/thesis.bib .
	cp -r LaTeX/thesis.cls .
	xelatex thesis
	bibtex thesis
	xelatex thesis
	xelatex thesis
	rm -rf fig
	rm -rf flowcharts
	cp thesis.pdf temp/.
	rm -rf macros.tex
	rm -rf thesis.*
	cp temp/thesis.pdf .
	rm -rf temp

.PHONY: clean revise

clean:
	rm -rf $(THESIS_PDF)
	rm -rf $(NOTES_PDFS)
	rm -rf thesis_pdf

revise: $(THESIS) LaTeX/thesis.bib
	mkdir -p temp
	cp -r LaTeX/fig .
	cp -r LaTeX/flowcharts .
	cp -r LaTeX/thesis.tex .
	cp -r LaTeX/macros.tex .
	cp -r LaTeX/thesis.bib .
	cp -r LaTeX/thesis.cls .
	xelatex thesis
	bibtex thesis
	xelatex thesis
	xelatex thesis
	rm -rf fig
	rm -rf flowcharts
	cp thesis.pdf temp/.
	rm -rf macros.tex
	rm -rf thesis.*
	cp temp/thesis.pdf .
