Gentoo Logo

Gentoo Developer Handbook

Content:

  • Introduction
    This part covers aspects which apply to most areas of Gentoo development. This section is only really relevant if you are a Gentoo developer; otherwise you should skip this.
    1. Introduction
      This section outlines the purpose of the Gentoo Developer Handbook.
    2. Becoming a developer
      This section aims to explain how one can become a Gentoo developer.
    3. What you get
      This section outlines what services are available to Gentoo developers.
    4. Help for new developers
      This section provides help and instructions for new developers.
    5. Developer hierarchy
      This section outlines the hierarchy of Gentoo Developers and development.
    6. Staff member policy
      This section outlines recruitment and retirement policies for Gentoo staff members.
  • Guides
    This section outlines and explains various development processes and provides standards for Gentoo developers.
    1. Ebuild HOWTO
      This section describes the Gentoo Linux Portage system, how to create new packages for Gentoo, and is also meant to be somewhat of a standard for the Gentoo Developers. It is a work in progress, and is constantly being updated and changed. It is by no means complete. You should always use this in conjunction with the manpages provided by portage (especially ebuild(5)) and the Gentoo Linux Development Policy.
    2. Eclass HOWTO
      This section aims to provide developers with a guide detailing how eclasses work and how they can be applied to ebuilds.
    3. Common ebuild Mistakes
      This section explains the frequent ebuild writing and submission mistakes made by contributors and developers.
    4. Gentoo Metadata
      This section explains the use and need of metadata.xml that is used within the Portage tree.
    5. Ebuild Maintenance HOWTO
      This section describes how developers would perform common tasks when maintaining ebuilds in the Portage tree.
    6. Manifest Signing Guide
      This section describes how developers can sign Manifests in the Portage tree using GPG.
  • Policies
    This part covers the different policies which we expect developers to abide when committing items to CVS.
    1. Ebuild policy
      This section outlines the ebuild policy which every ebuild in Portage must follow.
    2. Etiquette policy
      This section outlines the etiquette policy for Gentoo developers.

A. Introduction

1. Introduction

1.a. Introduction

The aim of this handbook is to outline Gentoo development policies, and make you, the developer, informed of policies, standards and procedures which Gentoo considers to be core values of our development system.

This handbook is not intended to be the universal guide to everything - the opportunities open to you are endless, and as a result, this handbook is designed to teach you the principles which we think make up a good Gentoo developer - the rest is up to you!

If you are new to Gentoo development or even an old veteran and are at any stage unsure about anything, feel free to ask the gentoo-dev mailing list, or #gentoo-dev.

1.b. Requirements

Before you start to tinker, it is important to have a working Gentoo installation, both for documentation and development purposes, and we also recommend that you have a good knowledge of topics covered in the ``Working with Gentoo'' section in the User Handbook to help you with your development work.

Most of this guide is targeted at developers, but, if you are just interested to see what makes Gentoo development work, this guide may provide some valuable insights.

The best way to get noticed [ and to possibly become a Gentoo developer! ] is to file intuitive and accurate bug reports at the Gentoo Bugzilla, with patches if possible, and to help us out with what you think would make a better Gentoo for everyone whether by providing patches for new features, submitting new ebuilds, or solving issues with existing ones.

2. Becoming a developer

2.a. Introduction

There are many ways to become a Gentoo developer, which this section discusses. There are also various steps that new "recruits" have to go through before they become official developers.

2.b. Helping out

Firstly; to be asked to become a developer you should either apply to an opening, or just help out whether in the form of user support or filing bug reports - we notice frequent contributors making contributions to Gentoo and we attempt to reward them by giving them the chance to become a Gentoo developer. Gentoo has many paths, and the Gentoo Developer Relations Recruitment Team is always looking out not just for developers - documentation writers and infrastructure maintainers are just as important too for our distribution to run smoothly.

You should look out for openings for developers in the GMN, as well as the /topic of #gentoo-bugs on irc.freenode.net - if you feel you could fill in one of those positions, try to find a mentor who is willing to sponsor you, or contact the Gentoo Recruiters who may be able to find a mentor for you. Please do not file "New Developer" bugs on yourself since this task is designated for the mentor and any such bugs will be closed.

2.c. Mentoring

All new developers must have a mentor, who is an existing Gentoo developer responsible for guiding a new developer as well as offering to help the developer later after the developer has passed through the recruitment process.

A mentor should assist you by helping you with any questions you might have, as well as outlining your Gentoo responsibilities, especially those in relation to what you would initially work on.

Once a developer agrees to mentor a new developer, the mentor should file a bug and assign it to the Gentoo Recruiters - the Gentoo Recruiters page explains in detail what information should be filed.

Note: The Gentoo Recruiters reserve the right to assign a developer a new mentor if the initial mentor is idle to queries about the new developer or if the mentor files the bug but then does not assist the new developer through the rest of the process.

2.d. Waiting

All new developers pass through a waiting period of up to a month, depending on how ready the mentor thinks the developer is as well as feedback from any other related staff. During this time, the new developer should complete the quiz which would be reviewed by the developer's mentor and the Gentoo Recruiters to ensure that the developer is "ready". In special cases, the waiting period is determined by the Recruiters and/or Gentoo Developer Relations leads.

Two quizzes are offered: the ebuild quiz, and the staff quiz. Developers who will be working purely on infrastructure, GLSAs or other non-ebuild areas should take the staff quiz, any developers who require commit access to the Portage tree should take the ebuild quiz.

Once a new developer has completed the quiz, the developer should send it off to the mentor who is responsible for reviewing it in conjunction with the Gentoo Recruiters. If the quiz answers are deemed to be of a sufficient standard, then the recruitment process would continue. Otherwise, a new developer can redo the quiz again, providing that it is completed in the waiting period.

Additionally, new developers should be responsive to any members of the Recruiters Team who have any questions - any developers who do not reply promptly will have their "New Developer" bug closed, which would only be reopened at the discretion of the Gentoo Recruiters.

2.e. Jumping the gap

After your mentor and the Gentoo Recruiters have reviewed your quiz and deemed it to be of a suitable standard, you should send it along with a public SSH2 DSA key (e.g. id_dsa.pub) to the Gentoo Recruiters. If the Recruiters consider your quiz to be of a satisfactory standard, they will set you up with the services that you require.

After this time, you enter a "probationary period" of 30 days during which your mentor is responsible for your actions, providing accountability - also, Gentoo Recruiters may reject new developers during this time if they feel it is appropriate.

3. What you get

3.a. Introduction

Gentoo provides developers with all the necessary services which they might need for their development efforts. If you require anything else, please do not hesitate to contact the Infrastructure Team!

Once you are an authorized developer, your recruiter should organize the following services. If you experience any problems, please see your recruiter or the mentioned staff with access to the required service.

3.b. Bugzilla

Developers are able to change all aspects of bugs in Bugzilla. If you have an existing account the email address should be changed to your Gentoo address by a Bugzilla administrator.

3.c. CVS

Not all developers receive CVS access - if you require Portage access to the gentoo, gentoo-projects, or gentoo-x86 tree get someone on the recruiters team to do this for you. You may need to justify your need for this to happen, however.

3.d. IRC

When you are a developer, you will receive operator status on #gentoo-dev signifying that you are a developer. Please contact Developer Relations if you do not. Additionally, team leads may decide to give you operator status on specialized channels such as #gentoo-hardened, for example. Abuse of operator powers on #gentoo-dev may lead to your operator powers being removed instantly along with the possible removal of your developership. If you are given operator powers, we ask that you use them constructively to benefit everybody when either developers or users break up the cleanliness of the channels.

Operator status on #gentoo is given at discretion by Developer Relations; it does not in any way signify that the user is a developer.

"Special" Gentoo channels such as #gentoo-hardened and #gentoo-server are given to people at the discretion of the team - in this case, the hardened and server teams.

IRC Channels are owned by their relevant project leads, whether strategical or operational and the owner has the discretion of voicing or unvoicing members of the public. If you believe that those powers are being abused or are being used with wrong considerations; then speak to the Gentoo Linux Developer Relations team.

3.e. Forums [Optional]

Ask one of the forums administrators in #gentoo-forums or forum-mods@gentoo.org to update your forum status on the Gentoo Forums, if needed. Forum accounts are not mandatory.

3.f. Planet [Optional]

Developers who have a personal blog can request to be added to the planet aggregator. The planet software creates a custom feed of all developer's blog posts, separated into two categories: on-topic (Gentoo and computer related content) on Planet Gentoo, and all topics on Gentoo Universe.

Also, if a user does not already have a blog, we host our own blogging software and can create an account for you.

Please see http://www.gentoo.org/proj/en/userrel/planet/index.xml for more details.

3.g. Mail

All developers are provided with a developer@gentoo.org mail address for Gentoo use.

Please see http://www.gentoo.org/proj/en/infrastructure/dev-email.xml for more details.

3.h. Mailing lists

All developers must be subscribed to the gentoo-core and gentoo-dev-announce mailing lists. All developers should be subscribed to gentoo-dev and gentoo-project, though neither are developer requirements. Contact someone on the Recruiters team to subscribe you to the above mailing lists or if you are having difficulties.

gentoo-core is to be used for internal discussions; technical discussions should be discussed on gentoo-dev; off topic or non-technical discussions should be discussed on gentoo-project; while gentoo-dev-announce is for announcements only. If you send a message to dev-announce, and expect a discussion to take place relating to it, you should manually cross-post and set reply-to suitably.

If you are subscribed on any other Gentoo mailing lists, you should unsubscribe and resubscribe with your new mail address.

3.i. Shell access

Developers currently get a shell account on dev.gentoo.org - this provides mail storage, SMTP relaying and also an IRC tunnel for developers to use to access freenode.

To ensure security, access is only available through SSH keys, which your mentor should place on your account and allow you to log in: please see http://www.gentoo.org/proj/en/infrastructure/cvs-sshkeys.xml for more details regarding SSH keys..

3.j. Service usage policies

Services provided by Gentoo should only be used for Gentoo development work. Infrastructure has the right to disable any accounts which are a security risk, these include inactive accounts which will be suspended by the infrastructure team if you are presumed idle, and your IRC #gentoo-dev status would also be voiced.

If any files in your account are found to be harmful towards other developers or users on the box, or pose a risk to the Gentoo project (such as illegal .torrents), Gentoo Infrastructure will suspend your account which would only be unlocked after investigation from Gentoo Developer Relations. In most cases, your developership may be suspended if such files are found. The same policies also apply to Gentoo CVS and other Gentoo-provided services you may be offered.

3.k. Activity policies

Gentoo understands that as life changes, so may your availability. We respectfully request that if you know you will be unavailable for an extended period of time (vacation, big project at work, family needs, etc) that you utilize the devaway system.

Code Listing 11.1: When going away

on dev.gentoo.org
$ echo "Away until 2007-08-30, contact $dev1 in my absence" > ~/.away

Code Listing 11.2: When coming back

on dev.gentoo.org
$ rm ~/.away

In the on going effort to keep our developer pool up-to-date and our resources secure, Developer Relations periodically reviews developer activity in the search for inactive developers. A developer is considered inactive if no contributions are made over a period of 60 days. Activity is determined by CVS commits, bugzilla statistics, and peer feedback. Not everyone's activities are so easily traced, as such, Developer Relations often requests feedback from a project lead or team members of a developer suspected to be inactive.

Any developer suspected to be inactive for a period in excess of 60 days may be subject to retirement. Developer Relations will first research and assess the situation, attempt to contact the developer, or if attempts are unsuccessful may chose to retire the developer. Please note that if you are in devaway for more than 60 days, you may also be considered inactive, however, return dates will be taken into consideration. If you are retired due to inactivity and wish to return, you need only contact Recruiters to begin the recruitment process again.

4. Help for new developers

4.a. Using CVS

Introduction

This guide is not intended to be a manual on using CVS; for that, take a look at the CVS info page or /doc/en/cvs-tutorial.xml. Instead, this guide focuses specifically on using CVS and Repoman in Gentoo's ebuild tree.

Configuration

Typically, you'll want something along these lines in your ~/.cvsrc:

Code Listing 1.1: ~/.cvsrc

cvs -q -z0
diff -u -B
checkout -P
update -d -P

