# See COPYING file for copyright, license and warranty details.

SITENAME=http://njw.me.uk
FOAF=http://njw.me.uk/card\#i
MARKDOWN=smu

RSS=index.ttl
PAGES=$(shell find . -name '*.txt' ! -name 'robots.txt' ! -name $(RSS))
EXTRAS=$(shell find . -name '*.css') card.ttl
TARGETS=$(PAGES:.txt=.xml) $(RSS)
GZIP=$(PAGES:=.gz) $(TARGETS:=.gz) $(EXTRAS:=.gz)

all: $(TARGETS) $(GZIP)

$(TARGETS): includes/header.xml includes/footer.xml

$(RSS): $(PAGES) makerss.sh
	@echo making $@
	@sh makerss.sh $(SITENAME) $(FOAF) $* > $@

index.xml: index.txt includes/header-index.xml includes/footer.xml
	@echo making $@
	@sed "s/TITLE/`head -n 1 < $<`/" < includes/header-index.xml > $@
	@$(MARKDOWN) $< >> $@
	@sed "s/MODDATE/`ls -lc --time-style=+%Y-%m-%d $<|awk '{print $$6}'`/" < includes/footer.xml >> $@

.txt.xml:
	@echo making $@
	@sed "s/TITLE/`head -n 1 < $<`/" < includes/header.xml > $@
	@$(MARKDOWN) $< >> $@
	@sed "s/MODDATE/`ls -lc --time-style=+%Y-%m-%d $<|awk '{print $$6}'`/" < includes/footer.xml >> $@

# not POSIX compatible
%.gz: %
	@echo compressing $<
	@gzip < $< > $@

clean:
	rm -f -- $(TARGETS) $(GZIP)

.SUFFIXES: .txt .xml .rdf .gz