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

DESTDIR=$(CURDIR)/debian/tmp
BINDIR=$(DESTDIR)/usr/bin
DOCDIR=$(DESTDIR)/usr/share/doc/libjs-of-ocaml-dev
COMPILER=$(shell awk '/COMPILER/{print $$NF}' Makefile.conf)

include /usr/share/ocaml/ocamlvars.mk

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

%:
	dh $@ --with ocaml

.PHONY: override_dh_auto_build
override_dh_auto_build:
ifeq ($(OCAML_HAVE_OCAMLOPT),yes)
	make -C compiler
else
	make -C compiler compile
	mv compiler/compile compiler/$(COMPILER)
endif
	make library runtime doc

.PHONY: override_dh_install
override_dh_install:
	dh_install -X.owner --list-missing

.PHONY: override_dh_compress
override_dh_compress:
	dh_compress -X.js

.PHONY: override_dh_auto_install
override_dh_auto_install:
	mkdir -p $(OCAMLFIND_DESTDIR) $(BINDIR) $(DESTDIR)$(OCAML_DLL_DIR)
	$(MAKE) install BINDIR=$(BINDIR)
	mkdir -p $(DOCDIR)/html $(DOCDIR)/examples
	cp -a doc/api-html $(DOCDIR)/html/api
	cp -a examples/* $(DOCDIR)/examples
	rm -f $(DOCDIR)/examples/*/*.cm* $(DOCDIR)/examples/*/*.byte

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	dh_auto_clean
	-cd $(CURDIR)/doc && make clean
