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

DESTDIR=$(CURDIR)/debian/opam
include /usr/share/ocaml/ocamlvars.mk
OCAMLFIND_DESTDIR=$(DESTDIR)/$(OCAML_STDLIB_DIR)
BINEXT = $(if $(OCAML_OPT_ARCH),native,byte)

%:
	dh $@ --with ocaml

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	./configure
	$(MAKE) -C src core/opamGitVersion.ml core/opamScript.ml
	for file in `ls -1 debian/buildsys/`; do \
		ln -s debian/buildsys/$$file; \
	done 

.PHONY: override_dh_auto_build
override_dh_auto_build:
	ocamlbuild $(OCAML_BEST).otarget
ifneq (,$(findstring opam-docs, $(shell dh_listpackages)))
	$(MAKE) -C doc OPAM=../opamMain.$(BINEXT) OPAM_ADMIN=../opam_admin.$(BINEXT) OPAM_INSTALLER=../opam_installer.$(BINEXT) man
	$(RM) -f doc/dev-manual/dev-manual.pdf
	$(MAKE) -C doc/dev-manual
endif

.PHONY: override_dh_auto_test
override_dh_auto_test:
	true

.PHONY: override_dh_auto_install
override_dh_auto_install:
	mkdir -p $(DESTDIR)/usr/bin
	cp _build/src/client/opamMain.$(BINEXT)			$(DESTDIR)/usr/bin/opam
	cp _build/src/tools/opam_admin.$(BINEXT)		$(DESTDIR)/usr/bin/opam-admin
	cp _build/src/tools/opam_installer.$(BINEXT)		$(DESTDIR)/usr/bin/opam-installer

.PHONY: override_dh_install
override_dh_install:
	dh_install --fail-missing

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	for file in `ls -1 debian/buildsys/`; do \
		$(RM) -f $$file || true; \
	done
	$(MAKE) clean || true
	$(RM) -rf _build
	$(RM) -f src/core/opamVersion.ml src/core/opamGitVersion.ml src/core/opamScript.ml Makefile.config config.log config.status *.$(BINEXT)

.PHONY: override_dh_compress
override_dh_compress:
	dh_compress -X.pdf
