SRC := $(wildcard 199*.xml 20*.xml)
CURRENT := ../d.html.jis
TARGETS := $(patsubst %.xml,%.html,$(SRC)) $(CURRENT) diary.xml
LASTTWO := $(shell ls 199*.xml 20*.xml | tail -2)
LATEST  := $(shell ls 199*.xml 20*.xml | tail -1 | sed -e s/\.xml//)

all: $(TARGETS)

%.html : %.xml month.xsl
	./genparam.pl $< > param.xml
	wk month.xsl $< /~AE5T-KSN/d/$@ > $@

latest.xml: latest.xml.head $(LASTTWO) latest.xml.foot
	(cat latest.xml.head ; \
	printf "  <d:latest>%s</d:latest>\n" $(LATEST) ; \
	ls -1tr $(LASTTWO) | \
	sed -e 's/^/  <inc:include href="/' \
	    -e 's/$$/" \/>/' \
	; cat latest.xml.foot)>latest.xml

$(CURRENT) : latest.xml latest.xsl
	wk latest.xsl latest.xml /~AE5T-KSN/d.html > $(CURRENT)

latest.xsl: diary.xsl

month.xsl: diary.xsl

diary.xml: latest.xml
	cp latest.xml diary.xml

clean:
	rm -f $(TARGETS)

debug:
	@echo $(LASTTWO)
