QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4080|回复: 4

[转] gentoo ebuild FUQ :-)

[复制链接]
发表于 2003-7-4 23:13:42 | 显示全部楼层 |阅读模式
作者:penny
出处http://linuxsir.com/bbs/showthre ... ;amp;threadid=49598
==================================================================
这个FUQ=Gentoo Frequently Unanswered Questions(FUQ)

主要是受到这个页面的启发
http://gentoo.zhware.net/fuq.html
这里说得很杂,我只结合自己的使用说说portage系统的一些技巧。

0. 定位ebuild
基础知识,比如
$emerge -s gcal
* app-misc/gcal
Latest version available: 3.01
Latest version installed: [ Not Installed ]
Size of downloaded files: 2,315 kB
Homepage: http://www.gnu.org/software/gcal/gcal.html
Description: The GNU Calendar - a replacement for cal

那么gcal这个软件的ebuild就在/usr/portage/app-misc/gcal/下面
在这个目录下,一般能看到很多ebuild文件,分别对应不同版本号

1. 怎么继续前次的ebuild操作?
比如,emerge到一半,发现一个错误,你google/去论坛搜了一圈,找出了解决办法,难道非要从头开始么? 解决办法其实很多了,说几个最常用的
a. 使用ccache
每个人都应该把它打开
emerge ccache之后,在/etc/make.conf里面
找到FEATURES设置,加上
FEATURES="ccache"
以及CCACHE_SIZE="2G"
默认好像是2G,我觉得如果硬盘空间足够,多多益善。
下次emerge的时候,你会发现编译的速度快了很多。这样间接起到了中断继续的效果。个人推荐这个方法,最简单。

b.继续make
emerge也就是一个用源码编译/安装的过程,而gnu make系统也保证了它实际上是可以"断点续传"的。而gentoo的portage系统在每次开始新的emerge的时候,会自己删掉以前的临时目录,重新生成,造成中断的emerge过程不可恢复。
你只要进入到临时目录,一般是
/var/tmp/portage/ebuild名称/work/ebuild名称/
下继续make,然后make install就行
不用怀疑,这样已经装好了。。但是,这样安装的软件包不会被记载在portage的world file里面。。所以,更优雅的办法是
0. 找到ebuild文件,比如abc-1.0.1.ebuild
1. ebuild abc-1.0.1.ebuild compile
2. ebuild abc-1.0.1.ebuild install
3. ebuild abc-1.0.1.ebuild qmerge
2. 作自己的ebuild
ebuild文件只是按照一定规律写的shell script而已,一般来说,它们是非常简单的(只限于100行以内条理清晰的 xfree的ebuild就是个很好的例外 ) 可以看看gentoo的ebuild guide,
http://www.gentoo.org/doc/en/gentoo-howto.xml
大概而言,只要知道
$A/$P等几个变量的含义就可以了。
从头写ebuild还是有点麻烦的,对于一个普通用户来说也没必要,但是
对于大多数软件的版本升级,你只要复制+改名+做digest就可以了
比如stardict最近出了2.2.1,但是ebuild只到2.2.0

[code:1]fancyworld stardict # cp stardict-2.2.0.ebuild stardict-2.2.1.ebuild
fancyworld stardict # ebuild stardict-2.2.1.ebuild digest
>>> Downloading ftp://ftp.ussg.iu.edu/pub/linux/gentoo/distfiles/stardict-2.2.1.tar.bz2
--22:26:57--  ftp://ftp.ussg.iu.edu/pub/linux/gentoo/distfiles/stardict-2.2.1.tar.bz2
           => `/usr/portage/distfiles/stardict-2.2.1.tar.bz2'
Resolving ftp.ussg.iu.edu... done.
Connecting to ftp.ussg.iu.edu[129.79.6.12]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD /pub/linux/gentoo/distfiles ... done.
==> PASV ... done.    ==> RETR stardict-2.2.1.tar.bz2 ...
No such file `stardict-2.2.1.tar.bz2'.

>>> Downloading http://aleron.dl.sourceforge.net/sourceforge/stardict/stardict-2.2.1.tar.bz2
--22:26:58--  http://aleron.dl.sourceforge.net/sourceforge/stardict/stardict-2.2.1.tar.bz2
           => `/usr/portage/distfiles/stardict-2.2.1.tar.bz2'
Resolving aleron.dl.sourceforge.net... done.
Connecting to aleron.dl.sourceforge.net[204.157.3.229]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 608,829 [application/x-bzip2]

100%[====================================>] 608,829      144.56K/s    ETA 00:00

22:28:02 (144.56 KB/s) - `/usr/portage/distfiles/stardict-2.2.1.tar.bz2' saved [608829/608829]

