Skip to content

Instantly share code, notes, and snippets.

@longkai

longkai/gocp.sh

Created Sep 8, 2016
Embed
What would you like to do?
A simple golang cross compile script
#!/bin/sh
# A simple golang(go 1.5+) cross compile script.
# Usage `gocp.sh [os] [version]`, default OS linux/mac/freebsd/window 64 binary with bzip2 format or zip(only windows) compression format with `latest` version.
# output pattern `os-arch-version.tar.bz2` or `os-arch-version.zip`
name=${PWD##*/}
v=$2
if [ -z "$v" ]; then
v="latest"
fi
build() {
GOOS=$1 GOARCH=$2 go build
case $3 in
tar)
tar jcf "$name-$1-$2-$v.tar.bz2" $name && rm -f $name
;;
zip)
zip "$name-$1-$2-$v.zip" $name.exe && rm -f $name.exe
;;
*)
echo "unsupport format $3"
;;
esac
}
case "$1" in
linux)
build linux amd64 tar
#build linux 386 tar
;;
darwin)
build darwin amd64 tar
;;
windows)
build windows amd64 zip
#build windows 386 zip
;;
freebsd)
build freebsd amd64 tar
;;
*)
build linux amd64 tar
build darwin amd64 tar
build freebsd amd64 tar
build windows amd64 zip
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment