forked from mendersoftware/mender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
205 lines (164 loc) · 5.92 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
DESTDIR ?= /
prefix ?= $(DESTDIR)
bindir=/usr/bin
datadir ?= /usr/share
sysconfdir ?= /etc
systemd_unitdir ?= /lib/systemd
GO ?= go
GOFMT ?= gofmt
V ?=
PKGS = $(shell go list ./... | grep -v vendor)
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
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
IDENTITY_SCRIPTS = \
support/mender-device-identity
INVENTORY_SCRIPTS = \
support/mender-inventory-bootloader-integration \
support/mender-inventory-hostinfo \
support/mender-inventory-network \
support/mender-inventory-os \
support/mender-inventory-rootfs-type
MODULES = \
support/modules/deb \
support/modules/docker \
support/modules/directory \
support/modules/single-file \
support/modules/rpm \
support/modules/script
MODULES_ARTIFACT_GENERATORS = \
support/modules-artifact-gen/docker-artifact-gen \
support/modules-artifact-gen/directory-artifact-gen \
support/modules-artifact-gen/single-file-artifact-gen
build: mender
mender: $(PKGFILES)
$(GO) build $(GO_LDFLAGS) $(BUILDV) $(BUILDTAGS)
install: install-bin install-conf install-identity-scripts install-inventory-scripts install-modules install-systemd
install-bin: mender
install -m 755 -d $(prefix)$(bindir)
install -m 755 mender $(prefix)$(bindir)/
install-conf:
install -m 755 -d $(prefix)$(sysconfdir)/mender
install -m 644 mender.conf.production $(prefix)$(sysconfdir)/mender/mender.conf.production
install -m 644 mender.conf.production $(prefix)$(sysconfdir)/mender/mender.conf
install -m 644 mender.conf.demo $(prefix)$(sysconfdir)/mender/mender.conf.demo
echo "artifact_name=unknown" > $(prefix)$(sysconfdir)/mender/artifact_info
install-datadir:
install -m 755 -d $(prefix)$(datadir)/mender
install-identity-scripts: install-datadir
install -m 755 -d $(prefix)$(datadir)/mender/identity
install -m 755 $(IDENTITY_SCRIPTS) $(prefix)$(datadir)/mender/identity/
install-inventory-scripts: install-datadir
install -m 755 -d $(prefix)$(datadir)/mender/inventory
install -m 755 $(INVENTORY_SCRIPTS) $(prefix)$(datadir)/mender/inventory/
install-modules:
install -m 755 -d $(prefix)$(datadir)/mender/modules/v3
install -m 755 $(MODULES) $(prefix)$(datadir)/mender/modules/v3/
install-modules-gen:
install -m 755 -d $(prefix)$(bindir)
install -m 755 $(MODULES_ARTIFACT_GENERATORS) $(prefix)$(bindir)/
install-systemd:
install -m 755 -d $(prefix)$(systemd_unitdir)/system
install -m 0644 support/mender.service $(prefix)$(systemd_unitdir)/system/
install-demo: install
install -m 755 mender.conf.demo $(prefix)$(sysconfdir)/mender/mender.conf
uninstall: uninstall-bin uninstall-conf uninstall-identity-scripts uninstall-inventory-scripts \
uninstall-modules uninstall-modules-gen uninstall-systemd
uninstall-bin:
rm -f $(prefix)$(bindir)/mender
-rmdir -p $(prefix)$(bindir)
uninstall-conf:
rm -f $(prefix)$(sysconfdir)/mender/mender.conf
rm -f $(prefix)$(sysconfdir)/mender/mender.conf.production
rm -f $(prefix)$(sysconfdir)/mender/mender.conf.demo
rm -f $(prefix)$(sysconfdir)/mender/artifact_info
-rmdir -p $(prefix)$(sysconfdir)/mender
uninstall-identity-scripts:
for script in $(IDENTITY_SCRIPTS); do \
rm -f $(prefix)$(datadir)/mender/identity/$$(basename $$script); \
done
-rmdir -p $(prefix)$(datadir)/mender/identity
uninstall-inventory-scripts:
for script in $(INVENTORY_SCRIPTS); do \
rm -f $(prefix)$(datadir)/mender/inventory/$$(basename $$script); \
done
-rmdir -p $(prefix)$(datadir)/mender/inventory
uninstall-modules:
for script in $(MODULES); do \
rm -f $(prefix)$(datadir)/mender/modules/v3/$$(basename $$script); \
done
-rmdir -p $(prefix)$(datadir)/mender/modules/v3
uninstall-modules-gen:
for script in $(MODULES_ARTIFACT_GENERATORS); do \
rm -f $(prefix)$(bindir)/$$(basename $$script); \
done
-rmdir -p $(prefix)$(bindir)
uninstall-systemd:
rm -f $(prefix)$(systemd_unitdir)/system/mender.service
-rmdir -p $(prefix)$(systemd_unitdir)/system
clean:
$(GO) clean
rm -f coverage.txt
get-tools:
set -e ; for t in $(TOOLS); do \
echo "-- go getting $$t"; \
go get -u $$t; \
done
check: test extracheck
test:
$(GO) test $(BUILDV) $(PKGS)
extracheck:
echo "-- checking if code is gofmt'ed"
if [ -n "$$($(GOFMT) -d $(PKGFILES))" ]; then \
"$$($(GOFMT) -d $(PKGFILES))" \
echo "-- gofmt check failed"; \
/bin/false; \
fi
echo "-- checking with govet"
$(GO) tool vet -unsafeptr=false $(PKGFILES_notest)
echo "-- checking for dead code"
deadcode -ignore version.go:Version
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
$(GO) test -coverprofile=coverage-tmp.txt -coverpkg=github.com/mendersoftware/... ./...
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 clean get-tools test check \
cover htmlcover coverage \
install install-bin install-conf install-datadir install-demo install-identity-scripts \
install-inventory-scripts install-modules install-modules-gen install-systemd \
uninstall uninstall-bin uninstall-conf uninstall-identity-scripts \
uninstall-inventory-scripts uninstall-modules uninstall-modules-gen uninstall-systemd