-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (102 loc) · 4.25 KB
/
Makefile
File metadata and controls
123 lines (102 loc) · 4.25 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# ################################################################################
# # Configuration and Variables
# ################################################################################
ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.15.2/zig)
BUILD_TYPE ?= Debug
BUILD_OPTS = -Doptimize=$(BUILD_TYPE)
JOBS ?= $(shell nproc || echo 2)
SRC_DIR := src
EXAMPLES_DIR := examples
BENCHMARKS_DIR:= benches
BUILD_DIR := zig-out
CACHE_DIR := .zig-cache
BINARY_NAME := example
RELEASE_MODE := ReleaseSmall
TEST_FLAGS := --summary all #--verbose
JUNK_FILES := *.o *.obj *.dSYM *.dll *.so *.dylib *.a *.lib *.pdb temp/
# Automatically find all example names
EXAMPLES := $(patsubst %.zig,%,$(notdir $(wildcard examples/*.zig)))
EXAMPLE ?= all
# Automatically find all benchmark names
BENCHMARKS := $(patsubst %.zig,%,$(notdir $(wildcard benches/*.zig)))
BENCHMARK ?= all
SHELL := /usr/bin/env bash
.SHELLFLAGS := -eu -o pipefail -c
################################################################################
# Targets
################################################################################
.PHONY: all help build rebuild run bench test release clean lint format docs serve-docs install-deps setup-hooks test-hooks
.DEFAULT_GOAL := help
help: ## Show the help messages for all targets
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@grep -E '^[a-zA-Z_-]+:.*## .*$$' Makefile | \
awk 'BEGIN {FS = ":.*## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
all: build test lint docs ## build, test, lint, and doc
build: ## Build project (e.g. 'make build BUILD_TYPE=ReleaseSmall' or 'make build' for Debug mode)
@echo "Building project in $(BUILD_TYPE) mode with $(JOBS) concurrent jobs..."
@$(ZIG) build $(BUILD_OPTS) -j$(JOBS)
rebuild: clean build ## clean and build
run: ## Run an example (like 'make run EXAMPLE=e1_btree_map' or 'make run' to run all examples)
@if [ "$(EXAMPLE)" = "all" ]; then \
echo "--> Running all examples..."; \
for ex in $(EXAMPLES); do \
echo ""; \
echo "--> Running '$$ex'"; \
$(ZIG) build run-$$ex $(BUILD_OPTS); \
done; \
else \
echo "--> Running example: $(EXAMPLE)"; \
$(ZIG) build run-$(EXAMPLE) $(BUILD_OPTS); \
fi
bench: ## Run a benchmark (like 'make bench BENCHMARK=b1_btree_map' or 'make run' to run all benchmarks)
@if [ "$(BENCHMARK)" = "all" ]; then \
echo "--> Running all benchmarks..."; \
for ex in $(BENCHMARKS); do \
echo ""; \
echo "--> Running '$$ex'"; \
$(ZIG) build bench-$$ex $(BUILD_OPTS); \
done; \
else \
echo "--> Running benchmark: $(BENCHMARK)"; \
$(ZIG) build bench-$(BENCHMARK) $(BUILD_OPTS); \
fi
test: ## Run tests
@echo "Running tests..."
@$(ZIG) build test $(BUILD_OPTS) -j$(JOBS) $(TEST_FLAGS)
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 junk files..."
@rm -rf $(BUILD_DIR) $(CACHE_DIR) $(JUNK_FILES) docs/api public
lint: ## Check code style and formatting of Zig files
@echo "Running code style checks..."
@$(ZIG) fmt --check $(SRC_DIR) $(EXAMPLES_DIR)
format: ## Format Zig files
@echo "Formatting Zig files..."
@$(ZIG) fmt .
docs: ## Generate API documentation
@echo "Generating API documentation..."
@$(ZIG) build docs
serve-docs: ## Serve the generated documentation on a local server
@echo "Serving API documentation locally..."
@cd docs/api && 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
setup-hooks: ## Install Git hooks (pre-commit and pre-push)
@echo "Setting up Git hooks..."
@if ! command -v pre-commit &> /dev/null; then \
echo "pre-commit not found. Please install it using 'pip install pre-commit'"; \
exit 1; \
fi
@pre-commit install --hook-type pre-commit
@pre-commit install --hook-type pre-push
@pre-commit install-hooks
test-hooks: ## Test Git hooks on all files
@echo "Testing Git hooks..."
@pre-commit run --all-files --show-diff-on-failure