For quite some time now (seems like forever) I’ve used a bit modified scripts from Techbase: Increased Productivity in KDE4 with Scripts to build KDE.

I don’t know why, but I’ve never even tried kdesvn-build script, so the things I’ll write here are maybe (probably) already present in it.

So, if you don’t use kdesvn-build, and have your system set up like it is explained in the above link, keep reading.

Important: I’m using ZSH, so the scripts here maybe need changing in order to be usable in BASH.

Environment

First of all, we need to add some global, environment variables. You should put this in the script for setting KDE4 variables (for example in .my-setup)

The first variable will be used by the build logging system. You should define it near the definitions of KDE_SRC and KDE_BUILD variables.

# build and src folders
# you might want to change these!
export KDE_BUILD=$KDE4ROOT/build
export KDE_SRC=$KDE4ROOT/src
export KDE_LOG=$KDE4ROOT/log

After this, we are making a variable that holds all the dirs to be included in the automatic build system.

# all build dirs
KDE_BUILD_DIRS=""

pushd $KDE_SRC > /dev/null
    for dir in                  \
        KDE/support         \
        KDE/libs            \
        KDE/pimlibs         \
        KDE/base            \
        KDE/plasmoids       \
        KDE/pim             \
        KDE/accessibility   \
        KDE/artwork         \
        KDE/bindings        \
        KDE/graphics        \
        KDE/multimedia      \
        KDE/network         \
        KDE/sdk             \
        KDE/utils           \
                                    \
        extragear/*         \
        other/*             \
        playground/*        \
    ;
    do
        KDE_BUILD_DIRS="$KDE_BUILD_DIRS $dir";
    done

popd > /dev/null

export KDE_BUILD_DIRS

SVN/GIT Updates

Now, we can create two very easy functions for fetching the updates:

function updatesource {
    if [ -n "$1" ]; then
        cd $1;
    fi
    if [ -d .svn ]; then echo "Updating directory: $PWD (svn)"; svn up; fi
    if [ -d .git ]; then echo "Updating directory: $PWD (git)"; git pull; fi
}

function kdeup {
    # clearing update logs
    rm -fr $KDE_LOG/update.log
    rm -fr $KDE_LOG/*.update

    cd $KDE_SRC
    for dir in `echo $KDE_BUILD_DIRS`; do
        updatesource $KDE_SRC/$dir || echo "$dir (see $log_file) update failed" >> $KDE_LOG/update.log
    done
}

Notice that it reports errors in $KDE_LOG/update.log file.

Building

Now we define kdemake command which will build all the directories we specified in $KDE_BUILD_DIRS. Like kdeup, it logs the process. The main log is $KDE_LOG/build.log and each built directory has its own build log (the output of cmake + make).

function kdemake {
    # clearing all logs
    rm -fr $KDE_LOG/build.log
    rm -fr $KDE_LOG/*.build

    cd $KDE_SRC
    for dir in `echo $KDE_BUILD_DIRS`; do
        cd $KDE_SRC/$dir;
        echo "Building $dir";

        log_file=`echo $dir | sed 's/\//_/g'`;
        log_file="$KDE_LOG/$log_file.build";
        echo "Building $dir > $log_file" > $log_file;

        echo "Building $dir" >> $KDE_LOG/build.log
        ( ( cmakekde || echo "FAILED: see $log_file" >> $KDE_LOG/build.log ) 2> /dev/stdout | tee -a $log_file )
    done
}

Debug builds

Sometimes you want to have a certain module build with debugging symbols - just replace the default cmakekde function with this one. It checks for the .debug file and if it exists, it builds that module with dbg symbols included.

function cmakekde {
    if test -n "$1"; then
        # srcFolder is defined via command line argument
        srcFolder="$1"
    else
        # get srcFolder for current dir
        srcFolder=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`
    fi
    # we are in the src folder, change to build directory
    # Alternatively, we could just use makeobj in the commands below...
    current=`pwd`
    if [ "$srcFolder" = "$current" ]; then
        cb
    fi
    # to enable tests, add -DKDE4_BUILD_TESTS=TRUE to the next line.
    # you can also change "debugfull" to "debug" to save disk space.
        # added "nice make..." to allow the user to work on the box while
        # compiling
        # Note: To speed up compiling, change 'make -j2' to 'make -jx',
        #   where x is your number of processors +1

    if test -e ".debug"; then
        echo "debug yes" && \
        cmake "$srcFolder" -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \
            -DCMAKE_BUILD_TYPE=debugfull \
            && nice make -j3 && make install
    elif test -e ".debug-release"; then
        echo "debug yes [release-debug]" && \
        cmake "$srcFolder" -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \
            -DCMAKE_BUILD_TYPE=RelWithDebInfo \
            && nice make -j3 && make install
    else
        echo "debug no" && \
        cmake "$srcFolder" -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \
            -DCMAKE_BUILD_TYPE=release \
            && nice make -j3 && make install
    fi
}

Checking logs

So, updating KDE is now a matter of calling kdeup and kdemake. The next thing to do is to create a watching mechanism (to put it in the command watch plasmoid for example).

The first script is outputting what is currently being built - something like this:

/opt/kde4trunk/log/KDE_support.build : [ 49%] Built target phonon

The code for this bash script is:

#!/bin/bash
WHATFILE=`ls -t1 /opt/kde4trunk/log/*.build | head -n 1`
WHAT=`grep '%' $WHATFILE | tail -n 1`
echo $WHATFILE ":" $WHAT

That’s all for today.


You can support my work on , or you can get my book Functional Programming in C++ at if you're into that sort of thing.