From 414073c185648bb9d20e5e4e528f36995efc1f95 Mon Sep 17 00:00:00 2001 From: BrandonPacewic <92102436+BrandonPacewic@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:56:12 -0700 Subject: [PATCH] feat(build): add makefile build script --- Makefile | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 65 -------------------------------------------------------- 2 files changed, 63 insertions(+), 65 deletions(-) create mode 100644 Makefile delete mode 100755 build.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4f41489 --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +# Copyright (c) Brandon Pacewic +# SPDX‑License‑Identifier: MIT + +BUILD_DIR ?= build +CMAKE_GENERATOR ?= Unix Makefiles +BUILD_TESTS ?= ON # pass BUILD_TESTS=OFF to skip +BUILD_BENCH ?= OFF +BUILD_TOOLS ?= OFF +BUILD_TYPE ?= Debug # Release | RelWithDebInfo ... +JOBS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu) + +CMAKE_FLAGS = \ + -G "$(CMAKE_GENERATOR)" \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -DBUILD_TESTING=$(BUILD_TESTS) \ + -DBUILD_BENCHMARKS=$(BUILD_BENCH) \ + -DBUILD_TOOLS=$(BUILD_TOOLS) \ + +.PHONY: build test bench tools \ + format clean distclean help + +configure: + @mkdir -p "$(BUILD_DIR)" + @cmake -S . -B "$(BUILD_DIR)" $(CMAKE_FLAGS) + +build: configure + @cmake --build "$(BUILD_DIR)" -- -j$(JOBS) + +test: build + @ctest --test-dir "$(BUILD_DIR)" --output-on-failure + +bench: BUILD_BENCH := ON +bench: build + @cmake --build "$(BUILD_DIR)" -j$(JOBS) + +tools: BUILD_TOOLS := ON +tools: build + +format: + @clang-format -i -style=file $(shell git ls-files '*.hpp' '*.h' '*.cpp') + +clean: + @cmake --build "$(BUILD_DIR)" --target clean || true + +distclean: + @rm -rf "$(BUILD_DIR)" + +help: + @echo "Targets:" + @echo " build - configure and build" + @echo " test - run ctest (RUN_TESTS=ON)" + @echo " bench - build & run benchmarks (BUILD_BENCH=ON)" + @echo " tools - build project-defined tools (BUILD_TOOLS=ON)" + @echo " format - run clang-format on all source files" + @echo " clean - clean build artefacts" + @echo " distclean - clean entire build dir" + @echo "" + @echo "Knobs (override with VAR=value):" + @echo " BUILD_DIR, CMAKE_GENERATOR, BUILD_TYPE, JOBS" + @echo " BUILD_TESTS, BUILD_BENCH, BUILD_TOOLS" + +# Default to help when running `make` without targets +.DEFAULT_GOAL := help diff --git a/build.sh b/build.sh deleted file mode 100755 index ce76c8d..0000000 --- a/build.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/sh - -# Copyright (c) Brandon Pacewic -# SPDX-License-Identifier: MIT - -set -e - -BUILD_DIR="build" -BUILD_TESTS=ON -RUN_TESTS=OFF -BUILD_BENCH=OFF -BUILD_TOOLS=OFF -CMAKE_GENERATOR="Unix Makefiles" - -while [ $# -gt 0 ]; do - case "$1" in - --clean) - rm -rf "$BUILD_DIR" - shift - ;; - --build-tests) - BUILD_TESTS=OFF - shift - ;; - --test) - RUN_TESTS=ON - shift - ;; - --bench) - BUILD_BENCH=ON - shift - ;; - --tools) - BUILD_TOOLS=ON - shift - ;; - --build-dir=*) - BUILD_DIR="${1#*=}" - shift - ;; - --help) - echo "Usage: $0 [--clean] [--build-tests] [--test] [--bench] [--tools] [--build-dir=