Skip to content

Instantly share code, notes, and snippets.

@HalCanary
Created November 28, 2023 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HalCanary/6ef3cd986544c32d5f6aa2689b869c13 to your computer and use it in GitHub Desktop.
Save HalCanary/6ef3cd986544c32d5f6aa2689b869c13 to your computer and use it in GitHub Desktop.
Go Makefile Example
all: test build
COMMANDS = $(notdir $(wildcard cmd/*))
BINARIES = $(addprefix build/,$(COMMANDS))
${BINARIES}: $(shell find . -name '*.go') go.mod go.sum
@mkdir -p build
go get ./...
go build -o build ./...
${HOME}/bin/%: build/%
@mkdir -p $(dir $@)
cp $^ $@
build: ${BINARIES}
install: $(addprefix ${HOME}/bin/,${COMMANDS})
clean:
rm -rf build
test:
go get ./...
go test ./...
fmt:
find . -type f -name '*.go' -exec gofmt -w {} \;
update_deps:
go get -u ./...
go mod tidy
.PHONY: all build clean fmt install test update_deps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment