【第一次安装】
1.安装gox
$ go get github.com/mitchellh/gox
$ cd $GOPATH/src/github.com/mitchellh/gox
$ go build
2.编辑~/.bash_profile(bsh) 或者~/.zshrc(zsh) 添加一行:
alias gox="$GOPATH/src/github.com/mitchellh/gox/gox"
新开终端,让设置生效。
3.生成本地工具链(如果go版本升级,比如从1.3.3升级到1.4,需要重新运行这个命令先)
$ gox -build-toolchain
注: 1.5以后,这一步不再需要了 (added 20170112)
-build-toolchain is no longer required for Go 1.5 or later.
You can start using Gox immediately!
1.比如有一个项目的目录在$GPATH/src/hello
$cd $GPATH/src/hello
$gox
Number of parallel builds: 8
--> darwin/386: hello
--> darwin/amd64: hello
--> linux/386: hello
--> linux/amd64: hello
--> linux/arm: hello
--> freebsd/386: hello
--> freebsd/amd64: hello
--> openbsd/386: hello
--> openbsd/amd64: hello
--> windows/386: hello
--> windows/amd64: hello
--> freebsd/arm: hello
--> netbsd/386: hello
--> netbsd/amd64: hello
--> netbsd/arm: hello
--> plan9/386: hello
--> dragonfly/386: hello
--> dragonfly/amd64: hello
--> solaris/amd64: hello
对应生成下面的各平台文件:
$ll
total 16768
drwxr-xr-x 23 wenke staff 782 12 30 19:42 .
drwxr-xr-x 7 wenke staff 238 12 28 16:21 ..
-rw-r--r-- 1 wenke staff 54 12 28 16:22 hello.go
-rwxr-xr-x 1 wenke staff 381420 12 30 19:42 hello_darwin_386
-rwxr-xr-x 1 wenke staff 467040 12 30 19:42 hello_darwin_amd64
-rwxr-xr-x 1 wenke staff 381536 12 30 19:42 hello_dragonfly_386
-rwxr-xr-x 1 wenke staff 469424 12 30 19:42 hello_dragonfly_amd64
-rwxr-xr-x 1 wenke staff 381296 12 30 19:42 hello_freebsd_386
-rwxr-xr-x 1 wenke staff 469240 12 30 19:42 hello_freebsd_amd64
-rwxr-xr-x 1 wenke staff 408336 12 30 19:42 hello_freebsd_arm
-rwxr-xr-x 1 wenke staff 390768 12 30 19:42 hello_linux_386
-rwxr-xr-x 1 wenke staff 475888 12 30 19:42 hello_linux_amd64
-rwxr-xr-x 1 wenke staff 413856 12 30 19:42 hello_linux_arm
-rwxr-xr-x 1 wenke staff 386440 12 30 19:42 hello_netbsd_386
-rwxr-xr-x 1 wenke staff 470448 12 30 19:42 hello_netbsd_amd64
-rwxr-xr-x 1 wenke staff 409224 12 30 19:42 hello_netbsd_arm
-rwxr-xr-x 1 wenke staff 381696 12 30 19:42 hello_openbsd_386
-rwxr-xr-x 1 wenke staff 469648 12 30 19:42 hello_openbsd_amd64
-rwxr-xr-x 1 wenke staff 365441 12 30 19:42 hello_plan9_386
-rwxr-xr-x 1 wenke staff 490296 12 30 19:42 hello_solaris_amd64
-rwxr-xr-x 1 wenke staff 385536 12 30 19:42 hello_windows_386.exe
-rwxr-xr-x 1 wenke staff 466944 12 30 19:42 hello_windows_amd64.exe
2.只生成mac和linux平台下的文件
$gox -os "darwin linux"
Number of parallel builds: 8
--> darwin/386: hello
--> darwin/amd64: hello
--> linux/386: hello
--> linux/amd64: hello
--> linux/arm: hello
3. 只生成linux平台amd64的文件
$gox -osarch="linux/amd64"
Number of parallel builds: 8
--> linux/amd64: hello