.PHONY: ci verify clippy tarpaulin sloc sloc-strict clean_tmp test fmt

SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -c

# 跨平台临时目录设置
ifeq ($(OS),Windows_NT)
    # Windows (Git Bash / MSYS2)
    TMP_DIR := $(shell pwd -W)/.tmp
else
    # Linux / macOS
    TMP_DIR := $(CURDIR)/.tmp
endif

TEMP_ENV := TEMP="$(TMP_DIR)" TMP="$(TMP_DIR)"

# 静默模式
ci:
	@mkdir -p .tmp
	@set -o pipefail && $(TEMP_ENV) cargo tarpaulin --config tarpaulin.toml 2>&1 | tail -n 30
	@cargo clippy --all-targets --all-features -q -- -D warnings
	@$(TEMP_ENV) sloc-guard -q check

# 正常模式
verify: tarpaulin clippy sloc fmt

clippy:
	cargo clippy --all-targets --all-features -- -D warnings

tarpaulin:
	mkdir -p .tmp
	$(TEMP_ENV) cargo tarpaulin --config tarpaulin.toml

clean_tmp:
	rm -rf .tmp


sloc:
	mkdir -p .tmp
	$(TEMP_ENV) sloc-guard check

test:
	cargo test

fmt:
	cargo fmt --all