-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·53 lines (46 loc) · 1.57 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
#!/bin/sh
ARCHS="darwin linux freebsd windows"
BINDIR="bin"
BINARY="super-hacker"
if [ -z $1 ]; then
echo "error: requires argument of [release|freebsd|darwin|linux|windows]"
exit 1
fi
if [ -z $2 ]; then
echo "error: requires version argument"
exit 1
fi
VERSION=$2
LDFLAGS="-X main.gitSHA=$(git rev-parse HEAD) -X main.version=${VERSION} -X main.name=${BINARY}"
if [ $1 == "release" ]; then
echo "Generating ${BINARY} release binaries..."
for arch in ${ARCHS}; do
GOOS=${arch} GOARCH=amd64 go build -v -ldflags "${LDFLAGS}" -o ${BINDIR}/${BINARY}-${arch}
done
fi
case "$1" in
"release")
echo "Building release..."
for arch in ${ARCHS}; do
GOOS=${arch} GOARCH=amd64 go build -v -ldflags "${LDFLAGS}" -o ${BINDIR}/${BINARY}-${arch}
tar -czvf ${BINDIR}/${BINARY}-${arch}.tar.gz ${BINDIR}/${BINARY}-${arch}
done
;;
"freebsd")
echo "Building binary for FreeBSD..."
GOOS=freebsd GOARCH=amd64 go build -v -ldflags "${LDFLAGS}" -o ${BINDIR}/${BINARY}-freebsd
;;
"darwin")
echo "Building binary for Darwin..."
GOOS=darwin GOARCH=amd64 go build -v -ldflags "${LDFLAGS}" -o ${BINDIR}/${BINARY}-darwin
;;
"linux")
echo "Building binary for Linux..."
GOOS=linux GOARCH=amd64 go build -v -ldflags "${LDFLAGS}" -o ${BINDIR}/${BINARY}-linux
;;
"windows")
echo "Building binary for Windows..."
GOOS=windows GOARCH=amd64 go build -v -ldflags "${LDFLAGS}" -o ${BINDIR}/${BINARY}-windows.exe
;;
esac
exit 0