1# Makefile for NDOUtils
2#
3# Copyright 2009-2014 Nagios Core Development Team and Community Contributors
4# Copyright 2005-2009 Ethan Galstad
5#
6# This file is part of NDOUtils.
7#
8# NDOUtils is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2 as
10# published by the Free Software Foundation.
11#
12# NDOUtils is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with NDOUtils. If not, see <http://www.gnu.org/licenses/>.
19
20
21# Source code directories
22SRC_BASE=./src
23SRC_INCLUDE=./include
24SRC_CONFIG=./config
25
26prefix=@prefix@
27exec_prefix=@exec_prefix@
28PIPEDIR=@localstatedir@
29CFGDIR=@sysconfdir@
30BINDIR=@bindir@
31LIBEXECDIR=@libexecdir@
32
33NDO2DB_USER=@ndo2db_user@
34NDO2DB_GROUP=@ndo2db_group@
35
36INSTALL=@INSTALL@
37GREP=@GREP@
38EGREP=@EGREP@
39
40INSTALL_OPTS=@INSTALL_OPTS@
41OPSYS=@opsys@
42DIST=@dist_type@
43
44INIT_TYPE=@init_type@
45INIT_DIR=@initdir@
46INIT_OPTS=-o root -g @root_grp@
47INIT_FILE=@initname@
48INETD_TYPE=@inetd_type@
49INETD_DIR=@inetddir@
50INETD_FILE=@inetdname@
51SRC_INETD=@src_inetd@
52SRC_INIT=@src_init@
53
54default:
55	@echo;\
56	echo Please enter 'make [option]' where [option] is one of:;\
57	echo;\
58	echo "     all                  builds the NDO Utilities";\
59	echo "     ndo2db               builds the ndo2db daemon";\
60	echo "     ndomod               builds the ndomod nagios module";\
61	echo "     file2sock            builds the file2sock utility";\
62	echo "     log2ndo              builds the log2ndo utility";\
63	echo "     sockdebug            builds the sockdebug utility";\
64	echo "     install-groups-users add the user and group if they do not exist";\
65	echo "     install              installs the module and programs";\
66	echo "     install-config       installs the sample configuration files";\
67	echo "     install-inetd        install the startup files for inetd, launchd, etc.";\
68	echo "     install-init         install the startup files for init, systemd, etc.";\
69	echo "     fullinstall          runs install-groups-users, install,";\
70	echo "                          install-config and install-init";\
71	echo
72
73all:
74	cd $(SRC_BASE) && $(MAKE)
75
76ndo2db:
77	cd $(SRC_BASE); $(MAKE) $@
78
79ndomod:
80	cd $(SRC_BASE); $(MAKE) $@
81
82file2sock:
83	cd $(SRC_BASE); $(MAKE) $@
84
85log2ndo:
86	cd $(SRC_BASE); $(MAKE) $@
87
88sockdebug:
89	cd $(SRC_BASE); $(MAKE) $@
90
91ctags:
92	ctags -R
93
94install:
95	cd $(SRC_BASE) && $(MAKE) $@
96	@echo ""
97	@echo "Main NDOUtils components installed"
98	@echo ""
99
100install-config:
101	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(CFGDIR)
102	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(PIPEDIR)
103	$(INSTALL) -m 644 $(INSTALL_OPTS) config/ndo2db.cfg-sample $(DESTDIR)$(CFGDIR)
104	$(INSTALL) -m 644 $(INSTALL_OPTS) config/ndomod.cfg-sample $(DESTDIR)$(CFGDIR)
105	@echo ""
106	@echo "*** Config files installed ***"
107	@echo ""
108	@echo "Remember, these are *SAMPLE* config files.  You'll need to rename"
109	@echo "the files in order to use them."
110	@echo "Please read the documentation to know what they are doing."
111	@echo ""
112
113install-groups-users:
114	@macros/add_group_user $(DIST) $(NDO2DB_USER) $(NDO2DB_GROUP)
115
116install-init:
117	@if test $(SRC_INIT) = unknown; then \
118		echo No init file to install; \
119		exit 1; \
120	fi
121	@if test $(INIT_TYPE) = upstart; then\
122		echo $(INSTALL) -m 644 startup/$(SRC_INIT) $(INIT_DIR)/$(INIT_FILE); \
123		$(INSTALL) -m 644 startup/$(SRC_INIT) $(INIT_DIR)/$(INIT_FILE); \
124		echo initctl reload-configuration; \
125		initctl reload-configuration; \
126	elif test $(INIT_TYPE) = systemd; then\
127		echo $(INSTALL) -m 644 startup/$(SRC_INIT) $(INIT_DIR)/$(INIT_FILE); \
128		$(INSTALL) -m 644 startup/$(SRC_INIT) $(INIT_DIR)/$(INIT_FILE); \
129	elif test $(INIT_TYPE) = smf10 -o $(INIT_TYPE) = smf11; then \
130		echo $(INSTALL) -m 775 -g sys -d $(INIT_DIR);\
131		$(INSTALL) -m 775 -g sys -d $(INIT_DIR);\
132		echo $(INSTALL) -m 644 startup/$(SRC_INIT) $(INIT_DIR)/$(INIT_FILE); \
133		$(INSTALL) -m 644 startup/$(SRC_INIT) $(INIT_DIR)/$(INIT_FILE); \
134		echo svccfg import $(INIT_DIR)/$(INIT_FILE); \
135		svccfg import $(INIT_DIR)/$(INIT_FILE); \
136		echo "*** Run 'svcadm enable ndo2db' to start it"; \
137	else\
138		echo $(INSTALL) -m 755 startup/$(SRC_INIT) $(INIT_DIR)/$(INIT_FILE); \
139		$(INSTALL) -m 755 startup/$(SRC_INIT) $(INIT_DIR)/$(INIT_FILE); \
140		if test $(INIT_TYPE) = newbsd; then\
141			if test $(DIST) = openbsd; then\
142				echo "# ndo2db@bsd_enable@=NO" >> /etc/rc.conf;\
143				echo "ndo2db@bsd_enable@=\"-d -c $(CFGDIR)/ndo2db.cfg\"" >> /etc/rc.conf;\
144				echo "Make sure to enable the ndo2db daemon";\
145			else\
146				echo "ndo2db@bsd_enable@=YES" >> /etc/rc.conf;\
147				echo "ndo2db_configfile=$(CFGDIR)/ndo2db.cfg" >> /etc/rc.conf;\
148			fi;\
149		elif test $(INIT_TYPE) = launchd; then\
150			launchctl load $(INIT_DIR)/$(INIT_FILE); \
151		else\
152			if test -f /sbin/chkconfig ; then \
153			    /sbin/chkconfig ndo2db on;\
154			else\
155				echo "Make sure to enable the ndo2db daemon";\
156			fi;\
157		fi;\
158	fi
159
160install-inetd:
161	@if test $(SRC_INETD) = unknown; then \
162		echo No inetd file to install; \
163		exit 1; \
164	fi
165	@if test $(INETD_TYPE) = inetd; then \
166		$(EGREP) -q "^\W*nrpe\s+" $(INETD_DIR)/$(INETD_FILE) 2>/dev/null || \
167		   cat startup/$(SRC_INETD) >> $(INETD_DIR)/$(INETD_FILE); \
168	elif test $(INETD_TYPE) = systemd; then \
169		SRC_INETD_FILE=`echo "$(SRC_INETD)" | sed -e 's/socket/socket-svc/'`; \
170		echo $(INSTALL) -m 644 startup/$$SRC_INETD_FILE $(INETD_DIR)/$(INIT_FILE); \
171		$(INSTALL) -m 644 startup/$$SRC_INETD_FILE $(INETD_DIR)/$(INIT_FILE); \
172	elif test $(INETD_TYPE) = smf10 -o $(INETD_TYPE) = smf11; then \
173		echo $(INSTALL) -m 775 -g sys -d $(INETD_DIR);\
174		$(INSTALL) -m 775 -g sys -d $(INETD_DIR);\
175		echo $(INSTALL) -m 644 startup/$(SRC_INETD) $(INETD_DIR)/$(INETD_FILE); \
176		$(INSTALL) -m 644 startup/$(SRC_INETD) $(INETD_DIR)/$(INETD_FILE); \
177		$(INSTALL) -m 775 -d $(INETD_DIR);\
178		echo svccfg import $(INETD_DIR)/$(INETD_FILE); \
179		svccfg import $(INETD_DIR)/$(INETD_FILE); \
180		echo "*** Run 'svcadm enable nrpe' to start it"; \
181	elif test $(INIT_TYPE) = launchd; then\
182		$(INSTALL) -m 644 startup/$(SRC_INETD) $(INETD_DIR)/$(INETD_FILE); \
183		launchctl load $(INETD_DIR)/$(INETD_FILE); \
184	else\
185		echo $(INSTALL) -m 644 startup/$(SRC_INETD) $(INETD_DIR)/$(INETD_FILE); \
186		$(INSTALL) -m 644 startup/$(SRC_INETD) $(INETD_DIR)/$(INETD_FILE); \
187	fi
188	@$(EGREP) -q "^nrpe[\t ]+@ndo2db_port@/tcp" /etc/services || \
189		echo "***** MAKE SURE 'ndo2db @ndo2db_port@/tcp' IS IN YOUR /etc/services FILE"
190
191fullinstall: install-groups-users install install-config install-init
192
193clean:
194	cd $(SRC_BASE) && $(MAKE) $@
195	rm -f core
196	rm -f *~ */*~ include/nagios-*/*~
197
198distclean: clean
199	cd $(SRC_BASE) && $(MAKE) $@; cd ..
200	cd docs/docbook/en-en/ && $(MAKE) $@
201	rm -f config.log config.status config.cache
202	rm -f $(SRC_INCLUDE)/dh.h $(SRC_INCLUDE)/config.h
203	rm -f $(SRC_CONFIG)/ndo2db.cfg-sample $(SRC_CONFIG)/ndomod.cfg-sample $(SRC_CONFIG)/nagios.cfg $(SRC_CONFIG)/misccommands.cfg
204	rm -f startup/bsd-init startup/debian-init startup/default-init startup/default-inetd
205	rm -f startup/default-service startup/default-socket startup/default-socket-svc
206	rm -f startup/default-xinetd startup/mac-init.plist startup/mac-inetd.plist
207	rm -f startup/newbsd-init startup/openbsd-init startup/openrc-conf
208	rm -f startup/openrc-init startup/rh-upstart-init startup/solaris-init.xml
209	rm -f startup/solaris-inetd.xml startup/tmpfile.conf startup/upstart-init
210	rm -f Makefile
211	rm -f tags
212	rm -rf autom4te.cache/
213
214devclean: distclean
215
216