Gentoo USE flags

Posted on Wed 02 July 2008 in geek

I run three distributions most of the time. My servers all run Debian which despite recent cock-ups is a stable, unsurprising distribution. Exactly what you want from a server OS. My work desktop runs Ubuntu which is regularly updated, runs pretty much the latest Gnome, Firefox etc and is simple to administer. However for the last 3 and a bit years I've been running Gentoo on my desktop at home. When I recently upgraded my desktop machine I considered other options but decided to stick to Gentoo for the main reason it is incredibly flexible.

Gentoo is a source based distribution. This means instead of downloading binary packages with pre-compiled images it downloads source code and compiles it on your machine before installing it. This has many benefits, none of which involve running silly compiler optimisations to get an extra 2% performance out of the applications. However for a developer there it is inherently useful to have all the headers for your libraries by default - and by implication every package you compile is linked against the right library. The result of this is it's very easy to run bleeding edge applications alongside a stable base system, something that quite often doesn't work with a binary distributions which make assumptions about what is actually installed on you machine.

The principle control for all of this is /etc/portage/package.keywords for which a portion of mine looks like this:

# KVM, bleeding edge  app-emulation/kvm       ~amd64  # Flash support (bit flakey)  net-www/gnash           ~amd64  # Kernel  sys-kernel/kerneloops           ~amd64  # Firefox  www-client/mozilla-firefox      ~amd64  dev-libs/nss                    ~amd64  dev-libs/nspr                   ~amd64  net-libs/xulrunner              ~amd64

This allows me to run the latest KVM, Firefox and gnash without having to sacrifice the stability of my base-system.

Another feature of the compiling by source is you don't need to enable every feature in the world. For example my /etc/make.conf is contains things like:

USE="$USE -kde -qt gnome gtk2"

Which disables all KDE and QT stuff (seeing as I don't run KDE) while enabling any gnome support an app my have. You can see the use flags that packages respect by running emerge -p -v:

danny ~ # emerge -p -v emacs  [ebuild   R   ] app-editors/emacs-22.2-r2  USE="X alsa gif gtk jpeg  kerberos png spell tiff xpm -Xaw3d -gzip-el -hesiod -motif -sound  -source -toolkit-scroll-bars" 0 kB

So my emacs automatically picks up X and GTK support (my make.conf is a little bigger than alluded to above ;-). However you may not want to build every application with support for everything. aalib is very handy on mplayer for checking encodes over a shell, but I don't want every application to link against it. Enter /etc/portage/package.use:

# KVM  #  # Disable kvm module (we have our own)  # Explicitly enable gcc4 support.  app-emulation/kvm       -kvm ncurses sdl gcc4  # Firefox needs Java support  www-client/mozilla-firefox      java  dev-java/blackdown-jre          nsplugin   # I hate totem but it's needed for other apps  # disable nsplugin so it doesn't drag firefox down  # disable dvd so doesn't have to pull in gst-plugins-ugly  media-video/totem               -nsplugin -dvd  # mplayer needs aalib :-)  media-video/mplayer             aalib

So here I stop kvm from building it's own kernel module (as I run my own kernels), enable java on Firefox (where it's useful, but I don't want it everywhere), disable totem plugins and dvd support (but keeping the library which other apps use), and explicitly enable aalib for mplayer (but not anyone else).

This is the sort of fine grained control I really appreciate for my home machine. And my compile flags, the rather sedentary CFLAGS="-O2 -pipe" ;-)