-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
117 lines (95 loc) · 4.08 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
# PREFIX is the prefix on the targetsystem
# DESTDIR can be used to prefix ALL paths, e.g., to do a dummy-install in a
# fake root dir, e.g., for building packages. Users mainly want PREFIX
PREFIX=/usr/local
DOCDIR=${PREFIX}/share/doc/svipul
GIT_DESCRIBE:=$(shell git describe --always --tag --dirty)
VERSION_NO=$(shell echo ${GIT_DESCRIBE} | sed s/[v-]//g)
OS:=$(shell uname -s | tr A-Z a-z)
ARCH:=$(shell uname -m)
binaries: svipul-snmp svipul-addjob
man: svipul-snmp.1 svipul-addjob.1
all: binaries man
svipul-snmp: $(wildcard *.go */*.go */*/*.go go.mod)
@echo 🤸 go build !
@go build -ldflags "-X main.versionNo=${VERSION_NO}" -o svipul-snmp ./cmd/svipul-snmp
svipul-addjob: $(wildcard *.go */*.go */*/*.go go.mod)
@echo 🤸 go build addjobb !
@go build -ldflags "-X main.versionNo=${VERSION_NO}" -o svipul-addjob ./cmd/svipul-addjob
%.1: docs/man/%.rst
@echo 🎢 Generating man-file $@
@rst2man < $< > $@
notes: docs/NEWS
@echo ⛲ Extracting release notes.
@./build/release-notes.sh $$(echo ${GIT_DESCRIBE} | sed s/-dirty//) > notes
install: svipul-snmp svipul-addjob
@echo 🙅 Installing
@install -D -m 0755 svipul-snmp ${DESTDIR}${PREFIX}/bin/svipul-snmp
@install -D -m 0755 svipul-addjob ${DESTDIR}${PREFIX}/bin/svipul-addjob
@install -D -m 0644 svipul-snmp.1 ${DESTDIR}${PREFIX}/share/man/man1/svipul-snmp.1
@install -D -m 0644 svipul-addjob.1 ${DESTDIR}${PREFIX}/share/man/man1/svipul-addjob.1
@install -D -m 0644 docs/examples/output/default.json ${DESTDIR}/etc/svipul/output.d/default.json
@install -D -m 0644 docs/examples/snmp.toml ${DESTDIR}/etc/svipul/snmp.toml
@cd docs; \
find . -type f -exec install -D -m 0644 {} ${DESTDIR}${DOCDIR}/{} \;
@install -D -m 0644 README.rst LICENSE -t ${DESTDIR}${DOCDIR}/
build/redhat-svipul.spec: build/redhat-svipul.spec.in FORCE
@echo ❕Building spec-file
@cat $< | sed "s/xxVxx/${GIT_DESCRIBE}/g; s/xxARCHxx/${ARCH}/g; s/xxVERSION_NOxx/${VERSION_NO}/g" > $@
@if [ ! -f /etc/redhat-release ]; then echo 🆒 Adding debian-workaround for rpm build; sed -i 's/^BuildReq/\#Debian hack, auto-commented out: BuildReq/g' $@; fi
rpm: build/redhat-svipul.spec
@echo 🎇 Triggering huge-as-heck rpm build
@mkdir -p rpm-prep/BUILDROOT
@DEFAULT_UNIT_DIR=/usr/lib/systemd/system ;\
RPM_UNIT_DIR=$$(rpm --eval $%{_unitdir}) ;\
if [ "$${RPM_UNIT_DIR}" = "$%{_unitdir}" ]; then \
echo "😭 _unitdir not set, setting _unitdir to $$DEFAULT_UNIT_DIR"; \
rpmbuild --quiet --bb \
--nodebuginfo \
--build-in-place \
--define "_rpmdir $$(pwd)" \
--define "_topdir $$(pwd)" \
--define "_unitdir $$DEFAULT_UNIT_DIR" \
--buildroot "$$(pwd)/rpm-prep/BUILDROOT" \
build/redhat-svipul.spec; \
else \
rpmbuild --quiet --bb \
--nodebuginfo \
--build-in-place \
--define "_rpmdir $$(pwd)" \
--define "_topdir $$(pwd)" \
--buildroot "$$(pwd)/rpm-prep/BUILDROOT" \
build/redhat-svipul.spec; \
fi
@cp x86_64/svipul-${VERSION_NO}-1.x86_64.rpm .
@echo ⭐ RPM built: ./svipul-${VERSION_NO}-1.x86_64.rpm
clean:
@echo 💩Cleaning up
@rm -f svipul-snmp svipul-addjob
@rm -f svipul-snmp.1 svipul-addjob.1
check: test fmtcheck vet
mibs:
@echo ✊ Grabbing mibs
@tools/get_mibs.sh
vet:
@echo 🔬 Vetting code
@go vet ./...
fmtcheck:
@echo 🦉 Checking format with gofmt -d -s
@if [ "x$$(find . -name '*.go' -not -wholename './gen/*' -and -not -wholename './vendor/*' -exec gofmt -d -s {} +)" != "x" ]; then find . -name '*.go' -not -wholename './gen/*' -and -not -wholename './vendor/*' -exec gofmt -d -s {} +; exit 1; fi
fmtfix:
@echo 🎨 Fixing formating
@find . -name '*.go' -not -wholename './gen/*' -and -not -wholename './vendor/*' -exec gofmt -d -s -w {} +
test:
@echo 🧐 Testing, without SQL-tests
@go test -short ./...
bench:
@echo 🏋 Benchmarking
@go test -run ^Bench -benchtime 1s -bench Bench ./... | grep Benchmark
covergui:
@echo 🧠 Testing, with coverage analysis
@go test -short -coverpkg ./... -covermode=atomic -coverprofile=coverage.out ./...
@echo 💡 Generating HTML coverage report and opening browser
@go tool cover -html coverage.out
FORCE:
.PHONY: clean test bench help install rpm release