-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·40 lines (31 loc) · 1.13 KB
/
make.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
#!/bin/bash -e
errEcho() { echo "$@" 1>&2; }
# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
pink=`tput setaf 5`
blue=`tput setaf 6`
reset=`tput sgr0`
FILENAME="dp"
# -s -w reduce the size of the binary
LDFLAGS="-X main.VERSION=$(git describe --always --long) -s -w"
build_linux() {
echo -e "*** Building Linux binary in: ${green}$FILENAME${reset}"
GOOS=linux GOARCH=amd64 go build -tags "netgo" -ldflags "$LDFLAGS" -o $FILENAME *.go
}
build_mac() {
echo -e "*** Building darwin binary in: ${green}$FILENAME${reset}"
GOOS=darwin GOARCH=amd64 go build -tags "netgo" -ldflags "$LDFLAGS" -o $FILENAME *.go
}
build_alpine() {
echo -e "*** Building Alpine binary in: ${green}$FILENAME${reset}"
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags "netgo" -ldflags "$LDFLAGS" -o $FILENAME *.go
}
errEcho
errEcho "*** ${green}$0${reset} executed with params: ${blue}$1 $2${reset}"
SUBCMD=$1
test "$SUBCMD" = "build-alpine" && build_alpine
test "$SUBCMD" = "build-linux" && build_linux
test "$SUBCMD" = "build-mac" && build_mac
exit 0