cabal := $(wildcard *.cabal) package := $(notdir ./$(cabal:.cabal=)) version := $(shell sed -ne 's/^version: *\(.*\)/\1/p' $(cabal)) project := $(patsubst %.cabal,%,$(cabal)) cabal_builddir ?= dist-newstyle sourceDirs := $(wildcard src tests app benchmarks) override REPL_OPTIONS += -ignore-dot-ghci override GHCID_OPTIONS += --no-height-limit --reverse-errors --color=always --restart $(cabal) --warnings override GHCIWATCH_OPTIONS += --watch src GHC_EVENTLOG_FLAGS := -agu all: build build: cabal build $(CABAL_BUILD_FLAGS) clean c: cabal clean rm -f *.eventlog *.eventlog.* *.hp repl: cabal repl $(CABAL_REPL_FLAGS) $(project) ghcid: ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) $(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' ghciwatch: ghciwatch $(GHCIWATCH_OPTIONS) .PHONY: tests t tests: cabal test $(CABAL_TEST_FLAGS) \ --test-show-details always --test-options "$(TEST_OPTIONS)" t/repl tests/repl: cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) $(project)-tests t/ghcid tests/ghcid: ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) $(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' \ --run=':! ghcid $(GHCID_OPTIONS) --command "cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) $(project)-tests" --test ":main $(TEST_OPTIONS)"' .PHONY: tests.eventlog tests.eventlog tests.prof: cabal test $(CABAL_TEST_FLAGS) \ --test-show-details always --test-options "$(TEST_OPTIONS) +RTS $(RTS_OPTIONS) -oltests.eventlog" \ --enable-profiling t/prof-cost tests/prof-cost: override RTS_OPTIONS += -hc t/prof-cost tests/prof-cost: tests.eventlog.html t/prof-heap tests/prof-heap: override RTS_OPTIONS += -hy t/prof-heap tests/prof-heap: tests.eventlog.html t/prof-time tests/prof-time: override RTS_OPTIONS += -p t/prof-time tests/prof-time: tests.eventlog.html %.eventlog.html: override RTS_OPTIONS += -l$(GHC_EVENTLOG_FLAGS) %.eventlog.html: %.eventlog eventlog2html $(EVENTLOG_FLAGS) $< %.eventlog.json: override RTS_OPTIONS += -l$(GHC_EVENTLOG_FLAGS) %.eventlog.json: %.eventlog hs-speedscope $(HS_SPEEDSCOPE_FLAGS) $< %/accept: override TEST_OPTIONS += --golden-start %/accept: % %/reset: override TEST_OPTIONS += --golden-reset %/reset: % %/cover: override CABAL_TEST_FLAGS += --enable-coverage %/cover: % .PHONY: app x app: cabal run $(CABAL_RUN_FLAGS) x/repl app/repl: cabal repl $(CABAL_REPL_FLAGS) exe:$(project) $(addprefix --repl-options ,$(REPL_OPTIONS)) x/ghcid app/ghcid: ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) exe:$(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' --test ":main $(TEST_OPTIONS)" .PHONY: app.eventlog app.eventlog app.prof: cabal run $(CABAL_RUN_FLAGS) \ --enable-profiling \ exe:$(project) \ -- +RTS $(RTS_OPTIONS) -olapp.eventlog x/prof-cost app/prof-cost: override RTS_OPTIONS += -hc x/prof-cost app/prof-cost: app.eventlog.html x/prof-heap app/prof-heap: override RTS_OPTIONS += -hy x/prof-heap app/prof-heap: app.eventlog.html x/prof-time app/prof-time: override RTS_OPTIONS += -p x/prof-time app/prof-time: app.eventlog.html doc: cabal haddock --haddock-css ocean --haddock-hyperlink-source .PHONY: benchmarks/html/$(version).html b benchmarks: benchmarks/html/$(version).html benchmarks/html/$(version).html: mkdir -p benchmarks/html cabal bench $(CABAL_BENCH_FLAGS) --benchmark-options "$(BENCHMARK_OPTIONS)" benchmarks/repl: cabal repl $(CABAL_REPL_FLAGS) --enable-benchmarks $(project)-benchmark b/prof-cost benchmarks/prof-cost: override RTS_OPTIONS += -hc b/prof-cost benchmarks/prof-cost: benchmarks.eventlog.html b/prof-heap benchmarks/prof-heap: override RTS_OPTIONS += -hy b/prof-heap benchmarks/prof-heap: benchmarks.eventlog.html b/prof-time benchmarks/prof-time: override RTS_OPTIONS += -p b/prof-time benchmarks/prof-time: benchmarks.eventlog.json .PHONY: benchmarks.eventlog benchmarks.eventlog benchmarks.prof: @echo "$$(tput setaf 1)WARNING: benchmarking with --enable-profiling can create significant biases$$(tput sgr0)" cabal bench $(CABAL_BENCH_FLAGS) \ --benchmark-options "$(BENCHMARK_OPTIONS) +RTS $(RTS_OPTIONS) -olbenchmarks.eventlog" \ --enable-profiling .PHONY: ChangeLog.md ChangeLog.md: ! git tag --merged | grep -Fqx $(package)-$(version) git diff --exit-code git tag -f $(package)-$(version) git-chglog --output $@.new --tag-filter-pattern '$(package)-.*' $(package)-$(version) touch $@ cat $@ >>$@.new mv -f $@.new $@ git tag -d $(package)-$(version) git add '$@' git commit -m 'doc: update `$@`' tag: build ChangeLog.md git tag -s -m $(package)-$(version) $(package)-$(version) tar: git diff --exit-code reuse lint cabal sdist cabal haddock --haddock-for-hackage --enable-doc upload: LANG=C upload: tar git tag --merged | grep -Fqx $(package)-$(version) git push --follow-tags $(GIT_PUSH_FLAGS) cabal upload $(CABAL_UPLOAD_FLAGS) "$(cabal_builddir)"/sdist/$(package)-$(version).tar.gz cabal upload $(CABAL_UPLOAD_FLAGS) --documentation "$(cabal_builddir)"/$(package)-$(version)-docs.tar.gz %/publish: override CABAL_UPLOAD_FLAGS += --publish %/publish: % publish: upload/publish .PHONY: .hlint.yaml .hlint.yaml: sed -i -e '/^# BEGIN: generated hints/,/^# END: generated hints/d' $@ echo >>$@ '# BEGIN: generated hints' find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \ hlint --find {} | grep -- '- fixity:' | sort -u >>$@ echo >>$@ '# END: generated hints' lint: .hlint.yaml if hlint --quiet --report=hlint.html $(HLINT_FLAGS) $(sourceDirs); \ then rm -f hlint.html; \ else sensible-browser ./hlint.html & fi lint/apply: .hlint.yaml find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \ hlint --refactor-options="-i" --refactor {} style: find $(sourceDirs) -name "*.hs" | xargs -P $(shell nproc) -I {} \ fourmolu --unsafe -q -o -XOverloadedLabels -o -XImportQualifiedPost --mode inplace {} cabal-fmt -i *.cabal .PHONY: .radicle .radicle: direnv allow rad auth git config user.signingKey "$$(rad self --ssh-key)" git config gpg.format ssh git config gpg.ssh.program ssh-keygen git config gpg.ssh.allowedSignersFile .gitsigners git config commit.gpgsign true