#!/usr/bin/make -f

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

%:
	dh $@ --with ocaml

override_dh_auto_build:
	sed -e 's/%%VERSION_NUM%%/$(DEB_VERSION_UPSTREAM)/g' -i elpi_REPL.ml
	sed -e 's/%%VERSION_NUM%%/$(DEB_VERSION_UPSTREAM)/g' -i src/compiler.ml
	make build

override_dh_auto_test:
	make tests

override_dh_auto_install:
	dune install --destdir=$(CURDIR)/debian/tmp --prefix=/usr --libdir=..$(OCAML_STDLIB_DIR)
	# drop excess LICENSE files
	find debian/tmp -name "LICENSE*" -delete
	# drop legacy stuff
	rm -rf debian/tmp/usr/doc/elpi-option-legacy-parser debian/tmp/usr/lib/ocaml/elpi-option-legacy-parser
	# we detect what to ship
	find debian/tmp -regextype posix-awk \
	  -regex '.*\.(cma|cmxs)$$' \
	  >> debian/libelpi-ocaml.install
	find debian/tmp -regextype posix-awk \
	  -regex '.*\.(a|cmi|cmo|cmt|cmti|cmx|cmxa|ml|mli|o])$$' \
	  >> debian/libelpi-ocaml-dev.install
