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