# Makefile for lualatex

# Paths and filenames
SRC_DIR  = src
OUT_DIR  = out
MAIN_TEX = main.tex   	# in SRC_DIR
MAIN_PDF = main.pdf  	# in OUT_DIR

# LaTeX and Biber commands

LATEX = lualatex
BIBER = biber

LATEX_OPTS := -output-directory=$(OUT_DIR) -interaction=nonstopmode -shell-escape

.PHONY: default release clean scripts

default: english
release: german english
# Default target
english: 
	sed -r -i 's/usepackage\[[^]]+\]\{babel\}/usepackage[english]{babel}/' $(SRC_DIR)/$(MAIN_TEX)
	-cd $(SRC_DIR) && latexmk -lualatex -g main.tex
	mv $(OUT_DIR)/$(MAIN_PDF) $(OUT_DIR)/$(shell date -I)_en_Formulary.pdf

german:
	sed -r -i 's/usepackage\[[^]]+\]\{babel\}/usepackage[german]{babel}/' $(SRC_DIR)/$(MAIN_TEX)
	-cd $(SRC_DIR) && latexmk -lualatex -g main.tex
	mv $(OUT_DIR)/$(MAIN_PDF) $(OUT_DIR)/$(shell date -I)_de_Formelsammlung.pdf

SCRIPT_DIR = scripts
PY_SCRIPTS = $(wildcard $(SCRIPT_DIR)/*.py)
PY_SCRIPTS_REL = $(notdir $(PY_SCRIPTS))
scripts:
	-#cd $(SCRIPT_DIR) && for file in $(find -type f -name '*.py'); do echo "Running $$file"; python3 "$$file"; done
	cd $(SCRIPT_DIR) && $(foreach script,$(PY_SCRIPTS_REL),echo "Running $(script)"; python3 $(script);)

# Clean auxiliary and output files
clean:
	rm -r $(OUT_DIR)

# Phony targets
.PHONY: all clean biber

