# GNU Makefile
# 01/15/98 C. Ludescher-Furth
# 08/25/98 CLF add texi
# 04/16/09 CLF add tshare update date
#
# Check for new  $(TRANSPROOT)/codesys/source/doc/*.hlp
# Convert to .html
#
# Must be run from ...help directory for perl to work
# Also: old files must be deleted; otherwise perl script will append.
#
SRC = $(TRANSPROOT)/codesys/source/doc

f_new = transp.hlp pspline.hlp nubeam.hlp trread.hlp trxplib.hlp \
	trgraf.hlp ufiles.hlp uread.hlp sg.hlp xplasma.hlp tek2ps.hlp \
	xplot.hlp xtc.hlp port_strategy.hlp supralu.hlp \
	trbugs.hlp trnews.hlp common_errors.hlp trdatbuf_lib.hlp

f_date =  trbugs.date trnews.date
files = 
tfiles = ufiles.texi

INDEX = ../transp/index.html
new_Up = $(shell date --date= +"%D" )
pdate=$(shell grep "pshare update" $(SRC)/trnews.hlp | tail -1 | sed 's/-- pshare update//' )
new_P = $(shell date --date "$(pdate)"  +"%D" )
tdate=$(shell grep "tshare update" $(SRC)/trnews.hlp | tail -1 | sed 's/-- tshare update//' )
new_T = $(shell date --date "$(tdate)"  +"%D" )


help: help0 help1 tex help_new trbugs.date trnews.date

help0:
	@echo hlp Files:  $(f_new)
	@echo texi Files: $(tfiles)
	@echo TRANSPROOT: $(TRANSPROOT)
	@echo date Files: $(f_date)

# Note: $* = target stem;  $@ = current target
#       $< is the source
#       12/10/98 replaced "cp $< ." with sed
#	02/11/03 convert http to URL

help1: $(foreach file,$(files),$(file))
%.hlp: $(SRC)/%.hlp
	-rm $@ $*_hlp.html body_$*_hlp.html
	@sed -e"s/</\&lt;/g" -e "s/>/\&gt;/g" $< > $@.foo1
	@sed -e's#http://\([^ ]* \|[^ ]*$$\)#<A href="http://\1"> http://\1 </A>#g' $@.foo1 > $@
	$(TRANSPROOT)/bin/hlptohtml.perl $@
	rm $@ $@.foo*
	touch $@

help_new: $(foreach file,$(f_new),$(file))
%.hlp: $(SRC)/%.hlp
	-rm $@ $*_hlp.html body_$*_hlp.html
	echo new
	@sed -e"s/</\&lt;/g" -e "s/>/\&gt;/g" $< > $@.foo1
	@sed -e's#http://\([^ ]* \|[^ ]*$$\)#<A href="http://\1" target="_top"> http://\1 </A>#g' $@.foo1 > $@
	$(TRANSPROOT)/bin/hlptohtml.perl $@
	@sed -e's/html"/html" Target="main"/' $*_hlp.html > $*_hlp.htm
	rm $@ $@.foo*
	touch $@

tex: $(foreach file,$(tfiles),$(file))
%.texi: $(SRC)/%.texi
	-rm -f $*_manual.html
	cp $< $*_manual.texi
	texi2html $*_manual.texi
	rm $*_manual.texi
	touch $@

trbugs.date: trbugs.hlp
	sed -e "s# Updated: .* </td># Updated: ${new_Up} </td>#" $(INDEX) > foo
	mv foo $(INDEX)
	touch $@

trnews.date: trnews.hlp
	sed -e "s# pshare Update: .* </td># pshare Update: ${new_P} </td>#" $(INDEX) > foo
	mv foo $(INDEX)
	sed -e "s# tshare Update: .* </td># tshare Update: ${new_T} </td>#" $(INDEX) > foo
	mv foo $(INDEX)
	touch $@

