#
# Makefile for Domtools
#
# by Paul Balyoz
#
# Useful targets:   all  install  clean
# See README for usage.
#
VERSION=1.4.0
# (don't change the version number)
#
# NOTES
#	Domtools consist of many programs and lib files with simple
#	names (which may conflict with other stuff on your system).
#	That's why I usually put them in their own sub-directory
#	named "domtools" within bin and lib dirs.  That way
#	anyone who wants to use these tools can add the new bin
#	directory to their path.
#

# Physical Installation Hierarchy - root of tree where Makefile should
# write files to.  For AFS use your "dot" path (writable branch).
PDEST=/usr/local
#PDEST=/afs/.site.dom.ain/sun4/usr/local
#PDEST=/home/pab
#PDEST=/oper/oper2/pbalyoz

# Logical Installation Hierarchy - paths that shell scripts should use
# when referring to lib files & programs from this package.
# Usually this is the same as PDEST, unless you're installing into AFS.
LDEST=$(PDEST)
#LDEST=/afs/site.dom.ain/sun4/usr/local

# Binary sub-directory under $LDEST where executables should go.
# This directory is created, below, if it doesn't exist.
#	"bin" will put it in $LDEST/bin.
#	"bin/domtools" (my favorite) puts it in $LDEST/bin/domtools.
DOMBIN=bin/domtools
#DOMBIN=bin

# Library sub-directory under $LDEST where other files such as awk scripts should go.
# This directory is created, below, if it doesn't exist.
DOMLIB=lib/domtools

# Do you want a world-writable Zone Cache directory, or not?
# Good points: speeds up the axfr tool substantially.
# Bad points: anyone can store files in there to get around their disk quota;
#             zone cache directory always grows (not automatically cleaned out).
# Uncomment exactly 1 of these lines:
ZONECACHEWANTED=1		# yes we want a zone cache
#ZONECACHEWANTED=0		# no we don't want a zone cache

# Path to the zone cache directory (ignored if $ZONECACHEWANTED is 0).
# This will have $(PDEST) or $(LDEST) prepended to it at the proper times,
# so it always ends up below the lib directory someplace.
ZONEDIR=$(DOMLIB)/zonecache

# The subdomain at your site/domain which contains nothing but TXT records
# for every network name at your site/domain.  These TXT records can be
# created to describe each network or keep track of important location
# information: building, room, department, whatever you want.
# They are used by the -x option to networktbl and netmasktbl.  The info in
# these TXT records is written as comment lines above each entry in their
# output files.  For example, the resource record:
#
#    csenet.networks.nau.edu. IN TXT "Computer Science Engineering, bldg 69, floor 1"
#
# would produce a comment line above the network entry:
#
#	  # Computer Science Engineering, bldg 69, floor 1
#	  134.114.64 csenet
#
# The comment line, above, might have come from a TXT record in domain.nau.edu.
# It makes the /etc/network and /etc/netmask files they generate much clearer.
# The domain below _must_ have an ending period on it.
# This is not an Internet standard of any sort; it's just a useful trick
# used in Northern Arizona University's Computer Science department,
# and you can use it too.
#
# This feature is optional; set NETWORKSDOM to nothing to disable it.
#
#NETWORKSDOM=networks.nau.edu.		# just an example!  change before using!
NETWORKSDOM=

# Number of levels of host aliases that should be generated by hosttbl when
# outputting /etc/host table data, by default (can be overridden on command line).
# Example values:       0   =>   1.2.3.4 host.cse.nau.edu
#                       1   =>   1.2.3.4 host.cse.nau.edu  host
#                       2   =>   1.2.3.4 host.cse.nau.edu  host host.cse
# You can use any number in the range 0..N where N is the minimum.
#
ALIASLEVELS=2

# If you're installing this systemwide as the root user, specify "chown".
# If you're installing this as a normal user, specify the "true" program instead.
# Uncomment exactly 1 of the following lines:
CHOWN=chown		# yes we are root and can run "chown".
#CHOWN=true		# no we aren't root and can't run "chown".

# Owner for installing Domtools directories and files.
# (if CHOWN=true, above, then OWNER is ignored)
OWNER= root
#OWNER= pab

