| 1 |
DESTDIR ?= / |
| 2 |
prefix ?= $(DESTDIR) |
| 3 |
bindir=/usr/bin |
| 4 |
datadir ?= /usr/share |
| 5 |
sysconfdir ?= /etc |
| 6 |
systemd_unitdir ?= /lib/systemd |
| 7 |
|
| 8 |
GO ?= go |
| 9 |
GOFMT ?= gofmt |
| 10 |
GOCYCLO ?= gocyclo |
| 11 |
V ?= |
| 12 |
PKGS = $(shell go list ./...) |
| 13 |
PKGFILES = $(shell find . \( -path ./vendor \) -prune \ |
| 14 |
-o -type f -name '*.go' -print) |
| 15 |
PKGFILES_notest = $(shell echo $(PKGFILES) | tr ' ' '\n' | grep -v '_test.go' ) |
| 16 |
GOCYCLO_LIMIT ?= 15 |
| 17 |
|
| 18 |
TOOLS = \ |
| 19 |
github.com/fzipp/gocyclo \ |
| 20 |
gitlab.com/opennota/check/cmd/varcheck \ |
| 21 |
github.com/mendersoftware/deadcode \ |
| 22 |
github.com/mendersoftware/gobinarycoverage |
| 23 |
|
| 24 |
VERSION = $(shell git describe --tags --dirty --exact-match 2>/dev/null || git rev-parse --short HEAD) |
| 25 |
|
| 26 |
GO_LDFLAGS = \ |
| 27 |
-ldflags "-X github.com/mendersoftware/mender-connect/config.Version=$(VERSION)" |
| 28 |
|
| 29 |
ifeq ($(V),1) |
| 30 |
BUILDV = -v |
| 31 |
endif |
| 32 |
|
| 33 |
TAGS = |
| 34 |
ifeq ($(LOCAL),1) |
| 35 |
TAGS += local |
| 36 |
endif |
| 37 |
|
| 38 |
ifneq ($(TAGS),) |
| 39 |
BUILDTAGS = -tags '$(TAGS)' |
| 40 |
endif |
| 41 |
|
| 42 |
build: mender-connect |
| 43 |
|
| 44 |
clean: |
| 45 |
@$(GO) clean |
| 46 |
@-rm -f coverage.txt |
| 47 |
|
| 48 |
mender-connect: $(PKGFILES) |
| 49 |
@$(GO) build $(GO_LDFLAGS) $(BUILDV) $(BUILDTAGS) |
| 50 |
|
| 51 |
install: install-bin install-systemd |
| 52 |
|
| 53 |
install-bin: mender-connect |
| 54 |
@install -m 755 -d $(prefix)$(bindir) |
| 55 |
@install -m 755 mender-connect $(prefix)$(bindir)/ |
| 56 |
|
| 57 |
install-conf: |
| 58 |
@install -m 755 -d $(prefix)$(sysconfdir)/mender |
| 59 |
@install -m 600 examples/mender-connect.conf $(prefix)$(sysconfdir)/mender/ |
| 60 |
|
| 61 |
install-systemd: |
| 62 |
@install -m 755 -d $(prefix)$(systemd_unitdir)/system |
| 63 |
@install -m 0644 support/mender-connect.service $(prefix)$(systemd_unitdir)/system/ |
| 64 |
|
| 65 |
uninstall: uninstall-bin uninstall-systemd |
| 66 |
|
| 67 |
uninstall-bin: |
| 68 |
@rm -f $(prefix)$(bindir)/mender-connect |
| 69 |
@-rmdir -p $(prefix)$(bindir) |
| 70 |
|
| 71 |
uninstall-systemd: |
| 72 |
@rm -f $(prefix)$(systemd_unitdir)/system/mender-connect.service |
| 73 |
@-rmdir -p $(prefix)$(systemd_unitdir)/system |
| 74 |
|
| 75 |
check: test extracheck |
| 76 |
|
| 77 |
test: |
| 78 |
@$(GO) test $(BUILDV) $(PKGS) |
| 79 |
|
| 80 |
extracheck: gofmt govet godeadcode govarcheck gocyclo |
| 81 |
@echo "All extra-checks passed!" |
| 82 |
|
| 83 |
gofmt: |
| 84 |
@echo "-- checking if code is gofmt'ed" |
| 85 |
@if [ -n "$$($(GOFMT) -d $(PKGFILES))" ]; then \ |
| 86 |
"$$($(GOFMT) -d $(PKGFILES))" \ |
| 87 |
echo "-- gofmt check failed"; \ |
| 88 |
/bin/false; \ |
| 89 |
fi |
| 90 |
|
| 91 |
govet: |
| 92 |
@echo "-- checking with govet" |
| 93 |
@$(GO) vet -unsafeptr=false |
| 94 |
|
| 95 |
godeadcode: |
| 96 |
@echo "-- checking for dead code" |
| 97 |
@deadcode -ignore version.go:Version |
| 98 |
|
| 99 |
govarcheck: |
| 100 |
@echo "-- checking with varcheck" |
| 101 |
@varcheck ./... |
| 102 |
|
| 103 |
gocyclo: |
| 104 |
@echo "-- checking cyclometric complexity > $(GOCYCLO_LIMIT)" |
| 105 |
@$(GOCYCLO) -over $(GOCYCLO_LIMIT) $(PKGFILES_notest) |
| 106 |
|
| 107 |
cover: coverage |
| 108 |
@$(GO) tool cover -func=coverage.txt |
| 109 |
|
| 110 |
htmlcover: coverage |
| 111 |
@$(GO) tool cover -html=coverage.txt |
| 112 |
|
| 113 |
coverage: |
| 114 |
@rm -f coverage.txt |
| 115 |
@$(GO) test -coverprofile=coverage-tmp.txt -coverpkg=./... ./... |
| 116 |
@if [ -f coverage-missing-subtests.txt ]; then \ |
| 117 |
echo 'mode: set' > coverage.txt; \ |
| 118 |
cat coverage-tmp.txt coverage-missing-subtests.txt | grep -v 'mode: set' >> coverage.txt; \ |
| 119 |
else \ |
| 120 |
mv coverage-tmp.txt coverage.txt; \ |
| 121 |
fi |
| 122 |
@rm -f coverage-tmp.txt coverage-missing-subtests.txt |
| 123 |
|
| 124 |
.PHONY: build |
| 125 |
.PHONY: clean |
| 126 |
.PHONY: get-tools |
| 127 |
.PHONY: test |
| 128 |
.PHONY: check |
| 129 |
.PHONY: extracheck |
| 130 |
.PHONY: cover |
| 131 |
.PHONY: htmlcover |
| 132 |
.PHONY: coverage |
| 133 |
.PHONY: install |
| 134 |
.PHONY: install-bin |
| 135 |
.PHONY: install-systemd |
| 136 |
.PHONY: uninstall |
| 137 |
.PHONY: uninstall-bin |
| 138 |
.PHONY: uninstall-systemd |