github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/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 [ "${TF_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 -arch="${XC_ARCH}" \ 43 -ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \ 44 -output "pkg/{{.OS}}_{{.Arch}}/terraform-{{.Dir}}" \ 45 ./... 46 47 # Make sure "terraform-terraform" is renamed properly 48 for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do 49 set +e 50 mv ${PLATFORM}/terraform-terraform.exe ${PLATFORM}/terraform.exe 2>/dev/null 51 mv ${PLATFORM}/terraform-terraform ${PLATFORM}/terraform 2>/dev/null 52 set -e 53 done 54 55 # Move all the compiled things to the $GOPATH/bin 56 GOPATH=${GOPATH:-$(go env GOPATH)} 57 case $(uname) in 58 CYGWIN*) 59 GOPATH="$(cygpath $GOPATH)" 60 ;; 61 esac 62 OLDIFS=$IFS 63 IFS=: MAIN_GOPATH=($GOPATH) 64 IFS=$OLDIFS 65 66 # Copy our OS/Arch to the bin/ directory 67 DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)" 68 for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do 69 cp ${F} bin/ 70 cp ${F} ${MAIN_GOPATH}/bin/ 71 done 72 73 if [ "${TF_DEV}x" = "x" ]; then 74 # Zip and copy to the dist dir 75 echo "==> Packaging..." 76 for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do 77 OSARCH=$(basename ${PLATFORM}) 78 echo "--> ${OSARCH}" 79 80 pushd $PLATFORM >/dev/null 2>&1 81 zip ../${OSARCH}.zip ./* 82 popd >/dev/null 2>&1 83 done 84 fi 85 86 # Done! 87 echo 88 echo "==> Results:" 89 ls -hl bin/