Recently I have written (and submitted to the Gentoo bugzilla) a few ebuilds that I think were lacking in the portage tree and decided to write a small post to encourage others to do so as well. Namely the net-im/kopete-antispam (Antispam plugin for Kopete 3.x), app-pda/libopensync-plugin-moto (Motorola plugin for OpenSync) and games-action/wordwarvi (awesome retro-style scrolling shoot'em up).

If you were (like me) afraid of all the headers and variables needed to even start – fear not! There is a nice little trick to make you start easier.

I will demonstrate just how easy it is to write a basic ebuild based on my experience with net-im/kopete-antispam.

First tip is to not to work directly on your local overlay, but have a separate directory in your home to play with (e.g. ~/Code/ebuilds/) and then move what works to the overlay (e.g. /usr/local/portage/). This way you can avoid running a buggy system.

The next few steps are quite self-explanatory:

cd ~/Code/ebuilds
mkdir -p net-im/kopete-antispam
vim net-im/kopete-antispam/kopete-antispam-0.3.ebuild

In the last line lies another trick – if you start Vim with trailing $GROUP/$PACKAGE/$EBUILD it will automatically apply not only the generic ebuild template (with the appropriate KEYWORDS="" entry), but also inherit the appropriate eclasses (e.g. the 'games' eclass when writing ebuilds that fit under games-* groups).

In our example this is what Vim generates:

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

DESCRIPTION=""
HOMEPAGE=""
SRC_URI=""

LICENSE=""
SLOT="0"
KEYWORDS="~amd64"
IUSE=""

DEPEND=""
RDEPEND=""

What we need to add now is basic information like the description, homepage, its USE flags, dependancies and so on. As you can see when downloading from SourceForge you can use the elegant mirror:// protocol to include all SF.net mirrors.

In our case we need no special USE flags (except those that come with the 'kde' eclass). But the package does depend on Kopete being installed either from the monolithic or the atomic KDE ebuilds on which the package depends both on compiling ($DEPEND) and on running ($RDEPEND)

Also note that since this is a KDE3 application (or actually plugin) we will inherit the 'kde' eclass and add the 'need-kde 3'.

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

inherit kde

DESCRIPTION="This plugin enables anti-spam properties in the KDE instant messenger Kopete."
HOMEPAGE="http://kopeteantispam.sourceforge.net"
SRC_URI="mirror://sourceforge/kopeteantispam/${P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""

DEPEND="|| ( =kde-base/kdenetwork-3.5* =kde-base/kopete-3.5* )"
RDEPEND="${DEPEND}"

need-kde 3

The above ebuild is already usable, but to make it even cleaner and more practical, we can tweak it a bit.

One thing that you might notice is that when you inherit the 'kde' class you currently automatically get 'arts' (amongst others) in the package's USE flags. Since the Kopete Antispam plugin has no need whatsoever for sound, we can safely remove the 'arts' USE flag.

Also the RDEPEND variable by default replicates the DEPEND, so it is cleaner (and desired) to just omit it when they are identical.

And while we are at it, we might as well add a nice message for the user to know how to enable the plugin. This can be easily done with the pkg_postinst() function.

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

ARTS_REQUIRED="never"
inherit kde

DESCRIPTION="This plugin enables simple anti-spam properties in the KDE instant messenger Kopete."
HOMEPAGE="http://kopeteantispam.sourceforge.net"
SRC_URI="mirror://sourceforge/kopeteantispam/${P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""

DEPEND="|| ( =kde-base/kopete-3.5* =kde-base/kdenetwork-3.5* )"

need-kde 3.5

pkg_postinst() {
    elog "You can now enable and set up the Antispam plugin in Kopete."
    elog "It can be reached in the Kopete Plugin dialog."
}

Of course this is a quite simple ebuild without any needed patching to the Makefile or source or other complications (e.g. non-standard uncompressing, compiling etc.). But there are a lot of packages out there that need nothing more then someone to write such a small ebuild for them and to maintain it. So be a sport and adopt an ebuild!

Further reading: Gentoo official ebuild writing manual FlameEyes' post on when to use DEPEND and when RDEPEND /usr/portage/eclass/* for which functions and variables each eclass introduces

Updates:

  • added the .ebuild extention which I initially forgot
  • changed mkdirhier to mkdir -p, because it is more common (thank you, John Alberts) _

Share on: TwitterFacebookEmail


Related Posts


Published

Category

Tehne

Tags

Stay in Touch