forked from Checkmk/checkmk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
290 lines (241 loc) · 10.1 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
#
include defines.make
include artifacts.make
DIST_ARCHIVE := check-mk-$(EDITION)-$(OMD_VERSION).tar.gz
TAROPTS := --owner=root --group=root --exclude=.svn --exclude=*~ \
--exclude=.gitignore --exclude=*.swp --exclude=.f12 \
--exclude=__pycache__ --exclude=*.pyc
PIPENV := scripts/run-pipenv
OPENAPI_SPEC := web/htdocs/openapi/checkmk.yaml
LOCK_FD := 200
LOCK_PATH := .venv.lock
PY_PATH := .venv/bin/python
ifneq ("$(wildcard $(PY_PATH))","")
PY_VIRT_MAJ_MIN := $(shell "${PY_PATH}" -c "from sys import version_info as v; print(f'{v.major}.{v.minor}')")
else
PY_VIRT_MAJ_MIN := "unknown"
endif
# The CI environment variable should only be set by Jenkins
CI ?= false
.PHONY: announcement all build check-setup \
clean dist documentation \
format format-c test-format-c format-python format-shell \
help install mrproper mrclean \
packages setup setversion version openapi \
Pipfile.lock protobuf-files frontend-vue .venv
help:
@echo "setup --> Prepare system for development and building"
@echo "make dist --> Create source tgz for later building of rpm/deb and livestatus tgz"
@echo "make rpm --> Create rpm package"
@echo "make deb --> Create deb package"
@echo "make cma --> Create cma package"
@echo "make version --> Switch to new version"
rpm:
$(MAKE) -C omd rpm
deb:
$(MAKE) -C omd deb
cma:
$(MAKE) -C omd cma
check-setup:
echo "From here on we check the successful setup of some parts ..."
@if [[ ":$(PATH):" != *":$(HOME)/.local/bin:"* ]]; then \
echo "Your PATH is missing '~/.local/bin' to work properly with pipenv."; \
exit 1; \
else \
echo "Checks passed"; \
fi
$(SOURCE_BUILT_LINUX_AGENTS):
$(MAKE) -C agents $@
ifeq ($(ENTERPRISE),yes)
$(SOURCE_BUILT_AGENT_UPDATER):
@echo "ERROR: Should have already been built by artifact providing jobs"
@echo "If you don't need the artifacts, you can use "
@echo "'scripts/fake-windows-artifacts' to continue with stub files"
@exit 1
endif
$(SOURCE_BUILT_OHM) $(SOURCE_BUILT_WINDOWS):
@echo "ERROR: Should have already been built by Windows node jobs"
@echo "If you don't need the windows artifacts, you can use "
@echo "'scripts/fake-windows-artifacts' to continue with stub files"
@exit 1
# Is executed by our build environment from a "git archive" snapshot and during
# RPM building to create the source tar.gz for the RPM build process.
# Would use --exclude-vcs-ignores but that's available from tar 1.29 which
# is currently not used by most distros
# Would also use --exclude-vcs, but this is also not available
# And --transform is also missing ...
dist: $(SOURCE_BUILT_AGENTS) $(SOURCE_BUILT_AGENT_UPDATER) protobuf-files cmk-frontend frontend-vue
$(MAKE) -C agents/plugins
set -e -o pipefail ; EXCLUDES= ; \
if [ -d .git ]; then \
git rev-parse HEAD > COMMIT ; \
for X in $$(git ls-files --directory --others -i --exclude-standard) ; do \
if [[ ! "$(DIST_DEPS)" =~ (^|[[:space:]])$$X($$|[[:space:]]) && $$X != omd/packages/mk-livestatus/mk-livestatus-$(VERSION).tar.gz && $$X != livestatus/* && $$X != enterprise/* ]]; then \
EXCLUDES+=" --exclude $${X%*/}" ; \
fi ; \
done ; \
else \
for F in $(DIST_ARCHIVE) non-free/cmk-update-agent/{build,build-32,src} non-free/cmk-update-agent/{build,build-32,src} enterprise/agents/winbuild; do \
EXCLUDES+=" --exclude $$F" ; \
done ; \
fi ; \
if [ -d check-mk-$(EDITION)-$(OMD_VERSION) ]; then \
rm -rf check-mk-$(EDITION)-$(OMD_VERSION) ; \
fi ; \
mkdir check-mk-$(EDITION)-$(OMD_VERSION) ; \
tar -c --wildcards \
$(TAROPTS) \
--exclude check-mk-$(EDITION)-$(OMD_VERSION) \
--exclude .git \
--exclude .gitignore \
--exclude .gitmodules \
--exclude .gitattributes \
$$EXCLUDES \
* .werks | tar x -C check-mk-$(EDITION)-$(OMD_VERSION)
if [ -f COMMIT ]; then \
rm COMMIT ; \
fi
tar -cz --wildcards -f $(DIST_ARCHIVE) \
$(TAROPTS) \
check-mk-$(EDITION)-$(OMD_VERSION)
rm -rf check-mk-$(EDITION)-$(OMD_VERSION)
cmk-frontend:
packages/cmk-frontend/run --clean --all
frontend-vue:
packages/cmk-frontend-vue/run --clean --all
announcement:
mkdir -p $(CHECK_MK_ANNOUNCE_FOLDER)
PYTHONPATH=${PYTHONPATH}:$(REPO_PATH) $(PIPENV) run python -m cmk.utils.werks announce .werks $(VERSION) --format=md > $(CHECK_MK_ANNOUNCE_MD)
PYTHONPATH=${PYTHONPATH}:$(REPO_PATH) $(PIPENV) run python -m cmk.utils.werks announce .werks $(VERSION) --format=txt > $(CHECK_MK_ANNOUNCE_TXT)
tar -czf $(CHECK_MK_ANNOUNCE_TAR) -C $(CHECK_MK_ANNOUNCE_FOLDER) .
packages:
$(MAKE) -C agents packages
version:
[ "$$(head -c 6 /etc/issue)" = "Ubuntu" \
-o "$$(head -c 16 /etc/issue)" = "Debian GNU/Linux" ] \
|| { echo 'You are not on the reference system!' ; exit 1; }
@newversion=$$(dialog --stdout --inputbox "New Version:" 0 0 "$(VERSION)") ; \
if [ -n "$$newversion" ] ; then $(MAKE) NEW_VERSION=$$newversion setversion ; fi
# NOTE: CMake accepts only up to 4 non-negative integer version parts, so we
# replace any character (like 'p' or 'b') with a dot. Not completely correct,
# but better than nothing. We have to rethink this setversion madness, anyway.
setversion:
sed -ri 's/^(VERSION[[:space:]]*:?= *).*/\1'"$(NEW_VERSION)/" defines.make
sed -i 's/^__version__ = ".*"$$/__version__ = "$(NEW_VERSION)"/' packages/cmk-ccc/cmk/ccc/version.py bin/livedump
$(MAKE) -C agents NEW_VERSION=$(NEW_VERSION) setversion
sed -i 's/^ARG CMK_VERSION=.*$$/ARG CMK_VERSION="$(NEW_VERSION)"/g' docker_image/Dockerfile
ifeq ($(ENTERPRISE),yes)
sed -i 's/^__version__ = ".*/__version__ = "$(NEW_VERSION)"/' non-free/cmk-update-agent/cmk_update_agent.py
sed -i 's/^VERSION = ".*/VERSION = "$(NEW_VERSION)"/' omd/packages/enterprise/bin/cmcdump
endif
$(OPENAPI_SPEC): $(shell find cmk/gui/openapi $(wildcard cmk/gui/cee/plugins/openapi) -name "*.py")
@export PYTHONPATH=${REPO_PATH} ; \
export TMPFILE=$$(mktemp); \
$(PIPENV) run python -m cmk.gui.openapi > $$TMPFILE && \
mv $$TMPFILE $@
openapi-clean:
rm -f $(OPENAPI_SPEC)
openapi: $(OPENAPI_SPEC)
# TODO(sp) The target below is not correct, we should not e.g. remove any stuff
# which is needed to run configure, this should live in a separate target. In
# fact, we should really clean up all this cleaning-chaos and finally follow the
# GNU standards here (see "Standard Targets for Users",
# https://www.gnu.org/prep/standards/html_node/Standard-Targets.html).
clean:
$(MAKE) -C omd clean
rm -rf *.rpm *.deb *.exe \
*~ counters autochecks \
precompiled cache announce*
EXCLUDE_PROPER= \
--exclude="**/.vscode" \
--exclude="**/.idea" \
--exclude=".werks/.last" \
--exclude=".werks/.my_ids"
EXCLUDE_CLEAN=$(EXCLUDE_PROPER) \
--exclude=".venv" \
--exclude=".venv.lock" \
--exclude=".cargo" \
--exclude="node_modules" \
--exclude=".cache"
# The list of files and folders to be protected from remove after "buildclean" is called
# Rust dirs are kept due to heavy load when compiled: .cargo, controller
AGENT_CTL_TARGET_PATH=packages/cmk-agent-ctl/target
MK_SQL_TARGET_PATH=packages/mk-sql/target
EXCLUDE_BUILD_CLEAN=$(EXCLUDE_CLEAN) \
--exclude="doc/plugin-api/build" \
--exclude=".cargo" \
--exclude=$(AGENT_CTL_TARGET_PATH) \
--exclude=$(MK_SQL_TARGET_PATH) \
--exclude="agents/plugins/*_2.py" \
--exclude="agents/plugins/*.py.checksum"
mrproper:
git clean -d --force -x $(EXCLUDE_PROPER)
mrclean:
git clean -d --force -x $(EXCLUDE_CLEAN)
# Used by our version build (buildscripts/scripts/build-cmk-version.jenkins)
# for cleaning up while keeping some build artifacts between version builds.
# This helps to speed up "make dist"
buildclean:
git clean -d --force -x $(EXCLUDE_BUILD_CLEAN)
setup:
sudo buildscripts/infrastructure/build-nodes/scripts/install-development.sh --profile all
sudo bash -c 'usermod -a -G docker $$SUDO_USER'
$(MAKE) check-setup
linesofcode:
@wc -l $$(find -type f -name "*.py" -o -name "*.js" -o -name "*.cc" -o -name "*.h" -o -name "*.css" | grep -v openhardwaremonitor | grep -v jquery ) | sort -n
protobuf-files:
ifeq ($(ENTERPRISE),yes)
$(MAKE) -C non-free/cmc-protocols protobuf-files
endif
format: format-python format-c format-shell format-bazel
format-c:
packages/livestatus/run --format
packages/unixcat/run --format
packages/neb/run --format
ifeq ($(ENTERPRISE),yes)
packages/cmc/run --format
endif
test-format-c:
packages/livestatus/run --check-format
packages/unixcat/run --check-format
packages/neb/run --check-format
ifeq ($(ENTERPRISE),yes)
packages/cmc/run --check-format
endif
format-python:
./scripts/run-pipenv run ruff check --select I --fix
./.venv/bin/ruff format
format-shell:
$(MAKE) -C tests format-shell
what-gerrit-makes:
$(MAKE) -C tests what-gerrit-makes
format-bazel:
scripts/run-buildifier --lint=fix --mode=fix
documentation:
echo Nothing to do here remove this target
sw-documentation-docker:
scripts/run-in-docker.sh scripts/run-pipenv run make -C doc/documentation html
Pipfile.lock:
@( \
flock $(LOCK_FD); \
if ! SKIP_MAKEFILE_CALL=1 $(PIPENV) verify > /dev/null; then \
if [ "${CI}" == "true" ]; then \
echo "A locking of Pipfile.lock is needed, but we're executed in the CI, where this should not be done."; \
echo "It seems you forgot to commit the new Pipfile.lock. Regenerate Pipfile.lock with e.g.:"; \
echo "make Pipfile.lock"; \
exit 1; \
fi; \
( SKIP_MAKEFILE_CALL=1 $(PIPENV) lock --python $(PYTHON_MAJOR_DOT_MINOR) ) \
|| ( $(RM) -r .venv ; exit 1 ) \
&& ( exec $(LOCK_FD)>&- ; bazel run //:requirements.update ) \
fi \
) $(LOCK_FD)>$(LOCK_PATH)
# .venv is PHONY because the dependencies are resolved now in the make_venv script
.venv: Pipfile.lock
@( \
flock $(LOCK_FD); \
$(REPO_PATH)/scripts/make_venv \
) $(LOCK_FD)>$(LOCK_PATH)