]> Git — Sourcephile - julm/worksheets.git/blob - Makefile
maint: code cleaning
[julm/worksheets.git] / Makefile
1 cabal := $(wildcard *.cabal)
2 package := $(notdir ./$(cabal:.cabal=))
3 version := $(shell sed -ne 's/^version: *\(.*\)/\1/p' $(cabal))
4 project := $(patsubst %.cabal,%,$(cabal))
5 cabal_builddir ?= dist-newstyle
6 sourceDirs := $(wildcard src tests app)
7
8 override REPL_OPTIONS += -ignore-dot-ghci
9 override GHCID_OPTIONS += --no-height-limit --reverse-errors --color=always --restart $(cabal) --warnings
10 override GHCIWATCH_OPTIONS += --watch src
11
12 all: build
13 build:
14 cabal build $(CABAL_BUILD_FLAGS)
15 clean c:
16 cabal clean
17 repl:
18 cabal repl $(CABAL_REPL_FLAGS) $(project)
19 ghcid:
20 ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) $(project) $(addprefix --repl-options ,$(REPL_OPTIONS))'
21 ghciwatch:
22 ghciwatch $(GHCIWATCH_OPTIONS)
23
24 .PHONY: tests
25 t tests:
26 cabal test $(CABAL_TEST_FLAGS) \
27 --test-show-details always --test-options "$(TEST_OPTIONS)"
28 t/repl tests/repl:
29 cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) $(project)-tests
30 t/ghcid tests/ghcid:
31 ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) $(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' \
32 --run=':! ghcid $(GHCID_OPTIONS) --command "cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) $(project)-tests" --test ":main $(TEST_OPTIONS)"'
33
34 x exe:
35 cabal run exe:$(project) $(CABAL_RUN_FLAGS) -- $(EXE_OPTIONS)
36 x/repl exe/repl:
37 cabal repl $(CABAL_REPL_FLAGS) exe:$(project) $(addprefix --repl-options ,$(REPL_OPTIONS))
38 x/ghcid exe/ghcid:
39 ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) exe:$(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' --test ":main $(TEST_OPTIONS)"
40
41 %/accept: TEST_OPTIONS += --golden-start
42 %/accept: %
43
44
45 %/reset: TEST_OPTIONS += --golden-reset
46 %/reset: %
47
48
49 doc:
50 cabal haddock --haddock-css ocean --haddock-hyperlink-source
51
52 .PHONY: ChangeLog.md
53 ChangeLog.md:
54 ! git tag --merged | grep -Fqx $(package)-$(version)
55 git diff --exit-code
56 git tag -f $(package)-$(version)
57 git-chglog --output $@.new --tag-filter-pattern '$(package)-.*' $(package)-$(version)
58 touch $@
59 cat $@ >>$@.new
60 mv -f $@.new $@
61 git tag -d $(package)-$(version)
62 git add '$@'
63 git commit -m 'doc: update `$@`'
64 tag: build ChangeLog.md
65 git tag -s -m $(package)-$(version) $(package)-$(version)
66
67 tar:
68 git diff --exit-code
69 reuse lint
70 cabal sdist
71 cabal haddock --haddock-for-hackage --enable-doc
72 upload: LANG=C
73 upload: tar
74 git tag --merged | grep -Fqx $(package)-$(version)
75 git push --follow-tags $(GIT_PUSH_FLAGS)
76 cabal upload $(CABAL_UPLOAD_FLAGS) "$(cabal_builddir)"/sdist/$(package)-$(version).tar.gz
77 cabal upload $(CABAL_UPLOAD_FLAGS) --documentation "$(cabal_builddir)"/$(package)-$(version)-docs.tar.gz
78 %/publish: CABAL_UPLOAD_FLAGS+=--publish
79 %/publish: %
80
81 publish: upload/publish
82
83 .PHONY: .hlint.yaml
84 .hlint.yaml:
85 sed -i -e '/^# BEGIN: generated hints/,/^# END: generated hints/d' $@
86 echo >>$@ '# BEGIN: generated hints'
87 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
88 hlint --find {} | grep -- '- fixity:' | sort -u >>$@
89 echo >>$@ '# END: generated hints'
90 lint: .hlint.yaml
91 if hlint --quiet --report=hlint.html $(HLINT_FLAGS) $(sourceDirs); \
92 then rm -f hlint.html; \
93 else sensible-browser ./hlint.html & fi
94 lint/apply: .hlint.yaml
95 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
96 hlint --refactor-options="-i" --refactor {}
97
98 style:
99 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
100 fourmolu -q -o -XOverloadedLabels -o -XImportQualifiedPost --mode inplace {}
101 cabal-fmt -i *.cabal