How to write better Makefiles for Go
Jan 4, 2021
TL;DR: go env
exists
Everyone knows them, not everyone loves them: Makefiles. Say what you want — they are useful.
When writing Makefiles for Go there are often some “hacky” ways to do simple tasks like getting the .exe
on Windows or GOOS
in general. A short list I compiled from GitHub: (ngl, some of these are kinda genius)
Introducing go env
. Have you heard of go env
? I didn’t, at least not until some days ago. So what does it do? Well…
Looks a bit like go tool dist env
, doesn’t it?
That’s because they do basically the same thing (go tool dist
just prints a subset). But go env
can something the other can’t:
So I assume we can all see where this leads: