# This file is part of RHIDE, (C) 1996 Robert Hhne
ifndef srcdir
srcdir=.
endif

VPATH=$(srcdir)

prefix=$(DJDIR)

SOURCES = rhide.txi rhidemac.txi rhidemac.htm rhidemac.txt $(wildcard *.sed)

prefix=$(DJDIR)

MAKEINFO=makeinfo -I $(srcdir)

INFVIEW=$(addprefix infview.,eng ger spa info)

all: rhide.dvi rhide.info rhide.html rhide.txt $(INFVIEW)

infview.inf: infview.info

infview.info: infview.eng
	cp infview.eng infview.info

infview.eng: infeng.txi
	-$(MAKEINFO) $<

infview.spa: infspa.txi
	-$(MAKEINFO) $<

infview.ger: infger.txi
	-$(MAKEINFO) $<

rhide.inf: rhide.info

rhide.info: rhide.num
	$(MAKEINFO) --no-split --fill-column 68 -o $@ $<

rhide.num: $(SOURCES) enum
	enum $< $@

enum: enum.c
	gcc -Wall -O2 -s -o $@ $<

html2ctx: html2ctx.c
	gcc -Wall -O2 -s -o $@ $<

rhide.ps: rhide.dvi
	dvips -o rhide.ps rhide.dvi

rhide.dvi: rhide.txi
	-$(MAKEINFO) -o nul --no-split -E rhidetex.tmp $<
	-tex rhidetex.tmp
	-texindex rhidetex.??
	-tex rhidetex.tmp
	-mv rhidetex.dvi rhide.dvi

rhide.tmp: rhide.num htmlprep.sed cindex.idx kindex.idx
	redir -o rhide.tmp sed -f $(srcdir)/htmlprep.sed $<

rhide.htm: rhide.html

rhide.html: rhide.tmp rhide.ctx
	$(MAKEINFO) --no-validate --no-split --no-headers --fill-column 200 -Dhtml -o $@ rhide.tmp

rhide.ct1: rhide.tmp htmlctx.sed
	redir -o rhide.ct1 -i rhide.tmp sed -n -f $(srcdir)/htmlctx.sed

rhide.ctx: rhide.ct1 html2ctx
	redir -o rhide.ctx -i rhide.ct1  html2ctx

cindex.idx kindex.idx: indices.sed rhide.info htmlidx.sed
	sed -n -f $(srcdir)/indices.sed rhide.info
	redir -o cindex.idx sed -n -f $(srcdir)/htmlidx.sed \
	cindex.tmp
	redir -o kindex.idx sed -n -f $(srcdir)/htmlidx.sed \
	kindex.tmp

contents.idx: rhide.num makefile
	redir -o $@ sed -n \
	-e 's/^@subsubsection  */  /p' \
	-e 's/^@subsection  */  /p' \
	-e 's/^@section  */  /p' \
	-e 's/^@chapter  *//p' \
	$<

chapters.tmp: rhide.num makefile
	redir -o $@ sed -n \
	-e '/^@node[ 	]/p' \
	-e '/^@top[ 	]/p' \
	-e '/^@chapter[ 	]/p' \
	-e '/^@subsubsection[ 	]/p' \
	-e '/^@subsection[ 	]/p' \
	-e '/^@section[ 	]/p' \
	-e '/^@unnumbered[ 	]/p' \
	$<

rhide.txt: rhide.num chapxref.sed idxref.sed chapters.tmp contents.idx
	redir -o textprep.tmp sed -f $(srcdir)/chapxref.sed chapters.tmp
	@echo.exe 'The following command may take a long time.  Be patient.'
	redir -o text.tmp sed -f textprep.tmp $<
	$(MAKEINFO) --no-split --no-headers --no-validate --fill-column 78 -Dtext -o txt.tmp text.tmp
	redir -o textpost.tmp sed -f $(srcdir)/idxref.sed chapters.tmp
	redir -o $@ sed -f textpost.tmp txt.tmp

clean:
	rm -f *.tmp
	rm -f *.idx
	rm -f rhide.??
	rm -f rhide.??s
	rm -f rhidetex.*
	rm -f *.log *.bak *.dsk *.dlg *.aux *.idx *.toc *.num
	rm -f rhide.ct?

distclean: clean
	rm -f rhide.info rhide.html rhide.dvi rhide.txt rhide.ps
	rm -f enum enum.exe html2ctx html2ctx.exe
	rm -f infview.*

install: all
	if not exist $(subst /,\,$(prefix))\info\nul mkdir $(subst /,\,$(prefix))\info
	if not exist $(subst /,\,$(prefix))\doc\nul mkdir $(subst /,\,$(prefix))\doc
	cp rhide.info $(INFVIEW) $(prefix)/info
	cp rhide.dvi rhide.html rhide.txt $(prefix)/doc