Finally, many people using CVS like to use compression (-z#). We ask that developers who are not on dialup connections please use -z0 - with the contents of our CVS repository and the load on our CVS server, you actually experience a speed increase without compression.

Checking out from CVS/SVN

There are a few useful modules in Gentoo's CVS repository. Ebuilds are kept in the gentoo-x86 module. gentoo contains the XML for the website, documentation, developer directories, developer pictures, and so on. gentoo-projects contains various projects and generally replaces the gentoo-src cvs module. gentoo-src is kept around for history, please transition to a different cvs module if you are still using it.

Code Listing 1.2: Checking out gentoo-x86

# cvs -d username@cvs.gentoo.org:/var/cvsroot co gentoo-x86

Before working in the tree at any time, it's always a good idea to do an update to check for changes and prevent conflicts. You can update in any subdirectory of the tree if you don't want to wait for a tree-wide update, but from time to time it's a good idea to update your entire tree:

Code Listing 1.3: Updating in gentoo-x86

# cd gentoo-x86
# cvs update

Gentoo also offers subversion services for those who prefer SVN over CVS. Many core projects such as portage and baselayout are hosted here now.

Code Listing 1.4: Checking out portage

# svn co svn+ssh://username@cvs.gentoo.org/var/svnroot/portage

Updating Portage

If you want to use CVS as your primary Portage tree, you can add the following lines to /etc/make.conf, replacing you with your username:

Code Listing 1.5: Changing /etc/make.conf for use with CVS

SYNC="cvs://you@cvs.gentoo.org:/var/cvsroot"
CVSROOT=":ext:you@cvs.gentoo.org:/var/cvsroot"

Note: Due to the fact that the cvs checkout has no metadata cache, your portage may become really slow

On supported architectures, you should also have sandbox in your FEATURES to ensure ebuilds do not modify the root filesystem directly.

Adding/Removing packages

Say you're ready to add a brand new package, foo, in app-misc:

Code Listing 1.6: Adding a package

(Replace CVSROOT with the location of your checked-out CVS tree.)
# cd $CVSROOT/app-misc
(Always update before working in part of the CVS tree!)
# cvs update
# mkdir foo
(Here, we add the package directory foo to the CVS repository.)
# cvs add foo
# cd foo
(It's better to keep in-progress ebuilds in an overlay outside of your CVS tree.)
# cp /path/to/foo-1.0.ebuild ./
(Make sure PORTDIR_OVERLAY is set to the CVS directory when creating manifests.)
# repoman manifest
# ${EDITOR} metadata.xml
You don't necessarily need a files directory any more
# cvs add foo-1.0.ebuild metadata.xml files
[Don't forget to create a ChangeLog - see the man page for echangelog.]
# echangelog "New ebuild for foo. Ebuild written by me. Fixes bug #XXXXXX."

See the Gentoo Metadata section for more information on metadata.xml.

At this point, you're ready to commit (see the section on Commits below). But what if you want to remove foo-1.0 when foo-1.1 is out?

Code Listing 1.7: Removing old versions

# cd CVSROOT/app-misc/foo
# cvs update
# cvs remove -f foo-1.0.ebuild

And now you're ready to commit (see the section on Commits below).

Commits

Always use repoman commit rather than cvs commit. Repoman is a quality assurance (QA) tool that performs basic checks and creates Manifests. If any part of repoman's output is unclear, please see man repoman. Additionally, you may tire of entering your key passphrase repeatedly; keychain (http://www.gentoo.org/proj/en/keychain.xml) can help you.

Code Listing 1.8: Using repoman

[Make sure there are no root-owned files present prior to running repoman!]
("scan" scans the current directory for QA issues. "full" is more complete.)
# repoman scan
("commit" does a scan, then commits, while also updating the Manifest. Make sure you
 add a verbose and useful CVS ChangeLog message...)
# repoman commit

Speeding CVS up

If you have noticable high ping times to the cvs server, you might want to use the ssh master slave setup where you only connect to the other ssh server once and let it do the next commands over that connection. This way you save the handshake overhead which may speed up the whole checkout/commit by factor 3. Just add the code snipped given below to your config

Code Listing 1.9: ~/.ssh/config

Host *
  ControlMaster auto
  ControlPath ~/.ssh/master-%r@%h:%p

After doing so, you can enable a backgrounded master connection by running

Code Listing 1.10: Open Master connection in background

You can look the meaning of the parameters up in the manpage of ssh
$ ssh -M -N -f ${USER}@cvs.gentoo.org

4.b. Miscellaneous

Putting files on mirrors

Distfiles are automatically fetched by the Gentoo Mirror System. You only need to monitor your distfiles for fetch errors. Please see the Distfiles Overview Guide for comprehensive instructions.

Mail and Web

Our infrastructure allows developers to manage their own mail. http://www.gentoo.org/proj/en/infrastructure/dev-email.xml contains instructions on configuring your @gentoo.org mail.

Developers have access to webhosting, http://dev.gentoo.org/~$YOURNAME. Please see the Webspace Configuration Guide for details.

5. Developer hierarchy

5.a. Introduction

This section aims to explain the Gentoo development hierarchy and gives developers an insight to how Gentoo Linux development management is structured.

5.b. A short history of Gentoo's management structure

The first attempt to come up with a management structure to solve problems with coordination and communication issues was made in 2003 with the structure described in GLEP 4. As Gentoo grew larger over the time, some problems with the management structure were discovered and a new one was needed to solve these issues. GLEP 39 describes both the reasons behind this as well as the outcome of the discussion.

5.c. Current Management structure according to GLEP 39

A project is a group of developers working towards a goal (or a set of goals).

  • A project exists if it has a web page at www.gentoo.org/proj/en/<project name> that is maintained. ("Maintained" means that the information on the page is factually correct and not out-of-date.) If the webpage isn't maintained, it is presumed dead.
  • It may have one or many leads, and the leads are selected by the members of the project. This selection must occur at least once every 12 months and may occur at any time.
  • It may have zero or more sub-projects. Sub-projects are just projects that provide some additional structure, and their web pages are in the project's space.
  • Not everything (or everyone) needs a project.
  • Projects need not be long-term.
  • Projects may well conflict with other projects. That's okay.
  • Any dev may create a new project just by creating a new page (or, more realistically, directory and page) in gentoo/xml/htdocs/proj/en and announcing it on the gentoo-dev-announce mailing list.

Global issues will be decided by an elected Gentoo council.

  • There will be a set number of council members. (For the first election that number was set to 7 by acclamation.)
  • Council members will be chosen by a general election of all devs once per year.
  • The council must hold an open meeting at least once per month.
  • Council decisions are by majority vote of those who show up (or their proxies).
  • If a council member (or their appointed proxy) fails to show up for two consecutive meetings, they are marked as a slacker.
  • If a council member who has been marked a slacker misses any further meeting (or their appointed proxy doesn't show up), they lose their position and a new election is held to replace that person. The newly elected council member gets a 'reduced' term so that the yearly elections still elect a full group.
  • Council members who have previously been booted for excessive slacking may stand for future elections, including the election for their replacement. They should, however, justify their reasons for slacking and should expect to have it pointed out if they don't do so themselves.
  • The 'slacker' marker is reset when a member is elected.
  • If any meeting has less than 50% attendance by council members, a new election for all places must be held within a month. The 'one year' is then reset from that point.
  • Disciplinary actions may be appealed to the council.
  • A proxy must not be an existing council member, and any single person may not be a proxy for more than one council member at any given meeting.

5.d. Consequences of Gentoo's management structure

As a consequence of the new management structure, global decisions will be made by the elected council. This should give Gentoo a general direction - smaller issues affecting only a project or two should be decided inside the projects involved, probably with input from other developers. The council should be a fair representation of the developer base as every developer is able to vote, so interests should be represented in a fair way. If the council does a bad job and the developer base is unhappy with its work, the council can be voted out.

Decisions within a project can be made by the people inside the project itself, of course coordination between the projects is necessary. The (sub-)project leads are usually responsible for doing this.

Most projects have an Operational and Strategic lead, but basically it is up to the project what positions are created and how they are called - this also applies to sub-projects.

Some projects appoint a contact person for communication to another project e.g. a developer within the forums project who is responsible for communication with the infrastracture project.

All in all, the current structure has no clear list of responsibilities the project leads are supposed to satisfy. They are chosen by the members of the project, the practical responsibility of a lead is "whatever the members require", and if that isn't satisfied, the members can get a new lead (if they can find somebody to take the job!).

6. Staff member policy

6.a. Gentoo Staff Member policy

Introduction

Running a Linux distribution has multiple aspects and many of them aren't directly connected to coding. Every distribution needs people to run its servers, help its community, provide documentation, handle project's finances and legal issues and serve many other tasks. Their contributions are as important as code contributions. These developers are called staff members in Gentoo.

Types of staff members

The following list contains all types of staff members we are currently recruiting in Gentoo:

Important: If the project you want to contribute to as a staff member isn't on this list and you think it should, please contact Developer Relations about policy change.

How is staff member access different from ebuild developer access?

Access is assigned based on the responsibilities of the Staff Member. All Gentoo Developers are provided with an gentoo.org mail address, ssh access to dev.gentoo.org (for shell, ldap, public_html, etc) as well as cvs access to gentoo's web/project pages. As a staff member you will not be granted access to the ebuild tree, as ebuild developers are, but may be granted access to other area's based on your need and responsibilities.

How can I become a Gentoo staff member?

You have to work with members of the project you wish to help. You are invited to the team when your level of contributions and expertise justify you becoming a developer in that project. It may take time and may also require passing internal recruitment procedures within that project first. Those procedures are in place to ensure you know what your future function within Gentoo involves, they are created and maintained by the project itself.

When you are ready, you will need to look for a mentor and a developer bug will be filed for you after your mentor has approved your staff quiz. Once a recruiter has been assigned to your developer bug, both of you will need to schedule your review. Please see the mentoring guide for more information.

Note: As a staff member who isn't going to work on ebuilds, you won't be asked technical questions about them. All that will be required from you at this stage of your recruitment is a good understanding of Gentoo internals.

I would like to be recruited as a staff member but also plan joining other projects in future

Every Gentoo developer can join any project (s)he wishes if developers of the project agree with that. Before you can start contributing to the ebuild tree though, you will have to apply for ebuild developer recruitment. This means you need a mentor, a history of technical contributions (bug fixes, overlays, etc...) and adequate training. Please contact recruiters about this.

How is retirement handled for staff members?

You have to either remain active within the project you have joined or move to other projects. If there are no projects within Gentoo you're active in, you are subject for retirement via Gentoo Undertakers procedures.

B. Guides

1. Ebuild HOWTO

1.a. The Portage tree

Introduction

The Portage tree is typically found at /usr/portage and is organized in a hierarchical structure consisting of category directories, followed by specific package directories. Here's an example; you can find the util-linux-2.11y.ebuild file in the /usr/portage/sys-apps/util-linux directory. There may be several other versions of util-linux ebuilds alongside util-linux-2.11y.ebuild. This is because all ebuilds for a particular package (regardless of version), share the same mycat/mypkg directory in /usr/portage, unless you have portage overlays installed.

Checking Out the Portage Tree from CVS

If you are unfamiliar with the CVS system, please read the CVS Tutorial for more information.

The Portage tree can be found in the gentoo-x86 module of the Gentoo Linux tree. To check out the module (about 350 megabytes) you would first set up CVS via the above guide, then check out the gentoo-x86 module.

What (not) to put in the Portage tree

Before writing a new ebuild, check bugs.gentoo.org to see if an ebuild has already been written for the package, but has not yet been added to the Portage tree. Go to bugs.gentoo.org, choose query and select Advanced Search; as product select Gentoo Linux, as component select ebuilds. In the search field put the name of the ebuild and as status select NEW, ASSIGNED, REOPENED and RESOLVED (RESOLVED is important), then submit the query. For you lazy people, click here.

In general, the Portage tree should only be used for storing .ebuild files, as well as any relatively small companion files, such as patches or sample configuration files. These types of files should be placed in the /usr/portage/mycat/mypkg/files directory to keep the main mycat/mypkg directory uncluttered. Exceptions to this rule are for larger patch files (we recommend this for patches above 20KB) which should be put onto the Gentoo mirrors so that people do not waste excessive amounts of bandwidth and hard drive space. Also, you should not add binary (non-ASCII) files to the Portage CVS tree. If you need to do this in another CVS tree, for example, if you need to add a small PNG graphic for whatever reason, be sure to add it to CVS by using the -kb option, like so:

Code Listing 1.1: Adding binary files to CVS

# cvs add -kb myphoto.png

The -kb option tells CVS that myphoto.png is a binary file and should be treated specially. For example, merging the differences between two different versions of this file should not be allowed to happen, for obvious reasons. Also, speaking of merging changes, any patches you add to Portage should generally not be compressed. This will allow CVS to merge changes and correctly inform developers of conflicts.

Remember, the packages that you commit must be ready out of the box for end users when committed as stable. Make sure that you have a good set of default settings that will satisfy the majority of systems and users that will use your package. If your package is broken, and you are not sure how to get it to work, check some other distributions that have done their own versions of the package. You can check Mandriva or Debian or Fedora for some examples.

When committing to CVS, all developers should use repoman commit instead of cvs commit to submit their ebuilds. Before committing, please run repoman full to make sure you didn't forget something.

CVS Commit Policy

  • Always run repoman scan before you commit.
  • Please run repoman full before you commit.
  • Always test that package.mask is okay by doing emerge --pretend mypkg before you commit and check that it doesn't contain any conflicts.
  • Always update the ChangeLog before you commit.
  • Always commit the updated package.mask before the updated package, in case conflicts occur while you commit package.mask.
  • Always do atomic commits; if you commit a package with a new license, or that is masked, then first commit the revised package.mask and/or license, then commit the ebuild, ChangeLog, patches and metadata.xml all in one go to avoid breaking users' installations.

The files Directory

As noted earlier, under each package subdirectory is a files/ directory. Any patches, configuration files, or other ancillary files your package might require should be added to this directory; any files bigger than 20KB-or-so should go to the mirrors to lower the amount of (unneeded) files our users have to download. You may want to consider naming patches you create yourself just to get your package to build with a version-specific name, such as mypkg-1.0-gentoo.diff, or more simply, 1.0-gentoo.diff. Also note that the gentoo extension informs people that this patch was created by us, the Gentoo Linux developers, rather than having been grabbed from a mailing list or somewhere else. Again, you should not compress these patches because CVS does not play well with binary files.

Consider prefixing or suffixing (such as mypkg-1.0) every file you put into the files/ directory, so that the files used for each individual version on an ebuild are distinguishable from one another, and so that the changes between different revisions are visible. This is generally a really good idea :). You may want to use a different suffix if you wish to convey more meaning with the patch name.

If you have many files that should go into the files/ directory, consider creating subdirectories such as files/1.0/ and putting the relevant files in the appropriate subdirectory. If you use this method, you do not need to add version information to the names of the files, which is often more convenient.

1.b. Ebuild scripts

Introduction

Ebuild scripts are the basis for the entire portage system. They contain all the information required to download, unpack, compile and install a set of sources, as well as how to perform any optional pre/post install/removal or configuration steps. While most of Portage is written in Python, the ebuild scripts themselves are written in bash, since using bash allows us to call commands as we would from the command-line. One of the important design principles behind ebuild scripts is to have the commands therein be analogs of those one would type on the command-line if installing the package manually. For this purpose, using bash syntax is a very good thing.

Ebuild scripts are interpreted by the ebuild and emerge commands. Think of the ebuild command as a low-level building tool. It can build and install a single ebuild, but no more. It will check to see if dependencies are satisfied, but it will not attempt to auto-resolve them. On the other hand emerge is a high level engine for ebuild, and has the ability to auto-merge dependencies if needed, perform pretend merges so that user can see what ebuilds would be merged, and more. Generally, emerge blows ebuild out of the water except in one area. With ebuild, you can incrementally step through the various parts of a package emerge (fetching, unpacking, compiling, installing and merging) one at a time. For developers, this is an invaluable debugging tool, because it allows you to isolate ebuild problems to a specific portion of the ebuild.

Naming ebuild files

Ebuild file names consist of four logical subsections:

pkg-ver{_suf{#}}{-r#}.ebuild

Note: The brackets ({}) delineate optional fields and do not appear in the literal package name. # represents any non-zero positive integer.

The first subsection, pkg, is the package name, which should only contain lowercase letters, the digits 0-9, and any number of single hyphen (-), underscore (_) or plus (+) characters. Examples: util-linux, sysklogd and gtk+. We have some packages in Portage that don't follow these rules, but your packages should.

The second subsection, ver, is the version of the package, which should normally be same as the version on the main source tarball. The version is normally made up of two or three (or more) numbers separated by periods, such as 1.2 or 4.5.2, and may have a single letter immediately following the last digit; e.g., 1.4b or 2.6h. The package version is joined to the package name with a hyphen. For example: foo-1.0, bar-2.4.6.

Important: If you're thinking of using a trailing letter in your version string, note that the trailing letter should not be used to signify alpha or beta status for the package, since alphas and betas are prereleases and letter revisions are newer versions. This is an important distinction because Portage uses an ebuild's version number to determine if it is newer or older than other packages with the same category and name. It's very important that version numbers faithfully represent the version of the package so that Portage properly performs its dependency checking duties.

The third subsection, {_suf{#}}, is optional and may contain one of these predefined suffixes, listed in least-recent to most-recent order:

Suffix Meaning
_alpha Alpha release
_beta Beta release
_pre Prerelease
_rc Release candidate
(none) Normal release
_p Patch level (normally accompanied by trailing integer)

Any of these suffixes may be immediately followed by a non-zero positive integer, e.g., linux-2.4.0_pre10. Assuming identical version parts, the suffixes are ordered as follows (lower means older): _alpha < _beta < _pre < _rc < (no suffix) < _p.

When comparing identical suffixes with trailing integers, the one with the larger integer will be considered most recent. Example: foo-1.0_alpha4 is more recent than foo-1.0_alpha3.

The fourth subsection of the package name is the Gentoo Linux-specific revision number ({-r#}). This subsection, like the suffix, is also optional. # is a non-zero positive integer; e.g., package-4.5.3-r3.

This revision number is independent of the version of the source tarball and is used to inform people that a new and improved Gentoo Linux revision of a particular package is available. Initial releases of ebuilds must have no revision number; e.g., package-4.5.3 and are considered by Portage to have a revision number of zero. This means that counting goes as follows: 1.0 (initial version), 1.0-r1, 1.0-r2, etc.

If you make non-trivial improvements to an existing ebuild file, you should copy the ebuild file to a new file with the revision number incremented by 1. Remember to always make mentions of your changes in the ChangeLog when you bump a revision and in your CVS commit message; not doing so is against policy.

... and I suppose that we actually have a fifth section of the ebuild name as well -- the .ebuild extension itself.

Contents of an ebuild file

This section is an introduction to ebuilds. For the full listing of everything possible in an ebuild, there is a manpage which talks about the internal format, variables, and functions in an ebuild script: man 5 ebuild.

Headers

When you submit your ebuilds, the header should be exactly the same as the one in /usr/portage/header.txt. Most importantly, do not modify it in any way and make sure that the $Header: $ line is intact.

The first three lines should look something like this:

Code Listing 2.1: Valid Header

# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

Variables

The first part of every ebuild file is made up of a number of variables. See the devmanual for information on the different variables.

Functions

There are a number of different functions that you can define in ebuild files that control the building and installation process of your package.

Function Purpose
pkg_setup Use this function to perform any miscellaneous prerequisite tasks. This might include checking for an existing configuration file.
pkg_nofetch Inform the user about required actions if for some reason (such as licensing issues) the sources may not be downloaded by Portage automatically. Use this in conjunction with RESTRICT="fetch". You only should display messages in this function, never call die.
src_unpack Use this function to unpack your sources, apply patches, and run auxiliary programs such as the autotools. By default, this function unpacks the packages listed in A. The initial working directory is defined by WORKDIR.
src_compile Use this function to configure and build the package. The initial working directory is S.
src_install Use this function to install the package to an image in D. If your package uses automake, you can do this simply with emake DESTDIR="${D}" install. Make sure your package installs all its files using D as the root! The initial working directory is S.
src_test Executed only when FEATURES="test" is set and RESTRICT="test" is unset, the default of this function executes an available testing function from any Makefiles in the ${S} directory, running either "make test" or "make check" depending on what is provided. It can be overriden to create a custom test setup.
pkg_preinst The commands in this function are run just prior to merging a package image into the file system.
pkg_postinst The commands in this function are run just following merging a package image into the file system.
pkg_prerm The commands in this function are run just prior to unmerging a package image from the file system.
pkg_postrm The commands in this function are run just following unmerging a package image from the file system.
pkg_config You use this function to set up an initial configuration for the package after it's installed. All paths in this function should be prefixed with ROOT which points to user-specified install root which may not happen to be /. This function is only executed if and when the user runs: emerge --config =${PF}.

Helper Functions

You can also use the following helper functions in your ebuilds.

Function Purpose
use Check if one or more given USE-flags are defined. If so, the function will return shell true. In either case, nothing is echoed to standard output. For a verbose version, please use usev which will echo the USE flag if it is defined.
has_version Returns 1 if the system has the requested version of a certain package. For instance has_version >=sys-libs/glibc-2.3.0.
best_version Returns category/package-version of the requested category/package. For instance best_version x11-libs/gtk+extra.
use_with This function checks if a use-flag has been defined and returns "--with-foobar" or "--without-foobar" accordingly. If you only use one argument, that argument is both use-flag and with(out)-string. Otherwise the first argument is the use-flag and the second argument the with(out)-string. For instance use_with truetype freetype will echo "--with-freetype" if truetype is in USE.
use_enable The same as use_with, but returns "--enable-foobar" or "--disable-foobar" accordingly.
check_KV Checks if Portage knows kernel version. If not, display an error and die. If you need the kernel version in your script, use the KV variable which is automatically defined by Portage. On a system running gentoo-sources-2.4.20-r6, KV would have the value "2.4.20".
keepdir Creates (if necessary) a .keep file in the given directory so that it isn't auto-cleaned. Never create a .keep file yourself. If portage changes how keepdir works, then creating the file yourself will break the package.
econf Issues ./configure with the necessary path-changes (prefix, host, mandir, infodir, datadir, sysconfdir, localstatedir). You can optionally pass extra arguments to ./configure by specifying them when you call econf, and users can set the environment variable EXTRA_ECONF if they need to. Options passed to configure take precedence in the reverse order that they were given. In other words, the first argument passed will always be overridden by the last.
einstall Issues make install with the necessary path-changes (prefix, datadir, mandir, infodir, datadir, sysconfdir, localstatedir). Again, you can pass extra arguments to the make command by specifying them when you call einstall. Please note that the preferred way to install a package is via the emake install DESTDIR="${D}" command and not via einstall. This command is only a fall back to override broken make files.
die Causes the current process to be aborted. It will notify the user using the given arguments as a reason. Do not neglect to pass a message to die if you have more than one call to it in a single function. It is harder to track down a failure if you're not sure where the package failed.
elog Inform the user about something important. The argument given to elog is the message that the user will see. Do not use elog to display banners such as "*************************************". The fact that you're using elog is enough to get the user's attention. The message is also logged using portages ELOG system.
einfo Display informative but non-important messages that don't need to be logged.

Helper Functions provided by eutils.eclass

You can use the following helper functions that are provided by the "eutils" eclass in your ebuilds. You must make sure that inherit eutils is present for these functions to work.

Function Purpose
epatch This function acts as a friendlier replacement to the patch command and epatch works with .bz2, .gz, .zip and plain text patches. You do not need to specify a "-p" option, any options that do need to be explicitly specified should be set in EPATCH_OPTS. The function expects either a file or a directory as an argument - if you specify a directory, all patches in the form of "??_${ARCH}_..." will be applied: for a patch to be applied, it needs to match the running architecture, have "_all_" in the name, or EPATCH_FORCE must be set to "yes".
gen_usr_ldscript This function generates linker scripts in /usr/lib for dynamic libraries in /lib. This fixes linking problems when a .so is in /lib while a .a is in /usr/lib.
edos2unix This function performs the same action as the dos2unix binary.
egetent egetent acts as a wrapper for getent for Linux or nidump for Mac OS X (R).
enewuser Creates a new user. This function expects a mandatory argument with the username, and several optional arguments can be specified: $2 contains a UID, pass -1 for the next available ID; $3 contains the shell, pass -1 for the default; $4 contains a home directory with /dev/null being the default, $5 contains any groups to which the user should be added, empty by default and $6 contains any extra options that you may wish to pass to useradd.
enewgroup Adds a new group. This function expects a mandatory argument with the group name - an optional second argument makes the group have a specific GID.
make_desktop_entry Makes a desktop entry: the first argument contains the path to the binary. Optionally, the second contains a name for the icon - the default is ${PN}; the third can contain a path to the icon relative to /usr/share/pixmaps or a full path - the default is ${PN}.png; the fourth can contain an application category, and the fifth argument contains an optional application startup path.
check_license Displays a license for the user to accept, if no arguments are specified then the license specified by ${LICENSE} is used.
unpack_pdv Unpacks a pdv generated archive, the first argument must contain the file to unpack and the second should contain "off_t" which has to be manually generated: strace -elseek ${file} and for something like "lseek(3, -4, SEEK_END)" you would pass the value "4".
unpack_makeself Unpacks a makeself generated archive, requires a file to unpack as the argument.
cdrom_get_cds Attempts to get a CD, present with files specified by the arguments present on the system and mounted at ${CDROM_ROOT}.
cdrom_load_next_cd Loads the next CD once you are done with the first CD. If the function returns, ${CDROM_ROOT} would point to the next CD.
strip-linguas This function makes sure that LINGUAS contains only the languages that a package can support specified by the arguments to the function. If the first argument is -i, then a list of .po files in the specified directories is built and the intersection of the lists is used. If the first argument is -u, then a list of .po files in the specified directories is built and the union of the lists is used.

Helper Functions provided by flag-o-matic.eclass

You can use the following helper functions that are provided by the "flag-o-matic" eclass in your ebuilds. You must make sure that inherit flag-o-matic is present for these functions to work. You should never modify any compiler settings directly, instead please use flag-o-matic to perform any actions such as filtering flags that cause trouble.

Function Purpose
filter-flags This function removes particular flags from C[XX]FLAGS - only complete flags are matched.
append-flags This function adds extra flags to the existing C[XX]FLAGS variables.
replace-flags This replaces the flag specified by the first argument with the one in the second argument in the current C[XX]FLAGS.
replace-cpu-flags Needs two arguments. Replace a given mtune/march/mcpu value with the new one (maybe like this: replace-cpu-flags 'i686' 'i586' will replace -mtune/-march/-mcpu=i686 with -mtune/-march/-mcpu=i586).
strip-flags Strips all flags, except those specified in ALLOWED_FLAGS.
strip-unsupported-flags Strips C[XX]FLAGS of any flags not supported by the running version of GCC.
get-flag Finds a flag and outputs its value.
is-flag This returns true if the flag is set in the current C[XX]FLAGS; only complete matches are performed.
append-ldflags This function adds extra flags to the existing LDFLAGS variable.
filter-ldflags Removes the specified flags from LDFLAGS, only complete flags are matched.
fstack-flags Appends -fno-stack-protector which suppresses -fstack-protector and -fstack-protector-all.

Helper Functions provided by toolchain-funcs.eclass

You can use the following helper functions that are provided by the "toolchain-funcs" eclass in your ebuilds. You must make sure that inherit toolchain-funcs is present for these functions to work. You should never explicitly specify any compiler or binutils settings directly, instead please use toolchain-funcs to specify compilers and binutils.

The purpose of using the below functions is to support cross-compiling and the icc compiler. These should be used whenever a package explicitly uses gcc, g++, ld, ranlib or any of the below tools. In general packages that use autoconfiguration tools detect cross compiling automatically and do not need the following functions.

Function Purpose
tc-getAR Returns the name of the archiver
tc-getAS Returns the name of the assembler
tc-getCC Returns the name of the C compiler
tc-getCXX Returns the name of the C++ compiler
tc-getLD Returns the name of the linker
tc-getNM Returns the name of the symbol/object inspection tool
tc-getRANLIB Returns the name of the archiver indexer
tc-getF77 Returns the name of the fortran compiler
tc-getGCJ Returns the name of the java compiler
tc-getBUILD_CC Returns the name of the C compiler for build
tc-is-cross-compiler A simple way to see if we're using a cross-compiler
gcc-fullversion Returns the version as by $($CC -dumpversion)
gcc-version Returns the version, but only the <major>.<minor>
gcc-major-version Returns the Major version
gcc-minor-version Returns the Minor version
gcc-micro-version Returns the Micro version

Rules for writing an ebuild file

Since ebuild files are really just shell scripts, you should use your editor's shell-script mode for editing them. You should use proper indentation, using only tab characters -- no spaces. Make sure you set up your editor to put tab stops at 4 spaces. Always make sure you use braces around your environment variables; e.g. ${P} instead of just $P.

Long lines are wrapped with ' \', thus:

Code Listing 2.2: Wrapping lines in ebuilds

./configure \
--prefix=/usr || die "configure failed"

For further details, refer to skel.ebuild (usually residing in /usr/portage).

If you use Vim for ebuild/eclass editing, the default Gentoo vimrc file, /etc/vim/vimrc, already ensures that correct indentation and filetype settings are used for ebuild and eclass files. For better results, including special syntax highlighting for ebuild keywords, emerge app-vim/gentoo-syntax.

On non-Gentoo systems, you can obtain similar results by using the following lines in your vimrc, or better yet by installing the gentoo-syntax scripts which can be downloaded from Gentoo mirrors.

Code Listing 2.3: Configuring vimrc for ebuild-editing

au BufRead,BufNewFile *.e{build,class} let is_bash=1|setfiletype sh
au BufRead,BufNewFile *.e{build,class} set ts=4 sw=4 noexpandtab

If you're using Emacs, you should emerge app-emacs/gentoo-syntax (for GNU Emacs) or app-xemacs/gentoo-syntax (for XEmacs). These packages provide Emacs major modes for automatic indentation and syntax highlighting of ebuilds and other Gentoo specific file types.

If you're using nano, then you're in luck! Just edit /etc/nanorc and uncomment the section referring to ebuild's.

USE Variables

The purpose of USE variables is to allow you to configure Portage to globally and automatically enable or disable certain optional build-time features. Here's an example. Let's say you're a GNOME fan, and you'd like any ebuild that has the option of compiling-in optional GNOME support to do so. In this case, you'd add gnome to the USE variable in /etc/make.conf, and then Portage will automatically add optional GNOME functionality to packages if it is available. Likewise, if you don't want optional GNOME features to be added to your ebuilds if they are available, simply edit /etc/make.conf and make sure that gnome is not set in the USE variable. Gentoo Linux has an almost overwhelming number of USE options, allowing you to have your system configured exactly the way you want it.

Note: If you unset a USE variable (for example, removing gnome from USE), this will only instruct Portage to disable optional build-time support for GNOME. However, if you emerge an ebuild that requires GNOME, the package will obviously have GNOME support enabled, as you would expect. This also means that GNOME will be automatically installed (as a dependency) if it hasn't been already. That's why it's always a good idea to do an emerge --pretend before doing the "real" emerge; that way, you'll always know exactly what you're going to get!

In your own ebuilds, you can check whether a USE variable is set by using the use <variable> command. You would normally use this command as follows:

Code Listing 2.4: Finding out if a USE-flag is set

if use X; then
  # Commands specific to X...
fi

USE variables can also be used to set dependencies. For example, you may only want to require a package if a certain USE variable is set. This is done by using the syntax flag? ( mycat/mypackage ) in the DEPEND variable for your ebuild. In this example, mycat/mypackage will only be required if flag is present in USE. It is also possible to specify what dependency should be used if some USE flag is set, and what dependency to use if it is not set: flag? ( mycat/mypackage) and !flag? ( othercat/otherpackage ). In this case, if flag is not set, othercat/otherpackage is used instead of mycat/mypackage. Make sure that your ebuilds use this syntax and not Bash if's. Bash conditionals interfere with Portage's dependency caching, and the use of them will break your ebuild.

Here's an important tip about how to use USE. Most of the time, a package will have a ./configure script used to perform configuration steps. Generally, if your ebuild uses ./configure, any optional build-time functionality will be enabled or disabled by passing the appropriate arguments to the ./configure command. Here's the best way to handle this:

Code Listing 2.5: Conditionals based on USE-settings

DEPEND="X? ( >=x11-base/xfree-4.3 )
mysql? ( >=dev-db/mysql-3.23.49 )
apache2? ( >=net-www/apache-2 )
!apache2? ( =net-www/apache-1* )"

src_compile() {
  econf \
    $(use_enable X x11) \
    $(use_enable mysql) \
    || die "Error: econf failed!"
  emake || die "Error: emake failed!"
}

This approach has a very nice result. We don't have to worry about what the default setting is for mysql or X (enable/disabled), we explicitly tell econf what we want it to do based upon the USE variable. Not to mention it's quite clean in terms of readability :).

Occasionally, ebuilds will have conflicting optional features. Checking for these conflicts and returning an error is not a viable solution. Instead, you must favor one of the features over the others. As to which, consult upstream (what they use as typical default), or consider which option provides more common functionality, or just flip a coin. One example comes from the msmtp ebuilds. The package can use either SSL with GnuTLS, SSL with OpenSSL, or no SSL at all. Because GnuTLS has a lot more features compared to OpenSSL, it is favoured:

Code Listing 2.6: Handling conflicting features

src_compile() {
    local myconf

    if use gnutls ; then
        myconf="${myconf} --enable-ssl --with-ssl=gnutls"
    elif use ssl ; then
        myconf="${myconf} --enable-ssl --with-ssl=openssl"
    else
        myconf="${myconf} --disable-ssl"
    fi

    econf \
        # Other stuff
        ${myconf} \
        || die "configure failed"

    emake || die "make failed"
}

To view a continuously updated table of USE variables, please go here.

1.c. File system Locations

Introduction to the FHS

The file system layout standards used in Gentoo Linux closely follow the FHS, short for File system Hierarchy Standard. A simplified description of the standard is given here; for a complete specification go to http://www.pathname.com/fhs/.

Note: The /opt hierarchy is addressed in section 3.12 of the FHS. Section 4.4 deals with the /usr/X11R6 directory. KDE and GNOME are not specifically addressed, and are in fact not even mentioned in the current version of the FHS.

How to fit your packages into the file system

Usually, if the package uses autoconf and automake, the default installation destinations are mostly correct, with a few exceptions:

  • If you're installing a program into /bin, /sbin, /usr/bin, or /usr/sbin, then the program's corresponding man page should be installed into the /usr/share/man tree. This can often be accomplished by specifying a ./configure --mandir=/usr/share/man in the ebuild.
  • GNU info files should always be installed to /usr/share/info, even if the info files are about X11, GNOME or KDE-specific programs or tools. Make a note: /usr/share/info is the only official location for GNU info files. Since many ./configure scripts default to installing GNU info files in /usr/info, it's often necessary to call ./configure with the --infodir=/usr/share/info argument.
  • Documentation files are installed in /usr/share/doc, into a subdirectory reflecting the name, version, and revision of the particular program. This applies to all programs: GNOME, KDE, X11 and console alike. However, some programs may install additional documentation and support files into a /usr/share hierarchy for their own purposes.
  • X11-specific programs and libraries should always be installed into /usr, not directly into /usr/X11R6. We reserve the /usr/X11R6 hierarchy for the X Window System, Version 11 Release 6 itself. This is perhaps a more to-the-letter interpretation of the FHS than some other distributions have made.
  • GNOME and KDE programs, similarly, should always be installed into /usr.

Important: Some distributions choose to install GNOME and KDE into /opt. There exists no standard for these desktop environments in terms of where to actually install their files. In the interests of simplicity and consistency, we elect to install all KDE and GNOME packages into the /usr hierarchy.

In general, you should have ebuilds install their files into the /usr tree. Some programs can be compiled and linked with or without GNOME, KDE, and X11 libraries, which can cause confusion. Our solution is to install everything into /usr which avoids ambiguity and needless complexity for ebuild authors. The location in which to install a program's files should not depend on the presence or absence of specific USE variables. Therefore, the ebuilds in the portage tree almost always install into the /usr hierarchy exclusively.

Note: The /opt directory is reserved in Gentoo Linux for binary-only packages. Examples include mozilla-bin, acroread, netscape and realplayer. Packages that get installed here will usually require a /etc/env.d/foo stub file. This is so that paths and additional variables can be included into the environment. For more information on /etc/env.d, please visit this document.

1.d. The Portage scripts and utilities

Public scripts

These are scripts used by the system-administrator to install and remove packages, and maintain the package database.

ebuild is the main engine of the Portage system; it performs all major tasks such as unpacking, compiling, installing, merging, and unmerging packages. It is called using the command: ebuild path/to/package.ebuild command. The commands available are:

Command Description Related ebuild Function
setup* Performs any miscellaneous commands required before the ebuild can proceed pkg_setup
depend Displays the dependencies required to build the package N/A
merge* Unpacks, compiles, installs, and merges the package into your file system N/A
qmerge* Merges the package into your file system, assuming that the unpack, compile, and install stages have already been executed N/A
unpack* Unpacks the source tarballs into the work directory src_unpack
compile* Compiles the package src_compile
rpm Creates an RPM from the package N/A
package Creates a Gentoo tbz2 package N/A
prerm* Executes the pre-removal stage of the package pkg_prerm
postrm* Executes the post-removal stage of the package pkg_postrm
preinst* Executes the pre-installation stage of the package pkg_preinst
postinst* Executes the post-installation stage of the package pkg_postinst
config Sets up a default configuration once the package is merged pkg_config
touch* Updates the mtimes for each source archive in the package N/A
clean* Cleans the work directory for the package N/A
fetch* Fetches the package source tarballs N/A
manifest* Creates a Manifest file for the package N/A
test* Runs the self-test routine for the package src_test
install* Installs the package into the image directory src_install
unmerge Unmerges the package from your file system N/A

Note: Commands with an asterisk (*) are normally only used by the developer.

emerge recursively merges a package and all of its dependencies into your file system. This command has many options, try emerge --help for a list of them.

env-update updates the configuration files (including, but not limited to /etc/ld.so.conf and /etc/profile.env) to include changes made by installed packages.

Private Scripts and Commands

These are scripts you can use in your ebuild files to perform common tasks.

For you down and dirty people, look at the scripts themselves in /usr/lib/portage/bin.

Command Default Value Description Example
diropts -m0755 Sets the options used when running dodir diropts -m0750
dobin N/A Installs the specified binaries into DESTTREE/bin dobin wmacpi
docinto "" Sets the relative subdir (DOCDESTTREE) used by dodoc docinto examples
dodir N/A Creates a directory, handling ${D} transparently dodir /usr/lib/newpackage
dodoc N/A Installs the specified files into the package's documentation directory (/usr/share/doc/${PF}/DOCDESTTREE) (see docinto) dodoc README *.txt
doexe N/A Installs the specified files with mode EXEOPTIONS (see exeopts) into PATH defined by EXEINTO (see exeinto). doexe ${FILESDIR}/quake3
dohard N/A Creates a hard link, handling ${D} transparently dohard ls /bin/dir
dohtml N/A Installs the specified files and directories into /usr/share/doc/${PF}/html dohtml -r doc/html/*
doinfo N/A Installs the specified files into /usr/share/info, then compresses them with gzip doinfo doc/*.info
doins N/A Installs the specified files with mode INSOPTIONS (see insopts) into INSDESTTREE (see insinto) doins *.png icon.xpm
dolib N/A Installs the specified libraries into DESTTREE/lib with mode 0644 dolib *.a *.so
dolib.a N/A Installs the specified libraries into DESTTREE/lib with mode 0644 dolib.a *.a
dolib.so N/A Installs the specified libraries into DESTTREE/lib with mode 0755 dolib.so *.so
doman N/A Installs the specified files into /usr/share/man/manX, according to the suffix of the file (file.1 will go into man1) doman *.1 *.5
dosbin N/A Installs the files into DESTTREE/sbin, making sure they are executable dosbin ksymoops
dosym N/A Creates a symlink, handles ${D} transparently dosym gzip /bin/zcat
emake N/A Runs make with MAKEOPTS. Some packages cannot be made in parallel; use emake -j1 instead. If you need to pass any extra arguments to make, simply append them onto the emake command. Users can set the EXTRA_EMAKE environment variable to pass extra flags to emake. emake
exeinto / Sets the root (EXEDESTTREE) for the doexe command exeinto /usr/lib/${PN}
exeopts -m0755 Sets the options used when running doexe exeopts -m1770
fowners N/A Applies the specified ownership to the specified file via the chown command, handles ${D} transparently fowners root:root /sbin/functions.sh
fperms N/A Applies the specified permissions to the specified file via the chmod command, handles ${D} transparently fperms 700 /var/consoles
insinto /usr Sets the root (INSDESTTREE) for the doins command insinto /usr/include
insopts -m0644 Sets the options used when running doins insopts -m0444
into /usr Sets the target prefix (DESTTREE) for all the 'do' commands (like dobin, dolib, dolib.a, dolib.so, domo, dosbin) into /
libopts -m0644 Sets the options used when running dolib libopts -m0555
newbin N/A Wrapper around dobin which installs the specified binary transparently renaming to the second argument newbin ${FILESDIR}/vmware.sh vmware
newdoc N/A Wrapper around dodoc which installs the specified file transparently renaming to the second argument newdoc README README.opengl
newexe N/A Wrapper around doexe which installs the specified file transparently renaming to the second argument newexe ${FILESDIR}/xinetd.rc xinetd
newins N/A Wrapper around doins which installs the specified file transparently renaming to the second argument newins ntp.conf.example ntp.conf
newman N/A Wrapper around doman which installs the specified file transparently renaming to the second argument newman xboing.man xboing.6
newsbin N/A Wrapper around dosbin which installs the specified file transparently renaming to the second argument newsbin strings strings-static
prepall N/A Runs prepallman, prepallinfo and prepallstrip. Also ensures all libraries in /opt/*/lib, /lib, /usr/lib and /usr/X11R6/lib are executable. also moves any stray aclocal macros into /usr/share/aclocal prepall
prepalldocs N/A Behavior has changed between Portage versions so new ebuilds should not use this function. prepalldocs
prepallinfo N/A Recursively gzips all info files in /usr/share/info prepallinfo
prepallman N/A Recursively gzips all man pages in /opt/*/man/*, /usr/share/man/*, /usr/local/man/*, /usr/X11R6/share/man/* and transparently fixes up any symlink paths prepallman

1.e. Package Dependencies

Why dependencies are important

Portage is more than just a convenience script that gives you a unified way to build any one project (program, library) from source. It will also fetch and install any necessary dependencies if you take care to specify these in your ebuild.

In the official ebuilds, all dependencies have already been specified, so when you issue emerge net-www/mozilla/mozilla-1.0, Portage will insure that all libraries necessary for Mozilla to build and run are properly installed before Mozilla itself is built.

Portage even distinguishes between build-time dependencies and run-time dependencies. (Caveat: Currently, Portage installs all build-time and run-time dependencies and leaves it at that. At a later stage, it will be possible to trim your installation so that only the run-time dependencies are left installed).

How to Specify Dependencies in Your ebuild Files (a.k.a. DEPEND Atoms)

The DEPEND variable inside your foo-x.y.z.ebuild tells Portage about which packages are needed to build foo. The RDEPEND variable specifies which packages are needed for foo to run. RDEPEND should be set explicitly even if it's the same as DEPEND because in the future it defaulting to DEPEND is planned to be removed from Portage.

Code Listing 5.1: Depend example

DEPEND="virtual/opengl
	dev-libs/libxml2"
RDEPEND="${DEPEND}"

This tells Portage that to build foo-x.y.z, the packages virtual/opengl (more on virtuals in a bit) and dev-libs/libxml2 are needed. It does not say anything about which version of opengl or libxml2 that are needed, which means "anything goes".

The "anything goes" is of course a bit scary, and will not work in the general case. But for libraries, which strive very hard to be 100% binary compatible all the time, it actually works. For other libraries, we can of course specify version dependencies.

Code Listing 5.2: Version example

>=sys-apps/bar-1.2
=sys-apps/baz-1.0

>= and = do what you would expect; sys-apps/bar version 1.2 or newer is okay (this means that sys-apps/bar-2.0 is okay), while sys-apps/baz version 1.0 is the only version that is accepted. For more information on the version schema of packages, see the section above on Naming ebuild Files.

Other methods of specifying version dependencies are as follows:

Code Listing 5.3: Specifying version dependencies

~sys-apps/qux-1.0
=sys-apps/foo-1.2*
!sys-libs/gdbm

~sys-apps/qux-1.0 will select the newest portage revision of qux-1.0.

=sys-apps/foo-1.2* will select the newest member of the 1.2 series, but will ignore 1.3 and later/earlier series. That is, foo-1.2.3 and foo-1.2.0 are both valid, while foo-1.3.3, foo-1.3.0, and foo-1.1.0 are not. Please note that foo-1.22.3 will also match, which can become a problem at times.

!sys-libs/gdbm will prevent this package from being emerged while gdbm is already emerged.

Important Notes

There are many things that go wrong with the DEPEND and RDEPEND variables. Here are some important points to follow when you write the dependencies.

  • Always include the CATEGORY.
    For example, use >=x11-libs/gtk+-2 and not >=gtk+-2.
  • Do not put an asterisk (*) for >= dependencies.
    For example, it should be >=x11-libs/gtk+-2 rather than >=x11-libs/gtk+-2*.
  • Never depend on a meta-package.
    So don't depend on gnome-base/gnome, always depend on the specific libraries like libgnome.
  • One dependency per line.
    Don't put multiple dependencies on the same line. It makes it ugly to read and hard to follow.
  • GTK: Always use =x11-libs/gtk+-1.2* for GTK+1 apps.

Additionally, it is important to ensure that all the dependencies are complete for your package:

  • Look in configure.in or configure.ac
    Look for checks for packages in here. Things to look out for are pkg-config checks or AM_* functions that check for a specific version.
  • Look at included .spec files
    A good indication of dependencies is to look at the included .spec files for relevant deps. However, do not trust them to be the definitive complete list of dependencies.
  • Look at the application/library website
    Check the application website for possible dependencies that they suggest are needed.
  • Read the README and INSTALL for the package
    They usually also contain useful information about building and installing packages.
  • Remember non-binary dependencies such as pkg-config, doc generation programs, etc.
    Usually the build process requires some dependencies such as intltool, libtool, pkg-config, doxygen, scrollkeeper, gtk-doc, etc. Make sure those are clearly stated.

For all the latest details about these DEPEND Atoms, please see the section 5 manpage on ebuilds: man 5 ebuild.

1.f. Testing and deploying

ChangeLog

Whenever you update (or write a new) an ebuild, you must also update its (or create a new) ChangeLog. The skel.ChangeLog contains a sample ChangeLog that you can use as a basis.

The purpose of the ChangeLog is to document what is being done, why it is being done, and by whom. This allows both developers and users to trace the changes made in an easy way.

The ChangeLog is primarily targeted at users, so be sure to keep your writing short, to the point, and avoid getting verbose about the internal technical details.

Storing your own ebuilds locally

In order to be able to test your ebuilds and let Portage know about them, you must place those in a known directory. Portage will use the PORTDIR_OVERLAY variable which you can define in /etc/make.conf. You should set this variable to your directory (e.g. /usr/local/portage).

In that directory, you must use the same structure (and categories) as in /usr/portage.

Using this PORTDIR_OVERLAY, your ebuilds remain on your system, even after an emerge sync, and they are still known to Portage.

Testing the package

Have a think about how you will test whether this package works. Sometimes the developers have already included a make test or make check routine that will test the basic functionality of the package. If so, then running FEATURES=test ebuild foo-x.y.z.ebuild test will execute it. If it is broken try to fix it so that it works (and submit the patch to the upstream developers).

If this is not the case consider adding a src_test routine to your ebuild. This is executed before the src_install routine and can be very helpful for testing the program works across various architectures. The architecture developers will appreciate if you add a routine here so that they do not require knowledge of the package's functionality.

Please keep in mind the general requirements of an ebuild here. The src_test routine must not be interactive. If the test routine depends on other packages use the test USE flag to specify the optional compile time DEPENDancies. Also, please note that src_test routines are not recommended for graphical X applications as the user running portage often cannot run them successfully.

Useful testing tools

We have a few useful tools to help you with writing and maintaining your ebuilds.

Tool Package Description
repoman sys-apps/portage Developer-only tool to assist with the CVS check in procedure. It does a lot of common QA and tries to make sure that files added to cvs will not break the portage tree.
ccache dev-util/ccache Tool that keeps pre-processed files so that recompilation gets done much faster. Be sure to add ccache to the FEATURES variable in /etc/make.conf!
sandboxshell app-shells/sandboxshell Launch a shell that creates a sandbox environment. Useful for entering the same environment that portage builds packages inside of and debugging things by hand.
echangelog app-portage/gentoolkit-dev Can create a new ChangeLog or add an entry to an existing one.

2. Eclass HOWTO

2.a. Introduction to eclasses

The idea behind eclasses

eclasses are modules of shared code. They are written in bash and have the same syntax as ordinary ebuilds, and are sourced ('inherited') by ebuilds and other eclasses, to provide default settings and functionality across many similar ebuilds.

This is used to ensure maximum code reuse among similar ebuilds.

This first chapter shows briefly how to write an eclass incorporating the standard tricks and techniques used in existing eclasses. The second is an overview of the kde eclasses.The third explains how to write a KDE ebuild using the kde group of eclasses.

An example of a simple eclass

Here is a fictive sourceforge.eclass, designed to provide homepage and download locations to sourceforge.net-hosted projects:

Code Listing 1.1: Example: sourceforge.eclass

# Copyright 2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
# Author Dan Armak <danarmak@gentoo.org>
# $Header: $

# This eclass sets ${HOMEPAGE} and ${SRC_URI} to the standard values for
# sourceforge.net - hosted projects.

HOMEPAGE="http://${PN}.sourceforge.net/"
SRC_URI="http://download.sourceforge.net/${PN}/${P}.tar.gz"

The first four lines are headers, just like those in any ebuild. The next two lines are a short description of the eclass. The rest of the code does the actual work - setting SRC_URI and HOMEPAGE.

Most eclasses go beyond setting variables and providing helper functions; they contain default versions of the special ebuild functions (src_unpack, src_compile and so on). Before writing a default function in an eclass, you should be aware of the default functions already contained in ebuild.sh. They are what gets executed if you don't put some function in your ebuild (not even via an eclass); the default src_unpack() is often used. If you haven't yet, go and look at the default implementations in ebuild.sh.

This is all you need to know to actually write eclasses. Put your new eclass in ${PORTDIR}/eclass/, and put this line at the beginning of your ebuild:

Code Listing 1.2: How to inherit eclasses

inherit sourceforge

The contents of the eclass will be sourced at this point. Remember that any variables or functions defined in the eclass can be overridden in the ebuild, whose code executes after any eclasses. Therefore, you should try to put as much default settings and common code in your eclass as possible. Any nonstandard settings and modifications can then be put into the ebuild.

Oh, and you can inherit several eclasses at the same time by saying:

Code Listing 1.3: Inheriting multiple eclasses

inherit eclass1 eclass2 [...]

...but watch their order! Remember, eclasses can inherit one another and override each other's settings, so you should be careful when dealing with multiple eclasses that might influence one another.

We will now go over all the tricks of eclass writing, before moving on to the actual eclasses in portage.

inherit()

This function lives in ebuild.sh and handles inheriting (sourcing) of eclasses. It is called with a list of eclass names to inherit: inherit <eclass1> [eclass2 eclass3...].

Besides actually sourcing the eclass files, it sets the ECLASS and INHERITED variables which are used by portage for caching eclass modification timestamps. The INHERITED variable might be of use in writing eclasses: it contains a list of all eclasses inherited (sourced) up to this point, in order. Thus an eclass can use it to determine whether or not it was called from some other eclass.

EXPORT_FUNCTIONS

A good eclass's predefined functions can often be used as-is; the ebuild will then contain very little code (which is good). Sometimes, though, the eclass functions won't do exactly what you need. You could write a new function in your ebuild, overriding the function definition from the eclass. However, this would minimize the benefit of code reuse. So we try to 'extend' the eclass functions instead.

Suppose you want to extend src_compile(). You can write an src_compile() definition in your ebuild, which would only include the parts missing from the eclass src_compile(). You would then call the eclass src_compile() from within the code of your custom function.

However, if you create a new function called src_compile(), bash will forget about the old one and you won't be able to call it! That's where the EXPORT_FUNCTIONS macro comes into play.

Let's look at another problem for a moment. Suppose that foo.eclass and bar.eclass both define src_compile(). If you inherit both foo and bar you'll get a different src_compile() depending on the order in which you inherit them. That's ok; you're supposed to keep track of your inheritance order. But you may want to call either of the two src_compile()s explicitly.

So, every eclass adds to the functions that it defines a prefix. For example, foo.eclass will define a function called foo_src_compile(), and bar.eclass will define a bar_src_compile(). That way, the ebuild can call either function and know what it'll get.

However, we also want to have some default function called just src_compile(), or the ebuild will have to define one. The EXPORT_FUCTIONS macro solves both this problem and the one presented earlier.

Code Listing 1.4: EXPORT_FUNCTIONS() (from ebuild.sh)

EXPORT_FUNCTIONS() {
	while [ "$1" ]; do
		eval "$1() { ${ECLASS}_$1 ; }" > /dev/null
		shift
	done
}

The inherit() function sets ${ECLASS} to the eclass's name before sourcing it. The eclass, at its end, calls EXPORT_FUNCTIONS(), passing as parameters the list of default functions it provides. For example, if you call

Code Listing 1.5: EXPORT_FUNCTIONS call example

EXPORT_FUNCTIONS src_compile src_install

then EXPORT_FUNCTIONS will call eval() on the following string:

Code Listing 1.6: EXPORT_FUNCTIONS result

src_compile() { foo_src_compile ; }
src_install() { foo_src_install ; }

Now, whichever eclass is inherited last will define the default src_compile() function, but both functions can be directly called by the ebuild if needed.

You can also extend the default src_compile() function by calling the eclass's function from within your own function. You then have to use the default function's full name of foo_src_compile. An example:

Code Listing 1.7: Extending eclass-provided default functions in your ebuild

#in foo.eclass:
foo_src_compile() {
	[default code here]
}

EXPORT_FUNCTIONS src_compile
#end eclass code

#in an ebuild:
inherit foo

src_compile() {
	[custom code here]
	foo_src_compile
	[more custom code]
}

Function sections

Sometimes, extending default functions by having code execute before and after isn't flexible enough. When dealing with long, complex functions, you often want to have your custom code run in the middle of those functions.

Function sections provide for greater flexibility required here. They break the functions down into sections and allow you to execute code between any two sections.

The implementation is simple. Let's take as an example the src_compile() function from base.eclass. (Note: it no longer exists, but it's a good example :-) It looks like this:

Code Listing 1.8: Example from original base.eclass

base_src_compile() {
    econf || die
    emake || die
}

Here is the same function, divided into sections:

Code Listing 1.9: The same function divided into sections.

base_src_compile() {
 
    [ -z "$1" ] && base_src_compile all
 
    while [ "$1" ]; do
        case $1 in
            configure)
                ./configure || die;;
            make)
                emake || die;;
            all)
                base_src_compile configure make;;
        esac
    shift
    done
 
}

The code has been divided into two sections: configure and make. In our simple example, they correspond to the two commands in the original function.

In the center of the new function is a while;case...esac;shift;done block. This block matches the parameters to the function with the defined section names and executes the corresponding lines of code.

The special case all calls the same function recursively with a list of sections in order. It's up to the eclass's author to maintain this list.

The line before the block says that a call without parameters should be treated the same as a call with the single parameter all. As you see, this function recurses a lot. Note, however, that the call base_src_compile configure all make is also legal; it will execute base_src_compile configure configure make make.

Now, in your ebuild (or eclass) that inherits from base.eclass, you get the stub function src_compile which calls base_src_compile without parameters. This makes base_src_compile execute all, that is, all its sections. You can leave it as-is. If you wish to extend it, you can define a new src_compile and call base_src_compile a section at a time:

Code Listing 1.10: Using the sectioned src_compile()

src_compile() {
    run_my_code1
    base_src_compile configure
    run_my_code2
    base_src_compile make
    run_my_code3
}

As you can see, the function sections add flexibility since you can now insert code between the two sections, as well as run them in a different order or run only some of the sections provided. This makes for greater code reuse overall.

The debug-print-* functions

These are more functions provided by ebuild.sh. They add verbose debug output facilities to eclasses, to allow you to trace their execution more easily without having to read the long traces provided by the bash debug mode. All my eclasses call these functions a lot.

debug-print() simply prints all its parameters with the 'debug:' prefix. It is called whenever there's something interesting to put in the debug log.

debug-print-function() prints 'debug: entering function $1, parameters: $2 [$3 ....] It is called at the beginning of a function.

debug-print-section() prints 'debug: now in section $1'. It is called at the beginning of a function's section.

The debug output normally goes into ${T}/eclass-debug.log. You can set the ECLASS_DEBUG_OUTPUT env. variable (in make.globals/conf or in the environment) and output will be sent there as well. You can also set it to the special value 'on', which echoes output to stdout together with the other emerge messages.

Let's add typical debug output statements to our sample function:

Code Listing 1.11: Adding debug statements

base_src_compile() {
 
    debug-print-function
    [ -z "$1" ] && base_src_compile all
 
    while [ "$1" ]; do
        case $1 in
            configure)
                debug-print-section configure
                ./configure || die;;
            make)
                debug-print-section make
                make || die;;
            all)
                debug-print-section all
                base_src_compile configure make;;
        esac
    shift
    done
 
    debug-print "${FUNCNAME}: result is ${RESULT}"
}

${FUNCNAME} is a bash built-in that returns the current function's name.

2.b. Existing eclasses

Introduction

Most eclasses are simple, and you should simply read them and maybe glance at a couple of ebuilds using them to understand how they work. Also, most eclasses are well-commented, so it's best to read them.

This chapter documents the overall relationship between the kde* eclasses.

base.eclass

This eclass defines some default variables and functions, similar to those you'd get by default in a non-inheriting ebuild (which are defined in ebuild.sh). You probably aren't interested in using it directly, but rather through one of the kde eclasses, which inherit it.

One interesting bit of functionality it provides is the autopatch capability. If you set the PATCHES variable to contain a list of files in your ebuild that uses base_src_unpack() (or kde_src_unpack()), the sources will be patched from those files. The patches need to work with -p0 when run from ${S}.

Note that you can set PATCHES without defining a custom src_unpack() in your ebuild! That is what it's for.

The newer epatch() function from eutils.eclass is much more powerful - it supports compressed patches, patch directories and series, and automatic detection of the patch level - and I intend to make autopatch use it sonmeday.

Note that the patch section in base_src_unpack() is deprecated and will be removed soon. If you see an ebuild using it, it needs to be converted to the autopatch style.

cvs.eclass

This eclass provides the functionality needed to create 'live' cvs ebuilds. Such ebuilds fetch sources from a specified cvs server at unpack time, thus always getting the latest bugs and fixes from upstream.

However, the necessary (versioning etc.) support for live cvs ebuilds has not yet been added to portage. They can work with this eclass, but it is inconvenient in many respects. Think twice before creating a live cvs ebuild; perhaps a regular cvs snapshot would be better. If you intend to add such an ebuild to portage, be aware of the cvs ebuild guidelines in the developer's guide.

Before inheriting cvs.eclass, set any non-default settings you want (at least the server address and module name). See the list of configurable settings and default values at the beginning of cvs.eclass, marked as 'ebuild-configurable settings'.

After that, things are mostly automatic. A cvs_src_unpack() (no sections) is provided. If you wish to know more, read the eclass itself.

kde-functions.eclass

This eclass contains all KDE-related helper functions. Some of them you should never need to use directly in an ebuild; these are not mentioned here, and should be well-commented in the source.

Note that by 'helper functions' I mean any functions that aren't special ebuild functions (src_unpack() etc.). All kde eclasses containing such 'special' functions inherit kde-functions.

The only code outside any functions in kde-functions.eclass (which thus runs on sourcing) is a block that determines whether or not the current ebuild is one from kde-base. If it is, KDEBASE=true is set. This variable is used in various logic tests elsewhere and it is comfortable to have one centralized test for it.

The current multi-kdedir scheme

A short explanation about the way Gentoo manages multiple KDE versions:

A KDE (that is, things from kde-base) live in /usr/kde/${major-version}.${minor-version}. So, fex., KDE 3.1.x lives in /usr/kde/3.1. However, this scheme was established after the KDE 3.0 release, and so older versions live in nonstandard locations: KDE 3.0.x lives in /usr/kde/3 (and not /usr/kde/3.0), and KDE 2.2.2 (the only 2.x version we have) lives in /usr/kde/2. The cvs ebuilds I maintain install into /usr/kde/cvs.

Any number of KDEs with different minor versions can thus coexist. kde-base packages have a SLOT of major.minor (e.g. 3.0, 3.1).

Since QT versions are supposed to be fully backward compatible across minor versions, we have only one of each major version installed and with a different slot; they live in /usr/qt/$major.

A non-kde-base ebuild always installs in /usr. The kde-env package puts KDEDIRS=/usr in env.d, allowing these apps to run properly. The app compiles and links against the latest KDE libraries found; the eclass checks the standard locations in descending order - /usr/kde/cvs, then /usr/kde/3.1, then /usr/kde/3. (kde-base ebuilds will always link against the kdelibs of their own version.) This of course also depends on the parameter given to need-kde() (see below).

There are several special variables you can set to change the default settings of this system. Their prime usage is to compile an ebuild against a specific KDE you have installed for testing, but you can also use them to install a KDE in a nonstandard location, and so have, fex., both KDE 3.0.1 and 3.0.2 installed side-by-side. This, again, is most useful for testing and development.

All KDE apps (base and non-base) will install into ${KDEPREFIX}, if set. It overrides all other logic in the eclasses.

A KDE app (even if it is a kde-base one) will try to link against the kdelibs installed in ${KDELIBSDIR}, if set. If it fails, it will fall back to the default logic of locating the latest kdelibs (or the proper version for kde-base version).

need-kde(), need-qt(), set-kdedir(), set-qtdir()

kde-functions.eclass provides two pairs of functions: need-kde(), need-qt() and set-kdedir(), set-qtdir(). These functions handle the details of multiple KDEs and QTs setup.

The need-kde() function is called with a parameter which is the minimal version number of kdelibs required. It adds the proper dependencies to DEPEND, RDEPEND and call the set-kdedir() function. If no parameter is passed, a version number of 0 (zero) is used, meaning that any version will satisfy the dependency. need-kde() also calls need-autoconf() and need-automake() with the correct parameters for this KDE version.

The set-kdedir() function then determines the installation prefix and kdelibsdir location your ebuild should use. These are passed to you in ${PREFIX} and ${KDEDIR}, respectively (and are handled automatically in kde.eclass). Note that no ebuild should ever address ${KDEPREFIX} or ${KDELIBSDIR} directly!

need-kde() also looks up the minimal version of QT required for this version of kdelibs from a table. It then calls need-qt() with this version. A qt-only (i.e. non-kde) app's ebuild usually calls need-qt directly, bypassing need-kde.

The need-qt() function adds the required QT version to DEPEND, RDEPEND and calls set-qtdir() with it. The set-qtdir() function sets QTDIR to be the default location of this version of QT. Unlike set-kdedir(), set-qtdir() doesn't actually check if there's a QT installed there.

need-kde() (or need-qt()) needs to be called from the main part of the ebuild (i.e. not from a function), so that any changes to DEPEND and RDEPEND affect emerge.

need-autoconf(), need-automake()

These functions set the necessary environment variables to make the requested version of autoconf or automake run. They also unset all previously set variables of this kind. For example, calling 'need-automake 1.4' will set NEED_AUTOMAKE_1_4=1 and unset all other WANT_AUTOMAKE* variables. For more info see the functions' code and the comments at the beginning of /usr/bin/auto{conf,make} (on a Gentoo system).

kde_sandbox_patch()

Some KDE makefiles are broken. They chmod or chown files in PREFIX when installing, but do not respect DESTDIR (${D}). I.e. when installing, they correctly copy a file to ${DESTDIR}/${PREFIX}/path/foo, but then try to chmod +x the file ${PREFIX}/path/foo on the live filesystem which may not even exist. And if it does exist, the sandbox prevents this operation.

This function runs a generic sed on makefiles which fixes all known cases of the problem. It is called with the directories to be processed as parameters, and processes Makefile, Makefile.in and Makefile.am in those directories. For example:

Code Listing 2.1: Processing

src_unpack() {
    base_src_unpack
    kde_sandbox_patch ${S}/dir1 ${S}/dir2/dir3
}

kde_remove_flag()

This is used to weed out compiler flags that are known to break packages. You call it after unpacking with the subdirectory of ${S} in which to work as the first parameter, and the name of the flag to remove as the second. Note that it is not recursive. Example: "kde_remove_flag foodir/barfoo -fomit-frame-pointer".

kde_remove_dir() and ${KDE_REMOVE_DIR}

This function removes the specified subdir from compilation. It deletes it and removes all mention of it from the subdirs file, configure and the makefiles. Note that it only works on subdirs of ${S} for now, not on 2nd level subdirs. You can call it with a list of subdirs to remove; it works on each parameter in turn.

You can call it directly, but to avoid having to define a custom src_unpack() just to do that, you can set KDE_REMOVE_DIR to a list of subdirs to remove. kde_src_unpack() will call 'kde_remove_dir ${KDE_REMOVE_DIR}' after unpacking. As you can see, I go to some lengths to avoid having to define an extra function in an ebuild, because this makes the ebuilds much cleaner and more readable.

kde.eclass

This is the main, central KDE eclass. It contains most of the KDE-related code. All KDE ebuilds inherit it, one way or another. The kde eclass inherits base and kde-functions.

As with the other eclasses, read it to find out what it does. Most of it should be self-obvious. Here is a short summary:

The eclass's global section (i.e. the one that's executed when you inherit it) adds the correct deps on kde-env, automake, autoconf, make and perl (the last is used by standard configure scripts for fast makefile generation). It also sets the default SLOT="0".

kde_src_unpack() basically just calls base_src_unpack(), passing on any parameters (e.g. sections to execute). After that, it adds kde-specific items. It touches all .ui files in the unpacked sources to regenerate any stale .cpp,.h files. It also calls kde_remove_dir() with ${KDE_REMOVE_DIR} if this variable is set (see above in the section on kde-functions).

kde_src_compile() also has several fixes. One is exporting kde_widgetdir="${KDEDIR}/lib/kde3/plugins/designer" to get around a bug in older kde acinclude.m4.in's. Another is setting HOME="${T}/fakehome", so that any accesses to ${HOME}/.kde and ${HOME}/.qt aren't stopped by the sandbox, and don't affect the user's home directory. It is a bug (or shortcoming) of uic that it always tries to access config files in these locations.

kde_src_compile() has several sections. myconf adds to ${myconf} the default kde configure script parameters, such as --prefix=${PREFIX} (remember, ${PREFIX} is set by set-kdedir()). You can add your own values to ${myconf} either before or after this section; just remember never to overwrite old values, because users can expect to set ${myconf} in the shell and in this way add something to the configure parameters used by the ebuild.

The configure section runs the configure script in ${S}, passing ${myconf} to it. If the configure script does not exist, it tries to generate it by running make -f Makefile.cvs or make -f admin/Makefile.common. Thus, this stage of compilation (which is needed for cvs snapshots, or ebuilds that patch files like configure.in) is also done automatically.

The make section simply runs emake || die. Finally, there is an all section which runs all of the above.

Finally, kde_src_install() has a make section which runs make install, and a dodoc section which runs dodoc on some standard doc names in ${S}, such as README and COPYING.

kde-base.eclass

This eclass is now deprecated, ebuilds should "inherit kde" instead.

kde-dist.eclass

This eclass is for the core kde distribution packages in kde-base/*. It inherits kde.

It sets the correct DESCRIPTION and HOMEPAGE and calls need-kde ${PV}. The simpler, smaller kde-base/ packages (e.g. kdetoys) don't need to make any changes to it; most of those that do only add deps and patches.

kde-i18n.eclass

This eclass is for the kde-i18n-* packages. In fact, all kde-i18n ebuilds are completely identical and so all they have to do is inherit from this eclass. Their ${P}, ${P}, ${PV} variables do the rest.

kde.org.eclass

This eclass is also deprecated, and all the code has been moved to kde-dist.eclass.

koffice-i18n.eclass

This eclass is meant for the koffice-i18n-* packages and is very similar to kde-i18n.eclass. Again, all kde-i18n ebuilds are completely identical and so all they have to do is inherit from this eclass.

kde-source.eclass

This eclass works on top of cvs.eclass, adding some kde-specific functionality. For example, it automatically fetches the admin/ dir from the kde-common module of kde cvs. Read the eclass to find out more, including kde-cvs-specific settings you can pass to it.

2.c. Writing KDE ebuilds

Introduction

This chapter explains how to write standard KDE ebuilds. All that is said here is mostly a rehashing of the information about eclasses above. When in doubt, look at other ebuilds, at the eclasses, or ask.

A typical KDE ebuild

The code below should be obvious after reading this howto:

Code Listing 3.1: A simple KDE ebuild, #1

<Header goes here...>
inherit kde

Some ebuilds end right here. Others need some customization.

The next stage is to add any extra deps. Remember: *always* extend variables, never override!

Because our goal is to avoid defining custom ebuild functions unless we have to, we set all the settings we can, and call all the helper functions we can, directly from the ebuild's main section. Remember though that there are limitations on code in the main section; for example, it must not produce any output (debug-print() output probably doesn't count though).

Code Listing 3.2: A simple KDE ebuild, #2: adding extra dependencies

DEPEND="foo/bar"
RDEPEND="bar/foo"

We also want to add some extra arguments to myconf, which are then passed to configure (assuming that we use kde_src_compile's configure section):

Code Listing 3.3: A simple KDE ebuild, #4: passing arguments to configure

myconf="$myconf --with-foobar"

We also have a patch to add. If it can be applied using -p0 in ${S}, we can use base_src_unpack's autopatch section. Remember, kde_src_unpack() calls base_src_unpack() passing on any parameters you gave it.

Code Listing 3.4: A simple KDE ebuild, #5: autopatching

PATCHES="$FILESDIR/$P-myfix.diff"

Finally, we want an extend src_install() to put in place some documentation:

Code Listing 3.5: A simple KDE ebuild, #6: extending src_install()

src_unpack() {
    kde_src_install
    dodoc $S/doc/*
}

Let's look at the ebuild we have created in this example:

Code Listing 3.6: A simple KDE ebuild - complete listing

<Header goes here...>
inherit kde

# add deps
DEPEND="foo/bar"
RDEPEND="bar/foo"

# always enable foobar
myconf="${myconf} --with-foobar"

# fix terrible bug
PATCHES="${FILESDIR}/${P}-myfix.diff"

src_unpack() {
    kde_src_install
	# install some extra docs not included in make install's targets
    dodoc ${S}/doc/*
}

A typical ebuild with optional KDE functionality

When adding kde (eclass) functionality to an existing ebuild, you should simply prefix each kde-specific line with use kde && , or create whole if [ -n "`use kde`" ]; then; fi blocks.

To the general section, add the following (only if USE kde is set, of course):

Code Listing 3.7: Optional KDE support - main ebuild section

inherit kde-functions

# This will add kdelibs, kde-env to your dep strings and set ${KDEDIR}
# to the correct value:

need-kde ${version} # minimal version of kde your app needs

# Add anything else you need for kde support:
use kde && myconf="${myconf} --with-my-parameter"

Then, tell your app to look for KDE in the ${KDEDIR} setting that is available after calling need-kde(). If you do not want the kdelibs dep to be added, call set-kdedir() instead of need-kde().

3. Common ebuild Mistakes

3.a. Common Ebuild Writing Mistakes

Introduction

Here is a list of common ebuild mistakes that are common in user-submitted ebuilds. Please make sure the ebuilds you submit don't violate any of these. Before submitting any ebuilds, make sure you read the Gentoo ebuild Development Policy and the Gentoo ebuild HOWTO. Also, make sure you read a couple (eg. more than one or two) of the ebuilds in the tree to make sure you know the style that ebuilds are written in.

Also it would be useful to read a couple of ebuilds that use eclasses and understand how to use them by reading the Eclass HOWTO. Finally, you must read the Contributing Ebuilds Guide carefully before submitting your ebuild(s).

Missing/Invalid/Broken Header

When you submit your ebuilds, the header should be exactly the same as the one in /usr/portage/skel.ebuild. Most importantly, do not modify it in any way and make sure that the $Header: $ line is intact.

The first three lines must look like this:

Code Listing 1.1: Valid Header

# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

Only if you are submitting a patched or version bumped ebuild, should you not need to modify the $Header: $ line. But the line must be present. When we check the ebuild into CVS, it will modify that header with the appropriate version and date information. So there is no need for you to manually modify it.

IUSE Missing

By far the most common omission is the IUSE variable. You must (according to the Gentoo ebuild HOWTO) include the IUSE variable even if there are no USE flags in use. If there are no USE flags supported, then just add the following:

Code Listing 1.2: Empty IUSE

IUSE=""

Redefined P, PV, PN, PF

You should never redefine those variables. Always use MY_P, MY_PN, MY_PV, P0, etc. See other ebuilds that do it in portage for more information. Most ebuilds use bash "Parameter Expansion". Please read the man page for bash to understand how "Parameter Expansion" works.

By the way, if you find a package that re-defines it, don't copy it. Submit a bug about that ebuild.

Including version numbers in SRC_URI and S

You should try not to include version numbers in the SRC_URI and S. Always try to use ${PV} or ${P}. It makes maintaining the ebuild much easier. If a version number is not consistent with the tarball/source, then use MY_P. An example dev-python/pyopenal fetches a tarball called PyOpenAL, so we redefine it like:

Code Listing 1.3: Example versioning redefinition

MY_P=${P/pyopenal/PyOpenAL}
SRC_URI="http://oomadness.tuxfamily.org/downloads/${MY_P}.tar.gz"
S=${WORKDIR}/${MY_P}

DEPEND has syntactical errors

There are many things that go wrong with user submitted DEPEND and RDEPEND fields. Here are some important points to follow when you write the dependency part.

  • Always include the CATEGORY.
    For example, use >=x11-libs/gtk+-2 and not >=gtk+-2.
  • Do not put an asterisk (*) for >= dependencies.
    For example, it should be >=x11-libs/gtk+-2 rather than >=x11-libs/gtk+-2*.
  • GTK specific. Always use =x11-libs/gtk+-1.2* for GTK+1 apps.
  • Never depend on a meta package.
    So don't depend on gnome-base/gnome, always depend on the specific libraries like libgnome.
  • One dependency per line.
    Don't put multiple dependency on the same line. It makes it ugly to read and hard to follow.

DEPEND is incomplete

This is another very common error. The ebuild submitter submits an ebuild that "just works" without checking if the dependencies are correct. Here are some tips on how to find the correct dependencies.

  • Look in configure.in or configure.ac
    Look for checks for packages in here. Things to look out for are pkg-config checks or AM_* functions that check for a specific version.
  • Look at included .spec files
    A good indication of dependencies is to look at the included .spec files for relevant deps. However, do not trust them to be the definitive complete list of dependencies
  • Look at the application/library website
    Check the application website for possible dependencies that they suggest are needed.
  • Read the README and INSTALL for the package
    They usually also contain useful information about building and installing packages.
  • Remember non-binary dependencies such as pkg-config, doc generation programs, etc.
    Usually the build process requires some dependencies such as intltool, libtool, pkg-config, doxygen, scrollkeeper, gtk-doc, etc. Make sure those are clearly stated.

LICENSE Invalid

Another common mistake users make when submitting ebuilds is supplying an invalid license. For example, GPL is not a valid license. You need to specify GPL-1 or GPL-2. Same with LGPL. Make sure the license you use in the LICENSE field is something that exists in /usr/portage/licenses. As a tip, check the COPYING in a source tarball for the license. If a package does not specify it uses GPL-1 or GPL-2, it is very likely it uses GPL-2.

If the license for the package you submit is unique and not in /usr/portage/licenses/, then you must submit the new license in a separate file.

Untested ARCHs in KEYWORDS

Please do not add other ARCHs into KEYWORDS unless the ebuild has been tested on that ARCH. Also all new ebuilds should be ~x86 or whatever architecture it is. Make sure when you bump a version, the stable KEYWORDS are all marked as ~.

SLOT missing

Make sure you have the SLOT variable in the ebuild. If you don't plan to use it, don't remove it. Put in:

Code Listing 1.4: Default SLOT variable

SLOT="0"

DESCRIPTION and HOMEPAGE wrong

Please check the if the HOMEPAGE variable is right and leads users to the right page if they want to find out more about the package. And make sure the DESCRIPTION is not overly long. Good descriptions will describe the main function of the package in a sentence.

Wrongfully used spaces instead of TABS

It is no fun reformatting lines of ebuilds because the submitter did not follow the guidelines to use TABS rather than spaces. So please use tabs!

Trailing whitespace

I'm often guilty of this. Remember to run repoman over your ebuilds so it can tell you if there is trailing whitespace at the end of lines or on empty lines.

Adding redundant S=${WORKDIR}/${P}

If S=${WORKDIR}/${P}, then you should not add it to your ebuild. This is implied already, you should only add it if it is something other than ${WORKDIR}/${P}.

Documentation missing

If your package has documentation, make sure you install it using dodoc or in /usr/share/doc/${PF}. Remember to check for errors when running dodoc/doins.

3.b. Common Ebuild Submission Mistakes

Introduction

Please submit ebuilds properly by following the Contributing Ebuild HOWTO on the Gentoo Docs Page.

Tarball'ing an ebuild

Please please please do not attach ebuilds as tarballs. Attach patches separately as well so we can easily examine them.

Inlining Ebuilds

Don't cut and paste an ebuild into bugzilla's comment field.

No description on what the package is

Please let us know what the package is, and fill in the URL with the home page of the application, if any exists.

Package updates without changing the ChangeLog

If you submit a package update, then make sure you explain what changes you made to the ebuild. For example if a package introduces a new features/option and you use a USE flag, list it in your bug. Don't make us hunt for it.

It is wise to submit a diff for a package update rather than the whole ebuild. The best way to generate it would be:

Code Listing 2.1: Creating a diff

$ diff -u some-package-0.1.0.ebuild some-package-0.2.0.ebuild > ~/some-package-0.2.0.diff

Submitting unchanged ebuilds for version bumps

If you are submitting a new version for a package in portage, make sure the existing ebuild works and make sure changes are incorporated in the new ebuild (such as added documentation.) If there are no required changes to the ebuild from the previous version, then don't attach the ebuild. Just say so in the bug report that you copied the ebuild over and verified that the package works and installs properly.

3.c. Comments and Suggestions

Comments, corrections and suggestions should go to Alastair Tse.

4. Gentoo Metadata

4.a. Why the need for metadata.xml?

The metadata.xml file has as its purpose to give extra information about ebuilds. The metadata.xml file should exist in every package directory. A skel file can be found as skel.metadata.xml in the portage tree.

4.b. Metadata Structure

A metadata.xml file can contain a number of tags:

tag description
<pkgmetadata> This is the root element of the metadata.xml file for packages. It has no attributes. Its required subtag is: <herd>. Furthermore, the following subtags are allowed: <email> for a general herd email address, <maintainer>, <longdescription>, <use>, and <upstream>.
<catmetadata> This is the root element of the metadata.xml file for categories as per GLEP 34. It has no attributes. It contains a number of <longdescription> tags, each for a different language.
<herd> There must at least be one herd subtag. The contents of this tag must be the name of a herd as specified in the herds.xml file or the "no-herd" herd. It must occur at least once.
<maintainer> Besides being part of a herd, a package can also be maintained directly. The maintainers of a package can be specified with the <maintainer> tag. This tag has one required subtag: <email>. It has two optional subtags: <name>, and <description>.
<email> This contains the e-mail address of the maintainer. It is required.
<name> This contains freetext with the name of the maintainer. It is optional.
<description> The description tag contains a description of the maintainership, or for example a remark that someone interested can take over the maintainership. It is optional.
<longdescription> This tag contains a description of the package. This is to augment the DESCRIPTION field in the ebuilds themselves. This tag has two optional subtags: <pkg> and <cat>.
<use> This tag contains descriptions of USE flags. This tag is optional and, if specified, has one required subtag: <flag>.
<flag> This tag contains a description of how the named USE flag affects this package. It is required if the <use> tag is specified. It alos requires the USE flag to be named in the name attribute. This tag has two optional subtags: <pkg> and <cat>.
<upstream> This tag contains information about the upstream developers/project.
<maintainer> Name and e-mail of an upstream maintainer. May appear more than once.
<name> The name of an upstream maintainer should contain a block of text with upstream's name. This element is mandatory for an upstream maintainer and must appear only once.
<email> The email address of an upstream may appear only once.
<changelog> Should contain a URL where the location of the upstream changelog can be found. The URL must be version independent and must point to a changelog which is only updated on new releases of the corresponding package. (This also implies that one can link to an automatically updated changelog in case of vcs snapshots only.)
<doc> Should contain a URL where the location of the upstream documentation can be found. The link must not point to any third party documentation and must be version independent. If the documentation is available in more than one language, a lang attribute can be used which follows the same rules as the one for longdescription.
<bugs-to> Should contain a place where bugs can be filed, a URL or an e-mail address prefixed with mailto:.
<remote-id> Should specify a type of package identification tracker and the identification that corresponds to the package in question. remote-id should make it easier to index information such as its Freshmeat ID or its CPAN name.
<pkg> This tag contains a valid package name in the format of a DEPEND.
<cat> This tag contains a valid category name as defined in profiles/categories.

There are also some attributes that can be used with these tags. They are all optional:

attribute tags description
lang <description>, <longdescription>, <use>, <doc> In every case where a description is required, there must be at least an english description. If an additional description in another language is given, this attribute is used to specify the language used. The format is the two-character language code as defined by the ISO-639-1 norm.
restrict <herd>, <maintainer>, <longdescription>, <flag> The restrict attribute allows one to restrict the application of certain tags to certain versions of a package. When this attribute is used, a tag without this attribute must also exist. That tag without the restrict attribute will serve as the default. The format of the restrict attribute is that of the DEPEND flag, except that "<" and ">" need to be specified by &lt; and &gt;.

For example, in the sys-libs/db package, restrict="&gt;=sys-libs/db-3.2.9-r5" on the maintainer tag shows that I'm currently maintaining all versions greater then 3.2.9-r5.
name <flag> This attribute is required on the <flag> tag. It simply contains the USE flag.

For example, in the sys-apps/hal package, <flag name='acpi'> Enables ACPI</flag>
status <maintainer> The upstream maintainer element has a status attribute, which is one of active or inactive. This attribute is not mandatory. The absence of it shall be interpreted as unknown. Please note: This attribute is only allowed in the <upstream> <maintainer> element!
type <remote-id> A string identifying the type of upstream source. A list of valid strings are kept in metadata.dtd. Developers should email the gentoo-dev mailing list before using a new type value.

4.c. Metadata Examples

First Example

In this first example we provide you with the metadata.xml for OpenOffice of which the ebuilds are completely managed by a herd called openoffice:

Code Listing 3.1: Herd-managed package

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
  <herd>openoffice</herd>
  <longdescription>
    OpenOffice is the  opensource version of staroffice.
    This ebuild allows you to compile it yourself. Unfortunately this
    compilation can take up to a day depending on the speed of your
    computer. It will however make a snappier openoffice than the binary
    version.
  </longdescription>
</pkgmetadata>

The openoffice herd is defined in herds.xml by the Gentoo Metastructure Project:

Note: This example may be outdated when you read it. It's just an example!

Code Listing 3.2: OpenOffice Herd Example

<herd>
  <name>openoffice</name>
  <email>openoffice@gentoo.org</email>
  <description>Openoffice related packages</description>
  <maintainer><email>pauldv@gentoo.org</email></maintainer>
  <maintainer><email>suka@gentoo.org</email></maintainer>
</herd>

If you want to add (or remove) yourself from a herd, edit herds.xml located in [gentoo]/xml/htdocs/proj/en/metastructure/herds in Gentoo's CVS repository. Make sure you know the e-mail alias the herd listens to (for instance the "sound" herd has sound@gentoo.org) and add yourself to the alias (by editing /var/mail/alias/misc/<alias name> on dev.gentoo.org).

Second Example

For the second example, we will examine the metadata.xml of app-portage/mirrorselect. This ebuild is maintained by the tools-portage herd, but has a separate maintainer.

Code Listing 3.3: Herd & individually maintained package

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
  <herd>tools-portage</herd>
  <maintainer>
    <email>johnm@gentoo.org</email>
    <name>John Mylchreest</name>
  </maintainer>
  <longdescription>
    This utility is used to select the fastest mirror (distfiles) and provide a
    nicer front-end for mirror selection (both rsync + distfiles) to a user.
  </longdescription>
</pkgmetadata>

Third Example

For the third example, we will describe the metadata.xml of sys-apps/hal. This ebuild is maintained by the gentopia herd and contains USE flag descriptions.

Code Listing 3.4: USE flag descriptions

<?xml version="1.0" encoding="UTF-8">
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<herd>gentopia</herd>
<maintainer>
	<email>compnerd@gentoo.org</email>
</maintainer>
<maintainer>
	<email>steev@gentoo.org</email>
</maintainer>
<use>
	<flag name='acpi'>Enables HAL to attempt to read from
	/proc/acpi/event, if unavailable, HAL will read events from
	<pkg>sys-power/acpid</pkg>. If you need multiple acpi
	readers, ensure acpid is in your default runlevel along with HAL. This
	will also enable HAL to read Toshia and IBM acpi events which do not
	get sent via /proc/acpi/event</flag>
	<flag name='crypt'>Allows HAL to mount volumes that are encrypted using
	LUKS. <pkg>sys-fs/cryptsetup-luks</pkg> which has recently been renamed
	to <pkg>sys-fs/cryptsetup</pkg> allows you to create such encrypted
	volumes. HAL will be able to handle volumes that are removable or
	fixed.</flag>
	<flag name='dell'>Builds an installs the Dell addon, which reads data from
	the Dell SM BIOS via <pkg>sys-libs/libsmbios</pkg>. It will read your
	service tag information and your hardware backlight data as well as
	allow you to modify the backlight settings on a Dell laptop.</flag>
	<flag name='disk-partition'>Allows HAL to use libparted from
	<pkg>sys-apps/parted</pkg> to read raw partition data from your disks
	and process that data. Future versions of HAL (possibly 0.5.11 and
	higher) will allow you to create, modify, delete and format partitions
	from a GUI interface agnostic of your desktop environment.</flag>
	<flag name='doc'>Generates documentation that describes HAL's fdi
	format.</flag>
	<flag name='pcmcia'>Allows HAL to process PCMCIA/CardBus slot data which
	includes inserts and removals and act on these events.</flag>
	<flag name='selinux'>Installs SELinux policies and links HAL to the SELinux
	libraries.</flag>
</use>
</pkgmetadata>

Fourth Example

This example demonstrates the usage of the upstream element:

Code Listing 3.5: Upstream description

<upstream>
        <maintainer status="inactive">
                <name>Foo Bar</name>
                <email>foo@bar.bar</email>
        </maintainer>
        <maintainer status="active">
                <name>Foo Gentoo</name>
                <email>foo@gentoo.org</email>
        </maintainer>
        <changelog>http://foo.bar/changelog.txt</changelog>
        <doc lang="en">http://foo.bar/doc/index.html</doc>
        <doc lang="de">http://foo.bar/doc/index.de.html</doc>
        <bugs-to>https://bugs.foo.bar</bugs-to>
        <remote-id type="freshmeat">foobar</remote-id>
        <remote-id type="sourceforge">foobar</remote-id>
</upstream>

5. Ebuild Maintenance HOWTO

5.a. Introduction

This guide aims to explain common everyday ebuild maintenance routines, as well as other rarer maintenance routines which developers may not be familiar with.

5.b. Adding a new ebuild

When adding a new ebuild, you should only include KEYWORDS for architectures on which you have actually tested the ebuild, confirming that it works as it should and that USE flags are properly honoured in the resulting package which would be installed. If possible, you should give the actual library or application thorough testing as well, since you would be responsible for any breakages for your architecture(s). Minimal testing such as checking that the application starts up without any errors should always be performed.

If you are adding a user-submitted ebuild, do not assume that the submitter has done testing on various architectures: often, KEYWORDS are cloned across packages or generated from documentation in the source packages, which does not signify that the package does indeed work on those architectures.

5.c. Stabilizing ebuilds

Only architecture maintainers for a given architecture should mark packages as stable on that architecture. The maintainer of the package should always be contacted just in case there are reasons not to do so. The exception to this is if you are part of an architecture team, in which case you may mark the package stable for that architecture. If you are not part of an architecture team, you should consult the guidelines below; if the architecture you are looking for is not listed then please consult the relevant lead.

You should never stabilize packages on architectures for which you cannot test and instead you should file a bug to the relevant architecture team, such as sparc@gentoo.org asking them to stabilize the ebuild. Alternatively, you may be able to find Gentoo developers on IRC who could help you with your request.

It is best to not use arch-maintainers@gentoo.org, adding architecture teams onto a bug's CC list individually instead. That way teams can remove themselves from the list when they are done, giving a clear indication of which teams still have to stabilize a package.

5.d. Stabilization rules

SPARC: You must have prior permission from the arch lead (currently Weeve). Usually we expect you to be on the sparc alias for QA reasons, although other arrangements can be made if you will only be working with a small group of packages.

ALPHA: Maintainers may keyword their own packages but are reminded to inform the Alpha team if they can help out with testing and keywording packages so the team can keep an eye out for possible keywording mistakes.

MIPS: You must have prior permission from any senior MIPS developer. Because of the massive range of hardware involved, being on the mips alias and having access to a variety of MIPS systems are generally requirements.

5.e. Upgrading ebuilds

New ebuilds should rarely go in with "arch" keywords and even if they do not, the package must be tested on any architectures listed in the KEYWORDS variable of the new ebuild.

Exceptions to the no "arch" rule are major bug fixes, or security fixes. If the previous version of the ebuild contains KEYWORDS which you cannot test for, you should downgrade them: turn any "arch" keyword to "~arch". If you think that your package may not work at all even on "~arch" then it is best to leave the keyword out and request testing from the relevant team: if you are to do this, you must file a bug to the team in question.

If a new version introduces new dependencies which are not available on some architectures, then you should file a bug or ask on IRC before you upgrade the package. If you really need to get the ebuild added in a hurry, for example, for a security fix, then you should drop any KEYWORDS which are causing problems and CC the relevant architectures on the bug - you should file a new bug to the architecture in question regarding this if no bug is already available.

If there are no new dependencies, do not remove keywords if your commit fails with repoman - please try a full cvs update and if you still have problems, then commit with repoman -I and file a bug to the broken architecture, noting it in your CVS commit message.

Warning: When committing, make sure that you reference any bugs in the ChangeLog as well as the CVS message. Failing to do so is considered to be in very poor taste and may result in disciplinary action.

5.f. Moving ebuilds

Moving ebuilds is a two-step process:

Firstly, you need to move the ebuild in CVS. To do this, you should copy the ebuild to its new location and commit that as you would with a new ebuild.

After this, you should change any ebuilds which DEPEND on the old ebuild to depend on the new one. After this, should add an entry to the latest file in profiles/updates/ in the Portage tree in the in the following format:

Code Listing 6.1: Adding an entry to updates

move net-misc/fwbuilder net-firewall/fwbuilder

This example would transparently move net-misc/fwbuilder to net-firewall/fwbuilder if users have it installed. This way, users would now automatically receive updates for net-firewall/fwbuilder when they are available.

Once this step is concluded, you are allowed to remove the old package. Simply issue a cvs remove -Rf $PN in the package category and commit the changes afterwards with a meaningful commit message.

Code Listing 6.2: Removing a package

net-misc # cvs rm -Rf fwbuilder
cvs remove: use `cvs commit' to remove these files permanently
net-misc # cvs ci -m "Moving net-misc/fwbuilder to net-firewall/fwbuilder."

Note: CVS cannot destroy directories: it will simply not re-create them if they are blank, providing you use CVS with the -P flag.

5.g. Removing ebuilds

When removing an ebuild make sure that no dependencies in Portage are broken due to the removal - additionally, your CVS commit message should explain clearly why the ebuild is being removed from CVS.

If you need to remove ebuilds, make sure you do not accidentally remove the newest/only stable ebuild for any architecture. If you would like to get a newer version marked stable, then please file a bug or ask on IRC.

You should also not cause an unnecessary downgrade for any "~arch" when removing ebuilds - instead, it is best to get the newest version marked "~arch" first and then remove redundant versions of the ebuild.

5.h. Removing a package

When removing an ebuild make sure that no dependencies in Portage are broken due to the removal - additionally, your CVS commit message should explain clearly why the ebuild is being removed from CVS.

In order to remove a package completely from CVS, delete any files from the directory and commit this, CVS will take care of removing empty directories itself.

Code Listing 8.1: Removing a package from CVS

# cd app-admin
# cvs rm -Rf scotty
# cvs ci -m "app-admin/scotty removal (pending 21st July 2006), see #77501 for reference." scotty

5.i. Conflicting files

When you encounter a package that is trying to install files that are already provided by another package (detectable with FEATURES=collision-protect for example) you have to fix this situation before you can commit the ebuild or, if you encounter this with an existing package, file a bug about that package (see below for a few exceptions). The reason file conflicts are critical is because if "foo" provides the file /usr/bin/example and "bar" is going to overwrite it, and later "bar" is unmerged, Portage will remove /usr/bin/example and it is therefore likely it will break "foo".

The most obvious fix is to add a blocking dependency to both packages that want to install that file, so they can't be installed at the same time. But unless there are also other reasons for those packages to block each other you should avoid this if possible and rather fix the package, which could include one or more of the following steps:

  • Make "foo" (R)DEPEND on "bar" and not install the conflicting file.
  • Remove conflicting files from "foo" in src_install or pkg_preinst.
  • Move conflicting files into a new subpackage and make "foo" and "bar" both (R)DEPEND on that package.
  • Change the location where "foo" or "bar" installs conflicting files.

In some cases conflicting files can't be really fixed or aren't critical, currently known exceptions are Perl module manpages (overwriting the ones from Perl itself) and CONFIG_PROTECT'ed files (which should still be fixed, but aren't critical as Portage won't overwrite them).

6. Manifest Signing Guide

6.a. How to sign Manifests?

Requirements:

  • >=sys-apps/portage-2.0.51_pre10
  • >=app-crypt/gnupg-1.2.4

Key Setup:

  • Create a new DSA GnuPG key with at least a 1024 bit keylength, an expiration period no longer than 6 months and a good passphrase.
  • Upload the key to a keyserver.

Portage Configuration:

  • Set PORTAGE_GPG_DIR to your ~/.gnupg/ directory (or the directory where the keyring with your new key is).
  • Set PORTAGE_GPG_KEY to the key id of your new key.
  • Set FEATURES="sign".

Now you should be able to sign your Manifests on repoman commit. Repoman will ask you for your passphrase before committing the Manifest. This step is after it has committed the other files. At the moment repoman doesn't check if the Manifest is already signed, so others are able to "unsign" your package later. This will change before signing is made mandatory.

C. Policies

1. Ebuild policy

1.a. General guidelines

Here are some general development guidelines to follow:

  • Always check in your changes with repoman; use repoman commit instead of cvs commit.
  • If a package is either broken in its current version or it has a really nasty build/install process, take a look at how other distributions do it:
  • Your package, when complete and unmasked, is supposed to "just work" for the end-user. Tweaking the installed product to get it to work should be optional; thus you need to install the package with reasonable default settings.
  • Don't be afraid to consult our on-line documentation and ebuilds written and maintained by more senior developers. Feel free to contact senior developers directly with any technical or policy questions.
  • Be cautious about what you commit. Remember that your commits can potentially harm thousands of users. If your commits cause any breakage in the tree, they must be fixed in a timely fashion.
  • Every package must be accompanied by a metadata.xml file which lists - amongst other information - what herd (and/or individual maintainers) are in charge of the package.

1.b. Specific guidelines

fPIC

On some architectures, shared libraries must be built with -fPIC. On x86 and others, shared libraries may build without -fPIC. This can be wasteful and potentially cause a performance hit. If you encounter a package that is not building shared libraries with -fPIC, patch the Makefile to build only the shared libraries with -fPIC. More information on PIC is available at http://www.gentoo.org/proj/en/hardened/pic-internals.xml. If you are unsure, please ask in a public developer forum (like the gentoo-dev mailing list or #gentoo-dev irc channel) for help.

Perl

New Perl modules are to be added to portage only when one of the following conditions is met:

  • The module(s) fulfill a dependency
  • The module(s) cannot be handled by g-cpan
  • The module(s) add functionality to existing ebuilds
  • The module(s) provide tools, applications or other features (i.e. more than what their .PM offers)

Please make sure that at least one member of the perl herders approves your addition.

1.c. Ebuild policy

Naming policy

Ebuild file names consist of four logical subsections:

pkg-ver{_suf{#}}{-r#}.ebuild

Note: The brackets ({}) delineate optional fields and do not appear in the literal package name. # represents any non-zero positive integer.

The first subsection, pkg, is the package name, which should only contain lowercase letters, the digits 0-9, and any number of single hyphen (-), underscore (_) or plus (+) characters. Examples: util-linux, sysklogd and gtk+. We have some packages in Portage that don't follow these rules, but your packages should.

The second subsection, ver, is the version of the package, which should normally be same as the version on the main source tarball. The version is normally made up of two or three (or more) numbers separated by periods, such as 1.2 or 4.5.2, and may have a single letter immediately following the last digit; e.g., 1.4b or 2.6h. The package version is joined to the package name with a hyphen. Examples: foo-1.0, bar-2.4.6.

The third subsection, {_suf{#}}, is optional may contain one of these predefined suffixes, listed in least-recent to most-recent order:

Suffix Meaning
_alpha Alpha release
_beta Beta release
_pre Prerelease
_rc Release candidate
(none) Normal release
_p Patch level (normally accompanied by trailing integer)

Any of these suffixes may be immediately followed by a non-zero positive integer, e.g., linux-2.4.0_pre10. Assuming identical version parts, the suffixes are ordered as follows (lower means older): _alpha < _beta < _pre < _rc < (no suffix) < _p.

When comparing identical suffixes with trailing integers, the one with the larger integer will be considered most recent. Example: foo-1.0_alpha4 is more recent than foo-1.0_alpha3.

The fourth subsection of the package name is the Gentoo Linux-specific revision number ({-r#}). This subsection, like the suffix, is also optional. # is a non-zero positive integer; e.g., package-4.5.3-r3.

This revision number is independent of the version of the source tarball and is used to inform people that a new and improved Gentoo Linux revision of a particular package is available. Initial releases of ebuilds must have no revision number; e.g., package-4.5.3 and are considered by Portage to have a revision number of zero. This means that counting goes as follows: 1.0 (initial version), 1.0-r1, 1.0-r2, etc.

Versioning and revision bumps

Package revision numbers should be incremented by Gentoo Linux developers when the ebuild has changed to the point where users would want to upgrade. Typically, this is the case when fixes are made to an ebuild that affect the resultant installed files, but the ebuild uses the same source tarball as the previous release. If you make an internal, stylistic change to the ebuild that does not change any of the installed files, then there is no need to bump the revision number. Likewise, if you fix a compilation problem in the ebuild that was affecting some users, there is no need to bump the revision number, since those for whom it worked perfectly would see no benefit in installing a new revision, and those who experienced the problem do not have the package installed (since compilation failed) and thus have no need for the new revision number to force an upgrade. A revision bump is also not necessary if a minority of users will be affected and the package has a nontrivial average compilation time; use your best judgement in these circumstances.

Important: Whenever you create a new revision of an ebuild, be sure to update the ChangeLog file in the ebuild directory. Failing to do so is considered to be in very poor taste and may result in disciplinary action.

Ebuilds should be based on the previous version of the ebuild to ensure that fixes aren't dropped accidentally. Fixes should include appropriate comments in the ebuild explaining what they are for and why they are needed. If you are not familiar with the fixes, or unable to determine if they are still needed, you should not be updating the ebuild.

Virtuals

Portage supports a concept called "virtual" packages. Using virtual packages, it is possible to have a particular category/package name map to another.

Here's an example of how to use virtual packages. Let's say you create a new cron package called foocron. Gentoo Linux is currently set up so that things that need a cron package of some kind depend on the virtual/cron package. This allows ebuilds to ensure that there is some kind of cron available while allowing users the flexibility to install the cron package that they prefer. To plug your foocron-1.0.ebuild into this system, you'd add a line to the ebuild that reads:

Code Listing 3.1: How to provide a virtual

PROVIDE="virtual/cron"

Now, when foocron-1.0 is installed, the virtual/cron package will be registered. If you didn't have any cron package installed before, this would mean that any package DEPENDing on virtual/cron would have that dependency fully satisfied. Note that it is advised to only specify a PROVIDE value for defined virtuals (see /etc/make.profile/virtuals). Also please note that (a) PROVIDE isn't to handle renaming of packages and (b) don't use it with new style virtuals.

There is a second component to the Gentoo Linux virtuals implementation. What would happen if there were no installed package that provided virtual/cron? How would Portage choose the "correct" cron to install to satisfy the virtual/cron dependency? Portage takes care of this situation by using a profile-specific virtual mapping file called virtuals which is stored in the profile directory /etc/make.profile. If you take a look at your virtuals file, you'll find that the contents look something like this:

Code Listing 3.2: Sample virtuals file

virtual/lpr             net-print/cups
virtual/python          dev-lang/python
virtual/mta             net-mail/ssmtp

The first line of this file tells Portage that if a package depends on virtual/lpr and no virtual/lpr is installed and no virtual/lpr package is available in the Portage tree, then net-print/cups should be installed to satisfy this dependency. net-print/cups contains a line that reads PROVIDE="virtual/lpr" so that future dependencies on virtual/lpr will be satisfied.

Now for the developer guidelines. If you were to add the foocron package, you would obviously want to ensure that all programs that depend upon virtual/cron are able to work correctly with it. And if you were to add a package named foobarosity that depended on virtual/cron, you should likewise ensure that all packages that provide virtual/cron will be satisfactory for the proper functioning of foobarosity.

Before creating new virtual packages, please begin a discussion on the internal developer mailing list about that virtual. Keeping developers informed of new virtuals is essential to ensure their uniform use.

Scope

Whenever an ebuild is sourced, the functions and variables within it are loaded into memory by the script interpreter. However, only variables and instructions that are not part of a function are interpreted - functions such as src_compile() are only executed by Portage when the ebuild has reached the compile stage.

The code within these functions are considered in "local scope" while everything outside of the functions is in the "global scope" meaning they are executed every time the ebuild is sourced.

An external application (such as grep, sed or awk) should never be called in global scope for performance reasons, and alternatives such as using built-in bash replacement should be used instead. Useful alternatives can be found in the Advanced Bash Scripting Guide.

Additionally, any external application that may be called in global scope can not be guaranteed to exist on the system. If the command is placed in local scope (for example, in the pkg_setup() function), we can guarantee its presence by placing it in the ebuild's ${DEPEND}.

CVS sources policy

There are two different ways to build an ebuild based on sources from a CVS development tree. The first and traditional way is to create a "CVS snapshot" ebuild by creating your own tarball snapshot of the upstream CVS tree, mirroring the sources on our official distfile repository, and writing an ebuild to specifically use this tarball snapshot. These types of CVS ebuilds will be referred to as "CVS snapshot ebuilds" below.

The other method of creating a CVS-based ebuild is to use cvs.eclass to create a "live" CVS ebuild. Such an ebuild will dynamically grab the latest development sources from a CVS repository at "fetch" time, ensuring that the sources are as up-to-date as possible. These types of CVS ebuilds will be referred to as "'live' ebuilds" below.

The following paragraphs detail the policy relating to the use of CVS-based ebuilds. Note that there are strict rules relating to the addition of such ebuilds to the Portage tree.

Snapshot cvs ebuilds are greatly preferred over "live" cvs.eclass cvs ebuilds.

Snapshot cvs ebuilds are allowed if a cvs snapshot contains known fixes that are needed for proper operation of a software package, or if the cvs version of a particular software package is known to or has been proven to simply "work better" than the normal release version.

"Live" cvs.eclass ebuilds are generally only intended for the convenience of developers and should always be masked with a ~[arch] keyword. It is impossible to guarantee the reliability of a "live" cvs.eclass ebuild since the upstream cvs tree may change at any time, which is why they should always be masked.

Whether a "live" CVS ebuild or a "snapshot" CVS ebuild, you the developer are responsible for ensuring that the ebuild works correctly. This is particularly difficult to do with "live" cvs ebuilds for obvious reasons.

If ebuilds (of any kind) do not work correctly or are flaky, they should be fixed or removed from the Portage tree. If they are "live" ebuilds, they may be ~[arch] keyword masked for their lifetime (this special exception is detailed below).

If a user or users specifically request a "live" cvs ebuild, you can add one for them. It should have a ~[arch] keyword so that other users don't merge it unsuspectingly.

This way, the user(s) requesting them (likely developers) can install them but other users will be protected from merging them accidentally. Again, this only applies to situations where a user or users specifically request a "live" cvs.eclass CVS ebuild. Snapshot ebuilds should only be added to the Portage tree with the intention that they are stable and provide better functionality than the normal release versions of said software.

Important: Snapshot ebuilds of pre-release CVS sources should be named as follows: foo-x.y_preYYYYMMDD.ebuild. foo is the package name, x.y is the version number of the upcoming release, _pre is a literal string, and YYYYMMDD is a timestamp of the day the CVS snapshot was taken. Use this naming convention to ensure that a x.y.1 release version won't be considered to be older than a x.y snapshot, while at the same time ensuring that the official x.y release will be considered newer than your CVS snapshot version. For CVS snapshots of already-released CVS sources, use the format foo-x.y_pYYYYMMDD.ebuild (notice the _p for "patchlevel.") This will ensure that your CVS ebuild will be considered newer than the standard x.y release.

Important: Currently, the policy for naming "live" cvs ebuilds is to ensure that the package name ends with -cvs. In the future, a _cvs version suffix will likely be added to Portage and this policy will be updated.

User-submitted ebuilds

User-submitted ebuilds should never be blindly trusted and should always be well-tested and audited before being committed to CVS. If a user-submitted ebuild has problems, you will be held accountable. By committing it to CVS, you are vouching that the ebuild meets all Gentoo Linux development standards.

Make sure that the user-submitted ebuild doesn't contain custom headers like this:

Code Listing 3.3: A custom header that should be transferred to the ChangeLog

# Ebuild updated by: me <me@me.com>

This information should be added to the ChangeLog using proper ChangeLog comment syntax. Always ensure that the ChangeLog gives proper credit to the user who submitted the ebuild. This information should appear in the first ChangeLog entry.

Also ensure that any new ebuilds you commit contain the following line:

Code Listing 3.4: Ebuild header

# $Header: $

Quite a few user-submitted ebuilds are based on files from rsync, which can contain incorrect header lines.

Encourage users to submit diffs to existing ebuilds if they are submitting an upgrade. By doing this, we can help avoid the re-introduction of previously-fixed bugs into our "new" ebuilds. If you are not working from a user-submitted diff but a complete ebuild, then use the diff command to see what has changed, keeping an eye open for anything from our current ebuild that should appear in the new ebuild, or anything in the new ebuild that should be fixed or removed.

In general, let the user do the work required to get his or her ebuild up to par, unless you want to clean up the ebuild on his or her behalf. Even so, it's often better to have the user do the work so that they can learn from their mistakes and submit cleaner ebuilds in the future. Be sure to be thankful for any submission, even if it isn't very good. Be polite but honest -- if an ebuild isn't usable, the user can be told in a way that does not insult their current ebuild-writing abilities. Remember that the user who submitted that broken ebuild may be a skilled and productive member of our project in the future -- that is, if they receive the right amount of encouragement and support and continue to improve in their abilities.

1.d. QA policy

Portage / baselayout release policy

Only members of the Portage team (who know who they are) have the authority to release new releases of Portage. No one else is allowed to roll new releases of Portage.

Only members of the baselayout team (who know who they are) have the authority to release new releases of baselayout. No one else is allowed to roll new releases of baselayout.

Masked packages

/usr/portage/profiles/package.mask contains a list of packages that should not be merged by users and comments detailing the specific reason why. Package.mask is used to prevent merging of packages that are broken, break something else, or badly need testing before going into ~ARCH KEYWORDS in the tree. When adding to package.mask, always commit package.mask prior to committing the masked ebuild. This prevents the ebuild from hitting users before the updated package.mask does.

Great care must be taken any time a package is removed from package.mask. Keep in mind that if an ebuild is in package.mask, it's there for a reason. If you didn't mask the ebuild, always contact the developer listed in the package.mask comments prior to taking any action. Additionally, if the masked ebuild is a core package, a dependency of a core package, or the unmasking has any possibility for adverse effects, the change must be discussed internally on the developer mailing list.

~ARCH in KEYWORDS

The purpose of ~arch is for testing new packages added to Portage.

There is a difference between using package.mask and ~arch for ebuilds. The use of ~arch denotes an ebuild requires testing. The use of package.mask denotes that the application or library itself is deemed unstable. For example, if gimp-1.2.0 is the stable release from Gimp developers, and a new bug fix release is available as 1.2.1, then a developer should mark the ebuild as ~arch for testing in portage because the release is deemed to be stable. In another example, if Gimp decides to release an unstable/development series marked as 1.3.0, then these ebuilds should be put in package.mask because the software itself is of development quality and is not recommended by the developers for distribution.

Any new package that enters Portage must be marked ~arch for the architecture(s) that this version is known to work on. The developer who commits the ebuild must verify it is in working order, and the KEYWORDS are correct.

Moving package versions from ~ARCH to ARCH

When a package version has proved stable for sufficient time and the Gentoo maintainer of the package is confident that the upgrade will not break a regular Gentoo user's machine, then it can be moved from ~ARCH to ARCH. An indication of the package's stability would be no verified or unresolved bug report for a month after the version's introduction.

It is up to the maintainer of the package to deem which versions are stable or if development versions should be in package.mask or left in ~arch.

You must also ensure that all the dependencies of such a package version are also in ARCH.

Important: Remember that arch teams alone are responsible for marking packages stable on their arch. Package maintainers should open stabilization bugs; they may not just mark packages stable. However, if the maintainer is also part of an arch team, then he or she may stabilize the package for his or her arch.

Warning: The ~ARCH step may only be ignored if and only if the concerned package version contains a security fix or is needed to fix an important bug in the Gentoo system.

1.e. Variables

Required variables

Gentoo Linux policy requires that all ebuilds contain KEYWORDS, LICENSE, and SLOT variables. HOMEPAGE, SRC_URI and DESCRIPTION should also be included except for special circumstances. DEPEND (and if necessary, RDEPEND) should be included if your package has any build or runtime dependencies, respectively.

DEPEND and RDEPEND

Use DEPEND to define the dependencies required for building a particular package, and set RDEPEND to the dependencies required to run a particular package. RDEPEND should be set explicitly, even if RDEPEND=${DEPEND}.

Code Listing 5.1: Example of RDEPEND

RDEPEND="${DEPEND}
	net-ftp/curl"

It's also important to note that only RDEPEND dependencies are satisfied when one installs a binary .tbz2 package; use this information to help you choose the correct RDEPEND dependencies.

A package should depend upon the oldest version that satisfies the dependency. If it works with libfoo-1.2.x, don't depend on libfoo-2.x just because that's what you have installed.

In general, packages should depend on =libfoo-1.2* instead of >=libfoo-1.2. Otherwise, things may start breaking horribly when libfoo-2.0 is introduced.

Depending on a virtual package entry like virtual/foo will only work when the different packages providing virtual/foo have identical interfaces. Consider virtual/jdk-1.3 for example. Some packages don't work with ibm-jdk-1.3 while they do work with sun-jdk-1.3. For this reason, be sure that your package is tested against all virtual providers before unmasking. It may be possible to only depend on a subset of those packages in the virtual rather than the virtual itself.

2. Etiquette policy

2.a. Introduction and some simple suggestions

These suggestions are designed to be an easy-to-follow guide to what Developer Relations would expect to be good developer etiquette. They should cover most areas and should be employed wherever they can be.

That doesn't mean that we expect you to follow this guide to the bullet point; nor do we expect you even agree with it - we do expect, however that all developers maintain reasonable standards of behaviour with our community - whether to other developers or users. However, you may be subject to sanctions or a suspension if a reasonable standard is not met.

By reasonable standards we don't want you to feel that we are not allowing you to say anything, rather, we believe that how you say it, and the method and professionalism in how you express your opinion defines whether you meet the reasonable standards or not, since, as a developer, what you say and do reflects upon Gentoo and the project as a whole. We just require you to be equally respectful to developers and users alike, and to value the opinion of everybody - even if you think it's totally wrong.

You should try to use good spelling and grammar everywhere: whether in a CVS commit message, a ChangeLog, or even on IRC if you want to be really nice and make somebody's day. But don't worry; we won't really mind if you don't. You might not notice it, but by taking some effort to clean things up, the amount of time it takes to read your sentences is greatly lowered. However, it is also important not to lose the rope at the same time and make something too eloquent that takes too long to parse.

2.b. What you should try not to do

One should try to not be rude, abusive or impolite under any circumstances. Sometimes, just one sarcastic comment can change the tone to the reader. If you think you might give somebody a bad as a result of your comment, and if you really need to say it, make sure people understand that you are not trying to be offensive.

Please remember that you are an official representative of Gentoo. In this capacity, you are expected to maintain a certain level of professionalism and courtesy in your day-to-day interactions with users and other developers.

2.c. Tips

ChangeLogs

  • Make your ChangeLogs readable to the average end-user: try to keep things simple and short if you can, but provide any critical information as needed. Remember that ChangeLogs need to be written in good, "correct" English even if they are short. Punctuation is essential.
  • Please don't use "Gentooified" language, except for accepted terms such as "ebuild" and "version bump". If you are being verbose, please use the correct punctuation and quote marks.
  • Any function names should be encapsulated in quotation marks or speech marks.
  • Be verbose: "Version bump." is good, however "Version bump; see bug #..." is even better. This not only helps users, but it also helps other developers as well.
  • Don't use phrases such as "Tested for months, should work." or "I think this should fix the problems." as something either does its job or it doesn't. It is much better to inform users to test your package thoroughly and to report any bugs to you.
  • When referring to ebuild sections such as the homepage variable, use "HOMEPAGE" remembering to add the quotes and to use the correct case. This makes things a bit more precise, namely telling the reader that you changed the variable; rather than the homepage your package might go to when it starts up, for example.
  • When using acronyms, please use the proper cases. For example, "ALSA", not "alsa", "Win4Lin" not "win4lin".

Ebuilds

  • Try to not bump ebuilds continuously unless there really is a benefit or a security fix which is important. Unnecessary examples of bumping include:
    • You change minor spelling errors in script file comments, script file indentation or something similar.
    • You patch a non-kernel ebuild to support a new kernel version (or a new version of a library), allowing more users to install your ebuild, but not changing anything for existing users of the current revision.
    As a general rule, fixes with non-trivial changes to any of the installed files of any ebuild warrant a revision bump. Put differently: If your fix changes the behaviour for existing users, you bump so that they know they can upgrade. See ebuild policy for more details.
  • Respect developers' coding preferences. Unnecessarily changing the syntax of an ebuild increases the load on the CVS server and can cause complications for others. Syntax changes should only be done if there is a real benefit, such as faster compilation, improved information for the end user, or compliance to Gentoo policies.

IRC

  • Be nice and respectful of everybody - even if they are bombarding you with messages.
  • Do not abuse or discriminate users or developers - whether as a joke or as sarcasm.
  • Answer any questions to the best of your knowledge - it is best that you do not answer what you don't know to avoid confusion. There is no policy on any collateral damage caused by developers to users however: if the developer did any contact such as SSHing into a users' box, the developer would be held accountable for any issues arising out of the same. As a result, we don't really recommend it.
  • If you are a developer with operator powers, you must not abuse them - if you have a disagreement with a user resolve the issue peacefully and do not resort to kicking them or even kickbanning them unless the situation is really severe and other developers approve of critical measures.
  • #gentoo and #gentoo-dev are clean-language channels; other #gentoo- channels have policies set by their respective channel owners. Because the majority of traffic on #gentoo-dev is from Gentoo developers, people perceive this channel as officially representing Gentoo. In order for us to present Gentoo in a professional manner, we request that developers keep #gentoo-dev a 'clean-language' channel.

Forums

  • Be nice and respectful of everybody - even if they are asking the most unimaginable questions. Either voice your opinion courteously, or voice no opinion.
  • Follow the forum rules and try keeping to the discussion rather than veering off course.
  • Try to be active in development. If users are asking why something was added, please explain it. If users are asking why something is missing, explain that. Use your knowledge and help out if you can. At the same time, if you don't know, don't confuse people.

Mail

  • Be nice and respectful of everybody. Don't respond to personal attacks with more attacks. Either voice your opinion courteously, or voice no opinion.
  • Don't use HTML mail - it can cause annoyances - and it is recommended that you use a word-wrapping mail client if sending out plain text messages. Some people also block HTML mail which may cause correspondence problems.
  • When replying to user or developer mail, be both courteous and don't simply refer the user along to another developer - try to explain why things are as they are if you can. An example of good, well thought reply goes along the lines of: "I am referring you to <insert name here> as <person> is now the maintainer of the package. Any further issues should be addressed to <person>. Sorry for any inconvenience."

Print

Updated October 16, 2009

Summary: This is the Gentoo Developer Handbook, a continuing effort to centralize development policies across Gentoo and to also outline Gentoo's development systems and procedures.

Sven Vermeulen
Author

Seemant Kulleen
Author

Shyam Mani
Author

Karl Trygve Kalleberg
Author

Mike Frysinger
Author

Alastair Tse
Author

Paul De Vrieze
Author

Nicholas D. Wolfwood
Author

Marius Mauch
Author

Daniel Black
Author

Wernfried Haas
Author

Chrissy Fullam
Author

Łukasz Damentko
Author

Daniel Robbins (Retired)
Author

John P. Davis (Retired)
Author

Tim Yamin (Retired)
Author

Jorge Paulo (Retired)
Author

Zack Gilburd (Retired)
Author

Benny Chuang (Retired)
Author

Erwin (Retired)
Author

Jon Portnoy (Retired)
Author

Carl Anderson (Retired)
Author

Donny Davies (Retired)
Author

Peter Gavin (Retired)
Author

Dan Armak (Retired)
Author

Owen Stampflee
Author

Ciaran McCreesh (Retired)
Author

Donate to support our development efforts.

Support OSL
Gentoo Centric Hosting: vr.org
Tek Alchemy
SevenL.net
Global Netoptex Inc.
Bytemark
Online Kredit Index
Copyright 2001-2009 Gentoo Foundation, Inc. Questions, Comments? Contact us.