Shinken is now also using shipped python
[omd.git] / Makefile
blob96dee0b4174668d6e1bd4754a55e13518ee0b6b7
1 SHELL = /bin/bash
2 # You can select a subset of the packages by overriding this
3 # variale, e.g. make PACKAGES='nagios rrdtool' pack
4 PACKAGES=perl-modules \
5 python \
6 python-modules \
7 apache-omd \
8 mod_python \
9 check_logfiles \
10 check_mk \
11 check_multi \
12 check_mysql_health \
13 check_oracle_health \
14 check_webinject \
15 dokuwiki \
16 example \
17 jmx4perl \
18 mk-livestatus \
19 mysql-omd \
20 icinga \
21 nagios \
22 monitoring-plugins \
23 nagvis \
24 nrpe \
25 nsca \
26 omd \
27 pnp4nagios \
28 rrdtool \
29 shinken \
30 thruk \
31 maintenance \
32 gearmand \
33 mod-gearman \
34 patch \
35 nail \
36 notifications-tt
38 include Makefile.omd
40 # If you just want to test package building, you can reduce the
41 # number of packages to just "omd" - to speed up your tests.
42 # PACKAGES="omd"
44 # This file is kept by 'make config' and also may override
45 # the list of packages
46 -include .config
48 DESTDIR ?=$(shell pwd)/destdir
49 RPM_TOPDIR=$$(pwd)/rpm.topdir
50 DPKG_TOPDIR=$$(pwd)/dpkg.topdir
51 SOURCE_TGZ=omd-$(OMD_VERSION).tar.gz
52 BIN_TGZ=omd-bin-$(OMD_VERSION).tar.gz
53 NEWSERIAL=$$(($(OMD_SERIAL) + 1))
54 APACHE_NAME=$(APACHE_INIT_NAME)
55 ifdef BUILD_CACHE
56 DEFAULT_BUILD=build-cached
57 else
58 DEFAULT_BUILD=build
59 endif
61 .PHONY: install-global
63 omd: $(DEFAULT_BUILD)
65 build-cached:
66 @set -e ; cd packages ; for p in $(PACKAGES) ; do \
67 OMD_VERSION="$(OMD_VERSION)" BUILD_CACHE="$(BUILD_CACHE)" ../build_cached "$(MAKE)" "$$p" "$(DISTRO_NAME)/$(DISTRO_VERSION)/$(shell uname -m)"; \
68 done
71 build:
72 @set -e ; cd packages ; for p in $(PACKAGES) ; do \
73 $(MAKE) -C $$p build ; \
74 done
76 speed:
77 @set -e ; cd packages ; for p in $(PACKAGES) ; do \
78 ( NOW=$$(date +%s) ; \
79 $(MAKE) -C $$p build > ../$$p.log 2>&1 \
80 && echo "$$p(ok - $$(( $$(date +%s) - NOW ))s)" \
81 || echo "$$p(ERROR - $$(( $$(date +%s) - NOW ))s)" ) & \
82 done ; wait ; echo "FINISHED."
84 pack:
85 rm -rf $(DESTDIR)
86 mkdir -p $(DESTDIR)$(OMD_PHYSICAL_BASE)
87 A="$(OMD_PHYSICAL_BASE)" ; ln -s $${A:1} $(DESTDIR)/omd
88 @set -e ; cd packages ; for p in $(PACKAGES) ; do \
89 $(MAKE) -C $$p DESTDIR=$(DESTDIR) install ; \
90 for hook in $$(cd $$p ; ls *.hook 2>/dev/null) ; do \
91 mkdir -p $(DESTDIR)$(OMD_ROOT)/lib/omd/hooks ; \
92 install -m 755 $$p/$$hook $(DESTDIR)$(OMD_ROOT)/lib/omd/hooks/$${hook%.hook} ; \
93 done ; \
94 done
96 # Repair packages that install with silly modes (such as Nagios)
97 chmod -R o+Xr $(DESTDIR)$(OMD_ROOT)
98 $(MAKE) install-global
100 # Install skeleton files (subdirs skel/ in packages' directories)
101 mkdir -p $(DESTDIR)$(OMD_ROOT)/skel
102 @set -e ; cd packages ; for p in $(PACKAGES) ; do \
103 if [ -d "$$p/skel" ] ; then \
104 tar cf - -C $$p/skel --exclude="*~" --exclude=".gitignore" . | tar xvf - -C $(DESTDIR)$(OMD_ROOT)/skel ; \
105 fi ;\
106 $(MAKE) DESTDIR=$(DESTDIR) SKEL=$(DESTDIR)$(OMD_ROOT)/skel -C $$p skel ;\
107 done
109 # Create permissions file for skel
110 mkdir -p $(DESTDIR)$(OMD_ROOT)/share/omd
111 @set -e ; cd packages ; for p in $(PACKAGES) ; do \
112 if [ -e $$p/skel.permissions ] ; then \
113 echo "# $$p" ; \
114 cat $$p/skel.permissions ; \
115 fi ; \
116 done > $(DESTDIR)$(OMD_ROOT)/share/omd/skel.permissions
118 # Make sure, all permissions in skel are set to 0755, 0644
119 @failed=$$(find $(DESTDIR)$(OMD_ROOT)/skel -type d -not -perm 0755) ; \
120 if [ -n "$$failed" ] ; then \
121 echo "Invalid permissions for skeleton dirs. Must be 0755:" ; \
122 echo "I'll fix this for you this time..." ; \
123 chmod -c 755 $$failed ; \
124 echo "$$failed" ; \
126 @failed=$$(find $(DESTDIR)$(OMD_ROOT)/skel -type f -not -perm 0644) ; \
127 if [ -n "$$failed" ] ; then \
128 echo "Invalid permissions for skeleton files. Must be 0644:" ; \
129 echo "$$failed" ; \
130 echo "I'll fix this for you this time..." ; \
131 chmod -c 644 $$failed ; \
134 # Fix packages which did not add ###ROOT###
135 find $(DESTDIR)$(OMD_ROOT)/skel -type f | xargs -n1 sed -i -e 's+$(OMD_ROOT)+###ROOT###+g'
137 # Remove site-specific directories that went under /omd/version
138 rm -rf $(DESTDIR)/{var,tmp}
140 # Pack the whole stuff into a tarball
141 tar czf $(BIN_TGZ) --owner=root --group=root -C $(DESTDIR) .
143 clean:
144 rm -rf $(DESTDIR)
145 @for p in packages/* ; do \
146 $(MAKE) -C $$p clean ; \
147 done
149 mrproper:
150 git clean -xfd
152 config:
153 @inarray () { \
154 elem="$$1" ; \
155 shift ; \
156 for x in "$$@" ; do if [ $$elem = $$x ] ; then return 0 ; fi ; done ; \
157 return 1 ; \
158 } ; \
159 if [ "$(PACKAGES)" = '*' ] ; \
160 then \
161 enabled='*' ; \
162 else \
163 enabled=( $(PACKAGES) ) ; \
164 fi ; \
165 echo "$$enabled" ; \
166 avail=$$(for p in $$(cd packages ; ls) ; do if [ "$$enabled" = '*' ] || inarray $$p $${enabled[@]} ; then en=on ; else en="-" ; fi ; echo -n "$$p - $$en " ; done) ; \
167 if packages=$$(dialog --stdout --checklist "Package configuration" 1 0 0 $$avail ) ; \
168 then \
169 echo "PACKAGES = $$packages" | sed 's/"//g' > .config ; \
173 # Create installations files that do not lie beyond /omd/versions/$(OMD_VERSION)
174 # and files not owned by a specific package.
175 install-global:
176 # Create link to default version
177 ln -s $(OMD_VERSION) $(DESTDIR)$(OMD_BASE)/versions/default
179 # Create global symbolic links. Those links are share between
180 # all installed versions and refer to the default version.
181 mkdir -p $(DESTDIR)/usr/bin
182 ln -sfn /omd/versions/default/bin/omd $(DESTDIR)/usr/bin/omd
183 mkdir -p $(DESTDIR)/usr/share/man/man8
184 ln -sfn /omd/versions/default/share/man/man8/omd.8.gz $(DESTDIR)/usr/share/man/man8/omd.8.gz
185 mkdir -p $(DESTDIR)/etc/init.d
186 ln -sfn /omd/versions/default/share/omd/omd.init $(DESTDIR)/etc/init.d/omd
187 mkdir -p $(DESTDIR)$(APACHE_CONF_DIR)
188 ln -sfn /omd/versions/default/share/omd/apache.conf $(DESTDIR)$(APACHE_CONF_DIR)/zzz_omd.conf
190 # Base directories below /omd
191 mkdir -p $(DESTDIR)$(OMD_BASE)/sites
192 mkdir -p $(DESTDIR)$(OMD_BASE)/apache
195 # Information about distribution and OMD
196 mkdir -p $(DESTDIR)$(OMD_ROOT)/share/omd
197 install -m 644 distros/Makefile.$(DISTRO_NAME)_$(DISTRO_VERSION) $(DESTDIR)$(OMD_ROOT)/share/omd/distro.info
198 echo -e "OMD_VERSION = $(OMD_VERSION)\nOMD_PHYSICAL_BASE = $(OMD_PHYSICAL_BASE)" > $(DESTDIR)$(OMD_ROOT)/share/omd/omd.info
200 # README files and license information
201 mkdir -p $(DESTDIR)$(OMD_ROOT)/share/doc
202 install -m 644 README COPYING TEAM $(DESTDIR)$(OMD_ROOT)/share/doc
203 install -m 644 Changelog $(DESTDIR)$(OMD_ROOT)/share/doc/CHANGELOG
205 # Create source tarball. This currently only works in a checked out GIT
206 # repository.
207 $(SOURCE_TGZ) dist:
208 rm -rf omd-$(OMD_VERSION)
209 mkdir -p omd-$(OMD_VERSION)
210 git archive HEAD | tar xf - -C omd-$(OMD_VERSION)
211 tar czf $(SOURCE_TGZ) omd-$(OMD_VERSION)
212 rm -rf omd-$(OMD_VERSION)
214 # Creates source tarball. This does only work well in directories extracted
215 # from a CLEAN git archive tarball.
216 $(SOURCE_TGZ)-snap snap:
217 rm -rf omd-$(OMD_VERSION)
218 mkdir -p omd-$(OMD_VERSION)
219 tar cf - --exclude="rpm.topdir" --exclude="*~" --exclude=".gitignore" --exclude "omd-$(OMD_VERSION)" . | tar xf - -C omd-$(OMD_VERSION)
220 tar czf $(SOURCE_TGZ) omd-$(OMD_VERSION)
221 rm -rf omd-$(OMD_VERSION)
223 # Build RPM from source code.
224 # When called from a git repository this uses 'make dist' and thus 'git archive'
225 # to create the source rpm.
226 # The second choice is to call this form a CLEAN git archive directory which
227 # then uses 'make snap' to use that snapshot.
228 rpm:
229 sed -e 's/^Requires:.*/Requires: $(OS_PACKAGES)/' \
230 -e 's/%{version}/$(OMD_VERSION)/g' \
231 -e 's/^Version:.*/Version: $(DISTRO_CODE)/' \
232 -e 's/^Release:.*/Release: $(OMD_SERIAL)/' \
233 -e 's#@APACHE_CONFDIR@#$(APACHE_CONF_DIR)#g' \
234 -e 's#@APACHE_NAME@#$(APACHE_NAME)#g' \
235 omd.spec.in > omd.spec
236 rm -f $(SOURCE_TGZ)
237 test -d .git && $(MAKE) $(SOURCE_TGZ) || $(MAKE) $(SOURCE_TGZ)-snap
238 mkdir -p $(RPM_TOPDIR)/{SOURCES,BUILD,RPMS,SRPMS,SPECS}
239 cp $(SOURCE_TGZ) $(RPM_TOPDIR)/SOURCES
240 # NO_BRP_STALE_LINK_ERROR ignores errors when symlinking from skel to
241 # share,lib,bin because the link has a invalid target until the site is created
242 NO_BRP_STALE_LINK_ERROR="yes" \
243 rpmbuild -ba --define "_topdir $(RPM_TOPDIR)" \
244 --buildroot=$$(pwd)/rpm.buildroot omd.spec
245 mv -v $(RPM_TOPDIR)/RPMS/*/*.rpm .
246 mv -v $(RPM_TOPDIR)/SRPMS/*.src.rpm .
247 rm -rf $(RPM_TOPDIR) rpm.buildroot
249 # Build DEB from prebuild binary. This currently needs 'make dist' and thus only
250 # works within a GIT repository.
251 deb-environment:
252 @if test -z "$(DEBFULLNAME)" || test -z "$(DEBEMAIL)"; then \
253 echo "please read 'man dch' and set DEBFULLNAME and DEBEMAIL" ;\
254 exit 1; \
257 # create a debian/changelog to build the package
258 deb-changelog: deb-environment
259 # this is a hack!
260 rm -f debian/changelog
261 dch --create --package omd-$(OMD_VERSION) \
262 --newversion 0.$(DISTRO_CODE) "`cat debian/changelog.tmpl`"
263 dch --release "releasing ...."
265 deb: deb-changelog
266 sed -e 's/###OMD_VERSION###/$(OMD_VERSION)/' \
267 -e 's/###BUILD_PACKAGES###/$(BUILD_PACKAGES)/' \
268 -e 's/###OS_PACKAGES###/$(OS_PACKAGES)/' \
269 -e '/Depends:/s/\> /, /g' \
270 -e '/Depends:/s/@/ /g' \
271 `pwd`/debian/control.in > `pwd`/debian/control
272 fakeroot debian/rules clean
273 debuild --no-lintian -i\.git -I\.git \
274 -iomd-bin-$(OMD_VERSION).tar.gz \
275 -Iomd-bin-$(OMD_VERSION).tar.gz \
276 -i.gitignore -I.gitignore \
277 -uc -us -rfakeroot
278 # -- renaming deb package to DISTRO_CODE dependend name
279 # arch=`dpkg-architecture -qDEB_HOST_ARCH` ; \
280 # build=`sed -e '1s/.*(\(.*\)).*/\1/;q' debian/changelog` ; \
281 # distro=`echo $$build | sed -e 's/build/$(DISTRO_CODE)/' ` ; \
282 # echo "$$arch $$build $$distro"; \
283 # mv "../omd-$(OMD_VERSION)_$${build}_$${arch}.deb" \
284 # "../omd-$(OMD_VERSION)_$${distro}_$${arch}.deb" ;
286 deb-snap: deb-environment
287 make clean && git checkout -- Makefile.omd packages/omd/omd && \
288 make VERSION=`./get_version` version && make deb && \
289 git checkout -- Makefile.omd packages/omd/omd
291 # Only to be used for developement testing setup
292 setup: pack xzf alt
294 # Only for development: install tarball below /
295 xzf:
296 tar xzf $(BIN_TGZ) -C / # HACK: Add missing suid bits if compiled as non-root
297 chmod 4755 $(OMD_ROOT)/lib/nagios/plugins/check_{icmp,dhcp}
298 chmod 4775 $(OMD_ROOT)/bin/mkeventd_open514
299 $(APACHE_CTL) -k graceful
301 # On debian based systems register the alternative switches
302 alt:
303 @if which update-alternatives >/dev/null 2>&1; then \
304 update-alternatives --install /omd/versions/default \
305 omd /omd/versions/$(OMD_VERSION) $(OMD_SERIAL) \
306 --slave /usr/bin/omd omd.bin /omd/versions/$(OMD_VERSION)/bin/omd \
307 --slave /usr/share/man/man8/omd.8.gz omd.man8 \
308 /omd/versions/$(OMD_VERSION)/share/man/man8/omd.8.gz ; \
309 fi ;
311 version:
312 @if [ -z "$(VERSION)" ] ; then \
313 newversion=$$(dialog --stdout --inputbox "New Version:" 0 0 "$(OMD_VERSION)") ; \
314 else \
315 newversion=$(VERSION) ; \
316 fi ; \
317 if [ -n "$$newversion" ] && [ "$$newversion" != "$(OMD_VERSION)" ]; then \
318 sed -ri 's/^(OMD_VERSION[[:space:]]*= *).*/\1'"$$newversion/" Makefile.omd ; \
319 sed -ri 's/^(OMD_SERIAL[[:space:]]*= *).*/\1'"$(NEWSERIAL)/" Makefile.omd ; \
320 sed -ri 's/^(OMD_VERSION[[:space:]]*= *).*/\1"'"$$newversion"'"/' packages/omd/omd ; \
321 fi ;
323 test:
324 t/test_all.sh