github.com/leowmjw/otto@v0.2.1-0.20160126165905-6400716cf085/scripts/build.sh (about) 1 #!/bin/bash 2 # 3 # This script builds the application from source for multiple platforms. 4 set -e 5 6 # Get the parent directory of where this script is. 7 SOURCE="${BASH_SOURCE[0]}" 8 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done 9 DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" 10 11 # Change into that directory 12 cd "$DIR" 13 14 # Get the git commit 15 GIT_COMMIT=$(git rev-parse HEAD) 16 GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) 17 18 # Determine the arch/os combos we're building for 19 XC_ARCH=${XC_ARCH:-"386 amd64 arm"} 20 XC_OS=${XC_OS:-linux darwin windows freebsd openbsd} 21 22 # Install dependencies 23 echo "==> Getting dependencies..." 24 go get ./... 25 26 # Delete the old dir 27 echo "==> Removing old directory..." 28 rm -f bin/* 29 rm -rf pkg/* 30 mkdir -p bin/ 31 32 # If its dev mode, only build for ourself 33 if [ "${OTTO_DEV}x" != "x" ]; then 34 XC_OS=$(go env GOOS) 35 XC_ARCH=$(go env GOARCH) 36 fi 37 38 # Build! 39 echo "==> Building..." 40 gox \ 41 -os="${XC_OS}" \ 42 -os="!freebsd" \ 43 -os="!openbsd" \ 44 -arch="${XC_ARCH}" \ 45 -ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \ 46 -output "pkg/{{.OS}}_{{.Arch}}/otto" \ 47 . 48 49 # Move all the compiled things to the $GOPATH/bin 50 GOPATH=${GOPATH:-$(go env GOPATH)} 51 case $(uname) in 52 CYGWIN*) 53 GOPATH="$(cygpath $GOPATH)" 54 ;; 55 esac 56 OLDIFS=$IFS 57 IFS=: MAIN_GOPATH=($GOPATH) 58 IFS=$OLDIFS 59 60 # Copy our OS/Arch to the bin/ directory 61 DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)" 62 for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do 63 cp ${F} bin/ 64 cp ${F} ${MAIN_GOPATH}/bin/ 65 done 66 67 if [ "${OTTO_DEV}x" = "x" ]; then 68 # Zip and copy to the dist dir 69 echo "==> Packaging..." 70 for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do 71 OSARCH=$(basename ${PLATFORM}) 72 echo "--> ${OSARCH}" 73 74 pushd $PLATFORM >/dev/null 2>&1 75 zip ../${OSARCH}.zip ./* 76 popd >/dev/null 2>&1 77 done 78 fi 79 80 # Done! 81 echo 82 echo "==> Results:" 83 ls -hl bin/