
# Yeah, I should fix this :D

objects = $(addsuffix .html,$(basename $(wildcard posts/*.rst)))

build_tools = util/*.sh Makefile

posts/%.html: posts/%.rst ${build_tools} tagcloud.html template/* template/template_gen.txt
	@echo Building $@
	@title=$$(util/title.sh $<) ;\
	cat $< template/post_end.rst | \
		rst2html --stylesheet=template/html4css1.css \
			 --input-encoding=UTF-8 \
			 --title="$${title}" \
			 --template template/template_gen.txt \
			 --strip-comments  > $@ || echo Building $@ failed...

%.html: %.rst ${build_tools} tagcloud.html template/template_gen.txt
	@echo Building $@
	@rst2html \
		--stylesheet=template/html4css1.css \
		--template template/template_gen.txt \
		--input-encoding=UTF-8 \
		--strip-comments \
		$< $@

all: tagcloud.html index.html ${objects} me.html feed.xml feedvarnish.xml archive.html feedspew.xml feedtott.xml nesquik/index.html tags-p

nesquik/index.html: nesquik/index.rst Makefile
	@echo Building $@
	@rst2html $< $@

template/template_gen.txt: tagcloud.html template/template_top.txt template/template_bot.txt template/template_mid.txt
	cat template/template_top.txt template/template_mid.txt tagcloud.html template/template_bot.txt > $@

tagcloud.html: posts/*.rst ${build_tools} tags/Makefile
	@echo Building tag cloud
	@-rm tagcloud-old.html || true
	@-cp tagcloud.html tagcloud-old.html || true
	@./util/tag.sh

tags-p: tagcloud.html template/template_gen.txt
	${MAKE} -C tags/	

index.rst: tagcloud.html ${objects} template/template_gen.txt template/* ${build_tools}
	@echo Building index
	@./util/index.sh

archive.rst: posts/*rst ${build_tools}
	@echo Building archive
	@./util/mkarchive.sh

# Silly, really, but feed%.xml wont match just feed.xml
# At least not with my gnu make version.
feed%.xml: index.html ${build_tools}
	@echo Building feed $*
	@./util/feedbuilder.sh $*

feed.xml: index.html ${build_tools}
	@echo Building feed
	@./util/feedbuilder.sh

dist: all $(objects)
	-rsync --delete -L --exclude=varnishfoo.info --exclude=friday --exclude=.well-known/ -a ./ www.kly.no:public_html/
	


subsystems:
	@$(MAKE) -C blan
	@$(MAKE) -C presentations

.PHONY: dist html subsystems tags-p
