-
Notifications
You must be signed in to change notification settings - Fork 1
/
ibuild.sh
executable file
·151 lines (136 loc) · 3.19 KB
/
ibuild.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
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
echo "Directory of current script: $SCRIPT_DIR"
cd ${SCRIPT_DIR}
root_dir=`pwd`
build_type="release"
inst_dir="${root_dir}/install"
san_type=""
compiler="gcc"
coverage=0
asan=0
tsan=0
get_key_value()
{
echo "$1" | sed 's/^-[a-zA-Z_-]*=//'
}
usage()
{
cat <<EOF
Usage: $0 [-t debug|release] [-d <inst_dir>]
Or
$0 [-h | --help]
-t Select the build type: release, debug.
-d Set the destination directory.
-g Enable the sanitizer of compiler,
asan for AddressSanitizer, tsan for ThreadSanitizer
-h, --help Show this help message.
-m Select compiler: gcc, clang
-a Enable coverage build
EOF
}
parse_options()
{
while test $# -gt 0
do
case "$1" in
-t=*)
build_type=`get_key_value "$1"`;;
-t)
shift
build_type=`get_key_value "$1"`;;
-d=*)
inst_dir=`get_key_value "$1"`;;
-d)
shift
inst_dir=`get_key_value "$1"`;;
-g=*)
san_type=`get_key_value "$1"`;;
-g)
shift
san_type=`get_key_value "$1"`;;
-m=*)
compiler=`get_key_value "$1"`;;
-m)
shift
compiler=`get_key_value "$1"`;;
-a)
coverage=1;;
-h | --help)
usage
exit 0;;
*)
echo "Unknown option '$1'"
exit 1;;
esac
shift
done
}
dump_options()
{
echo "=-------- Dumping the options used by $0 ------------="
echo "c_compiler: $c_compiler"
echo "cxx_compiler: $cxx_compiler"
echo "build_type=$build_type"
echo "Sanitizer=$san_type"
echo "coverage=$coverage"
echo ""
}
parse_options "$@"
dump_options
if [ x"$build_type" = x"debug" ]; then
build_type="Debug"
elif [ x"$build_type" = x"release" ]; then
build_type="RelWithDebInfo"
else
echo "Invalid build type, it must be \"debug\", \"release\" ."
exit 1
fi
if [ x"$san_type" = x"" ]; then
asan=0
tsan=0
elif [ x"$san_type" = x"asan" ]; then
asan=1
tsan=0
elif [ x"$san_type" = x"tsan" ]; then
asan=0
tsan=1
else
echo "Invalid sanitizer type, it must be \"asan\" or \"tsan\"."
exit 1
fi
if [ x"$compiler" = x"gcc" ]; then
c_compiler="gcc"
cxx_compiler="g++"
elif [ x"$compiler" = x"clang" ]; then
c_compiler="clang"
cxx_compiler="clang++"
else
echo "Invalid build type, it must be \"gcc\", \"clang\" ."
exit 1
fi
default_build_dir=${root_dir}/build/${build_type}
mkdir -p $default_build_dir && cd $default_build_dir
cmake \
-DCMAKE_BUILD_TYPE="$build_type" \
-DCMAKE_INSTALL_PREFIX="$inst_dir" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-DCMAKE_C_COMPILER="$c_compiler" \
-DCMAKE_CXX_COMPILER="$cxx_compiler" \
-DWITH_COVERAGE="$coverage" \
-DWITH_ASAN=$asan \
-DBIGNUM_BUILD_TESTS=1 \
-DBIGNUM_BUILD_BENCHMARK=1 \
${root_dir}
cp ${default_build_dir}/compile_commands.json ${root_dir}
# Check if nproc command exists
if command -v nproc &>/dev/null; then
num_processors=$(($(nproc) - 1))
if [ "$num_processors" -le 0 ]; then
num_processors=1
fi
else
echo "The nproc command is not available on this system."
num_processors=2
fi
make install -j${num_processors} VERBOSE=1