-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
40 lines (30 loc) · 1.41 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
GO_BINARY ?= $(shell which go)
BINARY_NAME ?= $(shell basename $(CURDIR))
TAG_COMMIT := $(shell git rev-list --abbrev-commit --all --max-count=1)
VERSION := $(shell git describe --abbrev=0 --tags --exact-match $(TAG_COMMIT) 2>/dev/null || true)
DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d%H%M")
ifeq ($(VERSION),)
VERSION := nightly-$(DATE)
endif
LDFLAGS := "-X github.com/mdeous/dnscheck/cmd.version=$(VERSION)"
GO_FLAGS := -ldflags $(LDFLAGS)
.PHONY: all clean rebuild deps update-deps cross-compile help
$(BINARY_NAME):
$(GO_BINARY) build $(GO_FLAGS) -o $(BINARY_NAME) .
all: $(BINARY_NAME) ## Default build action
clean: ## Clean artifacts from previous build
@rm -f $(BINARY_NAME)
@rm -rf ./build
rebuild: clean all ## Delete existing artifacts and rebuild
deps: ## Fetch project dependencies
$(GO_BINARY) get .
update-deps: ## Update project dependencies
$(GO_BINARY) get -u .
$(GO_BINARY) mod tidy -v
cross-compile: ## Build for all supported platforms
gox -os="windows linux" -arch="386" -output="build/{{.Dir}}-$(VERSION)_{{.OS}}_{{.Arch}}" -ldflags=$(LDFLAGS)
gox -os="windows linux darwin" -arch="amd64" -output="build/{{.Dir}}-$(VERSION)_{{.OS}}_{{.Arch}}" -ldflags=$(LDFLAGS)
version: ## Display program version
@echo $(VERSION)
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'