PKGS := symantic-grammar symantic-document symantic symantic-lib

all: build

build: $(PKGS:=/build)
%/build:
	cd $*; stack $(STACK_FLAGS) build $(STACK_BUILD_FLAGS)
.PHONY: $(PKGS) $(foreach p,$(PKGS),$(eval $p: $p/build))

test: $(PKGS:=/test)
%/test:
	! grep -q '^Test-Suite\>' $*/$*.cabal || \
	{ cd $*; stack $(STACK_FLAGS) test $(STACK_BUILD_FLAGS); }

clean: $(PKGS:=/clean)
%/clean:
	cd $*; stack $(STACK_FLAGS) clean --full

tag: $(PKGS:=/tag)
%/tag:
	cabal=$*/$*.cabal; \
	name=$$(sed -ne 's/^name: *\(.*\)/\1/p' "$$cabal"); \
	version=$$(sed -ne 's/^version: *\(.*\)/\1/p' "$$cabal"); \
	git tag --merged | grep -Fqx "$$name-$$version" || \
	git tag -f -s -m "$$name v$$version" $$name-$$version

.PHONY: stats
stats:
	gitstats . $@
stats/view: stats
	sensible-browser stats/index.html