#!/usr/bin/make -f

DESTDIR=$(CURDIR)/debian/tmp

include /usr/share/ocaml/ocamlvars.mk

export OCAML_DLL_DIR
export OCAML_HAVE_OCAMLOPT
export OCAMLFIND_DESTDIR=$(DESTDIR)/$(OCAML_STDLIB_DIR)

%:
	dh $@ --with ocaml

override_dh_auto_configure:
	ocaml setup.ml -configure --prefix /usr --destdir '$(DESTDIR)'

override_dh_auto_build:
	ocaml setup.ml -build

override_dh_auto_test:
	ocaml setup.ml -test

override_dh_auto_install:
	mkdir -p '$(OCAMLFIND_DESTDIR)'
	mkdir -p '$(DESTDIR)$(OCAML_DLL_DIR)'
	ocaml setup.ml -install
	rm -f '$(DESTDIR)$(OCAML_DLL_DIR)'/*.so.owner

override_dh_auto_clean:
	ocaml setup.ml -distclean

override_dh_install:
	dh_install --fail-missing

override_dh_ocamldoc:
	dh_ocamldoc
	rm -f debian/libcore-ocaml-dev/usr/share/doc-base/libcore-ocaml-dev.doc-base.apiref
	mkdir -p debian/libcore-ocaml-doc/usr/share/doc/libcore-ocaml-doc
	mv debian/libcore-ocaml-dev/usr/share/doc/libcore-ocaml-dev/html \
	   debian/libcore-ocaml-doc/usr/share/doc/libcore-ocaml-doc/html
