forked from qmatyanlab/Defect_GNN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
415 lines (381 loc) · 14.1 KB
/
Makefile
File metadata and controls
415 lines (381 loc) · 14.1 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
SHELL := /bin/bash
.DEFAULT_GOAL := help
# Directories
BUILD_DIR := build
BUILD_WASM_DIR := build-wasm
INCLUDE_DIR := include
SRC_DIR := src
THIRD_PARTY := third_party
TESTS_DIR := tests
WEB_DIR := web
WASM_OUTPUT_DIR := $(WEB_DIR)/public/wasm
# Emscripten
EMSDK_ENV := $(HOME)/emsdk/emsdk_env.sh
# Colors for output
GREEN := \033[0;32m
RED := \033[0;31m
BLUE := \033[0;34m
YELLOW := \033[0;33m
CYAN := \033[0;36m
NC := \033[0m
# Symbols
CHECK := $(GREEN)✓$(NC)
CROSS := $(RED)✗$(NC)
ARROW := $(CYAN)→$(NC)
.PHONY: help check-deps deps init configure build run clean rebuild format lint test \
wasm-init wasm-build wasm-clean web-init web-dev web-build web-clean all-clean \
preprocess
#==============================================================================
# Help
#==============================================================================
## help: Show this help message
help:
@printf "\n"
@printf "$(CYAN)════════════════════════════════════════════════════════════════$(NC)\n"
@printf "$(CYAN) Defect-GNN C++ - Development Commands$(NC)\n"
@printf "$(CYAN)════════════════════════════════════════════════════════════════$(NC)\n"
@printf "\n"
@printf "$(YELLOW)Setup:$(NC)\n"
@printf " check-deps Verify all required tools are installed\n"
@printf " deps Download all third-party dependencies\n"
@printf " init Full project initialization (deps + configure)\n"
@printf "\n"
@printf "$(YELLOW)Native Build:$(NC)\n"
@printf " build Compile the native executable\n"
@printf " run Build and run the executable\n"
@printf " preprocess Compute Betti features for all structures\n"
@printf " clean Remove native build artifacts\n"
@printf " rebuild Clean and rebuild everything\n"
@printf "\n"
@printf "$(YELLOW)Code Quality:$(NC)\n"
@printf " format Format all source files with clang-format\n"
@printf " lint Run clang-tidy on all source files\n"
@printf " test Run all tests\n"
@printf "\n"
@printf "$(YELLOW)WebAssembly:$(NC)\n"
@printf " wasm-init Configure Emscripten build\n"
@printf " wasm-build Compile to WebAssembly\n"
@printf " wasm-clean Remove WASM build artifacts\n"
@printf "\n"
@printf "$(YELLOW)Frontend:$(NC)\n"
@printf " web-init Initialize frontend (bun install)\n"
@printf " web-dev Start frontend dev server\n"
@printf " web-build Build frontend for production\n"
@printf " web-clean Remove frontend build artifacts\n"
@printf "\n"
@printf "$(YELLOW)Combined:$(NC)\n"
@printf " all-clean Remove all build artifacts\n"
@printf "\n"
#==============================================================================
# Dependency Checking
#==============================================================================
## check-deps: Verify all required tools are installed
check-deps:
@printf "\n"
@printf "$(BLUE)Checking dependencies...$(NC)\n"
@printf "\n"
@# CMake
@command -v cmake >/dev/null 2>&1 && \
printf " $(CHECK) cmake: $$(cmake --version | head -1)\n" || \
printf " $(CROSS) cmake: not found (apt install cmake)\n"
@# Ninja
@command -v ninja >/dev/null 2>&1 && \
printf " $(CHECK) ninja: $$(ninja --version)\n" || \
printf " $(CROSS) ninja: not found (apt install ninja-build)\n"
@# Clang
@command -v clang++ >/dev/null 2>&1 && \
printf " $(CHECK) clang++: $$(clang++ --version | head -1)\n" || \
printf " $(CROSS) clang++: not found (apt install clang)\n"
@# clang-format
@command -v clang-format >/dev/null 2>&1 && \
printf " $(CHECK) clang-format: $$(clang-format --version)\n" || \
printf " $(CROSS) clang-format: not found (apt install clang-format)\n"
@# clang-tidy
@command -v clang-tidy >/dev/null 2>&1 && \
printf " $(CHECK) clang-tidy: $$(clang-tidy --version | head -1)\n" || \
printf " $(CROSS) clang-tidy: not found (apt install clang-tidy)\n"
@# Emscripten
@if [ -f "$(EMSDK_ENV)" ]; then \
printf " $(CHECK) emscripten: $(EMSDK_ENV)\n"; \
else \
printf " $(CROSS) emscripten: not found at $(EMSDK_ENV)\n"; \
fi
@# Bun
@command -v bun >/dev/null 2>&1 && \
printf " $(CHECK) bun: $$(bun --version)\n" || \
printf " $(CROSS) bun: not found (curl -fsSL https://bun.sh/install | bash)\n"
@printf "\n"
@printf "$(BLUE)Checking third-party libraries...$(NC)\n"
@printf "\n"
@# Eigen
@if [ -f "$(THIRD_PARTY)/eigen/Eigen/Core" ]; then \
printf " $(CHECK) Eigen: $(THIRD_PARTY)/eigen/\n"; \
elif [ -f "/usr/include/eigen3/Eigen/Core" ]; then \
printf " $(CHECK) Eigen: /usr/include/eigen3/ (system)\n"; \
else \
printf " $(CROSS) Eigen: not found (run: make deps)\n"; \
fi
@# nlohmann/json
@if [ -f "$(THIRD_PARTY)/nlohmann_json/nlohmann/json.hpp" ]; then \
printf " $(CHECK) nlohmann/json: $(THIRD_PARTY)/nlohmann_json/\n"; \
else \
printf " $(CROSS) nlohmann/json: not found (run: make deps)\n"; \
fi
@# nanoflann
@if [ -f "$(THIRD_PARTY)/nanoflann/nanoflann.hpp" ]; then \
printf " $(CHECK) nanoflann: $(THIRD_PARTY)/nanoflann/\n"; \
else \
printf " $(CROSS) nanoflann: not found (run: make deps)\n"; \
fi
@# spdlog
@if [ -f "$(THIRD_PARTY)/spdlog/include/spdlog/spdlog.h" ]; then \
printf " $(CHECK) spdlog: $(THIRD_PARTY)/spdlog/\n"; \
else \
printf " $(CROSS) spdlog: not found (run: make deps)\n"; \
fi
@printf "\n"
#==============================================================================
# Setup
#==============================================================================
## deps: Download all third-party dependencies
deps:
@printf "\n"
@printf "$(BLUE)Downloading third-party dependencies...$(NC)\n"
@printf "\n"
@mkdir -p $(THIRD_PARTY)
@# Eigen
@if [ ! -f "$(THIRD_PARTY)/eigen/Eigen/Core" ]; then \
printf " $(ARROW) Downloading Eigen 3.4.0...\n"; \
mkdir -p $(THIRD_PARTY)/eigen; \
curl -sL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz | \
tar xz -C $(THIRD_PARTY)/eigen --strip-components=1; \
printf " $(CHECK) Eigen installed\n"; \
else \
printf " $(CHECK) Eigen already installed\n"; \
fi
@# nlohmann/json (single header)
@if [ ! -f "$(THIRD_PARTY)/nlohmann_json/nlohmann/json.hpp" ]; then \
printf " $(ARROW) Downloading nlohmann/json...\n"; \
mkdir -p $(THIRD_PARTY)/nlohmann_json/nlohmann; \
curl -sL https://github.com/nlohmann/json/releases/download/v3.11.3/json.hpp \
-o $(THIRD_PARTY)/nlohmann_json/nlohmann/json.hpp; \
printf " $(CHECK) nlohmann/json installed\n"; \
else \
printf " $(CHECK) nlohmann/json already installed\n"; \
fi
@# nanoflann (single header)
@if [ ! -f "$(THIRD_PARTY)/nanoflann/nanoflann.hpp" ]; then \
printf " $(ARROW) Downloading nanoflann...\n"; \
mkdir -p $(THIRD_PARTY)/nanoflann; \
curl -sL https://raw.githubusercontent.com/jlblancoc/nanoflann/v1.5.5/include/nanoflann.hpp \
-o $(THIRD_PARTY)/nanoflann/nanoflann.hpp; \
printf " $(CHECK) nanoflann installed\n"; \
else \
printf " $(CHECK) nanoflann already installed\n"; \
fi
@# spdlog (header-only)
@if [ ! -f "$(THIRD_PARTY)/spdlog/include/spdlog/spdlog.h" ]; then \
printf " $(ARROW) Downloading spdlog 1.14.1...\n"; \
mkdir -p $(THIRD_PARTY)/spdlog; \
curl -sL https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz | \
tar xz -C $(THIRD_PARTY)/spdlog --strip-components=1; \
printf " $(CHECK) spdlog installed\n"; \
else \
printf " $(CHECK) spdlog already installed\n"; \
fi
@printf "\n"
@printf "$(GREEN)All dependencies installed!$(NC)\n"
@printf "\n"
## configure: Configure CMake build system
configure:
@printf "\n"
@printf "$(BLUE)Configuring CMake...$(NC)\n"
@printf "\n"
@mkdir -p $(BUILD_DIR)
@cmake -B $(BUILD_DIR) -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_COMPILER=clang++
@printf "\n"
@printf "$(GREEN)Configuration complete!$(NC)\n"
@printf " $(ARROW) compile_commands.json symlinked to project root\n"
@printf "\n"
## init: Full project initialization (deps + configure)
init: deps configure
@printf "$(GREEN)Project initialized!$(NC)\n"
@printf " $(ARROW) Run 'make build' to compile\n"
@printf " $(ARROW) Restart VSCode for clangd to pick up changes\n"
@printf "\n"
#==============================================================================
# Native Build
#==============================================================================
## build: Compile the project
build:
@printf "\n"
@printf "$(BLUE)Building...$(NC)\n"
@printf "\n"
@if [ ! -d "$(BUILD_DIR)" ]; then \
printf "$(RED)Build directory not found. Run 'make init' first.$(NC)\n"; \
exit 1; \
fi
@cmake --build $(BUILD_DIR)
@printf "\n"
@printf "$(GREEN)Build complete!$(NC)\n"
@printf "\n"
## run: Build and run the executable
run: build
@./$(BUILD_DIR)/defect_gnn
## clean: Remove build artifacts
clean:
@printf "\n"
@printf "$(BLUE)Cleaning native build artifacts...$(NC)\n"
@rm -rf $(BUILD_DIR)
@rm -f compile_commands.json
@printf " $(CHECK) Build directory removed\n"
@printf "\n"
## rebuild: Clean and rebuild everything
rebuild: clean init build
@printf "$(GREEN)Full rebuild complete!$(NC)\n"
@printf "\n"
## preprocess: Compute Betti features for all structures
preprocess: build
@printf "\n"
@printf "$(BLUE)Running Betti preprocessing...$(NC)\n"
@printf "\n"
@./$(BUILD_DIR)/preprocess_betti
@printf "\n"
@printf "$(GREEN)Preprocessing complete!$(NC)\n"
@printf "\n"
#==============================================================================
# Code Quality
#==============================================================================
## format: Format all source files with clang-format
format:
@printf "\n"
@printf "$(BLUE)Formatting source files...$(NC)\n"
@printf "\n"
@find $(INCLUDE_DIR) $(SRC_DIR) $(TESTS_DIR) -name '*.hpp' -o -name '*.cpp' 2>/dev/null | \
xargs -r clang-format -i --style=file
@printf " $(CHECK) All files formatted\n"
@printf "\n"
## lint: Run clang-tidy on all source files
lint:
@printf "\n"
@printf "$(BLUE)Running clang-tidy...$(NC)\n"
@printf "\n"
@if [ ! -f "compile_commands.json" ]; then \
printf "$(RED)compile_commands.json not found. Run 'make configure' first.$(NC)\n"; \
exit 1; \
fi
@find $(SRC_DIR) -name '*.cpp' 2>/dev/null | \
xargs -r clang-tidy -p $(BUILD_DIR) 2>/dev/null || true
@printf "\n"
@printf "$(GREEN)Linting complete!$(NC)\n"
@printf "\n"
## test: Run all tests
test:
@printf "\n"
@printf "$(BLUE)Running tests...$(NC)\n"
@printf "\n"
@if [ ! -d "$(BUILD_DIR)" ]; then \
printf "$(RED)Build directory not found. Run 'make build' first.$(NC)\n"; \
exit 1; \
fi
@cd $(BUILD_DIR) && ctest --output-on-failure
@printf "\n"
#==============================================================================
# WebAssembly
#==============================================================================
## wasm-init: Initialize Emscripten build
wasm-init:
@printf "\n"
@printf "$(BLUE)Initializing WebAssembly build...$(NC)\n"
@printf "\n"
@if [ ! -f "$(EMSDK_ENV)" ]; then \
printf "$(RED)Emscripten not found at $(EMSDK_ENV)$(NC)\n"; \
printf "Install from: https://emscripten.org/docs/getting_started/downloads.html\n"; \
exit 1; \
fi
@mkdir -p $(BUILD_WASM_DIR)
@mkdir -p $(WASM_OUTPUT_DIR)
@source $(EMSDK_ENV) && \
emcmake cmake -B $(BUILD_WASM_DIR) -G Ninja \
-DCMAKE_BUILD_TYPE=Release
@printf "\n"
@printf "$(GREEN)WASM build configured!$(NC)\n"
@printf "\n"
## wasm-build: Compile to WebAssembly
wasm-build:
@printf "\n"
@printf "$(BLUE)Building WebAssembly...$(NC)\n"
@printf "\n"
@if [ ! -d "$(BUILD_WASM_DIR)" ]; then \
printf "$(RED)WASM build not configured. Run 'make wasm-init' first.$(NC)\n"; \
exit 1; \
fi
@source $(EMSDK_ENV) && cmake --build $(BUILD_WASM_DIR)
@printf "\n"
@printf "$(BLUE)Copying WASM files to web/public/wasm/...$(NC)\n"
@mkdir -p $(WASM_OUTPUT_DIR)
@cp $(BUILD_WASM_DIR)/defect_gnn_viz.js $(WASM_OUTPUT_DIR)/
@cp $(BUILD_WASM_DIR)/defect_gnn_viz.wasm $(WASM_OUTPUT_DIR)/
@printf " $(CHECK) defect_gnn_viz.js\n"
@printf " $(CHECK) defect_gnn_viz.wasm\n"
@printf "\n"
@printf "$(GREEN)WASM build complete!$(NC)\n"
@printf "\n"
## wasm-clean: Remove WASM build artifacts
wasm-clean:
@printf "\n"
@printf "$(BLUE)Cleaning WASM build artifacts...$(NC)\n"
@rm -rf $(BUILD_WASM_DIR)
@rm -f $(WASM_OUTPUT_DIR)/defect_gnn_viz.*
@printf " $(CHECK) WASM build directory removed\n"
@printf "\n"
#==============================================================================
# Frontend
#==============================================================================
## web-init: Initialize frontend (bun install)
web-init:
@printf "\n"
@printf "$(BLUE)Initializing frontend...$(NC)\n"
@printf "\n"
@if [ ! -d "$(WEB_DIR)" ]; then \
printf "$(RED)Web directory not found. Create web/ first.$(NC)\n"; \
exit 1; \
fi
@cd $(WEB_DIR) && bun install
@printf "\n"
@printf "$(GREEN)Frontend initialized!$(NC)\n"
@printf "\n"
## web-dev: Start frontend dev server
web-dev:
@printf "\n"
@printf "$(BLUE)Starting frontend dev server...$(NC)\n"
@printf "\n"
@cd $(WEB_DIR) && bun run dev
## web-build: Build frontend for production
web-build: wasm-build
@printf "\n"
@printf "$(BLUE)Building frontend for production...$(NC)\n"
@printf "\n"
@cd $(WEB_DIR) && bun run build
@printf "\n"
@printf "$(GREEN)Frontend build complete!$(NC)\n"
@printf "\n"
## web-clean: Remove frontend build artifacts
web-clean:
@printf "\n"
@printf "$(BLUE)Cleaning frontend build artifacts...$(NC)\n"
@rm -rf $(WEB_DIR)/.next
@rm -rf $(WEB_DIR)/out
@rm -rf $(WEB_DIR)/node_modules
@printf " $(CHECK) Frontend build artifacts removed\n"
@printf "\n"
#==============================================================================
# Combined
#==============================================================================
## all-clean: Remove all build artifacts
all-clean: clean wasm-clean web-clean
@printf "$(GREEN)All build artifacts removed!$(NC)\n"
@printf "\n"