forked from alibaba/MongoShake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·77 lines (59 loc) · 1.64 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
#!/usr/bin/env bash
set -o errexit
# compile specified module
modules=(collector)
tags=""
# older version Git don't support --short !
#branch=`git symbolic-ref --short -q HEAD`
branch=$(git symbolic-ref -q HEAD | awk -F'/' '{print $3;}')
cid=$(git rev-parse HEAD)
version=$branch","$cid
output=./bin/
# make sure we're in the directory where the script lives
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
rm -rf ${output}
GOPATH=$(pwd)
export GOPATH
#compile_line='-race'
compile_line=''
if [ -z "$DEBUG" ]; then
DEBUG=0
fi
info="mongoshake/common.VERSION=$version"
# inject program information about compile
if [ $DEBUG -eq 1 ]; then
echo "[ BUILD DEBUG ]"
info=$info',debug'
else
echo "[ BUILD RELEASE ]"
info=$info",release"
fi
# golang version
goversion=$(go version | awk -F' ' '{print $3;}')
info=$info","$goversion
t=$(date "+%Y-%m-%d_%H:%M:%S")
info=$info","$t
run_builder='go build -v'
for i in "${modules[@]}" ; do
echo "Build ""$i"
if [ $DEBUG -eq 1 ]; then
$run_builder ${compile_line} -ldflags "-X $info" -gcflags='-N -l' -o "bin/$i" -tags "debug" "src/mongoshake//$i/main/$i.go"
else
$run_builder ${compile_line} -ldflags "-X $info" -o "bin/$i" "src/mongoshake//$i/main/$i.go"
fi
# execute and show compile messages
if [ -f ${output}/"$i" ];then
${output}/"$i"
fi
done
# *.sh
cp scripts/start.sh ${output}/
cp scripts/stop.sh ${output}/
cp scripts/mongoshake-stat ${output}/
if [ "Linux" == "$(uname -s)" ];then
# hypervisor
gcc -Wall -O3 scripts/hypervisor.c -o ${output}/hypervisor -lpthread
elif [ "Darwin" == "$(uname -s)" ];then
printf "\\nWARNING !!! MacOS doesn't supply hypervisor\\n"
fi