# Build CV variants to ./build/<name>.pdf using a dockerised XeLaTeX.
# Run `make` (or `make full`) to build the full CV. Add new targets per variant.

DOCKER_IMAGE := texlive/texlive:latest
BUILD_DIR    := build
ENGINE       := xelatex

# Run the container with the current dir mounted. UID:GID match avoids root-owned outputs.
# TEXINPUTS prepends ./tex-vendor so altacv.cls (vendored) is found.
DOCKER_RUN = docker run --rm \
  -u $(shell id -u):$(shell id -g) \
  -v $(CURDIR):/work \
  -w /work \
  -e TEXINPUTS=.:./tex-vendor: \
  $(DOCKER_IMAGE)

.PHONY: all full clean shell
all: full

# Pattern rule: build/<name>.pdf is built from <name>.tex by running xelatex twice
# (twice to settle cross-references / hyperref).
$(BUILD_DIR)/%.pdf: %.tex preamble.tex $(wildcard chapters/*.tex) | $(BUILD_DIR)
	$(DOCKER_RUN) $(ENGINE) -interaction=nonstopmode -halt-on-error \
	    -output-directory=$(BUILD_DIR) $<
	$(DOCKER_RUN) $(ENGINE) -interaction=nonstopmode -halt-on-error \
	    -output-directory=$(BUILD_DIR) $<

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

full: $(BUILD_DIR)/cv-full.pdf

# Drop into an interactive TeX-Live shell (handy for debugging).
shell:
	docker run --rm -it -u $(shell id -u):$(shell id -g) \
	    -v $(CURDIR):/work -w /work $(DOCKER_IMAGE) bash

clean:
	rm -rf $(BUILD_DIR)
