# Copyright (C) 1996,1997 Robert Hhne, see COPYING.RH for details 
# This file is part of RHIDE. 
ifeq ($(strip $(RHIDESRC)),)
error You must set the environment variable RHIDESRC
endif

srcdir=$(RHIDESRC)/doc/editor
VPATH=$(srcdir)
doc_dir=..
doc_srcdir=$(srcdir)/..

src_files=makefile editor.tx htmlidx.sed
po_files=
cfg_files=
update_files=

subdirs=
po_subdirs=
obj_subdirs=

include $(RHIDESRC)/common.mak

MAKEINFO=makeinfo -I $(srcdir) -I $(doc_srcdir)

all:

doc: editor.info editor.html editor.txt

all_doc: info txt ps html

info: editor.info

tx2txi=$(doc_dir)/tx2txi.exe
enum=$(doc_dir)/enum.exe
html2ctx=$(doc_dir)/html2ctx.exe
htm2ctx=$(doc_dir)/htm2ctx.exe

$(tx2txi) $(enum) $(html2ctx) $(htm2ctx):
	$(MAKE) -C $(doc_dir) $(notdir $@)

editor.txi: editor.tx $(tx2txi) \
	$(addprefix $(doc_srcdir)/,rhidemac.txi rhidemac.htm rhidemac.txt)

%.txi: %.tx
	$(tx2txi) $< $@

install.info: info
	dtou editor.info
	ginstall -d $(prefix)/info
	ginstall editor.info $(prefix)/info
	echo info/editor.info > info.log

txt: editor.txt

install.txt: txt
	ginstall -d $(prefix)/doc
	ginstall editor.txt $(prefix)/doc
	echo doc/editor.txt > txt.log

html: editor.html

install.html: html
	ginstall -d $(prefix)/doc
	ginstall editor.html $(prefix)/doc
	echo doc/editor.html > html.log

editor.info: editor.num

%.info: %.num
	$(MAKEINFO) --fill-column 75 -o $@ $<

editor.inf: editor.info

editor.num: editor.txi $(enum)

%.num: %.txi
	$(enum) -I $(srcdir) -I $(doc_srcdir) $< $@

# dvi is not available, becasue editor.tx conatins too many very
# special characters

#dvi: editor.dvi
#
#ps: editor.ps
#
dvi ps:

#%.ps: %.dvi
#	dvips -o $@ $<
#
#edittex.tmp: editor.txi
#	-$(MAKEINFO) -o /dev/null --no-split -E $@ -Ddvi $<
#
#editor.dvi: edittex.tmp
#	-tex $<
#	-texindex edittex.??
#	-tex $<
#	-mv edittex.dvi $@

htmlctx.tmp: editor.num $(doc_srcdir)/htmlprep.sed
	sed -f $(doc_srcdir)/htmlprep.sed $< | \
	  sed -n -f $(doc_srcdir)/htmlctx.sed > $@

html.ctx: htmlctx.tmp $(htm2ctx)
	$(htm2ctx) $< > $@

htmlref.tmp: htmlctx.tmp makefile
	sed -e \
	  's/^[^{]*{\([^}]*\)}{\([0-9]\)[0-9\.][0-9\.]*}/s|"#\1"|"chap\2.html#\1"|/' \
	  $< > $@

split.tmp: editor.html htmlref.tmp
	sed -f htmlref.tmp editor.html > $@

htmlsplit: split.tmp htmlspl
	htmlspl $< chap

editor.ctx: editor.num cindex.idx kindex.idx $(html2ctx)
	sed -f $(doc_srcdir)/htmlprep.sed $< | \
	  sed -n -f $(doc_srcdir)/htmlctx.sed | \
	 $(html2ctx) > $@

editor.html: editor.num editor.ctx $(doc_srcdir)/htmlprep.sed
	sed -f $(doc_srcdir)/htmlprep.sed $< | \
	  $(MAKEINFO) --no-validate --no-split --no-headers --fill-column 200 \
	  -Dhtml -o $@

html.tmp: editor.num editor.ctx $(doc_srcdir)/htmlprep.sed
	sed -f $(doc_srcdir)/htmlprep.sed $< > $@

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

editor.htm: editor.html

cindex.tmp kindex.tmp: $(doc_srcdir)/indices.sed editor.info
	sed -n -f $^

kindex.idx: htmlidx.sed kindex.tmp
	sed -f $< kindex.tmp > kindex.idx

cindex.idx: $(doc_srcdir)/htmlidx.sed cindex.tmp
	sed -f $< cindex.tmp > cindex.idx

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

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

textprep.tmp: chapters.tmp $(doc_srcdir)/chapxref.sed
	sed -n -f $(doc_srcdir)/chapxref.sed chapters.tmp > $@

textpost.tmp: chapters.tmp $(doc_srcdir)/idxref.sed
	sed -n -f $(doc_srcdir)/idxref.sed chapters.tmp > $@

editor.txt: editor.num textprep.tmp textpost.tmp contents.idx
	@echo The following command may take a long time.  Be patient.
	sed -f textprep.tmp $< | \
	  $(MAKEINFO) --no-split --no-headers --no-validate --fill-column 78 \
	  -Dtext -o - | \
	  sed -f textpost.tmp > $@
	  
clean:
	rm -f *.tmp
	rm -f *.idx
	rm -f editor.??
	rm -f editor.??s
	rm -f edittex.*
	rm -f *.log *.bak *.dsk *.dlg *.aux *.idx *.toc *.num
	rm -f editor.ct?

distclean: clean
	rm -f editor.inf* editor.htm* editor.dvi editor.txt editor.ps editor.txi

install: install.info install.txt install.html
	cat info.log txt.log html.log > $(logfile)
	rm -f info.log txt.log html.log
