Difference between revisions of "Getting Started/Build/Mac OS X/MacPorts"

Line 321: Line 321:
===Configure svn+ssh===
===Configure svn+ssh===
If using svn+ssh for subversion access, copy your key into ~/.ssh and set its permissions to 400.
If using svn+ssh for subversion access, copy your key into ~/.ssh and set its permissions to 400.
===Create KDE directories===

Revision as of 10:53, 10 August 2010


The process described here is one of many ways to set up a KDE development environment on Mac OS X. It sets up a MacPorts installation to provide the required dependencies and uses this to then build a KDE trunk development environment. This approach has the big advantage of using MacPorts to build, install and keep updated the base system and libraries required with minimal effort and without touching the base OSX system install.

It also gives you the choice of installing and running the latest stable KDE SC for everyday use while still developing on the unstable trunk.

The main disadvantage is compiling all the MacPort dependencies takes longer than binary installs, but the ease of maintenance is worth it.

One point to remember is that OS X is a customised version of BSD, so while it feels fairly familiar to a Linux developer, there are the occasional banana skins to slip you up. My pet hate is how useless Finder is for file management, particularly with hidden .files. You will be glad when you get Dolphin and Krusader installed. More importantly, remember that the OS X filesystem despite appearances is by default not case sensitive, so KDE == kde == kDe.

Install XCode and X11.

Install Apple's XCode developer tools either from your OS X install disks or download from http://developer.apple.com/technologies/xcode.html.

If you are running Tiger you will also need to install Apple's X11 from your OS X Install disks. Snow Leopard and Leopard come with it installed by default.

Once installed, perform an OS X Software Update to ensure your system is fully up-to-date and reboot if required.


"The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system."

MacPorts installs everything into /opt/local and so doesn't interfere with the base OS X install or any other local installs you have. This enables you to control the environment search hierarchy for different purposes.

Applications installed via MacPorts can be run from the command line or from the /Applications/MacPorts folder in the finder.

Install MacPorts.

It is recommended to initially install MacPorts using the package installer as this will automatically set-up your required $PATH.

Using MacPorts.

MacPorts should be very easy to use for anyone used to Linux-style package management.

Update MacPorts and the list of available ports, you should do this first whenever you work with the port command:

 sudo port selfupdate

List all available packages, this will be very long:

 port list

List all installed packages:

 port installed

Search for a package:

 port search <package>

Show information about a package:

 port info <package>

Install a package, the -v is needed to see the build output:

 sudo port -v install <package>

List the contents of an installed package

 port contents <package>

List all installed packages with available updates:

 port outdated

Upgrade a package and uninstall the old version (omit the -u to just disable the old version, useful when the new version may break things):

 sudo port -u -v upgrade <package>

Upgrade all outdated packages with new versions and uninstall the old versions:

 sudo port -u -v upgrade outdated

Upgrade all installed packages and uninstall the old versions:

 sudo port -u -v upgrade installed

Uninstall a package:

 sudo port uninstall <package>

See the MacPorts documentation for more advanced options.

GUI frontends are available if you prefer.

Installing the base requirements

You can choose to find and install each requirement on your own, or if you have less time and plenty of disk space you can just install the stable KDE SC and let it pull all the dependencies in for you.

If you have plenty of time, just choose to install one of the major KDE packages and leave it running for 24-48 hours, kdesdk4 seems the obvious choice:

 sudo port -v install kdesdk4

This will resolve all the dependencies and compile and install everything you need including development tools like subversion and cmake.

You may prefer to break it up into smaller chunks, although the Qt build will still take a long time.

 sudo port -v install cmake
 sudo port -v install qt4-mac
 sudo port -v install kdelibs4

Feel free to install all the modules you later intend to build trunk for to ensure you have all your requirements. Once everything is built you should be able to run the stable apps from /Applications/MacPorts/KDE4 or just search for them using Spotlight.

Configure your KDE development environment

From this point on, the process is very similar to a standard KDE development build using dfaure's scripts. An alternative option might be the kdesrc-build script.

Configure bash scripts

Fire up a Terminal and perform the following steps.

Create a home bin directory and create a new script in it called findup:

 cd ~
 mkdir bin
 cd bin
 vim findup

Copy the following into findup: #!/bin/sh arg="$1" if test -z "$arg"; then exit 1; fi while ! test -e "$arg"; do

 cd ..
 if test "$PWD" = "/"; then
   exit 1

