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