cabal = $(wildcard *.cabal)
package = $(notdir ./$(cabal:.cabal=))
version = $(shell sed -ne 's/^version: *\(.*\)/\1/p' $(cabal))
all: build
build:
	cabal build
clean c:
	cabal clean
repl:
	cabal repl

t:
	cabal test $(TESTFLAGS) --test-show-details always --test-options "$(TESTOPTIONS) --color always --size-cutoff 1000000 $${p:+-p $$p}"
%/accept: TESTOPTIONS+=--accept
%/accept: %
	
%/cover: TESTFLAGS+=--enable-coverage
%/cover: %
	
t/prof: OPTIFLAGS?=-xc
t/prof:
	cabal v2-build lib:symantic-parser --enable-profiling --write-ghc-environment-files=always
	cabal test $(TESTFLAGS) --enable-profiling -fprof-auto -fprof-auto-calls \
	 --test-show-details always --test-options "$(TESTOPTIONS) $${p:+-p $$p}" \
	 --ghc-options "-opti+RTS -opti-p -opti-L100 -opti-ls $(addprefix -opti,$(OPTIFLAGS))"
t/repl:
	cabal repl --enable-tests symantic-parser-test

doc:
	cabal haddock --haddock-css ocean --haddock-hyperlink-source

tag:
	git tag --merged | grep -Fqx "$(package)-$(version)" || \
	git tag -f -s -m "$(package) v$(version)" $(package)-$(version)

tar:
	cabal sdist
	cabal haddock --haddock-for-hackage --enable-doc
upload: LANG=C
upload: tar
	cabal upload $(CABAL_UPLOAD_FLAGS) dist-newstyle/sdist/$(package)-$(version).tar.gz
	cabal upload $(CABAL_UPLOAD_FLAGS) --documentation dist-newstyle/$(package)-$(version)-docs.tar.gz
%/publish: CABAL_UPLOAD_FLAGS+=--publish
%/publish: %
	
publish: upload/publish

nix-build:
	nix -L build
nix-relock:
	nix flake update --recreate-lock-file
nix-repl:
	nix -L develop --command cabal repl
nix-shell:
	nix -L develop