-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.sh
executable file
·103 lines (86 loc) · 2.49 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
#!/bin/bash
# argument "p" means Platform:
# p=mac: GOOS=darwin GOARCH=amd64
# p=win32: GOOS=windows GOARCH=386
# p=win64: GOOS=windows GOARCH=amd64
# p=linux: GOOS=linux GOARCH=amd64
# p=arm: GOOS=linux GOARCH=arm
GOOS=""
GOARCH=""
Platform=""
Version=`git describe --tags`
BuildLDFlags="-X main.version=$Version -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=`git rev-parse HEAD`"
echo $BuildLDFlags
while getopts "p:v:w" arg #选项后面的冒号表示该选项需要参数
do
case $arg in
p)
Platform=$OPTARG
;;
?) #当有不认识的选项的时候arg为?
echo "Example usage: build.sh -p mac|win32|win64|linux|arc -v 0.1.0"
;;
esac
done
if [[ -z $Platform ]]; then
echo "Example usage: build.sh -p mac/win32/win64/linux/arc"
else
echo "Platform=$Platform"
fi
if [ -z $Platform ]; then
GOOS="darwin"
GOARCH="amd64"
elif [ $Platform = "win32" ]; then
GOOS="windows"
GOARCH="386"
elif [ $Platform = "win64" ];then
GOOS="windows"
GOARCH="amd64"
elif [ $Platform = "linux" ];then
GOOS="linux"
GOARCH="amd64"
elif [ $Platform = "arm" ];then
GOOS="linux"
GOARCH="arm"
else
GOOS="darwin"
GOARCH="amd64"
fi
echo "GOOS=$GOOS"
echo "GOARCH=$GOARCH"
ROOT=$(pwd)
echo $GOROOT
echo $GOPATH
echo $GOOS
echo $GOARCH
echo "############ Running go get. ############"
#go get google.golang.org/grpc
#go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
#go get github.com/robertkrimen/otto
#go get github.com/markcheno/go-talib
#Todo add more go get or use gb tool
echo "############ Build protoc. ############"
cd $ROOT/src/bitbotlib
protoc --go_out=plugins=grpc:. bitbot.proto
echo "############ build and install library. ############"
cd $ROOT/src/bitbotlib
GOOS=$GOOS GOARCH=$GOARCH go install
echo "############ remove all binary files. ############"
cd $ROOT/bin
#rm -rf *
echo "############ build and install console. ############"
cd $ROOT/src/console
GOOS=$GOOS GOARCH=$GOARCH go install -ldflags "$BuildLDFlags"
echo "############ build and install robot. ############"
cd $ROOT/src/robot
GOOS=$GOOS GOARCH=$GOARCH go install -ldflags "$BuildLDFlags"
echo "############ copy files to dist folder. ############"
cd $ROOT/dist
if [ -d "$Version" ]; then
rm -rf $Version
fi
mkdir $Version
cp -aR $ROOT/bin/. $ROOT/dist/$Version
echo "############ upload files to dist folder. ############"
cd $ROOT
echo "############ Done. ############"