+ -
当前位置:首页 → 问答吧 → 关于 apt-build 的一点讨论

关于 apt-build 的一点讨论

时间:2006-07-25

来源:互联网

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.html
引用:
Now, 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...cgi?bug=332959
引用:
From 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/gcc-4....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/pipermai...ay/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

作者: quanliking   发布时间: 2006-07-25

# dpkg –get-selections | awk ‘{if ($2 == “install”) print $1}’ > /etc/apt/apt-build.list
# sudo apt-build world
这两句说是可以优化编译系统所有安装了的包,自己从来也没尝试过

作者: realtang   发布时间: 2006-07-26

尝试过,但它不会自动编译依赖关系和相关库,而且编译过程问题不少,特别是不要选上 gcc 之类的。

作者: quanliking   发布时间: 2006-07-26

请问用 apt-build 的时候如何定义 configure 的选项,比如

./configure --prefix=/usr --libexecdir=/usr/lib --enable-shared --.... 之类?

作者: d00m3d   发布时间: 2006-07-26

config选项是源代码包里带的吧?

作者: 超级用户   发布时间: 2006-07-26

apt-build 就是去编译源代码嘛

作者: d00m3d   发布时间: 2006-07-26

configure apt-build 干不了,主要用途就是给你加上几个优化参数,如 -O3 之类的,最后是调用 dpkg-buildpackage -us -uc,而且你改 configure,相当于给维护者的包动了手术,不能保证依赖关系,可能会出问题,我想这个你只能手工来做了!

作者: quanliking   发布时间: 2006-07-26

看到这个真是感到有趣。

fedora.cn 现在用的编译工具是ybuild,是一个配合rpm/yum的类ports工具,看来现在谁都对借鉴gentoo的ports设计感兴趣阿。

作者: hellwolf   发布时间: 2006-07-26

引用:
作者: quanliking
configure apt-build 干不了,主要用途就是给你加上几个优化参数,如 -O3 之类的,最后是调用 dpkg-buildpackage -us -uc,而且你改 configure,相当于给维护者的包动了手术,不能保证依赖关系,可能会出问题,我想这个你只能手工来做了!
谢谢,终於搞懂了一个久未明白的问题,也真正明白 apt-build 的运作方式了,也就是说 apt-build 只能用编译於 repository 内现有 maintainer 维护的包,根据维护者的定义及依赖关系来操作的

唉~~偶的如意算盘还是打不响了~~

Debian 始终是 Debian,LFS 还是 LFS,未能齐於一起!

作者: d00m3d   发布时间: 2006-07-27

搜了一下,原来 apt-build 的讨论并不多,当精华之!

作者: d00m3d   发布时间: 2006-07-27

热门下载

更多