Created
September 8, 2016 18:03
-
-
Save longkai/0721a35eed899e0732aa4e47f5844023 to your computer and use it in GitHub Desktop.
A simple golang cross compile script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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