CTX  := $(wildcard text/*.ppf) # Preprocessor fodder
TXT  := $(wildcard text/*.txt) $(subst ppf,txt,${CTX})
TRAD := $(subst .txt,.an2,$(subst text,traditional,${TXT}))
XML  := $(subst .txt,.xml,$(subst text,xml,${TXT}))
CHKAN2K := $(subst .an2,.chk,$(subst traditional,chkan2k,${TRAD}))
XMLLINT := $(subst .xml,.lnt,$(subst xml/,xmllint/,${XML}))
FBILINT := $(subst .xml,.fbi,$(subst xml/,fbilint/,${XML}))
XMLRFC  := $(subst .xml,.rfc,$(subst xml/,xmlrfc/,${XML}))

all: traditional

clean:
	rm -f ${TRAD} ${XML}

txt: ${TXT}

traditional: ${TRAD}

xml: ${XML}

xmllint: ${XMLLINT}

fbilint: ${FBILINT}

xmlrfc: ${XMLRFC}

traditional/%.an2: text/%.txt
	txt2an2k $< $@

text/%.txt: text/%.ppf
	./tools/txtpp.pl < $< > $@

xml/%.xml: text/%.txt
	./tools/txt2xml.pl $< > $@

chkan2k: ${CHKAN2K}

chkan2k/%.chk: traditional/%.an2
	-chkan2k $< > $@ 2>&1

xmllint/%.lnt: xml/%.xml
	-xmllint --noout --huge --schema ../ansi-nist-itl-2011.iepd/XMLschemas/extension/example-extension.xsd $< > $@ 2>&1

fbilint/%.fbi: xml/%.xml
	-xmllint --noout --huge --schema ../fbi_ebts/xsd/fbi_ebts/3.0/fbi_ebts.xsd $< > $@ 2>&1

xmlrfc/%.rfc: xml/%.xml
	./tools/check-xml-completeness.pl < $< > $@