#!/usr/bin/make -f

DEB_BUILD_ARCH_OS ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)

confflags := --with-libxml2 --with-freetype

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

# Use default java implementation
JAVA_HOME=/usr/lib/jvm/default-java
ifeq (,$(wildcard $(JAVA_HOME)))
     $(info "warning: No suitable jni.h was found. Package will most probably FTBFS!")
endif

export JDK_HOME=$(JAVA_HOME)
$(info Located java at $(JAVA_HOME))
confflags += --enable-bdjava --with-bdj-type=j2se
endif

# Set CFLAGS to DEB_CFLAGS
CFLAGS=$(shell dpkg-buildflags --get CFLAGS 2>/dev/null | sed -e 's/-O2//g')

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

override_dh_auto_configure:
	dh_auto_configure -- $(confflags)

override_dh_auto_build-indep:
	make doxygen-doc

override_dh_strip:
	dh_strip -plibbluray1 --dbg-package=libbluray1-dbg
	dh_strip

override_dh_installdocs:
	dh_installdocs --exclude=jquery.js

override_dh_install:
	dh_install -X.la -Xlibbluray.jar --fail-missing

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

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