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 -fdump-splices --test-show-details always --test-options "--color always --size-cutoff 100000"
t/accept:
	cabal test --test-show-details always --test-options "--accept --color always --size-cutoff 100000"
t/prof:
	cabal test --enable-profiling --enable-library-coverage --enable-coverage --test-show-details always
t/repl:
	cabal repl --enable-tests symantic-parser-test
t/splices: t
	shopt -s globstar; $$EDITOR dist-newstyle/build/**/t/**/*.dump-splices

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