-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
83 lines (67 loc) · 1.91 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
.POSIX:
.SUFFIXES:
PKGNAME=usysconf
MODULE=github.com/getsolus/usysconf
TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
VERSION := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
PREFIX?=/usr/local
BINDIR?=$(DESTDIR)$(PREFIX)/bin
SYSDIR?=$(DESTDIR)/etc/$(PKGNAME).d
USRDIR?=$(DESTDIR)$(PREFIX)/share/default/$(PKGNAME).d
STATEPATH?=$(DESTDIR)/var/cache/$(PKGNAME)/state
GO?=go
GOFLAGS?=
GOSRC!=find . -name '*.go'
GOSRC+=go.mod go.sum
usysconf: $(GOSRC)
$(GO) build $(GOFLAGS) \
-ldflags " \
-X $(MODULE)/cli.Version=$(VERSION) \
-X $(MODULE)/config.SysDir=$(SYSDIR) \
-X $(MODULE)/config.UsrDir=$(USRDIR) \
-X $(MODULE)/state.Path=$(STATEPATH)" \
-o $@
all: usysconf
# Exists in GNUMake but not in NetBSD make and others.
RM?=rm -f
clean:
$(GO) mod tidy
$(RM) $(DOCS) $(PKGNAME) *.tar.gz
$(RM) -r vendor
install: all
mkdir -m755 -p $(BINDIR) $(USRDIR) $(SYSDIR) $(LOGDIR)
install -m755 $(PKGNAME) $(BINDIR)/$(PKGNAME)
RMDIR_IF_EMPTY:=sh -c '\
if test -d $$0 && ! ls -1qA $$0 | grep -q . ; then \
rmdir $$0; \
fi'
uninstall:
$(RM) $(BINDIR)/$(PKGNAME)
$(RM) -r $(LOGDIR)
$(RM) -r $(SYSDIR)
$(RM) -r $(USRDIR)
$(RMDIR_IF_EMPTY) $(BINDIR)
check:
$(GO) get -u golang.org/x/lint/golint
$(GO) get -u github.com/securego/gosec/cmd/gosec
$(GO) get -u honnef.co/go/tools/cmd/staticcheck
$(GO) get -u gitlab.com/opennota/check/cmd/aligncheck
$(GO) fmt -x ./...
$(GO) vet ./...
golint -set_exit_status `go list ./... | grep -v vendor`
gosec -exclude=G204 ./...
staticcheck ./...
aligncheck ./...
$(GO) test -cover ./...
vendor: check clean
$(GO) mod vendor
package: vendor
tar --exclude='.git' \
--exclude='*.tar.gz' \
--exclude='examples' \
--exclude="tags" \
--exclude=".vscode" \
--exclude="*~" \
-zcvf $(PKGNAME)-v$(VERSION).tar.gz ../$(PKGNAME)
.DEFAULT_GOAL := all
.PHONY: all clean install uninstall check vendor package