HOME = /mit/docsourc/doc/c.saber/ref
RMDIR = $(HOME)/.rm_dir/
PSROFF = psroff -me -t
PRINT = lpr
IPRINT = lpr -v -Pimagen -F
NROFF = nroff -Tlpr -me
PREVIEW = /usr/local/bin/impv
PROFF = ../pre_nroff | expand -4 | tbl

ONLINE_PAGES = action.onl badptr.onl calloct.onl catch.onl				\
	contents.onl delete.onl down.onl dump.onl edit.onl english.onl		\
	getopt.onl fg.onl freealloc.onl cont.onl gripe.onl help.onl			\
	history.onl ignore.onl jobs.onl killjob.onl link.onl list.onl		\
	load.onl malloct.onl next.onl options.onl printopt.onl quit.onl 	\
	reinit.onl rename.onl reset.onl restore.onl run.onl save.onl 		\
	setopt.onl start.onl status.onl step.onl stepout.onl stop.onl		\
	suppress.onl suspend.onl tag.onl tagaction.onl touch.onl trace.onl 	\
	typeof.onl udpf.onl unload.onl unres.onl unsetopt.onl unsuppress.onl\
	up.onl version.onl whatis.onl where.onl whereami.onl xref.onl

ONLINE_INFO = ansi.onl bugs.onl hints.onl intro.onl portability.onl 	\
	summary.onl errors.onl

PAGES = action.r badptr.r catch.r cont.r contents.r dump.r edit.r		\
	english.r freealloc.r help.r history.r jobs.r link.r list.r			\
	load.r malloct.r options.r quit.r rename.r run.r save.r setopt.r	\
	status.r step.r stop.r suppress.r tag.r touch.r trace.r typeof.r	\
	udpf.r unload.r up.r version.r whatis.r where.r xref.r

LINKS = calloct.r delete.r down.r fg.r getopt.r gripe.r ignore.r		\
	killjob.r next.r printopt.r reinit.r reset.r restore.r start.r		\
	steptout.r suspend.r tagaction.r unres.r unsetopt.r unsuppress.r	\
	whereami.r

ONLONLY = ansi.r bugs.r hints.r intro.r portability.r summary.r \
	errors.r

.SUFFIXES: .r .onl .tout .nout .lpr .ipr .img .src .imp


#
# RULES FOR ASSEMBLYING THE ONLINE REFERENCE MANUAL
#

online: $(ONLINE_PAGES) $(ONLINE_INFO)
	@echo "Online documents done."

#
# RULES FOR ASSEMBLYING THE REFERENCE MANUAL FOR PRINTING
#

release: ref_title.PS ref_commands.PS ref_contents.PS
	@echo ref_title.PS, ref_commands.PS and ref_contents.PS are ready

ref_title.PS : ref_title.r ref_macros
	cat ref_macros ref_title.r | $(PROFF) > temp
	$(PSROFF) temp > $@
	'rm' -f temp
	
ref_commands.PS : ref_commands.all ref_macros
	cat ref_macros ref_commands.all | $(PROFF) > temp
	$(PSROFF) temp 1> ref_commands.PS 2> contents.unsorted
#	'rm' -f temp ref_commands.temp

ref_commands.all : $(PAGES)
	cat $(PAGES) > $@

ref_contents.PS: contents.sorted ref_macros
	cat ref_macros ref_contents.r | $(PROFF) > temp
	$(PSROFF) temp > $@
	'rm' -f temp

ref_commands.me : ref_commands.all
	cat ref_macros ref_commands.all | $(PROFF) > ref_commands.me

contents.sorted: contents.unsorted
	grep .EI contents.unsorted > temp.con
	sort temp.con > $@
	'rm' -f temp.con

help.tar: online
	tar cvf help.tar $(ONLINE_PAGES) $(ONLINE_INFO)

#
# MACRO FILES
#



online_macros: common_macros
	touch -c ref_macros

#
# EXCEPTION CASES AND SPECIAL RULES
#

summary.r : ../src/help.src
	touch -c summary.r

portability.r: ../src/port.src
	touch -c portability.r

ansi.r: ../src/ansi.src
	touch -c ansi.r

bugs.r: ../src/bugs.src
	touch -c bugs.r

hints.r: ../src/hints.src
	touch -c hints.r

intro.r: ../src/intro.src
	touch -c intro.r

errors.r: ../src/errors.load ../src/errors.run
	touch -c errors.r

#
# MISCELLANEOUS AND DEFAULT RULES
#

.r.onl:
	cat online_macros $< | $(PROFF) > $*.temp
	$(NROFF) $*.temp 2> /dev/null | cat -s > $@
	'rm' -f $*.temp

.r.nout:
	cat ref_macros $< | $(PROFF) > $*.temp
	$(NROFF) $*.temp 2> /dev/null > $@
	'rm' -f $*.temp

.r.tout:
	cat ref_macros $< | $(PROFF) > $*.temp
	$(PSROFF) $*.temp 2> /dev/null > $@
	'rm' -f $*.temp

.nout.lpr:
	$(PRINT) $<

.onl.lpr:
	$(PRINT) $<

.nout.ipr:
	$(IPRINT) $<

.tout.img:
	$(IPRINT) $<

.tout.imp:
	imptool $<

# Links commands which are listed on the same page.
# Touch's file to  make sure it exists; saves original.
links:
	touch calloct.r ;	mv calloct.r $(RMDIR) ;		ln malloct.r calloct.r
	touch delete.r ;	mv delete.r $(RMDIR) ;		ln status.r delete.r
	touch down.r ;		mv down.r $(RMDIR) ;		ln up.r down.r 
	touch fg.r ;		mv fg.r $(RMDIR) ;			ln jobs.r fg.r
	touch getopt.r ;	mv getopt.r $(RMDIR) ;		ln setopt.r getopt.r
	touch gripe.r ;		mv gripe.r $(RMDIR) ;		ln version.r gripe.r
	touch ignore.r ;	mv ignore.r $(RMDIR) ;		ln catch.r ignore.r
	touch killjob.r ;	mv killjob.r $(RMDIR) ;		ln jobs.r killjob.r
	touch next.r ;		mv next.r $(RMDIR) ;		ln step.r next.r
	touch printopt.r ;	mv printopt.r $(RMDIR) ;	ln setopt.r printopt.r
	touch reinit.r ;	mv reinit.r $(RMDIR) ;		ln run.r reinit.r
	touch reset.r; 		mv reset.r $(RMDIR) ;		ln cont.r reset.r
	touch restore.r; 	mv restore.r $(RMDIR) ;		ln save.r restore.r
	touch start.r ;		mv start.r $(RMDIR) ;		ln run.r start.r
	touch stepout.r ;	mv stepout.r $(RMDIR) ;		ln step.r stepout.r
	touch suspend.r ;	mv suspend.r $(RMDIR) ;		ln quit.r suspend.r
	touch tagaction.r; 	mv tagaction.r $(RMDIR) ;	ln tag.r tagaction.r
	touch unres.r ;		mv unres.r $(RMDIR) ;		ln link.r unres.r
	touch unsetopt.r ;	mv unsetopt.r $(RMDIR) ;	ln setopt.r unsetopt.r
	touch unsuppress.r; mv unsuppress.r $(RMDIR) ;	ln suppress.r unsuppress.r
	touch whereami.r;	mv whereami.r $(RMDIR) ;	ln where.r whereami.r

beta: 
	tar cvf beta.tar $(ONLINE) saber.man

