# 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
VPATH=$(srcdir)

src_files=\
	  infeng.txi infger.txi infspa.txi \
	  rhidemac.txi rhidemac.htm rhidemac.txt \
	  chapxref.sed htmlctx.sed htmlidx.sed htmlprep.sed idxref.sed \
	  indices.sed enum.c html2ctx.c	makefile rhide.tx tx2txi.c \
	  htmlspl.c checkmki.txi makeinfo.dif
po_files=
cfg_files=
update_files=

subdirs=editor
po_subdirs=
obj_subdirs=

include $(RHIDESRC)/common.mak

MAKEINFO=makeinfo -I $(srcdir)

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

all:

editor.info editor.dvi editor.txt editor.html editor.ps: force
	$(MAKE) -C editor $@

doc: rhide.info rhide.html rhide.txt $(INFVIEW)

all_doc: info dvi txt ps html

info: rhide.info $(INFVIEW) editor.info

tx2txi tx2txi.exe: tx2txi.c
	gcc -o $@ -O -s $<

rhide.txi: rhide.tx tx2txi rhidemac.txi rhidemac.htm rhidemac.txt

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

rhide_info=rhide.info $(shell ls rhide.i[1-9]*)

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

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

dvi: rhide.dvi

txt: rhide.txt editor.txt

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

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

ps: rhide.ps

html: rhide.html editor.html

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

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

infview.info: infview.eng
	cp $< $@

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

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

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

rhide.info: rhide.num

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

rhide.inf: rhide.info

rhide.num: rhide.txi enum

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

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

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

%.ps: %.dvi
	dvips -o $@ $<

rhidetex.tmp: rhide.txi
	-$(MAKEINFO) -o /dev/null --no-split -E $@ -Ddvi $<

rhide.dvi: rhidetex.tmp
	-tex $<
	-texindex rhidetex.??
	-tex $<
	-mv rhidetex.dvi $@

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

html.ctx: htmlctx.tmp html2ctx
	html2ctx $< > $@

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

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

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

htmlsplit: split.tmp htmlspl
	htmlspl $< chap

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

rhide.html: rhide.num rhide.ctx $(srcdir)/htmlprep.sed check.makeinfo
	sed -f $(srcdir)/htmlprep.sed $< | \
	  $(MAKEINFO) --no-validate --no-split --no-headers --fill-column 200 \
	  -Dhtml -o rhide.html

rhide.htm: rhide.html

rhide_.inf: rhide.num
	$(MAKEINFO) --no-split --fill-column 75 -o $@ $<

cindex.tmp kindex.tmp: indices.sed rhide_.inf
	sed -n -f $^

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

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

chapters.tmp: rhide.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 $(srcdir)/chapxref.sed
	sed -n -f $(srcdir)/chapxref.sed chapters.tmp > $@

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

rhide.txt: rhide.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 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.inf* rhide.htm* rhide.dvi rhide.txt rhide.ps rhide.txi
	rm -f enum enum.exe html2ctx html2ctx.exe tx2txi tx2txi.exe
	rm -f htmlspl htmlspl.exe
	rm -f chap*.htm*
	rm -f infview.*

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

check.makeinfo: checkmki.txi force
	@-redir -o /dev/null -e checkmki.err makeinfo -o /dev/null $<
	@echo If make stops here you need at least makeinfo.exe from
	@echo texinfo 3.9 with the patch \'$(srcdir)/makeinfo.dif\', otherwise
	@echo you will not be able to produce the html format.
	@echo Apply the patch like the following command:
	@echo ''
	@echo patch $(DJDIR)/gnu/texinfo3.9/makeinfo/makeinfo.c $(srcdir)/makeinfo.dif
	@echo ''
	@test ! -s checkmki.err

force:
