W=$(HOME)/w3ccvs/WWW
SWAP=$(W)/2000/10/swap
CWM=$(SWAP)/cwm.py
RST2HTML=rst2html

PYTHON=python

RDFS=$(SWAP)/util/rdfs-nice.n3
STD=$(SWAP)/util/owlth.n3 $(RDFS) owl2.n3
THEORIES=speech.n3 httpspeech.n3 httpsocial.n3 time.n3

.SUFFIXES: .html .rst .n3 .n3pf
.rst.html:
	$(RST2HTML) $< $@
.n3pf.rst:
	PYTHONPATH=$(SWAP)/.. \
		$(PYTHON) $(SWAP)/check.py --report $< \
		| perl -pe 's,file://'`/bin/pwd`'/,,g' >$@

.rst.n3:
	$(PYTHON) extract_rst_literals.py <$< >$@

all: hypertext proofs

hypertext: story.html refi_ex.html badmeta.html scriptorigin.html \
	httpspeech.html httpsocial.html speech.html mashup.html

proofs: refi-pf.html badmeta-pf.html xsrf-pf.html mash1-pf.html

clean:
	rm -f ,* *~
	rm -f *.n3pf *-pf.rst *-pf.html
	rm -f story.html
	rm -f refi_ex.{html,n3} badmeta.{html,n3} httpspeech.{html,n3}
	rm -f httpsocial.{html,n3} mashup.{n3,html} speech.{n3,html}
	rm -f scriptorigin.{html,n3}
	echo and time.{html,n3} and owl2.{html,n3}

# ugh! foo.{bar,baz} notation doesn't seem to work in the
# shell used by gnumake

httpspeech.html: httpsocial.rst
httpspeech.n3: httpsocial.rst

httpsocial.html: httpsocial.rst
httpsocial.n3: httpsocial.rst

scriptorigin.html: scriptorigin.rst
scriptorigin.n3: scriptorigin.rst

story.html: story.rst

refi-pf.html: refi-pf.rst

refi-pf.rst: refi-pf.n3pf

refi-pf.n3pf:  refi_ex.n3 refi_goal.n3 speech.n3
	$(PYTHON) $(CWM) refi_ex.n3 speech.n3 \
		--solve=refi_goal.n3 --why >$@

refi_ex.n3: refi_ex.rst

,refi_ex.n3: $(THEORIES) refi_ex.n3
	$(PYTHON) $(CWM) refi_ex.n3 $(STD) $(THEORIES) --think >$@

badmeta-pf.n3pf: badmeta.n3 $(THEORIES) contradiction.n3
	$(PYTHON) $(CWM) badmeta.n3 $(THEORIES) $(STD) \
		--solve=contradiction.n3 --why --n3=/ >$@

badmeta.n3: badmeta.rst extract_rst_literals.py
	$(PYTHON) extract_rst_literals.py <badmeta.rst >$@

,badmeta-closure.n3: badmeta.n3 $(THEORIES) contradiction.n3
	$(PYTHON) $(CWM) badmeta.n3 $(THEORIES) $(STD) \
		--think  --n3=/ >$@

,conneg-closure.n3:  $(STD) $(THEORIES) connegthm.n3
	$(PYTHON) $(CWM) $(STD) $(THEORIES) connegthm.n3 --think >$@

xsrf-pf.html: xsrf-pf.n3pf

xsrf-pf.n3pf: mashup.n3 speech.n3 xsrf-goal.n3 httpsocial.n3
	$(PYTHON) $(CWM) mashup.n3 speech.n3 httpsocial.n3 $(RDFS) \
		--solve=xsrf-goal.n3 --why >$@

mash1-pf.html: mash1-pf.n3pf

mash1-pf.n3pf: mash1-goal.n3 mashup.n3 scriptorigin.n3 speech.n3 \
		httpsocial.n3 httpspeech.n3
	$(PYTHON) $(CWM) mashup.n3 scriptorigin.n3 speech.n3 httpsocial.n3 \
		 httpspeech.n3 $(RDFS) --solve=mash1-goal.n3 --why >$@

,mashup-closure.n3: mashup.n3 scriptorigin.n3 speech.n3 httpsocial.n3 \
		httpspeech.n3 
	$(PYTHON) $(CWM) mashup.n3 speech.n3 httpsocial.n3  httpspeech.n3 \
		scriptorigin.n3 $(RDFS) \
		--think >$@

,pfbug-pf.rst: ,pfbug-pf.n3pf

,pfbug-pf.n3pf: pfbug.n3
	$(PYTHON) $(CWM) pfbug.n3 --think --why >$@

.PRECIOUS: badmeta-pf.rst refi-pf.rst xsrf-pf.rst
