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

include /usr/share/ocaml/ocamlvars.mk

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

DESTDIR=$(CURDIR)/debian/tmp/$(OCAML_STDLIB_DIR)
OCAMLSDL=$(CURDIR)/debian/libsdl-ocaml
OCAMLSDLDEV=$(OCAMLSDL)-dev

%:
	dh $@ --with ocaml

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	[ ! -f makefile.config.gcc ] || $(MAKE) clean
	rm -f config.log config.status
	rm -f makefile.config.gcc src/config.h

.PHONY: override_dh_auto_install
override_dh_auto_install:
	mkdir -p $(DESTDIR)
	$(MAKE) install OCAMLFIND_DESTDIR=$(DESTDIR) OCAMLFIND_LDCONF=ignore

.PHONY: override_dh_installchangelogs
override_dh_installchangelogs:
	dh_installchangelogs NEWS
