SOURCE ?= feature_definition.tex
TARGET ?= $(subst .tex,.pdf,$(SOURCE))
GRPH_DIR ?= graphics
GRPH_SOURCE ?= $(wildcard $(GRPH_DIR)/*.tex)
GRPH_TARGET ?= $(subst .tex,.pdf,$(GRPH_SOURCE))

JOBNAME = $(subst .pdf,,$(TARGET))

# build configuration

LATEXMK ?= latexmk
# for pdflatex: LATEXMK_TARGET = -pdf
# for latex -> dvi -> pdf: LATEXMK_TARGET = -pdfdvi
LATEXMK_TARGET += -xelatex
LATEXMK_OPTS += -recorder -use-make -latexoption="-interaction=nonstopmode -synctex=1" 
LATEXMK_ARTIFACTS += *.bbl
LATEXMK_ARTIFACTS += *.synctex.gz
LATEXMK_ARTIFACTS += *-converted-to.pdf
LATEXMK_ARTIFACTS += *.synctex.gz\(busy\)
LATEXMK_ARTIFACTS += *.rro
LATEXMK_ARTIFACTS += *.aux
LATEXMK_ARTIFACTS += *.run.xml

$(TARGET): $(SOURCE) $(GRPH_TARGET)
	$(LATEXMK) $(LATEXMK_OPTS) $(LATEXMK_TARGET) $<

$(GRPH_DIR)/%.pdf: $(GRPH_DIR)/%.tex
	$(LATEXMK) -lualatex -outdir=$(GRPH_DIR) $(LATEXMK_OPTS) $<

.PHONY: clean Clean
clean: 
	$(LATEXMK) $(SOURCE) -c

Clean:
	$(LATEXMK) $(SOURCE) -C
	$(LATEXMK) -outdir=$(GRPH_DIR) $(GRPH_SOURCE) -C
	rm -f $(LATEXMK_ARTIFACTS)

