Last active
April 12, 2023 00:26
-
-
Save Lajule/a6ffd658cf622b41a772988408361ad3 to your computer and use it in GitHub Desktop.
Makefile for Go
This file contains hidden or 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
# Makefile for Golang projects | |
SHELL := /bin/sh | |
BINARY ?= bin | |
VERSION ?= 0.0.1 | |
PACKAGE ?= github.com/Lajule/bin | |
.PHONY: all | |
all: tidy generate build | |
.PHONY: build | |
build: | |
go build -ldflags="-s -X \"main.Version=$(VERSION)\"" -tags "$(GOTAGS)" $(GOFLAGS) -o $(BINARY) $(PACKAGE) | |
.PHONY: run | |
run: | |
go run -tags "$(GOTAGS)" $(PACKAGE) | |
.PHONY: dlv | |
dlv: | |
dlv debug --build-flags "-tags \"$(GOTAGS)\"" $(PACKAGE) | |
.PHONY: air | |
air: | |
air -c .air.toml | |
.PHONY: | |
generate: | |
go generate ./... | |
.PHONY: tidy | |
tidy: | |
go mod tidy | |
.PHONY: test | |
test: | |
go test -tags "$(GOTAGS)" -v -coverprofile=coverage.out ./... | |
.PHONY: coverage | |
coverage: test | |
go tool cover -html=coverage.out -o coverage.html | |
.PHONY: vet | |
vet: | |
go vet ./... | |
.PHONY: lint | |
lint: | |
golangci-lint run | |
.PHONY: fmt | |
fmt: | |
go fmt ./... | |
.PHONY: clean | |
clean: | |
go clean -i -cache -testcache -modcache | |
.PHONY: bootstrap | |
bootstrap: | |
find $(SUBDIRS) -type d -exec sh -c "echo \"%:\n\t\\\$$(MAKE) -C .. \\\$$@\n\" >{}/Makefile" \; | |
.PHONY: dist | |
dist: | |
touch $(BINARY).tar.gz && tar -czf $(BINARY).tar.gz --exclude=$(BINARY).tar.gz . | |
.PHONY: install | |
install: | |
install -t $(DESTDIR) $(BINARY) |
This file contains hidden or 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
BINARY ?= tmp | |
VERSION := 0.0.1 | |
PACKAGE := github.com/Lajule/tmp | |
include go.mk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment