#!/usr/bin/make -f
# -*- makefile -*-
include /usr/share/ocaml/ocamlvars.mk

DESTDIR=$(CURDIR)/debian/tmp
export OCAMLFIND_DESTDIR=$(DESTDIR)/$(OCAML_STDLIB_DIR)
export OCAMLFIND_LDCONF=ignore

# Needed for running tests on bytecode architectures
export CAML_LD_LIBRARY_PATH=$(CURDIR)/_build/src

%:
	dh $@ --with ocaml

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	ocaml setup.ml -configure --prefix /usr --destdir '$(DESTDIR)' --enable-pcre --docdir /usr/share/doc/libtext-ocaml-dev

.PHONY: override_dh_auto_build
override_dh_auto_build:
	ocaml setup.ml -build
ifeq ($(OCAML_NATDYNLINK),yes)
	cd _build && for u in text text-pcre text-bigarray; do ocamlopt -shared -I src -o src/$$u.cmxs src/$$u.cmxa; done
	cd _build && for u in text-pcre-syntax; do ocamlopt -shared -I syntax -o syntax/$$u.cmxs syntax/$$u.cmxa; done
endif
	ocaml setup.ml -doc

.PHONY: override_dh_auto_test
override_dh_auto_test:
	ocaml setup.ml -test

.PHONY: override_dh_auto_install
override_dh_auto_install:
	mkdir -p '$(OCAMLFIND_DESTDIR)'
	ocaml setup.ml -install

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

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	ocaml setup.ml -distclean
