#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
include /usr/share/ocaml/ocamlvars.mk

%:
	dh $@ --with ocaml

override_dh_auto_build:
	dune build @install

override_dh_auto_install:
	dune install --destdir=$(CURDIR)/debian/tmp --prefix=/usr --libdir=..$(OCAML_STDLIB_DIR)
	# drop excess files
	rm -rf debian/tmp/usr/lib/ocaml/psmt2-frontend_bin
	find debian/tmp -name "LICENSE*" -delete
	find debian/tmp -name index.mld -delete
	find debian/tmp -name CHANGES.md -delete
	find debian/tmp -type d -empty -delete
	# we detect what to ship
	find debian/tmp -regextype posix-awk \
	  -regex '.*\.(cma|cmxs)$$' \
	  >> debian/libpsmt2-frontend-ocaml.install
	find debian/tmp -regextype posix-awk \
	  -regex '.*\.(a|cmi|cmo|cmt|cmti|cmx|cmxa|ml|mli|o])$$' \
	  >> debian/libpsmt2-frontend-ocaml-dev.install

override_dh_auto_test:
ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dune runtest
endif
