Simple Makefile for Go projects


How to create a simple Makefile for building Go projects.

So, I’ve recently started coding in Go and found that when moving projects between different computers, it was a hassle to remember which dependencies I needed to install, which commands did what, etc. So I created my own Makefile which means I only need to remember “make”, “make test” and “make run”.

After some trial and errors, this is the Makefile I found to work well enough:

all: project_name

project_name: *.go subdirectory/*.go
    go build .

    rm -rf project_name


    go test ./... -v

    go get -u


I’ve just started working in Go, so this file is by all means not the perfect Makefile out there for Go, it’s just something I’ve fiddled with to get a smooth experience working with Go projects.

If you have a better solution on how to handle this, please send me a Tweet @hagbarddenstore