Common mistakes

This section contains information on the common mistakes developers make when writing ebuilds.

Common ebuild writing mistakes

Unguarded external calls

Calls to external tools should be guarded with || die (or use assert) in almost all cases to allow failure to be detected. See Error handling.

Invalid use of static USE flag

The static use-flag should only be used to make a binary use static linking instead of dynamic linking. It should not be used to make a library install static libraries. Instead, the static-libs use-flag is used for this.

Invalid use of ROOT

The usage of ROOT is only designed to influence the way the package is installed (ie. into ROOT) — building and compiling should not depend on ROOT. As a consequence of this, the usage of ROOT in src_* functions is not allowed. pkgcheck can now detect some such cases via its MisplacedVariable check. See bug 775191 for more information.

See also ROOT.

Referencing the full path to documentation files that could be compressed

When printing out to the users where to find files like INSTALL, do not specify the full path since PORTAGE_COMPRESS comes into play. The file could be compressed with gzip, bzip2, or some other random compression tool. So, instead of doing this:

elog "They are listed in /usr/share/doc/${PF}/INSTALL.gz"

Do something like:

elog "They are listed in the INSTALL file in /usr/share/doc/${PF}"

Build log not verbose

When writing ebuilds, you should always check the build log, because the build system might ignore CC/CXX/LD/CFLAGS/LDFLAGS and such or add undesired flags by default. In order to analyze this and have complete information, in case someone reports a bug for your package, the build log must always be verbose.

There are several ways to fix non-verbose build logs depending on the build system:

  • For cmake-based build systems, it should be sufficient that the ebuild calls cmake_src_compile which picks up the cmake.eclass variable CMAKE_VERBOSE=1 by default. If you call emake directly for whatever reason, you can do emake VERBOSE=1 (note that 'cmake_src_compile' takes arguments as well which are passed to make).
  • For autotools based build systems, econf automatically passes '--disable-silent-rules' to ./configure. If necessary, emake V=1 should also work. Note that V=1 is not a universal parameter so may not always work.
  • For custom Makefiles, you often have to write a patch. Try to get upstream to include an option like 'V=1' to enable full verbosity.
  • Note that when building Go manually outside of the eclass, you will need GOFLAGS="-x".

-Werror compiler flag not removed

"-Werror" is a flag which turns all warnings into errors and thus will abort compiling if any warning is encountered. See bug 260867 for more information and real-life examples/fixes in the Gentoo tree.

Rationale

This flag is not recommended for releases and should always be disabled when encountered in build logs, because there are numerous cases where this breaks without purpose, e.g.:

  • new warnings on version bumps of GCC/glibc of which the developer was not aware at the point of coding
  • some autoconf checks will fail badly
  • libraries adding deprecated API warnings although that API is still working/supported
  • on less known architectures we may get different/more warnings than on common ones
  • random breakage depending on what distro/architecture/library version/kernel/userland the developer was testing "-Werror" on

By turning off "-Werror", we will still see the warnings, but there is no reason that they cause compile failure. Note that Portage already emits QA notices about GCC warnings that can cause runtime breakage.

How to fix

To fix the affected build system you should try the following methods:

  • remove the compiler flag from the build system, e.g. Makefile.am or configure.ac or even provide a switch (for autotools based build systems that could be "--disable-werror", which is good for sending a patch upstream)
  • use append-flags -Wno-error (needs flag-o-matic.eclass); for this to work the environment flags have to be respected and placed after build system flags; this method is not preferred as it will disable all "-Werror=specific-warning" flags as well, see next section

Always check that it's really gone in the build log.

Specific -Werror=... flags

The compiler (e.g. GCC) can turn any specific warning into an error. A specific -Werror flag would be "-Werror=implicit-function-declaration" for example and will only affect warnings about implicit function declarations. It's mostly safe to leave these untouched, because they are pinned to this issue and should not cause random build-time breakage. Also, we can expect that upstream did this on purpose to avoid known runtime errors and not just for testing their builds. However, you should check the specified warnings yourself or ask other developers if unsure.

Exceptions

Removing "-Werror" from configure.ac can cause breakage in very rare cases where the configure phase relies on the exit code. See app-emulation/open-vm-tools bug. But even then we remove it from the resulting Makefile.

Missing/invalid/broken header

When you submit your ebuilds, the header must be exactly the same as the one in skel.ebuild.

The first two lines must look like this:

# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

Redefined P, PV, PN, PF variables

You should never redefine those variables. Always use MY_P, MY_PN, MY_PV, 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. For example dev-python/pyopenal fetches a tarball called PyOpenAL, so we redefine it like:

MY_P=${P/pyopenal/PyOpenAL}
SRC_URI="http://download.gna.org/pyopenal/${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, usually in BDEPEND.

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 the licenses directory. 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 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 ~.

Unused flags and eclass inherits

Sometimes obsolete USE flags remain in IUSE despite having no function, e.g. a dependency may have become mandatory but the USE flag remains in IUSE and *DEPEND. Similarly, eclasses often become redundant due to changes in the ebuild, or new EAPIs, e.g. eutils.eclass should be obsolete in modern EAPIs. Remember to prune these.

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:

SLOT="0"

DESCRIPTION and HOMEPAGE wrong

Make sure the DESCRIPTION is not overly long. Good descriptions will describe the main function of the package in a sentence.

Please check if the HOMEPAGE variable is right and leads users to the right page if they want to find out more about the package. If no homepage for the package is available, set the HOMEPAGE variable to https://wiki.gentoo.org/wiki/No_homepage. Please also strive to test HTTPS support for the site used in HOMEPAGE.

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

Remember to run pkgcheck 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.

If the package documentation is large or requires additional dependencies to build, you should make it optional with the doc USE flag. If the documentation is small and does not require additional dependencies (e.g. README files), install it unconditionally.

Masking unsupported/broken USE flags

Exceptionally, a package may have an unsupported/broken USE flag (this can happen with vanilla or custom-cflags). Then the USE flag must be masked for that ebuild (usually in profiles/base/package.use.mask), at least when the ebuild hits the stable branch.

Not using latest EAPI

Often, user-submitted ebuilds do not use the latest EAPI and may even be several versions behind. EAPIs bring new helper functions and improved methods for completing common tasks. It's recommended that submitted ebuilds use the latest EAPI possible (subject to eclass constraints) to improve the ebuild's quality and ease review.

Calling pkg-config directly

You should not call pkg-config directly in ebuilds because this is problematic for e.g. cross-compiling. The correct helper respects ${PKG_CONFIG}. Instead, use tc-getPKG_CONFIG from toolchain-funcs.eclass, e.g.

sed -i -e "s:-lncurses:$($(tc-getPKG_CONFIG) --libs ncurses):" || die

Don't then forget to add virtual/pkgconfig to BDEPEND!

Common ebuild submission mistakes

Introduction

Please submit ebuilds properly by following the Adding a new ebuild tutorial.

Tarballing an ebuild

Please do not attach ebuilds or patches as tarballs. It avoids extra operations when reviewing.

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 explaining what has changed

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:

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

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.