#!/usr/bin/make -f
# -*- makefile -*-

DESTDIR=$(CURDIR)/debian/tmp

include /usr/share/ocaml/ocamlvars.mk

export OCAMLPATH := $(CURDIR)/_tmp$(OCAML_STDLIB_DIR)
export PATH := $(CURDIR)/_tmp/usr/bin:$(PATH)

DUNE_INSTALL := dune install --destdir=$(CURDIR)/_tmp --prefix=/usr --libdir=..$(OCAML_STDLIB_DIR)

%:
	dh $@ --with ocaml

override_dh_auto_clean:
	dh_auto_clean
	rm -rf _tmp

override_dh_auto_build:
	dune build -p js_of_ocaml-compiler
	$(DUNE_INSTALL) js_of_ocaml-compiler
	dune build -p js_of_ocaml
	$(DUNE_INSTALL) js_of_ocaml
	dune build -p js_of_ocaml-ppx
	$(DUNE_INSTALL) js_of_ocaml-ppx
	dune build -p js_of_ocaml-ppx_deriving_json
	$(DUNE_INSTALL) js_of_ocaml-ppx_deriving_json
	dune build -p js_of_ocaml-lwt
	$(DUNE_INSTALL) js_of_ocaml-lwt
	dune build -p js_of_ocaml-ocamlbuild
	$(DUNE_INSTALL) js_of_ocaml-ocamlbuild
	dune build -p js_of_ocaml-toplevel
	$(DUNE_INSTALL) js_of_ocaml-toplevel
	dune build -p js_of_ocaml-tyxml
	$(DUNE_INSTALL) js_of_ocaml-tyxml

override_dh_auto_test:
# Needs ppx-expect

override_dh_auto_install:
	rm -rf debian/tmp
	cp -a _tmp debian/tmp
	for u in js_of_ocaml-compiler js_of_ocaml-ppx js_of_ocaml-ppx_deriving_json js_of_ocaml-lwt js_of_ocaml-ocamlbuild js_of_ocaml-toplevel js_of_ocaml-tyxml; do \
	  rm -rf debian/tmp/usr/doc/$$u; \
	done
	rm -f debian/tmp/usr/doc/js_of_ocaml/LICENSE

override_dh_missing:
	dh_missing --fail-missing
