PROJECT_NAME := voirs-evaluation
CARGO_TARGET_DIR ?= target
CARGO_FLAGS :=
FEATURES :=
RELEASE_FLAGS :=
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
PLATFORM := macos
endif
ifeq ($(UNAME_S),Linux)
PLATFORM := linux
endif
ifeq ($(UNAME_S),FreeBSD)
PLATFORM := freebsd
endif
ifdef OS
ifeq ($(OS),Windows_NT)
PLATFORM := windows
endif
endif
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
ARCH := x86_64
endif
ifeq ($(UNAME_M),arm64)
ARCH := aarch64
endif
ifeq ($(UNAME_M),aarch64)
ARCH := aarch64
endif
ifneq (,$(shell tput setaf 1 2>/dev/null))
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
BLUE := $(shell tput setaf 4)
RESET := $(shell tput sgr0)
else
RED :=
GREEN :=
YELLOW :=
BLUE :=
RESET :=
endif
.DEFAULT_GOAL := help
export CARGO_TARGET_DIR
export RUST_BACKTRACE=1
.PHONY: help info clean build build-release build-all test test-release bench docs check \
install python ci format clippy examples integration-tests doc-tests \
dev-setup platform-info
help:
@echo "$(BLUE)VoiRS Evaluation Build System$(RESET)"
@echo ""
@echo "$(GREEN)Available targets:$(RESET)"
@echo " help Show this help message"
@echo " info Show build environment information"
@echo " clean Clean build artifacts"
@echo " build Build the project (debug mode)"
@echo " build-release Build the project (release mode)"
@echo " build-all Build with all features enabled"
@echo " test Run all tests"
@echo " test-release Run tests in release mode"
@echo " bench Run benchmarks"
@echo " docs Generate documentation"
@echo " check Run code quality checks"
@echo " format Format code"
@echo " clippy Run Clippy lints"
@echo " install Install the package"
@echo " python Build Python bindings"
@echo " ci Run full CI pipeline"
@echo " dev-setup Setup development environment"
@echo " platform-info Show platform information"
@echo ""
@echo "$(GREEN)Variables:$(RESET)"
@echo " FEATURES=<features> Specify features to enable"
@echo " CARGO_FLAGS=<flags> Additional cargo flags"
@echo ""
@echo "$(GREEN)Examples:$(RESET)"
@echo " make build FEATURES=python"
@echo " make test-release"
@echo " make ci"
info: platform-info
@echo "$(BLUE)[INFO]$(RESET) Build environment information"
@echo "Platform: $(PLATFORM)"
@echo "Architecture: $(ARCH)"
@echo "Cargo target directory: $(CARGO_TARGET_DIR)"
@echo "Rust version: $$(rustc --version 2>/dev/null || echo 'Not found')"
@echo "Cargo version: $$(cargo --version 2>/dev/null || echo 'Not found')"
platform-info:
@echo "$(BLUE)[INFO]$(RESET) Platform: $(PLATFORM) ($(ARCH))"
clean:
@echo "$(BLUE)[INFO]$(RESET) Cleaning build artifacts..."
cargo clean
@if [ -d "$(CARGO_TARGET_DIR)/doc" ]; then rm -rf "$(CARGO_TARGET_DIR)/doc"; fi
@echo "$(GREEN)[SUCCESS]$(RESET) Clean completed"
build:
@echo "$(BLUE)[INFO]$(RESET) Building $(PROJECT_NAME) (debug mode)..."
cargo build $(CARGO_FLAGS) $(if $(FEATURES),--features $(FEATURES))
@echo "$(GREEN)[SUCCESS]$(RESET) Build completed"
build-release:
@echo "$(BLUE)[INFO]$(RESET) Building $(PROJECT_NAME) (release mode)..."
cargo build --release $(CARGO_FLAGS) $(if $(FEATURES),--features $(FEATURES))
@echo "$(GREEN)[SUCCESS]$(RESET) Release build completed"
build-all:
@echo "$(BLUE)[INFO]$(RESET) Building $(PROJECT_NAME) with all features..."
cargo build --all-features $(CARGO_FLAGS)
@echo "$(GREEN)[SUCCESS]$(RESET) Build with all features completed"
examples:
@echo "$(BLUE)[INFO]$(RESET) Building examples..."
cargo build --examples $(CARGO_FLAGS) $(if $(FEATURES),--features $(FEATURES))
@echo "$(GREEN)[SUCCESS]$(RESET) Examples built"
test:
@echo "$(BLUE)[INFO]$(RESET) Running tests..."
cargo test $(CARGO_FLAGS) $(if $(FEATURES),--features $(FEATURES))
@echo "$(GREEN)[SUCCESS]$(RESET) All tests passed"
test-release:
@echo "$(BLUE)[INFO]$(RESET) Running tests (release mode)..."
cargo test --release $(CARGO_FLAGS) $(if $(FEATURES),--features $(FEATURES))
@echo "$(GREEN)[SUCCESS]$(RESET) All release tests passed"
integration-tests:
@echo "$(BLUE)[INFO]$(RESET) Running integration tests..."
cargo test --test integration_tests $(CARGO_FLAGS) $(if $(FEATURES),--features $(FEATURES))
@echo "$(GREEN)[SUCCESS]$(RESET) Integration tests passed"
doc-tests:
@echo "$(BLUE)[INFO]$(RESET) Running documentation tests..."
cargo test --doc $(CARGO_FLAGS) $(if $(FEATURES),--features $(FEATURES))
@echo "$(GREEN)[SUCCESS]$(RESET) Documentation tests passed"
bench:
@echo "$(BLUE)[INFO]$(RESET) Running benchmarks..."
cargo bench --all
@echo "$(GREEN)[SUCCESS]$(RESET) Benchmarks completed"
docs:
@echo "$(BLUE)[INFO]$(RESET) Generating documentation..."
cargo doc --all-features --no-deps
@echo "$(GREEN)[SUCCESS]$(RESET) Documentation generated"
check: format clippy
@echo "$(GREEN)[SUCCESS]$(RESET) All code quality checks passed"
format:
@echo "$(BLUE)[INFO]$(RESET) Formatting code..."
cargo fmt
@echo "$(GREEN)[SUCCESS]$(RESET) Code formatted"
clippy:
@echo "$(BLUE)[INFO]$(RESET) Running Clippy lints..."
cargo clippy --all-features -- -D warnings
@echo "$(GREEN)[SUCCESS]$(RESET) Clippy checks passed"
install:
@echo "$(BLUE)[INFO]$(RESET) Installing $(PROJECT_NAME)..."
cargo install --path . --all-features
@echo "$(GREEN)[SUCCESS]$(RESET) Installation completed"
python:
@echo "$(BLUE)[INFO]$(RESET) Building Python bindings..."
@if ! command -v python3 >/dev/null 2>&1 && ! command -v python >/dev/null 2>&1; then \
echo "$(RED)[ERROR]$(RESET) Python is required for building Python bindings"; \
exit 1; \
fi
cargo build --release --features python
@if command -v maturin >/dev/null 2>&1; then \
maturin build --release --features python; \
else \
echo "$(YELLOW)[WARNING]$(RESET) maturin not found. Install with: pip install maturin"; \
fi
@echo "$(GREEN)[SUCCESS]$(RESET) Python bindings built"
dev-setup:
@echo "$(BLUE)[INFO]$(RESET) Setting up development environment..."
@ @if ! command -v rustfmt >/dev/null 2>&1; then \
echo "Installing rustfmt..."; \
rustup component add rustfmt; \
fi
@if ! command -v cargo-clippy >/dev/null 2>&1; then \
echo "Installing clippy..."; \
rustup component add clippy; \
fi
@ @echo "Consider installing additional development tools:"
@echo " cargo install cargo-udeps @echo " cargo install cargo-audit @echo " cargo install cargo-watch @echo "$(GREEN)[SUCCESS]$(RESET) Development environment setup completed"
ci: clean check build-all test docs
@echo "$(GREEN)[SUCCESS]$(RESET) CI pipeline completed successfully"
dev: format clippy test
@echo "$(GREEN)[SUCCESS]$(RESET) Development cycle completed"
watch:
@if command -v cargo-watch >/dev/null 2>&1; then \
echo "$(BLUE)[INFO]$(RESET) Starting file watcher..."; \
cargo watch -x "build" -x "test"; \
else \
echo "$(RED)[ERROR]$(RESET) cargo-watch not installed. Install with: cargo install cargo-watch"; \
exit 1; \
fi
audit:
@if command -v cargo-audit >/dev/null 2>&1; then \
echo "$(BLUE)[INFO]$(RESET) Running security audit..."; \
cargo audit; \
echo "$(GREEN)[SUCCESS]$(RESET) Security audit completed"; \
else \
echo "$(YELLOW)[WARNING]$(RESET) cargo-audit not installed. Install with: cargo install cargo-audit"; \
fi
unused-deps:
@if command -v cargo-udeps >/dev/null 2>&1; then \
echo "$(BLUE)[INFO]$(RESET) Checking for unused dependencies..."; \
cargo +nightly udeps --all-features; \
echo "$(GREEN)[SUCCESS]$(RESET) Unused dependency check completed"; \
else \
echo "$(YELLOW)[WARNING]$(RESET) cargo-udeps not installed. Install with: cargo install cargo-udeps"; \
fi
profile:
@echo "$(BLUE)[INFO]$(RESET) Building with profiling enabled..."
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --release
@echo "$(GREEN)[SUCCESS]$(RESET) Profile build completed"
size-opt:
@echo "$(BLUE)[INFO]$(RESET) Building for size optimization..."
RUSTFLAGS="-C opt-level=z -C target-cpu=native" cargo build --release
@echo "$(GREEN)[SUCCESS]$(RESET) Size-optimized build completed"
perf-opt:
@echo "$(BLUE)[INFO]$(RESET) Building for performance optimization..."
RUSTFLAGS="-C opt-level=3 -C target-cpu=native" cargo build --release
@echo "$(GREEN)[SUCCESS]$(RESET) Performance-optimized build completed"