allEntities = Organization AggOrg Occupation Degree Cip
theSpecs = $(foreach ent,$(allEntities),clientSpecs/EntitySpec.${ent}.json)
theIssues = $(foreach ent,$(allEntities),issues/${ent}.issues.json)

all: setup $(theIssues)

clean:
	rm -rf tmp
	rm -rf clientSpecs
	rm -rf issues

setup:
	mkdir -p tmp
	mkdir -p clientSpecs
	mkdir -p issues

tmp/header.csv:
	echo 'file:entity:loc:type' > $@

tmp/extractedfields.csv:
	./clientDataRequirements.sh | tr -d '\r'  > $@

tmp/clientSpec.json: tmp/header.csv tmp/extractedfields.csv
	cat tmp/header.csv tmp/extractedfields.csv | ripemunger -d -s \: > $@

$(theSpecs): tmp/clientSpec.json
	cat tmp/clientSpec.json | ripesplitter -o clientSpecs/entitySpec -s json -t value -k entity

$(theIssues): issues/%.issues.json: clientSpecs/EntitySpec.%.json $(theSpecs)
	ripediffspecs --spec dataSpecs/$*.spec.json --diffSpec $< --idField file | ripemunger -t ./consolidateErrors.xform.json > $@
