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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
#export DH_OPTIONS=-v

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

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

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:
	echo 'let version = "$(DEB_VERSION_UPSTREAM)"' > atd/src/version.ml
	dune build -p atdgen-codec-runtime
	$(DUNE_INSTALL) atdgen-codec-runtime
	dune build -p atd
	$(DUNE_INSTALL) atd
	dune build -p atdgen-runtime
	$(DUNE_INSTALL) atdgen-runtime
	dune build -p atdgen
	$(DUNE_INSTALL) atdgen
	dune build -p atdts
	$(DUNE_INSTALL) atdts
	$(MAKE) -C manual

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dune runtest -p atdgen-codec-runtime
	dune runtest -p atd
	dune runtest -p atdgen-runtime
	dune runtest -p atdgen
	dune runtest -p atdts
endif

override_dh_auto_install:
	rm -rf debian/tmp
	cp -a _tmp debian/tmp
	rm -rf debian/tmp/usr/doc/atdgen*runtime debian/tmp/usr/doc/*/LICENSE.md
