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

export DH_VERBOSE=1
export DH_OPTIONS=-v
export JBUILDER_ARGS=--verbose

DESTDIR=$(CURDIR)/debian/tmp
include /usr/share/ocaml/ocamlvars.mk
OCAMLFIND_DESTDIR=$(DESTDIR)/$(OCAML_STDLIB_DIR)

%:
	dh $@ --with ocaml

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	./configure --prefix=/usr --libdir=$(OCAML_STDLIB_DIR) --enable-certificate-check

.PHONY: override_dh_auto_build
override_dh_auto_build:
	$(MAKE)
ifneq (,$(findstring opam-docs, $(shell dh_listpackages)))
	$(MAKE) man
	$(RM) -f doc/dev-manual/dev-manual.pdf
	$(MAKE) -C doc/dev-manual
endif

.PHONY: override_dh_auto_test
override_dh_auto_test:
ifeq ($(OCAML_HAVE_OCAMLOPT),yes)
	dh_auto_test
endif

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	$(MAKE) clean || true
	$(RM) -f doc/dev-manual/dev-manual.pdf
	$(RM) -f META Makefile.config config.log config.status src/core/opamTypes.cmti src/core/opamVersion.ml tests/fulltest.log tests/packages/*.tar.gz tests/test.log
	$(RM) -rf tests/tmp

.PHONY: override_dh_installdocs
override_dh_installdocs:
	dh_installdocs -p opam --link-doc=opam-installer
	dh_installdocs --remaining-packages

.PHONY: override_dh_compress
override_dh_compress:
	dh_compress -X.pdf

.PHONY: override_dh_missing
override_dh_missing:
	dh_missing --fail-missing
