-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathMakefile
63 lines (50 loc) · 1.78 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
GO ?= go
GOOS ?= $(shell ${GO} env GOOS)
GOARCH ?= $(shell ${GO} env GOARCH)
VERSION ?= $(shell git describe --tags --abbrev=0 | sed -e 's/^v//')
STATICCHECK ?= $(shell $(GO) env GOPATH)/bin/staticcheck
REVIVE ?= $(shell $(GO) env GOPATH)/bin/revive
GOFUMPT ?= $(shell $(GO) env GOPATH)/bin/gofumpt
DOCKER ?= docker
BINARY = fastly-exporter
BINPKG = ./cmd/fastly-exporter
SOURCE = $(shell find . -name *.go)
DIST_DIR = dist/v${VERSION}
DIST_BIN_FILE = ${BINARY}-${VERSION}.${GOOS}-${GOARCH}
DIST_ZIP_FILE = ${DIST_BIN_FILE}.tar.gz
DIST_BIN = ${DIST_DIR}/${DIST_BIN_FILE}
DIST_ZIP = ${DIST_DIR}/${DIST_ZIP_FILE}
DOCKER_TAG = fastly-exporter:${VERSION}
DOCKER_ZIP = ${DIST_DIR}/${BINARY}-${VERSION}.docker.tar.gz
${BINARY}: ${SOURCE} Makefile
env CGO_ENABLED=0 ${GO} build -o ${BINARY} -ldflags="-X main.programVersion=${VERSION}" ${BINPKG}
${DIST_BIN}: ${DIST_DIR} ${SOURCE} Makefile
env CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} ${GO} build -o $@ -ldflags="-X main.programVersion=${VERSION}" ${BINPKG}
${DIST_DIR}:
mkdir -p $@
${DIST_ZIP}: ${DIST_BIN}
tar -C ${DIST_DIR} -c -z -f ${DIST_ZIP} ${DIST_BIN_FILE}
${DOCKER_ZIP}: ${SOURCE} Dockerfile
${DOCKER} build --tag=${DOCKER_TAG} .
${DOCKER} save --output=$@ ${DOCKER_TAG}
${STATICCHECK}:
${GO} install honnef.co/go/tools/cmd/staticcheck@latest
${REVIVE}:
${GO} install github.com/mgechev/revive@latest
${GOFUMPT}:
${GO} install mvdan.cc/gofumpt@latest
.PHONY: lint
lint: ${STATICCHECK} ${REVIVE} ${GOFUMPT} ${SOURCE}
${GO} vet ./...
${STATICCHECK} ./...
${REVIVE} ./...
${GOFUMPT} -l -d -e .
.PHONY: test
test: ${SOURCE}
${GO} test -race ./...
.PHONY: dist
dist: ${DIST_ZIP}
.PHONY: docker
docker: ${DOCKER_ZIP}
.PHONY: release
release: dist docker