|
| 1 | +.PHONY: help install build clean test format lint check check-all fix |
| 2 | + |
| 3 | +BUILD_DIR := build |
| 4 | +CLANG_FORMAT := $(shell if command -v clang-format >/dev/null 2>&1; then echo clang-format; fi) |
| 5 | +CLANG_TIDY := $(shell if command -v clang-tidy >/dev/null 2>&1; then echo clang-tidy; fi) |
| 6 | +CPPCHECK := $(shell if command -v cppcheck >/dev/null 2>&1; then echo cppcheck; fi) |
| 7 | +CLANG_TIDY_EXTRA_ARGS := $(shell if [ "$$(uname)" = "Darwin" ]; then echo "--extra-arg=--sysroot=$$(xcrun --show-sdk-path)"; fi) |
| 8 | + |
| 9 | +SRC_FILES := src/*.c include/*.h |
| 10 | +TEST_FILES := tests/arch/generic/*.c |
| 11 | +ALL_FILES := $(SRC_FILES) $(TEST_FILES) |
| 12 | + |
| 13 | +help: ## Show available make targets |
| 14 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ |
| 15 | + awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}' |
| 16 | + |
| 17 | +configure: ## Configure cmake |
| 18 | + cmake --preset default |
| 19 | + |
| 20 | +build: ## Build the project |
| 21 | + cmake --build --preset default |
| 22 | + |
| 23 | +clean: ## Remove build directory |
| 24 | + @test -n "$(CURDIR)" && [ "$(CURDIR)" != "/" ] |
| 25 | + rm -rf "$(CURDIR)/$(BUILD_DIR)" |
| 26 | + |
| 27 | +test: ## Build and run tests |
| 28 | + cmake --workflow --preset default |
| 29 | + |
| 30 | +format: ## Check code formatting |
| 31 | + @test -n "$(CLANG_FORMAT)" || { echo "error: clang-format not found"; exit 1; } |
| 32 | + $(CLANG_FORMAT) --dry-run --Werror $(ALL_FILES) --verbose |
| 33 | + |
| 34 | +lint: ## Check code linting |
| 35 | + @test -n "$(CLANG_TIDY)" || { echo "error: clang-tidy not found"; exit 1; } |
| 36 | + $(CLANG_TIDY) -p $(BUILD_DIR) $(CLANG_TIDY_EXTRA_ARGS) \ |
| 37 | + --header-filter="^$(CURDIR)/(src|include|tests)/" src/*.c tests/arch/generic/*.c |
| 38 | + |
| 39 | +check: ## Static analysis |
| 40 | + @test -n "$(CPPCHECK)" || { echo "error: cppcheck not found"; exit 1; } |
| 41 | + $(CPPCHECK) --enable=warning,style,performance,portability --error-exitcode=1 \ |
| 42 | + --project=$(BUILD_DIR)/compile_commands.json --suppress=missingIncludeSystem \ |
| 43 | + -i$(BUILD_DIR) |
| 44 | + |
| 45 | +check-all: format lint check ## Run all checks |
| 46 | + |
| 47 | +fix: ## Fix code formatting and linting issues |
| 48 | + @test -n "$(CLANG_FORMAT)" || { echo "error: clang-format not found"; exit 1; } |
| 49 | + $(CLANG_FORMAT) -i $(ALL_FILES) |
0 commit comments