On Aug 22, 2021, at 23:11, jlfo...@berkeley.edu <jlforr...@berkeley.edu> wrote:
> 
> 
> I've noticed that few, if any, Go programs use Makefiles. Is that because the 
> overhead of using make is greater than the overhead of just always compiling 
> and linking everything?
> One piece of evidence for this is that the Go compiler leaves no artifacts, 
> like object files, so as is make wouldn't fit into the current build method.

I use Makefiles in our own internal projects because it allows me to establish 
a lot of good tooling around them, especially for repos which build a lot of 
binaries, Dockerize them, etc. It’s quite useful, despite the lack of 
intermediate files which Make tends to rely on to determine whether to rebuild 
things. Among other things, Make deals a lot better with lists of files and the 
concept of prerequisite steps than e.g. Bourne shell, and the Make package is 
actually considerably smaller than Bash in most tiny distros like Alpine, which 
is a consideration for Dockerfiles.

Unfortunately, to make Make worth the effort in Go projects, you need to 
understand it, otherwise you’ll just wind up with a lot of independent targets 
with a lot of repetitive code. Many developers these days (especially newer 
ones) have never been exposed to Make other than just running it and aren’t 
aware of what it can do, and so tend not to understand why you might not use it 
instead of e.g. Bash (they also tend not to understand why it might not be a 
good idea to use Bashisms instead of vanilla Bourne shell, but that’s a 
conversation for another time).

Basically, Make can make your Go projects a lot more intuitive to build, 
especially when it comes to things like default flags and consistency with CI, 
but you do have to put some effort into it, and you have to get people over the 
“Make is hard” mindset or they will “fix” your project by getting rid of it, 
IME.

FWIW, our default “make test” target generally just does “go test -race ./…”, 
with some optional coverage arguments spliced in when you “make cover”. “make 
cover-report” is where Make starts to shine; there’s a file prerequisite rule 
defined for the coverage file as well as for the HTML coverage report, and 
“make cover-report” just says to build the report file and Make’s dependency 
resolution magically takes care of the rest. It’s actually a pretty good basic 
demonstration of capabilities that used to be considered standard knowledge.


- Dave

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/052168C4-EFE0-49AA-AEDC-8B3557025C81%40gmail.com.

Reply via email to