Getting Started/Build/Mac OS X/MacPorts

From KDE TechBase

Introduction

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.

OS X for Linux developers

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.

The OS X filesystem, despite appearances, is by default not case sensitive, so KDE == kde == kDe.

It would appear all bash customisations need to go in ~/.profile rather than ~/.bashrc.

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 :-)

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.

MacPorts.

"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>

Switch to a different installed version of a package:

 sudo port -v activate <package> <version>

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
 etc...

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.

Programs will not start until you run the command, replacing $USER with your username:

 sudo chown -R $USER ~/Library/Preferences/KDE

Don't forget that dbus needs to be started as the local user (not with sudo) before any KDE programs will launch. To start it run the following command:

 launchctl load /Library/LaunchAgents/org.freedesktop.dbus-session.plist

You may or may not need to manually install the following:

 polkit-qt
 openslp
 samba3?
 libssh2?

Reported not found:

kdelibs:

 QCA2
 libacl
 FAM
 HSpell

kdebase-runtime:

 OpenSLP
 Samba
 libssh >= 0.4.0

kdesdk:

 boost >= 1.33.1

kdebase4:

 XKB

kdegraphics:

 Poppler-Qt4 >= 0.8
 libepub

kdepim:

 indicate-qt

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
 fi

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

export KDE_COLOR_DEBUG=1 export QTEST_COLORED=1

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

export OBJ_REPLACEMENT="s#$KDE_SRC#$KDE_BUILD#"

  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
               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
       cmake "$srcFolder" -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \
               -DKDE4_BUILD_TESTS=TRUE \
               -DCMAKE_BUILD_TYPE=debugfull
       # 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=$?
       cs
       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"
 else
   builtin cd "$1" "$2"
 fi
 _f=`findup .my-setup`
 if test -n "$_f" -a "$_lastf" != "$_f"; then
   echo "Loading $_f"
   _lastf="$_f"
   source "$_f"
 fi

}

  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"
               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"

}

  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"
       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

}

  1. 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}) )

}

  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

Choose you KDE development base directory where the KDE source, build and installation will be kept. In this example the base directory is ~/kde but it could be anywhere with sufficient space and permissions. Create the following set of directories:

 cd ~
 mkdir kde
 cd kde
 mkdir kde/build
 mkdir kde/home
 mkdir kde/inst
 mkdir kde/src
 mkdir kde/src/branches
 mkdir kde/src/trunk

Configure your KDE environment

Now install the script that will set up the KDE environment for trunk development:

 vim ~/kde/src/trunk/.my-setup

Copy the following into .my-setup and set BASEDIR as required:

#Set up base directory to your chosen location export BASEDIR=/Users/your-user/kde

  1. Set up Qt environment
  2. Use Qt from MacPorts, change QTDIR if using own version of Qt

export QTDIR=/opt/local/libexec/qt4-mac export PATH=$QTDIR/bin:$PATH export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH export PKG_CONFIG_PATH=$QTDIR/lib:$PKG_CONFIG_PATH

  1. Set up KDE environment

export KDE_BUILD=$BASEDIR/build export KDEHOME=$BASEDIR/home/.kde4trunk export KDEDIR=$BASEDIR/inst/kde4trunk export KDE_SRC=$BASEDIR/src export KDETMP=/tmp/kde4trunk-$USER export KDEVARTMP=/var/tmp/kde4trunk-$USER mkdir -p $KDETMP mkdir -p $KDEVARTMP export PATH=$KDEDIR/bin:$PATH export LD_LIBRARY_PATH=$KDEDIR/lib:$LD_LIBRARY_PATH prepend PKG_CONFIG_PATH $KDEDIR/lib/pkgconfig export QT_PLUGIN_PATH=$KDEDIR/lib/kde4/plugins export KDEDIRS=$KDEDIR

export PYTHON_SITE_PACKAGES_DIR=$KDEDIR/lib/python2.6/site-packages/PyKDE4

export PATH export LD_LIBRARY_PATH export PKG_CONFIG_PATH export QT_PLUGIN_PATH

  1. CMake
  2. Make sure CMake searches the right places.

prepend CMAKE_PREFIX_PATH $KDEDIR prepend CMAKE_LIBRARY_PATH $KDEDIR/lib prepend CMAKE_INCLUDE_PATH $KDEDIR/include

export CMAKE_PREFIX_PATH export CMAKE_LIBRARY_PATH export CMAKE_INCLUDE_PATH

  1. DBus
  2. only set DBUS related variables if you compiled dbus on your own
  3. (which is really discouraged). if you use the distro provided dbus,
  4. skip this variable. Uncomment it if necessary.
  5. export DBUSDIR=$KDEDIR
  6. prepend PKG_CONFIG_PATH $DBUSDIR/lib/pkgconfig
  1. only needed on some strange systems for compiling Qt. do not set
  2. it unless you have to.
  3. export YACC='byacc -d'
  1. XDG
  2. unset XDG_DATA_DIRS # to avoid seeing kde3 files from /usr
  3. unset XDG_CONFIG_DIRS

Finally, change into the trunk directory to activate the environment:

 cd ~/kde/src/trunk

You should see the message:

 Loading /Users/odysseus/kde/src/trunk/.my-setup

Try typing env to see settings similar to: BASEDIR=/Users/odysseus/kde QTDIR=/opt/local/libexec/qt4-mac QT_PLUGIN_PATH=/Users/odysseus/kde/inst/kde4trunk/lib/kde4/plugins KDE_BUILD=/Users/odysseus/kde/build KDE_SRC=/Users/odysseus/kde/src KDEDIR=/Users/odysseus/kde/inst/kde4trunk KDEDIRS=/Users/odysseus/kde/inst/kde4trunk KDEHOME=/Users/odysseus/kde/home/.kde4trunk KDETMP=/tmp/kde4trunk-odysseus KDEVARTMP=/var/tmp/kde4trunk-odysseus LD_LIBRARY_PATH=/Users/odysseus/kde/inst/kde4trunk/lib:/opt/local/libexec/qt4-mac/lib PATH=/Users/odysseus/kde/inst/kde4trunk/bin:/opt/local/libexec/qt4-mac/bin:/opt/local/bin:/opt/local/sbin:/Users/odysseus/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin PKG_CONFIG_PATH=/opt/local/libexec/qt4-mac/lib PYTHON_SITE_PACKAGES_DIR=/Users/odysseus/kde/inst/kde4trunk/lib/python2.6/site-packages/PyKDE4