# Makefile for LaTeX documents

LATEX=latexmk
BIBTEX=biber
LATEX_FLAGS=-xelatex -shell-escape -synctex=1 -interaction=nonstopmode

SOURCE=Main.tex
PDF=$(SOURCE:.tex=.pdf)

OUT_DIR=Output

BUILD_DIR=Build

PDF_SOURCE=$(BUILD_DIR)/$(PDF)
PDF_TARGET=$(OUT_DIR)/$(PDF)
VERSION=v1.2

all: compile
	xdg-open $(PDF_TARGET)

clean:
	git clean -dfX

pdfs:
	# Make all PDFs for the VERSION (branches VERSION/QSM, VERSION/VSM and VERSION/VGL)
	git checkout $(VERSION)/QSM
	make compile
	cp $(PDF_TARGET) $(OUT_DIR)/$(VERSION)_QSM.pdf
	git checkout $(VERSION)/VSM
	make compile
	cp $(PDF_TARGET) $(OUT_DIR)/$(VERSION)_VSM.pdf
	git checkout $(VERSION)/VGL
	make compile
	cp $(PDF_TARGET) $(OUT_DIR)/$(VERSION)_VGL.pdf
	git checkout master

compile:
# If not Exists, create 'Build' directory
	[ -d $(BUILD_DIR) ] || mkdir -p $(BUILD_DIR)
	$(LATEX) $(LATEX_FLAGS) -output-directory=$(BUILD_DIR) $(SOURCE)
# If not Exists, create 'Output/' directory
	[ -d $(OUT_DIR) ] || mkdir -p $(OUT_DIR)
# Copy the PDF to the 'Output/' directory
	cp $(PDF_SOURCE) $(PDF_TARGET)

.PHONY: all clean
