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

export DH_VERBOSE=1

include /usr/share/ocaml/ocamlvars.mk

WHYDIR    = $(CURDIR)/debian/why
FRAMADIR  = $(WHYDIR)/$(shell frama-c -print-plugin-path)
FRAMAVER  = $(shell dpkg-query -W -f='$${Version}' frama-c-base)
VERSION   = $(shell cat Version | grep ^VERSION | cut -d= -f 2)
export OCAMLINIT_SED += -e 's/@VERSION@/$(VERSION)/g'

override_dh_auto_test:
	: # requires coq
	true

override_dh_auto_configure:
	autoconf
	./configure \
	    --host=$(DEB_HOST_GNU_TYPE) \
	    --build=$(DEB_BUILD_GNU_TYPE) \
	    --prefix=/usr \
	    --libdir=/usr/share \
	    --mandir=\$${prefix}/share/man \
	    --infodir=\$${prefix}/share/info \
	    --enable-apron=yes \
	    LDFLAGS="-Wl,-z,defs"

override_dh_auto_clean:
	[ ! -f Makefile ] || sed -e 's/include .depend.*//g' Makefile > Makefile.debian
	[ ! -f Makefile.debian ] || $(MAKE) -f Makefile.debian clean
	$(RM) -f lib/coq/*.glob

override_dh_auto_install:
	mkdir -p $(FRAMADIR)
	$(MAKE) prefix=$(WHYDIR)/usr install \
		LIBDIR=$(WHYDIR)/usr/share   \
		PLUGIN_INSTALL_DIR=$(WHYDIR)/usr/lib/frama-c/plugins \
		COQLIB=$(CURDIR)/debian/libwhy-coq/$(COQ_STDLIB_DIR)
	#Used to remove /usr/share/coq/jessie_why.v which is alone and installed by libwhy-coq
	-$(RM) -rf $(WHYDIR)/usr/share/coq/
	#There is no program using the Jessie library.
	-$(RM) -rf $(WHYDIR)/usr/share/jessie/
	#Jessie.cma is installed, no need for this extra file
	-$(RM) -f $(FRAMADIR)/Jessie.cmo
	echo 'F:FramaCVersion=$(FRAMAVER)' >> debian/why.substvars

override_dh_compress:
	dh_compress -X.v -X.sx -X.why

%:
	dh --with ocaml $@

#	dh_installchangelogs CHANGES
