Gentoo Ebuild 编写基本指南

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Basic guide to write Gentoo Ebuilds and the translation is 77% complete.
Other languages:
English • ‎italiano • ‎中文(中国大陆)‎ • ‎日本語

这篇文章 包含了关于 ebuild 开发的初学者说明。

Portage,Gentoo 之心,运行于 ebuild!

一个 ebuild 文件是一个文本文件,供 Gentoo 包管理器使用,它标识一个特定的软件包以及 Gentoo 包管理器应该如何处理它。它使用一个 bash 类似语法风格,并通过 EAPI 版本进行标准化。

Gentoo Linux 使用 ebuild 作为单个软件的包管理格式。这些 ebuild 包含相关软件的元数据(软件的名称和版本、软件使用的许可证和主页)​​、依赖信息(构建时和运行时依赖)以及有关如何处理的说明使用软件(配置、构建、安装、测试...)。

Ebuilds:他们在哪里?

The location of ebuilds from the Gentoo repository (available in the snapshot) are usually at /var/db/repos/gentoo[1] or in /usr/portage for older installs. The location is determined by the repos.conf file. Custom ebuilds are recommended to be placed in a custom repository, say /var/db/repos/larry.

如何创建一个 ebuild

vim 的用户自动获取基本骨架(由 app-vim/gentoo-syntax 提供):

root #vim ./foobar.ebuild
FILE foobar.ebuildvim 从模板开始
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
 
EAPI=7
 
DESCRIPTION=""
HOMEPAGE=""
SRC_URI=""
 
LICENSE=""
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""
 
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND=""

GNU Emacs 或 XEmacs 用户可以使用类似的工具(分别由 app-emacs/ebuild-modeapp-xemacs/ebuild-mode 提供)。

其他编辑器的用户从 skel.ebuild 手动复制:

root #cp /var/db/repos/gentoo/skel.ebuild ./foobar.ebuild

Essential information of the new package should be known and added to the ebuild-defined variables DESCRIPTION, HOMEPAGE, SRC_URI, LICENSE.

给定源压缩包示例

Scrub 创建一个 ebuild,版本 2.6.1(如果它不存在)可能会显示:

root #mkdir -p /var/db/repos/larry/app-misc/scrub
root #cd $_
root #vim ./scrub-2.6.1.ebuild
FILE scrub-2.6.1.ebuildvim 从模板开始
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
 
EAPI=7
 
DESCRIPTION="Some words here"
HOMEPAGE="https://github.com/chaos/scrub"
SRC_URI="https://github.com/chaos/scrub/releases/download/2.6.1/scrub-2.6.1.tar.gz"
 
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""
 
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND=""
Note
Using ${PN} variable inside SRC_URI is allowed, but not suggested. While it may shrink the line, some reasoning why not to use it is worth consideration as well.
CODE 使用变量的 SRC_URI
SRC_URI="https://github.com/chaos/${PN}/releases/download/${PV}/${P}.tar.gz"

It can be tested using the ebuild command like:

root #ebuild ./scrub-2.6.1.ebuild clean unpack
Appending /var/db/repos/larry to PORTDIR_OVERLAY...
>>> Downloading 'https://ftp.halifax.rwth-aachen.de/gentoo/distfiles/scrub-2.6.1.tar.gz'
--2019-06-03 16:42:57--  https://ftp.halifax.rwth-aachen.de/gentoo/distfiles/scrub-2.6.1.tar.gz
Resolving ftp.halifax.rwth-aachen.de... 137.226.34.46, 2a00:8a60:e012:a00::21
Connecting to ftp.halifax.rwth-aachen.de|137.226.34.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 362536 (354K) [application/octet-stream]
Saving to: '/usr/portage/distfiles/scrub-2.6.1.tar.gz.__download__'
 
/usr/portage/distfiles/scrub-2.6.1.tar.gz.__download__             100%[==============================================================================================================================================================>] 354.04K  --.-KB/s    in 0.08s   
 
2019-06-03 16:42:58 (4.24 MB/s) - '/usr/portage/distfiles/scrub-2.6.1.tar.gz.__download__' saved [362536/362536]
 
 * scrub-2.6.1.tar.gz BLAKE2B SHA512 size ;-) ...                                                                                                                                                                                                                  [ ok ]
>>> Unpacking source...
>>> Unpacking scrub-2.6.1.tar.gz to /var/tmp/portage/app-misc/scrub-2.6.1/work
>>> Source unpacked in /var/tmp/portage/app-misc/scrub-2.6.1/work

这应该下载并解压源压缩包。在极少数情况下,包应该可以工作,并且不需要在 ebuild 中进一步调整。

打补丁

In case the source code needs to get patched the patch can be created from the unpacked source code as explained in the patches article.

user $cd /var/tmp/portage/app-misc/scrub-2.6.1/work/scrub-2.6.1/

The patch will then be listed in an array called PATCHES as is explained in the devmanual.

CODE 将在 src_prepare 期间应用补丁
PATCHES=(
	"${FILESDIR}"/${P}-foo.patch
	"${FILESDIR}"/${P}-bar.patch
)
 
src_prepare() {
    default
    ...
}

为 ebuild 添加对用户补丁的支持

Since EAPI 6, the support for user patches is provided by eapply_user. This can be done by putting default on top in the src_prepare function:

CODE src_prepare 示例
src_prepare() {
    default
    ...
}

EAPI 7 之前的 EAPI 版本不应用于新的 ebuild。

另请参阅

外部资源

参考