#!/usr/bin/make -f

# Set LD_LIBRARY_PATH to the installed library directory to allow dh_shlibdeps to function
# Also include the main Trinity path
ifeq ("$(LD_LIBRARY_PATH)", "")
LD_LIBRARY_PATH=debian/tmp/opt/trinity/lib:debian/tmp/opt/trinity/lib/trinity
else
LD_LIBRARY_PATH += :debian/tmp/opt/trinity/lib:debian/tmp/opt/trinity/lib/trinity
endif
export LD_LIBRARY_PATH

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/cmake.mk
include /usr/share/cdbs/1/rules/simple-patchsys.mk
include /usr/share/cdbs/1/rules/utils.mk
include debian/cdbs/debian-qt-kde.mk

DEB_KDE_APIDOX := yes

DEB_CMAKE_EXTRA_FLAGS := -DLIB_SUFFIX="" -DCMAKE_INSTALL_PREFIX="/opt/trinity" -DCONFIG_INSTALL_DIR="/etc/trinity" -DSYSCONF_INSTALL_DIR="/etc/trinity" -DXDG_MENU_INSTALL_DIR="/etc/xdg/menus" -DCMAKE_LIBRARY_PATH="/opt/trinity/lib" -DCMAKE_INCLUDE_PATH="/opt/trinity/include/" -DAUTODETECT_QT_DIRS="ON" -DCMAKE_VERBOSE_MAKEFILE="ON" -DBUILD_ALL="ON" -DCMAKE_SKIP_RPATH="OFF" \
-DBUILD_ALL="ON" -DBUILD_KITCHENSYNC="ON" \
-DWITH_ARTS="ON" -DWITH_SASL="ON" -DWITH_NEWDISTRLISTS="ON" -DWITH_GNOKII="OFF" -DWITH_EXCHANGE="ON" -DWITH_EGROUPWARE="ON" -DWITH_KOLAB="ON" -DWITH_SLOX="ON" -DWITH_GROUPWISE="ON" -DWITH_FEATUREPLAN="ON" -DWITH_GROUPDAV="ON" -DWITH_BIRTHDAYS="ON" -DWITH_NEWEXCHANGE="ON" -DWITH_SCALIX="ON" -DWITH_CALDAV="ON" -DWITH_CARDDAV="ON" -DWITH_INDEXLIB="ON"

# Honour "parallel=N" option of DEB_BUILD_OPTIONS.  Comment out to
# never build in parallel, regardless of DEB_BUILD_OPTIONS.
DEB_BUILD_PARALLEL = true

DEB_DH_INSTALL_SOURCEDIR := $(DEB_DESTDIR)

DEB_INSTALL_DOCS_ALL :=

DEB_INSTALL_CHANGELOGS_ALL = $(shell for f in ChangeLog CHANGELOG CHANGES; do if test -s $(DEB_SRCDIR)/$(cdbs_curpkg)/$$f; then echo $(DEB_SRCDIR)/$(cdbs_curpkg)/$$f; break; fi; done)

shlibs_ver=4:3.5.7
DEB_DH_MAKESHLIBS_ARGS_libindex0-trinity := -V'libindex0-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkcal2b-trinity := -V'libkcal2b-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkdenetwork2-trinity := -V'libkdenetwork2-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkdepim1a-trinity := -V'libkdepim1a-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkgantt0-trinity := -V'libkgantt0-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkleopatra1-trinity := -V'libkleopatra1-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkmime2-trinity := -V'libkmime2-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkpimexchange1-trinity := -V'libkpimexchange1-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkpimidentities1-trinity := -V'libkpimidentities1-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libksieve0-trinity := -V'libksieve0-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libktnef1-trinity := -V'libktnef1-trinity (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libmimelib1c2a-trinity := -V'libmimelib1c2a-trinity (>= $(shlibs_ver))'

# kontact-trinity starts fine without korganizer-trinity or kpilot-trinity dependencies
# specialdates-trinity is only in recommends to get the kaddressbook-trinity dependency there
kontact-trinity_recommends_plugins := korganizer-trinity specialdates
kontact-trinity_suggests_plugins := journal kpilot-trinity todo

DEB_DH_SHLIBDEPS_ARGS_kontact-trinity := \
	$(foreach p,$(kontact-trinity_recommends_plugins) $(kontact-trinity_suggests_plugins),-Xopt/trinity/lib/trinity/libkontact_$(p)plugin.so) \
	-- -dRecommends \
	$(foreach p,$(kontact-trinity_recommends_plugins),debian/kontact/opt/trinity/lib/trinity/libkontact_$(p)plugin.so) \
	-dSuggests \
	$(foreach p,$(kontact-trinity_suggests_plugins),debian/kontact/opt/trinity/lib/trinity/libkontact_$(p)plugin.so) \
	-dDepends	# Since -u args go first in dpkg-shlibdeps call

## Move kaddressbook-trinity dependency (from libkabc_xmlrpc.so) to Recommends
#DEB_DH_SHLIBDEPS_ARGS_kdepim-kresources-trinity := \
#	-Xopt/lib/trinity/libkabc_xmlrpc.so.1 \
#	-- -dRecommends \
#	debian/kdepim-kresources/opt/trinity/lib/libkabc_xmlrpc.so.1.* \
#	-dDepends
#
## Move kaddressbook dependency of libkcal2b-trinity to Recommends
#DEB_DH_SHLIBDEPS_ARGS_libkcal2b-trinity := \
#	-Xopt/trinity/lib/trinity/kcal_kabc.so \
#	-- -dRecommends \
#	debian/libkcal2b/opt/trinity/lib/trinity/kcal_kabc.so \
#	-dDepends

test-shlibdeps:
	@echo $(DEB_DH_SHLIBDEPS_ARGS_kontact-trinity)

KDE_UPSTREAM_VERSION := $(shell echo $(DEB_UPSTREAM_VERSION) | sed -e 's/\.dfsg.*//')
KDE_TARBALL := ../$(DEB_SOURCE_PACKAGE)-$(KDE_UPSTREAM_VERSION).tar.bz2
KDE_SOURCEDIR := dfsg-tmp/$(DEB_SOURCE_PACKAGE)-$(KDE_UPSTREAM_VERSION)
NEWDEB_SOURCEDIR := $(DEB_SOURCE_PACKAGE)-$(DEB_UPSTREAM_VERSION)
