#  Makefile for circles-and-arrows diagrams of W3C structure etc
#
#  There are two principal sorts of data:
#
# Technical goals and dependencies on specs
#    - master rule file:  all.n3
#    - data in w3c.n3  etc -- see $(W3C)
#    - style in style.n3
# Organisational structure is extracted by Dan's magic in $(MEMNEWS)
#    - master rule file: structure.n3
#    - structure-sync a combination of the files
#    - style also in structure.n3
#
# 

W=../../..
# Dan Connolly's process diagram stuff
PD=$(W)/2001/02pd/

#XT=~connolly/src/xtdebug
#XT=~connolly/src/xt
#XSLT=/cygdrive/c/winnt/system32/sabcmd

DOT=../../../2000/10/swap/test/viz/dot.exe

# From sw-team irc dancon 2002/11/13
JAVA=java
SAXONJAR=/usr/share/java/saxon.jar # debian package lib-saxon-java
SAXONCMD=CLASSPATH=$(SAXONJAR) $(JAVA) com.icl.saxon.StyleSheet
# saxon 1-6 syntax:
# java com.icl.saxon.StyleSheet [options] source-document   stylesheet   [ params…]
#
# saxon 7 syntax:
# java net.sf.saxon.Transform [options] source-document   stylesheet   [ params…]
# 
# xsltproc syntax:
# xsltproc [options] stylesheet file [file ...] 
#
RM=rm

MEMNEWS=$(W)/2000/04/mem-news

#include $(PD)XSLT.mak
include $(PD)GVDOT.mak

PYTHON=python
SWAP=$(W)/2000/10/swap
CWM=$(SWAP)/cwm.py

W3C=w3c.n3 ontaria.n3
.SUFFIXES: .svg .dot .graph .xgraph .rdg .rdf .n3 .graffle3 .graffle

.graffle.graffle3:
	xsltproc $(SWAP)/util/plist2rdf.xsl $<  | $(CWM) --rdf --n3  > $@

.graffle3.n3:
	$(CWM) $< --filter=graffle2rm.n3 --with $@ > $@
.n3.graph:
	$(PYTHON) $(CWM) $< $(W3C) style.n3 -think -purge > $@
# Do not confuse with .rdg in this directory, which is more procesed
.n3.rdf:
	$(PYTHON) $(CWM) --n3 $< --rdf > $@

.n3.xgraph:
	$(PYTHON) $(CWM) $< $(W3C) style.n3 -think -purge --rdf > $@

#.graph.dot:
#	TARGET=$< $(PYTHON) $(CWM) $(SWAP)/util/todot.n3 -think --strings | sed -f $(SWAP)/util/fix-amp.sed > $@
# fix-amp.sed is a total kludge because the SVG generation in Graphviz doesn't do "&" properly.


.n3.rdg:
	$(PYTHON) $(CWM) -n3 $< $(W3C) style.n3 org-style.n3 -think -purge  -bySubject --rdf=c  > $@

.xgraph.dot:
#	$(SAXONCMD) $< $(PD)rdf2dot.xsl > $@
	xsltproc $(PD)rdf2dot.xsl  $< > $@

#	TARGET=$< $(PYTHON) $(CWM) $(SWAP)/util/todot.n3 --think --strings > $@
#	$(XSLT) $< $(PD)rdf2dot.xsl  $@
#	$(XSLT) $(PD)rdf2dot.xsl  $< $@

GENERATED=how-why.svg structure.svg all.dot all.ps all.svg all.png  \
	goals.svg eb.png eb.gif eb.svg annotea.svg sw.svg ws.svg \
	swws.svg about.svg about.png about.gif

all: errors.n3 how-why.svg all.svg make.svg vocab.rdf

deep:
	(cd $(MEMNEWS); cvs update; make)
	make all
	touch deep

errors.n3 : dangling.n3 aggregate.n3
	$(PYTHON) $(CWM) aggregate.n3 --filter=dangling.n3 > $@

structure-sync.graph: structure.n3 $(MEMNEWS)/groups.rdf $(W3C) style.n3 $(SWAP)/test/sameThing.n3 $(SWAP)/test/forgetDups.n3 $(SWAP)/pim/contact.n3
	$(PYTHON) $(CWM) --rdf $(MEMNEWS)/groups.rdf --n3 structure.n3 $(W3C) style.n3 $(SWAP)/pim/contact.n3 $(SWAP)/test/sameThing.n3 --think --apply=$(SWAP)/test/forgetDups.n3 --purge > $@