>>> Generating digest file...
<<< stardict-2.2.1.tar.bz2
>>> Generating manifest file...
<<< stardict-2.0.0.ebuild
<<< stardict-2.2.1.ebuild
<<< stardict-2.2.0.ebuild
<<< ChangeLog
<<< files/stardict-gentoo.patch
<<< files/stardict-config.sh
<<< files/digest-stardict-2.0.0
<<< files/digest-stardict-2.2.0
<<< files/digest-stardict-2.2.1
>>> Computed message digests.[/code:1]

然后试着emerge stardict-2.2.1.ebuild看看?

当然大多数时候,没有这么简单,可能会做一些小修改。我的标准步骤是
cp xxx.1.ebuild xxx.2.ebuild
ebuild xxx.2.ebuild digest
ebuild xxx.2.ebuild unpack
如果到这里一帆风顺,那么估计后面也没问题了,否则,仔细检查,看看是哪里出错了。出错的原因很多,但是一般都是因为几个变量的写法,或者是下载地址变更,再就是老的ebuild里的patch,在新版本上无法使用。总之,看看ebuild guide,自己多熟悉一下,升级软件真的很简单。

3. 加patch
做法有两种,参考前面提到的介绍
a. 在临时目录里面修改

从1.知道,临时文件在/var/tmp/portage/下面
以fontconfig 2.2.1+firefly的patch为例

[code:1]fancyworld superkaramba # emerge -p fontconfig

These are the packages that I would merge, in order:

Calculating dependencies ...done!
[ebuild    N ] media-libs/fontconfig-2.2.0-r2

fancyworld superkaramba # cd /usr/portage/media-libs/fontconfig/
fancyworld fontconfig # ebuild fontconfig-2.2.1.ebuild unpack
fancyworld fontconfig # ebuild fontconfig-2.2.1.ebuild unpack
>>> md5 src_uri ;-) fontconfig-2.2.1.tar.gz
>>> Unpacking source...
>>> Unpacking fontconfig-2.2.1.tar.gz to /var/tmp/portage/fontconfig-2.2.1/work
* Applying fontconfig-2.1-slighthint.patch...                            [ ok ]
* Applying fontconfig-2.2-local_fontdir-r1.patch...                      [ ok ]
* Applying fontconfig-2.2-blacklist.patch...                             [ ok ]
* Applying fontconfig-2.2-remove_subpixel_test.patch...                  [ ok ]
>>> Source unpacked.
fancyworld fontconfig # cd /var/tmp/portage/fontconfig-2.2.1/work/fontconfig-2.2.1/
fancyworld fontconfig-2.2.1 # wget http://firefly.idv.tw/setfont-xft/p...-20030618.patch http://firefly.idv.tw/setfont-xft/p...030626.patch.gz http://firefly.idv.tw/setfont-xft/p...-20030617.patch

fancyworld fontconfig-2.2.1 # patch -p1 < fontconfig-2.2.1-fclang-miss_1_percent-20030617.patch
patching file src/fclang.c

.............[/code:1]


然后
fancyworld fontconfig-2.2.1 # ebuild /usr/portage/media-libs/fontconfig/fontconfig-2.2.1.ebuild merge

这个merge操作会保留临时目录,在这个基础上进行./configure, make, make install的动作

b. 修改ebuild

gentoo的portage系统恐怕是最适合patch 的包管理系统了
还是以上为例
fancyworld fontconfig-2.2.1 # cd /usr/portage/media-libs/fontconfig/files/
下载patch
fancyworld files # wget http://firefly.idv.tw/setfont-xft/p...-20030618.patch http://firefly.idv.tw/setfont-xft/p...030626.patch.gz http://firefly.idv.tw/setfont-xft/p...-20030617.patch
解压.gz(特例,因为这个patch太大了,所以firefly把它打包了一下)
gunzip fontconfig-2.2.1-include_CJK_charmaps-20030626.patch.gz
得到fontconfig-2.2.1-include_CJK_charmaps-20030626.patch
回到上一级,修改ebuild
fancyworld files # cd ..
fancyworld fontconfig # vi fontconfig-2.2.1.ebuild
可以看到

[code:1]src_unpack() {
    unpack ${A}
    cd ${S}

    local PPREFIX="${FILESDIR}/patch/${PN}"

    # Some patches from Redhat
    epatch ${PPREFIX}-2.1-slighthint.patch
    # Add our local fontpaths (duh dont forget!)
    epatch ${PPREFIX}-2.2-local_fontdir-r1.patch
    # Blacklist some fonts that break fontconfig
    epatch ${PPREFIX}-2.2-blacklist.patch
    # Remove the subpixel test from local.conf (#12757)
    epatch ${PPREFIX}-2.2-remove_subpixel_test.patch

    # The date can be troublesome
    sed -i "s:\`date\`::" configure
}[/code:1]


