2014-10-06 16:58:23 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-12-19 19:22:08 +00:00
|
|
|
#
|
|
|
|
# This script builds the application from source.
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Get the parent directory of where this script is.
|
|
|
|
SOURCE="${BASH_SOURCE[0]}"
|
|
|
|
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
|
|
|
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
|
|
|
|
|
|
|
# Change into that directory
|
2015-09-11 16:19:22 +00:00
|
|
|
cd "$DIR"
|
2013-12-19 19:22:08 +00:00
|
|
|
|
|
|
|
# Get the git commit
|
|
|
|
GIT_COMMIT=$(git rev-parse HEAD)
|
|
|
|
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
2014-11-18 22:06:46 +00:00
|
|
|
GIT_DESCRIBE=$(git describe --tags)
|
2013-12-19 19:22:08 +00:00
|
|
|
|
|
|
|
# If we're building on Windows, specify an extension
|
|
|
|
EXTENSION=""
|
|
|
|
if [ "$(go env GOOS)" = "windows" ]; then
|
|
|
|
EXTENSION=".exe"
|
|
|
|
fi
|
|
|
|
|
2014-05-01 17:55:54 +00:00
|
|
|
GOPATHSINGLE=${GOPATH%%:*}
|
|
|
|
if [ "$(go env GOOS)" = "windows" ]; then
|
|
|
|
GOPATHSINGLE=${GOPATH%%;*}
|
|
|
|
fi
|
|
|
|
|
2014-05-30 20:05:06 +00:00
|
|
|
if [ "$(go env GOOS)" = "freebsd" ]; then
|
|
|
|
export CC="clang"
|
|
|
|
fi
|
|
|
|
|
2014-06-11 17:07:38 +00:00
|
|
|
# On OSX, we need to use an older target to ensure binaries are
|
|
|
|
# compatible with older linkers
|
|
|
|
if [ "$(go env GOOS)" = "darwin" ]; then
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET=10.6
|
|
|
|
fi
|
|
|
|
|
2013-12-19 19:22:08 +00:00
|
|
|
# Install dependencies
|
|
|
|
echo "--> Installing dependencies to speed up builds..."
|
2014-05-30 20:05:06 +00:00
|
|
|
go get \
|
|
|
|
-ldflags "${CGO_LDFLAGS}" \
|
|
|
|
./...
|
2013-12-19 19:22:08 +00:00
|
|
|
|
|
|
|
# Build!
|
|
|
|
echo "--> Building..."
|
|
|
|
go build \
|
2014-11-18 22:06:46 +00:00
|
|
|
-ldflags "${CGO_LDFLAGS} -X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY} -X main.GitDescribe ${GIT_DESCRIBE}" \
|
2013-12-19 19:22:08 +00:00
|
|
|
-v \
|
|
|
|
-o bin/consul${EXTENSION}
|
2015-09-11 16:19:22 +00:00
|
|
|
cp bin/consul${EXTENSION} "${GOPATHSINGLE}/bin"
|