Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
68 lines (53 loc) · 1.64 KB
/
Copy pathMakefile
File metadata and controls
68 lines (53 loc) · 1.64 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
# Otne 便捷构建脚本:封装 CMake 常用命令
# 用法:make help
BUILD_DIR ?= build
BUILD_TYPE ?= Release
FILE ?= resources/code/HelloWorld.otne
JOBS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
CMAKE ?= cmake
BIN := $(BUILD_DIR)/bin/otne
.PHONY: all build release debug rebuild run tokens test ctest clean distclean help
all: build
## build: 配置并构建(BUILD_TYPE 默认 Release)
build:
$(CMAKE) -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
$(CMAKE) --build $(BUILD_DIR) --parallel $(JOBS)
## release: Release 构建
release:
$(MAKE) build BUILD_TYPE=Release
## debug: Debug 构建
debug:
$(MAKE) build BUILD_TYPE=Debug
## rebuild: 删除构建目录后重新构建
rebuild:
$(MAKE) distclean
$(MAKE) build
## run: 运行源文件(FILE=路径,默认 resources/code/HelloWorld.otne)
run: build
./$(BIN) $(FILE)
## tokens: 只输出词法单元(FILE=路径)
tokens: build
./$(BIN) --tokens $(FILE)
## test: 运行冒烟测试
test: build
./tests/smoke.sh $(BIN)
## ctest: 通过 CTest 运行测试
ctest: build
cd $(BUILD_DIR) && ctest --output-on-failure
## clean: 清理编译产物(保留构建目录)
clean:
@$(CMAKE) --build $(BUILD_DIR) --target clean 2>/dev/null || true
## distclean: 删除整个构建目录
distclean:
rm -rf $(BUILD_DIR)
## help: 显示可用目标
help:
@echo "Otne 构建目标:"
@echo
@grep -E '^## ' $(MAKEFILE_LIST) | sed -e 's/^## / make /'
@echo
@echo "可用变量:"
@echo " BUILD_DIR=$(BUILD_DIR) BUILD_TYPE=$(BUILD_TYPE)"
@echo " FILE=$(FILE)"
@echo
@echo "示例:make run FILE=resources/code/Fibonacci.otne"