#!/usr/bin/make -f

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_BUILD_ARCH_OS ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)
DEB_BUILD_ARCH := $(shell dpkg-architecture -qDEB_BUILD_ARCH)

confflags := --libdir=/usr/lib/$(DEB_HOST_MULTIARCH) --enable-doxygen-doc

# enable bdjava on linux hosts only
ifneq (,$(findstring linux,$(DEB_BUILD_ARCH_OS)))

# openjdk-6_6b23~pre8-2 and later have multiarchified JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-6-openjdk-$(DEB_BUILD_ARCH)
ifeq (,$(wildcard $(JAVA_HOME)))
JAVA_HOME=/usr/lib/jvm/java-6-openjdk
ifeq (,$(wildcard $(JAVA_HOME)))
     $(info "warning: No suitable jni.h was found. Package will most probably FTBFS!")
endif
endif

$(info Located java at $(JAVA_HOME))
confflags += --enable-bdjava --with-jdk=$(JAVA_HOME)
endif

# Set CFLAGS to DEB_CFLAGS
CFLAGS=$(DEB_CFLAGS)

ifneq (,$(findstring linux,$(DEB_BUILD_ARCH_OS)))
%:
	dh $@ --parallel --with javahelper
else
%:
	dh $@ --parallel
endif

override_dh_auto_configure:
	dh_auto_configure -- $(confflags)

override_dh_auto_build:
	dh_auto_build
	make doxygen-doc

override_dh_installdocs:
	dh_installdocs --exclude=jquery.js

override_dh_clean:
	dh_clean
	rm -rf src/libbluray/bdj/build

get-orig-source:
	$(dir $_)libbluray-get-orig-source
