Difference between revisions of "Getting Started/Build/Environment"

Jump to: navigation, search
m (Git Configuration)
(Add category.)
 
(34 intermediate revisions by 6 users not shown)
Line 11: Line 11:
 
== Git Configuration ==
 
== Git Configuration ==
  
Add the following to your ~/.gitconfig:
+
KDE uses Git as its main source repository and revision control software which you need to configure before you can use it in KDE.  You can find the recommended Git configuration for KDE on the [[Development/Git/Configuration|Git Configuration]] page.
 +
 
  
<code>
 
[url "git://anongit.kde.org/"]
 
insteadOf = kde://
 
</code>
 
  
 
== Path Configuration ==
 
== Path Configuration ==
  
 
This section explains the different paths that need to be configured for building KDE.  The following section will demonstrate a simple method for setting up the required paths.
 
This section explains the different paths that need to be configured for building KDE.  The following section will demonstrate a simple method for setting up the required paths.
 +
 +
=== Qt Path ===
 +
 +
The $QTDIR environment variable defines where the KDE Build System can find the Qt library and include files to use when building KDE.  Normally you will want to set this to your system Qt, but you may want to change this to point to a different version of Qt you have [[Getting_Started/Build/Qt|built yourself]].
  
 
=== Source Path ===
 
=== Source Path ===
Line 26: Line 27:
 
The $KDE_SRC path environment variable defines where the KDE Build System can find the source files.
 
The $KDE_SRC path environment variable defines where the KDE Build System can find the source files.
  
TODO: Decide how to do stable and unstable source branches in parallel. While Git supports having these in a single source clone to save disk space, it is sometimes nice to have separate clones to allow simultaneous parallel builds, and it takes less scripting to achieve.  It's also conceptually closer to how svn works so seems preferable during the transition.
+
By tradition this is usually saved in your home directory, but can be anywhere convenient or large enough to hold the source, build and install files:
 +
 
 +
~/kde/src/
 +
 
 +
Inside this directory you can copy all the required git and svn source code repositories, for example:
 +
 
 +
~/kde/src/kdelibs
 +
 
 +
This works fine if you only build a few repositories.  However, if you build many repositories or branches you may want to organise your repositories in a directory hierarchy.
 +
 
 +
If you need to build multiple branches of KDE such as stable and unstable in parallel then you will need to add an extra level to the directory structure to keep these separate:
 +
 
 +
  ~/kde/src/master/
 +
~/kde/src/4.6/
 +
 
 +
