###################################
# Makefile for NSCA Solaris Package
#
# Last Modified: 6 Jan 2012
###################################

TARGET_OS=@TARGET_OS@
TARGET_VER=@TARGET_VER@
TARGET_ARCH=@TARGET_ARCH@
TARGET_PLATFORM=@TARGET_PLATFORM@

SOLARIS_CONFIG_OPTS=--prefix=/opt/nagios --sysconfdir=/etc/nagios

PKG_NAME=NGOSnsca
PKG_VERSION=@PKG_VERSION@
PKG_FILE=@PACKAGE_NAME@-$(PKG_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH)-local

TOPDIR=@top_builddir@
PKGDIR=@builddir@/pkg
SRCDIR=@builddir@/build/src
INSTALLDIR=@builddir@/install
ABSINSTALLDIR=@abs_builddir@/install

build:
	if [ ! -d build ] ; then mkdir build ; fi
	cd build; ../../../configure $(SOLARIS_CONFIG_OPTS); make all

prototype: $(PKGDIR)
	@echo "i pkginfo" > $(PKGDIR)/prototype
	@echo "i copyright=../$(TOPDIR)/LEGAL" >> $(PKGDIR)/prototype
	@echo "i preinstall" >> $(PKGDIR)/prototype
	@echo "i i.config" >> $(PKGDIR)/prototype
	@echo "i r.config" >> $(PKGDIR)/prototype
	@echo "d none /etc/nagios 0755 nagios nagios" >> $(PKGDIR)/prototype
	@echo "f config /etc/nagios/send_nsca.cfg=$(TOPDIR)/sample-config/send_nsca.cfg 0600 nagios nagios" >> $(PKGDIR)/prototype
	@echo "d none /opt/nagios/bin 0755 nagios bin" >> $(PKGDIR)/prototype
	@echo "f none /opt/nagios/bin/send_nsca=$(SRCDIR)/send_nsca 0755 nagios bin" >> $(PKGDIR)/prototype

pkginfo: $(PKGDIR)
	@echo PKG="$(PKG_NAME)" > $(PKGDIR)/pkginfo
	@echo NAME="Nagios Service Check Acceptor $(PKG_VERSION)" >> $(PKGDIR)/pkginfo
	@echo VERSION="$(PKG_VERSION)" >> $(PKGDIR)/pkginfo
	@echo ARCH="$(TARGET_ARCH)" >> $(PKGDIR)/pkginfo
	@echo CATEGORY="utility" >> $(PKGDIR)/pkginfo
	@echo CLASSES="none config manifest" >> $(PKGDIR)/pkginfo
	@echo VENDOR="www.nagios.org" >> $(PKGDIR)/pkginfo
	@echo EMAIL="nagios-users@lists.sourceforge.net" >> $(PKGDIR)/pkginfo
	@echo ISTATES="S s 1 2 3" >> $(PKGDIR)/pkginfo
	@echo RSTATES="S s 1 2 3" >> $(PKGDIR)/pkginfo
	@echo BASEDIR="/" >> $(PKGDIR)/pkginfo

$(PKG_FILE): pkginfo prototype
	pkgmk -o -d $(PKGDIR) -f $(PKGDIR)/prototype -r .
	pkgtrans ./pkg $(PKG_FILE) $(PKG_NAME)

pkg: $(PKG_FILE)

all: pkg

clean: 
	rm -rf build package
	rm -rf $(PKGDIR)/$(PKG_NAME)
	rm -f $(PKGDIR)/prototype $(PKGDIR)/pkginfo
	rm -f $(PKGDIR)/$(PKG_FILE)
	rm -f core
	rm -f *~ */*~

distclean: clean
	rm -f Makefile
	rm -f config.log

devclean: distclean

