#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DESTDIR=$(CURDIR)/debian/tmp
include /usr/share/ocaml/ocamlvars.mk

%:
	dh $@ --with ocaml

# Instead of running "dune build" via "make all" we run dune with -p dose3
# because otherwise we get this error on salsaci:
# Error: Too many opam files for package "dose3":
# - debian/output/source_dir/dose3.opam
# - dose3.opam
override_dh_auto_build-arch:
	dune build -p dose3 @install --verbose
	make -C doc/manpages man
	pod2man --section 8 -release "apt-cudf $(RELEASE)" \
		debian/update-cudf-solvers > debian/update-cudf-solvers.8

override_dh_auto_build-indep:
	dune build -p dose3 @doc
	# running targets manually because we don't want to build the "pages"
	make -C doc/debcheck.primer
	make -C doc/apt-external-solvers.primer
	make -C doc/manpages html

override_dh_auto_install-arch:
	dune install -p dose3 --destdir=$(DESTDIR) --prefix=/usr --libdir=..$(OCAML_STDLIB_DIR)
	rm -f $(DESTDIR)/usr/doc/dose3/README.git
	rm -f $(DESTDIR)/usr/doc/dose3/README.architecture
	rm -f $(DESTDIR)/usr/doc/dose3/CHANGES

# No install or test needed for docs
override_dh_auto_test-indep:
override_dh_auto_install-indep:

override_dh_auto_test-arch:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dune runtest -p dose3
endif
