
all : ../o/t/index.json ../o/p/index.xml ../o/p/url.cdb ../o/p/url.old.cdb ../o/p/t.cdb ../o/p/t.old.cdb

clean :
	find ../o -type f -delete

../o/p/id.cdb : $(wildcard var/db/p/*.s)
	awk '/\(id / {printf "%s ", $$2} /\(link / {print $$2}' $^ | tr -d '")' | cdb -cem $@

../o/p/id.old.cdb : $(wildcard var/db/p-*.s)
	awk '/\(id / {printf "%s ", $$2} /\(link / {print $$2}' $^ | tr -d '")' | cdb -cem $@

../o/p/url.cdb : ../o/p/id.cdb
	cdb -dm $^ | awk '// {print $$2, $$1}' | cdb -cem $@

../o/p/url.old.cdb : ../o/p/id.old.cdb
	cdb -dm $^ | awk '// {print $$2, $$1}' | cdb -cem $@

../o/p/t.cdb : $(wildcard var/db/p/*.s)
	fgrep ' (categories ' $^ | tr -d ')' | tr ' ' '\n' | fgrep -v '(categories' | sort | uniq -c | awk 'NR>1{print $$2, " ", $$1}' | cdb -cem $@

../o/p/t.old.cdb : $(wildcard var/db/p-*.s)
	fgrep ' (categories ' $^ | tr -d ')' | tr ' ' '\n' | fgrep -v '(categories' | sort | uniq -c | awk 'NR>1{print $$2, " ", $$1}' | cdb -cem $@

../o/p/.count : ../o/p/id.cdb ../o/p/id.old.cdb
	cdb -s ../o/p/id.cdb | awk '/number of records:/ {print $$4}' > $@

../o/.head.xml : etc/config.s ../o/p/.count
	cat $^ > $@

../o/t/index.json : ../o/p/t.old.cdb ../o/p/t.cdb
	cdb -lm ../o/p/t.cdb > $@
	cdb -lm ../o/p/t.old.cdb >> $@

../o/p/index.xml : ../o/.head.xml $(wildcard var/db/p/*.s)
	cat $^ > $@
