-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c4aa62
commit e4a0210
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
-include .env | ||
|
||
VERSION := $(shell git describe --tags) | ||
BUILD := $(shell git rev-parse --short HEAD) | ||
PROJECTNAME := $(shell basename "$(PWD)") | ||
|
||
# Go related variables. | ||
GOBASE := $(shell pwd) | ||
GOPATH := $(GOBASE)/vendor:$(GOBASE) | ||
GOBIN := $(GOBASE)/out | ||
GOFILES := $(wildcard *.go) | ||
|
||
# Use linker flags to provide version/build settings | ||
LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD)" | ||
|
||
# Make is verbose in Linux. Make it silent. | ||
MAKEFLAGS += --silent | ||
|
||
## install: Install missing dependencies. Runs `go get` internally. e.g; make install get=github.com/foo/bar | ||
install: go-get | ||
|
||
## test: Run all tests | ||
test: | ||
@-$(MAKE) -s go-test | ||
|
||
## compile: Compile the binary. | ||
compile: | ||
@-$(MAKE) -s go-compile | ||
|
||
## exec: Run given command, wrapped with custom GOPATH. e.g; make exec run="go test ./..." | ||
exec: | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) $(run) | ||
|
||
## clean: Clean build files. Runs `go clean` internally. | ||
clean: | ||
@-rm $(GOBIN)/$(PROJECTNAME) 2> /dev/null | ||
@-$(MAKE) go-clean | ||
|
||
go-compile: go-get go-build | ||
|
||
go-build: | ||
@echo " > Building binary..." | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go build $(LDFLAGS) -o $(GOBIN)/$(PROJECTNAME) $(GOFILES) | ||
|
||
go-generate: | ||
@echo " > Generating dependency files..." | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go generate $(generate) | ||
|
||
go-get: | ||
@echo " > Checking if there is any missing dependencies..." | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get $(get) | ||
|
||
go-install: | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go mod tidy | ||
|
||
go-vendor: | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go mod vendor | ||
|
||
go-test: | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go test -v ./... | ||
|
||
richgo-test: | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) richgo test -v ./... | ||
|
||
go-clean: | ||
@echo " > Cleaning build cache" | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go clean | ||
|
||
.PHONY: help | ||
all: help | ||
help: Makefile | ||
@echo | ||
@echo " Choose a command run in "$(PROJECTNAME)":" | ||
@echo | ||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' | ||
@echo |