#!/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)))

# 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

$(info Located java at $(JAVA_HOME))
confflags += --enable-bdjava --with-jdk=$(JAVA_HOME)
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
else
%:
	dh $@ --parallel
endif

override_dh_auto_configure:
	dh_auto_configure -- $(confflags)

override_dh_auto_build:
	dh_auto_build
	make doxygen-doc

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

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
