-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
158 lines (143 loc) · 4.99 KB
/
Makefile
File metadata and controls
158 lines (143 loc) · 4.99 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
CONFIG ?= debug
UNAME_S := $(shell uname -s 2>/dev/null)
UNAME_M := $(shell uname -m 2>/dev/null)
ifeq ($(CONFIG),debug)
SUFFIX := debug
else ifeq ($(CONFIG),release)
SUFFIX := release
else ifeq ($(CONFIG),asan-ubsan)
SUFFIX := asan-ubsan
else ifeq ($(CONFIG),tsan)
SUFFIX := tsan
else ifeq ($(CONFIG),release-lto)
SUFFIX := release-lto
else ifeq ($(CONFIG),debug-gcc)
SUFFIX := debug
LINUX_TOOLCHAIN := gcc
else ifeq ($(CONFIG),debug-clang)
SUFFIX := debug
LINUX_TOOLCHAIN := clang
else
$(error Unknown CONFIG '$(CONFIG)'. Use one of: debug release asan-ubsan tsan release-lto debug-gcc debug-clang)
endif
ifeq ($(UNAME_S),Darwin)
ifeq ($(UNAME_M),arm64)
CMAKE_CONFIGURE_PRESET := macos-arm64-$(SUFFIX)
else ifeq ($(UNAME_M),x86_64)
CMAKE_CONFIGURE_PRESET := macos-x64-$(SUFFIX)
else
$(error Unsupported macOS arch '$(UNAME_M)')
endif
BUILD_DIR := build/$(CMAKE_CONFIGURE_PRESET)
else ifeq ($(UNAME_S),Linux)
ifndef LINUX_TOOLCHAIN
LINUX_TOOLCHAIN := gcc
endif
CMAKE_CONFIGURE_PRESET := linux-x64-$(LINUX_TOOLCHAIN)-$(SUFFIX)
BUILD_DIR := build/$(CMAKE_CONFIGURE_PRESET)
else
# Windows (i.e. Git Bash/MSYS) often reports uname -s like MINGW64_NT-*
# For native Windows usage, recommend running from a shell where `cmake` works.
ifneq (,$(findstring MINGW,$(UNAME_S)))
CMAKE_CONFIGURE_PRESET := windows-x64-msvc-$(SUFFIX)
BUILD_DIR := build/$(CMAKE_CONFIGURE_PRESET)
else ifneq (,$(findstring MSYS,$(UNAME_S)))
CMAKE_CONFIGURE_PRESET := windows-x64-msvc-$(SUFFIX)
BUILD_DIR := build/$(CMAKE_CONFIGURE_PRESET)
else ifneq (,$(findstring CYGWIN,$(UNAME_S)))
CMAKE_CONFIGURE_PRESET := windows-x64-msvc-$(SUFFIX)
BUILD_DIR := build/$(CMAKE_CONFIGURE_PRESET)
else
# If uname isn't available, assume Windows.
CMAKE_CONFIGURE_PRESET := windows-x64-msvc-$(SUFFIX)
BUILD_DIR := build/$(CMAKE_CONFIGURE_PRESET)
endif
ifeq ($(SUFFIX),asan-ubsan)
$(error CONFIG=asan-ubsan is not supported for windows-x64-msvc presets)
endif
ifeq ($(SUFFIX),tsan)
$(error CONFIG=tsan is not supported for windows-x64-msvc presets)
endif
endif
# Derive the vcpkg triplet from platform to match CMakePresets.json
ifeq ($(UNAME_S),Darwin)
ifeq ($(UNAME_M),arm64)
VCPKG_TRIPLET := arm64-osx
else ifeq ($(UNAME_M),x86_64)
VCPKG_TRIPLET := x64-osx
else
$(error Unsupported macOS arch '$(UNAME_M)')
endif
else ifeq ($(UNAME_S),Linux)
VCPKG_TRIPLET := x64-linux
else
# Windows/MSYS/Git Bash/Cygwin (probably)
VCPKG_TRIPLET := x64-windows
endif
.PHONY: deps vcpkg-install configure build run clean bench-noop bench-touch
### testing this for non-gh actions
deps:
@set -e; \
if ! command -v ninja >/dev/null 2>&1; then \
echo "ninja not found; attempting to install..."; \
if command -v apt-get >/dev/null 2>&1; then \
if command -v sudo >/dev/null 2>&1; then SUDO=sudo; else SUDO=; fi; \
$$SUDO apt-get update; \
$$SUDO apt-get install -y ninja-build; \
elif command -v dnf >/dev/null 2>&1; then \
if command -v sudo >/dev/null 2>&1; then SUDO=sudo; else SUDO=; fi; \
$$SUDO dnf install -y ninja-build; \
elif command -v pacman >/dev/null 2>&1; then \
if command -v sudo >/dev/null 2>&1; then SUDO=sudo; else SUDO=; fi; \
$$SUDO pacman -S --noconfirm ninja; \
elif command -v zypper >/dev/null 2>&1; then \
if command -v sudo >/dev/null 2>&1; then SUDO=sudo; else SUDO=; fi; \
$$SUDO zypper --non-interactive install ninja; \
elif command -v brew >/dev/null 2>&1; then \
brew install ninja; \
elif command -v winget >/dev/null 2>&1 || command -v winget.exe >/dev/null 2>&1; then \
if command -v winget >/dev/null 2>&1; then WINGET=winget; else WINGET=winget.exe; fi; \
$$WINGET install --id Ninja-build.Ninja --exact --accept-package-agreements --accept-source-agreements; \
else \
echo "error: ninja is missing and no supported package manager was found"; \
exit 1; \
fi; \
else \
echo "ninja already installed"; \
fi; \
if [ ! -f "vcpkg/bootstrap-vcpkg.sh" ] && [ ! -f "vcpkg/bootstrap-vcpkg.bat" ]; then \
echo "vcpkg checkout not found; cloning..."; \
rm -rf vcpkg; \
git clone https://github.com/microsoft/vcpkg.git vcpkg; \
else \
git submodule update --init --recursive; \
fi; \
if [ -f "vcpkg/bootstrap-vcpkg.sh" ]; then \
if [ ! -f "vcpkg/vcpkg" ]; then \
echo "Bootstrapping vcpkg (Unix)..."; \
cd vcpkg && ./bootstrap-vcpkg.sh; \
else \
echo "vcpkg already bootstrapped"; \
fi; \
elif [ -f "vcpkg/bootstrap-vcpkg.bat" ]; then \
if [ ! -f "vcpkg/vcpkg.exe" ]; then \
echo "Bootstrapping vcpkg (Windows)..."; \
cd vcpkg && ./bootstrap-vcpkg.bat; \
else \
echo "vcpkg already bootstrapped"; \
fi; \
else \
echo "error: vcpkg bootstrap script not found"; \
exit 1; \
fi
vcpkg-install: deps
./vcpkg/vcpkg install --triplet $(VCPKG_TRIPLET)
configure:
cmake --preset $(CMAKE_CONFIGURE_PRESET)
./scripts/sync_compile_commands.sh $(BUILD_DIR)
build: configure
cmake --build $(BUILD_DIR)
run: build
cmake --build $(BUILD_DIR) --target run
clean:
rm -rf build