See https://github.com/hashicorp/consul/blob/v0.7.5/scripts/build.sh#L44 for how consul's build script does it.