SHELL=/usr/bin/bash
PAPER=main.tex
LATEX=lualatex  # Change to xelatex if you prefer XeLaTeX

# Extract the version string from main.tex (e.g., v1.0.0)
VERSION := $(shell grep -oP 'doc version: \Kv[0-9]+\.[0-9]+\.[0-9]+' $(PAPER))
PDF=Auboard_15P_Development_Kit_$(VERSION)

all :
	@echo '.........: Building $(PDF).pdf'
	@echo '.........: $(LATEX) running pass 1...'
	$(LATEX) -jobname=$(PDF) $(PAPER) 2>&1 | tee errors.err
	@echo '.........: biber running...'
	biber $(PDF) 2>&1 | tee -a errors.err
	@echo '.........: $(LATEX) running pass 2...'
	$(LATEX) -jobname=$(PDF) $(PAPER) 2>&1 | tee -a errors.err
	@echo '.........: $(LATEX) and biber run finished. Output: $(PDF).pdf'

clean :
	-rm -f errors.err
	-rm -f *.aux
	-rm -f *.bbl
	-rm -f *.blg
	-rm -f *.log
	-rm -f *.out
	-rm -f *.run.xml
	-rm -f *.toc
	-rm -f *.lsttmp
	-rm -f *.bcf
	-rm -f *.atfi
	-rm -f Auboard_15P_Development_Kit_*.pdf
	-rm -f BUILD
	@echo '.........: Cleaned up temporary files.'

