-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sh
executable file
·103 lines (76 loc) · 2.04 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
#!/bin/sh
BuildVersion=`git describe --abbrev=0 --tags`
BuildTime=`date +%FT%T%z`
CommitID=`git rev-parse HEAD`
servername=weather
function help() {
echo "$0 linux|windows|mac"
}
function linux(){
echo "编译中..."
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-linux-musl-gcc CGO_LDFLAGS="-static" go build -a -ldflags "-w -s -X main.BuildVersion=${BuildVersion} -X main.CommitID=${CommitID} -X main.BuildTime=${BuildTime}"
}
function windows(){
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build -ldflags "-w -s -X main.BuildVersion=${BuildVersion} -X main.CommitID=${CommitID} -X main.BuildTime=${BuildTime}"
}
function mac(){
go build -ldflags "-w -s -X main.BuildVersion=${BuildVersion} -X main.CommitID=${CommitID} -X main.BuildTime=${BuildTime}"
}
function copyFile() {
echo "编译完成,正在发布到执行目录..."
cd ../
mkdir -p bin/config
mkdir -p bin/db
mkdir -p bin/log
cp -r config/. bin/config/
cp -r db/weather.sqlite bin/db/
if [ "$1" == "windows" ]; then
cp weather-srv/weather-srv.exe bin/
cp api-srv/api-srv.exe bin/
cp tools/micro/micro.exe bin/
rm -f weather-srv/weather-srv.exe
rm -f api-srv/api-srv.exe
rm -f tools/micro/micro.exe
else
cp weather-srv/weather-srv bin/
cp api-srv/api-srv bin/
cp tools/micro/micro bin/
rm -f weather-srv/weather-srv
rm -f api-srv/api-srv
rm -f tools/micro/micro
cp curl.sh bin/
fi
}
cd weather-srv
if [ "$1" == "" ]; then
help
elif [ "$1" == "linux" ];then
linux
elif [ "$1" == "windows" ];then
windows
elif [ "$1" == "mac" ];then
mac
fi
cd ../
cd api-srv
if [ "$1" == "linux" ];then
linux
elif [ "$1" == "windows" ];then
windows
elif [ "$1" == "mac" ];then
mac
fi
cd ../
cd tools/micro
if [ "$1" == "linux" ];then
linux
elif [ "$1" == "windows" ];then
windows
elif [ "$1" == "mac" ];then
mac
fi
cd ../
if [ "$1" != "" ]; then
copyFile
echo "编译结束。"
fi