#!/usr/bin/make -f
TMP     =$(CURDIR)/debian/sks

#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

OCAMLABI = $(shell ocamlc -version)
BYTECODE = $(shell [ -x /usr/bin/ocamlopt ] || echo yes)
all      = $(if $(BYTECODE),all.bc,all)
OCAMLRUN = $(if $(BYTECODE),ocaml-base-nox-$(OCAMLABI))

export DEB_BUILD_OPTIONS += $(if $(BYTECODE)," nostrip",)

BDB_VERSION ?= $(shell LC_ALL=C dpkg-query -l 'libdb[45].[0-9]-dev' | grep ^.i | sed -e 's|.*\s\libdb\([45]\.[0-9]\)-dev\s.*|\1|')

%:
	dh  $@ --with=ocaml

override_dh_auto_clean:
	cp debian/Makefile.local ./Makefile.local
	dh_auto_clean
#	touch .depend

override_dh_clean:
	dh_clean -X .orig

override_dh_auto_build:
	cp debian/Makefile.local ./Makefile.local
	make dep
#	Check that we have a value for BDB_VERSION
	[ -n "$(BDB_VERSION)" ]
	echo $(BDB_VERSION) > debian/berkeley_db.txt
	dh_auto_build -v --  $(all)
	$(if $(BYTECODE), $(foreach x, sks sks_add_mail, mv $(x).bc $(x);))
	chmod a+x sks_build.sh

override_dh_auto_install:

override_dh_gencontrol:
	dh_gencontrol -- -Vbdb:Depends="db$(BDB_VERSION)-util"
