forked from mendersoftware/mender-artifact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
101 lines (81 loc) · 2.34 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
GO ?= go
GOFMT ?= gofmt
V ?=
PKGS = $(shell go list ./... | grep -v vendor)
BUILDFILES = $(shell find cli/mender-artifact \( -path ./vendor -o -path ./Godeps \) -prune \
-o -type f -name '*.go' -print | tr ' ' '\n' | grep -v _test.go)
PKGNAME = mender-artifact
PKGFILES = $(shell find . \( -path ./vendor -o -path ./Godeps \) -prune \
-o -type f -name '*.go' -print)
PKGFILES_notest = $(shell echo $(PKGFILES) | tr ' ' '\n' | grep -v _test.go)
GOCYCLO ?= 15
CGO_ENABLED=1
export CGO_ENABLED
INSTALL_DIR=cli/mender-artifact
TOOLS = \
github.com/fzipp/gocyclo \
github.com/opennota/check/cmd/varcheck \
github.com/mendersoftware/deadcode
VERSION = $(shell git describe --tags --dirty --exact-match 2>/dev/null || git rev-parse --short HEAD)
GO_LDFLAGS = \
-ldflags "-X main.Version=$(VERSION)"
ifeq ($(V),1)
BUILDV = -v
endif
TAGS =
ifeq ($(LOCAL),1)
TAGS += local
endif
ifneq ($(TAGS),)
BUILDTAGS = -tags '$(TAGS)'
endif
build:
$(GO) build $(GO_LDFLAGS) $(BUILDV) $(BUILDTAGS) -o $(PKGNAME) $(BUILDFILES)
install:
cd $(INSTALL_DIR) && $(GO) install $(GO_LDFLAGS) $(BUILDV) $(BUILDTAGS)
clean:
$(GO) clean
rm -f coverage.txt coverage-tmp.txt
get-tools:
set -e ; for t in $(TOOLS); do \
echo "-- go getting $$t"; \
go get -u $$t; \
done
check: test extracheck
tooldep:
echo "check if mtools is installed on the system"
mtools --version
test: tooldep
$(GO) test -v $(PKGS)
extracheck:
echo "-- checking if code is gofmt'ed"
if [ -n "$$($(GOFMT) -d $(PKGFILES))" ]; then \
echo "-- gofmt check failed"; \
echo $GOFMT -d $PKGFILES \
/bin/false; \
fi
echo "-- checking with govet"
$(GO) tool vet -unsafeptr=false $(PKGFILES_notest)
echo "-- checking for dead code"
deadcode
echo "-- checking with varcheck"
varcheck .
echo "-- checking cyclometric complexity > $(GOCYCLO)"
gocyclo -over $(GOCYCLO) $(PKGFILES_notest)
cover: coverage
$(GO) tool cover -func=coverage.txt
htmlcover: coverage
$(GO) tool cover -html=coverage.txt
coverage:
rm -f coverage.txt
echo 'mode: set' > coverage.txt
set -e ; for p in $(PKGS); do \
rm -f coverage-tmp.txt; \
$(GO) test -coverprofile=coverage-tmp.txt $$p ; \
if [ -f coverage-tmp.txt ]; then \
cat coverage-tmp.txt |grep -v 'mode:' | cat >> coverage.txt; \
fi; \
done
rm -f coverage-tmp.txt
.PHONY: build clean get-tools test check \
cover htmlcover coverage tooldep