# Deedy-Resume (OpenFonts) build
#
# Requires: latexmk, xelatex, bibtex (TeX Live or MacTeX).
# Run all targets from the repo root — the .cls references fonts/ by
# relative path and only resolves correctly from here.

TEX     := deedy_resume-openfont.tex
NAME    := $(basename $(TEX))
DIST    := dist
PDF     := $(DIST)/$(NAME).pdf

SOURCES := $(TEX) deedy-resume-openfont.cls publications.bib

LATEXMK       := latexmk
LATEXMK_FLAGS := -xelatex -interaction=nonstopmode -halt-on-error -output-directory=$(DIST)

# Pick a PDF viewer: xdg-open on Linux, open on macOS.
VIEWER := $(shell command -v xdg-open 2>/dev/null || command -v open 2>/dev/null)

.PHONY: all build watch preview clean distclean help

all: build

## build: compile the resume into dist/
build: $(PDF)

$(PDF): $(SOURCES) | $(DIST)
	$(LATEXMK) $(LATEXMK_FLAGS) $(TEX)

$(DIST):
	mkdir -p $(DIST)

## watch: rebuild + live-preview on every save (dev mode)
watch: | $(DIST)
	$(LATEXMK) $(LATEXMK_FLAGS) -pvc $(TEX)

## preview: build once and open the PDF
preview: build
ifeq ($(VIEWER),)
	@echo "No PDF viewer found (install xdg-open or open). PDF is at $(PDF)."
else
	$(VIEWER) $(PDF)
endif

## clean: remove LaTeX aux files but keep the PDF
clean:
	-$(LATEXMK) -c -output-directory=$(DIST) $(TEX)

## distclean: remove dist/ entirely
distclean:
	rm -rf $(DIST)

## help: list available targets
help:
	@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## //'
