Archive:Getting Started/Increased Productivity in KDE4 with Scripts (zh CN): Difference between revisions

From KDE TechBase
(New page: {{Template:I18n/Language Navigation Bar|Getting_Started/Increased Productivity in KDE4 with Scripts}} {{TutorialBrowser| series=Getting Started| name=Increasing Your Productivity With S...)
 
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Template:I18n/Language Navigation Bar|Getting_Started/Increased Productivity in KDE4 with Scripts}}
<!--fortruth初稿!-->


{{TutorialBrowser|
{{TutorialBrowser (zh CN)|


series=Getting Started|
series=开始入门|


name=Increasing Your Productivity With Scripts|
name=使用脚本提升效率|
pre=[[../Build/KDE4]]|
pre=[[../Build/KDE4]]|


reading=[http://conference2006.kde.org/conference/talks/11.php Original presentation by David Faure]
reading=[http://conference2006.kde.org/conference/talks/11.php David Faure的演讲内容]
}}
}}


== Abstract ==
== 摘要 ==


Time is precious. This tutorial shares David Faure's collected wisdom for how to get the most of our time and effort by saving on both using some simple scripts and techniques while developing KDE 4.
时间宝贵。本教程分享了 David Faure 的超人智慧,通过使用一些简单的脚本和技术来开发 KDE 4,这样大大节省了我们的时间和精力。


== Setting Up the Environment ==
== 配置环境 ==


=== Why install as user and not as root? ===
=== 为什么是以用户身份安装,而不是 root?===
*a single command to compile+link+install (or even a single key in your editor), no su/sudo needed
*compile+link+install 这些只是一条简单的命令 (或者甚至是你的编辑器中的一个键), 不需要 su/sudo
*no risk of root-owned files in the builddir, as can happen when some change forces make install to recompile some files
*在构建目录中没有属于 root 文件的风险,只有当某些变化强制 make install 重新编译一些文件才可能发生。
*safer if something goes wrong (for instance, using the wrong prefix would overwrite the system kde3)
*在发生某些错误时会更安全 (例如,使用错误的编译预 profix 选项可能会改写 kde3 系统)
*make install is faster than "make && sudo make install" since the Makefiles are parsed only once
*"make install" 比 "make && sudo make install" 更快,因为 Makefiles 文件只解析了一次
*no link errors during sudo make install due to root's environment missing entries in LD_LIBRARY_PATH. Really, setting up the environment once is hard enough, why do it for two users?
*在 "sudo make install" 时不会有连接错误,因为在 "root" 的环境变量没有 LD_LIBRARY_PATH 记录。并且,配置一次环境已经非常辛苦了,为什么还要为两个用户呢?


=== Set up for development ===
=== 配置开发环境 ===


If you really want to use a separate account for development, see [[../Build/KDE4#Set_up_the_development_user_account|here]].
如果你想开一个单独的帐户专门用来开发,请阅读[[../Build/KDE4#Set_up_the_development_user_account|这篇文章]]


But to save time and avoid many problems, it is strongly recommended to do it all from your usual user.
但是,为了节省时间和避免许多麻烦,强烈建议使用你经常用的帐户。
All you need is an easy way to switch between environments.
你所要做的只是简单地在不同环境之间做一下切换。
You go to ~/kde/src/4, you want to be in the kde4 environment, right?
你来到 ~/kde/src/4 目录,你想使用 KDE4 环境,不是么?


To do this, paste http://web.davidfaure.fr/scripts/cd_function into your .zshrc or .bashrc, and put http://web.davidfaure.fr/scripts/findup in your $PATH.
要实现这个目的,拷贝 http://web.davidfaure.fr/scripts/cd_function 到你的 .zshrc 或者 .bashrc 中,然后,把 http://web.davidfaure.fr/scripts/findup 放到你的路径下 $PATH。


This way, whenever you enter a directory, it will look up a .my-setup file and source it (it also looks up in parent directories until it finds one, and it doesn't source the same one twice in a row).
这样,当你进入某个目录,它就会寻找 .my-setup 文件并向上级目录追溯,只到找到 .my-setup(而且它不会在同一方向上找到两次)。


Set up all the environment variables that are specific to kde4 (they will be detailed later on in this page) into that ~/kde/src/4/.my-setup file, and do the same for other environments (kde3, and anywhere you need project-specific environment variables...)
~/kde/src/4/.my-setup 文件中配置好 KDE 4 的所有环境变量 (在本页的后面将会详细介绍),其他环境也同样做(kde3,和其他任何你需要特别配置环境变量的地方...)


=== Example paths ===
=== 路径举例 ===


==== Qt ====
==== Qt ====
For Qt, by habit from the Qt3 times and to save time by avoiding "make install" after a change, I recommend using one directory for source, builds and install. This is done by configuring Qt with --prefix=$PWD. This isn't mandatory though.
对于 Qt 而言,自 QT3 时代以来的习惯,同时也为了节省时间,我们尽量避免在一个小变化后就 "make install",我建议在一个目录下编辑源文件,构建和安装。这可以通过配置 Qt 编译预选项 -prefix=$PWD 完成 Qt with --prefix=$PWD。当然,你并不一定非要这样做。


Qt-Path: {{path|~/qt/4/qt-copy}}
Qt 的路径:{{path|~/qt/4/qt-copy}}


==== KDE ====
==== KDE ====
It was convenient in kde3, it is mandatory in kde4: you need to use out-of-source builds, i.e. separate build and source directories.
kde3 中这是可选的,但在 KDE4 中则是必需的:你需要在源代码(source)目录外进行构建,也就是说构建目录和源代码(source)目录必需是分开的。
It makes it very easy to rebuild from scratch, removing all generated files - even old ones that "make clean" wouldn't remove. It is easier to look at the source files (grep, ls etc.). It allows multiple build trees with different settings, e.g. debug and release.
这样做可以在出现错误后,很方便地重新构建,删除所有生成的文件 - 包括那些 "make clean" 也无法删除老文件。而且也可以更方便地查看源文件(grep,ls 等)。这样就允许在多个构建树下使用不同的配置,例如:调试用(debug)版本和发布版本。


# Source: {{path|~/kde/src/[version]}}
# 源代码(source)目录路径: {{path|~/kde/src/[version]}}
# Build:  {{path|~/kde/build/[version]}}
# 构建(Build)目录路径:  {{path|~/kde/build/[version]}}


Thus source modules for kde4 are checked out in {{path|~/kde/src/4/}} and building happens in {{path|~/kde/build/4/}}.
因此 kde4 的源代码(source)模块是同步在 {{path|~/kde/src/4/}} 而构建是在 {{path|~/kde/build/4/}} 中进行的。


== Environment Variables and other helpful functions ==
== 环境变量和其他有用的函数 ==


=== Bash ===
=== Bash ===
If you use bash, take a look at [[Getting Started/Increased Productivity in KDE4 with Scripts/.bashrc|this .bashrc]]. It is an example bash config which sets all KDE4 environment variables and some helper functions.
如果你在使用 bash, 请先阅读 [[Getting Started/Increased Productivity in KDE4 with Scripts/.bashrc|这个.bashrc文件]].。这是一个用来设置 KDE4 环境变量和一些有帮助的函数的 bash 配置文件的例子。


The steps below describe some of these features as well as giving alternative and additional functions.
下面描述了其中的一些功能并给出了其他可选的函数。


Read further about [[#Compiling_a_KDE_module|compiling a KDE module]].
更多了解,请阅读 [[#Compiling_a_KDE_module|编译KDE模块]]


=== Directory navigation ===
=== 目录导航 ===


To easily swap from build and source folder back and forth, you can use cs and cb functions that work like the following:
你可以使用 cs cb 函数来帮你很方便地在源目录和构建目录进行切换,具体操作如下:
<code bash>
 
<syntaxhighlight lang="bash">
pwd
pwd
  ~/kde/src/4/kdebase
  ~/kde/src/4/kdebase
cb && pwd
cb && pwd
  ~/kde/build/4/kdebase
  ~/kde/build/4/kdebase
  # note that this folder is created if it does not exist
  # 注意如果这个目录不存在将会创建。
cs && pwd
cs && pwd
  ~/kde/src/4/kdebase
  ~/kde/src/4/kdebase
</code>
</syntaxhighlight>


A number of kde-related scripts will have to be able to do the same. Simply do:
许多和 KDE 相关的脚本可以做相同的事。简单点的如:
export OBJ_REPLACEMENT='s#/kde/src/#/kde/build/#'
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:
这个命令就是让 kdesdk 中的 makeobj 脚本能实现从 src 目录到构建目录转换
 
如果你也做了下面的操作:
alias make=makeobj
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 {{path|~/src/4/kdelibs}}, from anywhere.
这会让你只需简单地从源目录键入"make", 就可以进行构建。这在编辑器中会很有用的 - 如果你的 vi 或 emacs 是用 makeobj 做为 make 的,你就可能一键编译了。
For instance, you could be in {{path|~/kde/src/4/kdebase/workspace/kcontrol}} and now you decide to look at kdecore... No need to type a long series of <tt>"../.."</tt> or to restart from the top. You can just type <tt>cs 4/kdelibs/kdecore</tt>.
 
另外,为了快速转移到其他目录,用 “cs 4/kdelibs" 将可以很方便地从任何地方转换到目录 {{path|~/src/4/kdelibs}}
 
例如你现在在 {{path|~/kde/src/4/kdebase/workspace/kcontrol}} 目录,而现在你决定查看一下kdecore... 你不需要输入一长串的 <tt>"../.."</tt> 或从头重新开始。你只需要键入 <tt>cs 4/kdelibs/kdecore</tt> 就可以了。


This is doable via the two functions <tt>cs</tt> and <tt>cb</tt> defined in [[Getting Started/Increased Productivity in KDE4 with Scripts/.bashrc|the .bashrc]].
这也可以通过两个函数 <tt>cs</tt><tt>cb</tt> 来实现。这两个函数在 [[Getting Started/Increased Productivity in KDE4 with Scripts/.bashrc|.bashrc]]中有定义。


==== Alternative ====
==== 其他选择 ====
The following code will enable you to use <tt>cd</tt> similar to <tt>cs</tt> described above:
下面的代码可以让你像用 <tt>cs</tt> 一样来用 <tt>cd</tt>
<code bash>
<syntaxhighlight lang="bash">
export CDPATH=.:~/kde/src
export CDPATH=.:~/kde/src
</code>
</syntaxhighlight>
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? :)
这样做的优点在于,当你使用 zsh 时可以自动补全。试着输入 cd 4/kdemul 然后按 Tab 键,它将自动补全为 4/kdemultimedia,无论你现在在什么目录下。这在 bash 中是不能实现的 - 那么你现在是不是想要使用 zsh ? :)
 
最简单的 cs和cb aliases (同上面的一样但是不支持参数) 如下如示:


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 cb='cd `pwd | sed -e s,/kde/src/,/kde/build/,`'
alias cs='cd `pwd | sed -e s,/kde/build/,/kde/src/,`'
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:
zsh 中返回先前目录很容易。在 .zshrc 中是这样设置的:
<code bash>
 
<syntaxhighlight lang="bash">
setopt AUTO_PUSHD
setopt AUTO_PUSHD
alias p=popd
alias p=popd
</code>
</syntaxhighlight>
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).
然后你就可以输入 "p" 来跳回到你上一次所在的目录,需要多少次都可以 (输入 "dirs -v" 可以查看先前目录的历史记录)


=== CMake ===
=== CMake ===


==== CMake and subdirs ====
==== CMake 和子目录 ====


cd 4/kdelibs/kio/kio ; make => nothing happens, the Makefile is in the parent directory.
cd 4/kdelibs/kio/kio ; make => 不会发生任何事,Makefile 文件在上一级目录。
   
   
Make your editor use a wrapper script instead
让你的编辑器用外部脚本替代
<code bash>
<syntaxhighlight lang="bash">
#!/bin/sh
#!/bin/sh
if test "$1" = "-k"; then shift; fi
if test "$1" = "-k"; then shift; fi
Line 135: Line 143:
echo "calling makeobj -j $jvalue $arg"
echo "calling makeobj -j $jvalue $arg"
makeobj -j $jvalue $arg
makeobj -j $jvalue $arg
</code>
</syntaxhighlight>


Get this script: http://web.davidfaure.fr/scripts/makefromemacs.
从这里获取脚本:http://web.davidfaure.fr/scripts/makefromemacs.


==== CMake and dependencies ====
==== CMake和关系 ====
  touch kdecore/kapplication.h
  touch kdecore/kapplication.h
  cd kdeui ; make
  cd kdeui ; make
=> recompiles kdecore first
=> 首先重新编译 kdecore  
  touch kdecore/kapplication.h
  touch kdecore/kapplication.h
  cd kdeui ; make kdeui/fast
  cd kdeui ; make kdeui/fast
=> recompiles only kdeui
=> 只重新编译 kdeui
  make install/fast
  make install/fast
But note that the normal mode (without /fast) is also useful in other cases:
但是请注意在其他情况下,正常模式(没有 /fast)也是可用的:
For instance you edit
例如你编辑
  kdelibs/kio/kio/kdirmodel.cpp
  kdelibs/kio/kio/kdirmodel.cpp
and the unit test for it
然后对其进行单元测试
  kdelibs/kio/tests/kdirmodeltest.cpp
  kdelibs/kio/tests/kdirmodeltest.cpp
Then, to recompile both libkio and the unit test, simply do "make kdirmodeltest" from kdelibs/kio/tests.
最后,对 libkio 进行重新编译和单元测试,简单地说就是在 kdelibs/kil/tests 下执行 ”make kdirmodeltest“ 就可以了。


=== List of KDE 4 environment variables ===
=== KDE 4 环境变量列表 ===
This lists all the environment variables you should set, for instance in $KDESRC/4/.my-setup
此列表列举了你要设置的所有环境变量,例如 $KDESRC/4/.my-setup 中的设置


==== Qt ====
==== Qt ====
<code bash>
<syntaxhighlight lang="bash">
export QTDIR=/d/qt/4/qt-copy
export QTDIR=/d/qt/4/qt-copy
export PATH=$QTDIR/bin:$PATH
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$QTDIR/lib:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=$QTDIR/lib:$PKG_CONFIG_PATH
</code>
</syntaxhighlight>


==== KDE ====
==== KDE ====
<code bash>
<syntaxhighlight lang="bash">
export KDEDIR=/d/kde/inst/kde4
export KDEDIR=/d/kde/inst/kde4
export PATH=$KDEDIR/bin:$PATH
export PATH=$KDEDIR/bin:$PATH
Line 172: Line 180:
export QT_PLUGIN_PATH=$KDEDIR/lib/kde4/plugins
export QT_PLUGIN_PATH=$KDEDIR/lib/kde4/plugins
export KDEDIRS=$KDEDIR
export KDEDIRS=$KDEDIR
</code>
</syntaxhighlight>


==== User ====
==== 用户 ====
<code bash>
<syntaxhighlight lang="bash">
export KDEHOME=$HOME/.kde4
export KDEHOME=$HOME/.kde4
</code>
</syntaxhighlight>


==== Others ====
==== 其他 ====
<code bash>
<syntaxhighlight lang="bash">
export QTEST_COLORED=1
export QTEST_COLORED=1
export KDE_COLOR_DEBUG=1
export KDE_COLOR_DEBUG=1
</code>
</syntaxhighlight>


==Compiling a KDE module==
== 编译一个 KDE 模块 ==
===Manually===
=== 手工编译 ===
If you use the aforementioned {{path|~/.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 [[Getting_Started/Sources/Using_Subversion_with_KDE|Using Subversion with KDE]]):
如果你使用了先前提到的 {{path|~/.bashrc}} 它对编译 KDE 模块很实用 (前提是源代码已经获取到本地,例如通过 SVN。详细可见 [[Getting_Started/Sources/Using_Subversion_with_KDE|KDE下使用Subversion]]):
<code bash>
<syntaxhighlight lang="bash">
cs KDE/kdebase
cs KDE/kdebase
cmakekde
cmakekde
</code>
</syntaxhighlight>


Else you'll have to do the following:
另外你还要完全以下操作:
<code bash>
<syntaxhighlight lang="bash">
mkdir -p ~/build/KDE/kdebase && cd ~/build/KDE/kdebase
mkdir -p ~/build/KDE/kdebase && cd ~/build/KDE/kdebase
cmake -DKDE4_BUILD_TESTS=TRUE -DCMAKE_BUILD_TYPE=debugfull \
cmake -DKDE4_BUILD_TESTS=TRUE -DCMAKE_BUILD_TYPE=debugfull \
-DCMAKE_INSTALL_PREFIX=~/kde ~/src/KDE/kdelibs
-DCMAKE_INSTALL_PREFIX=~/kde ~/src/KDE/kdelibs
make
make
</code>
</syntaxhighlight>


{{tip|Never delete CMakeCache.txt and then type make; always re-run cmake with the correct options after deleting CMakeCache.txt.}}
{{tip|永远不要先把CMakeCache.txt删除再运行"make"; 在删除CMakeCache.txt后,加上合适的参数重新运行一下"cmake"。}}


===Using kdesvn-build===
=== 使用 kdesvn-build 来编译 ===
[http://kdesvn-build.kde.org 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.
[http://kdesvn-build.kde.org kdesvn-build] 是一个全能脚本:它可以处理同Subversion 的同步和更新,运行cmake,make,make install,和存储所有的输出到日志(log)文件。
   
   
Copy kdesvn-buildrc-sample to $KDE_SRC/.kdesvn-buildrc, then edit it.
拷贝 kdesvn-buildrc-sample $KDE_SRC/.kdesvn-buildrc,然后编辑。
Global options:
全局选项:
* binpath - don't forget the path to icecream, the PATH env var doesn't count
* binpath - 不要忘了到 icecream 的路径,不包括环境变量 PATH
* qtdir, svn-server, source-dir, build-dir, kdedir
* qtdir, svn-server, source-dir, build-dir, kdedir


Per-module options:
每个模块的选项:
  module qt-copy
  module qt-copy
   # kdesvn-build sets the prefix to $qtdir
   #kdesvn-build 设置 $qtdir 编译预选项
   configure-flags [....]
   configure-flags [....]
   apply-qt-patches true
   apply-qt-patches true
Line 223: Line 231:
  end module
  end module


==KDE4 programs in KDE3==
== KDE3 中的 KDE4 程序 ==
  Xephyr -screen 1240x768 -ac :4 &
  Xephyr -screen 1240x768 -ac :4 &
  export DISPLAY=:4
  export DISPLAY=:4
Line 236: Line 244:
  Killing /d/kde/inst/kde4/bin/kpersonalizer, pid 6757
  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/
你可以从这里http://web.davidfaure.fr/scripts/ 获取脚本 list-kde4-binaries kill-kde4-binaries
 
[[Category:Shell Scripting]]
[[Category:Shell Scripting]]
[[Category:KDE4]]
[[Category:KDE4]]

Latest revision as of 12:41, 23 June 2013


Template:TutorialBrowser (zh CN)

摘要

时间宝贵。本教程分享了 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|这篇文章]]。

但是,为了节省时间和避免许多麻烦,强烈建议使用你经常用的帐户。 你所要做的只是简单地在不同环境之间做一下切换。 你来到 ~/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)版本和发布版本。

  1. 源代码(source)目录路径: ~/kde/src/[version]
  2. 构建(Build)目录路径: ~/kde/build/[version]

因此 kde4 的源代码(source)模块是同步在 ~/kde/src/4/ 而构建是在 ~/kde/build/4/ 中进行的。

环境变量和其他有用的函数

Bash

如果你在使用 bash, 请先阅读 这个.bashrc文件.。这是一个用来设置 KDE4 环境变量和一些有帮助的函数的 bash 配置文件的例子。

下面描述了其中的一些功能并给出了其他可选的函数。

更多了解,请阅读 编译KDE模块

目录导航

你可以使用 cs 和 cb 函数来帮你很方便地在源目录和构建目录进行切换,具体操作如下:

pwd
 ~/kde/src/4/kdebase
cb && pwd
 ~/kde/build/4/kdebase
 # 注意如果这个目录不存在将会创建。
cs && pwd
 ~/kde/src/4/kdebase

许多和 KDE 相关的脚本可以做相同的事。简单点的如: export OBJ_REPLACEMENT='s#/kde/src/#/kde/build/#'

这个命令就是让 kdesdk 中的 makeobj 脚本能实现从 src 目录到构建目录转换

如果你也做了下面的操作: alias make=makeobj

这会让你只需简单地从源目录键入"make", 就可以进行构建。这在编辑器中会很有用的 - 如果你的 vi 或 emacs 是用 makeobj 做为 make 的,你就可能一键编译了。

另外,为了快速转移到其他目录,用 “cs 4/kdelibs" 将可以很方便地从任何地方转换到目录 ~/src/4/kdelibs

例如你现在在 ~/kde/src/4/kdebase/workspace/kcontrol 目录,而现在你决定查看一下kdecore... 你不需要输入一长串的 "../.." 或从头重新开始。你只需要键入 cs 4/kdelibs/kdecore 就可以了。

这也可以通过两个函数 cscb 来实现。这两个函数在 .bashrc中有定义。

其他选择

下面的代码可以让你像用 cs 一样来用 cd

export CDPATH=.:~/kde/src

这样做的优点在于,当你使用 zsh 时可以自动补全。试着输入 cd 4/kdemul 然后按 Tab 键,它将自动补全为 4/kdemultimedia,无论你现在在什么目录下。这在 bash 中是不能实现的 - 那么你现在是不是想要使用 zsh 了? :)

最简单的 cs和cb aliases (同上面的一样但是不支持参数) 如下如示:

alias cb='cd `pwd | sed -e s,/kde/src/,/kde/build/,`'

alias cs='cd `pwd | sed -e s,/kde/build/,/kde/src/,`'

返回先前目录

在 zsh 中返回先前目录很容易。在 .zshrc 中是这样设置的:

setopt AUTO_PUSHD
alias p=popd

然后你就可以输入 "p" 来跳回到你上一次所在的目录,需要多少次都可以 (输入 "dirs -v" 可以查看先前目录的历史记录)。

CMake

CMake 和子目录

cd 4/kdelibs/kio/kio ; make => 不会发生任何事,Makefile 文件在上一级目录。

让你的编辑器用外部脚本替代

#!/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

从这里获取脚本:http://web.davidfaure.fr/scripts/makefromemacs.

CMake和关系

touch kdecore/kapplication.h
cd kdeui ; make

=> 首先重新编译 kdecore

touch kdecore/kapplication.h
cd kdeui ; make kdeui/fast

=> 只重新编译 kdeui

make install/fast

但是请注意在其他情况下,正常模式(没有 /fast)也是可用的: 例如你编辑

kdelibs/kio/kio/kdirmodel.cpp

然后对其进行单元测试

kdelibs/kio/tests/kdirmodeltest.cpp

最后,对 libkio 进行重新编译和单元测试,简单地说就是在 kdelibs/kil/tests 下执行 ”make kdirmodeltest“ 就可以了。

KDE 4 环境变量列表

此列表列举了你要设置的所有环境变量,例如 $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

用户

export KDEHOME=$HOME/.kde4

其他

export QTEST_COLORED=1
export KDE_COLOR_DEBUG=1

编译一个 KDE 模块

手工编译

如果你使用了先前提到的 ~/.bashrc 它对编译 KDE 模块很实用 (前提是源代码已经获取到本地,例如通过 SVN。详细可见 KDE下使用Subversion):

cs KDE/kdebase
cmakekde

另外你还要完全以下操作:

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
Tip
永远不要先把CMakeCache.txt删除再运行"make"; 在删除CMakeCache.txt后,加上合适的参数重新运行一下"cmake"。


使用 kdesvn-build 来编译

kdesvn-build 是一个全能脚本:它可以处理同Subversion 的同步和更新,运行cmake,make,make install,和存储所有的输出到日志(log)文件。

拷贝 kdesvn-buildrc-sample 到 $KDE_SRC/.kdesvn-buildrc,然后编辑。 全局选项:

  • binpath - 不要忘了到 icecream 的路径,不包括环境变量 PATH
  • qtdir, svn-server, source-dir, build-dir, kdedir

每个模块的选项:

module qt-copy
  #用 kdesvn-build 设置 $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

KDE3 中的 KDE4 程序

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

你可以从这里http://web.davidfaure.fr/scripts/ 获取脚本 list-kde4-binaries 和 kill-kde4-binaries