Created
November 28, 2023 12:05
-
-
Save HalCanary/6ef3cd986544c32d5f6aa2689b869c13 to your computer and use it in GitHub Desktop.
Go Makefile Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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