1 SHELL
= /bin
/bash
-e
-o pipefail
3 BUILD_HELPER_DIR
:= build-helper
4 PACKAGE_DIR
:= $(shell pwd
)/packages
7 include $(BUILD_HELPER_DIR
)/build-helper-files.make
8 include packages
/packages.make
10 # You can build singele packages by calling macke <PACKAGENAME>
11 # e.g.: make nagios rrdtool
13 # You can select a subset of the packages by overriding this
14 # variale, e.g. make PACKAGES='nagios rrdtool' pack
16 # If you just want to test package building, you can reduce the
17 # number of packages to just "omd" - to speed up your tests.
20 # You can also create a file named .config and override the
21 # PACKAGES variable there to customzie the list of packages.
61 ifeq ($(EDITION
),enterprise
)
62 PACKAGES
+= enterprise
64 ifeq ($(EDITION
),managed
)
65 PACKAGES
+= enterprise
71 # Workaround: Makefiles evaluate Variables the first time they are read. If a variable is not set the
72 # moment it is read, it is replaced with an empty string. Therefor our dependencies get lost, if the
73 # inlcuded Makefiles are not ordered correctly. For that reason, we parse the Makefiles for certain
74 # variable definitions and write them to an extra Makefile, which we include before the package Makefile.
75 $(BUILD_HELPER_DIR
)/build-helper-files.make
:
76 mkdir
-p
$(BUILD_HELPER_DIR
)
78 for P in
$(PACKAGES
); do \
79 inc_path
=$(PACKAGE_DIR
)/$$P/$$P.make
; \
80 if
[[ $$P == 'enterprise' ||
$$P == 'managed' ]] ; then \
81 inc_path
=$(REPO_PATH
)/$$P/$$P.make
; \
83 P_VAR
=$$(echo
$${P^^
} | tr
'-' '_' ); \
84 egrep
-h
"$$P_VAR\s:=\s" $$inc_path >> $@
; \
85 egrep
-h
"$${P_VAR}_VERS\s:=\s" $$inc_path >> $@
; \
86 egrep
-h
"$${P_VAR}_DIR\s:=\s" $$inc_path >> $@
; \
87 egrep
-h
"$${P_VAR}_BUILD\s:=\s" $$inc_path >> $@
; \
88 egrep
-h
"$${P_VAR}_INSTALL\s:=\s" $$inc_path >> $@
; \
93 DESTDIR ?
=$(shell pwd
)/destdir
94 RPM_TOPDIR
=$$(pwd
)/rpm.topdir
95 BIN_TGZ
=check-mk-
$(EDITION
)-bin-
$(OMD_VERSION
).
tar.gz
96 NEW_SERIAL
=$$(($(OMD_SERIAL
) + 1))
97 SKEL
:= $(DESTDIR
)$(OMD_ROOT
)/skel
98 # NEW_VERSION should be set on the command line.
99 # Replace all '/' since sed tries to interpret them
100 # '/' might occur in custom branches
101 # filenames and sed arguments should not contain '/'
102 NEW_VERSION_STRING
:= $(subst /,-,$(NEW_VERSION
))
103 CMA_PKG_VERSION_TXT
:= $(shell if
[ "$(DISTRO_CODE)" = "stretch" ]; then echo
"-2" ; fi
)
104 PKG_VERSION
:= $(basename $(OMD_VERSION
))
105 ARCH
:= $(shell uname
-m
)
106 CMA_PACKAGE
:= $(REPO_PATH
)/check-mk-
$(EDITION
)-$(PKG_VERSION
)$(CMA_PKG_VERSION_TXT
)-$(ARCH
).cma
108 PRE_INSTALL
:= $(BUILD_HELPER_DIR
)/pre-install
109 PRE_SKEL
:= $(BUILD_HELPER_DIR
)/pre-skel
110 INSTALL
:= $(BUILD_HELPER_DIR
)/install
111 INSTALL_GLOBAL
:= $(BUILD_HELPER_DIR
)/install-global
113 BUILD_TARGET_VARS
:= $(shell echo
$(PACKAGES
) | tr
'a-z' 'A-Z' | tr
'-' '_' )
114 BUILD_TARGETS
:= $(foreach package
,$(addsuffix _BUILD
,$(BUILD_TARGET_VARS
)),$($(package
)))
115 INSTALL_TARGETS
:= $(foreach package
,$(addsuffix _INSTALL
,$(BUILD_TARGET_VARS
)),$($(package
)))
116 SKEL_TARGETS
:= $(foreach package
,$(addsuffix _SKEL
,$(BUILD_TARGET_VARS
)),$($(package
)))
118 .PHONY
: install-global build
install pack skel
120 build
: $(BUILD_TARGETS
)
124 install-global
: $(INSTALL_GLOBAL
)
128 skel
: $(DESTDIR
)$(OMD_ROOT
)/share
/omd
/skel.permissions
$(FIX_SKEL
)
132 #Prepare clean install environment
135 rm -rf
$(BUILD_HELPER_DIR
)/*-install
136 $(MKDIR
) $(DESTDIR
)$(OMD_PHYSICAL_BASE
)
137 A
="$(OMD_PHYSICAL_BASE)" ; ln
-s
$${A
:1} $(DESTDIR
)/omd
138 $(MKDIR
) $(DESTDIR
)$(OMD_ROOT
)/bin
139 $(MKDIR
) $(DESTDIR
)$(OMD_ROOT
)/omd
/versions
/$(OMD_VERSION
)/bin
140 $(MKDIR
) $(DESTDIR
)$(OMD_ROOT
)/lib
/omd
/hooks
141 $(MKDIR
) $(DESTDIR
)$(OMD_ROOT
)/lib
/nagios
/plugins
142 $(MKDIR
) $(DESTDIR
)$(OMD_ROOT
)/share
/omd
143 $(MKDIR
) $(DESTDIR
)$(OMD_ROOT
)/share
/diskspace
144 $(MKDIR
) $(DESTDIR
)$(OMD_ROOT
)/share
/man
/man1
148 $(INSTALL_TARGETS
): $(PRE_INSTALL
)
150 $(SKEL_TARGETS
): $(PRE_SKEL
)
152 $(INSTALL
): $(INSTALL_TARGETS
)
153 # Repair packages that install with silly modes (such as Nagios)
154 chmod
-R o
+Xr
$(DESTDIR
)$(OMD_ROOT
)
157 $(PRE_SKEL
) : $(INSTALL_GLOBAL
)
158 # Install skeleton files (subdirs skel/ in packages' directories)
159 mkdir
-p
$(DESTDIR
)$(OMD_ROOT
)/skel
160 @set
-e
; cd packages
; for p in
$(PACKAGES
) ; do \
161 if
[ -d
"$$p/skel" ] ; then \
162 tar cf
- -C
$$p/skel
--exclude
="*~" --exclude
=".gitignore" . |
tar xvf
- -C
$(DESTDIR
)$(OMD_ROOT
)/skel
; \
167 $(DESTDIR
)$(OMD_ROOT
)/share
/omd
/skel.permissions
: $(SKEL_TARGETS
)
168 # Create permissions file for skel
169 mkdir
-p
$(DESTDIR
)$(OMD_ROOT
)/share
/omd
170 set
-e
; cd packages
; for p in
$(PACKAGES
) ; do \
171 if
[ -d
$$p ] && [ -e
$$p/skel.permissions
] ; then \
173 cat
$$p/skel.permissions
; \
175 done
> $(DESTDIR
)$(OMD_ROOT
)/share
/omd
/skel.permissions
177 $(FIX_SKEL
): $(SKEL_TARGETS
)
178 # Make sure, all permissions in skel are set to 0755, 0644
179 @failed
=$$(find
$(DESTDIR
)$(OMD_ROOT
)/skel
-type d
-not
-perm
0755) ; \
180 if
[ -n
"$$failed" ] ; then \
181 echo
"Fixing invalid permissions for skeleton dirs. Must be 0755:" ; \
182 chmod
-c
755 $$failed ; \
185 @failed
=$$(find
$(DESTDIR
)$(OMD_ROOT
)/skel
-type f
-not
-perm
0644) ; \
186 if
[ -n
"$$failed" ] ; then \
187 echo
"Fixing invalid permissions for skeleton files. Must be 0644:" ; \
189 chmod
-c
644 $$failed ; \
192 # Fix packages which did not add ###ROOT###
193 find
$(DESTDIR
)$(OMD_ROOT
)/skel
-type f | xargs
-n1 sed
-i
-e
's+$(OMD_ROOT)+###ROOT###+g'
195 # Remove site-specific directories that went under /omd/version
196 rm -rf
$(DESTDIR
)/{var
,tmp
}
199 # Create installations files that do not lie beyond /omd/versions/$(OMD_VERSION)
200 # and files not owned by a specific package.
201 $(INSTALL_GLOBAL
): $(INSTALL
)
202 # Create link to default version
203 ln
-s
$(OMD_VERSION
) $(DESTDIR
)$(OMD_BASE
)/versions
/default
205 # Create global symbolic links. Those links are share between
206 # all installed versions and refer to the default version.
207 mkdir
-p
$(DESTDIR
)/usr
/bin
208 ln
-sfn
/omd
/versions
/default
/bin
/omd
$(DESTDIR
)/usr
/bin
/omd
209 mkdir
-p
$(DESTDIR
)/usr
/share
/man
/man8
210 ln
-sfn
/omd
/versions
/default
/share
/man
/man8
/omd
.8.gz
$(DESTDIR
)/usr
/share
/man
/man8
/omd
.8.gz
211 mkdir
-p
$(DESTDIR
)/etc
/init.d
212 ln
-sfn
/omd
/versions
/default
/share
/omd
/omd.init
$(DESTDIR
)/etc
/init.d
/omd
213 mkdir
-p
$(DESTDIR
)$(APACHE_CONF_DIR
)
214 ln
-sfn
/omd
/versions
/default
/share
/omd
/apache.conf
$(DESTDIR
)$(APACHE_CONF_DIR
)/zzz_omd.conf
216 # Base directories below /omd
217 mkdir
-p
$(DESTDIR
)$(OMD_BASE
)/sites
218 mkdir
-p
$(DESTDIR
)$(OMD_BASE
)/apache
220 # Information about distribution and OMD
221 mkdir
-p
$(DESTDIR
)$(OMD_ROOT
)/share
/omd
222 install -m
644 distros
/$(DISTRO_NAME
)_
$(DISTRO_VERSION
).mk
$(DESTDIR
)$(OMD_ROOT
)/share
/omd
/distro.
info
223 echo
-e
"OMD_VERSION = $(OMD_VERSION)\nOMD_PHYSICAL_BASE = $(OMD_PHYSICAL_BASE)" > $(DESTDIR
)$(OMD_ROOT
)/share
/omd
/omd.
info
225 # Install ChangeLog created from all werks
226 mkdir
-p
$(DESTDIR
)$(OMD_ROOT
)/share
/doc
227 ln
-s check_mk
/ChangeLog
$(DESTDIR
)$(OMD_ROOT
)/share
/doc
/ChangeLog
228 install -m
644 Licenses.csv
$(DESTDIR
)$(OMD_ROOT
)/share
/doc
/Licenses.csv
230 if
[ -f COMMIT
]; then \
231 install -m
644 COMMIT
$(DESTDIR
)$(OMD_ROOT
)/share
/doc
; \
235 $(BIN_TGZ
): $(DESTDIR
)$(OMD_ROOT
)/share
/omd
/skel.permissions
$(FIX_SKEL
)
236 # Pack the whole stuff into a tarball
237 tar czf
$@
--owner
=root
--group
=root
-C
$(DESTDIR
) .
240 PKG_VERSION
=$(OMD_VERSION
) ; \
241 sed
-e
's/^Requires:.*/Requires: $(OS_PACKAGES)/' \
242 -e
's/%{version}/$(OMD_VERSION)/g' \
243 -e
"s/%{pkg_version}/$(PKG_VERSION)/g" \
244 -e
's/%{edition}/$(EDITION)/g' \
245 -e
's/^Version:.*/Version: $(DISTRO_CODE)/' \
246 -e
's/^Release:.*/Release: $(OMD_SERIAL)/' \
247 -e
's#@APACHE_CONFDIR@#$(APACHE_CONF_DIR)#g' \
248 -e
's#@APACHE_NAME@#$(APACHE_INIT_NAME)#g' \
249 omd.spec.in
> omd.spec
250 if
[ "$(EDITION)" = "raw" ]; then \
251 sed
-i
'/icmpsender/d;/icmpreceiver/d' omd.spec
; \
253 mkdir
-p
$(RPM_TOPDIR
)/{SOURCES
,BUILD
,RPMS
,SRPMS
,SPECS
}
254 cp ..
/check-mk-
$(EDITION
)-$(OMD_VERSION
).
tar.gz
$(RPM_TOPDIR
)/SOURCES
255 # NO_BRP_STALE_LINK_ERROR ignores errors when symlinking from skel to
256 # share,lib,bin because the link has a invalid target until the site is created
257 # NO_BRP_CHECK_RPATH ignores errors with the compiled python2.7 binary which
258 # has a rpath hard coded to the OMD shipped libpython2.7.
259 NO_BRP_CHECK_RPATH
="yes" \
260 NO_BRP_STALE_LINK_ERROR
="yes" \
261 rpmbuild
-ba
--define "_topdir $(RPM_TOPDIR)" \
262 --buildroot
=$$(pwd
)/rpm.buildroot omd.spec
263 mv
-v
$(RPM_TOPDIR
)/RPMS
/*/*.rpm
$(REPO_PATH
)
264 mv
-v
$(RPM_TOPDIR
)/SRPMS
/*.src.rpm
$(REPO_PATH
)
265 rm -rf
$(RPM_TOPDIR
) rpm.buildroot
267 # create a debian/changelog to build the package
269 # Build DEB from prebuild binary. This currently needs 'make dist' and thus only
270 # works within a GIT repository.
271 @if
test -z
"$(DEBFULLNAME)" ||
test -z
"$(DEBEMAIL)"; then \
272 echo
"please read 'man dch' and set DEBFULLNAME and DEBEMAIL" ;\
276 rm -f debian
/changelog
277 PKG_VERSION
=$(OMD_VERSION
) ; \
278 PKG_VERSION
=$${PKG_VERSION
/.cee
/} ; \
279 PKG_VERSION
=$${PKG_VERSION
/.cre
/} ; \
280 PKG_VERSION
=$${PKG_VERSION
/.cme
/} ; \
281 dch
--create
--package check-mk-
$(EDITION
)-$$PKG_VERSION \
282 --newversion
0.
$(DISTRO_CODE
) "`cat debian/changelog.tmpl`"
283 dch
--release
"releasing ...."
285 deb
: debian
/changelog
286 sed
-e
's/###OMD_VERSION###/$(OMD_VERSION)/' \
287 -e
"s/###PKG_VERSION###/$(PKG_VERSION)/" \
288 -e
's/###EDITION###/$(EDITION)/' \
289 -e
's/###BUILD_PACKAGES###/$(BUILD_PACKAGES)/' \
290 -e
's/###OS_PACKAGES###/$(OS_PACKAGES)/' \
291 -e
'/Depends:/s/\> /, /g' \
292 -e
'/Depends:/s/@/ /g' \
293 `pwd`/debian
/control.in
> `pwd`/debian
/control
294 fakeroot bash
-c
"export EDITION=$(EDITION) ; debian/rules clean"
295 debuild
--set-envvar EDITION
=$(EDITION
) \
296 --prepend-path
=/usr
/local
/bin
--no-lintian
-i\.git
-I\.git \
297 -icheck-mk-
$(EDITION
)-bin-
$(OMD_VERSION
).
tar.gz \
298 -Icheck-mk-
$(EDITION
)-bin-
$(OMD_VERSION
).
tar.gz \
299 -i.gitignore
-I.gitignore \
301 # -- renaming deb package to DISTRO_CODE dependend name
302 # arch=`dpkg-architecture -qDEB_HOST_ARCH` ; \
303 # build=`sed -e '1s/.*(\(.*\)).*/\1/;q' debian/changelog` ; \
304 # distro=`echo $$build | sed -e 's/build/$(DISTRO_CODE)/' ` ; \
305 # echo "$$arch $$build $$distro"; \
306 # mv "../omd-$(OMD_VERSION)_$${build}_$${arch}.deb" \
307 # "../omd-$(OMD_VERSION)_$${distro}_$${arch}.deb" ;
309 # On debian based systems register the alternative switches
311 @if which update-alternatives
>/dev
/null
2>&1; then \
312 update-alternatives
--install /omd
/versions
/default \
313 omd
/omd
/versions
/$(OMD_VERSION
) $(OMD_SERIAL
) \
314 --slave
/usr
/bin
/omd omd.bin
/omd
/versions
/$(OMD_VERSION
)/bin
/omd \
315 --slave
/usr
/share
/man
/man8
/omd
.8.gz omd.man8 \
316 /omd
/versions
/$(OMD_VERSION
)/share
/man
/man8
/omd
.8.gz
; \
320 NEW_OMD_VERSION
=$(NEW_VERSION_STRING
).
$(EDITION_SHORT
)$(DEMO_SUFFIX
) ; \
321 if
[ -n
"$$NEW_OMD_VERSION" ] && [ "$$NEW_OMD_VERSION" != "$(OMD_VERSION)" ]; then \
322 sed
-ri
's/^(OMD_SERIAL[[:space:]]*= *).*/\1'"$(NEW_SERIAL)/" Makefile.omd
; \
324 sed
-ri
's/^(OMD_VERSION[[:space:]]*= *).*/\1"'"$$NEW_OMD_VERSION"'"/' packages
/omd
/omdlib
/__init__.py
329 $(CMA_INSTALL
): $(INSTALL_TARGETS
)
331 $(CMA_PACKAGE
): $(CMA-INSTALL
) $(DESTDIR
)$(OMD_ROOT
)/share
/omd
/skel.permissions
$(FIX_SKEL
)
332 # Create info file to mark minimal cma firmware version requirement
333 @if
[ "$(DISTRO_CODE)" = "stretch" ]; then \
334 MIN_VERSION
=1.4.0 ; \
336 MIN_VERSION
=1.1.2 ; \
338 echo
-e
"MIN_VERSION=$${MIN_VERSION}\n" > $(DESTDIR
)/opt
/omd
/versions
/$(OMD_VERSION
)/cma.
info
340 # Mark demo builds in cma.info file
341 @if
[ -f packages
/nagios
/patches
/9999-demo-version.dif
]; then \
342 echo
-e
"DEMO=1\n" >> $(DESTDIR
)/opt
/omd
/versions
/$(OMD_VERSION
)/cma.
info ; \
348 -C
$(DESTDIR
)/opt
/omd
/versions
/ \
351 clean: $(addsuffix -clean,$(PACKAGES
))
353 @for p in packages
/* ; do \
354 if
[ -d
$$p ] && [ -f
$$p/Makefile
]; then \
355 $(MAKE
) -C
$$p clean ; \
358 $(RM
) -r
$(BUILD_HELPER_DIR
)
360 # Only for development: install tarball below /
362 tar xzf
$(BIN_TGZ
) -C
/ # HACK: Add missing suid bits if compiled as non-root
363 chmod
4755 $(OMD_ROOT
)/lib
/nagios
/plugins
/check_
{icmp
,dhcp
}
364 chmod
4775 $(OMD_ROOT
)/bin
/mkeventd_open514
365 $(APACHE_CTL
) -k graceful
368 @echo
"Packages needed for compilation:"
369 @echo
"$(BUILD_PACKAGES)"
370 @CMD
="$(PACKAGE_INSTALL) $(BUILD_PACKAGES)" ; \
371 if
[ $$(id
-u
) != 0 ]; then \
372 CMD
="$(BECOME_ROOT) '$$CMD'" ; \
374 echo
"Going to run >>> $$CMD <<<..." ; \
376 if eval
"$$CMD"; then \
377 echo
"OK - You are now ready for 'make rpm' or 'make deb'" ; \
379 echo
"ERROR: Some packages could not be installed. You will get " ; \
380 echo
"problems while compiling if something is missing." ; \