KDE TechBase
  • Page
  • Discussion
  • Edit
  • History
KDE TechBase is a Wiki - You can help! Please contribute! Questions?
Please ask development related questions in the KDE Community Forum.

Getting Started/Increased Productivity in KDE4 with Scripts/Environment Scripts

< Getting Started | Increased Productivity in KDE4 with Scripts
Revision as of 22:00, 24 September 2009 by Mwoehlke (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenščina | српски | Українська | 简体中文 | 繁體中文

Contents

  • 1 Abstract
  • 2 Functions
  • 3 The Scripts
    • 3.1 .bash_profile
    • 3.2 .siteconfig
    • 3.3 .k4funcs

[edit] Abstract

This is an example for a ~/.bash_profile file and supporting ~/.k4funcs for use with your kde-devel account. These are provided as an alternative to the example .bashrc (which they are based on) in the hopes that they provide some useful additions (and because the author is too lazy to try to merge them right now ;-) ).

Some features are:

  • separate ~/.k4funcs can be sourced multiple times to pick up changes
  • tab completion of 'cs'
  • short aliases for everything, for lazy typists :-) (aren't we all?)
  • filtered 'svn up' output

Please note that no build type is specified in cmakekde. 'debugfull' is recommended for development or advanced debugging. If you just want to build the latest KDE, 'relwithdebinfo' (the default when no build type is specified) will result in faster binaries, at the expense of some debugging ability. Also see here. In other words, if you don't want relwithdebinfo, you should add that line to cmakekde and cmakekdeclean.

Please also note that this comes from a Fedora x64 system that needs -DLIB_SUFFIX=64. If you are using system libraries from /usr/lib instead of /usr/lib64, you probably want to remove this line.

[edit] Functions

Here is a quick run-down of the functions created by these scripts. We'll assume you are lazy and only care about the short forms. You can easily find the long forms by checking the output of 'alias'.

  • cs: change to the specified source directory
    • with an argument, changes to that subdirectory of your source root ($KDE_SRC); understands tab completion
    • without arguments, changes to the corresponding source directory when in a build directory, otherwise changes to your source root
  • cb: change to the specified build directory
    • function is similar to 'cs' but lacks tab completion (you won't use this nearly as often, and you can always 'cs' to a named location and then 'cb')
  • up: fetches latest changes
    • without an argument, updates all subdirectories of the source root
    • with arguments, updates just the named subdirectories; understands tab completion
    • output is abbreviated; conflicts and merges are shown in color, property changes are shown normally (mostly because they occur infrequently enough that the author is too lazy to filter them :-) ); everything else is shown as a summary of number of files modified, added, deleted, etc.
    • works on svn with conflicts postponed
    • works on unmodified hg
    • works on git and git-svn, as long as the branch to pull is named 'master'; if the current branch is not 'master', the function attempts to switch to master, rebase that onto upstream, then rebase the current branch onto the new master
  • co: shortcut to check out a module from trunk/KDE; takes the name of the module to check out
  • qc: shortcut to configure qt-kde; use in qt-kde's source directory
  • qm: shortcut to build qt-kde; same notes as 'qc'
  • kc: configures the current directory, which should be the top level of a module (can be in either the source or build directory)
  • kcc: like 'kc', but nukes the build directory first, i.e. does a "clean" configure
  • km: builds the current directory (can be used at top level or in subdirectories, in either the source or build trees)
  • kmv: verbose variant of 'km'
  • kt: runs 'ctest' with the specified arguments in the effective build directory (i.e. 'cb ; ctest "$@"')
  • kmm: build several modules; specify one or more modules to build as arguments; understands tab completion
  • kma: builds KDE core ($core_packages; see .siteconfig); the "a" is for "all"
  • kcma: like 'kma', but configure first
  • kccma: like 'kma' but do clean configure first
  • kmra: build everything ($core_packages plus $extra_packages; see .siteconfig); the "ra" is for "really all"
  • kcmra: like 'kmra' but configure first
  • kccmra: see the pattern yet? :-)

[edit] The Scripts

All of these go in your kde build user's home directory. For convenience, things you should customize (or otherwise be aware of) are marked with '###'. This is designed so that .k4funcs should be usable without modification on multiple systems. System-specific settings (including the list of packages to build) live either in .bash_profile or .siteconfig. The former is concerned mainly with how your tree is set up, and should only ever be run at login. The latter deals with configuring the functions and can be run at will (e.g. if you make changes, you can re-source .k4funcs without logging out and back in).

