# Xymon main Makefile
#
# This file is included from the Makefile created by the "configure" script



#####################
# Build targets
#####################

CFLAGS += -I$(BUILDTOPDIR)/include

ifeq ($(CLIENTONLY),yes)
	BUILDTARGETS = client
	CFLAGS += -DCLIENTONLY=1
	XYMONCLIENTHOME = $(XYMONTOPDIR)
	XYMONHOME = $(XYMONTOPDIR)
ifeq ($(LOCALCLIENT),yes)
	CLIENTTARGETS = lib-client common-client build-build xymond-client
	INSTALLTARGETS = install-client install-localclient install-clientmsg
	CFLAGS += -DLOCALCLIENT=1 $(PCREINCDIR)
else
	CLIENTTARGETS = lib-client common-client build-build
	INSTALLTARGETS = install-client install-clientmsg
endif
else
	BUILDTARGETS = lib-build common-build xymongen-build xymonnet-build xymonproxy-build docs-build build-build xymond-build web-build client
	CLIENTTARGETS = lib-client common-client build-build
	INSTALLTARGETS = install-xymongen install-xymonnet install-xymonproxy install-xymond install-web install-docs install-client install-servermsg
	CFLAGS += $(PCREINCDIR)
	XYMONCLIENTHOME = $(XYMONTOPDIR)/client
	XYMONHOME = $(XYMONTOPDIR)/server
endif

ifndef INSTALLBINDIR
INSTALLBINDIR = $(XYMONHOME)/bin
endif
ifndef INSTALLETCDIR
INSTALLETCDIR = $(XYMONHOME)/etc
endif
ifndef INSTALLEXTDIR
INSTALLEXTDIR = $(XYMONHOME)/ext
endif
ifndef INSTALLTMPDIR
INSTALLTMPDIR = $(XYMONHOME)/tmp
endif
ifndef INSTALLWEBDIR
INSTALLWEBDIR = $(XYMONHOME)/web
endif
ifndef INSTALLWWWDIR
INSTALLWWWDIR = $(XYMONHOME)/www
endif

ARESVER = 1.10.0
FPINGVER = 3.0

IDTOOL := $(shell if test `uname -s` = "SunOS"; then echo /usr/xpg4/bin/id; else echo id; fi)

ifdef RPATH
RPATHOPT := $(RPATH)$(shell echo $(RPATHVAL) | sed -e 's/ / $(RPATH)/g')
endif

all: include/config.h $(BUILDTARGETS)
	@echo ""
	@echo "Build complete."
	@echo ""
	@echo "#####################################################################"
	@echo "IMPORTANT: If upgrading from 4.2.x, see the docs/upgrade-to-430.txt"
	@echo "           file for instructions. You must run build/upgrade430.sh"
	@echo "           before installing the new version."
	@echo "#####################################################################"
	@echo ""
	@echo "Now run '${MAKE} install' as root"
	@echo ""

client: include/config.h $(CLIENTTARGETS)
	CC="$(CC)" CFLAGS="$(CFLAGS)" XYMONHOME="$(XYMONCLIENTHOME)" XYMONHOSTIP="$(XYMONHOSTIP)" LOCALCLIENT="$(LOCALCLIENT)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" LIBRTDEF="$(LIBRTDEF)" $(MAKE) -C client all

include/config.h:
	MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" $(BUILDTOPDIR)/build/genconfig.sh

build-build:
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONHOME="$(XYMONHOME)" $(MAKE) -C build all

lib-build: include/config.h
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" OSDEF="$(OSDEF)" RPATHOPT="$(RPATHOPT)" PCREINCDIR="$(PCREINCDIR)" ZLIBINCDIR="$(ZLIBINCDIR)" SSLFLAGS="$(SSLFLAGS)" SSLINCDIR="$(SSLINCDIR)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONHOME="$(XYMONHOME)" XYMONCLIENTHOME=$(XYMONCLIENTHOME) XYMONLOGDIR="$(XYMONLOGDIR)" XYMONHOSTNAME="$(XYMONHOSTNAME)" XYMONHOSTIP="$(XYMONHOSTIP)" XYMONHOSTOS="$(XYMONHOSTOS)" $(MAKE) -C lib all

