File: Makefile

package info (click to toggle)
mender-connect 2.1.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 724 kB
  • sloc: makefile: 123; ansic: 66; sh: 21
file content (138 lines) | stat: -rw-r--r-- 3,247 bytes parent folder | download | duplicates (2)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
DESTDIR ?= /
prefix ?= $(DESTDIR)
bindir=/usr/bin
datadir ?= /usr/share
sysconfdir ?= /etc
systemd_unitdir ?= /lib/systemd

GO ?= go
GOFMT ?= gofmt
GOCYCLO ?= gocyclo
V ?=
PKGS = $(shell go list ./...)
PKGFILES = $(shell find . \( -path ./vendor \) -prune \
		-o -type f -name '*.go' -print)
PKGFILES_notest = $(shell echo $(PKGFILES) | tr ' ' '\n' | grep -v '_test.go' )
GOCYCLO_LIMIT ?= 15

TOOLS = \
	github.com/fzipp/gocyclo                     \
	gitlab.com/opennota/check/cmd/varcheck       \
	github.com/mendersoftware/deadcode           \
	github.com/mendersoftware/gobinarycoverage

VERSION = $(shell git describe --tags --dirty --exact-match 2>/dev/null || git rev-parse --short HEAD)

GO_LDFLAGS = \
	-ldflags "-X github.com/mendersoftware/mender-connect/config.Version=$(VERSION)"

ifeq ($(V),1)
BUILDV = -v
endif

TAGS =
ifeq ($(LOCAL),1)
TAGS += local
endif

ifneq ($(TAGS),)
BUILDTAGS = -tags '$(TAGS)'
endif

build: mender-connect

clean:
	@$(GO) clean
	@-rm -f coverage.txt

mender-connect: $(PKGFILES)
	@$(GO) build $(GO_LDFLAGS) $(BUILDV) $(BUILDTAGS)

install: install-bin install-systemd

install-bin: mender-connect
	@install -m 755 -d $(prefix)$(bindir)
	@install -m 755 mender-connect $(prefix)$(bindir)/

install-conf:
	@install -m 755 -d $(prefix)$(sysconfdir)/mender
	@install -m 600 examples/mender-connect.conf $(prefix)$(sysconfdir)/mender/

install-systemd:
	@install -m 755 -d $(prefix)$(systemd_unitdir)/system
	@install -m 0644 support/mender-connect.service $(prefix)$(systemd_unitdir)/system/

uninstall: uninstall-bin uninstall-systemd

uninstall-bin:
	@rm -f $(prefix)$(bindir)/mender-connect
	@-rmdir -p $(prefix)$(bindir)

uninstall-systemd:
	@rm -f $(prefix)$(systemd_unitdir)/system/mender-connect.service
	@-rmdir -p $(prefix)$(systemd_unitdir)/system

check: test extracheck

test:
	@$(GO) test $(BUILDV) $(PKGS)

extracheck: gofmt govet godeadcode govarcheck gocyclo
	@echo "All extra-checks passed!"

gofmt:
	@echo "-- checking if code is gofmt'ed"
	@if [ -n "$$($(GOFMT) -d $(PKGFILES))" ]; then \
		"$$($(GOFMT) -d $(PKGFILES))" \
		echo "-- gofmt check failed"; \
		/bin/false; \
	fi

govet:
	@echo "-- checking with govet"
	@$(GO) vet -unsafeptr=false

godeadcode:
	@echo "-- checking for dead code"
	@deadcode -ignore version.go:Version

govarcheck:
	@echo "-- checking with varcheck"
	@varcheck ./...

gocyclo:
	@echo "-- checking cyclometric complexity > $(GOCYCLO_LIMIT)"
	@$(GOCYCLO) -over $(GOCYCLO_LIMIT) $(PKGFILES_notest)

cover: coverage
	@$(GO) tool cover -func=coverage.txt

htmlcover: coverage
	@$(GO) tool cover -html=coverage.txt

coverage:
	@rm -f coverage.txt
	@$(GO) test -coverprofile=coverage-tmp.txt -coverpkg=./... ./...
	@if [ -f coverage-missing-subtests.txt ]; then \
		echo 'mode: set' > coverage.txt; \
		cat coverage-tmp.txt coverage-missing-subtests.txt | grep -v 'mode: set' >> coverage.txt; \
	else \
		mv coverage-tmp.txt coverage.txt; \
	fi
	@rm -f coverage-tmp.txt coverage-missing-subtests.txt

.PHONY: build
.PHONY: clean
.PHONY: get-tools
.PHONY: test
.PHONY: check
.PHONY: extracheck
.PHONY: cover
.PHONY: htmlcover
.PHONY: coverage
.PHONY: install
.PHONY: install-bin
.PHONY: install-systemd
.PHONY: uninstall
.PHONY: uninstall-bin
.PHONY: uninstall-systemd