#<: 'Makefile' v0.010 @ 2012-10-07 00:19:05 UTC (Jonas@Ubbe-III) "Jonas Eckerman" <jonas@truls.org> :>#

# What the DNS?
# make utilities

SRCS=$(wildcard wtdns*.pl)
CMDS=$(SRCS:.pl=)

BIN=wtdnsinfo wtdnsadd wtdns-deepen wtdns-flatten
SBIN=wtdns-fromlog wtdns-maintain

MODS=Config::IniHash Data::Validate::IP Date::Format Date::Parse File::Path File::Temp Sys::Syslog Text::CSV Time::Duration::Parse Unix::SetUser URL::Encode Net::DNS::Resolver Linux::Smaps Net::DNS::SEC MIME::Base64
DEBS=libconfig-inihash-perl libdata-validate-ip-perl libtimedate-perl libfile-path-perl libsys-syslog-perl libtext-csv-perl libtext-csv-xs-perl libtime-duration-parse-perl libnet-dns-perl libnet-dns-sec-perl

IFO=-p -m u=rwx,go=rx,a-s

default: all

all: $(CMDS)

.SUFFIXES:
.SUFFIXES: .pl

.pl: $(SRCS)
	sed -e /^require\ \[\'\"\]config\.pl\[\'\"\]\;$$/r\ config.pl "$<" | \
	sed -e /^require\ \[\'\"\]update\.pl\[\'\"\]\;$$/r\ update.pl | \
	sed -e /^require\ \[\'\"\]dnssec\.pl\[\'\"\]\;$$/r\ dnssec.pl | \
	sed -e /^require\ \[\'\"\]control\.pl\[\'\"\]\;$$/r\ control.pl | \
	sed -e /^require\ \[\'\"\]logging\.pl\[\'\"\]\;$$/r\ logging.pl | \
	sed -e /^require\ \[\'\"\]usergroup\.pl\[\'\"\]\;$$/r\ usergroup.pl | \
	sed -e s/^\\\(require\ \[\'\"\][-_a-z]\*\.pl\[\'\"\]\;\\\)$$/#\\1/m > "$*"
	chmod a+x "$*"

clean:
	set -e; \
	for p in *.pl; do \
	  f=`echo $$p | sed -e s/\.pl$$//`; \
	  rm -f $$f; \
	done

distclean: clean
	rm -f wtdns-scratch.pl

preinstall:
	set -e; \
	nm=; \
	for m in $(MODS); do \
	  if ! perl -m$$m -e "" > /dev/null 2>&1; then nm="$$nm$$m\\n"; fi; \
	done; \
	if [ -n "$$nm" ]; then \
	  echo "\\n\\n==============================================================================\\n"; \
	  echo "You need to install the following perl modules:\\n\\n$$nm"; \
	  if which dpkg > /dev/null; then \
	    np=; \
	    for m in $(DEBS); do \
	      if ! dpkg -s $$m > /dev/null 2>&1; then np="$$np$$m\\n"; fi; \
	    done; \
	    if [ -n "$$np" ]; then echo "If you are using a Debian based system it might be possible to install some of\\nthem by installing the following packages:\\n\\n$$np"; fi; \
	  fi; \
	  exit 1; \
	fi

postinstall:

prepackage:

postpackage:

install: preinstall
	set -e; for f in $(SBIN); do install $(IFO) $$f /usr/sbin/$$f; done
	set -e; for f in $(BIN); do install $(IFO) $$f /usr/bin/$$f; done