done echo $PWD/$arg

Modify your bash profile with some handy utilities:

 cd ~
 vim .profile

Copy the following into .profile:

export PATH=~/bin:$PATH

alias ls='ls -AFG'

    1. A script to setup some needed variables and functions for KDE 4 development.

prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" && export $1 ; }

  1. This will make the debug output prettier


  1. Make
  2. Tell many scripts how to switch from source dir to build dir:


  1. Use makeobj instead of make, to automatically switch to the build dir.
  2. If you don't have makeobj, install the package named kdesdk-scripts or
  3. kdesdk, or check out kdesdk/scripts from svn, or just don't set the alias
  4. yet.

alias make=makeobj

  1. A function to easily build the current directory of KDE.
  2. This builds only the sources in the current ~/{src,build}/KDE subdirectory.
  3. Usage: cs KDE/kdebase && cmakekde
  4. will build/rebuild the sources in ~/src/KDE/kdebase

function cmakekde {

       if test -n "$1"; then
               # srcFolder is defined via command line argument
               # get srcFolder for current dir
               srcFolder=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`
       # we are in the src folder, change to build directory
       # Alternatively, we could just use makeobj in the commands below...
       if [ "$srcFolder" = "$current" ]; then
       # 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
       cmake "$srcFolder" -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \
               -DKDE4_BUILD_TESTS=TRUE \
       # uncomment the following two lines to make builds wait after
       # 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 -j3 && make install
       return ${RETURN}


  1. for the lazy ones, add/comment other directories

function cmakekdeall {

       cs trunk/kdesupport && svn up && cmakekde
       cs trunk/KDE/kdelibs && svn up && cmakekde
       cs trunk/KDE/kdepimlibs && svn up && cmakekde
       cs trunk/KDE/kdebase && svn up && cmakekde
       cs trunk/KDE/kdepim && svn up && cmakekde
       cs trunk/KDE/kdegraphics && svn up && cmakekde
       cs trunk/KDE/kdemultimedia && svn up && cmakekde
       cs trunk/KDE/kdenetwork && svn up && cmakekde
       cs trunk/KDE/kdeutils && svn up && cmakekde


function cd() {

 if test -z "$1"; then
   builtin cd
 elif test -z "$2"; then
   builtin cd "$1"
   builtin cd "$1" "$2"
 _f=`findup .my-setup`
 if test -n "$_f" -a "$_lastf" != "$_f"; then
   echo "Loading $_f"
   source "$_f"


  1. A function to easily change to the build directory.
  2. Usage: cb KDE/kdebase
  3. will change to $KDE_BUILD/KDE/kdebase
  4. Usage: cb
  5. will simply go to the build folder if you are currently in a src folder
  6. Example:
  7. $ pwd
  8. /home/user/src/KDE/kdebase
  9. $ cb && pwd
  10. /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"
       # 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"
       cd "$dest"


  1. Change to the source directory. Same as cb, except this
  2. switches to $KDE_SRC instead of $KDE_BUILD.
  3. Usage: cs KDE/kdebase
  4. will change to $KDE_SRC/KDE/kdebase
  5. Usage: cs
  6. will simply go to the source folder if you are currently in a build folder
  7. Example:
  8. $ pwd
  9. /home/user/build/KDE/kdebase
  10. $ cs && pwd
  11. /home/user/src/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"
               # substitute build dir with src dir
               dest=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`
               if [ "$dest" = "$current" ]; then
                       cd "$KDE_SRC"
                       cd "$dest"


  1. Add autocompletion to cs function

function _cs_scandir {

       local base ext
       if [ -d $base ]; then
               for d in `ls $base`; do
                       if [ -d $base/$d ]; then
                               dirs="$dirs $ext$d/"


function _cs() {

       local cur dirs
       _cs_scandir "$KDE_SRC"
       _cs_scandir "$KDE_SRC/KDE" "KDE/"
       COMPREPLY=( $(compgen -W "${dirs}" -- ${cur}) )


  1. Remove comment on next line to enable cs autocompletion

complete -F _cs cs

svndiff() {

   svn diff "$*" | colordiff | less;


Configure svn+ssh

If using svn+ssh for subversion access, copy your key into ~/.ssh and set its permissions to 400.

Create KDE directories

Content is available under Creative Commons License SA 4.0 unless otherwise noted.