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

include /usr/share/ocaml/ocamlvars.mk

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

%:
	dh --with ocaml $@

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	cp debian/Makefile.config .

.PHONY: override_dh_auto_build
override_dh_auto_build:
	$(MAKE)
ifneq ($(OCAML_OPT_ARCH),)
	$(MAKE) opt
endif

	# Quick replacement for docbook/po4a CDBS class
	# TODO: use cdbs + po4a
	xmllint --nonet --noout --postvalid --xinclude $(CURDIR)/debian/xml-man/en/lablgl.xml
	xsltproc --nonet --xinclude --param man.charmap.use.subset 0 \
	  -o $(CURDIR)/  /usr/share/xml/docbook/stylesheet/nwalsh/manpages/docbook.xsl \
	  $(CURDIR)/debian/xml-man/en/lablgl.xml

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	[ ! -f "$(CURDIR)/Makefile" ] || [ ! -f "$(CURDIR)/Makefile.config" ] || $(MAKE) clean

.PHONY: override_dh_auto_install
override_dh_auto_install:
	$(MAKE) install									\
		LIBDIR=$(CURDIR)/debian/liblablgl-ocaml-dev$(OCAML_STDLIB_DIR)		\
		DLLDIR=$(CURDIR)/debian/liblablgl-ocaml$(OCAML_STDLIB_DIR)/stublibs	\
		BINDIR=$(CURDIR)/debian/liblablgl-ocaml-dev/usr/bin
	cp debian/META $(CURDIR)/debian/liblablgl-ocaml-dev$(OCAML_STDLIB_DIR)/lablgl
	ln -sf $(OCAML_STDLIB_DIR)/lablgl $(CURDIR)/debian/liblablgl-ocaml-dev$(OCAML_STDLIB_DIR)/lablGL