[edit] .bash_profile

# .bash_profile
 
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
 
# User specific environment and startup programs
 
### Optional
PATH=$HOME/bin:$PATH
export PATH
 
# Set konsole colors
### This will let you set up a color scheme just for your KDE build environment;
### helpful to tell instantly what a konsole tab is for
# echo -ne "\033]50;ColorScheme=Linux KDE\a"
 
#BEGIN KDE build environment setup
prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" ; } # unbreak vim's syntax HL --> "
 
# KDE
### Change to taste
export KDEDIR=/usr/local/kde-trunk-svn
export KDEHOME=$HOME/.kde-trunk
export KDETMP=/tmp/$USER-kde-trunk
mkdir -p $KDETMP
export KDEVARTMP=/var/tmp/$USER-kde-trunk
export KDEDIRS=$KDEDIR
 
### Replace 'lib64' with 'lib' if that matches your system
prepend PKG_CONFIG_PATH $KDEDIR/lib64/pkgconfig
prepend LD_LIBRARY_PATH $KDEDIR/lib64
prepend PATH $KDEDIR/bin
 
# Qt
### Change to taste, or omit this section if using your distro's Qt
export QTDIR=/usr/local/qt4-kde
 
prepend QT_PLUGIN_PATH $KDEDIR/lib64/kde4/plugins
prepend PKG_CONFIG_PATH $QTDIR/lib64/pkgconfig
prepend LD_LIBRARY_PATH $QTDIR/lib64
prepend PATH $QTDIR/bin
 
# Java
### This works for Fedora 10; change to match your system
export JAVA_HOME=/usr/lib/jvm/java
 
# Export anything that may have been empty
export LD_LIBRARY_PATH PKG_CONFIG_PATH QT_PLUGIN_PATH PATH
 
# XDG
unset XDG_DATA_DIRS
unset XDG_CONFIG_DIRS
 
# Build and source folders
### Change these to taste
export KDE_BUILD=/var/local/build/kde/svn/trunk
export KDE_SRC=/usr/local/src/kde/svn/trunk
 
[ -d $KDE_SRC ] || mkdir -p $KDE_SRC
[ -d $KDE_BUILD ] || mkdir -p $KDE_BUILD
 
unset -f prepend
#END KDE build environment setup
 
. ~/.k4funcs

[edit] .siteconfig

# kate: hl bash
 
# Prompt
ps_src='\e[1;34m[source]\e[1;36m'
ps_bld='\e[1;35m[build]\e[1;36m'
 
### If konsole is set to use '%w' for tab titles, this is what your tab title
### will be; mostly it is to reset the tab title after parts of .k4funcs change
### it to show your build status
export TAB_TITLE="[kde] \$(basename \"\$PWD\")"
# Use substitution on local PS1; we likes the shiny
### Change to taste; the 'shortpath' bit will abbreviate your source and build
### directories (see .k4funcs, below)
export PS1="\[\e]0;\$(eval echo \$TAB_TITLE)\a\]\[\e[1;31m\]\t \[\e[33m\]\u@\h \[\e[36m\]\$(shortpath \"\w\")\[\e[0m\e[K\]\n\[\e[1;36m\]\W\[\e[1;37m\]\\$\[\e[0m\] "
 
# Status functions
function configure_result {
### This is run when 'cmakekde' completes, with the result in $1.
### You can add notifications here, e.g. you might play a sound.
return $1
}
 
function make_result {
### This is run when 'makekde' completes, with the result in $1.
### You can add notifications here, e.g. you might play a sound.
[ $1 -eq 0 ] && echo SUCCESS
return $1
}
 
# Extra arguments to cmake
cmake_extra=
### Add anything you need as array elements. For example:
### cmake_extra[0]=-DLIB_SUFFIX=64
### cmake_extra[1]=-DCMAKE_BUILD_TYPE=debugfull
 
