1+ #! /usr/bin/env bash
2+ # #####
3+ #
4+ # This script will build bitrex-cli and
5+ # calculate hash for each (DEP_BUILD_PLATFORMS, DEP_BUILD_ARCHS) pair.
6+ #
7+ # usage:
8+ # # build only for linux-amd64
9+ # DEP_BUILD_PLATFORMS="linux" DEP_BUILD_ARCHS="amd64" ./bin/build-all.bash
10+ #
11+ # Based on https://github.com/golang/dep/blob/5bdae264c61be23446d622ea84a1c97b895f78cc/hack/build-all.bash
12+ # Copyright 2017 The Go Authors. All rights reserved.
13+ # Use of this source code is governed by a BSD-style
14+ # license that can be found in the LICENSE file.
15+ # https://github.com/golang/dep/blob/master/LICENSE
16+ # https://github.com/golang/dep/blob/master/PATENTS
17+ #
18+ # #####
19+
20+ set -e
21+
22+ REPO_ROOT=$( git rev-parse --show-toplevel)
23+ VERSION=$( git describe --tags --dirty)
24+ COMMIT_HASH=$( git rev-parse --short HEAD 2> /dev/null)
25+ DATE=$( date " +%Y-%m-%d" )
26+ IMPORT_DURING_SOLVE=${IMPORT_DURING_SOLVE:- false}
27+
28+ if [[ " $( pwd) " != " ${REPO_ROOT} " ]]; then
29+ echo " you are not in the root of the repo" 1>&2
30+ echo " please cd to ${REPO_ROOT} before running this script" 1>&2
31+ exit 1
32+ fi
33+
34+ GO_BUILD_CMD=" go build -a -installsuffix cgo"
35+ GO_BUILD_LDFLAGS=" -s -w \
36+ -X main.commitHash=${COMMIT_HASH} \
37+ -X main.buildDate=${DATE} \
38+ -X main.version=${VERSION} \
39+ -X main.flagImportDuringSolve=${IMPORT_DURING_SOLVE} "
40+
41+ if [[ -z " ${DEP_BUILD_PLATFORMS} " ]]; then
42+ DEP_BUILD_PLATFORMS=" linux windows darwin freebsd"
43+ fi
44+
45+ if [[ -z " ${DEP_BUILD_ARCHS} " ]]; then
46+ DEP_BUILD_ARCHS=" amd64 386"
47+ fi
48+
49+ mkdir -p " ${REPO_ROOT} /release"
50+
51+ for OS in ${DEP_BUILD_PLATFORMS[@]} ; do
52+ for ARCH in ${DEP_BUILD_ARCHS[@]} ; do
53+ NAME=" bittrex-cli-${OS} -${ARCH} "
54+ if [[ " ${OS} " == " windows" ]]; then
55+ NAME=" ${NAME} .exe"
56+ fi
57+ echo " building for ${OS} /${ARCH} "
58+ GOARCH=${ARCH} GOOS=${OS} CGO_ENABLED=0 ${GO_BUILD_CMD} -ldflags " ${GO_BUILD_LDFLAGS} " \
59+ -o " ${REPO_ROOT} /release/${NAME} " .
60+ shasum -a 256 " ${REPO_ROOT} /release/${NAME} " > " ${REPO_ROOT} /release/${NAME} " .sha256
61+ done
62+ done
0 commit comments