11# ################################################################################
22# # Configuration and Variables
33# ################################################################################
4- ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.14 .1/zig)
4+ ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.15 .1/zig)
55BUILD_TYPE ?= Debug
66BUILD_OPTS = -Doptimize=$(BUILD_TYPE )
77JOBS ?= $(shell nproc || echo 2)
88SRC_DIR := src
99EXAMPLES_DIR := examples
10+ BENCHMARKS_DIR: = benches
1011BUILD_DIR := zig-out
1112CACHE_DIR := .zig-cache
1213BINARY_NAME := example
@@ -18,14 +19,18 @@ JUNK_FILES := *.o *.obj *.dSYM *.dll *.so *.dylib *.a *.lib *.pdb temp/
1819EXAMPLES := $(patsubst % .zig,% ,$(notdir $(wildcard examples/* .zig) ) )
1920EXAMPLE ?= all
2021
22+ # Automatically find all benchmark names
23+ BENCHMARKS := $(patsubst % .zig,% ,$(notdir $(wildcard benches/* .zig) ) )
24+ BENCHMARK ?= all
25+
2126SHELL := /usr/bin/env bash
2227.SHELLFLAGS := -eu -o pipefail -c
2328
2429# ###############################################################################
2530# Targets
2631# ###############################################################################
2732
28- .PHONY : all help build rebuild run test release clean lint format docs serve-docs install-deps setup-hooks test-hooks
33+ .PHONY : all help build rebuild run bench test release clean lint format docs serve-docs install-deps setup-hooks test-hooks
2934.DEFAULT_GOAL := help
3035
3136help : # # Show the help messages for all targets
@@ -43,7 +48,7 @@ build: ## Build project (e.g. 'make build BUILD_TYPE=ReleaseSmall' or 'make buil
4348
4449rebuild : clean build # # clean and build
4550
46- run : # # Run an example (e.g. 'make run EXAMPLE=sorted_set ' or 'make run' to run all examples)
51+ run : # # Run an example (like 'make run EXAMPLE=e1_btree_map ' or 'make run' to run all examples)
4752 @if [ " $( EXAMPLE) " = " all" ]; then \
4853 echo " --> Running all examples..." ; \
4954 for ex in $( EXAMPLES) ; do \
@@ -56,6 +61,19 @@ run: ## Run an example (e.g. 'make run EXAMPLE=sorted_set' or 'make run' to run
5661 $(ZIG ) build run-$(EXAMPLE ) $(BUILD_OPTS ) ; \
5762 fi
5863
64+ bench : # # Run a benchmark (like 'make bench BENCHMARK=b1_btree_map' or 'make run' to run all benchmarks)
65+ @if [ " $( BENCHMARK) " = " all" ]; then \
66+ echo " --> Running all benchmarks..." ; \
67+ for ex in $( BENCHMARKS) ; do \
68+ echo " " ; \
69+ echo " --> Running '$$ ex'" ; \
70+ $(ZIG ) build bench-$$ ex $(BUILD_OPTS ) ; \
71+ done ; \
72+ else \
73+ echo " --> Running benchmark: $( BENCHMARK) " ; \
74+ $(ZIG ) build bench-$(BENCHMARK ) $(BUILD_OPTS ) ; \
75+ fi
76+
5977test : # # Run tests
6078 @echo " Running tests..."
6179 @$(ZIG ) build test $(BUILD_OPTS ) -j$(JOBS ) $(TEST_FLAGS )
0 commit comments