# What to build
### This assumes you have checked out e.g. kdesupport as
### $KDE_SRC/kdesupport; likewise for kdelibs, etc. Change as needed.
###
### This specifies what packages are considered when building
### "just the core". For example, you may want to add 'eigen2', 'wv2' and/or
### 'libssh', or remove kdesupport.
core_packages="kdesupport kdelibs kdepimlibs kdebase"
###
### This specifies what packages are considered when building "everything"
### (kmra and friends).
extra_packages="kdeutils kdegraphics kdegames kdepim kdenetwork kdesdk kdevplatform kdevelop kdemultimedia kdeartwork kdeaccessibility koffice kdeplasma-addons"

[edit] .k4funcs

# kate: hl bash
 
# Set EDITOR for subversion
### Optional
export EDITOR=vim
 
# Nicer man/git paging
export LESS=-F
 
# Prettier debug
export KDE_COLOR_DEBUG=1
export QTEST_COLORED=1
 
##
# Site configuration
# This is for stuff that might differ between machines. It should define:
# - core_packages, extra_packages (variables)
# - ps_src, ps_bld (variables)
# - cmake_extra (array variable)
# - configure_result, make_result (functions)
. ~/.siteconfig
 
##
# IMPORTANT! Uncomment the following lines if DBus does not work. DBus is not
# working if, when you run `dbus-uuidgen --ensure && qdbus`, you get an error.
#
# alias dbusstart="eval `PATH=$DBUSDIR/bin \
# $DBUSDIR/bin/dbus-launch --auto-syntax`"
 
