-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
83 lines (65 loc) · 1.72 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
SHELL := /usr/bin/env bash
NAME := spu-exporter
IMPORT := github.com/EMnify/$(NAME)
BIN := bin
DIST := dist
GO := go
EXECUTABLE := $(NAME)
PACKAGES ?= $(shell go list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f)
GENERATE ?= $(PACKAGES)
ifndef DATE
DATE := $(shell date -u '+%Y%m%d')
endif
ifndef VERSION
VERSION ?= $(shell git rev-parse --short HEAD)
endif
ifndef REVISION
REVISION ?= $(shell git rev-parse --short HEAD)
endif
LDFLAGS += -s -w
LDFLAGS += -X "main.Version=$(VERSION)"
LDFLAGS += -X "main.BuildDate=$(DATE)"
LDFLAGS += -X "main.Revision=$(REVISION)"
.PHONY: all
all: build
.PHONY: clean
clean:
$(GO) clean -i ./...
rm -rf $(BIN)/
rm -rf $(DIST)/
.PHONY: sync
sync:
$(GO) mod download
.PHONY: fmt
fmt:
$(GO) fmt $(PACKAGES)
.PHONY: vet
vet:
$(GO) vet $(PACKAGES)
.PHONY: lint
lint:
@which golangci-lint > /dev/null; if [ $$? -ne 0 ]; then \
(echo "please install golangci-lint"; exit 1) \
fi
golangci-lint run -v
.PHONY: test
test:
GOBIN="$(PWD)" $(GO) install github.com/haya14busa/goverage@latest
./goverage -v -coverprofile coverage.out $(PACKAGES)
.PHONY: build
build: $(BIN)/$(EXECUTABLE)
$(BIN)/$(EXECUTABLE): $(SOURCES)
$(GO) build -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ .
.PHONY: release
release: release-dirs release-build release-checksums
.PHONY: release-dirs
release-dirs:
mkdir -p $(DIST)
.PHONY: release-build
release-build:
GOBIN="$(PWD)" $(GO) install github.com/mitchellh/gox@latest
./gox -os="linux darwin" -arch="amd64" -verbose -ldflags '-w $(LDFLAGS)' -output="$(DIST)/$(EXECUTABLE)-{{.OS}}-{{.Arch}}" .
.PHONY: release-checksums
release-checksums:
cd $(DIST); $(foreach file, $(wildcard $(DIST)/$(EXECUTABLE)-*), sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)