这里的${FILESDIR}就等于 /usr/portage/media-libs/fontconfig/files/目录
${P}表示的是完整软件名+版本号,这里是fontconfig-2.2.1
${PN}就只是单纯的软件名,这里是fontconfig
注意 epatch ${PPREFIX}-2.2-local_fontdir-r1.patch
和 firefly的patch部分冲突,把它去掉。
为了避免不必要的困扰,你的ebuild没有必要写的那么漂亮,所以,修改如下

[code:1]src_unpack() {
unpack ${A}
cd ${S}

local PPREFIX="${FILESDIR}/patch/${PN}"

# Some patches from Redhat
epatch ${PPREFIX}-2.1-slighthint.patch
# Add our local fontpaths (duh dont forget!)
# epatch ${PPREFIX}-2.2-local_fontdir-r1.patch
# Blacklist some fonts that break fontconfig
epatch ${PPREFIX}-2.2-blacklist.patch
# Remove the subpixel test from local.conf (#12757)
epatch ${PPREFIX}-2.2-remove_subpixel_test.patch


[color=green]# CJK font patch by firefly
epatch ${FILESDIR}/fontconfig-2.2.1-fclang-miss_1_percent-20030617.patch
epatch ${FILESDIR}/fontconfig-2.2.1-include_CJK_charmaps-20030626.patch
epatch ${FILESDIR}/fontconfig-2.2.1-multifamily-20030618.patch[/color]

# The date can be troublesome
sed -i "s:\`date\`::" configure
}[/code:1]

epatch是个eclass,它的特点就是屏蔽了patch的细节,让你无需考虑patch的参数问题。
最后直接emerge这个修改过的ebuild文件就行了。

这一部分说起来有点长,自己做一次就知道其实非常简单了。
4. 其他要注意的。。

a. emerge gentoolkit
我不知道为什么没把它作为基本系统的一部分,但是里面的qpkg工具绝对是gentoo必备的,它提供了各种对已安装package的查询,列表等功能,具体的自己man一下

b. 尽量减小编译带来的影响
新的portage系统已经引入优先级设置了,在
/etc/make.conf里面,
PORTAGE_NICENESS=10
我一般用10,这样在emerge 的时候基本没什么感觉了。这个比较适合基本系统已经完成的情况,否则可以把这个数值设成0甚至-10,然后看看滚屏,也很有成就感。

c. 只编译需要的部分
比如koffice里面包括kword, kspread, kexi, kchat等等,我不需要kword kchat,可以这样
export DO_NOT_COMPILE="kword kchat"
emerge koffice

d. 善用sudo
用visudo,我把下面的一些命令都加到/etc/sudoers里面了

lucida fancyworld=NOPASSWD: /usr/bin/emerge
lucida fancyworld=NOPASSWD: /usr/bin/ebuild
lucida fancyworld=NOPASSWD: /usr/bin/make
lucida fancyworld=NOPASSWD: /usr/bin/vi

要装软件,直接sudo emerge xxx就行,或者make, sudo make install。。。在日常操作中避免用root而又不损失方便性,sudo是个很好的解决办法。

e. 查看use变量
emerge -pv xxx

顺便说一下,ebuild被mask其实是有两个可能的
一个是ebuild文件本身
如果里面有KEYWORDS="~x86"
那么ACCEPT_KEYWORDS="~x86" emerge xxx就行
另外一个是/usr/portage/profiles/package.mask文件
这个列表里面的东东只能
emerge xxx.ebuild才行,或者直接修改文件,去掉黑名单

f. 多看看info
info提供的内容比man丰富的多,可以emerge pinfo,然后pinfo xxx, 它支持彩色,看起来更加舒服。或者用konqueror,试试在地址栏输入
info:/gcc

5. 一些有用的站点
http://www.breakmygentoo.net/
这里有很多软件的非官方ebuild
http://cvs.gentoo.org/~danarmak/kde-cvs.html
kde的cvs版ebuild(我一直在用的)
大概来说,在/etc/make.conf里面加上
PORTDIR_OVERLAY=/usr/local/portage
然后把下载的ebuild解压到这个目录下面就可以了
它会和正常的portage tree整合在一起,唯一的区别是emerge sync的时候,这个目录下面的内容会得以保留。
发表于 2003-7-7 16:13:49 | 显示全部楼层
very good ! 3ks ,Kuye
回复

使用道具 举报

 楼主| 发表于 2003-7-7 20:47:10 | 显示全部楼层
别提了。。。

借着房东家的电话驾着小猫跑着红帽实在写不出什么东西(两个多月没写了),这两天只好抄抄 Linuxsir 上的了。。。

Debentoo 什么时候来不来北京玩?!
回复

使用道具 举报

发表于 2003-7-8 18:16:59 | 显示全部楼层
I've never use Gentoo for 6 months,hehe. Now I'm intereted in IPB ;)
回复

使用道具 举报

发表于 2004-3-20 10:27:29 | 显示全部楼层
找到了!
昨天的努力可以不白费了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-10-5 12:33 , Processed in 0.068846 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表