Perhaps the most idiomatic way of achieving this is: GOBIN=$PWD go install ./cmd/{foo,bar}
go install is also more efficient than go build because it will only perform the link step if the target is out of date. I'm no expert with make, so I don't know how this sort of approach maps back onto make. Returning however to the problem you're seeing with your existing setup, a change in Go 1.12 should prevent the race condition you're seeing: https://go-review.googlesource.com/c/go/+/146380 On Fri, 18 Jan 2019 at 01:41, Tycho Andersen <ty...@tycho.ws> wrote: > > Hi everyone, > > I'm trying to get an existing project which outputs multiple binaries > to work with go modules. The package follows roughly the recommended > layout: https://github.com/golang-standards/project-layout > > That is, it looks like > > /go.mod > /go.sum > /code.go > /cmd/foo/main.go > /cmd/bar/main.go > > I have a top level make file that looks roughly like: > > all: foo bar > > foo: ... > go build -o foo ./cmd/foo/... > > bar: ... > go build -o bar ./cmd/bar/... > > When I type "make", it seems like go.sum and go.mod end up with only > bar's dependencies, because the last go invocation prunes the "unused" > dependencies from the module files. I've tried various ways of using > mutiple go.mod and go.sum files (one in each binary directory), but I > can't quite get the includes of the top level package right. > > I see https://github.com/golang/go/issues/14295, which will solve this > problem for me, but it doesn't exist yet. > > Is there some clever way of structuring a project like this with go > modules that I haven't figured out yet? > > Thanks, > > Tycho > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.