-
Notifications
You must be signed in to change notification settings - Fork 0
/
linuxBuild.sh
executable file
·221 lines (184 loc) · 4.57 KB
/
linuxBuild.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
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
#!/bin/bash
DP_FLAG=1
EP_FLAG=2
name=headerParser
def_target=${name}
pos_targets="app|sh|st|pck|cln|del"
target="app"
build_mode=2
mode="Release"
help=0
debug_print=$EP_FLAG
# Clean build directory from meta files
#
# @param $1 build directory
function clean() {
local dir=$1
echo "cleaning dir: $dir"
if [[ ${dir} == "${ROOT}" ]]; then
return 0
fi
cd ${dir} || return -1
rm -r ./CMakeFiles 2> /dev/null
rm -r ./CTestTestfile.cmake 2> /dev/null
rm -r ./CMakeCache.txt 2> /dev/null
rm -r ./cmake_install.cmake 2> /dev/null
rm -rf ./tests 2> /dev/null
rm -f ./*.cbp 2> /dev/null
rm -r ./Makefile 2> /dev/null
rm -rf ./debug 2> /dev/null
rm -rf ./.cmake 2> /dev/null
cd - || return -2
return 0
}
# Delete build directory and all files in it
#
# @param $1 build directory
function delete() {
local dir=$1
echo "deleting dir: $dir"
if [[ ${dir} == "${ROOT}" ]]; then
return 0
fi
rm -rf ${dir} 2> /dev/null
return 0
}
# CMake build a target
#
# @param $1 cmake target
# @param $2 build directory
# @param $3 build mode
function buildTarget() {
local target=$1
local dir=$2
local mode=$3
local dp=$4
local ep=0
if ! mkdir -p ${dir}; then
return 1
fi
if [[ $((dp & $EP_FLAG)) == $EP_FLAG ]]; then
ep=1
fi
dp=$((dp & ~$EP_FLAG))
# if no space at -B..., older cmake (ubuntu 18) will not build
if ! cmake -S ${ROOT} -B${dir} -DCMAKE_BUILD_TYPE=${mode} -DDEBUG_PRINT=${dp} -DERROR_PRINT=${ep}; then
return 2
fi
if ! cmake --build ${dir} --target ${target}; then
return 3
fi
# if [[ ${mode} == "Release" || ${mode} == "release" ]] && [[ ${target} == ${name} ]]; then
# sha256sum ${dir}/${target} | awk '{print $1}' > ${dir}/${target}.sha256
# fi
return 0
}
# Build a clean runnable package without metafiles.
#
# @param $1 cmake target
# @param $2 build directory
# @param $3 build mode
function buildPackage()
{
local target=$1
local dir=$2
local mode=$3
local dp=$4
if ! buildTarget ${target} ${dir} ${mode} 0; then
return 1
fi
if ! clean ${dir}; then
return 4
fi
return 0
}
function printUsage() {
echo "Usage: $0 [-t ${pos_targets}] [-m Debug|Release] [-h]"
echo "Default: $0 [-t app -r]"
return 0;
}
function printHelp() {
printUsage
echo ""
echo "-t A possible target: ${pos_targets}"
echo " * app: build headerParser application"
echo " * sh: build headerParser shared library"
echo " * st: build headerParser static library"
echo " * pck: build headerParser application and clean up build dir"
echo " * cln: clean build dir, remove cmake files"
echo " * del: delete build dir, i.e. delete all build targets"
echo "-d Build in debug mode"
echo "-r Build in release mode"
echo "-h Print this."
return 0;
}
while getopts ":p:t:hdr" opt; do
case $opt in
d)
build_mode=1
;;
h)
help=1
;;
p)
debug_print="$OPTARG"
;;
r)
build_mode=2
;;
t)
target="$OPTARG"
;;
\?)
echo "Invalid option -$OPTARG" >&2
;;
esac
done
if [[ ${help} == 1 ]]; then
printHelp
exit $?
fi
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
release_build_dir="${ROOT}/build"
debug_build_dir="${ROOT}/build/debug"
if [[ $((build_mode & 2)) == 2 ]]; then
mode="Release"
build_dir=${release_build_dir}
else
mode="Debug"
build_dir=${debug_build_dir}
fi
echo "target: "${target}
echo "mode: "${mode}
echo "build_dir: "${build_dir}
if [[ ${target} == "cln" || ${target} == "clean" ]]; then
clean ${build_dir}
exit $?
elif [[ ${target} == "del" || ${target} == "delete" ]]; then
delete ${build_dir}
exit $?
elif [[ ${target} == "pck" ]]; then
target=${name}_pck
buildPackage ${name} ${release_build_dir} Release
exit $?
else
if [[ ${target} == "app" ]]; then
target=${name}
elif [[ ${target} == "sh" || ${target} == "shared" ]]; then
target=${name}_sh
elif [[ ${target} == "st" || ${target} == "static" ]]; then
target=${name}_st
elif [[ ${target} == "tso" ]]; then
target=testHeaderParserLib
elif [[ ${target} == "tpso" ]]; then
target=testHeaderParserLibPE
elif [[ ${target} == "dirun" ]]; then
target=HPDirectoryRunner
else
echo "Unknown target: ${target}"
exit $?
fi
buildTarget ${target} ${build_dir} ${mode} ${debug_print}
exit $?
fi
exit $?