See the Git Configuration page for details on setting up [[Development/Git/Configuration#Multiple_Work_Branches|Multiple Work Branches]].
 +
 
 +
In Subversion the KDE Source Code was organised into Modules with a single repository holding all the applications for that module which imposed a clear structure.  In Git many KDE Modules have been split up into separate repositories for each application and library which can get very messy.  It is recommended you organize the repositories into separate sub-directories for each traditional Module:
 +
 
 +
~/kde/src/master/kdesupport/akonadi
 +
~/kde/src/master/KDE/kdelibs
 +
~/kde/src/master/KDE/kdeedu/marble
 +
~/kde/src/master/extragear/multimedia/amarok
 +
 
 +
See the [[Getting_Started/Sources|KDE Sources page]] or the [http://projects.kde.org/projects KDE Projects page] to see how the KDE Modules are organized.
  
 
=== Build Path ===
 
=== Build Path ===
Line 37: Line 62:
 
* It allows multiple build trees with different settings, e.g. debug and release.  
 
* It allows multiple build trees with different settings, e.g. debug and release.  
  
While for some simple build scenarios you could just create a "build" directory inside your 'source' directory (e.g. "kde/src/kdelibs/build"), this negates many of the advantages when used with a full KDE build.  Instead clearly separate paths are recommended.
+
While for some simple build scenarios you could just create a 'build' directory inside your 'source' directory (e.g. ~/kde/src/kdelibs/build), this negates many of the advantages when used with a full KDE build.  Instead clearly separate paths are recommended.
  
For example if we were building kdelibs we could have the following folders:
+
Continuing the example given above, you will now need the following new directories:
  
  /home/myuser/kde/src/kdelibs
+
  ~/kde/build/master/
  /home/myuser/kde/build/kdelibs
+
  ~/kde/build/4.6/
  
If you plan to build multiple branches of KDE such as stable and unstable in parallel then you will need to add an extra level to the directory:
+
=== Install Path ===
  
/home/myuser/kde/src/master/kdelibs
 
/home/myuser/kde/src/4.6/kdelibs
 
/home/myuser/kde/build/master/kdelibs
 
/home/myuser/kde/build/4.6/kdelibs
 
 
=== Install Path ===
 
 
The $KDEDIR path environment variable defines where the KDE Build System will install KDE.
 
The $KDEDIR path environment variable defines where the KDE Build System will install KDE.
  
It is strongly recommended for a development build that you do a user based install and not a root install, i.e. install your KDE build into a separate user folder and not into the system /usr folder.  This provides a number of advantages:
+
It is strongly recommended for a development build that you do a user based install and not a root install, i.e. install your KDE build into a user-owned directory and not into the system /usr directory.  This provides a number of advantages:
 
* Your root/system installed version of KDE is untouched, meaning your normal desktop and applications remain stable and usable even if your development build breaks
 
* Your root/system installed version of KDE is untouched, meaning your normal desktop and applications remain stable and usable even if your development build breaks
 
* You can build and run multiple development versions of KDE at the same time, i.e. a stable branch for bug fixes and an unstable branch for new features
 
* You can build and run multiple development versions of KDE at the same time, i.e. a stable branch for bug fixes and an unstable branch for new features
Line 65: Line 84:
 
That said, the build instructions provided are completely generic and will work for building a root system install if you configure your environment to do so, i.e. for Linux from Scratch or doing a root install in a virtual machine for testing or packaging purposes.
 
That said, the build instructions provided are completely generic and will work for building a root system install if you configure your environment to do so, i.e. for Linux from Scratch or doing a root install in a virtual machine for testing or packaging purposes.
  
For the kdelibs example given above we would then have:
+
Continuing the example given above, you will now need the following new directories:
  
  /home/myuser/kde/src/master/kdelibs
+
  ~/kde/inst/master/
/home/myuser/kde/src/4.6/kdelibs
+
  ~/kde/inst/4.6/
/home/myuser/kde/build/master/kdelibs
+
/home/myuser/kde/build/4.6/kdelibs
+
/home/myuser/kde/inst/master/kdelibs
+
  /home/myuser/kde/inst/4.6/kdelibs
+
  
 
=== Home Path ===
 
=== Home Path ===
The $KDEHOME path environment variable defines wat directory KDE will treat as your home folder, i.e. for stroing data writing config files to.
+
 
 +
The $KDEHOME path environment variable defines what directory KDE will treat as your home folder, i.e. for storing data and writing config files to.
  
 
For the same reason as the Install Path, it is strongly recommended that you set your KDE Home Path to be different from your normal home folder.
 
For the same reason as the Install Path, it is strongly recommended that you set your KDE Home Path to be different from your normal home folder.
  
For the kdelibs example given above we would then have:
+
Continuing the example given above, you will now need the following new directories:
  
  /home/myuser/kde/src/master/kdelibs
+
  ~/kde/home/master/
  /home/myuser/kde/src/4.6/kdelibs
+
  ~/kde/home/4.6/
/home/myuser/kde/build/master/kdelibs
+
 
  /home/myuser/kde/build/4.6/kdelibs
+
=== XDG Paths ===
  /home/myuser/kde/inst/master/kdelibs
+
 
/home/myuser/kde/inst/4.6/kdelibs
+
The Cross Desktop (XDG) Paths XDG_DATA_DIRS and XDG_CONFIG_DIRS are a standard set of paths used to find various shared cross-desktop standard data and config such as mimetypes. If you are building the KDE Development Platform yourself then it is recommended to unset these paths to prevent your build from seeing your system install (usually /usr) as this will cause problemsHowever, if you do so you must install the shared-mime-info data into your development install pathIf you are not building your own KDE Development Platform then you should not unset the XDG Data Paths.
  /home/myuser/kde/home/master/kdelibs
+
/home/myuser/kde/home/4.6/kdelibs
+
  
 
=== Other Paths ===
 
=== Other Paths ===
 +
 
There are a number of other paths that are required, but these can all be automatically derived and created by the config script given below.
 
There are a number of other paths that are required, but these can all be automatically derived and created by the config script given below.
 +
 +
=== Summary ===
 +
 +
If you are only working on unstable, then you will end up with a directory hierarchy looking like:
 +
 +
~/kde/src/
 +
~/kde/build/
 +
~/kde/inst/
 +
~/kde/home/
 +
 +
If you are working on both unstable and stable then you will end up with a directory hierarchy looking like:
 +
 +
~/kde/src/master/
 +
~/kde/src/4.6/
 +
~/kde/build/master/
 +
~/kde/build/4.6/
 +
~/kde/inst/master/
 +
~/kde/inst/4.6/
 +
~/kde/home/master/
 +
~/kde/home/4.6/
 +
 +
Just remember that you do not have to put the directories in your home folder, they can be anywhere you like that has sufficient space.  You can even have each directory in a different location.
 +
 +
Normally you would need to manually create all the directories yourself and set the KDE Path Environment Variables manually, but if you use the config scripts below then you only need to create the source directory, all the other directories will be created by the KDE Build System when required.
  
 
== Environment Configuration ==
 
== Environment Configuration ==
 +
 
The example environment configuration script given below is for building KDE against your system Qt under your normal user account with an out-of-source build and installing into a user directory.  By changing just four variables you can use the script to configure any KDE build environment you want.
 
The example environment configuration script given below is for building KDE against your system Qt under your normal user account with an out-of-source build and installing into a user directory.  By changing just four variables you can use the script to configure any KDE build environment you want.
  
Line 101: Line 141:
  
 
If you are building KDE using a dedicated user to run a full desktop session, then you should put this config into the users ~/.bashrc file.
 
If you are building KDE using a dedicated user to run a full desktop session, then you should put this config into the users ~/.bashrc file.
 +
 +
Please see the notes above about the [[Getting_Started/Build/Environment#XDG_Paths|XDG Paths]], the example config script below overrides the XDG Data Paths.
  
 
=== Sample .build-config file ===
 
=== Sample .build-config file ===
<code>
+
<syntaxhighlight lang="bash">
 
# KDE4 Build Environment configuration script
 
# KDE4 Build Environment configuration script
 
#
 
#
Line 110: Line 152:
 
#
 
#
 
# The default values provided are for a master/trunk/unstable build in your own
 
# The default values provided are for a master/trunk/unstable build in your own
# user directory using your own build of Qt
+
# user directory using your system Qt
  
 
# Uncomment if building on a 64 bit system
 
# Uncomment if building on a 64 bit system
Line 128: Line 170:
 
#export PATH=$QTDIR/bin:$PATH
 
#export PATH=$QTDIR/bin:$PATH
 
#export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
 
#export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
#export PKG_CONFIG_PATH=$QTDIR/lib:$PKG_CONFIG_PATH
+
#export PKG_CONFIG_PATH=$QTDIR/lib/pkgconfig:$PKG_CONFIG_PATH
  
 
# Set up the KDE paths
 
# Set up the KDE paths
Line 159: Line 201:
  
 
# Unset XDG to avoid seeing KDE files from /usr
 
# Unset XDG to avoid seeing KDE files from /usr
 +
# If unset then you must install shared-mime-info
 
unset XDG_DATA_DIRS
 
unset XDG_DATA_DIRS
 
unset XDG_CONFIG_DIRS
 
unset XDG_CONFIG_DIRS
Line 173: Line 216:
 
echo "PATH=" $PATH
 
echo "PATH=" $PATH
 
echo
 
echo
</code>
+
</syntaxhighlight>
  
== Useful Scripts ==
+
== Useful Bash Scripts ==
 +
 
 +
This section provides a set of bash scripts to simplify setting up your build environment and managing the KDE build process.  If you use these scripts, then you can use the 'Easy Recipe' option documented in these pages.  If you do not want to use these scripts then you will need to use the 'Full Recipe' option documented in these pages.
 +
 
 +
You can find further details about using these scripts on the [[../Recipes|Build Recipes]] page.
 +
 
 +
The main commands provided are:
 +
 
 +
;''cs''
 +
Change to source directory
 +
;''cb''
 +
Change to build directory
 +
;''cmakekde''
 +
Configure, build and install the current KDE module
 +
;''kdebuild''
 +
Configure, build and install the current KDE module
 +
;''kdecmake''
 +
Configure the current KDE module using cmake
 +
;''kdemake''
 +
Build and install the current KDE module
  
 
=== findup ===
 
=== findup ===
 
Save this script in an executable file called "findup" somewhere in your path, usually ~/bin/findup.
 
Save this script in an executable file called "findup" somewhere in your path, usually ~/bin/findup.
  
<code>
+
<syntaxhighlight lang="bash">
 
#!/bin/sh
 
#!/bin/sh
  
Line 194: Line 256:
  
 
echo $PWD/$arg
 
echo $PWD/$arg
</code>
+
</syntaxhighlight>
  
 
=== .bashrc ===
 
=== .bashrc ===
<code>
+
Add the following script to the end of your ~/.bashrc, or save as a separate ~/.kde-bashrc and add ''source .kde-bashrc'' to your ~/.bashrc.
 +
 
 +
<syntaxhighlight lang="bash">
 
###
 
###
 
## A script to setup some needed variables and functions for KDE 4 development.
 
## A script to setup some needed variables and functions for KDE 4 development.
 
## This should normally go in the ~/.bashrc file of your kde development user.
 
## This should normally go in the ~/.bashrc file of your kde development user.
 
+
###
 +
 +
CURRENT_SHELL=$(echo $0)
 +
 
prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" && export $1 ; }
 
prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" && export $1 ; }
 
+
 
# This will make the debug output prettier
 
# This will make the debug output prettier
 
export KDE_COLOR_DEBUG=1
 
export KDE_COLOR_DEBUG=1
 
export QTEST_COLORED=1
 
export QTEST_COLORED=1
 
+
 
# Make
 
# Make
 
# Tell many scripts how to switch from source dir to build dir:
 
# Tell many scripts how to switch from source dir to build dir:
 
export OBJ_REPLACEMENT="s#$KDE_SRC#$KDE_BUILD#"
 
export OBJ_REPLACEMENT="s#$KDE_SRC#$KDE_BUILD#"
 
+
 
# Use makeobj instead of make, to automatically switch to the build dir.
 
# Use makeobj instead of make, to automatically switch to the build dir.
 
# If you don't have makeobj, install the package named kdesdk-scripts or
 
# If you don't have makeobj, install the package named kdesdk-scripts or
Line 217: Line 284:
 
# yet.
 
# yet.
 
alias make=makeobj
 
alias make=makeobj
 
+
 
##
 
##
 
# A function to easily build the current directory of KDE.
 
# A function to easily build the current directory of KDE.
Line 224: Line 291:
 
# Usage: cs KDE/kdebase && cmakekde
 
# Usage: cs KDE/kdebase && cmakekde
 
#  will build/rebuild the sources in ~/src/KDE/kdebase
 
#  will build/rebuild the sources in ~/src/KDE/kdebase
#
+
##
 
function cmakekde {
 
function cmakekde {
 
     if test -n "$1"; then
 
     if test -n "$1"; then
Line 243: Line 310:
 
     cmake "$srcFolder" \
 
     cmake "$srcFolder" \
 
           -DCMAKE_INSTALL_PREFIX=$KDEDIR \
 
           -DCMAKE_INSTALL_PREFIX=$KDEDIR \
 +
          -DKDE4_AUTH_POLICY_FILES_INSTALL_DIR=$KDEDIR/share/polkit-1/actions \
 
           -DKDE4_BUILD_TESTS=TRUE \
 
           -DKDE4_BUILD_TESTS=TRUE \
 
           -DCMAKE_BUILD_TYPE=debugfull
 
           -DCMAKE_BUILD_TYPE=debugfull
 
+
 
         # Comment out the following two lines to stop builds waiting after
 
         # Comment out the following two lines to stop builds waiting after
 
         # the configuration step, so that the user can check configure output
 
         # the configuration step, so that the user can check configure output
 
         echo "Press <ENTER> to continue..."
 
         echo "Press <ENTER> to continue..."
 
         read userinput
 
         read userinput
 
+
 
         # Note: To speed up compiling, change 'make -j2' to 'make -jx',
 
         # Note: To speed up compiling, change 'make -j2' to 'make -jx',
 
         #  where x is your number of processors +1
 
         #  where x is your number of processors +1
Line 260: Line 328:
 
         return ${RETURN}
 
         return ${RETURN}
 
}
 
}
 
+
 
+
##
 +
# A function to easily build the current directory of KDE.
 +
#
 +
# This builds only the sources in the current ~/{src,build}/KDE subdirectory.
 +
# Usage: cs KDE/kdebase && kdebuild
 +
#  will build/rebuild the sources in ~/src/KDE/kdebase
 +
##
 +
function kdebuild {
 +
    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 disable tests, remove -DKDE4_BUILD_TESTS=TRUE
 +
    # To save disk space change "debugfull" to "debug"
 +
    cmake "$srcFolder" \
 +
          -DCMAKE_INSTALL_PREFIX=$KDEDIR \
 +
          -DKDE4_AUTH_POLICY_FILES_INSTALL_DIR=$KDEDIR/share/polkit-1/actions \
 +
          -DKDE4_BUILD_TESTS=TRUE \
 +
          -DCMAKE_BUILD_TYPE=debugfull
 +
 +
    # Comment out the following two lines to stop builds waiting after
 +
    # the configuration step, so that the user can check configure output
 +
    echo "Press <ENTER> to continue..."
 +
    read userinput
 +
 +
    # Note: To speed up compiling, change 'make -j2' to 'make -jx',
 +
    #  where x is your number of processors +1
 +
    nice make -j2 && make install
 +
    #Use this line instead if using icecream
 +
    #nice make CC=icecc -j6 && make install
 +
    RETURN=$?
 +
    cs
 +
    return ${RETURN}
 +
}
 +
 +
##
 +
# A function to easily run cmake for KDE configuration
 +
##
 +
function kdecmake {
 +
    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 disable tests, remove -DKDE4_BUILD_TESTS=TRUE
 +
    # To save disk space change "debugfull" to "debug"
 +
    cmake "$srcFolder" \
 +
          -DCMAKE_INSTALL_PREFIX=$KDEDIR \
 +
          -DKDE4_AUTH_POLICY_FILES_INSTALL_DIR=$KDEDIR/share/polkit-1/actions \
 +
          -DKDE4_BUILD_TESTS=TRUE \
 +
          -DCMAKE_BUILD_TYPE=debugfull
 +
    RETURN=$?
 +
    cs
 +
    return ${RETURN}
 +
}
 +
 +
##
 +
# A function to easily make and install the current or selected directory of KDE.
 +
##
 +
function kdemake {
 +
    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
 +
 +
    # Note: To speed up compiling, change 'make -j2' to 'make -jx',
 +
    #  where x is your number of processors +1
 +
    nice make -j2 && make install
 +
    #Use this line instead if using icecream
 +
    #nice make CC=icecc -j6 && make install
 +
    RETURN=$?
 +
    cs
 +
    return ${RETURN}
 +
}
 +
 
function cd() {
 
function cd() {
 
   if test -z "$1"; then
 
   if test -z "$1"; then
Line 277: Line 445:
 
   fi
 
   fi
 
}
 
}
 
+
 
+
 
##
 
##
 
# A function to easily change to the build directory.
 
# A function to easily change to the build directory.
Line 293: Line 460:
 
function cb {
 
function cb {
 
         local dest
 
         local dest
 
+
 
     # Make sure build directory exists.
 
     # Make sure build directory exists.
 
     mkdir -p "$KDE_BUILD"
 
     mkdir -p "$KDE_BUILD"
 
+
 
     # command line argument
 
     # command line argument
 
     if test -n "$1"; then
 
     if test -n "$1"; then
Line 310: Line 477:
 
     cd "$dest"
 
     cd "$dest"
 
}
 
}
 
+
 
##
 
##
 
# Change to the source directory.  Same as cb, except this
 
# Change to the source directory.  Same as cb, except this
Line 326: Line 493:
 
function cs {
 
function cs {
 
         local dest current
 
         local dest current
 
+
 
     # Make sure source directory exists.
 
     # Make sure source directory exists.
 
     mkdir -p "$KDE_SRC"
 
     mkdir -p "$KDE_SRC"
 
+
 
     # command line argument
 
     # command line argument
 
     if test -n "$1"; then
 
     if test -n "$1"; then
Line 344: Line 511:
 
     fi
 
     fi
 
}
 
}
 
+
 
##
 
##
 
# Add autocompletion to cs function
 
# Add autocompletion to cs function
Line 351: Line 518:
 
{
 
{
 
         local base ext
 
         local base ext
 
+
 
     base=$1
 
     base=$1
 
     ext=$2
 
     ext=$2
Line 362: Line 529:
 
     fi
 
     fi
 
}
 
}
 
+
 
function _cs()
 
function _cs()
 
{
 
{
Line 372: Line 539:
 
     COMPREPLY=( $(compgen -W "${dirs}" -- ${cur}) )
 
     COMPREPLY=( $(compgen -W "${dirs}" -- ${cur}) )
 
}
 
}
 
+
complete -F _cs cs
+
 
+
 
+
 
svndiff ()
 
svndiff ()
 
{
 
{
 
     svn diff "$*" | colordiff | less;
 
     svn diff "$*" | colordiff | less;
 
}
 
}
 +
 +
# Setup shell
 +
if [ "$CURRENT_SHELL" = "bash" ]; then
 +
    complete -F _cs cs
 +
fi
  
</code>
+
</syntaxhighlight>
 +
[[Category:Build KDE]]

Latest revision as of 14:42, 22 December 2012

Contents

[edit] Introduction

Configuring your build environment is the single most important step in building KDE. A wrong decision or mistake here could at best mean you have to rebuild everything from scratch again, or at worst break your system KDE rendering your system unusable.

A lot of very important concepts will be discussed and it is important that you understand them before proceeding.

A set of configuration scripts and bash commands are provided as a recommended configuration when building KDE manually. If you use these as provided then your KDE build will be a lot easier and it will be easier for you to find support online. The one disadvantage to these scripts is that they hide important details from you which you may want to learn about, but the two methods are completely interchangeable so once you are comfortable building KDE using the scripts you can learn more by doing everything yourself.

It is recommended that you build KDE using your normal user account. In some circumstances you may want to build using a separate user account, such as if you are a KWin or Plasma developer wishing to test a full KDE session with compositing effects, but for most circumstances a simple way can be found for achieving the same aim while still running using your normal user account (e.g. Nested X using xypher).

[edit] Git Configuration

KDE uses Git as its main source repository and revision control software which you need to configure before you can use it in KDE. You can find the recommended Git configuration for KDE on the Git Configuration page.


[edit] Path Configuration

This section explains the different paths that need to be configured for building KDE. The following section will demonstrate a simple method for setting up the required paths.

[edit] Qt Path

The $QTDIR environment variable defines where the KDE Build System can find the Qt library and include files to use when building KDE. Normally you will want to set this to your system Qt, but you may want to change this to point to a different version of Qt you have built yourself.

[edit] Source Path

The $KDE_SRC path environment variable defines where the KDE Build System can find the source files.

By tradition this is usually saved in your home directory, but can be anywhere convenient or large enough to hold the source, build and install files:

~/kde/src/

Inside this directory you can copy all the required git and svn source code repositories, for example:

~/kde/src/kdelibs

This works fine if you only build a few repositories. However, if you build many repositories or branches you may want to organise your repositories in a directory hierarchy.

If you need to build multiple branches of KDE such as stable and unstable in parallel then you will need to add an extra level to the directory structure to keep these separate:

~/kde/src/master/
~/kde/src/4.6/

See the Git Configuration page for details on setting up Multiple Work Branches.

In Subversion the KDE Source Code was organised into Modules with a single repository holding all the applications for that module which imposed a clear structure. In Git many KDE Modules have been split up into separate repositories for each application and library which can get very messy. It is recommended you organize the repositories into separate sub-directories for each traditional Module:

~/kde/src/master/kdesupport/akonadi
~/kde/src/master/KDE/kdelibs
~/kde/src/master/KDE/kdeedu/marble
~/kde/src/master/extragear/multimedia/amarok

See the KDE Sources page or the KDE Projects page to see how the KDE Modules are organized.

[edit] Build Path

The $KDE_BUILD path environment variable defines where the KDE Build System will create the build files.

The KDE build system requires that your source and build files be in different directories (aka out-of-source builds). This keeps your source directories clean and simplifies management of your different build files. :

  • It makes it very easy to rebuild from scratch, you just delete the build directory to remove all the generated files - even old ones that "make clean" wouldn't remove.
  • It is easier to look at the source files (grep, ls etc.).
  • It allows multiple build trees with different settings, e.g. debug and release.

While for some simple build scenarios you could just create a 'build' directory inside your 'source' directory (e.g. ~/kde/src/kdelibs/build), this negates many of the advantages when used with a full KDE build. Instead clearly separate paths are recommended.

Continuing the example given above, you will now need the following new directories:

~/kde/build/master/
~/kde/build/4.6/

[edit] Install Path

The $KDEDIR path environment variable defines where the KDE Build System will install KDE.

It is strongly recommended for a development build that you do a user based install and not a root install, i.e. install your KDE build into a user-owned directory and not into the system /usr directory. This provides a number of advantages:

  • Your root/system installed version of KDE is untouched, meaning your normal desktop and applications remain stable and usable even if your development build breaks
  • You can build and run multiple development versions of KDE at the same time, i.e. a stable branch for bug fixes and an unstable branch for new features
  • You can use a single alias or bash command to compile/link/install without having to do a su/sudo in the middle
  • Doing "make" and "make install" as the same user is a lot quicker as the Makefiles are only parsed once.
  • No root owned files in the build directory
  • No problems caused by root not having a correctly configured KDE build environment
  • It makes it very easy to reinstall from scratch, you just delete the install directory to remove all the installed files and rerun the build.

That said, the build instructions provided are completely generic and will work for building a root system install if you configure your environment to do so, i.e. for Linux from Scratch or doing a root install in a virtual machine for testing or packaging purposes.

Continuing the example given above, you will now need the following new directories:

~/kde/inst/master/
~/kde/inst/4.6/

[edit] Home Path

The $KDEHOME path environment variable defines what directory KDE will treat as your home folder, i.e. for storing data and writing config files to.

For the same reason as the Install Path, it is strongly recommended that you set your KDE Home Path to be different from your normal home folder.

Continuing the example given above, you will now need the following new directories:

~/kde/home/master/
~/kde/home/4.6/

[edit] XDG Paths

The Cross Desktop (XDG) Paths XDG_DATA_DIRS and XDG_CONFIG_DIRS are a standard set of paths used to find various shared cross-desktop standard data and config such as mimetypes. If you are building the KDE Development Platform yourself then it is recommended to unset these paths to prevent your build from seeing your system install (usually /usr) as this will cause problems. However, if you do so you must install the shared-mime-info data into your development install path. If you are not building your own KDE Development Platform then you should not unset the XDG Data Paths.

[edit] Other Paths

There are a number of other paths that are required, but these can all be automatically derived and created by the config script given below.

[edit] Summary

If you are only working on unstable, then you will end up with a directory hierarchy looking like:

~/kde/src/
~/kde/build/
~/kde/inst/
~/kde/home/

If you are working on both unstable and stable then you will end up with a directory hierarchy looking like:

~/kde/src/master/
~/kde/src/4.6/
~/kde/build/master/
~/kde/build/4.6/
~/kde/inst/master/
~/kde/inst/4.6/
~/kde/home/master/
~/kde/home/4.6/

Just remember that you do not have to put the directories in your home folder, they can be anywhere you like that has sufficient space. You can even have each directory in a different location.

Normally you would need to manually create all the directories yourself and set the KDE Path Environment Variables manually, but if you use the config scripts below then you only need to create the source directory, all the other directories will be created by the KDE Build System when required.

[edit] Environment Configuration

The example environment configuration script given below is for building KDE against your system Qt under your normal user account with an out-of-source build and installing into a user directory. By changing just four variables you can use the script to configure any KDE build environment you want.

It is recommended you create a separate script for each build environment you require. If you have separate source directories for each build then save the script into the root source directory with the name ".build-config" to allow the bash scripts in the next section to automatically load the config and create the required directories.

If you don't wish to use the bash scripts then you must manually create the required directories and manually execute the config script.

If you are building KDE using a dedicated user to run a full desktop session, then you should put this config into the users ~/.bashrc file.

Please see the notes above about the XDG Paths, the example config script below overrides the XDG Data Paths.

[edit] Sample .build-config file

# KDE4 Build Environment configuration script
#
# To configure your build environment set LIB_SUFFIX, BASEDIR, BUILDNAME and
# QTDIR as appropriate
#
# The default values provided are for a master/trunk/unstable build in your own
# user directory using your system Qt
 
# Uncomment if building on a 64 bit system
#export LIB_SUFFIX=64
 
# Set where your base KDE development folder is located, usually ~/kde
export BASEDIR=~/kde
 
# Give the build a name, e.g. master, 4.6, debug, etc
export BUILDNAME=master
 
# Set up which Qt to use
# Use the system Qt, adjust path as required
export QTDIR=/usr
# Uncomment to use your own build of qt-kde
#export QTDIR=$BASEDIR/inst/master/qt-kde
#export PATH=$QTDIR/bin:$PATH
#export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
#export PKG_CONFIG_PATH=$QTDIR/lib/pkgconfig:$PKG_CONFIG_PATH
 
# Set up the KDE paths
export KDE_SRC=$BASEDIR/src
export KDE_BUILD=$BASEDIR/build
export KDEDIR=$BASEDIR/inst/$BUILDNAME
export KDEDIRS=$KDEDIR
export KDEHOME=$BASEDIR/home/.$BUILDNAME
export KDETMP=/tmp/$BUILDNAME-$USER
export KDEVARTMP=/var/tmp/$BUILDNAME-$USER
mkdir -p $KDETMP
mkdir -p $KDEVARTMP
 
# Add the KDE plugins to the Qt plugins path
export QT_PLUGIN_PATH=$KDEDIR/lib/kde4/plugins
 
# Do we really need these?
export KDE4_DBUS_INTERFACES_DIR=$KDEDIR/share/dbus-1/interfaces
export PYTHON_SITE_PACKAGES_DIR=$KDEDIR/lib/python2.6/site-packages/PyKDE4
 
# Export the standard paths to include KDE
export PATH=$KDEDIR/bin:$PATH
export LD_LIBRARY_PATH=$KDEDIR/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$KDEDIR/lib/pkgconfig:$PKG_CONFIG_PATH
 
# Export the CMake paths so it searches for KDE in the right places
export CMAKE_PREFIX_PATH=$KDEDIR:$CMAKE_PREFIX_PATH
export CMAKE_LIBRARY_PATH=$KDEDIR/lib:$CMAKE_LIBRARY_PATH
export CMAKE_INCLUDE_PATH=$KDEDIR/include:$CMAKE_INCLUDE_PATH
 
# Unset XDG to avoid seeing KDE files from /usr
# If unset then you must install shared-mime-info
unset XDG_DATA_DIRS
unset XDG_CONFIG_DIRS
 
# Uncomment if you are using Icecream for distributed compiling
#export PATH=/opt/icecream/bin:$PATH
 
# Report what the environment is set to
echo
echo "*** Configured KDE Build Environment " $BUILDNAME " ***"
echo
echo "QTDIR=" $QTDIR
echo "KDEDIR=" $KDEDIR
echo "PATH=" $PATH
echo

[edit] Useful Bash Scripts

This section provides a set of bash scripts to simplify setting up your build environment and managing the KDE build process. If you use these scripts, then you can use the 'Easy Recipe' option documented in these pages. If you do not want to use these scripts then you will need to use the 'Full Recipe' option documented in these pages.

You can find further details about using these scripts on the Build Recipes page.

The main commands provided are:

cs

Change to source directory

cb

Change to build directory

cmakekde

Configure, build and install the current KDE module

kdebuild

Configure, build and install the current KDE module

kdecmake

Configure the current KDE module using cmake

kdemake

Build and install the current KDE module

[edit] findup

Save this script in an executable file called "findup" somewhere in your path, usually ~/bin/findup.

#!/bin/sh
 
arg="$1"
if test -z "$arg"; then exit 1; fi
 
while ! test -f "$arg"; do
 cd ..
 if test "$PWD" = "/"; then
    exit 1
 fi
done
 
echo $PWD/$arg

[edit] .bashrc

Add the following script to the end of your ~/.bashrc, or save as a separate ~/.kde-bashrc and add source .kde-bashrc to your ~/.bashrc.

###
## A script to setup some needed variables and functions for KDE 4 development.
## This should normally go in the ~/.bashrc file of your kde development user.
###
 
CURRENT_SHELL=$(echo $0)
 
prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" && export $1 ; }
 
# This will make the debug output prettier
export KDE_COLOR_DEBUG=1
export QTEST_COLORED=1
 
# Make
# Tell many scripts how to switch from source dir to build dir:
export OBJ_REPLACEMENT="s#$KDE_SRC#$KDE_BUILD#"
 
# Use makeobj instead of make, to automatically switch to the build dir.
# If you don't have makeobj, install the package named kdesdk-scripts or
# kdesdk, or check out kdesdk/scripts from svn, or just don't set the alias
# yet.
alias make=makeobj
 
##
# A function to easily build the current directory of KDE.
#
# This builds only the sources in the current ~/{src,build}/KDE subdirectory.
# Usage: cs KDE/kdebase && cmakekde
#   will build/rebuild the sources in ~/src/KDE/kdebase
##
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 disable tests, remove -DKDE4_BUILD_TESTS=TRUE
    # To save disk space change "debugfull" to "debug"
    cmake "$srcFolder" \
          -DCMAKE_INSTALL_PREFIX=$KDEDIR \
          -DKDE4_AUTH_POLICY_FILES_INSTALL_DIR=$KDEDIR/share/polkit-1/actions \
          -DKDE4_BUILD_TESTS=TRUE \
          -DCMAKE_BUILD_TYPE=debugfull
 
        # Comment out the following two lines to stop builds waiting after
        # the configuration step, so that the user can check configure output
        echo "Press <ENTER> to continue..."
        read userinput
 
        # Note: To speed up compiling, change 'make -j2' to 'make -jx',
        #   where x is your number of processors +1
        nice make -j2 && make install
        #Use this line instead if using icecream
        #nice make CC=icecc -j6 && make install
        RETURN=$?
        cs
        return ${RETURN}
}
 
##
# A function to easily build the current directory of KDE.
#
# This builds only the sources in the current ~/{src,build}/KDE subdirectory.
# Usage: cs KDE/kdebase && kdebuild
#   will build/rebuild the sources in ~/src/KDE/kdebase
##
function kdebuild {
    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 disable tests, remove -DKDE4_BUILD_TESTS=TRUE
    # To save disk space change "debugfull" to "debug"
    cmake "$srcFolder" \
          -DCMAKE_INSTALL_PREFIX=$KDEDIR \
          -DKDE4_AUTH_POLICY_FILES_INSTALL_DIR=$KDEDIR/share/polkit-1/actions \
          -DKDE4_BUILD_TESTS=TRUE \
          -DCMAKE_BUILD_TYPE=debugfull
 
    # Comment out the following two lines to stop builds waiting after
    # the configuration step, so that the user can check configure output
    echo "Press <ENTER> to continue..."
    read userinput
 
    # Note: To speed up compiling, change 'make -j2' to 'make -jx',
    #   where x is your number of processors +1
    nice make -j2 && make install
    #Use this line instead if using icecream
    #nice make CC=icecc -j6 && make install
    RETURN=$?
    cs
    return ${RETURN}
}
 
##
# A function to easily run cmake for KDE configuration
##
function kdecmake {
    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 disable tests, remove -DKDE4_BUILD_TESTS=TRUE
    # To save disk space change "debugfull" to "debug"
    cmake "$srcFolder" \
          -DCMAKE_INSTALL_PREFIX=$KDEDIR \
          -DKDE4_AUTH_POLICY_FILES_INSTALL_DIR=$KDEDIR/share/polkit-1/actions \
          -DKDE4_BUILD_TESTS=TRUE \
          -DCMAKE_BUILD_TYPE=debugfull
    RETURN=$?
    cs
    return ${RETURN}
}
 
##
# A function to easily make and install the current or selected directory of KDE.
##
function kdemake {
    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
 
    # Note: To speed up compiling, change 'make -j2' to 'make -jx',
    #   where x is your number of processors +1
    nice make -j2 && make install
    #Use this line instead if using icecream
    #nice make CC=icecc -j6 && make install
    RETURN=$?
    cs
    return ${RETURN}
}
 
function cd() {
  if test -z "$1"; then
    builtin cd
  elif test -z "$2"; then
    builtin cd "$1"
  else
    builtin cd "$1" "$2"
  fi
  _f=`findup .build-config`
  if test -n "$_f" -a "$_lastf" != "$_f"; then
    echo "Loading $_f"
    _lastf="$_f"
    source "$_f"
  fi
}
 
##
# A function to easily change to the build directory.
# Usage: cb KDE/kdebase
#   will change to $KDE_BUILD/KDE/kdebase
# Usage: cb
#   will simply go to the build folder if you are currently in a src folder
#   Example:
#     $ pwd
#     /home/user/src/KDE/kdebase
#     $ cb && pwd
#     /home/user/build/KDE/kdebase
#
function cb {
        local dest
 
    # Make sure build directory exists.
    mkdir -p "$KDE_BUILD"
 
    # command line argument
    if test -n "$1"; then
        cd "$KDE_BUILD/$1"
        return
    fi
    # substitute src dir with build dir
    dest=`pwd | sed -e s,$KDE_SRC,$KDE_BUILD,`
    if test ! -d "$dest"; then
        # build directory does not exist, create
        mkdir -p "$dest"
    fi
    cd "$dest"
}
 
##
# Change to the source directory.  Same as cb, except this
# switches to $KDE_SRC instead of $KDE_BUILD.
# Usage: cs KDE/kdebase
#   will change to $KDE_SRC/KDE/kdebase
# Usage: cs
#   will simply go to the source folder if you are currently in a build folder
#   Example:
#     $ pwd
#     /home/myuser/kde/build/master/KDE/kdebase
#     $ cs && pwd
#     /home/myuser/kde/src/master/KDE/kdebase
#
function cs {
        local dest current
 
    # Make sure source directory exists.
    mkdir -p "$KDE_SRC"
 
    # command line argument
    if test -n "$1"; then
        cd "$KDE_SRC/$1"
    else
        # substitute build dir with src dir
        dest=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`
        current=`pwd`
        if [ "$dest" = "$current" ]; then
            cd "$KDE_SRC"
        else
            cd "$dest"
        fi
    fi
}
 
##
# Add autocompletion to cs function
#
function _cs_scandir
{
        local base ext
 
    base=$1
    ext=$2
    if [ -d $base ]; then
        for d in `ls $base`; do
            if [ -d $base/$d ]; then
                dirs="$dirs $ext$d/"
            fi
        done
    fi
}
 
function _cs()
{
    local cur dirs
    _cs_scandir "$KDE_SRC"
    _cs_scandir "$KDE_SRC/KDE" "KDE/"
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    COMPREPLY=( $(compgen -W "${dirs}" -- ${cur}) )
}
 
svndiff ()
{
    svn diff "$*" | colordiff | less;
}
 
# Setup shell
if [ "$CURRENT_SHELL" = "bash" ]; then
    complete -F _cs cs
fi

This page was last modified on 22 December 2012, at 14:42. This page has been accessed 35,737 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal