html: diffs head.html log.html index.html

.PHONY: html diffs

RST2HTML ?= rst2html

diffs: parents
	mkdir -p diff
	awk -f diffmake.awk <parents >diff/Makefile
	make -C diff

log: .bzr/branch/last-revision
	bzr log -n 0 --long --show-ids >log.new
	mv log.new log

parents: log
	awk -f parents.awk <log >parents.new
	mv parents.new parents

raw/.bzr/checkout/dirstate: .bzr/branch/last-revision
	set -x; if test -d raw; then \
		cd raw && bzr revert && bzr pull --overwrite .. && bzr up; \
	else \
		bzr co --lightweight . raw && cd raw; \
	fi && find -type f -executable -exec chmod -x '{}' +

files: .bzr/branch/last-revision
	bzr ls --recursive --versioned >files.new
	mv files.new files

files.txt: files raw/.bzr/checkout/dirstate
	cd raw && file -NF '	' -f ../files >../files.txt.new
	mv files.txt.new files.txt

files.mime: files raw/.bzr/checkout/dirstate
	cd raw && file -iNF '	' -f ../files >../files.mime.new
	mv files.mime.new files.mime

files.csv: files.txt files.mime render_files file_table
	./render_files
	./file_table >files.csv.new
	mv files.csv.new files.csv

head.html: files.csv head.rst
	$(RST2HTML) head.rst >head.html.new
	mv head.html.new head.html

log.html: log
	awk -f log.awk log | $(RST2HTML) >log.html.new
	mv log.html.new log.html

index.html: generate_index raw/.bzr/checkout/dirstate head.rst files.csv
	./generate_index | $(RST2HTML) >index.html.new
	mv index.html.new index.html