# This makefile is used to create the various help files and index files
# needed for the CRISP help system. We try to organise things so that
# data which is creatable from source is held in a single directory
# so that it makes it easier to copy that or remove it.
#
# The default rule for make is to build the files so that they can be
# processed rapidly, in small handlable chunks by CRISP.
#
# The alternative rules build troffed sources from the files so we
# can print the manuals.
#
# The whole business about ninfo is that its difficult to force nroff/troff
# to do the special processing we want. The two major issues are avoiding
# page breaks for the main manuals, and avoiding having a directory with
# 300 tiny small files describing the CRISP primitives.
#
# Anyway, to build printable documentation, you want to use the following rules:
#
#  make pr_prim		Creates file in /tmp/prim.ps.
#			This is the CRISP macro primitive manual.
#  make pr_config	Creates file in /tmp/config.ps
#			This is the CRISP configuration guide manual.
#  make pr_prog		Creates file in /tmp/prog.ps
#			This is the CRISP programmers guide.
#  make pr_user		Creates file in /tmp/user.ps
#			This is the user guide.
#  make printer		Builds all the PostScript manuals in /tmp.
#
###########################################################################
#		System V Definitions
#  If you are on a System V machine, then uncomment the following definitions
#  and make sure the redefinitions below are commented out.
#MSMAC=
#TROFF= troff -Tps -mm | devps
###########################################################################
#		BSD Definitions
#  If you are on a non System V machine (e.g. a Sun) you should uncomment
#  the following definitions if you want to get a machine readable copy
#  of the documentation.
MSMAC=mac.ms
TROFF=ptroff -t -ms
###########################################################################
TBL=tbl
COL=col -p
SHELL=/bin/sh
NROFF=nroff
PG=-o1-99
NINFO=../ninfo
CRUNCH=../crunch/crunch
OBJ	= \
		obj/config.hlp \
		obj/prog.hlp \
		obj/user.hlp \
		obj/prim.000

all:	obj help

obj:
	-mkdir obj

help:	$(OBJ) obj/var.sec
	cd cshelp ; $(MAKE) NINFO=../$(NINFO) CRUNCH=../$(CRUNCH)
	cd features ; $(MAKE) NINFO=../$(NINFO) CRUNCH=../$(CRUNCH)

obj/config.hlp:	config.mm obj/config.cm
obj/config.cm: config.mm $(CRUNCH)
	$(NINFO) -i obj/config.cr config.mm > obj/config.hlp
	$(CRUNCH) obj/config.cr
obj/prog.hlp:	prog.mm obj/prog.cm
obj/prog.cm: prog.mm $(CRUNCH)
	$(NINFO) -i obj/prog.cr prog.mm > obj/prog.hlp
	$(CRUNCH) obj/prog.cr
obj/user.hlp: user.mm obj/user.cm
obj/user.cm: user.mm $(CRUNCH)
	$(NINFO) -i obj/user.cr user.mm > obj/user.hlp
	$(CRUNCH) obj/user.cr
	
# Entry to create manual pages for primitives.
obj/prim.000:	prim.mm
	-rm -f obj/prim.???
	$(NINFO) -o obj/prim -s 50000 prim.mm

clean:
	-rm obj/*

# Make sections for the help. We use the comments in keywd.c to tell us how
# to cross-reference the entries.
obj/var.sec: ../keywd.c
	rm -f obj/*.sec
	grep '^{' ../keywd.c | grep MACRO | \
	sed -e 's/,/ /g' -e 's/^{"//' -e 's;".*/\*;;' -e 's;\*/;;' | \
	awk -f sections.awk | sh

printer:
	$(MAKE) MSMAC="$(MSMAC)" "TROFF=$(TROFF)" pr_prim
	$(MAKE) MSMAC="$(MSMAC)" "TROFF=$(TROFF)" pr_config
	$(MAKE) MSMAC="$(MSMAC)" "TROFF=$(TROFF)" pr_prog
	$(MAKE) MSMAC="$(MSMAC)" "TROFF=$(TROFF)" pr_user

pr_prim:
	cat $(MSMAC) prim.mm | $(TBL) | $(TROFF) > /tmp/pr_prim
pr_config:
	cat $(MSMAC) config.mm | $(TBL) | $(TROFF) > /tmp/pr_config
pr_prog:
	cat $(MSMAC) prog.mm | $(TBL) | $(TROFF) > /tmp/pr_prog
pr_user:
	cat $(MSMAC) user.mm | $(TBL) | $(TROFF) > /tmp/pr_user
