# $Id: Makefile 434 2012-10-23 22:03:11Z kdeugau $
# DNS Admin makefile

PKGNAME=dnsadmin
VERSION=1.0.4
RELEASE=1

# Include some boilerplate Gnu makefile definitions.
prefix = /usr/local

exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
libdir = ${exec_prefix}/lib
infodir = ${prefix}/info
includedir = ${prefix}/include
datadir = ${prefix}/share
localedir = $(datadir)/locale
sysconfdir = ${prefix}/etc
mandir = ${prefix}/man

INSTALL = /usr/bin/install
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
INSTALLMODE= -m 0755
INSTALLMODE2 = -m 0555

DESTDIR =

# flag to indicate if we install in a version-numbered location to
# support parallel installs (packaged or otherwise) or if we're
# installing to .../dnsdb/ (overwrite whatever was there last)
PARA_VERSIONS = 0

# also set the leaf directories we'll be putting things in
PKG_LEAF = dnsdb
CFG_LEAF = dnsdb

# tweak the final leaf directories we install to if PARA_VERSIONS is set
ifeq "$(PARA_VERSIONS)" "1"
PKG_LEAF = dnsdb-$(VERSION)
CFG_LEAF = dnsdb/$(VERSION)
endif

MANIFEST = \
	INSTALL COPYING TODO Makefile dnsadmin.spec \
	\
	new-dns.sql dns.sql dns.cgi dns-rpc.cgi textrecs.cgi DNSDB.pm vega-import.pl export.pl \
	\
	index.shtml \
	\
	images/trash2.png images/fwd.png images/ffwd.png images/frev.png \
	images/rev.png images/DESC.png images/ASC.png images/tree_open.png images/tree_closed.png \
	\
	templates/adddomain.tmpl templates/addgroup.tmpl templates/addrec.tmpl templates/adduser.tmpl \
	templates/axfr.tmpl templates/bulkchange.tmpl templates/bulkdomain.tmpl templates/dberr.tmpl \
	templates/deldom.tmpl templates/delgrp.tmpl templates/delrec.tmpl templates/deluser.tmpl \
	templates/dns.css templates/dnsq.tmpl templates/domlist.tmpl templates/edgroup.tmpl \
	templates/editsoa.tmpl templates/footer.tmpl templates/fpnla.tmpl templates/grouptree.css \
	templates/grouptree-ie.css templates/grpman.tmpl templates/grptree.tmpl templates/header.tmpl \
	templates/lettsearch.tmpl templates/login.tmpl templates/log.tmpl templates/menu.tmpl \
	templates/newdomain.tmpl templates/newgrp.tmpl templates/permlist_enabled.tmpl templates/permlist.tmpl \
	templates/pgcount.tmpl templates/reclist.tmpl templates/record.tmpl templates/sbox.tmpl \
	templates/soadata.tmpl templates/template.tmpl templates/textrecs.tmpl templates/updatesoa.tmpl \
	templates/useradmin.tmpl templates/user.tmpl templates/whoisq.tmpl \
	\
	dnsdb.conf

DIRS = \
	images templates

IMAGES = \
	images/trash2.png images/fwd.png images/ffwd.png images/frev.png \
	images/rev.png images/DESC.png images/ASC.png

SCRIPTS = \
	dns.cgi dns-rpc.cgi textrecs.cgi vega-import.pl export.pl

MODULES = DNSDB.pm

TEMPLATES = \
	templates/adddomain.tmpl templates/addgroup.tmpl templates/addrec.tmpl templates/adduser.tmpl \
	templates/axfr.tmpl templates/bulkchange.tmpl templates/bulkdomain.tmpl templates/dberr.tmpl \
	templates/deldom.tmpl templates/delgrp.tmpl templates/delrec.tmpl templates/deluser.tmpl \
	templates/dns.css templates/dnsq.tmpl templates/domlist.tmpl templates/edgroup.tmpl \
	templates/editsoa.tmpl templates/footer.tmpl templates/fpnla.tmpl templates/grouptree.css \
	templates/grouptree-ie.css templates/grpman.tmpl templates/grptree.tmpl templates/header.tmpl \
	templates/lettsearch.tmpl templates/login.tmpl templates/log.tmpl templates/menu.tmpl \
	templates/newdomain.tmpl templates/newgrp.tmpl templates/permlist_enabled.tmpl templates/permlist.tmpl \
	templates/pgcount.tmpl templates/reclist.tmpl templates/record.tmpl templates/sbox.tmpl \
	templates/soadata.tmpl templates/template.tmpl templates/textrecs.tmpl templates/updatesoa.tmpl \
	templates/useradmin.tmpl templates/user.tmpl templates/whoisq.tmpl

