open-vault/scripts/build.sh

60 lines
1.3 KiB
Bash
Raw Normal View History

2015-07-22 02:06:54 +00:00
#!/usr/bin/env bash
2015-03-04 07:14:18 +00:00
#
# This script builds the application from source for multiple platforms.
set -e
GO_CMD=${GO_CMD:-go}
2015-03-04 07:14:18 +00:00
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
SOURCE_DIR=$( dirname "$SOURCE" )
2015-03-04 07:14:18 +00:00
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$SOURCE_DIR/.." && pwd )"
2015-03-04 07:14:18 +00:00
# Change into that directory
cd "$DIR"
2016-04-28 00:47:44 +00:00
# Set build tags
2016-04-28 00:59:33 +00:00
BUILD_TAGS="${BUILD_TAGS:-"vault"}"
2016-04-28 00:47:44 +00:00
2015-03-04 07:14:18 +00:00
# Get the git commit
GIT_COMMIT="$(git rev-parse HEAD)"
GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)"
2015-03-04 07:14:18 +00:00
BUILD_DATE=$("$SOURCE_DIR"/build_date.sh)
GOPATH=${GOPATH:-$(${GO_CMD} env GOPATH)}
case $(uname) in
CYGWIN*)
GOPATH="$(cygpath $GOPATH)"
;;
esac
2015-03-04 07:14:18 +00:00
# Delete the old dir
echo "==> Removing old directory..."
rm -f bin/*
rm -rf pkg/*
mkdir -p bin/
# Build!
echo "==> Building..."
${GO_CMD} build \
-gcflags "${GCFLAGS}" \
-ldflags "${LD_FLAGS} -X github.com/hashicorp/vault/sdk/version.GitCommit='${GIT_COMMIT}${GIT_DIRTY}' -X github.com/hashicorp/vault/sdk/version.BuildDate=${BUILD_DATE}" \
-o "bin/vault" \
-tags "${BUILD_TAGS}" \
2015-03-04 07:14:18 +00:00
.
# Move all the compiled things to the $GOPATH/bin
OLDIFS=$IFS
IFS=: MAIN_GOPATH=($GOPATH)
2015-03-04 07:14:18 +00:00
IFS=$OLDIFS
rm -f ${MAIN_GOPATH}/bin/vault
cp bin/vault ${MAIN_GOPATH}/bin/
2015-03-04 07:14:18 +00:00
# Done!
echo
echo "==> Results:"
ls -hl bin/