-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
75 lines (58 loc) · 2.54 KB
/
Copy pathMakefile
File metadata and controls
75 lines (58 loc) · 2.54 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
# Thin convenience wrapper around CMake. The build itself is defined in
# CMakeLists.txt; these targets just save typing and keep lint/format handy.
#
# make configure (if needed) and build
# make run build and launch the game
# make test build and run the unit tests (CTest)
# make package build a distributable (.dmg / .zip / .tar.gz) via CPack
# make lint run clang-tidy over the sources
# make format rewrite sources to match .clang-format
# make clean remove the build directory
BUILD_DIR := build
# On macOS the build produces SpaceInvaders.app; elsewhere a plain executable.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
BIN := $(BUILD_DIR)/SpaceInvaders.app/Contents/MacOS/SpaceInvaders
else
BIN := $(BUILD_DIR)/spaceinvaders
endif
SOURCES := src/Main.cpp src/Game.cpp src/Audio.cpp src/Draw.cpp src/Formation.cpp
HEADERS := include/Game.h include/Audio.h include/Draw.h include/Formation.h include/Sprites.h
TESTS := tests/formation_test.cpp
# Homebrew's llvm installs clang-tidy/clang-format but not on PATH.
CLANG_TIDY := $(shell command -v clang-tidy || echo /opt/homebrew/opt/llvm/bin/clang-tidy)
CLANG_FORMAT := $(shell command -v clang-format || echo /opt/homebrew/bin/clang-format)
SDL_CFLAGS := $(shell pkg-config --cflags sdl3)
# On macOS, standalone clang-tidy needs the SDK path spelled out explicitly.
ifeq ($(shell uname -s),Darwin)
SYSROOT := -isysroot $(shell xcrun --show-sdk-path)
endif
.PHONY: all configure build run test package lint format format-check clean
all: build
# Configure into BUILD_DIR (only re-runs if the cache is missing).
configure: $(BUILD_DIR)/CMakeCache.txt
$(BUILD_DIR)/CMakeCache.txt:
cmake -S . -B $(BUILD_DIR)
build: configure
cmake --build $(BUILD_DIR)
run: build
./$(BIN)
# Build and run the unit tests via CTest.
test: build
ctest --test-dir $(BUILD_DIR) --output-on-failure
# Build a distributable package for the current platform (CPack picks the
# generator: .dmg on macOS, .zip on Windows, .tar.gz on Linux).
package: build
cd $(BUILD_DIR) && cpack
# Static analysis. Reads checks from .clang-tidy; flags after `--` are the
# compile flags (so no compile_commands.json is required).
lint:
$(CLANG_TIDY) $(SOURCES) -- -std=c++20 -Iinclude $(SDL_CFLAGS) $(SYSROOT)
# Rewrite sources in place to match .clang-format.
format:
$(CLANG_FORMAT) -i $(SOURCES) $(HEADERS) $(TESTS)
# Fail (without editing) if anything isn't formatted -- handy for CI.
format-check:
$(CLANG_FORMAT) --dry-run --Werror $(SOURCES) $(HEADERS) $(TESTS)
clean:
rm -rf $(BUILD_DIR)