lib-client:
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" OSDEF="$(OSDEF)" RPATHOPT="$(RPATHOPT)" PCREINCDIR="$(PCREINCDIR)" ZLIBINCDIR="$(ZLIBINCDIR)" SSLFLAGS="$(SSLFLAGS)" SSLINCDIR="$(SSLINCDIR)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONHOME="$(XYMONCLIENTHOME)" XYMONCLIENTHOME=$(XYMONCLIENTHOME) XYMONLOGDIR="$(XYMONLOGDIR)" XYMONHOSTNAME="$(XYMONHOSTNAME)" XYMONHOSTIP="$(XYMONHOSTIP)" XYMONHOSTOS="$(XYMONHOSTOS)" LOCALCLIENT="$(LOCALCLIENT)" $(MAKE) -C lib client

common-build: lib-build
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" SSLFLAGS="$(SSLFLAGS)" SSLINCDIR="$(SSLINCDIR)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)"  ZLIBLIBS="$(ZLIBLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONHOME="$(XYMONHOME)" $(MAKE) -C common all

common-client: lib-client
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" SSLFLAGS="$(SSLFLAGS)" SSLINCDIR="$(SSLINCDIR)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)"  ZLIBLIBS="$(ZLIBLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONHOME="$(XYMONCLIENTHOME)" $(MAKE) -C common client

xymongen-build: lib-build common-build
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" SSLFLAGS="$(SSLFLAGS)" SSLINCDIR="$(SSLINCDIR)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONHOME="$(XYMONHOME)" XYMONVAR="$(XYMONVAR)" HISTGRAPHDEF="$(HISTGRAPHDEF)" RUNTIMEDEFS="$(RUNTIMEDEFS)" PCREINCDIR="$(PCREINCDIR)" PCRELIBS="$(PCRELIBS)" ZLIBINCDIR="$(ZLIBINCDIR)" ZLIBLIBS="$(ZLIBLIBS)" $(MAKE) -C xymongen all


xymonnet-build: lib-build common-build
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" SSLFLAGS="$(SSLFLAGS)" SSLINCDIR="$(SSLINCDIR)" SSLLIBS="$(SSLLIBS)" DOLDAP="$(DOLDAP)" LDAPFLAGS="$(LDAPFLAGS)" LDAPINCDIR="$(LDAPINCDIR)" LDAPLIBS="$(LDAPLIBS)" DOSNMP="$(DOSNMP)" NETLIBS="$(NETLIBS)" XYMONHOME="$(XYMONHOME)" ARESVER="$(ARESVER)" FPINGVER="$(FPINGVER)" RUNTIMEDEFS="$(RUNTIMEDEFS)" PCREINCDIR="$(PCREINCDIR)" PCRELIBS="$(PCRELIBS)" SYSTEMCARES="$(SYSTEMCARES)" CARESINCDIR="$(CARESINCDIR)" CARESLIBS="$(CARESLIBS)" SQLITELIBS="$(SQLITELIBS)" ZLIBINCDIR="$(ZLIBINCDIR)" ZLIBLIBS="$(ZLIBLIBS)" LIBRTDEF="$(LIBRTDEF)" $(MAKE) -C xymonnet all

xymonproxy-build: lib-build common-build
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONHOME="$(XYMONHOME)" $(MAKE) -C xymonproxy all

xymond-build: lib-build build-build common-build 
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" DORRD="$(DORRD)" RRDDEF="$(RRDDEF)" RRDINCDIR="$(RRDINCDIR)" PCREINCDIR="$(PCREINCDIR)" SSLFLAGS="$(SSLFLAGS)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" RRDLIBS="$(RRDLIBS)" PCRELIBS="$(PCRELIBS)" SQLITELIBS="$(SQLITELIBS)" ZLIBINCDIR="$(ZLIBINCDIR)" ZLIBLIBS="$(ZLIBLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONHOME="$(XYMONHOME)" XYMONVAR="$(XYMONVAR)" XYMONLOGDIR="$(XYMONLOGDIR)" XYMONHOSTNAME="$(XYMONHOSTNAME)" XYMONHOSTIP="$(XYMONHOSTIP)" XYMONHOSTOS="$(XYMONHOSTOS)" XYMONUSER="$(XYMONUSER)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" XYMONHOSTURL="$(XYMONHOSTURL)" XYMONCGIURL="$(XYMONCGIURL)" SECUREXYMONCGIURL="$(SECUREXYMONCGIURL)" MAILPROGRAM="$(MAILPROGRAM)" RUNTIMEDEFS="$(RUNTIMEDEFS)" INSTALLWWWDIR="$(INSTALLWWWDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" FPING="$(FPING)" $(MAKE) -C xymond all

web-build: lib-build build-build common-build 
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" DORRD="$(DORRD)" RRDDEF="$(RRDDEF)" RRDINCDIR="$(RRDINCDIR)" PCREINCDIR="$(PCREINCDIR)" ZLIBINCDIR="$(ZLIBINCDIR)" ZLIBLIBS="$(ZLIBLIBS)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" RRDLIBS="$(RRDLIBS)" PCRELIBS="$(PCRELIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONHOME="$(XYMONHOME)" XYMONVAR="$(XYMONVAR)" XYMONLOGDIR="$(XYMONLOGDIR)" XYMONHOSTNAME="$(XYMONHOSTNAME)" XYMONHOSTIP="$(XYMONHOSTIP)" XYMONHOSTOS="$(XYMONHOSTOS)" XYMONUSER="$(XYMONUSER)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" XYMONHOSTURL="$(XYMONHOSTURL)" XYMONCGIURL="$(XYMONCGIURL)" SECUREXYMONCGIURL="$(SECUREXYMONCGIURL)" MAILPROGRAM="$(MAILPROGRAM)" RUNTIMEDEFS="$(RUNTIMEDEFS)" INSTALLWWWDIR="$(INSTALLWWWDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" $(MAKE) -C web all

xymond-client: lib-client build-build common-client 
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" LIBRTDEF="$(LIBRTDEF)" RRDDEF="$(RRDDEF)" RRDINCDIR="$(RRDINCDIR)" PCREINCDIR="$(PCREINCDIR)" NETLIBS="$(NETLIBS)" RRDLIBS="$(RRDLIBS)" PCRELIBS="$(PCRELIBS)" ZLIBINCDIR="$(ZLIBINCDIR)" ZLIBLIBS="$(ZLIBLIBS)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONHOME="$(XYMONHOME)" XYMONVAR="$(XYMONVAR)" XYMONLOGDIR="$(XYMONLOGDIR)" XYMONHOSTNAME="$(XYMONHOSTNAME)" XYMONHOSTIP="$(XYMONHOSTIP)" XYMONHOSTOS="$(XYMONHOSTOS)" XYMONUSER="$(XYMONUSER)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" XYMONHOSTURL="$(XYMONHOSTURL)" XYMONCGIURL="$(XYMONCGIURL)" SECUREXYMONCGIURL="$(SECUREXYMONCGIURL)" MAILPROGRAM="$(MAILPROGRAM)" RUNTIMEDEFS="$(RUNTIMEDEFS)" INSTALLWWWDIR="$(INSTALLWWWDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" $(MAKE) -C xymond client

docs-build:
	XYMONHOSTURL="$(XYMONHOSTURL)" $(MAKE) -C docs all

custom-build: lib-build
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" RRDDEF="$(RRDDEF)" RRDINCDIR="$(RRDINCDIR)" PCREINCDIR="$(PCREINCDIR)" NETLIBS="$(NETLIBS)" RRDLIBS="$(RRDLIBS)" PCRELIBS="$(PCRELIBS)" ZLIBINCDIR="$(ZLIBINCDIR)" ZLIBLIBS="$(ZLIBLIBS)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONHOME="$(XYMONHOME)" XYMONVAR="$(XYMONVAR)" XYMONLOGDIR="$(XYMONLOGDIR)" XYMONHOSTNAME="$(XYMONHOSTNAME)" XYMONHOSTIP="$(XYMONHOSTIP)" XYMONHOSTOS="$(XYMONHOSTOS)" XYMONUSER="$(XYMONUSER)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" XYMONHOSTURL="$(XYMONHOSTURL)" XYMONCGIURL="$(XYMONCGIURL)" SECUREXYMONCGIURL="$(SECUREXYMONCGIURL)" MAILPROGRAM="$(MAILPROGRAM)" RUNTIMEDEFS="$(RUNTIMEDEFS)" INSTALLWWWDIR="$(INSTALLWWWDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" $(MAKE) -C custom all || echo "Skipped custom modules"

demo-build:
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" NETLIBS="$(NETLIBS)" $(MAKE) -C demotool all


win32: include/config.h
	CC="$(CC)" CFLAGS="$(CFLAGS) -DXYMONWINCLIENT -DCLIENTONLY" LDFLAGS="$(LDFLAGS)" RPATHOPT="$(RPATHOPT)" SSLFLAGS="$(SSLFLAGS)" SSLINCDIR="$(SSLINCDIR)" SSLLIBS="$(SSLLIBS)" NETLIBS="$(NETLIBS)" LIBRTDEF="$(LIBRTDEF)" XYMONHOME="$(XYMONHOME)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONLOGDIR="$(XYMONLOGDIR)" XYMONHOSTNAME="$(XYMONHOSTNAME)" XYMONHOSTIP="$(XYMONHOSTIP)" XYMONHOSTOS="$(XYMONHOSTOS)" $(MAKE) -C common xymon.exe

#####################
# Cleanup targets
#####################
distclean: allclean
	rm -f Makefile
	rm -rf xymonnet/c-ares
	rm -rf debbuild rpmbuild

allclean: clean
	(cd xymonnet/c-ares 2>/dev/null && $(MAKE) clean) || true

clean:
	$(MAKE) -C build clean
	$(MAKE) -C lib clean
	$(MAKE) -C common clean
	$(MAKE) -C xymongen clean
	$(MAKE) DOSNMP="$(DOSNMP)" DOLDAP="$(DOLDAP)" -C xymonnet clean
	$(MAKE) -C xymonproxy clean
	$(MAKE) DORRD="$(DORRD)" -C xymond clean
	$(MAKE) DORRD="$(DORRD)" -C web clean
	$(MAKE) -C docs clean
	$(MAKE) -C client clean
#	$(MAKE) -C demotool clean
#	$(MAKE) -C custom clean || echo ""
	rm -f ./*~ include/config.h include/*~ debian/*~ rpm/*~ contrib/*~


####################
# Install targets
####################

install: $(INSTALLTARGETS)

install-servermsg:
	@echo ""
	@echo "Installation complete."
	@echo ""
	@echo "You must configure your webserver for the Xymon webpages and CGI-scripts."
	@echo "A sample Apache configuration is in ${XYMONHOME}/etc/xymon-apache.conf"
	@echo "If you have your Administration CGI scripts in a separate directory,"
	@echo "then you must also setup the password-file with the htpasswd command."
	@echo ""
	@echo "To start Xymon, as the $(XYMONUSER) user run '${XYMONHOME}/bin/xymon.sh start'"
	@echo "To view the Xymon webpages, go to http://${XYMONHOSTNAME}${XYMONHOSTURL}"

install-dirs:
	mkdir -p $(INSTALLROOT)$(XYMONHOME) $(INSTALLROOT)$(XYMONHOME)/download $(INSTALLROOT)$(XYMONVAR)
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONHOME) $(INSTALLROOT)$(XYMONHOME)/download $(INSTALLROOT)$(XYMONVAR)
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONHOME) $(INSTALLROOT)$(XYMONHOME)/download $(INSTALLROOT)$(XYMONVAR)
	chmod 755 $(INSTALLROOT)$(XYMONHOME) $(INSTALLROOT)$(XYMONHOME)/download $(INSTALLROOT)$(XYMONVAR)
endif

	mkdir -p $(INSTALLROOT)$(INSTALLBINDIR)
ifneq ($(INSTALLBINDIR),$(XYMONHOME)/bin)
	rm -f $(INSTALLROOT)$(XYMONHOME)/bin || true
	ln -s $(INSTALLBINDIR) $(INSTALLROOT)$(XYMONHOME)/bin || true
endif
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(INSTALLBINDIR)
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(INSTALLBINDIR)
	chmod 755 $(INSTALLROOT)$(INSTALLBINDIR)
endif

	mkdir -p $(INSTALLROOT)$(INSTALLETCDIR)
ifneq ($(INSTALLETCDIR),$(XYMONHOME)/etc)
	rm -f $(INSTALLROOT)$(XYMONHOME)/etc || true
	ln -s $(INSTALLETCDIR) $(INSTALLROOT)$(XYMONHOME)/etc || true
endif
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(INSTALLETCDIR)
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(INSTALLETCDIR)
	chmod 755 $(INSTALLROOT)$(INSTALLETCDIR)
endif

	mkdir -p $(INSTALLROOT)$(INSTALLEXTDIR)
ifneq ($(INSTALLEXTDIR),$(XYMONHOME)/ext)
	rm -f $(INSTALLROOT)$(XYMONHOME)/ext || true
	ln -s $(INSTALLEXTDIR) $(INSTALLROOT)$(XYMONHOME)/ext || true
endif
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(INSTALLEXTDIR)
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(INSTALLEXTDIR)
	chmod 755 $(INSTALLROOT)$(INSTALLEXTDIR)
endif

	mkdir -p $(INSTALLROOT)$(INSTALLTMPDIR)
ifneq ($(INSTALLTMPDIR),$(XYMONHOME)/tmp)
	rm -f $(INSTALLROOT)$(XYMONHOME)/tmp || true
	ln -s $(INSTALLTMPDIR) $(INSTALLROOT)$(XYMONHOME)/tmp || true
endif
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(INSTALLTMPDIR)
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(INSTALLTMPDIR)
	chmod 755 $(INSTALLROOT)$(INSTALLTMPDIR)
endif

	mkdir -p $(INSTALLROOT)$(INSTALLWEBDIR)
ifneq ($(INSTALLWEBDIR),$(XYMONHOME)/web)
	rm -f $(INSTALLROOT)$(XYMONHOME)/web || true
	ln -s $(INSTALLWEBDIR) $(INSTALLROOT)$(XYMONHOME)/web || true
endif
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(INSTALLWEBDIR)
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(INSTALLWEBDIR)
	chmod 755 $(INSTALLROOT)$(INSTALLWEBDIR)
endif

	mkdir -p $(INSTALLROOT)$(INSTALLWWWDIR) $(INSTALLROOT)$(INSTALLWWWDIR)/gifs $(INSTALLROOT)$(INSTALLWWWDIR)/help $(INSTALLROOT)$(INSTALLWWWDIR)/html $(INSTALLROOT)$(INSTALLWWWDIR)/menu $(INSTALLROOT)$(INSTALLWWWDIR)/notes $(INSTALLROOT)$(INSTALLWWWDIR)/rep $(INSTALLROOT)$(INSTALLWWWDIR)/snap $(INSTALLROOT)$(INSTALLWWWDIR)/wml
ifneq ($(INSTALLWWWDIR),$(XYMONHOME)/www)
	rm -f $(INSTALLROOT)$(XYMONHOME)/www || true
	ln -s $(INSTALLWWWDIR) $(INSTALLROOT)$(XYMONHOME)/www || true
endif
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(INSTALLWWWDIR) $(INSTALLROOT)$(INSTALLWWWDIR)/gifs $(INSTALLROOT)$(INSTALLWWWDIR)/help $(INSTALLROOT)$(INSTALLWWWDIR)/html $(INSTALLROOT)$(INSTALLWWWDIR)/menu $(INSTALLROOT)$(INSTALLWWWDIR)/notes $(INSTALLROOT)$(INSTALLWWWDIR)/rep $(INSTALLROOT)$(INSTALLWWWDIR)/snap $(INSTALLROOT)$(INSTALLWWWDIR)/wml
	chgrp `$(IDTOOL) -g $(XYMONUSER)`  $(INSTALLROOT)$(INSTALLWWWDIR) $(INSTALLROOT)$(INSTALLWWWDIR)/gifs $(INSTALLROOT)$(INSTALLWWWDIR)/help $(INSTALLROOT)$(INSTALLWWWDIR)/html $(INSTALLROOT)$(INSTALLWWWDIR)/menu $(INSTALLROOT)$(INSTALLWWWDIR)/notes $(INSTALLROOT)$(INSTALLWWWDIR)/rep $(INSTALLROOT)$(INSTALLWWWDIR)/snap $(INSTALLROOT)$(INSTALLWWWDIR)/wml
	chmod 755  $(INSTALLROOT)$(INSTALLWWWDIR) $(INSTALLROOT)$(INSTALLWWWDIR)/gifs $(INSTALLROOT)$(INSTALLWWWDIR)/help $(INSTALLROOT)$(INSTALLWWWDIR)/html $(INSTALLROOT)$(INSTALLWWWDIR)/menu $(INSTALLROOT)$(INSTALLWWWDIR)/notes $(INSTALLROOT)$(INSTALLWWWDIR)/rep $(INSTALLROOT)$(INSTALLWWWDIR)/snap $(INSTALLROOT)$(INSTALLWWWDIR)/wml
ifdef HTTPDGID
# The www/rep and www/snap directories must be writable by the apache daemon
	chgrp $(HTTPDGID) $(INSTALLROOT)$(INSTALLWWWDIR)/rep $(INSTALLROOT)$(INSTALLWWWDIR)/snap
endif
	chmod g+w $(INSTALLROOT)$(INSTALLWWWDIR)/rep $(INSTALLROOT)$(INSTALLWWWDIR)/snap
endif

	mkdir -p $(INSTALLROOT)$(XYMONVAR)/acks
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONVAR)/acks
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONVAR)/acks
	chmod 755 $(INSTALLROOT)$(XYMONVAR)/acks
endif

	mkdir -p $(INSTALLROOT)$(XYMONVAR)/data
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONVAR)/data
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONVAR)/data
	chmod 755 $(INSTALLROOT)$(XYMONVAR)/data
endif

	mkdir -p $(INSTALLROOT)$(XYMONVAR)/disabled
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONVAR)/disabled
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONVAR)/disabled
	chmod 755 $(INSTALLROOT)$(XYMONVAR)/disabled
endif

	mkdir -p $(INSTALLROOT)$(XYMONVAR)/hist
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONVAR)/hist
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONVAR)/hist
	chmod 755 $(INSTALLROOT)$(XYMONVAR)/hist
endif

	mkdir -p $(INSTALLROOT)$(XYMONVAR)/histlogs
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONVAR)/histlogs || echo "Warning: Could not set owner on the histlogs directory"
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONVAR)/histlogs || echo "Warning: Could not set group on the histlogs directory"
	chmod 755 $(INSTALLROOT)$(XYMONVAR)/histlogs
endif

	mkdir -p $(INSTALLROOT)$(XYMONVAR)/hostdata
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONVAR)/hostdata || echo "Warning: Could not set owner on the hostdata directory"
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONVAR)/hostdata || echo "Warning: Could not set group on the hostdata directory"
	chmod 755 $(INSTALLROOT)$(XYMONVAR)/hostdata
endif

	mkdir -p $(INSTALLROOT)$(XYMONVAR)/logs
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONVAR)/logs
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONVAR)/logs
	chmod 755 $(INSTALLROOT)$(XYMONVAR)/logs
endif

	mkdir -p $(INSTALLROOT)$(XYMONVAR)/rrd
ifndef PKGBUILD
	chown $(XYMONUSER) $(INSTALLROOT)$(XYMONVAR)/rrd
	chgrp `$(IDTOOL) -g $(XYMONUSER)` $(INSTALLROOT)$(XYMONVAR)/rrd
	chmod 755 $(INSTALLROOT)$(XYMONVAR)/rrd
endif

install-common: install-dirs
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" $(MAKE) -C common install

install-xymongen: install-common
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" $(MAKE) -C xymongen install

install-xymongen-nocgi: install-common
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" $(MAKE) -C xymongen install-nocgi

install-xymonnet: install-common
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" ARESVER="$(ARESVER)" FPINGVER="$(FPINGVER)" DOSNMP="$(DOSNMP)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" PKGBUILD="$(PKGBUILD)" $(MAKE) -C xymonnet install

install-xymonproxy: install-common
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" $(MAKE) -C xymonproxy install

install-xymond: install-common
	DORRD="$(DORRD)" MANROOT="$(MANROOT)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONHOME="$(XYMONHOME)" XYMONVAR="$(XYMONVAR)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" XYMONLOGDIR="$(XYMONLOGDIR)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" HTTPDGID="$(HTTPDGID)" $(MAKE) -C xymond install

install-web: install-common
	DORRD="$(DORRD)" MANROOT="$(MANROOT)" XYMONTOPDIR="$(XYMONTOPDIR)" XYMONHOME="$(XYMONHOME)" XYMONVAR="$(XYMONVAR)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" XYMONLOGDIR="$(XYMONLOGDIR)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" $(MAKE) -C web install
	find $(INSTALLROOT)$(INSTALLWWWDIR) -type f -exec chmod 644 {} \;


# NOTE: This one is normally not used - man-page install is done by the sub-Makefiles during "make install"
install-man:
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" INSTALLROOT="$(INSTALLROOT)" $(MAKE) -C common install-man
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" CGIDIR="$(CGIDIR)" SECURECGIDIR="$(SECURECGIDIR)" INSTALLROOT="$(INSTALLROOT)" $(MAKE) -C xymongen install-man
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" INSTALLROOT="$(INSTALLROOT)" $(MAKE) -C xymonnet install-man
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" INSTALLROOT="$(INSTALLROOT)" $(MAKE) -C xymonproxy install-man
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" INSTALLROOT="$(INSTALLROOT)" $(MAKE) -C xymond install-man
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" INSTALLROOT="$(INSTALLROOT)" $(MAKE) -C web install-man
	find $(INSTALLROOT)$(MANROOT) -type f -exec chmod 644 {} \;

install-docs:
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" $(MAKE) -C docs install

install-custom:
	XYMONHOME="$(XYMONHOME)" MANROOT="$(MANROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" INSTALLROOT="$(INSTALLROOT)" INSTALLBINDIR="$(INSTALLBINDIR)" INSTALLETCDIR="$(INSTALLETCDIR)" INSTALLEXTDIR="$(INSTALLEXTDIR)" INSTALLTMPDIR="$(INSTALLTMPDIR)" INSTALLWEBDIR="$(INSTALLWEBDIR)" INSTALLWWWDIR="$(INSTALLWWWDIR)" $(MAKE) -C custom install || echo "Skipped custom modules"


client-install: install-client

install-client: client
	XYMONHOME="$(XYMONCLIENTHOME)" INSTALLROOT="$(INSTALLROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" PKGBUILD="$(PKGBUILD)" LOCALCLIENT="$(LOCALCLIENT)" $(MAKE) -C client install

install-clientmsg:
	@echo ""
	@echo "Installation complete."
	@echo ""
	@echo "To start the Xymon client, as the $(XYMONUSER) user run '${XYMONHOME}/runclient.sh start'"

install-localclient:
	XYMONHOME="$(XYMONCLIENTHOME)" INSTALLROOT="$(INSTALLROOT)" XYMONUSER="$(XYMONUSER)" IDTOOL="$(IDTOOL)" LOCALCLIENT="$(LOCALCLIENT)" $(MAKE) -C client install-localclient

