CANDIDATE = Max_Mustermann
OUTPUT_NAME  = IPA_Dokumentation_$(CANDIDATE).pdf

## drawio variables
DRAWIO_CMD   = drawio
DRAWIO_DIR = 02_Grafiken

DIAGRAM_SRCS= $(wildcard $(DRAWIO_DIR)/*.drawio)
DIAGRAMS = $(DIAGRAM_SRCS:drawio=pdf)


# Find files specifically inside the subdirectory

.PHONY: build-all
build-all: $(OUTPUT_NAME)

$(OUTPUT_NAME): $(DIAGRAMS)  03_Zeitplan/Zeitplan.pdf sourcepaths.txt versionhistory.csv
	typst compile ./main.typ $(OUTPUT_NAME) --root . 

.PHONY: watch 
watch:  $(DIAGRAMS) 03_Zeitplan/Zeitplan.pdf sourcepaths.txt versionhistory.csv timetable.yaml
	typst watch ./main.typ $(OUTPUT_NAME) --root .


03_Zeitplan/Zeitplan.pdf: 03_Zeitplan/Zeitplan.xlsx
	soffice --headless --convert-to 'pdf:calc_pdf_Export:{}' 03_Zeitplan/Zeitplan.xlsx --outdir 03_Zeitplan/

.PHONY: sourcepaths.txt
sourcepaths.txt:
	bash -c "cd 04_Code && git ls-files > ../sourcepaths.txt"

.PHONY: versionhistory.csv
versionhistory.csv:
	git log --pretty=format:"%ad,%an,%s" --date=short > ./versionhistory.csv

timetable.yaml: 03_Zeitplan/Zeitplan.xlsx
	bash -c "cd 03_Zeitplan && python3 export.py > ../timetable.yaml"



.PHONY: drawio
drawio: $(DIAGRAMS)

# Pattern rule to convert .drawio -> .pdf inside the subdirectory
# $(DRAWIO_DIR)/%.pdf matches files like "05_Diagrams/network.pdf"
$(DRAWIO_DIR)/%.pdf: $(DRAWIO_DIR)/%.drawio
	$(DRAWIO_CMD) -x -f pdf --crop -o $@ $<



