.PHONY: all pack clean test doc run stddev help

# Default target
all: install-deps

# Install Python dependencies from requirements.txt
install-deps:
	pip3 install -r requirements.txt

# Run unit tests for the math library
test:
	python3 -m pytest calc_tests.py -v 2>/dev/null || python3 -m unittest discover -s . -p "calc_tests.py" -v

# Generate documentation using Doxygen
doc:
	doxygen Doxyfile

# Run the main calculator application
run: install-deps
	python3 -m application

# Prepare and run the standard deviation profiling program
# Python script - just ensure dependencies are installed
stddev: install-deps
	@echo "Running stddev program for profiling..."
	@echo "Usage: python3 stddev.py < input.txt"
	@echo "Or: cat data.txt | python3 stddev.py"

# Package the project for submission
pack: clean
	cd .. && tar -czf IVS_projekt2.tar.gz \
		--exclude='.git' \
		--exclude='__pycache__' \
		--exclude='*.pyc' \
		--exclude='.pytest_cache' \
		--exclude='doxygen_output' \
		--exclude='html' \
		--exclude='latex' \
		--exclude='*.tar.gz' \
		--exclude='.venv' \
		--exclude='venv' \
		README.md \
		LICENSE \
		src/ \
		plan/ \
		profiling/ \
		mockup/ \
		debugging.png \
		debugging.jpg \
		debugging.pdf \
		manual.pdf \
		screenshot.png \
		screenshot.jpg \
		skutecnost.txt \
		hodnoceni.txt \
		.gitignore \
		.editorconfig

# Clean build artifacts and temporary files
clean:
	find .. -type d -name '__pycache__' -exec rm -rf {} + 2>/dev/null || true
	find .. -type f -name '*.pyc' -delete 2>/dev/null || true
	find .. -type d -name '.pytest_cache' -exec rm -rf {} + 2>/dev/null || true
	find .. -type d -name 'doxygen_output' -exec rm -rf {} + 2>/dev/null || true
	find .. -type d \( -name 'html' -o -name 'latex' \) -exec rm -rf {} + 2>/dev/null || true
	rm -rf ../IVS_projekt2.tar.gz 2>/dev/null || true

# Display help information
help:
	@echo "=========================================="
	@echo "IVS Projekt 2 - Calculator Application"
	@echo "Makefile Targets - GNU Make"
	@echo "=========================================="
	@echo ""
	@echo "Usage: make [target]"
	@echo "       make (without target executes 'all')"
	@echo ""
	@echo "Available targets:"
	@echo ""
	@echo "  all       Install Python dependencies (PyQt5) from requirements.txt"
	@echo "            Run this first on fresh VM installation"
	@echo "            DEFAULT TARGET: automatically executed when running 'make'"
	@echo ""
	@echo "  install-deps"
	@echo "            Install all Python dependencies listed in requirements.txt"
	@echo ""
	@echo "  run       Run the calculator GUI application"
	@echo "            Requires: 'make all' to be run first for dependencies"
	@echo ""
	@echo "  test      Run unit tests for the mathematical library"
	@echo "            Tests located in: calc_tests.py"
	@echo ""
	@echo "  doc       Generate API documentation using Doxygen"
	@echo "            Configuration file: Doxyfile"
	@echo "            Output: doxygen_output/ directory"
	@echo ""
	@echo "  stddev    Prepare the standard deviation profiling program"
	@echo "            Usage: python3 stddev.py < data.txt"
	@echo "            Calculates sample standard deviation from input numbers"
	@echo ""
	@echo "  pack      Create a distributable archive (IVS_projekt2.tar.gz)"
	@echo "            Automatically runs 'make clean' first"
	@echo "            Includes: source code, docs, profiling data, mockups"
	@echo "            Excludes: build artifacts, caches, compiled files"
	@echo ""
	@echo "  clean     Remove all generated files and temporary artifacts"
	@echo "            Removes: __pycache__, *.pyc, .pytest_cache,"
	@echo "            Doxygen output, build archives"
	@echo ""
	@echo "  help      Display this help message"
	@echo ""
	@echo "=========================================="
	@echo "Quick Start on Virtual Machine:"
	@echo "=========================================="
	@echo "1. make all        (install dependencies)"
	@echo "2. make run        (start the calculator)"
	@echo "3. make test       (run unit tests)"
	@echo "4. make doc        (generate documentation)"
	@echo "5. make pack       (create submission archive)"
	@echo "=========================================="
	@echo ""
	@echo "Compilation on VM without Makefile:"
	@echo "  cd src/"
	@echo "  pip3 install -r requirements.txt"
	@echo "  python3 -m application"
	@echo ""
	@echo "=========================================="
