#! /usr/bin/make -f

# DEB_TAR_SRCDIR := $(shell basename $(wildcard *.tar.bz2) .tar.bz2)

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

DEB_CONFIGURE_INCLUDEDIR := /opt/kde3/include/kde
DEB_CONFIGURE_MANDIR := /opt/kde3/share/man
DEB_CONFIGURE_PREFIX := /opt/kde3
DEB_CONFIGURE_INFODIR := /opt/kde3/share/info

cdbs_configure_flags := --with-qt-dir=/usr/share/qt3 --disable-rpath --with-xinerama $(cdbs_kde_enable_final) $(cdbs_kde_enable_debug)

DEB_KDE_APIDOX := yes

DEB_CONFIGURE_EXTRA_FLAGS := --prefix=/opt/kde3 --with-extra-libs=/opt/kde3/lib

DEB_CONFIGURE_SCRIPT_ENV += KMIX=/opt/kde3/bin/kmix KTTSD=/opt/kde3/bin/kttsd CC=gcc-4.3 CXX=g++-4.3

DEB_DH_INSTALL_SOURCEDIR := $(DEB_DESTDIR)

#override cdbs files, no --enable-final in kdepim-kde3
DEB_KDE_ENABLE_FINAL :=

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-kde3 := -V'libindex0-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkcal2b-kde3 := -V'libkcal2b-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkdenetwork2-kde3 := -V'libkdenetwork2-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkdepim1a-kde3 := -V'libkdepim1a-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkgantt0-kde3 := -V'libkgantt0-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkleopatra1-kde3 := -V'libkleopatra1-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkmime2-kde3 := -V'libkmime2-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkpimexchange1-kde3 := -V'libkpimexchange1-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libkpimidentities1-kde3 := -V'libkpimidentities1-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libksieve0-kde3 := -V'libksieve0-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libktnef1-kde3 := -V'libktnef1-kde3 (>= $(shlibs_ver))'
DEB_DH_MAKESHLIBS_ARGS_libmimelib1c2a-kde3 := -V'libmimelib1c2a-kde3 (>= $(shlibs_ver))'

#PACKAGES_WITH_LIBS := akregator-kde3 kaddressbook-kde3 kalarm-kde3 kdepim-kresources-kde3 \
#	kdepim-wizards-kde3 kitchensync-kde3 kleopatra-kde3 kmail-kde3 knode-kde3 knotes-kde3 kode-kde3 kontact-kde3 \
#	korganizer-kde3 kpilot-kde3 ksync-kde3 ktnef-kde3 libindex0-kde3 libkcal2b-kde3 libkdenetwork2-kde3 \
#	libkdepim1a-kde3 libkgantt0-kde3 libkleopatra1-kde3 libkmime2-kde3 libkpimexchange1-kde3 \
#	libkpimidentities1-kde3 libksieve0-kde3 libktnef1-kde3 libmimelib1c2a-kde3

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

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

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

# Move kaddressbook dependency of libkcal2b-kde3 to Recommends
DEB_DH_SHLIBDEPS_ARGS_libkcal2b-kde3 := \
	-Xopt/kde3/lib/kde3/kcal_kabc.so \
	-- -dRecommends \
	debian/libkcal2b/opt/kde3/lib/kde3/kcal_kabc.so \
	-dDepends

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

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)

common-binary-indep::
	if ! test -d debian/tmp/opt/kde3/share/doc/kde/HTML/en/kdepim-apidocs; then mv debian/tmp/opt/kde3/share/doc/kde/HTML/en/kdepim-*apidocs debian/tmp/opt/kde3/share/doc/kde/HTML/en/kdepim-apidocs; fi

common-binary-arch::
	if ! test -d debian/tmp/opt/kde3/share/doc/kde/HTML/en/kdepim-apidocs; then mv debian/tmp/opt/kde3/share/doc/kde/HTML/en/kdepim-*apidocs debian/tmp/opt/kde3/share/doc/kde/HTML/en/kdepim-apidocs; fi
