forked from howtowhale/dvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·58 lines (49 loc) · 1.49 KB
/
build
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
#!/usr/bin/env bash
# build - builds for the current OS and ARCH
# build all - builds entire matrix
cd $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
get_commit() {
COMMIT=$(git rev-parse --verify --short HEAD)
RETURN_CODE=$?
export COMMIT
return $RETURN_CODE
}
get_version() {
# Version will be the most recent tag + "-dev" if working tree is dirty
# e.g.: "1.0.1"" or "1.0.1-dev"
VERSION=$(git describe --tags --dirty='-dev' 2> /dev/null)
export VERSION
return 0
}
build() {
# Detect the current OS and ARCH if not specified
[ -z "$1" ] && local GOOS=$(uname -s | tr '[:upper:]' '[:lower:]') || local GOOS=$1
[ -z "$2" ] && local GOARCH=$([ $(getconf LONG_BIT) == 64 ] && echo amd64 || echo 386) || local GOARCH=$2
[ "$GOOS" == "windows" ] && local FILE_EXT=".exe" || local FILE_EXT=""
local BINARY="dvm-helper-${GOOS}-${GOARCH}${FILE_EXT}"
GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "${LDFLAGS}" -o bin/$BINARY
$(cd bin && shasum -a 256 $BINARY > $BINARY.sha256)
}
# Remove previously downloaded dvm-helper binaries
if [ -e 'dvm-helper' ]; then
rm dvm-helper
fi
if [ -e 'dvm-helper.exe' ]; then
rm dvm-helper.exe
fi
# Use information about git repo to set the binary version and commit
get_commit
get_version
LDFLAGS="-X main.dvmCommit=${COMMIT} \
-X main.dvmVersion=${VERSION}"
# Build ALL THE THINGS!
if [ "$1" != "all" ]; then
build
else
build windows amd64
build windows 386
build darwin amd64
build darwin 386
build linux amd64
build linux 386
fi