# =============================================================================
# Makefile — Differential Equations Handbook
# =============================================================================

TARGET = main
TEX    = pdflatex
BIBTEX = bibtex

.PHONY: all quick clean view distclean

## all: Full build (pdflatex -> bibtex if needed -> pdflatex x2)
all:
	$(TEX) -interaction=nonstopmode $(TARGET).tex
	@if [ -f $(TARGET).blg ] || grep -ql '\\bibliography\|\\bibliographystyle' $(TARGET).tex; then \
		$(BIBTEX) $(TARGET); \
		$(TEX) -interaction=nonstopmode $(TARGET).tex; \
		$(TEX) -interaction=nonstopmode $(TARGET).tex; \
	fi

## quick: Single pdflatex pass for rapid iteration
quick:
	$(TEX) -interaction=nonstopmode $(TARGET).tex

## clean: Remove all auxiliary files
clean:
	rm -f $(TARGET).aux $(TARGET).log $(TARGET).out $(TARGET).toc \
	      $(TARGET).lof $(TARGET).lot $(TARGET).nls $(TARGET).nlo \
	      $(TARGET).vrb $(TARGET).synctex.gz $(TARGET).fls $(TARGET).out \
	      $(TARGET).blg $(TARGET).bbl $(TARGET).run.xml

## view: Open the resulting PDF
view:
	xdg-open $(TARGET).pdf

## distclean: Clean + remove PDF
distclean: clean
	rm -f $(TARGET).pdf
