-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
81 lines (63 loc) · 1.31 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
#!/bin/bash
# Reference:
# https://github.com/golang/go/blob/master/src/go/build/syslist.go
os_archs=(
darwin/amd64
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/s390x
windows/386
windows/amd64
windows/arm
)
releases=()
fails=()
for os_arch in "${os_archs[@]}"
do
goos=${os_arch%/*}
goarch=${os_arch#*/}
filename=dvs
if [[ ${goos} == "windows" ]];
then
filename+=.exe
fi
echo building ${os_arch}
CGO_ENABLED=0 GOOS=${goos} GOARCH=${goarch} go build -mod=vendor -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -ldflags "-s -w" -o ./bin/${filename} main.go
# if build success
if [[ $? == 0 ]];then
releases+=(${os_arch})
cd ./bin
tar -czf dvs_${goos}_${goarch}.tar.gz ${filename}
rm -rf ./${filename}
cd ../
else
fails+=(${os_arch})
fi
done
echo
if [[ -n "$fails" ]]; then
echo "fails:"
for os_arch in "${fails[@]}"
do
printf "\t%s\n" "${os_arch}"
done
fi
if [[ -n "releases" ]]; then
echo "release:"
for os_arch in "${releases[@]}"
do
printf "\t%s\n" "${os_arch}"
done
else
echo "there's no build success"
exit 1
fi
echo