Guide de création d'Ebuild pour débuter
Mise en garde: la traduction de cet article est en cours, c'est brouillon et seul le début est commencé - passez votre chemin, pour l'instant. Voir page de discussion / see talk page.
Ce guide permet de débuter dans la création d' ebuild, pour utiliser la puissance de Portage, pour installer et gérer encore d'avantage de logiciels.
Écrivez un ebuild pour permettre d'installer un logiciel sur Gentoo, lorsqu'il n'y a pas d'ebuild préexistant. Il est relativement simple de créer un ebuild, et il s'agit du seul moyen d'installer la plupart des logiciels tiers pour qu'ils soient accessibles par tout le système. L'ebuild permet au gestionnaire de paquets de suivre chaque fichier installé sur le système, pour pouvoir faire les mises à jour et les désinstallations proprement.
Selon l'article ebuild: Un fichier ebuild est un fichier texte, habituellement contenu dans un "repository"; qui identifie un paquet spécifique et indique au gestionnaire de paquets comment le prendre en charge. Les ebuilds utilisent un syntaxe proche du bash, et suivent un standard: le Package Manager Specification, en respectant un EAPI particulier.
Les ebuild contiennent des métadonnées concernant chaque version de chaque logiciel (nom, numéro de version, licence, site web...), les informations sur les dépendances (pour l’exécution et pour la construction), ainsi que les étapes à suivre pour construire et installer le logiciel (configuration, compilation, construction, installation, test...).
Une fois qu'un ebuild fonctionne, il peut être partagé soit en soumettant un pull request ou en le rendant publiquement accessible dans un ebuild repository.
See the dev manual on writing ebuilds for full reference documentation. See the quick start to writing ebuilds in the dev manual for further examples of how to write ebuilds. See the Ebuild article for explanations about ebuilds themselves, the ebuild repository article about what an ebuild repository is, and the creating an ebuild repository article on how to create them.
Ebuild repositories
Pour que les ebuild soient rendus disponibles à Portage, ils sont placés dans un ebuild repository qui est configuré avec Portage par le fichier /etc/portage/repos.conf (voir section sur gestion de repository pour plus d'informations sur ces répertoires.
Créez un répertoire pour les tests, pour pouvoir poursuivre ce guide. Le restant de cet article considère qu'il existe un répertoire dans /var/db/repos/example_repository.
eselect repository makes creating a repository simple:
root #
eselect repository create example_repository
Ebuilds can be installed with the ebuild command, however this is not recommended - this command is for development purposes only. This article will use the ebuild command with the ebuild file for testing during development, but be sure to use the emerge command with an ebuild in a repository otherwise.
How to create an ebuild
Ebuilds are simply text files, in their most basic form. All that is needed to start writing ebuilds is a text editor, to provide installable software packages for Gentoo.
In this section, {CATEGORY}, {PN}, and {P} represent package category, package name, and package name and version, and are standard variables used in ebuilds. Together, these variables can represent a version specifier.
Some editors have optional ebuild functionality, in that case there skip to the appropriate section. Otherwise a skeleton ("template") may be used to get started quicker.
Start with the skeleton
If the editor does not have integrated ebuild functionality to help to start off, there is a skeleton ebuild file (skel.ebuild) located in the Gentoo ebuild repository. To start with that file as a base, simply copy it to an appropriate location (nano is used as the text editor in this example):
user $
mkdir --parents /var/db/repos/example_repository/{CATEGORY}/{PN}
user $
cp /var/db/repos/gentoo/skel.ebuild /var/db/repos/example_repository/{CATEGORY}/{PN}
user $
cd /var/db/repos/example_repository/{CATEGORY}/{PN}
user $
nano {P}.ebuild
Vim
There is a vim plugin to automatically start from a skeleton when creating an empty ebuild file.
After installing app-vim/gentoo-syntax, create the appropriate directory for the ebuild, then launch vim with a new "{P}.ebuild" filename provided on the command line, to be automatically met with a basic skeleton that can be modified and saved:
user $
mkdir --parents /var/db/repos/example_repository/{CATEGORY}/{PN}
user $
cd /var/db/repos/example_repository/{CATEGORY}/{PN}
user $
vim {P}.ebuild
Emacs
A similar tool is available for users of Emacs, provided by app-emacs/ebuild-mode or app-xemacs/ebuild-mode, depending on Emacs distribution.
Demonstration by example
This example will create an ebuild for scrub, version 2.6.1 (if it didn't already exist), to show how a typical process might go.
Create a directory to house the ebuild, in the ebuild repository created earlier:
user $
mkdir -p /var/db/repos/example_repository/app-misc/scrub
Change the shell working directory to the new path:
user $
cd /var/db/repos/example_repository/app-misc/scrub
Some shells, such as Bash, provide the last parameter of the previous command in the "$_" variable. This can be used to call the newly created directory without specifying the path on the command line, as long as this is used as the directly next command.
user $
cd $_
This example will use Vim to create the ebuild file and provide a skeleton to serve as a basis to write the ebuild on, but use editor of choice (see previous section about using Emacs, or the skeleton file):
user $
vim ./scrub-2.6.1.ebuild
Add important information about the new package by setting the ebuild-defined variables: DESCRIPTION, HOMEPAGE, SRC_URI, LICENSE:
scrub-2.6.1.ebuild
vim editing a new file from template# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 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=""
This— with the omission of those lines with =""
— is the minimum information necessary to get something that will work. Ebuilds inheriting certain eclasses might come with a different set of minimal information, e.g. ant-jsch-1.10.9.ebuild. Save the file - voila an ebuild, in it's most basic form,it's that simple!
Using the
${PN}
variable inside SRC_URI
is allowed, though this is not necessarily best practice. While it may be shorter to type, there is some reasoning on why not to use it that may be worth consideration.
SRC_URI="https://github.com/gentoo/${PN}/releases/download/${PV}/${P}.tar.gz" # Reads better as, e.g. SRC_URI="https://github.com/gentoo/gentoo/releases/download/${PV}/${P}.tar.gz"
See this ebuild file format policy guide page for more recommendations.
It is possible to test fetching and unpacking the upstream sources by the new ebuild, using the ebuild command:
root #
ebuild ./scrub-2.6.1.ebuild manifest clean unpack
Appending /var/db/repos/example_repository 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
This should download and unpack the source tarball, without error, as in the example output.
For some exceptionally simple packages like this one, that do not need patching or other more advanced treatment, the ebuild may work just so - with no further adjustments needed.
For best practice, the test suite may be run at this stage - this is particularly true when starting out:
root #
ebuild scrub-2.6.1.ebuild clean test install
To actually install the new ebuild on the system, run:
root #
ebuild scrub-2.6.1.ebuild clean install merge
Patching upstream source in an ebuild
The source can be patched at installation time, to adapt to Gentoo specificities for example, by setting up patches from an ebuild.
Put the patches in the right directory:
user $
cd /var/tmp/portage/app-misc/scrub-2.6.1/work/scrub-2.6.1/
A patch can be created from the unpacked source code as explained in the Creating a patch article. Patches should then be listed in an array called PATCHES as explained in the devmanual:
PATCHES=( "${FILESDIR}"/${P}-foo.patch "${FILESDIR}"/${P}-bar.patch ) src_prepare() { default ... }
QA testing
Use pkgcheck (dev-util/pkgcheck) to check for QA errors in an ebuild:
user $
pkgcheck scan
See also
- GitHub Pull Requests — how to contribute to Gentoo by creating pull requests on GitHub.
- java-ebuilder — an experimental package being developed by Gentoo Java developers to generate initial ebuilds from Maven
pom.xml
files. - Notes on ebuilds with GUI
- Project:GURU — an official repository of new Gentoo packages that are maintained collaboratively by Gentoo users
- Project:Proxy_Maintainers/User_Guide/Style_Guide
- Project:Python - the Python project pages have information on creating ebuilds for packages written in Python
- Project:X11/Ebuild_maintenance
- Proxied Maintainer FAQ
- Test environment
- Writing go Ebuilds — a short reference, intended to be read alongside Basic guide to write Gentoo Ebuilds and the go-module.eclass documentation
External resources
- Gentoo Policy Guide
- Quickstart Ebuild Guide
- Gentoo Development guide
- Michał Górny: Category: Ebuild writing
- Michał Górny: The ultimate guide to EAPI 7
- Michał Górny: The ultimate guide to EAPI 8
- man 1 ebuild - The ebuild command's man page.
- man 5 ebuild - The ebuild file format man page.
- The skel.ebuild
- Adding new packages via proxy-maint project