###############################
# Makefile for PNP
#
# Last Modified: 12-10-2006
###############################


# Source code directories
SRC_BASE=@srcdir@/src
SRC_SHARE=@srcdir@/share
SRC_LIB=@srcdir@/lib
SRC_SCRIPTS=@srcdir@/scripts
SRC_CONFIG=@srcdir@/sample-config
SRC_MAN=@srcdir@/man
SRC_CONTRIB=@srcdir@/contrib
SRC_HELPERS=@srcdir@/helpers

CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@
LDFLAGS=@LDFLAGS@ @LIBS@

prefix=@prefix@
exec_prefix=@exec_prefix@
LOGDIR=@localstatedir@
CFGDIR=@sysconfdir@
BINDIR=@bindir@
LIBEXECDIR=@libexecdir@
LIBDIR=@libdir@
KOHANA=@KOHANA@
CGIDIR=@sbindir@
INSTALL=@INSTALL@
INSTALL_OPTS=@INSTALL_OPTS@
DATAROOTDIR=@datarootdir@

CP=@CP@
PERL=@PERL@

none:
	@echo "Please supply a command line argument (i.e. 'make all').  Other targets are:"
	@echo "   clean"
	@echo "   install install-init install-config install-processperfdata install-html fullinstall"
	@echo "   install-plugins"

all:
	cd $(SRC_BASE) && $(MAKE)
	cd $(SRC_SHARE) && $(MAKE)
	cd $(SRC_SCRIPTS) && $(MAKE)
	chmod a+r $(SRC_CONTRIB)/ssi/status-header.ssi

	@echo ""
	@echo "*** Compile finished ***"
	@echo ""
	@echo "  make install"
	@echo "     - This installs the main program and HTML files"
	@echo ""
	@echo "  make fullinstall"
	@echo "     - This installs the main program, runlevel scripts, config and HTML files"
	@echo ""
	@echo "Enjoy."
	@echo ""

scripts:
	cd $(SRC_SCRIPTS) && $(MAKE)

share:
	cd $(SRC_SHARE) && $(MAKE)

clean:
	cd $(SRC_BASE) && $(MAKE) $@
	cd $(SRC_MAN) && $(MAKE) $@
	cd $(SRC_SHARE) && $(MAKE) $@
	cd $(SRC_LIB) && $(MAKE) $@
	cd $(SRC_SCRIPTS) && $(MAKE) $@
	cd $(SRC_CONFIG) && $(MAKE) $@
	-rm -f *.cfg core
	-rm -f *~ *.*~ */*~ */*.*~
	-rm -f config.log config.status config.cache

distclean: 
	cd $(SRC_BASE) && $(MAKE) $@
	cd $(SRC_MAN) && $(MAKE) $@
	cd $(SRC_SHARE) && $(MAKE) $@
	cd $(SRC_LIB) && $(MAKE) $@
	cd $(SRC_SCRIPTS) && $(MAKE) $@
	cd $(SRC_CONFIG) && $(MAKE) $@
	-rm -f *.cfg core
	-rm -f *~ *.*~ */*~ */*.*~
	-rm -f config.log config.status config.cache
	rm -f Makefile include/stamp-h1 include/config.h config.status config.log
	rm -f subst summary
	rm -f $(SRC_CONTRIB)/ssi/status-header.ssi

devclean: distclean

install-html:
	cd $(SRC_SHARE) && $(MAKE) install

install-base:
	cd $(SRC_BASE) && $(MAKE) install

install-man:
	cd $(SRC_MAN) && $(MAKE) install

install-processperfdata:
	cd $(SRC_SCRIPTS) && $(MAKE) install

install-init:
	cd $(SRC_SCRIPTS) && $(MAKE) $@

install-config:
	cd $(SRC_CONFIG) && $(MAKE) $@

	@echo ""
	@echo "*** PNP4Nagios sample config files installed ***"
	@echo ""
	@echo "Please run 'make install-init' if you want to use"
	@echo "BULK Mode with NPCD"
	@echo ""
	@echo ""
	@echo ""

install-webconf:
	cd $(SRC_CONFIG) && $(MAKE) $@


	@echo ""
	@echo "*** Apache config file installed ***"
	@echo ""
	@echo "Restart your apache webserver to activete your changes."
	@echo ""
	@echo "Please run 'make install-config' to install sample"
	@echo "configuration files"
	@echo ""
	@echo "Please run 'make install-init' if you want to use"
	@echo "BULK Mode with NPCD"
	@echo ""
	@echo ""
	@echo ""

install-plugins:
	cd $(SRC_SCRIPTS) && $(MAKE) $@

install:
	cd $(SRC_BASE) && $(MAKE) $@
	cd $(SRC_MAN) && $(MAKE) $@
	cd $(SRC_SHARE) && $(MAKE) $@
	if [ x$(KOHANA) = xyes ]; then \
		cd $(SRC_LIB) && $(MAKE) $@; \
	fi

	cd $(SRC_SCRIPTS) && $(MAKE) $@
	cd $(SRC_CONFIG) && $(MAKE) $@

	@echo ""
	@echo "*** Main program, Scripts and HTML files installed ***"
	@echo ""
	@echo "Please run 'make install-webconf' to install the"
	@echo "web configuration file"
	@echo ""
	@echo "Please run 'make install-config' to install sample"
	@echo "configuration files"
	@echo ""
	@echo "Please run 'make install-init' if you want to use"
	@echo "BULK Mode with NPCD"
	@echo ""
	@echo ""
	@echo ""

install-unstripped:
	cd $(SRC_BASE) && $(MAKE) $@
	cd $(SRC_SHARE) && $(MAKE) $@
	cd $(SRC_SCRIPTS) && $(MAKE) $@
	$(MAKE) install-basic

fullinstall: install install-webconf install-config install-init

	$(PERL) summary fullinstall
	@echo ""
	@echo "*** Main program, Scripts and HTML files installed ***"
	@echo ""
	@echo "Enjoy."
	@echo ""

