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

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

DESTDIR=$(CURDIR)/debian/tmp
BINDIR=$(DESTDIR)/usr/bin
MANDIR=$(DESTDIR)/usr/share/man

include /usr/share/ocaml/ocamlvars.mk

export OCAMLFIND_DESTDIR=$(DESTDIR)/$(OCAML_STDLIB_DIR)
export OCAMLFIND_LDCONF=ignore

# This should test OCAML_HAVE_OCAMLOPT, but camlp4 usage seems to
# force dynlink...
ifeq ($(OCAML_NATDYNLINK),yes)
  BUILD_TARGET := all
  INSTALL_TARGET := install
else
  BUILD_TARGET := byte
  INSTALL_TARGET := install.byte
endif

%:
	dh $@ --with ocaml

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	chmod +x configure
#we must recreate those directories from the tar because git remove
#the empty directories.
	mkdir -p local/etc
	mkdir -p src/client/sigs
	./configure \
	    --prefix /usr \
	    --libdir $(OCAML_STDLIB_DIR) \
	    --temproot $(DESTDIR) \
	    --mandir /usr/share/man/ \

.PHONY: override_dh_auto_build
override_dh_auto_build:
	$(MAKE) $(BUILD_TARGET)
	$(MAKE) doc

.PHONY: override_dh_auto_install
override_dh_auto_install:
	mkdir -p $(OCAMLFIND_DESTDIR)
	$(MAKE) $(INSTALL_TARGET) install.doc

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

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	[ ! -f Makefile.config ] || $(MAKE) distclean
