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

Jump to: navigation, search
(Introduction)
(Configure bash scripts)
Line 95: Line 95:
  
 
===Configure bash scripts===
 
===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:
 +
<code>
 +
  #!/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
 +
</code>
 +
 +
Modify your bash profile with some handy utilities:
 +
  cd ~
 +
  vim .profile
 +
 +
Copy the following into .profile:
 +
 +
<code>
 +
export PATH=~/bin:$PATH
 +
 +
# MacPorts Installer addition on 2010-02-02_at_21:23:42: adding an appropriate PATH variable for use with MacPorts.
 +
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
 +
# Finished adapting your PATH environment variable for use with MacPorts.
 +
 +
alias ls='ls -AFG'
 +
 +
###
 +
## A script to setup some needed variables and functions for KDE 4 development.
 +
## This should normally go in the ~/.bashrc file of your kde-devel user, so
 +
## that it is executed when a session for that user is started.
 +
##
 +
## Example:
 +
##  su - kde-devel
 +
##  kwrite ~/.bashrc
 +
##  (then paste this file)
 +
##  exit
 +
##  su - kde-devel
 +
##
 +
## If you don't use a separate user, the first section with the
 +
## environment variables should go into a separate file of course.
 +
 +
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;
 +
}
 +
</code>
  
 
===Configure subversion===
 
===Configure subversion===

Revision as of 11:21, 10 August 2010

Contents

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.

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.

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>

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.

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

  1. MacPorts Installer addition on 2010-02-02_at_21:23:42: adding an appropriate PATH variable for use with MacPorts.

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

  1. Finished adapting your PATH environment variable for use with MacPorts.

alias ls='ls -AFG'

    1. A script to setup some needed variables and functions for KDE 4 development.
    2. This should normally go in the ~/.bashrc file of your kde-devel user, so
    3. that it is executed when a session for that user is started.
    4. Example:
    5. su - kde-devel
    6. kwrite ~/.bashrc
    7. (then paste this file)
    8. exit
    9. su - kde-devel
    10. If you don't use a separate user, the first section with the
    11. environment variables should go into a separate file of course.

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 subversion


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal