+PKGS := \
+ hjugement \
+ hjugement-protocol
+hjugement-protocol/test: TEST_FLAGS:=
+
+HS = $(shell find . -name '*.hs' -not -name 'HLint.hs')
cabal := $(shell find . -name '*.cabal' -print -quit)
-package := $(notdir ./$(cabal:.cabal=))
+QUICKCHECK_TESTS = 1000
+QUICKCHECK_MAXSIZE = 100
+TEST_FLAGS = --quickcheck-tests $(QUICKCHECK_TESTS) --quickcheck-max-size $(QUICKCHECK_MAXSIZE)
+BENCH_HTML_FLAGS = --output benchmarks/html/$(shell sed -ne 's/^version: *\(.*\)/\1/p' $p/$p.cabal).html
all: build
-build:
- stack $(STACK_FLAGS) build $(STACK_BUILD_FLAGS)
-
-.PHONY: test
-test:
- ! grep -q '^Test-Suite\>' $(cabal) || \
- { stack $(STACK_FLAGS) test $(STACK_TEST_FLAGS); }
+build: $(PKGS:=/build)
+%/build:
+ cd $* && stack $(STACK_FLAGS) build $(STACK_BUILD_FLAGS)
+.PHONY: $(PKGS) $(foreach p,$(PKGS),$(eval $p: $p/build))
-QUICKCHECK_FLAGS ?= --quickcheck-tests 10000 --quickcheck-max-size 1000
-%/quickcheck: STACK_TEST_FLAGS:=--test-arguments "$(QUICKCHECK_FLAGS)"
-%/quickcheck: %
-
+test: $(PKGS:=/test)
+define test
+$p/test:
+ ! grep -iq '^Test-Suite\>' $p/$p.cabal || \
+ { cd $p && stack $$(STACK_FLAGS) test --test-arguments "$$(TEST_FLAGS)" $$(STACK_TEST_FLAGS); }
+endef
+$(foreach p,$(PKGS),$(eval $(call test)))
-GHCID_TEST ?= "System.Environment.withArgs (words \"--color always\") main \`Control.Exception.finally\` putStrLn \"\x1b[m\""
-ghcid:
- ghcid \
+GHCID_TEST_ARGS ?=
+GHCID_TEST ?= ":main $(GHCID_TEST_ARGS)"
+ghcid: $(PKGS:=/ghcid)
+%/ghcid:
+ cd $* && ghcid \
--warnings \
- --command "stack ghci \
- $(package):lib \
- $(package):$(package)-test \
+ --command "stack $(STACK_FLAGS) $(GHCID_STACK_FLAGS) ghci $(GHCID_GHCI_FLAGS) \
+ $$(2>&1 stack ide targets | grep -v :test:) \
--ghci-options=-fobject-code" \
- --test $(GHCID_TEST)
+ --test $(GHCID_TEST) \
+ $(GHCID_FLAGS)
+
+bench: $(PKGS:=/bench)
+define bench
+$p/bench:
+ mkdir -p $p/benchmarks/html
+ ! grep -iq '^Benchmark\>' $p/$p.cabal || \
+ { cd $p && stack $$(STACK_FLAGS) bench \
+ --benchmark-arguments "$(call BENCH_HTML_FLAGS) $$(BENCH_FLAGS)" \
+ $$(STACK_BENCH_FLAGS); }
+endef
+$(foreach p,$(PKGS),$(eval $(call bench)))
-clean:
- stack $(STACK_FLAGS) clean $(STACK_CLEAN_FLAGS)
-cleaner:
- stack $(STACK_FLAGS) clean --full $(STACK_CLEAN_FLAGS)
+clean: $(PKGS:=/clean)
+cleaner: $(PKGS:=/cleaner)
+%/clean:
+ cd $* && stack $(STACK_FLAGS) clean $(STACK_CLEAN_FLAGS)
+%/cleaner:
+ cd $* && stack $(STACK_FLAGS) clean --full $(STACK_CLEAN_FLAGS)
+%/quickcheck: override QUICKCHECK_TESTS=10000
+%/quickcheck: override QUICKCHECK_MAXSIZE=1000
+%/quickcheck: %
+
%/fast: override STACK_BUILD_FLAGS+=--fast
%/fast: override STACK_HADDOCK_FLAGS+=--fast
%/fast: override STACK_TEST_FLAGS+=--fast
+%/fast: override QUICKCHECK_TESTS=100
+%/fast: override QUICKCHECK_MAXSIZE=100
%/fast: %
-doc:
- stack $(STACK_FLAGS) haddock $(STACK_HADDOCK_FLAGS)
+%/debug: override STACK_BUILD_FLAGS+=--flag $(cabal:.cabal=):debug
+%/debug: override STACK_TEST_FLAGS+=--flag $(cabal:.cabal=):debug
+%/debug: %
+
+
+%/accept: override STACK_TEST_ARGS+=--accept
+%/accept: %
+
+
+doc: $(PKGS:=/doc)
+%/doc:
+ cd $* && stack $(STACK_FLAGS) haddock $(STACK_HADDOCK_FLAGS)
%.html: %.md
markdown $*.md >$*.html
%.html/view: %.html
sensible-browser $*.html
-HLint.hs: $(shell find . -name '*.hs' -not -name 'HLint.hs')
+HLint.hs: $(HS)
sed -i -e '/^-- BEGIN: generated hints/,/^-- END: Generated by hlint/d' HLint.hs
echo '-- BEGIN: generated hints' >> HLint.hs
- hlint --find . | grep '^'infix | sort -u >> HLint.hs
+ hlint $(foreach p,$(PKGS),--find $p) | grep '^'infix | sort -u >> HLint.hs
echo '-- END: generated hints' >> HLint.hs
-lint: HLint.hs
- if hlint --quiet --report=hlint.html -XNoCPP \
- $(shell cabal-cargs --format=ghc --only=default_extensions --sourcefile=$(cabal)) $(HLINT_FLAGS) .; \
+lint: $(PKGS:=/lint) $(HS)
+%/lint: HLint.hs
+ cd $* && if hlint --quiet --report=hlint.html -XNoCPP \
+ $(shell cabal-cargs --format=ghc --only=default_extensions --sourcefile=$*) $(HLINT_FLAGS) .; \
then rm -f hlint.html; \
- else sensible-browser hlint.html & fi
+ else sensible-browser ./hlint.html & fi
-tag:
- name=$$(sed -ne 's/^name: *\(.*\)/\1/p' $(cabal)); \
- version=$$(sed -ne 's/^version: *\(.*\)/\1/p' $(cabal)); \
+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
-tar:
- stack $(STACK_FLAGS) sdist $(STACK_SDIST_FLAGS)
-upload:
- LANG=C stack $(STACK_FLAGS) upload $(STACK_UPLOAD_FLAGS) .
+tar: $(PKGS:=/tar)
+%/tar:
+ cd $* && stack $(STACK_FLAGS) sdist $(STACK_SDIST_FLAGS)
+upload: $(PKGS:=/upload)
+%/upload:
+ cd $* && LANG=C stack $(STACK_FLAGS) upload $(STACK_UPLOAD_FLAGS) .
.PHONY: stats
stats: