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