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