Archive:Getting Started/Increased Productivity in KDE4 with Scripts (zh CN)
Getting_Started/Increased Productivity in KDE4 with Scripts
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
Tutorial Series | Getting Started |
Previous | [[../Build/KDE4]] |
What's Next | n/a |
Further Reading | Original presentation by David Faure |
摘要
时间宝贵。本教程分享了 David Faure 的超人智慧,通过使用一些简单的脚本和技术来开发 KDE 4,这样大大节省了我们的时间和精力。
配置环境
为什么是以用户身份安装,而不是 root?
- 像 compile+link+install 这些只是一条简单的命令 (或者甚至是你的编辑器中的一个键), 不需要 su/sudo
- 在构建目录中没有属于 root 文件的风险,只有当某些变化强制 make install 重新编译一些文件才可能发生。
- 在发生某些错误时会更安全 (例如,使用错误的编译预 profix 选项可能会改写 kde3 系统)
- make install 比 "make && sudo make install" 更快,因为 Makefiles 文件只解析了一次
- 在 sudo make install 时不会有连接错误,因为在 root 的环境变量没有 LD_LIBRARY_PATH 记录。并且,配置一次环境已经非常辛苦了,为什么还要为两个用户呢?
配置开发环境
如果你想开一个单独的帐户专门用来开发,请阅读[[../Build/KDE4#Set_up_the_development_user_account|here]]。
但是,为了节省时间和避免许多麻烦,强烈建议使用你经常用的帐户。 你所要做的只是简单地在不同环境之间做一下切换。 你来到 ~/kde/src/4 目录,你想使用 KDE4 环境,不是么?
要实现这个目的,拷贝 http://web.davidfaure.fr/scripts/cd_function 到你的 .zshrc 或者 .bashrc 中,然后,把 http://web.davidfaure.fr/scripts/findup 放到你的路径下 $PATH。
这样,当你进入某个目录,它就会寻找 .my-setup 文件并向上级目录追溯,只到找到 .my-setup(而且它不会在同一方向上找到两次)。
在 ~/kde/src/4/.my-setup 文件中配置好 KDE 4 的所有环境变量 (在本页的后面将会详细介绍),其他环境也同样做(kde3,和其他任何你需要特别配置环境变量的地方...)。
路径举例
Qt
对于 Qt 而言,自 QT3 时代以来的习惯,同时也为了节省时间,我们尽量避免在一个小变化后就 "make install",我建议在一个目录下编辑源文件,构建和安装。这可以通过配置 Qt 编译预选项 -prefix=$PWD 完成 Qt with --prefix=$PWD。当然,你并不一定非要这样做。
Qt 的路径:~/qt/4/qt-copy
KDE
在 kde3 中这是可选的,但在 KDE4 中则是必需的:你需要在 source 目录外进行构建,也就是说构建目录和 source 目录必需是分开的。 这样做可以在出现错误后,很方便地重新构建,删除所有生成的文件 - 包括那些 "make clean" 也无法删除老文件。而且也可以更方便地查看源文件(grep,ls 等)。这样就允许在多个构建树下使用不同的配置,例如:debug 和 发布。
- Source 路径: ~/kde/src/[version]
- Build 路径: ~/kde/build/[version]
因此 kde4 的 source 模块是同步在 ~/kde/src/4/ 而构建是在 ~/kde/build/4/ 中进行的。
环境变量和其他有用的函数
Bash
如果你在使用 bash, 请先阅读 this .bashrc.。这是一个用来设置 KDE4 环境变量和一些有帮助的函数的 bash 配置文件的例子。
下面描述了其中的一些功能并给出了其他可选的函数。
更多了解,请阅读 compiling a KDE module。
目录导航
你可以使用 cs 和 cb 函数来帮你很方便地在源目录和构建目录进行切换,具体操作如下:
pwd
~/kde/src/4/kdebase
cb && pwd
~/kde/build/4/kdebase
# 注意如果这个目录不存在将会创建。
cs && pwd
~/kde/src/4/kdebase
A number of kde-related scripts will have to be able to do the same. Simply do: export OBJ_REPLACEMENT='s#/kde/src/#/kde/build/#' This allows the makeobj script from kdesdk to switch from src to build. If you also do: alias make=makeobj then you can simply type make from the source dir and it will be able to build. This is also very useful in editors - if your vi or emacs uses makeobj as the make command, you can compile with a single key press.
In addition, for fast navigation to other directories, it is very convenient to be able to type "cs 4/kdelibs" in order to go to ~/src/4/kdelibs, from anywhere. For instance, you could be in ~/kde/src/4/kdebase/workspace/kcontrol and now you decide to look at kdecore... No need to type a long series of "../.." or to restart from the top. You can just type cs 4/kdelibs/kdecore.
This is doable via the two functions cs and cb defined in the .bashrc.
Alternative
The following code will enable you to use cd similar to cs described above:
export CDPATH=.:~/kde/src
The advantage, when using zsh, is that completion even works. Try cd 4/kdemul and press Tab, it will complete to 4/kdemultimedia, no matter where you currently are. Doesn't work in bash though - but surely you're using zsh by now, aren't you? :)
The minimal cs and cb aliases (same as above but without support for arguments) are: alias cb='cd `pwd | sed -e s,/kde/src/,/kde/build/,`' alias cs='cd `pwd | sed -e s,/kde/build/,/kde/src/,`'
Going back to the previous directory
Going back to the previous directory easily can be done with zsh. Set this in .zshrc:
setopt AUTO_PUSHD
alias p=popd
and then you can type "p" to pop back to the directory where you were last,
as many times as needed (type "dirs -v" to see the stack of previous directories).
CMake
CMake and subdirs
cd 4/kdelibs/kio/kio ; make => nothing happens, the Makefile is in the parent directory.
Make your editor use a wrapper script instead
- !/bin/sh
if test "$1" = "-k"; then shift; fi
cmake_in_parent=0
if test -f CMakeLists.txt; then
if ! grep -q kde4_add CMakeLists.txt; then
cmake_in_parent=1
cd ..
fi
fi
if test $# -gt 0; then
arg="$1"
if test "$arg" != install -a $cmake_in_parent -eq 1; then
arg=`basename $PWD`/"$arg"
fi
fi
jvalue=1
echo "calling makeobj -j $jvalue $arg"
makeobj -j $jvalue $arg
Get this script: http://web.davidfaure.fr/scripts/makefromemacs.
CMake and dependencies
touch kdecore/kapplication.h cd kdeui ; make
=> recompiles kdecore first
touch kdecore/kapplication.h cd kdeui ; make kdeui/fast
=> recompiles only kdeui
make install/fast
But note that the normal mode (without /fast) is also useful in other cases: For instance you edit
kdelibs/kio/kio/kdirmodel.cpp
and the unit test for it
kdelibs/kio/tests/kdirmodeltest.cpp
Then, to recompile both libkio and the unit test, simply do "make kdirmodeltest" from kdelibs/kio/tests.
List of KDE 4 environment variables
This lists all the environment variables you should set, for instance in $KDESRC/4/.my-setup
Qt
export QTDIR=/d/qt/4/qt-copy
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$QTDIR/lib:$PKG_CONFIG_PATH
KDE
export KDEDIR=/d/kde/inst/kde4
export PATH=$KDEDIR/bin:$PATH
export LD_LIBRARY_PATH=$KDEDIR/lib:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=$KDEDIR/lib/kde4/plugins
export KDEDIRS=$KDEDIR
User
export KDEHOME=$HOME/.kde4
Others
export QTEST_COLORED=1
export KDE_COLOR_DEBUG=1
Compiling a KDE module
Manually
If you use the aforementioned ~/.bashrc it is very convenient to compile a KDE module (it is required to already have aquired the source code, e.g. via SVN. see Using Subversion with KDE):
cs KDE/kdebase
cmakekde
Else you'll have to do the following:
mkdir -p ~/build/KDE/kdebase && cd ~/build/KDE/kdebase
cmake -DKDE4_BUILD_TESTS=TRUE -DCMAKE_BUILD_TYPE=debugfull \
-DCMAKE_INSTALL_PREFIX=~/kde ~/src/KDE/kdelibs
make
Using kdesvn-build
kdesvn-build is an all-in-one script: it handles the checking-out or updating from subversion, running cmake, make, make install, and storing all output in log files.
Copy kdesvn-buildrc-sample to $KDE_SRC/.kdesvn-buildrc, then edit it. Global options:
- binpath - don't forget the path to icecream, the PATH env var doesn't count
- qtdir, svn-server, source-dir, build-dir, kdedir
Per-module options:
module qt-copy # kdesvn-build sets the prefix to $qtdir configure-flags [....] apply-qt-patches true make-options -j3 sub-src sub-tools end module module kdelibs make-options -DKDE4_BUILD_TESTS=TRUE -DCMAKE_BUILD_TYPE=debugfull end module
KDE4 programs in KDE3
Xephyr -screen 1240x768 -ac :4 & export DISPLAY=:4 sh -x startkde 2>&1 | tee kde4.log
>./list-kde4-binaries /d/kde/inst/kde4/bin/kwin, pid 6756 /d/kde/inst/kde4/bin/kpersonalizer, pid 6757
>./kill-kde4-binaries Killing /d/kde/inst/kde4/bin/kwin, pid 6756 Killing /d/kde/inst/kde4/bin/kpersonalizer, pid 6757
You can get the scripts list-kde4-binaries and kill-kde4-binaries from http://web.davidfaure.fr/scripts/ v