#!/usr/bin/make -f

DEB_KDE_LINK_WITH_AS_NEEDED = no

BINARYVERSION ?= $(shell dpkg-parsechangelog | grep '^Version: ' | sed 's/^Version: //')
UPSTREAMVERSION ?= $(shell echo '$(BINARYVERSION)' | sed 's/^\(.*\)-.*/\1/')
UPSTREAMVERSION := $(UPSTREAMVERSION)
#UPSTREAMVERSION ?= 4:4.4.85
#PLASMA_ABI=$(shell grep 'plasma-abi-' debian/libplasma3.symbols.in | head -n1 | sed 's/^.*\(plasma-abi-\S\+\).*/\1/')
RUNTIME_DEPS := kdebase-runtime

DEB_DBG_PACKAGE_ALL := kdelibs5-dbg

DEB_CMAKE_EXTRA_FLAGS += -DKDESU_USE_SUDO_DEFAULT=true

#bump version for every new upstream version!
DEB_DH_MAKESHLIBS_ARGS_libkdecore5 := -V'libkdecore5 (>= $(UPSTREAMVERSION)), $(RUNTIME_DEPS)'
DEB_DH_MAKESHLIBS_ARGS_ALL := -V -u-c0
#DEB_DH_MAKESHLIBS_ARGS_libplasma3 := -V'libplasma3 (>= $(UPSTREAMVERSION)), $(PLASMA_ABI)'

# remove dependencies on kdebase-runtime and phonon (the metapackage)
DEB_DH_SHLIBDEPS_ARGS_ALL := -- -xkdebase-runtime -xphonon

# Libraries stuff
DEB_KDE43_LIBRARY_PACKAGES := libkdecore5 libkdeui5 libkde3support4 libkdesu5 libkdnssd4 \
    libkfile4 libkhtml5 libkimproxy4 libkio5 libkjsapi4 libkjsembed4 libkmediaplayer4 \
    libknewstuff2-4 libknotifyconfig4 libkntlm4 libkparts4 libkpty4 libkrosscore4 libkrossui4 \
    libktexteditor4 libkutils4 libnepomuk4 libsolid4 libthreadweaver4
DEB_ALL_LIBRARIES_SUBST_PACKAGES = kdelibs5-dev kdelibs5-dbg
DEB_KDE43_LIBRARIES_SUBST_PACKAGES = kdelibs5
DEB_STRICT_LOCAL_SHLIBS_PACKAGES = $(DEB_LIBRARY_PACKAGES)

# Fixes FTBFS (4:4.3.4-2) on ia64 (khtml code is too large to fit):
#   html/khtmlview.cpp:3623: relocation truncated to fit: GPREL22 against `.rodata'
# etc. We will have to reevalute if this is still needed some time later.
ifeq (ia64,$(DEB_HOST_ARCH))
    CFLAGS += -ffunction-sections
    CXXFLAGS += -ffunction-sections
endif

include /usr/share/pkg-kde-tools/qt-kde-team/1/debian-qt-kde.mk
include /usr/share/pkg-kde-tools/qt-kde-team/1/library-packages.mk

binary-post-install/kdelibs5-data::
	chmod a+x debian/kdelibs5-data/usr/share/kde4/apps/kconf_update/ksslcertificatemanager.upd.sh

#binary-predeb/libplasma3::
#	echo plasma:abi-provides=$(PLASMA_ABI) >> debian/libplasma3.substvars

DEB_FIXPERMS_EXCLUDE := usr/lib/kde4/libexec/fileshareset

export KUBUNTU_DESKTOP_POT=kdelibs

binary-install/kdelibs5-data::

	install -D -p -m0644 debian/icons/kubuntu.png \
		debian/kdelibs5-data/usr/share/icons/hicolor/16x16/apps/kubuntu.png

	install -D -p -m0644 debian/icons/launchpad.png \
		debian/kdelibs5-data/usr/share/icons/hicolor/16x16/apps/launchpad.png

	ln -s kde debian/kdelibs5-data/usr/share/doc/kde4
