#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
#
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

CFLAGS +=-I/usr/include/libavcodec -I/usr/include/xbmc
CPPFLAGS +=-I/usr/include/libavcodec -I/usr/include/xbmc
XBMC_VERSION = $(shell dpkg-query -W -f='$${Version}' xbmc-addons-dev)

%:
	dh $@ --parallel

override_dh_clean:
	dh_clean
	find . \( -name "*.pvr" -o -name "config.status" -o -name "config.cache" -o -name "config.log" \
	-o -name "config.guess" -o -name "config.sub" -o -name "Makefile.in" -o -name "INSTALL" \
	-o -name "aclocal.m4" -o -name "configure" -o -name "depcomp" -o -name "install-sh"  \
	-o -name "ltmain.sh" -o -name "missing" -o -name "libvdr-*.so.*" \
	 \) -exec rm -f "{}" \;
	$(MAKE) clean -C addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver

override_dh_auto_configure:
	rm lib/tinyxml/tiny*
	rm -rf xbmc
	./bootstrap
	./configure --prefix=/usr --enable-addons-with-dependencies --enable-release

override_dh_gencontrol:
	sh /usr/share/vdr-dev/dependencies.sh
	sed -i 's/^vdr:Depends/# vdr:Depends/' $(CURDIR)/debian/xbmc-*.substvars
	for i in $(CURDIR)/debian/substvars $(CURDIR)/debian/xbmc-*.substvars ; do echo "xbmc-addons-abi:Depends=xbmc (>= $(XBMC_VERSION))" >> $$i; done
	dh_gencontrol

override_dh_shlibdeps:
	dh_shlibdeps
	chmod -x $(CURDIR)/debian/xbmc-pvr-*/usr/lib/xbmc/addons/pvr.*/*.pvr

override_dh_auto_build:
	#cd addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver
	VDRDIR=/usr/include/vdr LIBDIR=$(CURDIR)/debian/vdr-plugin-vnsiserver/usr/lib/vdr/plugins LOCALEDIR=locale $(MAKE) CXXFLAGS="$(CXXFLAGS) -fPIC" CFLAGS="$(CFLAGS)" compile -C addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver
	dh_auto_build

override_dh_install:
	 dh_install -XLICENSE.txt

override_dh_auto_install:
	VDRDIR=/usr/include/vdr LIBDIR=$(CURDIR)/debian/vdr-plugin-vnsiserver/usr/lib/vdr/plugins LOCALEDIR=locale $(MAKE) install-lib -C addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver
	dh_auto_install
	find $(CURDIR)/debian/tmp/usr/share/xbmc $(CURDIR)/debian/tmp/usr/lib/xbmc -type f -exec chmod 644 "{}" \;
	chmod +x $(CURDIR)/debian/tmp/usr/lib/xbmc/addons/pvr.*/*.pvr

