#!/usr/bin/make -f

DESTDIR=$(CURDIR)/debian/tmp

include /usr/share/ocaml/ocamlvars.mk

export OCAMLFIND_DESTDIR=$(DESTDIR)/$(OCAML_STDLIB_DIR)
export OCAMLBUILD_BEST

BUILD_ARGS :=

ifeq ($(OCAML_HAVE_OCAMLOPT),yes)
  BUILD_ARGS += native=true
else
  BUILD_ARGS += native=false
endif

ifeq ($(OCAML_NATDYNLINK),yes)
  BUILD_ARGS += native-dynlink=true
else
  BUILD_ARGS += native-dynlink=false
endif

%:
	dh $@ --with ocaml

override_dh_auto_build:
	cp pkg/META.in pkg/META
	ocaml pkg/build.ml $(BUILD_ARGS)
	make doc

override_dh_auto_test:
	ocamlbuild -classic-display -use-ocamlfind src_test/test_ppx_deriving.byte --

override_dh_auto_install:
	mkdir -p $(OCAMLFIND_DESTDIR)
	make install

override_dh_auto_clean:
	rm -rf _build

override_dh_install:
	dh_install -XLICENSE.txt

override_dh_missing:
	dh_missing --fail-missing

override_dh_dwz:
	dh_dwz --no-dwz-multifile