aggregate.n3:  $(MEMNEWS)/groups.rdf $(W3C) deliverables.n3 \
			$(SWAP)/util/smush-rules.n3 \
			$(SWAP)/pim/contact.n3
	$(PYTHON) $(CWM) --closure=e --rdf $(MEMNEWS)/groups.rdf --n3  $(W3C) deliverables.n3\
		$(SWAP)/pim/contact.n3 $(SWAP)/util/smush-rules.n3 --think  > $@

#aggregate.n3:  $(MEMNEWS)/groups.rdf $(W3C) deliverables.n3 $(SWAP)/test/sameThing.n3 \
#		$(SWAP)/test/forgetDups.n3 $(SWAP)/pim/contact.n3
#	$(PYTHON) $(CWM) --closure=e --rdf $(MEMNEWS)/groups.rdf --n3  $(W3C) deliverables.n3 $(SWAP)/pim/contact.n3 $(SWAP)/test/sameThing.n3 --think --apply=$(SWAP)/test/forgetDups.n3 --purge > $@

# Everything;
how-why.xgraph: how-why.n3 aggregate.n3 style.n3 org-style.n3
	$(PYTHON) $(CWM) how-why.n3 aggregate.n3 style.n3 org-style.n3 --think --data --rdf > $@

# Just org structure:
structure.xgraph: structure.n3 aggregate.n3 style.n3 org-style.n3
	$(PYTHON) $(CWM) structure.n3 aggregate.n3 style.n3 org-style.n3 --think --rdf > $@


# fix-amp.sed is a total kludge because the SVG generation in Graphviz doesn't do "&" properly.
#structure-sync.dot : structure-sync.graph
#	$(PYTHON) $(CWM) structure-sync.graph todot.n3 -think -strings | sed -f fix-amp.sed > structure-sync.dot

structure-sync.rdg: structure.n3 $(MEMNEWS)/groups.rdf $(W3C) style.n3 $(SWAP)/test/sameThing.n3 $(SWAP)/test/forgetDups.n3 $(SWAP)/pim/contact.n3
	$(PYTHON) $(CWM) --rdf $(MEMNEWS)/groups.rdf --n3 structure.n3 $(W3C) style.n3 $(SWAP)/pim/contact.n3 $(SWAP)/test/sameThing.n3 --think --apply=$(SWAP)/test/forgetDups.n3 --purge  --bySubject --rdf="c" > $@

clean:
	$(RM) $(GENERATED) goals.rdg *.dot *.ps *.svg *.png

#all.rdg: all.n3 $(W3C) style.n3 ../../02pd/rdf2dot.xsl

all.graph: all.n3 $(W3C) style.n3 $(SWAP)/util/todot.n3

all.xgraph: all.n3 $(W3C) style.n3

#	$(PYTHON) $(CWM) all.n3 $(W3C) style.n3 -think -purge -bySubject -rdf >$@

ws.rdg: ws.n3 $(W3C) style.n3 ../../02pd/rdf2dot.xsl

sw.rdg: sw.n3 $(W3C) style.n3 ../../02pd/rdf2dot.xsl

goals.rdg: goals.n3 $(W3C) style.n3 ../../02pd/rdf2dot.xsl


#swws.dot: swws.rdg
#	sabcmd ../../02pd/rdf2dot.xsl swws.rdg >$@


#  Organization structure stuff:

groups.rdg: ../../../Member/Mail/Overview.html groups.xsl
	sabcmd groups.xsl ../../../Member/Mail/Overview.html >$@

# Should come from ../../../2000/04/mem-news/groups.rdf or http://...
groups1.n3: 
	$(PYTHON) $(CWM) -rdf groups0.rdf -n3 > $@

######## Makefile itself:

make.n3 : Makefile $W/2000/10/swap/util/make2n3.py
	$(PYTHON) $W/2000/10/swap/util/make2n3.py Makefile > $@

make.graph: make.n3 make-style.n3
	$(PYTHON) $(CWM) make.n3 make-style.n3 --think >$@
make.xgraph: make.n3 make-style.n3
	$(PYTHON) $(CWM) make.n3 make-style.n3 --think --rdf >$@

make.svg: make.xgraph

#ends

