Getting Started/Build/Mac OS X/MacPorts: Difference between revisions

From KDE TechBase
Line 487: Line 487:
   svn co svn+ssh://[email protected]/home/kde/trunk/kdesupport
   svn co svn+ssh://[email protected]/home/kde/trunk/kdesupport


===Edit 07/2012 ====
===Edit 07/2012 ===


I haven't luck with this method on lion
I haven't luck with this method on lion

Revision as of 14:13, 13 July 2012

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, note however that keeping the old version around may confuse the KDE build):

 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
 sudo port -v install dialog
 sudo perl -MCPAN -e 'install Bundle::LWP'

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.

At time of writing (10 Aug 2010) the following KDE SC 4.4.5 packages were available:

 kdebase4
 kdebase4-runtime
 kdeedu4
 kdegames4
 kdegraphics4
 kdelibs4
 kdemultimedia4
 kdenetwork4
 kdepim4
 kdepimlibs4
 kdesdk4
 kdetoys4
 kdeutils4
 amarok
 digikam
 kipi-plugins
 kdesvn
 kdenlive
 kile
 konversation
 krusader
 ktorrent

Before running any KDE apps you need to perform a couple of steps once only (replace $USER with your our username):

 sudo chown -R $USER ~/Library/Preferences/KDE
 sudo launchctl load  -w /Library/LaunchDaemons/org.freedesktop.dbus-system.plist
 launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist

The 2nd and 3rd lines start DBUS and configure it to auto-run on every boot. Ignore what the KDE packages say, these are the correct commands needed now as described by the dbus package itself.

Once this is done you should be able to run the stable apps from /Applications/MacPorts/KDE4 or just search for them using Spotlight.

You may want to install the following extra packages to enable more features:

 ffmpeg
 polkit-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
 vim bin/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

Make findup executable:

 chmod 777 bin/findup

Modify your bash profile with some handy utilities:

 vim ~/.profile

Copy the following into .profile:

export PATH=~/bin:$PATH

alias ls='ls -AFG'

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

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

##
# 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
}

##
# 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/user/build/KDE/kdebase
#     $ cs && pwd
#     /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
}

##
# 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}) )
}

# Remove comment on next line to enable cs autocompletion
complete -F _cs cs

svndiff()
{
    svn diff "$*" | colordiff | less;
}

Close your Terminal and open a new Terminal to have the .profile changes take effect, you should hopefully not see any error messages.

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

#Set up Qt environment
#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

#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
 
# CMake
# Make sure CMake searches the right places.

# Add the MacPorts paths so they take priority over any system versions
prepend CMAKE_PREFIX_PATH  /opt/local
prepend CMAKE_LIBRARY_PATH /opt/local/lib
prepend CMAKE_INCLUDE_PATH /opt/local/include

# Add the KDE paths so they always take priority
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
 
# DBus
# only set DBUS related variables if you compiled dbus on your own
# (which is really discouraged). if you use the distro provided dbus,
# skip this variable. Uncomment it if necessary.
#export DBUSDIR=$KDEDIR
#prepend PKG_CONFIG_PATH $DBUSDIR/lib/pkgconfig
 
# only needed on some strange systems for compiling Qt. do not set
# it unless you have to.
#export YACC='byacc -d'
 
# XDG
#unset XDG_DATA_DIRS # to avoid seeing kde3 files from /usr
#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

Checkout and Build KDE

Next cd into the source directory and checkout kdesupport:

 cd ~/kde/src/trunk
 svn co svn+ssh://[email protected]/home/kde/trunk/kdesupport

Edit 07/2012

I haven't luck with this method on lion

 I have had best luck by downloading the KDEsrc from their homepage  kdesrc-build 1.15.1 http://kdesrc-build.kde.org/releases/kdesrc-build-1.15.1.php
 once downloaded i place the file in ~/kdesrc  when running the ./kdesrc-build-setup use the default variables
 you can then run ./kdesrc-build


If your checkout completes OK, then start compiling:

 cd kdesupport
 cmakekde

This will pause after running the configure step for you to confirm everything is OK. Press enter if you are happy to continue, or ctrl-c to cancel. Later, you can remove this pause/enter by editing the cmakekde command in your .profile.