.PHONY: all help compile index catalog clean

ROOT_DIR := ..
PYTHON ?= python3

all: compile index

help:
	@echo "MarkCharm Demos Sub-Makefile"
	@echo "Usage:"
	@echo "  make all          - Compile all demos and update indexes"
	@echo "  make compile      - Compile all .mc demo files to .html"
	@echo "  make index        - Update demos/index_html.md and catalogs"
	@echo "  make minify       - Regenerate minified demo files (e.g. main.mc from original.mc.bak)"
	@echo "  make clean        - Remove generated .html files in demos/"

compile:
	@echo "[demos] Compiling all demo files..."
	cd $(ROOT_DIR) && PYTHONPATH=src $(PYTHON) scripts/compile_all_demos.py

index:
	@echo "[demos] Updating index and catalog..."
	cd $(ROOT_DIR) && PYTHONPATH=src $(PYTHON) scripts/generate_index.py

catalog: index

minify:
	@echo "[demos] Minifying heavy demo files..."
	cd $(ROOT_DIR) && $(PYTHON) scripts/mc_minify.py demos/demo_30_tr_master/original.mc demos/demo_30_tr_master/main.mc

clean:
	@echo "[demos] Removing generated HTML and DOCX demo files..."
	find . -type f \( -name "*.html" -o -name "*.docx" \) ! -name "tbl-*.html" -delete
