github.com/aminjam/goflat@v0.4.1-0.20160331105230-ec639fc0d5b3/scripts/build.bash (about) 1 #!/bin/bash 2 3 build() { 4 local commit=$(git rev-parse HEAD) 5 local dirty=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) 6 local message=$(git describe --tags) 7 local ldflag="-X main.GitCommit=${commit}${dirty} -X main.GitDescribe=${message}" 8 9 local os="darwin freebsd linux windows" 10 local arch="386 amd64 arm" 11 if [ "${DEV}" == "dev" ]; then 12 local os=$(go env GOOS) 13 local arch=$(go env GOARCH) 14 fi 15 16 # Build! 17 echo "==> Building ${MAIN_PACKAGE}...(${arch}) for (${os})" 18 gox \ 19 -os="${os}" \ 20 -arch="${arch}" \ 21 -ldflags="${ldflag}" \ 22 -output="$DIR/pkg/{{.OS}}_{{.Arch}}/${BINARY_NAME}" \ 23 ${MAIN_PACKAGE} 24 } 25 26 copy_to_path() { 27 # Copy our OS/Arch to the bin/ directory 28 local binary_file="$DIR/pkg/$(go env GOOS)_$(go env GOARCH)" 29 for F in $(find ${binary_file} -mindepth 1 -maxdepth 1 -type f); do 30 cp ${F} "${GOPATH}/bin/" 31 done 32 } 33 34 package() { 35 echo "==> Packaging..." 36 for PLATFORM in $(find $DIR/pkg -mindepth 1 -maxdepth 1 -type d); do 37 local osarch=$(basename ${PLATFORM}) 38 echo "--> ${osarch}" 39 pushd $PLATFORM >/dev/null 2>&1 40 zip ../${osarch}.zip ./* 41 popd >/dev/null 2>&1 42 done 43 } 44 45 main() { 46 set +e 47 set -o pipefail 48 49 SOURCE="${BASH_SOURCE[0]}" 50 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done 51 DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" 52 rm -rf $DIR/pkg 53 mkdir -p $DIR/pkg 54 55 #parse args 56 BINARY_NAME=$1 57 MAIN_PACKAGE=$2 58 DEV=$3 59 60 build 61 copy_to_path 62 63 if [ "$DEV" != "dev" ]; then 64 package 65 fi 66 } 67 68 main "$@" 69