MD_FILE := InCommon-metadata.xml
MD_URL := https://mdq.incommon.org/entities/all

OUTPUT_FILES := all-entities.out inc-entities.out inc-unique-public-emails.out inc-unique-saml-https-hosts-ports.out inc-unique-ui-urls.out

define newline


endef

.PHONY: all
all: $(OUTPUT_FILES)
	$(foreach output_file,$^,@wc -l $(output_file)$(newline))

.PHONY: clean
clean:
	rm -f $(OUTPUT_FILES)
	rm -f $(MD_FILE)

$(MD_FILE):
	curl -o $(MD_FILE) $(MD_URL)

all-entities.out inc-entities.out: $(@:.out=.xsl) $(MD_FILE)
	xsltproc $(@:.out=.xsl) $(MD_FILE) > $@

inc-unique-public-emails.out: inc-email-urls.xsl $(MD_FILE)
	xsltproc $< $(MD_FILE) | sed -e 's/^mailto://' | sort -u > $@

inc-unique-saml-https-hosts-ports.out: inc-saml-urls.xsl $(MD_FILE)
	xsltproc $< $(MD_FILE) | grep '^https://' | awk -F'/' '{print $$3}' | sort -u > $@

inc-unique-ui-urls.out: inc-ui-urls.xsl $(MD_FILE)
	xsltproc $< $(MD_FILE) | sort -u > $@