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