-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
49 lines (40 loc) · 1.52 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
GO?=go
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
BINARY_NAME=ovh-exporter
# TODO less bruteforce ?
BINARY_FILES=$(shell find ${PWD} -type f -name "*.go")
GOFMT_FILES?=$(shell find . -not -path "./vendor/*" -type f -name '*.go')
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
PKG=github.com/wiremind/ovh-exporter
# Control if static or dynamically linked (static by default)
export CGO_ENABLED:=0
GO_GCFLAGS?=
GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG)'
.PHONY: build
build: ${BINARY_NAME}
${BINARY_NAME}: ${BINARY_FILES}
${GO} build ${GO_GCFLAGS} ${GO_LDFLAGS} -o $@ cmd/${BINARY_NAME}/*.go
strip -x $@
## Lints all the go code in the application.
.PHONY: lint
lint: dependencies
gofmt -w $(GOFMT_FILES)
$(GOBIN)/goimports -w $(GOFMT_FILES)
$(GOBIN)/gofumpt -l -w $(GOFMT_FILES)
$(GOBIN)/gci write $(GOFMT_FILES) --skip-generated
$(GOBIN)/golangci-lint run
## Loads all the dependencies to vendor directory
.PHONY: dependencies
dependencies:
go install golang.org/x/tools/cmd/[email protected]
go install mvdan.cc/[email protected]
go install github.com/daixiang0/[email protected]
go install github.com/golangci/golangci-lint/cmd/[email protected]
go mod vendor
go mod tidy