-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
GNUmakefile
193 lines (162 loc) · 5.67 KB
/
GNUmakefile
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
PLUGIN=check_ssl_cert
VERSION=`cat VERSION`
DIST_DIR=$(PLUGIN)-$(VERSION)
# files to be included in the distribution
DIST_FILES=AUTHORS.md COPYING.md ChangeLog INSTALL.md Makefile GNUmakefile NEWS.md README.md VERSION $(PLUGIN) $(PLUGIN).spec COPYRIGHT.md ${PLUGIN}.1 CITATION.cff check_ssl_cert.completion check_ssl_cert_icinga2.conf
# this year
YEAR=`date +"%Y"`
# file to be checked for formatting
FORMATTED_FILES=test/unit_tests.sh test/integration_tests.sh test/badssl_tests.sh ChangeLog INSTALL.md Makefile VERSION $(PLUGIN) $(PLUGIN).spec COPYRIGHT.md ${PLUGIN}.1 .github/workflows/* utils/*.sh check_ssl_cert.completion
# shell scripts (to be checked with ShellCheck)
SCRIPTS=check_ssl_cert test/*.sh utils/*.sh
XATTRS_OPTION := $(shell if tar --help 2>&1 | grep -q bsdtar ; then echo '--no-xattrs' ; fi )
.PHONY: install clean test rpm distclean check version_check codespell integration_tests unit_tests integration_tests_with_proxy unit_tests_with_proxy
all: dist
# checks if the version is updated in all the files
version_check: CITATION.cff
@echo "Checking version $(VERSION)"
grep -q "VERSION *= *[\'\"]*$(VERSION)" $(PLUGIN)
grep -q "^%global version *$(VERSION)" $(PLUGIN).spec
grep -q -F -- "- $(VERSION)-" $(PLUGIN).spec
grep -q "\"$(VERSION)\"" $(PLUGIN).1
grep -q -F "${VERSION}" NEWS.md
grep -q "^version: ${VERSION}" CITATION.cff
@echo "Version check: OK"
# builds the release files
dist: version_check CITATION.cff
rm -rf $(DIST_DIR) $(DIST_DIR).tar.gz
mkdir $(DIST_DIR)
cp -r $(DIST_FILES) $(DIST_DIR)
# avoid to include extended attribute data files
# see https://superuser.com/questions/259703/get-mac-tar-to-stop-putting-filenames-in-tar-archives
export COPY_EXTENDED_ATTRIBUTES_DISABLE=true; \
export COPYFILE_DISABLE=true; \
tar $(XATTRS_OPTION) -c -z -f $(DIST_DIR).tar.gz $(DIST_DIR) && \
tar $(XATTRS_OPTION) -c -j -f $(DIST_DIR).tar.bz2 $(DIST_DIR)
install:
ifndef DESTDIR
@echo "Please define DESTDIR and MANDIR variables with the installation targets"
@echo "e.g, make DESTDIR=/nagios/plugins/dir MANDIR=/nagios/plugins/man/dir install"
@echo
@echo "If you are using 'sudo' please specify the '-E, --preserve-env' option"
else
mkdir -p $(DESTDIR)
install -m 755 $(PLUGIN) $(DESTDIR)
mkdir -p ${MANDIR}/man1
install -m 644 ${PLUGIN}.1 ${MANDIR}/man1/
endif
ifdef COMPLETIONDIR
mkdir -p $(COMPLETIONDIR)
install -m 644 check_ssl_cert.completion $(COMPLETIONDIR)/check_ssl_cert
endif
COMPLETIONS_DIR := $(shell pkg-config --variable=completionsdir bash-completion)
install_bash_completion:
ifdef COMPLETIONS_DIR
cp check_ssl_cert.completion $(COMPLETIONS_DIR)/check_ssl_cert
endif
CITATION.cff: AUTHORS.md VERSION NEWS.md
./utils/update_citation.sh
# we check for tabs
# and remove trailing blanks
formatting_check:
! grep -q '[[:blank:]]$$' $(FORMATTED_FILES)
CODESPELL := $(shell command -v codespell 2> /dev/null )
# spell check
codespell:
ifndef CODESPELL
@echo "no codespell installed"
else
codespell \
.
endif
SHFMT := $(shell command -v shfmt 2> /dev/null)
format:
ifndef SHFMT
@echo "No shfmt installed"
else
# -p POSIX
# -w write to file
# -s simplify
# -i 4 indent with 4 spaces
shfmt -p -w -s -i 4 $(SCRIPTS)
shfmt -ln bash -w -s -i 4 check_ssl_cert.completion
endif
clean:
find . -name "*~" -delete
find . -name "*.bak" -delete
find . -name "#*#" -delete
rm -rf rpmroot
distclean: clean
rm -rf check_ssl_cert-[0-9]*
rm -f *.crt
rm -f *.error
rm -f headers.txt
check: test
SHELLCHECK := $(shell command -v shellcheck 2> /dev/null)
SHUNIT := $(shell if [ -z "${SHUNIT2}" ] ; then command -v shunit2 2> /dev/null || if [ -x /usr/share/shunit2/shunit2 ] ; then echo /usr/share/shunit2/shunit2 ; fi; else echo "${SHUNIT2}"; fi )
distcheck: disttest
disttest: dist formatting_check shellcheck codespell
./utils/check_documentation.sh
man ./check_ssl_cert.1 > /dev/null
test: formatting_check shellcheck unit_tests integration_tests badssl_tests badssl_tests_with_proxy unit_tests_with_proxy integration_tests_with_proxy
unit_tests:
ifndef SHUNIT
@echo "No shUnit2 installed: see README.md"
exit 1
else
( export SHUNIT2=$(SHUNIT) && export LC_ALL=C && cd test && ./unit_tests.sh )
endif
unit_tests_with_proxy:
ifndef SHUNIT
@echo "No shUnit2 installed: see README.md"
exit 1
else
./utils/start_proxy.sh ./test/tinyproxy.conf
( export SHUNIT2=$(SHUNIT) && export http_proxy=127.0.0.1:8888 && export LC_ALL=C && cd test && ./unit_tests.sh )
killall tinyproxy
sleep 1
endif
integration_tests:
ifndef SHUNIT
@echo "No shUnit2 installed: see README.md"
exit 1
else
( export SHUNIT2=$(SHUNIT) && export LC_ALL=C && cd test && ./integration_tests.sh )
endif
integration_tests_with_proxy:
ifndef SHUNIT
@echo "No shUnit2 installed: see README.md"
exit 1
else
./utils/start_proxy.sh ./test/tinyproxy.conf
( export SHUNIT2=$(SHUNIT) && export http_proxy=127.0.0.1:8888 && export LC_ALL=C && cd test && ./integration_tests.sh )
killall tinyproxy
sleep 1
endif
badssl_tests:
ifndef SHUNIT
@echo "No shUnit2 installed: see README.md"
exit 1
else
( export SHUNIT2=$(SHUNIT) && export LC_ALL=C && cd test && ./badssl_tests.sh )
endif
badssl_tests_with_proxy:
ifndef SHUNIT
@echo "No shUnit2 installed: see README.md"
exit 1
else
./utils/start_proxy.sh ./test/tinyproxy.conf
( export SHUNIT2=$(SHUNIT) && export http_proxy=127.0.0.1:8888 && export LC_ALL=C && cd test && ./badssl_tests.sh )
killall tinyproxy
sleep 1
endif
shellcheck:
ifndef SHELLCHECK
@echo "No shellcheck installed: skipping check"
else
if shellcheck --help 2>&1 | grep -q -- '-o ' ; then shellcheck -o all $(SCRIPTS) ; else shellcheck $(SCRIPTS) ; fi
endif
rpm: dist
mkdir -p rpmroot/SOURCES rpmroot/BUILD
cp $(DIST_DIR).tar.gz rpmroot/SOURCES
rpmbuild --define "_topdir `pwd`/rpmroot" -ba check_ssl_cert.spec