# Group for installing Domtools directories and files.
GROUP= bin
#GROUP= staff
#GROUP= oper
#GROUP= user
#GROUP= users

# "change ownership" options to the install program.
# Uncomment only 1 of the following 2 lines:
# Use the first line if installing as the root user, second line if not.
CHOWNOPT = -o $(OWNER)
#CHOWNOPT =

# BSD-style installation command that creates missing parent dirs with "-d dir".
# You specify use Gnu Install here if you have it.
# First line is for BSD or SunOS; second is for SysV like Solaris 2.
INSTALL=install
#INSTALL=/usr/ucb/install
#INSTALL=/usr/local/gnu/bin/install
#INSTALL=/stor/gnu/aix/bin/install
#INSTALL=ginstall

# Where is your Perl executable located?  /usr/bin/perl is _supposed_ to work,
# but some sites still don't have it there.
PERLPROG=/usr/bin/perl
#PERLPROG=/usr/local/bin/perl
#PERLPROG=/usr/intel/bin/perl

# Which Bourne-shell should Bourne-shell shell scripts use?
# You'd think /bin/sh works everywhere, wouldn't you.
# BSDI (at least thru version 2.1) have a bug in /bin/sh.  Test it out:
#		true; `false`; echo $?
# The correct answer is any non-zero number (false), but BSDI returns 0 (true)!
# BSDI's ksh and bash do the right thing though, as does /bin/sh, ksh, and bash on
# every other platform I've tried (AIX 3.2.x, AIX 4.1.x, HP/UX 9.x, HP/UX 10.x,
# SunOS 4.1.x, Solaris 2.x, Linux, NCR SVR4).
# Use /bin/sh here, unless your /bin/sh returned true to the commands above.
BOURNESHELL=/bin/sh
#BOURNESHELL=/bin/bash		# BSDI needs this one!

# A few scripts need the Gnu version of awk (gawk) because they
# pass arguments into the awk scripts using the -v option.
# Some newer operating systems like BSDI have gawk installed as "awk".
# Regardless of the name, it _must_ be a gnu-based awk.
# If you don't have gawk, get it and install it; or hosttbl,networktbl,netmasktbl
# tools won't work right.  Gawk is much better than awk or nawk anyway.
GAWKPROG=gawk			# many systems
#GAWKPROG=awk			# BSDI, Linux
#GAWKPROG=/usr/local/bin/awk

#---------------------------------------------------------------------------------------
#   END OF CONFIGURABLE PARAMETERS!
#---------------------------------------------------------------------------------------

# Shell and perl scripts:
SHS=	address addr2net addr2mask axfr basedomain check1101 domsort f2iaddr hinfo \
	hosts hosttbl i2faddr ipsort isequal issubdom makestatic \
	netkillzeros netmask network netname netwithzeros nsap \
	ns nsroot ptr root soa subdom subdom2 subzone txt type zone any wks \
	mx networktbl netmasktbl uinfo cachebuild localad localdom subnetmask \
	siteinfo cname rndarg soalist digparse gensubnetlist

# Items for lib directory:
LIBS=	basedomain.awk domsort.awk f2iaddr.awk hosttbl.awk \
	i2faddr.awk ipsort.awk netkillzeros.awk \
	netwithzeros.awk subdom.awk subzone.awk type.awk \
	hosttbl.footer hosttbl.header networktbl.footer networktbl.header \
	networktbl.awk netmasktbl.footer netmasktbl.header netmasktbl.awk \
	hosttbl.perl

# Document files for lib directory:
DOCS=	README MANUAL HOWTOUSE COPYRIGHT

#-------

# Sed input file for replacing macro strings with full pathnames
# in the various programs during installation.
# See below for the set of macro replacements.
MACRO=macros.sed

#-------

all:
		@echo 'nothing to make, try "make install".'

#-------

$(MACRO):	Makefile
		-rm -f $(MACRO)
		echo "s,VERSION,$(VERSION),g" >> $(MACRO)
		echo "s,DOMBIN,$(LDEST)/$(DOMBIN),g" >> $(MACRO)
		echo "s,DOMLIB,$(LDEST)/$(DOMLIB),g" >> $(MACRO)
		echo "s,ZONEDIR,$(LDEST)/$(ZONEDIR),g" >> $(MACRO)
		echo "s,ZONECACHEWANTED,$(ZONECACHEWANTED),g" >> $(MACRO)
		echo "s,PERLPROG,$(PERLPROG),g" >> $(MACRO)
		echo "s,NETWORKSDOM,$(NETWORKSDOM),g" >> $(MACRO)
		echo "s,ALIASLEVELS,$(ALIASLEVELS),g" >> $(MACRO)
		echo "s,BOURNESHELL,$(BOURNESHELL),g" >> $(MACRO)
		echo "s,GAWKPROG,$(GAWKPROG),g" >> $(MACRO)

#-------

# Install all tools and related files systemwide.

install:	install-bins install-libs

install-bins:	$(SHS) $(MACRO) delete-old-bins
		$(INSTALL) -m 755 $(CHOWNOPT) -g $(GROUP) -d $(PDEST)/$(DOMBIN)
		for i in $(SHS); do \
			sed -f $(MACRO) < $$i > xxxtool; \
			$(INSTALL) -c -m 755 $(CHOWNOPT) -g $(GROUP) xxxtool $(PDEST)/$(DOMBIN)/$$i; \
		done
		-rm -f xxxtool
		-rm -f $(PDEST)/$(DOMBIN)/gw > /dev/null 2>&1
		-ln -s netname $(PDEST)/${DOMBIN}/gw

delete-old-bins:
		-rm -f $(PDEST)/$(DOMBIN)/ad > /dev/null 2>&1

install-libs:	$(LIBS) $(DOCS) $(MACRO) delete-old-libs
		$(INSTALL) -m 755 $(CHOWNOPT) -g $(GROUP) -d $(PDEST)/$(DOMLIB)
		# Don't panic; ZONEDIR (zonecache directory) must be writable by everyone.
		# (If you don't want this, set ZONECACHEWANTED to 0, above).
		# If directory doesn't exist, create it, otherwise erase all files out of it.
		# (Very important for BIND 8 users, because zone file format changed)
		# No, we don't want the sticky (text) bit set on this directory.
		-if test $(ZONECACHEWANTED) -eq 1; then \
			$(INSTALL) -m 777 $(CHOWNOPT) -g $(GROUP) -d $(PDEST)/$(ZONEDIR); \
			rm -f $(PDEST)/$(ZONEDIR)/* > /dev/null 2>&1; \
		fi
		for i in $(LIBS); do \
			sed -f $(MACRO) < $$i > xxxtool; \
			$(INSTALL) -c -m 644 $(CHOWNOPT) -g $(GROUP) xxxtool $(PDEST)/$(DOMLIB)/$$i; \
		done
		-rm -f xxxtool
		for i in $(DOCS); do \
			$(INSTALL) -c -m 644 $(CHOWNOPT) -g $(GROUP) $$i $(PDEST)/$(DOMLIB)/$$i; \
		done

delete-old-libs:
		-rm -f $(PDEST)/$(DOMLIB)/digout.awk > /dev/null 2>&1
		-rm -f $(PDEST)/$(DOMLIB)/digoutany.awk > /dev/null 2>&1
		-rm -f $(PDEST)/$(DOMLIB)/axfroutany.awk > /dev/null 2>&1

#-------

#
# Pack up all the files, ready for distribution.
#

dist:		clean
		d=`pwd`; d=`basename $$d`; cd ..; tar czf /tmp/$$d.tar.gz \
			--exclude RCS \
			--exclude Old \
			--exclude Test \
			--exclude ToolList \
			$$d; echo "done.  distribution file is /tmp/$$d.tar.gz"

#-------

#
# Clean up all extraneous files.  This does NOT damage the software package.
#

clean:
		-rm -f $(MACRO) xxxtool core

#-------

#
# Spell check all english documents.
#

spell:
		{ for i in README COPYING MANUAL HOWTOUSE WHY COPYRIGHT TODO BUGS CHANGES INSTALL TESTS; do \
			ispell -p WORDS -l < $$i; \
		done } | sort -u

# End of Makefile.