CONFIGFILES = dnsdb.conf

all:
	# nullop

install:
	@mkdir -p $(DESTDIR)${datadir}/$(PKG_LEAF)/images
	@$(INSTALL_DATA) $(IMAGES) $(DESTDIR)${datadir}/$(PKG_LEAF)/images
	@mkdir -p $(DESTDIR)${datadir}/$(PKG_LEAF)/templates
	@$(INSTALL_DATA) $(TEMPLATES) $(DESTDIR)${datadir}/$(PKG_LEAF)/templates
	@# munge in necessary 'use lib ...' bits so scripts can find libs and config...
	@# datadir is correct;  no arch-specific files
	@for i in $(SCRIPTS) $(MODULES); do \
		$(INSTALL_SCRIPT) -D $$i $(DESTDIR)${datadir}/$(PKG_LEAF)/$$i ; \
		perl -pi -e 's|use lib '.';	##uselib##|use lib "${datadir}/$(PKG_LEAF)/";|;' $(DESTDIR)${datadir}/$(PKG_LEAF)/$$i ; \
		perl -pi -e 's|use lib '.';	##uselib##|use lib "${datadir}/$(PKG_LEAF)/";|;' $(DESTDIR)${datadir}/$(PKG_LEAF)/$$i ; \
	done
	@$(INSTALL) -d $(DESTDIR)${sysconfdir}/$(CFG_LEAF)/
	@# install an example config file with all known settings
	@for i in $(CONFIGFILES) ; do \
		if [ -e $(DESTDIR)${sysconfdir}/$(CFG_LEAF)/$$i ]; then \
			echo "refusing to overwrite existing config file, created as $$i.new" ; \
			$(INSTALL_DATA) $$i $(DESTDIR)${sysconfdir}/$(CFG_LEAF)/$$i.new ; \
		else \
			$(INSTALL_DATA) $$i $(DESTDIR)${sysconfdir}/$(CFG_LEAF)/ ; \
		fi ; \
		perl -pi -e 's|"/etc/dnsdb";	##CFG_LEAF##|"${sysconfdir}/$(CFG_LEAF)";|;' $(DESTDIR)${datadir}/$(PKG_LEAF)/DNSDB.pm ; \
	done
#	# and now munge MyDNSDB.pm so it can find the core library
#	perl -pi -e 's|##uselib##|use lib "${libdir}/dnsdb";|;' $(DESTDIR)${sysconfdir}/dnsdb/MyDNSDB.pm

#clean:
#	@for i in $(DIRS) ; do \
#		$(MAKE) -C $$i clean ; \
#	done

dist:
	mkdir $(PKGNAME)-$(VERSION)
	tar cf - $(MANIFEST) | (cd $(PKGNAME)-$(VERSION); tar xf -)
	/usr/bin/perl -p -e 's/#VERSION#/$(VERSION)/;s/#RELEASE#/$(RELEASE)/;s/#BETA#//g' < $(PKGNAME).spec > $(PKGNAME)-$(VERSION)/$(PKGNAME).spec
	/usr/bin/perl -p -e 's/#VERSION#/$(VERSION)/;s/#RELEASE#/$(RELEASE)/;s/#BETA#//g' < INSTALL > $(PKGNAME)-$(VERSION)/INSTALL
	perl -pi -e 's/["\d.]+;\s*##VERSION##/"$(VERSION)";/;' $(PKGNAME)-$(VERSION)/DNSDB.pm
	tar cf $(PKGNAME)-$(VERSION).tar $(PKGNAME)-$(VERSION)
	gzip -v -f -9 $(PKGNAME)-$(VERSION).tar
	rm -rf $(PKGNAME)-$(VERSION)
	gpg -a --detach-sign $(PKGNAME)-$(VERSION).tar.gz
