BUILD		?=		cmake -B build -G Ninja
NINJA		?=		ninja -C build
COMPILE		?=		$(BUILD) && $(NINJA)
INSTALL		?=		$(BUILD) && $(NINJA) && sudo ninja -C build install

CPPFMT ?=		find . \( -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -not -path './build/*' -exec clang-format -i --style=file {} +

NUITKA ?=		nuitka --module --include-package=zshell cli/src/zshell/ --output-dir=cli/

.DEFAULT_GOAL := help

# string is misaligned to align when run in terminal
help:
	@echo "build			cmake builds into build directory"
	@echo "install			cmake builds, compiles and installs into filesystem"
	@echo "compile			cmake builds and compiles C++ code"
	@echo "cpp-fmt			format C++ code with clang-format"
	@echo "cpp-lint		lint check C++ code with clang-tidy"
	@echo "cpp-compile		alias to make compile"
	@echo "py-fmt			format Python code with ruff"
	@echo "py-lint			lint check Python code with ruff"
	@echo "py-check		lsp and typecheck all Python code using Basedpyright"
	@echo "py-test			run all Python tests using Pytest"
	@echo "py-compile		compiles Python code using Nuitka"
	@echo "rs-compile		compiles Rust code"
	@echo "rs-format		formats Rust code with Rustfmt"
	@echo "rs-lint			lint check Rust code with Clippy"
	@echo "rs-test			runs all Rust tests"
	@echo "check-cpp		runs all C++ checks"
	@echo "check-py		runs all Python checks"
	@echo "check-rs		runs all Rust checks"

build:
	$(BUILD)

install:
	$(INSTALL)

compile:
	$(COMPILE)

# TODO: Anything below is not ready

# C++
cpp-fmt:
	$(CPPFMT)

# cpp-lint needs adjustments in ci and here

cpp-compile:
	$(COMPILE)

# Python
py-fmt:
	ruff format --check

py-lint:
	ruff check ./cli

py-check:
	basedpyright

py-test:
	python -m pytest ./cli/tests/ -v

# Want to use gcc, clang or zig C compiler instead? Output directory?
py-compile:
	$(NUITKA)

# Rust
rs-compile:
	cd ./zshell-img-tools/ && cargo run

rs-fmt:
	cd ./zshell-img-tools/ && cargo fmt && echo "formatted!"

rs-lint:
	cd ./zshell-img-tools/ && cargo clippy

rs-test:
	cd ./zshell-img-tools/ && cargo test

# Qml


# Full checks
check-cpp:
	$(MAKE) cpp-fmt
	$(MAKE) cpp-lint
	$(MAKE) install

check-rs:
	$(MAKE) rs-fmt
	$(MAKE) rs-lint
	$(MAKE) rs-test
	$(MAKE) rs-compile

check-py:
	$(MAKE) py-fmt
	$(MAKE) py-lint
	$(MAKE) py-test
	$(MAKE) py-check
	$(MAKE) py-compile