##
# A function to easily change to the build directory.
# Usage: cb kdebase
# will change to $KDE_BUILD/kdebase
# Usage: cb
# will simply go to the build folder if you are currently in a src folder
# Example:
# $ pwd
# /home/user/src/kdebase
# $ cb && pwd
# /home/user/build/kdebase
#
function cb {
# command line argument
if [ -n "$1" ]; then
cd $KDE_BUILD/$1
return
fi
# substitue src dir with build dir
dest=`pwd | sed -e s,$KDE_SRC,$KDE_BUILD,`
if [ ! -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 kdebase
# will change to $KDE_SRC/kdebase
# Usage: cs
# will simply go to the source folder if you are currently in a build folder
# Example:
# $ pwd
# /home/user/build/kdebase
# $ cs && pwd
# /home/user/src/kdebase
#
function cs {
# command line argument
if [ -n "$1" ]; then
cd $KDE_SRC/$1
else
# substitue build dir with src dir
dest=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`
if [ $dest = `pwd` ]; then
cd $KDE_SRC
else
cd $dest
fi
fi
}
 
function completecs {
COMPREPLY=( $(cd $KDE_SRC; compgen -d "$2") )
}
complete -o nospace -F completecs cs
 
function shortpath {
case "$1" in
$KDE_SRC*) echo -ne "$ps_src"; echo "${1:${#KDE_SRC}}";;
$KDE_BUILD*) echo -ne "$ps_bld"; echo "${1:${#KDE_BUILD}}";;
*) echo "$1";;
esac
}
 
##
# A function to easily configure the current directory of KDE, from scratch.
#
# This configures only the sources in the current src/build subdirectory, but
# first it nukes the build directory.
# Usage: cs kdebase && cmakekdeclean
# will configure the sources in ${KDE_SRC}/kdebase
#
function cmakekdeclean() (
[ "`pwd | grep $KDE_SRC`" = "" ] && cs "$@"
srcFolder=`pwd`
cb
buildFolder=`pwd`
[ ${#KDE_BUILD} -gt 0 ] \
&& [ "${buildFolder:0:${#KDE_BUILD}}" = "$KDE_BUILD" ] \
&& rm -rf "$buildFolder"/*
cmake -DCMAKE_INSTALL_PREFIX=$KDEDIR \
-DKDE4_BUILD_TESTS=TRUE \
"${cmake_extra[@]}" \
$srcFolder
configure_result $?; return $?
)
 
##
# A function to easily configure the current directory of KDE.
#
# This configures only the sources in the current src/build subdirectory.
# Usage: cs KDE/kdebase && cmakekde
# will configure the sources in ${KDE_SRC}/kdebase
#
function cmakekde() (
[ "`pwd | grep $KDE_SRC`" = "" ] && cs "$@"
srcFolder=`pwd`
cb
cmake -DCMAKE_INSTALL_PREFIX=$KDEDIR \
-DKDE4_BUILD_TESTS=TRUE \
"${cmake_extra[@]}" \
$srcFolder
configure_result $?; return $?
)
 
function installfilter {
local l
while read l ; do
if [ -n "$COLUMNS" ] && (( ${#l} > $COLUMNS )) ; then
l="`echo "$l" | cut -c $((COLUMNS - 4))`..."
fi
if [ "${l:0:15}" = "-- Installing: " ] \
|| [ "${l:0:15}" = "-- Up-to-date: " ] \
|| [ "${l:0:23}" = "-- Set runtime path of " ]
then
echo -ne "$l"'\e[K\e[0G'
else
echo -e "$l"'\e[K'
fi
done
echo -ne '\e[K'
}
 
##
# A function to easily build the current directory of KDE.
#
# This builds only the sources in the current src/build subdirectory.
# Usage: cs KDE/kdebase && cmakekde
# will build/rebuild the sources in ${KDE_SRC}/kdebase
#
function makekde() (
export LC_ALL=C
cb "$@"
cat <<- EOF
 
= Building ${PWD:$(( ${#KDE_BUILD} + 1 ))}
============================================================
EOF
echo -e '\e]0;[k4] building '"${PWD:$(( ${#KDE_BUILD} + 1 ))}"'...\a'
time make -j4 || { make_result $?; return $?; }
echo -e '\e]0;[k4] installing '"${PWD:$(( ${#KDE_BUILD} + 1 ))}"'...\a'
time make install/fast | installfilter
make_result ${PIPESTATUS[0]}; return $?
)
 
function makekdemulti {
local extra
local result
if [ "${1:0:2}" = "--" ] ; then
case "$1" in
--config) extra=cmakekde;;
--clean) extra=cmakekdeclean;
esac
shift 1
fi
for t in "$@" ; do
(
cd $KDE_SRC/"$t"
if [ -n "$extra" ] ; then $extra || exit $? ; fi
makekde
)
result=$?
if [ $result -ne 0 ] ; then
echo "Error(s) while building $t"
return $result
fi
done
}
 
function configureqt() (
[ "`pwd | grep $KDE_SRC`" = "" ] && cs "$@"
srcFolder=`pwd`
cb
$srcFolder/configure -nomake examples -nomake demos \
-qt-gif -webkit -dbus -no-phonon -xinerama -plugin-sql-mysql \
-system-libpng -system-libjpeg -system-zlib \
-debug -fast -no-separate-debug-info -no-exceptions \
-prefix $QTDIR -confirm-license -opensource "$@"
configure_result $?; return $?
)
 
function makeqt() (
export LC_ALL=C
cb "$@"
cat <<- EOF
 
= Building ${PWD:$(( ${#KDE_BUILD} + 1 ))}
============================================================
EOF
echo -e '\e]0;[k4] building '"${PWD:$(( ${#KDE_BUILD} + 1 ))}"'...\a'
time make -j4 || { make_result $?; return $?; }
time make install
make_result $?; return $?
)
 
function testkde() (
cb
ctest "$@"
)
 
function co {
if [ -n "$1" ]; then
cd $KDE_SRC
### Replace with your user name, or the appropriate https or anonsvn
### prefix if not using svn
svn co svn+ssh://user@svn.kde.org/home/kde/trunk/KDE/$1
cd $1
else
echo "Check out what?"
return 1
fi
}
 
function svn_upfilter {
local _u=0 _a=0 _d=0 _g=0 _c=0 out l result=0
while read l ; do
if [ "${l:1:1}" = " " ] ; then
case "${l:0:1}" in
U) (( _u++ ));;
A) (( _a++ ));;
D) (( _d++ ));;
G) (( _g++ )); echo -e " \e[1;32m$l\e[0m";;
C) (( _c++ )); echo -e " \e[1;31m$l\e[0m";;
*) echo " $l";;
esac
elif [ "${l:0:1}" = "`printf '\e'`" ] ; then
echo "$l"
elif [ -n "`echo $l`" ] ; then
if [ -n "$out" ] ; then
out="$out`printf '\n '`$l"
else
out=" $l"
fi
fi
done
[ $_u -gt 0 ] && echo " Updated: $_u"
[ $_a -gt 0 ] && echo " Added: $_a"
[ $_d -gt 0 ] && echo " Removed: $_d"
[ $_g -gt 0 ] && echo -e " Merged: \e[1;32m$_g\e[0m"
[ $_c -gt 0 ] && echo -e " Conflicts: \e[1;31m$_c\e[0m" && result=2
echo "$out"
return $result
}
 
function git_svn_upfilter {
local _m=0 _a=0 _d=0 _r=0 _c=0 _revs=0 out l
while read l ; do
if [ "${l:1:1}" = " " ] ; then
case "${l:0:1}" in
M) (( _m++ ));;
A) (( _a++ ));;
D) (( _d++ ));;
R) (( _r++ ));;
C) (( _c++ ));;
*) echo " $l";;
esac
elif [[ "$l" =~ '^r.*(git-svn)' ]] ; then
(( _revs++ ))
elif [ "$l" = "First, rewinding head to replay your work on top of it..." ] ; then :
elif [ -n "`echo $l`" ] ; then
if [ -n "$out" ] ; then
out="$out`printf '\n '`$l"
else
out=" $l"
fi
fi
done
[ $_m -gt 0 ] && echo " Modified: $_m"
[ $_a -gt 0 ] && echo " Added: $_a"
[ $_c -gt 0 ] && echo " Copied: $_c"
[ $_r -gt 0 ] && echo " Renamed: $_r"
[ $_d -gt 0 ] && echo " Removed: $_d"
[ $_revs -gt 0 ] && echo " $_revs change(s)"
echo "$out"
}
 
function git_up {
local branch=`git branch | sed -n 's/^[*]\s\+//p'`
if [ "$branch" != "master" ] ; then
git checkout master || return $?
fi
git "$@" || return $?
if [ "$branch" != "master" ] ; then
git rebase master $branch || return $?
fi
}
 
function up() (
result=0
echo -e '\e]0;[k4] updating...\a'
cd $KDE_SRC
[ -z "$*" ] && set -- *
for d in "$@" ; do if [ -d $d ] ; then
echo -e "\e[1m$d\e[0m"
if [ -e "$d/.no-update" ] ; then
echo " Directory $d is marked no-update; skipping"
elif [ -d "$d/.svn" ] ; then
( cd $d && svn up --accept postpone ) | svn_upfilter
elif [ -d "$d/.git" ] ; then
if [ -d "$d/.git/svn" ] ; then
( cd $d && git_up svn rebase 2>&1 ) | git_svn_upfilter
echo " Last svn revision: $(cd $d && git svn info | grep 'Last Changed Rev' | sed 's/.*: //')"
else
( cd $d && git_up pull --rebase 2>&1 ) | sed 's/^/ /'
fi
elif [ -d "$d/.hg" ] ; then
( cd $d && hg pull &>/dev/null && hg update ) | sed 's/^/ /'
else
echo " Directory $d doesn't seem to be using any of svn, hg or git; skipping"
fi
for r in ${PIPESTATUS[@]} ; do [ $r -eq 0 ] || result=$r ; done
fi ; done
exit $result
)
complete -W "$(cd $KDE_SRC && find . -maxdepth 1 -type d \! -name '.*' | sed 's,[.]/,,')" up kmm makekdemulti
 
export cmakekde makekde makekdemulti co up git_up svn_upfilter git_svn_upfilter
 
alias kc='cmakekde'
alias kcc='cmakekdeclean'
alias km='makekde'
alias kmv='VERBOSE=1 makekde'
alias kmm='makekdemulti'
alias kma="makekdemulti $core_packages"
alias kcma="makekdemulti --config $core_packages"
alias kccma="makekdemulti --clean $core_packages"
alias kmra="makekdemulti $core_packages $extra_packages"
alias kcmra="makekdemulti --config $core_packages $extra_packages"
alias kccmra="makekdemulti --clean $core_packages $extra_packages"
alias kt='testkde'
alias qc='configureqt'
alias qm='makeqt'
Retrieved from "http://techbase.kde.org/Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/Environment_Scripts"

Navigation

  • Home
  • Help
  • Recent changes

Sections

  • Getting started
  • Development
  • Schedules
  • Policies
  • Contribute
  • Projects

Toolbox

  • What links here
  • Related changes
  • Special pages
  • Printable version
  • Permanent link

Personal tools

  • 38.107.191.99
  • Talk for this IP
  • Log in / create account
  • Login with OpenID
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