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

include /usr/share/ocaml/ocamlvars.mk

DH_AUTO_BUILD_EXTRA := @install

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
ifneq (,$(filter libjs-of-ocaml-doc,$(shell dh_listpackages)))
DH_AUTO_BUILD_EXTRA += @doc @doc-manual
endif
endif

%:
	dh $@ --with ocaml --buildsystem ocaml_dune

execute_before_dh_auto_build:
	rm -f compiler/tests-jsoo/dune         # makes the build fail on amd64
	rm -f compiler/lib-runtime/tests/dune  # makes the build fail on bytecode architectures
ifeq ($(OCAML_HAVE_OCAMLOPT),no)
	sed -i 's/ native//' compiler/bin-js_of_ocaml/dune
endif

override_dh_auto_build:
	dh_auto_build -- $(DH_AUTO_BUILD_EXTRA)

override_dh_auto_test:
# Needs ppx-expect, ppx-hash, node, Uchar.utf_decode...

execute_after_dh_install-indep:
	mkdir -p debian/libjs-of-ocaml-doc/usr/share/doc/libjs-of-ocaml-doc
	rm -rf debian/libjs-of-ocaml-doc/usr/share/doc/libjs-of-ocaml-doc/api
	rm -rf debian/libjs-of-ocaml-doc/usr/share/doc/libjs-of-ocaml-doc/manual
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
ifneq (,$(filter libjs-of-ocaml-doc,$(shell dh_listpackages)))
	cp -a _build/default/_doc/_html debian/libjs-of-ocaml-doc/usr/share/doc/libjs-of-ocaml-doc/html
endif
endif
