-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·97 lines (83 loc) · 2.06 KB
/
build.sh
File metadata and controls
executable file
·97 lines (83 loc) · 2.06 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
#!/bin/bash
# 颜色定义
BLUE='\033[1;34m'
RED='\033[1;31m'
NC='\033[0m' # No Color
# 输出函数
print_status() {
echo -e "${BLUE}[BUILD]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
BUILD_TYPE=Release
CC=clang
CXX=clang++
# 解析命令行参数
while [[ $# -gt 0 ]]; do
case $1 in
--build-type)
BUILD_TYPE="$2"
shift # 移动到下一个参数
shift # 移动到下一个参数
;;
--cc)
CC="$2"
shift # 移动到下一个参数
shift # 移动到下一个参数
;;
--cxx)
CXX="$2"
shift # 移动到下一个参数
shift # 移动到下一个参数
;;
*)
print_error "Unknown option $1"
exit 1
;;
esac
done
# 设置默认构建类型并转换为小写
BUILD_TYPE=$(echo "$BUILD_TYPE" | tr '[:upper:]' '[:lower:]')
# 验证构建类型
case "$BUILD_TYPE" in
debug|release)
print_status "Build type: ${BUILD_TYPE}"
;;
*)
print_error "Invalid build type. Use 'debug' or 'release'"
exit 1
;;
esac
# 根据构建类型设置目录
BUILD_DIR="build_${BUILD_TYPE}"
# 清理旧的构建目录
print_status "Cleaning old build directories..."
rm -rf ${BUILD_DIR}/
# 清理旧的数据
print_status "Cleaning old data directories..."
rm -rf data/*
# 创建必要的目录
print_status "Creating directories..."
mkdir -p ${BUILD_DIR}/
mkdir -p data/
# 进入构建目录并保存项目根目录
PROJECT_ROOT=$(pwd)
cd "${BUILD_DIR}" || {
print_error "Failed to enter build directory"
exit 1
}
# 运行 CMAKE
print_status "Running CMAKE..."
BUILD_TYPE_UPPER=$(echo "$BUILD_TYPE" | tr '[:lower:]' '[:upper:]')
if ! cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE_UPPER} -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_VERBOSE_MAKEFILE=ON "${PROJECT_ROOT}"; then
print_error "CMAKE configuration failed"
exit 1
fi
# 编译项目
print_status "Building project..."
if ! make -j$(nproc); then
print_error "Build failed"
exit 1
fi
print_status "Build completed successfully!"