]> Git — Sourcephile - haskell/logic.git/blob - Makefile
init
[haskell/logic.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 doc:
36 cabal haddock --haddock-css ocean --haddock-hyperlink-source
37
38 .PHONY: ChangeLog.md
39 ChangeLog.md:
40 ! git tag --merged | grep -Fqx $(package)-$(version)
41 git diff --exit-code
42 git tag -f $(package)-$(version)
43 git-chglog --output $@.new --tag-filter-pattern '$(package)-.*' $(package)-$(version)
44 touch $@
45 cat $@ >>$@.new
46 mv -f $@.new $@
47 git tag -d $(package)-$(version)
48 git add '$@'
49 git commit -m 'doc: update `$@`'
50 tag: build ChangeLog.md
51 git tag -s -m $(package)-$(version) $(package)-$(version)
52
53 tar:
54 git diff --exit-code
55 reuse lint
56 cabal sdist
57 cabal haddock --haddock-for-hackage --enable-doc
58 upload: LANG=C
59 upload: tar
60 git tag --merged | grep -Fqx $(package)-$(version)
61 git push --follow-tags $(GIT_PUSH_FLAGS)
62 cabal upload $(CABAL_UPLOAD_FLAGS) "$(cabal_builddir)"/sdist/$(package)-$(version).tar.gz
63 cabal upload $(CABAL_UPLOAD_FLAGS) --documentation "$(cabal_builddir)"/$(package)-$(version)-docs.tar.gz
64 %/publish: CABAL_UPLOAD_FLAGS+=--publish
65 %/publish: %
66
67 publish: upload/publish
68
69 .PHONY: .hlint.yaml
70 .hlint.yaml:
71 sed -i -e '/^# BEGIN: generated hints/,/^# END: generated hints/d' $@
72 echo >>$@ '# BEGIN: generated hints'
73 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
74 hlint --find {} | grep -- '- fixity:' | sort -u >>$@
75 echo >>$@ '# END: generated hints'
76 lint: .hlint.yaml
77 if hlint --quiet --report=hlint.html $(HLINT_FLAGS) $(sourceDirs); \
78 then rm -f hlint.html; \
79 else sensible-browser ./hlint.html & fi
80 lint/apply: .hlint.yaml
81 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
82 hlint --refactor-options="-i" --refactor {}
83
84 style:
85 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
86 fourmolu -q -o -XImportQualifiedPost --mode inplace {}
87 cabal-fmt -i *.cabal