2 ms·
After struggling a lot, I think, I finally understood best use for GOPATH with Makefile based projects. I use it as follows: I have ~/go for all 3rd party code
by iambvk 9y ago
After struggling a lot, I think, I finally understood best use for GOPATH with Makefile based projects. I use it as follows:
I have ~/go for all 3rd party code that I did not develop. My personal projects live in a different directory with a different structure (including, configure.ac, Makefile.am, etc.). My projects tend to use multiple languages, so I need Makefile support.
I fix GOPATH in project specific Makefiles with ~/go as the first directory followed by project specific directory for Go code. For example, I add the following in Makefile.am of every project.
GOPATH := $(HOME)/go:$(CURDIR)/go
One cool result of this is: When I do go-get of any 3rd party package (either through command-line or as part of a rule from Makefiles), Go downloads them into ~/go directory (it picks the first directory in GOPATH or defaults to ~/go). This leaves my project specific directories free of 3rd party code -- which is what I want.
End result is, ~/go ends up with 3rd party code from across all projects and it doesn't include my project code, so can be deleted any time and re-created automatically by Makefile rules.