# SPDX-License-Identifier: MIT
# Copyright (c) 2026 Lukasz P. Orlowski <lukasz@orlowski.io>. All rights granted under MIT license.

PKG_NAME = $(shell grep -A 1 "\[package\]" Cargo.toml | tail -1 | awk -F ' = ' '{ print $$2 }' | tr -d '"')
VERSION = $(shell cargo pkgid $(PKG_NAME) | awk -F '@' '{ print $$2 }')

# Build the binary
.PHONY: build
build:
	cargo build --release

# Build the binary
.PHONY: all
all:
	cargo build --all-features --release

# Build documentation for the library
.PHONY: doc
doc:
	cargo fmt --check
	cargo doc --all-features --no-deps

# Run all tests (no coverage)
.PHONY: test
test:
	cargo test --all-features

# Run unit and integration tests and measure coverage.
# Additional flags can be passed with LLVM_COV_ARGS
.PHONY: unit-test-coverage
unit-test-coverage:
	@cargo llvm-cov --lib --all-features --codecov --output-path target/unit-tests-codecov.json

.PHONY: integration-test-coverage
integration-test-coverage:
	@cargo llvm-cov --test '*' --codecov --output-path target/integration-tests-codecov.json

# Clean up
.PHONY: clean
clean:
	cargo clean

# ==== Directives for developers ====

# Print the version of the package
.PHONY: version
version:
	@echo v$(VERSION)

# Run only unit tests (shorthand for developers)
.PHONY: unit-test
unit-test:
	cargo test --lib --all-features

# Run only integration tests (shorthand for developers)
.PHONY: integration-test
integration-test:
	cargo test --test '*'

# ==== Helper directives ====

# Format codebase
.PHONY: format
format:
	cargo fmt
	dprint fmt

# Lint codebase
.PHONY: lint
lint:
	dprint check
	cargo check --all-targets --all-features
	cargo fmt --all --check
	cargo clippy --all-targets --all-features -- -D warnings
