-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·56 lines (52 loc) · 1.44 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
#!/bin/bash
echo "Please select the compiled platform version"
# export CGO_ENABLED=0
# shellcheck disable=SC2006
BuildTime=`date +'%Y.%m.%d %H:%M:%S'`
BuildGoVersion="$(go version)"
LdFlags="-X 'github.com/sohaha/zzz/cmd.buildTime=${BuildTime}' -X 'github.com/sohaha/zzz/cmd.buildGoVersion=${BuildGoVersion}' "
NAME="zzz"
GOOS_D="Darwin/amd64"
GOOS_L="Linux/amd64"
GOOS_W="Windows/amd64"
GOOS_A=$(uname)/$(uname -m)
GOOS_Z="All"
GOARCH=amd64
__CGO_EN__=0
select opt in $GOOS_A" (auto)" $GOOS_D $GOOS_L $GOOS_W $GOOS_Z;do
if [ "$opt" = $GOOS_D ];then
GOOS=darwin
BUILD_NAME=$NAME.sh
break
elif [ "$opt" = $GOOS_L ];then
GOOS=linux
BUILD_NAME=$NAME
break
elif [ "$opt" = $GOOS_W ];then
GOOS=windows
BUILD_NAME=$NAME.exe
break
elif [ "$opt" = $GOOS_Z ];then
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$LdFlags -s -w" -o ./dist/$NAME ./
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$LdFlags -s -w" -o ./dist/$NAME.sh ./
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$LdFlags -s -w" -o ./dist/$NAME.exe ./
echo Compiled
exit
else
__CGO_EN__=
GOARCH=
GOOS=
echo "Compile the current version of the platform"
BUILD_NAME=zzz
break
fi
done
if [ "$opt" = "" ];then
__CGO_EN__=
GOARCH=
GOOS=
echo "Compile the current version of the platform"
BUILD_NAME=zzz
fi
CGO_ENABLED=$__CGO_EN__ GOARCH=$GOARCH GOOS=$GOOS go build -ldflags "$LdFlags -s -w" -o ./dist/$BUILD_NAME ./
echo $GOOS Compiled