-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·155 lines (140 loc) · 3.6 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
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
#!/usr/bin/bash
#require cmake version 3.0.0
PBC_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -e
set -x
if [ -z "$ACI_JOB_NAME" ]; then
renice -n 10 $$
fi
BUILD_TYPE=Debug
THIRD_PARTY_BUILD_TYPE=Release
ENABLE_THIN_LTO=OFF
# Default compiler is Clang
USE_CLANG=1
######### parsing arguments #############
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-a|--asan)
USE_ASAN=1
shift # past argument
;;
-t|--tsan)
USE_TSAN=1
shift # past argument
;;
-d|--debug)
BUILD_TYPE=Debug
shift # past argument
;;
-r|--release)
BUILD_TYPE=Release
shift # past argument
;;
--clang)
USE_CLANG=1
USE_GCC=""
shift # past argument
;;
--gcc)
USE_CLANG=""
USE_GCC=1
shift # past argument
;;
--gcov)
USE_GCOV=1
shift # past argument
;;
--thin-lto)
ENABLE_THIN_LTO=ON
shift
;;
-v|--verbose)
MAKE_VERBOSE="VERBOSE=1"
shift # past argument
;;
*) # unknown option POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ -z "$PBC_MAKE_JOBS" ]; then
PBC_MAKE_JOBS=`grep processor /proc/cpuinfo | wc -l`
fi
echo "PBC Project build with parallel $PBC_MAKE_JOBS"
if [ -z "$ACI_JOB_NAME" ]; then
# in non-ACI environment, use the current timesteamp for version
BUILD_TIMESTAMP=`date +"%Y%m%d%H%M"`
else
# in ACI enviroment, use last commit time for version
BUILD_TIMESTAMP=`git log -1 --format=%ct | xargs -I{} date -d @{} +%Y%m%d%H%M`
fi
CMAKE_FLAGS=""
CMAKE_CXX_FLAGS=""
LAUNCHER=""
if [ ! -z "$USE_ASAN" ]; then
echo "Build with AddressSanitizer"
CMAKE_FLAGS="$CMAKE_FLAGS -DENABLE_ASAN=ON"
BUILD_FLAG=".asan"
BUILD_DIR="build_asan"
elif [ ! -z "$USE_TSAN" ]; then
echo "Build with ThreadSanitizer"
CMAKE_FLAGS="$CMAKE_FLAGS -DENABLE_TSAN=ON"
BUILD_FLAG=".tsan"
BUILD_DIR="build_tsan"
elif [ ! -z "$USE_GCOV" ]; then
echo "Build with coverage"
CMAKE_FLAGS="$CMAKE_FLAGS -DENABLE_COVERAGE=ON"
BUILD_FLAG=".cov"
BUILD_DIR="build_cov"
else
CMAKE_FLAGS="$CMAKE_FLAGS -DENABLE_ASAN=OFF"
BUILD_DIR="build"
fi
if [ ! -z "$USE_CLANG" ]; then
echo "Build with Clang"
export CC=clang
export CXX=clang++
fi
if [ ! -z "$USE_GCC" ]; then
echo "Build with GCC"
export CC=gcc
export CXX=g++
fi
# build third-party with GCC
if [ ! -f "${GCC_HOME}/bin/gcc" ]; then
GCC_HOME="/usr"
fi
mkdir -p ${PBC_HOME}/third-party/build
pushd ${PBC_HOME}/third-party/build
cmake \
-DDOWNLOAD_DIR=${PBC_HOME}/third-party/downloads \
-DCMAKE_INSTALL_PREFIX=${PBC_HOME}/third-party/install \
-DCMAKE_CXX_COMPILER_LAUNCHER=$LAUNCHER \
${PBC_HOME}/third-party
make -j$PBC_MAKE_JOBS
popd
if [ ! -z "$USE_CHECKER" ]; then
export CCC_CC=clang
export CCC_CXX=clang++
export CC=clang
export CXX=clang++
export REPORTS_DIR=${PBC_HOME}/testresult/analyzer-report/$BUILD_VERSION
export MAKE_PREFIX="scan-build -v --use-c++=$CCC_CXX --use-cc=$CCC_CC --exclude ${PBC_HOME}/third-party/ --exclude ${PBC_HOME}/src/deps/ -o $REPORTS_DIR "
export USE_CHECKER
mkdir -p $REPORTS_DIR
echo "ouptut static analyzer at $REPORTS_DIR"
fi
echo "building pbc..."
mkdir -p ${PBC_HOME}/${BUILD_DIR}
pushd ${PBC_HOME}/${BUILD_DIR}
$MAKE_PREFIX cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_FLAGS \
-DCMAKE_C_FLAGS="$CMAKE_C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS"\
-DCMAKE_CXX_COMPILER_LAUNCHER=$LAUNCHER \
-DENABLE_THIN_LTO=$ENABLE_THIN_LTO \
..
$MAKE_PREFIX make -j$PBC_MAKE_JOBS $MAKE_VERBOSE