github.com/yoctocloud/packer@v0.6.2-0.20160520224004-e11a0a18423f/scripts/build.sh (about) 1 #!/usr/bin/env 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 # If its dev mode, only build for ourself 19 if [ "${PACKER_DEV}x" != "x" ]; then 20 XC_OS=${XC_OS:-$(go env GOOS)} 21 XC_ARCH=${XC_ARCH:-$(go env GOARCH)} 22 fi 23 24 # Determine the arch/os combos we're building for 25 XC_ARCH=${XC_ARCH:-"386 amd64 arm"} 26 XC_OS=${XC_OS:-linux darwin windows freebsd openbsd} 27 28 # Delete the old dir 29 echo "==> Removing old directory..." 30 rm -f bin/* 31 rm -rf pkg/* 32 mkdir -p bin/ 33 34 # Build! 35 echo "==> Building..." 36 set +e 37 gox \ 38 -os="${XC_OS}" \ 39 -arch="${XC_ARCH}" \ 40 -ldflags "-X github.com/mitchellh/packer/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" \ 41 -output "pkg/{{.OS}}_{{.Arch}}/packer" \ 42 . 43 set -e 44 45 # Move all the compiled things to the $GOPATH/bin 46 GOPATH=${GOPATH:-$(go env GOPATH)} 47 case $(uname) in 48 CYGWIN*) 49 GOPATH="$(cygpath $GOPATH)" 50 ;; 51 esac 52 OLDIFS=$IFS 53 IFS=: 54 case $(uname) in 55 MINGW*) 56 IFS=";" 57 ;; 58 MSYS*) 59 IFS=";" 60 ;; 61 esac 62 MAIN_GOPATH=($GOPATH) 63 IFS=$OLDIFS 64 65 # Copy our OS/Arch to the bin/ directory 66 echo "==> Copying binaries for this platform..." 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 # Done! 74 echo 75 echo "==> Results:" 76 ls -hl bin/