# $Id: Makefile 861 2016-04-20 20:34:11Z kdeugau $
# IPDB makefile

PKGNAME=ipdb
VERSION=2.6
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 -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
INSTALLMODE= -m 0755
INSTALLMODE2 = -m 0555

DESTDIR =

HTML = \
	alloctypes.html help.html index.shtml ipdb.css rDNS.html

JS = templates/widgets.js

IMAGES = images/logo.png images/tree_closed.png images/tree_open.png

TEMPLATES = \
	templates/aclerror.tmpl templates/addmaster.tmpl templates/addvrf.tmpl templates/assign.tmpl \
	templates/confirm.tmpl templates/confmerge.tmpl templates/dberr.tmpl templates/delete.tmpl \
	templates/delvrf.tmpl templates/domerge.tmpl templates/dosplit.tmpl templates/dunno.tmpl \
	templates/edit.tmpl templates/finaldelete.tmpl templates/finaldelvrf.tmpl templates/footer.tmpl \
	templates/header.tmpl templates/index2.tmpl templates/index.tmpl templates/insert.tmpl \
	templates/listpool.tmpl templates/merge.tmpl templates/newcity.tmpl templates/newmaster.tmpl \
	templates/newnode.tmpl templates/newvrf.tmpl templates/nodesearch.tmpl templates/showsubs2.tmpl \
	templates/showsubs.tmpl templates/showvrf.tmpl templates/split.tmpl templates/subnet-calc.tmpl \
	templates/update.tmpl templates/utilbar.tmpl \
	\
	templates/admin/aclerr.tmpl templates/admin/addnotice.tmpl templates/admin/alloc.tmpl \
	templates/admin/alloctweak.tmpl templates/admin/confirm.tmpl templates/admin/dberr.tmpl \
	templates/admin/delnotice.tmpl templates/admin/deluser.tmpl templates/admin/dunno.tmpl \
	templates/admin/edcust.tmpl templates/admin/ednotice.tmpl templates/admin/emailnotice.tmpl \
	templates/admin/header.tmpl templates/admin/listcust.tmpl templates/admin/main.tmpl \
	templates/admin/newuser.tmpl templates/admin/showallocs.tmpl templates/admin/showpools.tmpl \
	templates/admin/showusers.tmpl templates/admin/touch.tmpl templates/admin/tweakpool.tmpl \
	templates/admin/updacl.tmpl templates/admin/updatepool.tmpl templates/admin/update.tmpl \
	templates/admin/updcust.tmpl templates/admin/updnotice.tmpl \
	\
	templates/search/compsearch.tmpl templates/search/sresults.tmpl

SCRIPTS = \
	cgi-bin/access-pwd-update.pl cgi-bin/allocate.pl cgi-bin/combineblocks.pl \
	cgi-bin/consistency-check.pl cgi-bin/db-update.pl cgi-bin/freespace.pl \
	\
	cgi-bin/admin.cgi cgi-bin/ipdb-rpc.cgi cgi-bin/main.cgi cgi-bin/newcity.cgi cgi-bin/newnode.cgi \
	cgi-bin/search.cgi cgi-bin/snCalc.cgi \
	\
	cgi-bin/extras/db2rwhois.pl

SQL = cgi-bin/ipdb.psql cgi-bin/ipdb-2.7-3.0.sql

MODULES = cgi-bin/IPDB.pm

CONFIGMODULES = cgi-bin/MyIPDB.pm cgi-bin/CustIDCK.pm

RWHOIS = \
	cgi-bin/extras/rwhois-net-skel.tar.gz cgi-bin/extras/rwhois-config \
	cgi-bin/extras/network.tmpl

DIRS = images templates cgi-bin cgi-bin/extras

MANIFEST = \
	$(HTML) \
	$(JS) \
	$(IMAGES) \
	$(TEMPLATES) \
	$(SCRIPTS) \
	$(SQL) \
	$(MODULES) \
	$(CONFIGMODULES) \
	$(RWHOIS)

all:
	# nullop

install:
	@for i in $(HTML) $(IMAGES) $(JS) $(TEMPLATES); do \
		$(INSTALL_DATA) -D $$i $(DESTDIR)${libdir}/ipdb-$(VERSION)/$$i ; \
	done
	# munge in necessary 'use lib ...' bits so scripts can find MyIPDB.pm...
	@for i in $(SCRIPTS) $(MODULES) $(RWHOIS); do \
		$(INSTALL_SCRIPT) -D $$i $(DESTDIR)${libdir}/ipdb-$(VERSION)/$$i ; \
		perl -pi -e 's|##uselib##|use lib "${sysconfdir}/ipdb-$(VERSION)/";|;' $(DESTDIR)${libdir}/ipdb-$(VERSION)/$$i ; \
	done
	$(INSTALL) -d $(DESTDIR)${sysconfdir}/ipdb-$(VERSION)/
	@for i in $(CONFIGMODULES) ; do \
		$(INSTALL_DATA) $$i $(DESTDIR)${sysconfdir}/ipdb-$(VERSION)/ ; \
	done
	# and now munge MyIPDB.pm so it can find the core library
	perl -pi -e 's|##uselib##|use lib "${libdir}/ipdb-$(VERSION)";|;' $(DESTDIR)${sysconfdir}/ipdb-$(VERSION)/MyIPDB.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)/g;s/#RELEASE#/$(RELEASE)/g;s/#BETA#//g' < $(PKGNAME).spec > $(PKGNAME)-$(VERSION)/$(PKGNAME).spec
	/usr/bin/perl -p -e 's/#VERSION#/$(VERSION)/g;s/#RELEASE#/$(RELEASE)/g;s/#BETA#//g' < INSTALL > $(PKGNAME)-$(VERSION)/INSTALL
	perl -pi -e 's/[\d.]+;\s*##VERSION##/"$(VERSION)";/;' $(PKGNAME)-$(VERSION)/cgi-bin/IPDB.pm
	tar cf $(PKGNAME)-$(VERSION).tar $(PKGNAME)-$(VERSION)
	gzip -v -f -9 $(PKGNAME)-$(VERSION).tar
	rm -rf $(PKGNAME)-$(VERSION)
	# gpg --detach-sign $(PKGNAME)-$(VERSION).tar.gz
