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

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

include /usr/share/ocaml/ocamlvars.mk

DESTDIR=$(CURDIR)/debian/tmp

DEB_DUNE_OTHER_PACKAGES := dune-private-libs dune-configurator dune-build-info dune-site stdune xdg dyn ordering

DEB_DUNE_ALL_PACKAGES := dune
ifeq (,$(filter pkg.ocaml-dune.bootstrap,$(DEB_BUILD_PROFILES)))
DEB_DUNE_ALL_PACKAGES += $(DEB_DUNE_OTHER_PACKAGES)
endif

%:
	dh $@ --with ocaml

override_dh_auto_configure:
	./configure --libdir $(OCAML_STDLIB_DIR)

override_dh_auto_build:
	ocaml boot/bootstrap.ml
	./dune.exe build --release --profile dune-bootstrap dune.install
ifeq (,$(filter pkg.ocaml-dune.bootstrap,$(DEB_BUILD_PROFILES)))
	./dune.exe build --release $(addsuffix .install,$(DEB_DUNE_OTHER_PACKAGES))
endif

override_dh_auto_install:
	./dune.exe install --release --destdir=$(DESTDIR) --prefix=/usr --libdir=$(OCAML_STDLIB_DIR) $(DEB_DUNE_ALL_PACKAGES)
ifeq (,$(filter pkg.ocaml-dune.bootstrap,$(DEB_BUILD_PROFILES)))
	rm -rf $(addprefix debian/tmp/usr/doc/,$(DEB_DUNE_OTHER_PACKAGES))
endif
	rm -f debian/tmp/usr/doc/dune/LICENSE.md

override_dh_auto_test:
# Upstream tests assume opam is installed; skip them
