by nstart · 9y ago · 0 comments
```
export GOPATH=$(pwd)
export PATH=$PATH:$GOPATH/bin
go install target/to/build
export GOOS=darwin
export GOARCH=amd64
go install target/to/build
```
which should be simple. Right? Set environment variables, run a command. Set another environment variable, run a command.
45 minutes in and I haven't been able to quite figure it out just yet. I definitely figured out how to write my build.sh files in less than 15 minutes for sure when I started out.
It uses a private GOPATH inside the repo, created by:
$ cd /path/to/repo
$ mkdir -p .gopath/src/github.com/username
$ ln -s ../../../.. .gopath/src/github.com/username/projectname
With this you can run `go build` etc. with `GOPATH=/path/to/repo/.gopath` and it will work regardless of where the repo is checked out, and you can also `go get` the repo into the normal `GOPATH`.It's the best of both worlds, in a way. A Go developer can use `go get` etc. and everything works as he expects. A distro packager can grab a release tarball, unpack it in some random place and do `make && make check && make install DESTDIR=/tmp/build` as she expects.
This is why many who use Go don't get all the fuss with makefiles that some folks insist on. You just go to your project directory and 'go test' or 'go build' or whatnot. Simple. No need to 'make test' or 'make build' unless you have some strange, complicated set up.