Building kdepim (and the whole KDE world) from current git

I tried to build the latest kdepim (i needed it to look into ktimetracker), on Debian Jessie. I was trying to follow a few tutorials [1] [2], but after I started to see through the dependency relations between the lower level KDE stuff like Framworks  and the current versions of kdepim, i decided that it would be easier to build the whole KDE world alltogether, especially as i wanted to get my builds based the current 4.14 KDE version, and the Frameworks based (aka "KDE 5" version) as well.
  Fortunately the KDE project provides a cool tool called kdesrc-build [3], which made up from a couple of perl scripts, a few config files, and provides example configs for building KDE4 (using Qt4.x) and Frameworks based KDE (using Qt5.x) as well.

It took some time while i got all of the dependencies right, so here is what i had to install on a relatively clean Debian Jessie install (probably not full, but covers most of the stuff):

apt-get install libgrantlee-dev libsasl2-dev libprison-dev libical-dev libakonadi-dev libgpgme11-dev kdelibs5-dev libqtwebkit-dev libqt4-opengl-dev libiodbc2-dev libraptor2-dev librasqal3-dev librdf0-dev libbz2-dev libdbus-1-dev libfam-dev libclucene-dev libclucene-core1 libboost-all-dev libqjson-devlibecm-dev libjpeg-dev libgif-dev libdbusmenu-qt-dev libqt5x11extras5-dev libgcrypt20-dev libqt5xmlpatterns5-private-dev libvlc-dev libgstreamer1.0-dev libvlccore-dev libqtgstreamer-dev libgstreamer-plugins-base1.0-dev libxcb1-dev libxcb-xtest0-dev libxapian-dev libnm-util-dev libxcb-composite0-dev libxcb-damage0-dev fontforge libxcb-image0-dev libnm-gtk-dev libnetworkmanagerqt-dev libhunspell-dev libldap2-dev qdbus-qt5 git-core libjson-perl cmake bzr qtscript5-dev libxcb-keysyms1-dev qtbase5-dev libqt5x11extras5-dev qtscript5-dev qttools5-dev libqt5svg5-dev libudev-dev libqt5webkit5-dev libssl-dev libepoxy-dev qtbase5-private-dev libegl1-mesa-dev xsltproc liblcms2-dev qttools5-dev-tools xserver-xephyrlibasound2-dev libpolkit-qt-1-dev libbaloowidgets-dev libdlrestrictions-dev libkactivities-dev libkfilemetadata-dev libqimageblitz-dev libtidy-0.99-0 libtidy-dev libxkbfile-dev libsane-dev libexiv2-dev libraw-dev libcups2-dev libmusicbrainz3-dev

Set up the kde url prefix for git add to ~/.gitconfig:

[url "git://anongit.kde.org/"]
        insteadOf = kde:
[url "git@git.kde.org:"]
        pushInsteadOf = kde:

I wanted to install my KDE builds under /opt, so i created two directories and give them to my normal user:

mkdir /opt/{kde5,kde4}
chown myuser:myuser /opt/kde*

Cloned the kdesrc-build scripts:

git clone git://anongit.kde.org/kdesrc-build && cd kdesrc-build

Edit the kdesrc-buildrc-sample file to set your paths (also for Qt the /usr, so it won't build Qt as well), and build kde4:

./kdesrc-build --rc-file kdesrc-buildrc-sample

which takes some hours, if you see something didn't build, look into the logfiles, and install the needed dependecies. It also occured to me that the script failed to clone first some of the git repositories, so i had to restart the build process.

For the Frameworks based KDE, edit the kdesrc-buildrc-kf5-sample, and build:

./kdesrc-build --rc-file kdesrc-buildrc-kf5-sample

To run a nested session in Xephyr, i created the following quick&dirty script, you might need to adjust it to your needs:

#!/bin/bash
export KDEDIR=/opt/kde4
export KDEHOME=~/kdehome4
#export KDEDIR=/opt/kde5
#export KDEHOME=~/kdehome5
Xephyr -ac :1 -screen 1024x768 &
sleep 3
export DISPLAY=:1
export KDE_COLOR_DEBUG=1
export XDG_CONFIG_DIRS=$KDEDIR/etc/xdg:$XDG_CONFIG_DIRS:/etc/xdg
export QML2_IMPORT_PATH=$KDEDIR/lib/qml:$KDEDIR/lib64/qml:$KDEDIR/lib/x86_64-linux-gnu/qml
export XDG_DATA_HOME=$KDEHOME/.local
export XDG_CONFIG_HOME=$KDEHOME/.config
export XDG_CACHE_HOME=$KDEHOME/.cache
export LD_LIBRARY_PATH=$KDEDIR/lib:$KDEDIR/lib/x86_64-linux-gnu/plugins:$LD_LIBRARY_PATH
export XDG_DATA_DIRS="$XDG_DATA_DIRS:/opt/kde/share:/usr/share"
export QT_PLUGIN_PATH=$KDEDIR/lib/x86_64-linux-gnu/plugins

dbus-launch $KDEDIR/bin/startkde  --failsafe

Depending on the version/dependency changes in the future (and the current Moon phase) this probably will need some tweaking, but i hope it gives a some guidence.

Sources:

[1] http://blogs.fsfe.org/torsten.grote/2012/10/03/compiling-kde-kontact-from-source/

[2] https://community.kde.org/KDE_PIM/Development/Start

[3] https://kdesrc-build.kde.org/

Currently unrated