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)
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
15 cabal build $(CABAL_BUILD_FLAGS)
18 rm -f *.eventlog *.eventlog.* *.hp
20 cabal repl $(CABAL_REPL_FLAGS) $(project)
22 ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) $(project) $(addprefix --repl-options ,$(REPL_OPTIONS))'
24 ghciwatch $(GHCIWATCH_OPTIONS)
28 cabal test $(CABAL_TEST_FLAGS) \
29 --test-show-details always --test-options "$(TEST_OPTIONS)"
31 cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) $(project)-tests
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)"'
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" \
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
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) $<
55 %/accept: override TEST_OPTIONS += --golden-start
59 %/reset: override TEST_OPTIONS += --golden-reset
63 %/cover: override CABAL_TEST_FLAGS += --enable-coverage
69 cabal run $(CABAL_RUN_FLAGS)
71 cabal repl $(CABAL_REPL_FLAGS) exe:$(project) $(addprefix --repl-options ,$(REPL_OPTIONS))
73 ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) exe:$(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' --test ":main $(TEST_OPTIONS)"
75 app.eventlog app.prof:
76 cabal run $(CABAL_RUN_FLAGS) \
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
88 cabal haddock --haddock-css ocean --haddock-hyperlink-source
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)"
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" \
113 ! git tag --merged | grep -Fqx $(package)-$(version)
115 git tag -f $(package)-$(version)
116 git-chglog --output $@.new --tag-filter-pattern '$(package)-.*' $(package)-$(version)
120 git tag -d $(package)-$(version)
122 git commit -m 'doc: update `$@`'
123 tag: build ChangeLog.md
124 git tag -s -m $(package)-$(version) $(package)-$(version)
130 cabal haddock --haddock-for-hackage --enable-doc
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
140 publish: upload/publish
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'
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 {}
158 find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \
159 fourmolu --unsafe -q -o -XOverloadedLabels -o -XImportQualifiedPost --mode inplace {}
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