]> Git — Sourcephile - julm/worksheets.git/blob - Makefile
update
[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 benchmarks)
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 GHC_EVENTLOG_FLAGS := -agu
12
13 all: build
14 build:
15 cabal build $(CABAL_BUILD_FLAGS)
16 clean c:
17 cabal clean
18 rm -f *.eventlog *.eventlog.* *.hp
19 repl:
20 cabal repl $(CABAL_REPL_FLAGS) $(project)
21 ghcid:
22 ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) $(project) $(addprefix --repl-options ,$(REPL_OPTIONS))'
23 ghciwatch:
24 ghciwatch $(GHCIWATCH_OPTIONS)
25
26 .PHONY: tests
27 t tests:
28 cabal test $(CABAL_TEST_FLAGS) \
29 --test-show-details always --test-options "$(TEST_OPTIONS)"
30 t/repl tests/repl:
31 cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) $(project)-tests
32 t/ghcid tests/ghcid:
33 ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) $(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' \
34 --run=':! ghcid $(GHCID_OPTIONS) --command "cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) $(project)-tests" --test ":main $(TEST_OPTIONS)"'
35
36 .PHONY: tests.eventlog
37 tests.eventlog tests.prof:
38 cabal test $(CABAL_TEST_FLAGS) \
39 --test-show-details always --test-options "$(TEST_OPTIONS) +RTS $(RTS_OPTIONS) -oltests.eventlog" \
40 --enable-profiling
41 t/prof-cost tests/prof-cost: override RTS_OPTIONS += -hc
42 t/prof-cost tests/prof-cost: tests.eventlog.html
43 t/prof-heap tests/prof-heap: override RTS_OPTIONS += -hy
44 t/prof-heap tests/prof-heap: tests.eventlog.html
45 t/prof-time tests/prof-time: override RTS_OPTIONS += -p
46 t/prof-time tests/prof-time: tests.eventlog.html
47
48 %.eventlog.html: override RTS_OPTIONS += -l$(GHC_EVENTLOG_FLAGS)
49 %.eventlog.html: %.eventlog
50 eventlog2html $(EVENTLOG_FLAGS) $<
51 %.eventlog.json: override RTS_OPTIONS += -l$(GHC_EVENTLOG_FLAGS)
52 %.eventlog.json: %.eventlog
53 hs-speedscope $(HS_SPEEDSCOPE_FLAGS) $<
54
55 %/accept: override TEST_OPTIONS += --golden-start
56 %/accept: %
57
58
59 %/reset: override TEST_OPTIONS += --golden-reset
60 %/reset: %
61
62
63 %/cover: override CABAL_TEST_FLAGS += --enable-coverage
64 %/cover: %
65
66
67 .PHONY: app
68 x app:
69 cabal run $(CABAL_RUN_FLAGS)
70 x/repl app/repl:
71 cabal repl $(CABAL_REPL_FLAGS) exe:$(project) $(addprefix --repl-options ,$(REPL_OPTIONS))
72 x/ghcid app/ghcid:
73 ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) exe:$(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' --test ":main $(TEST_OPTIONS)"
74 .PHONY: app.eventlog
75 app.eventlog app.prof:
76 cabal run $(CABAL_RUN_FLAGS) \
77 --enable-profiling \
78 exe:$(project) \
79 -- +RTS $(RTS_OPTIONS) -olapp.eventlog
80 x/prof-cost app/prof-cost: override RTS_OPTIONS += -hc
81 x/prof-cost app/prof-cost: app.eventlog.html
82 x/prof-heap app/prof-heap: override RTS_OPTIONS += -hy
83 x/prof-heap app/prof-heap: app.eventlog.html
84 x/prof-time app/prof-time: override RTS_OPTIONS += -p
85 x/prof-time app/prof-time: app.eventlog.html
86
87 doc:
88 cabal haddock --haddock-css ocean --haddock-hyperlink-source
89
90 .PHONY: benchmarks/html/$(version).html
91 b benchmarks: benchmarks/html/$(version).html
92 benchmarks/html/$(version).html:
93 mkdir -p benchmarks/html
94 cabal bench $(CABAL_BENCH_FLAGS) --benchmark-options "$(BENCHMARK_OPTIONS)"
95 benchmarks/repl:
96 cabal repl $(CABAL_REPL_FLAGS) --enable-benchmarks $(project)-benchmark
97 b/prof-cost benchmarks/prof-cost: override RTS_OPTIONS += -hc
98 b/prof-cost benchmarks/prof-cost: benchmarks.eventlog.html
99 b/prof-heap benchmarks/prof-heap: override RTS_OPTIONS += -hy
100 b/prof-heap benchmarks/prof-heap: benchmarks.eventlog.html
101 b/prof-time benchmarks/prof-time: override RTS_OPTIONS += -p
102 b/prof-time benchmarks/prof-time: benchmarks.eventlog.json
103 .PHONY: benchmarks.eventlog
104 benchmarks.eventlog benchmarks.prof:
105 @echo "$$(tput setaf 1)WARNING: benchmarking with --enable-profiling can create significant biases$$(tput sgr0)"
106 cabal bench $(CABAL_BENCH_FLAGS) \
107 --benchmark-options "$(BENCHMARK_OPTIONS) +RTS $(RTS_OPTIONS) -olbenchmarks.eventlog" \
108 --enable-profiling
109
110
111 .PHONY: ChangeLog.md
112 ChangeLog.md:
113 ! git tag --merged | grep -Fqx $(package)-$(version)
114 git diff --exit-code
115 git tag -f $(package)-$(version)
116 git-chglog --output $@.new --tag-filter-pattern '$(package)-.*' $(package)-$(version)
117 touch $@
118 cat $@ >>$@.new
119 mv -f $@.new $@
120 git tag -d $(package)-$(version)
121 git add '$@'
122 git commit -m 'doc: update `$@`'
123 tag: build ChangeLog.md
124 git tag -s -m $(package)-$(version) $(package)-$(version)
125
126 tar:
127 git diff --exit-code
128 reuse lint
129 cabal sdist
130 cabal haddock --haddock-for-hackage --enable-doc
131 upload: LANG=C
132 upload: tar
133 git tag --merged | grep -Fqx $(package)-$(version)
134 git push --follow-tags $(GIT_PUSH_FLAGS)
135 cabal upload $(CABAL_UPLOAD_FLAGS) "$(cabal_builddir)"/sdist/$(package)-$(version).tar.gz
136 cabal upload $(CABAL_UPLOAD_FLAGS) --documentation "$(cabal_builddir)"/$(package)-$(version)-docs.tar.gz
137 %/publish: override CABAL_UPLOAD_FLAGS += --publish
138 %/publish: %
139
140 publish: upload/publish
141
142 .PHONY: .hlint.yaml
143 .hlint.yaml:
144 sed -i -e '/^# BEGIN: generated hints/,/^# END: generated hints/d' $@
145 echo >>$@ '# BEGIN: generated hints'
146 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
147 hlint --find {} | grep -- '- fixity:' | sort -u >>$@
148 echo >>$@ '# END: generated hints'
149 lint: .hlint.yaml
150 if hlint --quiet --report=hlint.html $(HLINT_FLAGS) $(sourceDirs); \
151 then rm -f hlint.html; \
152 else sensible-browser ./hlint.html & fi
153 lint/apply: .hlint.yaml
154 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
155 hlint --refactor-options="-i" --refactor {}
156
157 style:
158 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
159 fourmolu --unsafe -q -o -XOverloadedLabels -o -XImportQualifiedPost --mode inplace {}
160 cabal-fmt -i *.cabal
161
162 .PHONY: .radicle
163 .radicle:
164 direnv allow
165 rad auth
166 git config user.signingKey "$$(rad self --ssh-key)"
167 git config gpg.format ssh
168 git config gpg.ssh.program ssh-keygen
169 git config gpg.ssh.allowedSignersFile .gitsigners
170 git config commit.gpgsign true