-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (82 loc) · 3.53 KB
/
Makefile
File metadata and controls
101 lines (82 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
################################################################################
# Configuration and Variables
################################################################################
ZIG_LOCAL := $(HOME)/.local/share/zig/0.16.0/zig
ZIG ?= $(shell test -x $(ZIG_LOCAL) && echo $(ZIG_LOCAL) || which zig)
ZIG_VERSION := $(shell $(ZIG) version)
BUILD_TYPE ?= Debug
BUILD_OPTS = -Doptimize=$(BUILD_TYPE)
JOBS ?= $(shell nproc || echo 2)
SRC_DIR := src
TEST_DIR := tests
BUILD_DIR := zig-out
CACHE_DIR := .zig-cache
DOC_SRC := src/lib.zig
DOC_OUT := docs/api
RELEASE_MODE := ReleaseSmall
# Get all .zig files in the examples directory and extract their stem names
EXAMPLES := $(patsubst %.zig,%,$(notdir $(wildcard examples/*.zig)))
EXAMPLE ?= all
SHELL := /usr/bin/env bash
.SHELLFLAGS := -eu -o pipefail -c
################################################################################
# Targets
################################################################################
.PHONY: all build rebuild example test lint format docs docs-serve clean install-deps release help coverage \
setup-hooks test-hooks
.DEFAULT_GOAL := help
help: ## Show the help messages for all targets
@grep -E '^[a-zA-Z0-9_-]+:.*?## ' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " %-10s %s\n", $$1, $$2}'
all: build test lint docs ## build, test, lint, and docs
build: ## Build project (Mode=$(BUILD_TYPE))
@echo "Building project in $(BUILD_TYPE) mode with $(JOBS) concurrent jobs..."
$(ZIG) build $(BUILD_OPTS) -j$(JOBS)
rebuild: clean build ## clean and build
example: ## Run examples (default: all tests, or 'make example EXAMPLE=e1_transitive_closure')
ifeq ($(EXAMPLE),all)
@for ex in $(EXAMPLES); do \
echo "--> Running example: $$ex"; \
$(ZIG) build run-$$ex $(BUILD_OPTS); \
done
else
@echo "--> Running example: $(EXAMPLE)"
$(ZIG) build run-$(EXAMPLE) $(BUILD_OPTS)
endif
test: ## Run all tests (unit tests and tests in the `tests/` directory)
@echo "Running tests..."
$(ZIG) build test $(BUILD_OPTS) -j$(JOBS) --summary all
release: ## Build in Release mode
@echo "Building the project in Release mode..."
@$(MAKE) BUILD_TYPE=$(RELEASE_MODE) build
clean: ## Remove docs, build artifacts, and cache directories
@echo "Removing build artifacts, cache, generated docs, and coverage files..."
rm -rf $(BUILD_DIR) $(CACHE_DIR) $(DOC_OUT) *.profraw
lint: ## Check code style and formatting of Zig files
@echo "Running code style checks..."
$(ZIG) fmt --check $(SRC_DIR) $(TEST_DIR)
format: ## Format Zig files
@echo "Formatting Zig files..."
$(ZIG) fmt .
docs: ## Generate API documentation
@echo "Generating documentation..."
$(ZIG) build docs
@echo "Copying documentation to $(DOC_OUT)..."
rm -rf $(DOC_OUT)
mkdir -p $(DOC_OUT)
cp -r $(BUILD_DIR)/docs/* $(DOC_OUT)
docs-serve: ## Serve API documentation locally
@echo "Serving documentation locally"
cd $(DOC_OUT) && python3 -m http.server 8000
install-deps: ## Install system dependencies (for Debian-based systems)
@echo "Installing system dependencies..."
sudo apt-get update
sudo apt-get install -y make llvm snapd
sudo snap install zig --beta --classic # Use `--edge --classic` to install the latest version
setup-hooks: ## Install Git hooks (pre-commit and pre-push)
@echo "Installing Git hooks..."
@pre-commit install --hook-type pre-commit
@pre-commit install --hook-type pre-push
@pre-commit install-hooks
test-hooks: ## Run Git hooks on all files manually
@echo "Running Git hooks..."
@pre-commit run --all-files