forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·118 lines (109 loc) · 3.25 KB
/
build.sh
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
#!/bin/sh
#####################################################################################
# @Filename: build.sh
# @Brief :
# @Auth : yuelw
# @Date : 2016-12-05
# @Version : ver 1.1
# @Function:
# @Inparam : NA
# @Outparam: NA
# @Remark : NA
#####################################################################################
BUILD_PATH="./build"
#####################################################################################
# @Brief : 简单日志
# @Inparam : NA
# @Outparam: NA
# @Remark : NA
#####################################################################################
function Log
{
echo "[BUILD] " `date +"%Y-%m-%d %H:%M:%S"` " " $1;
}
#####################################################################################
# @Brief : 检查是否存在外部编译目录不存在则创建
# @Inparam : NA
# @Outparam: NA
# @Remark : NA
#####################################################################################
function CreateBuildDirectory
{
Log "checking build path..."
if [ ! -x "${BUILD_PATH}" ]; then
Log "creating build path..."
mkdir "${BUILD_PATH}"
##由于权限可能导致创建失败,将在使用该目录时候检查
fi
}
#####################################################################################
# @Brief : 打印帮助信息
# @Inparam : NA
# @Outparam: NA
# @Remark : NA
#####################################################################################
function PrintUsage
{
echo "Usage:"
echo " $0 {release|debug|all|clean}"
echo " - realse cmake .."
echo " - debug cmake -DCMAKE_BUILD_TYPE=Debug -DUSER_DEBUG=1 .."
echo " - all cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_GCOV=1 -DUSER_DEBUG=1 .."
echo " - clean clean .."
}
#####################################################################################
# @Brief : 编译目标文件
# @Inparam : cmake 参数
# @Outparam: NA
# @Remark : NA
#####################################################################################
function BuildTarget
{
Log "access ${BUILD_PATH}"
cd ${BUILD_PATH}
if [ $? -eq 0 ]; then
Log "execute cmake $1"
cmake $1
if [ $? -eq 0 ]; then
make
else
Log "execute cmake $1 failed!"
fi
else
Log "access ${BUILD_PATH} failed!"
fi
}
#####################################################################################
# @Brief : 主函数
# @Inparam : NA
# @Outparam: NA
# @Remark : NA
#####################################################################################
function Main
{
case "x$1" in
xrelease)
CreateBuildDirectory
BuildTarget ".."
;;
xdebug)
CreateBuildDirectory
BuildTarget "-DCMAKE_BUILD_TYPE=Debug -DUSER_DEBUG=1 .."
;;
xall)
CreateBuildDirectory;
BuildTarget "-DCMAKE_BUILD_TYPE=Debug -DENABLE_GCOV=1 -DUSER_DEBUG=1 .."
;;
xclean)
Log "cleaning..."
if [ -x "${BUILD_PATH}" ]; then
rm -rf "${BUILD_PATH}";
fi
;;
*)
PrintUsage;
;;
esac
}
## Entrance...
Main $1