#                           Documentation/Makefile
#
# This file is the gateway to building all of the documentation in this
# directory.  It compiles all of the .sdf files in this directory into
# .txt, .html, and .ps formats, then creates a simple index page.
# 

LEVEL = ..

DestDir    = $(LEVEL)/Install/Docs
DocDestDir = $(DestDir)
Docs       = $(sort $(wildcard *.sdf))

include $(LEVEL)/Makefile.common

DestTXT    = $(patsubst %.sdf,$(DestDir)/%.txt,  $(Docs))
DestHTML   = $(patsubst %.sdf,$(DestDir)/%.html, $(Docs))
DestPS     = $(patsubst %.sdf,$(DestDir)/%.ps,   $(Docs))

#DestIDX    = $(DestDir)/index.html

# Disable building of documentation...
#DestALL    = $(DestIDX) $(DestTXT) $(DestHTML) #$(DestPS)


# HACK TO COPY DOCUMENTATION OVER:
#
DestALL    = $(addprefix $(DestDir)/,$(wildcard *.gif *.html))
$(DestDir)/%: %
	cp $< $(DestDir)

# To build all files, build all of the documentation and the dir to put it in.
#
all:: $(DestDir)/.dir $(DestALL)

# To Install Documentation, copy to /usr/doc/MagicStats2/
#
install:: $(DocInstDir)/.dir all
	cd $(DocInstDir)/..; ln -sf MagicStats2 magicstats2
	cd $(LibInstDir); ln -sf $(DocInstDir) Documentation
	if test ! "" = "$(DestALL)"; then \
		cp -f $(DestALL) $(DocInstDir); \
	fi

# Nothing needed for clean... no temporary files... Clobber get's them all
#
clean::

# RowCommand is the command to issue to add one line to the index file...
Filename = $(basename $(F))
RowCommand  = echo -n " $(Filename),"; echo "<TR><TD>$(basename $(F)):</TD>
RowCommand += <TD><a href='$(Filename).txt'>Text Format</a></TD>
RowCommand += <TD><a href='$(Filename).html'>HTML Format</a></TD>
RowCommand += <TD><a href='$(Filename).ps'>PostScript Format</a></TD>
RowCommand += </TR>" 

# Rule to build the index file... Index is dependant on . because someone could
# have just added a file to the current directory that needs to be indexed...
#
$(DestIDX): . indexTop.html indexBottom.html
	cp indexTop.html $(DestDir)/index.html
	@echo -n "*** Adding document index for:"
	@echo "<TABLE ALIGN=Center>" >> $(DestDir)/index.html
	@$(foreach F,$(Docs), $(RowCommand) >> $(DestDir)/index.html; )
	@echo "</TABLE>" >> $(DestDir)/index.html
	@#
	@# Add the trailing newline...
	@echo ".."
	cat indexBottom.html >> $(DestDir)/index.html
