2015-11-04 09:29:26 -05:00
|
|
|
#!/usr/bin/env bash
|
2017-02-02 02:05:09 -05:00
|
|
|
|
2014-09-02 18:13:55 -04:00
|
|
|
# This script builds the application from source for multiple platforms.
|
2017-02-02 02:05:09 -05:00
|
|
|
# Determine the arch/os combos we're building for
|
|
|
|
ALL_XC_ARCH="386 amd64 arm arm64 ppc64le"
|
|
|
|
ALL_XC_OS="linux darwin windows freebsd openbsd solaris"
|
|
|
|
|
2014-09-02 18:13:55 -04:00
|
|
|
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
|
|
|
|
cd $DIR
|
|
|
|
|
|
|
|
# Delete the old dir
|
|
|
|
echo "==> Removing old directory..."
|
|
|
|
rm -f bin/*
|
|
|
|
rm -rf pkg/*
|
|
|
|
mkdir -p bin/
|
|
|
|
|
2017-02-02 02:05:09 -05:00
|
|
|
# helpers for Cygwin-hosted builds
|
|
|
|
: ${OSTYPE:=`uname`}
|
|
|
|
|
|
|
|
case $OSTYPE in
|
|
|
|
MINGW*|MSYS*|cygwin|CYGWIN*)
|
|
|
|
# cygwin only translates ';' to ':' on select environment variables
|
|
|
|
PATHSEP=';'
|
2017-02-02 02:05:09 -05:00
|
|
|
;;
|
2017-02-02 02:05:09 -05:00
|
|
|
*) PATHSEP=':'
|
2017-02-02 02:05:09 -05:00
|
|
|
esac
|
|
|
|
|
2017-02-02 02:05:09 -05:00
|
|
|
function convert_path() {
|
|
|
|
local flag
|
|
|
|
[ "${1:0:1}" = '-' ] && { flag="$1"; shift; }
|
|
|
|
|
|
|
|
[ -n "$1" ] || return 0
|
|
|
|
case ${OSTYPE:-`uname`} in
|
|
|
|
cygwin|CYGWIN*)
|
|
|
|
cygpath $flag -- "$1"
|
|
|
|
;;
|
|
|
|
*) echo "$1"
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# XXX works in MINGW?
|
|
|
|
which go &>/dev/null || PATH+=":`convert_path "${GOROOT:?}"`/bin"
|
|
|
|
|
|
|
|
OLDIFS="$IFS"
|
|
|
|
|
|
|
|
# make sure GOPATH is consistent - Windows binaries can't handle Cygwin-style paths
|
|
|
|
IFS="$PATHSEP"
|
|
|
|
for d in ${GOPATH:-$(go env GOPATH)}; do
|
|
|
|
_GOPATH+="${_GOPATH:+$PATHSEP}$(convert_path --windows "$d")"
|
|
|
|
done
|
|
|
|
GOPATH="$_GOPATH"
|
|
|
|
|
|
|
|
# locate 'gox' and traverse GOPATH if needed
|
|
|
|
which "${GOX:=gox}" &>/dev/null || {
|
|
|
|
for d in $GOPATH; do
|
|
|
|
GOX="$(convert_path --unix "$d")/bin/gox"
|
|
|
|
[ -x "$GOX" ] && break || unset GOX
|
|
|
|
done
|
|
|
|
}
|
|
|
|
IFS="$OLDIFS"
|
|
|
|
|
2014-09-02 18:13:55 -04:00
|
|
|
# Build!
|
|
|
|
echo "==> Building..."
|
2017-02-02 02:05:09 -05:00
|
|
|
|
|
|
|
# If in dev mode, only build for ourself
|
|
|
|
if [ -n "${PACKER_DEV+x}" ]; then
|
|
|
|
XC_OS=$(go env GOOS)
|
|
|
|
XC_ARCH=$(go env GOARCH)
|
|
|
|
fi
|
|
|
|
|
2014-09-11 14:51:44 -04:00
|
|
|
set +e
|
2017-02-02 02:05:09 -05:00
|
|
|
${GOX:?command not found} \
|
|
|
|
-os="${XC_OS:-$ALL_XC_OS}" \
|
|
|
|
-arch="${XC_ARCH:-$ALL_XC_ARCH}" \
|
2017-05-15 16:31:38 -04:00
|
|
|
-osarch="!darwin/arm !darwin/arm64" \
|
2017-05-04 23:30:09 -04:00
|
|
|
-ldflags "${GOLDFLAGS}" \
|
2015-10-21 19:41:58 -04:00
|
|
|
-output "pkg/{{.OS}}_{{.Arch}}/packer" \
|
|
|
|
.
|
2017-02-02 02:05:09 -05:00
|
|
|
set -e
|
2014-09-02 18:13:55 -04:00
|
|
|
|
2017-02-02 02:05:09 -05:00
|
|
|
# trim GOPATH to first element
|
|
|
|
IFS="$PATHSEP"
|
|
|
|
MAIN_GOPATH=($GOPATH)
|
|
|
|
MAIN_GOPATH="$(convert_path --unix "$MAIN_GOPATH")"
|
2014-09-07 18:58:36 -04:00
|
|
|
IFS=$OLDIFS
|
|
|
|
|
2014-09-02 18:13:55 -04:00
|
|
|
# Copy our OS/Arch to the bin/ directory
|
2014-09-07 18:58:36 -04:00
|
|
|
echo "==> Copying binaries for this platform..."
|
2017-02-02 02:05:09 -05:00
|
|
|
DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)"
|
2018-04-09 19:47:41 -04:00
|
|
|
for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f 2>/dev/null); do
|
2017-02-02 02:05:09 -05:00
|
|
|
cp -v ${F} bin/
|
2017-02-02 02:05:09 -05:00
|
|
|
cp -v ${F} ${MAIN_GOPATH}/bin/
|
2014-09-02 18:13:55 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
# Done!
|
|
|
|
echo
|
|
|
|
echo "==> Results:"
|
|
|
|
ls -hl bin/
|