]> Git — Sourcephile - majurity.git/blob - GNUmakefile
protocol: add benchmarks
[majurity.git] / GNUmakefile
1 PKGS := \
2 hjugement \
3 hjugement-protocol
4 hjugement-protocol/test: TEST_FLAGS:=
5
6 HS = $(shell find . -name '*.hs' -not -name 'HLint.hs')
7 cabal := $(shell find . -name '*.cabal' -print -quit)
8 QUICKCHECK_TESTS = 1000
9 QUICKCHECK_MAXSIZE = 100
10 TEST_FLAGS = --quickcheck-tests $(QUICKCHECK_TESTS) --quickcheck-max-size $(QUICKCHECK_MAXSIZE)
11 BENCH_HTML_FLAGS = --output benchmarks/html/$(shell sed -ne 's/^version: *\(.*\)/\1/p' $p/$p.cabal).html
12
13 all: build
14
15 build: $(PKGS:=/build)
16 %/build:
17 cd $* && stack $(STACK_FLAGS) build $(STACK_BUILD_FLAGS)
18 .PHONY: $(PKGS) $(foreach p,$(PKGS),$(eval $p: $p/build))
19
20 test: $(PKGS:=/test)
21 define test
22 $p/test:
23 ! grep -iq '^Test-Suite\>' $p/$p.cabal || \
24 { cd $p && stack $$(STACK_FLAGS) test --test-arguments "$$(TEST_FLAGS)" $$(STACK_TEST_FLAGS); }
25 endef
26 $(foreach p,$(PKGS),$(eval $(call test)))
27
28 GHCID_TEST_ARGS ?=
29 GHCID_TEST ?= ":main $(GHCID_TEST_ARGS)"
30 ghcid: $(PKGS:=/ghcid)
31 %/ghcid:
32 cd $* && ghcid \
33 --warnings \
34 --command "stack $(STACK_FLAGS) $(GHCID_STACK_FLAGS) ghci $(GHCID_GHCI_FLAGS) \
35 $$(2>&1 stack ide targets | grep -v :test:) \
36 --ghci-options=-fobject-code" \
37 --test $(GHCID_TEST) \
38 $(GHCID_FLAGS)
39
40 bench: $(PKGS:=/bench)
41 define bench
42 $p/bench:
43 mkdir -p $p/benchmarks/html
44 ! grep -iq '^Benchmark\>' $p/$p.cabal || \
45 { cd $p && stack $$(STACK_FLAGS) bench \
46 --benchmark-arguments "$(call BENCH_HTML_FLAGS) $$(BENCH_FLAGS)" \
47 $$(STACK_BENCH_FLAGS); }
48 endef
49 $(foreach p,$(PKGS),$(eval $(call bench)))
50
51 clean: $(PKGS:=/clean)
52 cleaner: $(PKGS:=/cleaner)
53 %/clean:
54 cd $* && stack $(STACK_FLAGS) clean $(STACK_CLEAN_FLAGS)
55 %/cleaner:
56 cd $* && stack $(STACK_FLAGS) clean --full $(STACK_CLEAN_FLAGS)
57
58 %/quickcheck: override QUICKCHECK_TESTS=10000
59 %/quickcheck: override QUICKCHECK_MAXSIZE=1000
60 %/quickcheck: %
61
62 %/fast: override STACK_BUILD_FLAGS+=--fast
63 %/fast: override STACK_HADDOCK_FLAGS+=--fast
64 %/fast: override STACK_TEST_FLAGS+=--fast
65 %/fast: override QUICKCHECK_TESTS=100
66 %/fast: override QUICKCHECK_MAXSIZE=100
67 %/fast: %
68
69
70 %/debug: override STACK_BUILD_FLAGS+=--flag $(cabal:.cabal=):debug
71 %/debug: override STACK_TEST_FLAGS+=--flag $(cabal:.cabal=):debug
72 %/debug: %
73
74
75 %/accept: override STACK_TEST_ARGS+=--accept
76 %/accept: %
77
78
79 doc: $(PKGS:=/doc)
80 %/doc:
81 cd $* && stack $(STACK_FLAGS) haddock $(STACK_HADDOCK_FLAGS)
82 %.html: %.md
83 markdown $*.md >$*.html
84 %.html/view: %.html
85 sensible-browser $*.html
86
87 HLint.hs: $(HS)
88 sed -i -e '/^-- BEGIN: generated hints/,/^-- END: Generated by hlint/d' HLint.hs
89 echo '-- BEGIN: generated hints' >> HLint.hs
90 hlint $(foreach p,$(PKGS),--find $p) | grep '^'infix | sort -u >> HLint.hs
91 echo '-- END: generated hints' >> HLint.hs
92
93 lint: $(PKGS:=/lint) $(HS)
94 %/lint: HLint.hs
95 cd $* && if hlint --quiet --report=hlint.html -XNoCPP \
96 $(shell cabal-cargs --format=ghc --only=default_extensions --sourcefile=$*) $(HLINT_FLAGS) .; \
97 then rm -f hlint.html; \
98 else sensible-browser ./hlint.html & fi
99
100 tag: $(PKGS:=/tag)
101 %/tag:
102 cabal=$*/$*.cabal; \
103 name=$$(sed -ne 's/^name: *\(.*\)/\1/p' "$$cabal"); \
104 version=$$(sed -ne 's/^version: *\(.*\)/\1/p' "$$cabal"); \
105 git tag --merged | grep -Fqx "$$name-$$version" || \
106 git tag -f -s -m "$$name v$$version" $$name-$$version
107
108 tar: $(PKGS:=/tar)
109 %/tar:
110 cd $* && stack $(STACK_FLAGS) sdist $(STACK_SDIST_FLAGS)
111 upload: $(PKGS:=/upload)
112 %/upload:
113 cd $* && LANG=C stack $(STACK_FLAGS) upload $(STACK_UPLOAD_FLAGS) .
114
115 .PHONY: stats
116 stats:
117 gitstats . $@
118 stats/view: stats
119 sensible-browser stats/index.html