# Must hard-code manpage starting page

CHAPTERS = frtmat.new pref.new overview.new ddn.new \
        x25prep.new ir.new install.new x25only.new run.new \
        hdlc.new x25tshoot.new pdn.new params.new \
        ddn_params.new x25mgr.new diskless.new \
        nullmodem.new routes.new \
        x121.new acro.new gloss.new manpag.new

PREFACE = pref.new

ALLFILES = frtmat.new pref.new overview.new ddn.new genprep.new \
        x25prep.new ir.new install.new x25only.new run.new \
        hdlc.new x25tshoot.new params.new pdn.new \
        ddn_params.new x25mgr.new diskless.new \
        nullmodem.new autolink.new \
        acro.new gloss.new manpag.new gated.man

MANPAGES = gated.man 
# The file gated.man contains the actual -msunman formatted manual pages.

all: doc.dit contents.dit tables.dit figures.dit preface.dit man.dit index.dit 
# tables.dit figures.dit man.dit

some: doc.dit contents.dit man.dit

part: preface.dit contents.dit

doc.dit: $(CHAPTERS) 
	xref $(CHAPTERS) | pic | tbl | \
	 troff -t -mex -rF1 >doc.dit 2>slush.tmp 
	recode < slush.tmp >slush.file; rm -f slush.tmp 
# make doc.dit to ascertain the starting page number of $(MANPAGES).

man.dit: $(MANPAGES) 
	tbl $(MANPAGES) | troff -t -msunman -rF1 -rC1 -rD1 -rP155 \
	> man.dit 2>slush.tmp 
	recode < slush.tmp >> slush.file; rm -f slush.tmp 
# number register -rPpage# contains starting page number of $(MANPAGES).
# append $(MANPAGES) index items to slush.file


index.dit: doc.dit 
	grep '^\.IE' slush.file | (echo .UH INDEX; index) | \
	 troff -t -mex -rF1 -rP`tail -1 slush.file` >index.dit 2>>slush.file

contents.dit: doc.dit 
	(echo .UH CONTENTS ; grep '^\.CE [CANU]' slush.file) | \
	grep -v Preface | \
	 troff -t -mex -rF1 -rP3 >contents.dit 2>>slush.file

tables.dit: doc.dit 
	(echo .UH TABLES; grep '^\.CE T' slush.file) | \
	 troff -t -mex -rF1 -rP`tail -1 slush.file` >tables.dit 2>>slush.file

figures.dit: doc.dit 
	(echo .UH FIGURES; grep '^\.CE F' slush.file) | \
	 troff -t -mex -rF1 -rP`tail -1 slush.file` >figures.dit 2>>slush.file

preface.dit: Outline.File $(PREFACE) Stringdefs
	xref -o Outline.File $(PREFACE) | \
	troff -t -mex -rF1 -rp`tail -1 slush.file` \
	 >preface.dit 2>>slush.file 

Outline.File:   $(CHAPTERS) $(PREFACE)
	egrep -h '^\.(H|TN|FN) ' $(CHAPTERS) $(PREFACE) > Outline.File

paginate.dit: doc.dit 
	paginate -b`tail -1 slush.file | awk '{print $$1 - 1}'` slush.file | \
	 pic | troff -t -mex /usr/doctools/lib/paginate.mex - > paginate.dit

check: 
	check $(CHAPTERS)

print: doc.dit 
	ditprint -Pwords paginate.dit man.dit index.dit
	if test `ls -s doc.dit | awk '{print $$1}'` -gt 1000; \
	 then psdit doc.dit > doc.PS; psprint doc.PS; \
	 else ditprint -Pwords doc.dit; \
	fi
	ditprint -Pwords preface.dit figures.dit tables.dit contents.dit

show: 
	@echo $(CHAPTERS)

showall: 
	@echo $(ALLFILES)

get: 
	-for i in $(CHAPTERS) ; do sccs get -s -G$$i $$i ; done

clean: 
	rm -f slush.* doc.PS *.dit

