.PHONY: all build json json-2 fast clean norm tests fix-permissions help

all: clean json build json-2

build:
	@echo "Building project (full rebuild with search index)..."
	emacs -Q --script lisp/build.el

json:
	@echo "Generating the JSON output..."
	/usr/bin/python3 search-index.py

json-2:
	@echo "Generating the JSON output 2..."
	/usr/bin/python3 generate_sidebar_tree.py

fast:
	@echo "Building project (fast rebuild without search index)..."
	emacs -Q --script lisp/build.el --fast

clean:
	@echo "Cleaning output directory..."
	rm -rf output/

norm:
	@echo "sorting out the backups..."
	find . -path ./backups -prune -o -type f -name '*~' -exec mv {} backups/ \;

tests:
	@echo "Running all the tests..."
	emacs -batch -l ert -l tests/macros-tests.el -f ert-run-tests-batch-and-exit

fix-permissions:
	echo "shakkal123" | sudo -S chown -R zaine:zaine .

restore-permissions:
	echo "shakkal123" | sudo -S chown -R 33:33 .

help:
	@echo "Available targets:"
	@echo "  make        - Clean, build, and generate search index (default)"
	@echo "  make build  - Full rebuild (with search index)"
	@echo "  make json   - Generate JSON output for search index"
	@echo "  make fast   - Fast rebuild (without search index)"
	@echo "  make clean  - Remove output directory"
	@echo "  make tests  - Run all of the tests associated with the project"
	@echo "  make norm   - Move all files that end with ~ to the backup folder"
	@echo "  make fix-permissions - Fix permissions for the project directory (requires sudo)"
	@echo "  make restore-permissions - Restore permissions for the project directory (requires sudo)"
	@echo "  make help   - Show this help message"
