sources = $(shell find . -name "*.go" | grep -v [.]gen[.]go)

default: build

all: clean fmt build cover

build: $(sources) tags promote-to-tags
	go build

tags: \
	tag/block.gen.go \
	tag/inline.gen.go \
	tag/void.block.gen.go \
	tag/void.inline.gen.go \
	tag/inlinechildren.gen.go \
	tag/preformatted.gen.go \
	tag/script.gen.go
	go fmt tag/*

promote-to-tags: tag/promote.gen.go
	go fmt tag/*

tag/block.gen.go: $(sources) tag.block.txt
	go run script/generate-tags.go < tag.block.txt > tag/block.gen.go

tag/inline.gen.go: $(sources) tag.inline.txt
	go run script/generate-tags.go Inline < tag.inline.txt > tag/inline.gen.go

tag/inlinechildren.gen.go: $(sources) tag.inlinechildren.txt
	go run script/generate-tags.go InlineChildren < tag.inlinechildren.txt > tag/inlinechildren.gen.go

tag/void.block.gen.go: $(sources) tag.void.block.txt
	go run script/generate-tags.go Void < tag.void.block.txt > tag/void.block.gen.go

tag/void.inline.gen.go: $(sources) tag.void.inline.txt
	go run script/generate-tags.go Void Inline < tag.void.inline.txt > tag/void.inline.gen.go

tag/preformatted.gen.go: $(sources) tag.preformatted.txt
	go run script/generate-tags.go Preformatted < tag.preformatted.txt > tag/preformatted.gen.go

tag/script.gen.go: $(sources) tag.script.txt
	go run script/generate-tags.go ScriptContent < tag.script.txt > tag/script.gen.go

tag/promote.gen.go: $(sources) promote-to-tags.txt
	go run script/promote-to-tags.go < promote-to-tags.txt > tag/promote.gen.go

fmt: $(sources) tags
	go fmt ./...

check: $(sources) tags promote-to-tags
	go test -count 1

.cover: $(sources) tags promote-to-tags
	go test -count 1 -coverprofile .cover

cover: .cover
	go tool cover -func .cover

showcover: .cover
	go tool cover -html .cover

clean:
	go clean
	rm -f tag/*.gen.go
	rm .cover
