-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
97 lines (77 loc) · 2.08 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
SHELL := bash
NAME := openvpn_exporter
IMPORT := github.com/patrickjahns/$(NAME)
BIN := bin
DIST := dist
GO := go
CGO_ENABLED := 0
ifeq ($(OS), Windows_NT)
EXECUTABLE := $(NAME).exe
else
EXECUTABLE := $(NAME)
endif
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 "$(IMPORT)/pkg/version.Version=$(VERSION)"
LDFLAGS += -X "$(IMPORT)/pkg/version.BuildDate=$(DATE)"
LDFLAGS += -X "$(IMPORT)/pkg/version.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: generate
generate:
$(GO) generate $(GENERATE)
.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:
@which goverage > /dev/null; if [ $$? -ne 0 ]; then \
GO111MODULE=off $(GO) get -u github.com/haya14busa/goverage; \
fi
goverage -v -coverprofile coverage.out $(PACKAGES)
.PHONY: build
build: $(BIN)/$(EXECUTABLE)
$(BIN)/$(EXECUTABLE): $(SOURCES)
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release
release: release-dirs release-build release-checksums
.PHONY: release-dirs
release-dirs:
mkdir -p $(DIST)
.PHONY: release-build
release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
GO111MODULE=off $(GO) get -u github.com/mitchellh/gox; \
fi
gox -arch="386 amd64 arm" -osarch '!darwin/386' -verbose -ldflags '-w $(LDFLAGS)' -output="$(DIST)/$(EXECUTABLE)-{{.OS}}-{{.Arch}}" ./cmd/$(NAME)
.PHONY: release-checksums
release-checksums:
cd $(DIST); $(foreach file, $(wildcard $(DIST)/$(EXECUTABLE)-*), sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)