-
Notifications
You must be signed in to change notification settings - Fork 55
/
Makefile
103 lines (84 loc) · 2.63 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
98
99
100
101
102
103
GO ?= go
EPOCH_TEST_COMMIT ?= b0fc980
PROJECT := github.com/cri-o/ocicni
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
OCICNI_IMAGE := ocicni_dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
OCICNI_INSTANCE := ocicni_dev
PREFIX ?= ${DESTDIR}/usr/local
BINDIR ?= ${PREFIX}/bin
LIBEXECDIR ?= ${PREFIX}/libexec
MANDIR ?= ${PREFIX}/share/man
ETCDIR ?= ${DESTDIR}/etc
GIT_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_INFO := $(shell date +%s)
BUILD_PATH := $(shell pwd)/build
GOLANGCI_LINT := ${BUILD_PATH}/golangci-lint
GOLANGCI_LINT_VERSION := v1.61.0
# If GOPATH not specified, use one in the local directory
ifeq ($(GOPATH),)
export GOPATH := $(CURDIR)/_output
unexport GOBIN
endif
GOPKGDIR := $(GOPATH)/src/$(PROJECT)
GOPKGBASEDIR := $(shell dirname "$(GOPKGDIR)")
# Update VPATH so make finds .gopathok
VPATH := $(VPATH):$(GOPATH)
LDFLAGS := -ldflags '-X main.gitCommit=${GIT_COMMIT} -X main.buildInfo=${BUILD_INFO}'
all: binaries
.gopathok:
ifeq ("$(wildcard $(GOPKGDIR))","")
mkdir -p "$(GOPKGBASEDIR)"
ln -s "$(CURDIR)" "$(GOPKGBASEDIR)"
endif
touch "$(GOPATH)/.gopathok"
gofmt:
@./hack/verify-gofmt.sh
binaries: ocicnitool
ocicnitool: .gopathok $(shell hack/find-godeps.sh $(GOPKGDIR) tools/ocicnitool $(PROJECT))
$(GO) build $(LDFLAGS) -tags "$(BUILDTAGS)" -o $@ $(PROJECT)/tools/ocicnitool
check: .gopathok
@./hack/test-go.sh $(GOPKGDIR)
@./hack/verify-gofmt.sh
hack/tree_status.sh
clean:
ifneq ($(GOPATH),)
rm -f "$(GOPATH)/.gopathok"
endif
rm -rf _output
# When this is running in travis, it will only check the travis commit range
.gitvalidation: .gopathok
ifeq ($(TRAVIS),true)
GIT_CHECK_EXCLUDE="./vendor ./_output" $(GOPATH)/bin/git-validation -q -run DCO,short-subject,dangling-whitespace
else
GIT_CHECK_EXCLUDE="./vendor ./_output" $(GOPATH)/bin/git-validation -v -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..HEAD
endif
install.tools: .install.gitvalidation
.install.gitvalidation: .gopathok
if [ ! -x "$(GOPATH)/bin/git-validation" ]; then \
go get -u github.com/vbatts/git-validation; \
fi
vendor:
$(GO) mod tidy && \
$(GO) mod vendor && \
$(GO) mod verify
$(GOLANGCI_LINT):
export VERSION=$(GOLANGCI_LINT_VERSION) \
URL=https://raw.githubusercontent.com/golangci/golangci-lint \
BINDIR=${BUILD_PATH} && \
curl -sSfL $$URL/$$VERSION/install.sh | sh -s $$VERSION
lint: ${GOLANGCI_LINT}
${GOLANGCI_LINT} version
${GOLANGCI_LINT} linters
GL_DEBUG=gocritic ${GOLANGCI_LINT} run
.PHONY: \
binaries \
clean \
default \
gofmt \
help \
check \
install.tools \
.gitvalidation \
vendor \
lint