|
|
apt-build 号称 debian 里的 ports (bsd 系统和 gentoo 中最吸引人的功能),能够对包裹进行优化编译。虽然早已不是新鲜玩意,最近对 ports 产生兴趣,故又搬出来玩玩。
首先由于 apt 包管理机制过于复杂的依赖关系,所以 apt-build 并不是很完善,特别对于 apt-build world 这样高难度动作,很难实现。以下是我的一点实践:
1. /etc/apt/apt-build.conf- build-dir = /var/cache/apt-build/build
- repository-dir = /var/cache/apt-build/repository
- Olevel = -O2
- mtune = -mtune=pentium-m
- options = " "
- make_options = " "
复制代码 这个是比较标准的写法,很多人会问,为什么没看到 FLAGS 呢?
以下引用作者之一 Julien Reveret 的解释:
http://julien.danjou.info/article-apt-build.htmlNow, Gentoo fans will ask me "what about flags ?" ; sorry for us, but there are not. By flags, Gentoo users mean libraries with which software are linked to. Here, it is out of the question for a simple user to change package dependancies. Indeed, if you do this, you could make mistakes that don't exist with the original package. No need to fill a bug report in this case, you are not using the official Debian package anymore, but yours. 看来作者对 FLAGS 之类不感冒。
有人会写一大堆 flags 放在 options 里,然后在加上 march 之类的,统统不管用,因为源代码里就定义了上面列出来的参数,而且每个参数一个值。这个不知是否算是 bug, 还是作者有意这么做。
2.屏幕输出和配置文件不符
我想这里是很多人最最疑惑的地方,难道 apt-build 根本就没有实现它的承诺么?
其实不然。屏幕输出的是 make 调用的命令,而背后包装过的 gcc (/var/lib/apt-build)使用的是你的配置:
作者的解答:
http://bugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=332959From README.Debian:
Q: gcc and g++ do not seem to be called with good options!
A: *** They are called with them! ***
What you see on your screen is the command called by make, but
the wrapper wraps (yeah, it does) calls to gcc/g++ and adds options you
specified in the apt-build configuration file.
You won't see this on your screen.
Try `ps ax | grep gcc' instead as a proof, while building. 多开一个 terminal,输入:
$ ps ax | grep gcc
真相大白。
3. 使用中的一些好玩的地方:
有关 -march 和 -mtune, 照 gcc docs 中的说法:
http://gcc.gnu.org/onlinedocs/gc ... -x86_002d64-Options-mtune=cpu-type
Tune to cpu-type everything applicable about the generated code, except for the ABI and the set of available instructions.
......
While picking a specific cpu-type will schedule things appropriately for that particular chip, the compiler will not generate any code that does not run on the i386 without the -march=cpu-type option being used.
-march=cpu-type
Generate instructions for the machine type cpu-type. The choices for cpu-type are the same as for -mtune. Moreover, specifying -march=cpu-type implies -mtune=cpu-type.
-mcpu=cpu-type
A deprecated synonym for -mtune. 指定 -march 已经隐含了 -mtune。
故我修改 apt-build.conf,如下:- build-dir = /var/cache/apt-build/build
- repository-dir = /var/cache/apt-build/repository
- Olevel = -O2
- mtune = -march=pentium-m
- options = " "
- make_options = " "
复制代码
ps ax | grep gcc, 同样生效。
有关 -march , -mtune 其它讨论:
http://linuxfromscratch.org/pipermail/livecd/2006-May/003435.html
http://gentoo-wiki.com/Safe_Cflags
还有更好玩的,其实作者只是简单定义了几个变量,你可以随意修改,比如:- build-dir = /var/cache/apt-build/build
- repository-dir = /var/cache/apt-build/repository
- Olevel = -msse2
- mtune = -mtune=pentium-m
- options = "-mfpmath=sse"
- make_options = " "
复制代码
遗憾的是一行只能一个参数,上面看起来很不雅观,不过至少能到达目的。
说实话,apt-build 并不复杂,用 C 和 perl 写成,主要借助 apt 来解决依赖关系和自身的主要功能,如果要添加大量的所谓优化参数,可以手工修改一下它的分析参数代码,并不难。
$ apt-get source apt-build
我并不是非常赞成过度优化,对于桌面应用如 firefox 之类的,很多都是 I/O bound 的东西,而非 cpu bound, 性能上是否有提高,能提高多少,估计没几个人能说的清,很多都是一些感觉或某些网站的测评。
有兴趣的又有时间可以玩玩如何 port 或 emerge debian  |
|