20100209

Hacking in Gentoo

I started using Linux as my primary OS some 4 years ago, but as much as I liked to brag that I had the theoretical ability to modify (almost) anything on my system, the reality was that getting a generic source package to work on whatever particular distribution I had was difficult (or at least intimidating). At best the paths would all be screwed up, and at worse I'd get library issues. Not to mention the hassle of specially handling that package from then on in my package manager.

Enter Gentoo.

In Gentoo's package manager, Portage, every package is installed by running a custom Python script, and you can store custom versions of it using their overlay system, while keeping all the dependency tracking information. The Bottom Line: I can patch anything as it's being installed onto my system, and I get all their fancy install scripts for free.

So, for the Gentoo aficionado, here's how I fixed xfdesktop to do exactly what I wanted when auto-sizing my wallpapers.

Howto install custom software versions in Gentoo:
  1. Setup a Portage overlay

    See the Gentoo Handbook or this site for more details but basically you make the /usr/local/portage folder, and add PORTDIR_OVERLAY=/usr/local/portage to your /etc/make.conf

  2. Copy over the package you want to customize from the regular tree

    ie Copy everything from /usr/portage/xfce-base/xfdesktop to /usr/local/portage/xfce-base/xfdesktop

  3. Make your patch

    Use the actual distfiles Gentoo is already using (emerge -f xfdesktop will list them) to save yourself headaches later.
    Personally I just unpack the source, setup a git repository, muck with the code, and then use git format-patch to give me the patch file I need.

  4. Modify the ebuild to use your patch

    If you have a particularly weird package, this can be tricky until you get better at writing ebuilds. But for most packages, this is cake. Just add your patch to the list of patches they're already applying. (Or checkout other ebuilds that have some patches to add and copy what they did). Here's the diff -u of my new ebuild.

    --- /usr/portage/xfce-base/xfdesktop/xfdesktop-4.6.1-r1.ebuild    2010-01-18 16:38:19.000000000 -0800
    +++ /usr/local/portage/xfce-base/xfdesktop/xfdesktop-4.6.1-r1.ebuild    2010-01-27 17:26:10.355164734 -0800
    @@ -56,7 +56,8 @@
    $(use_enable debug)"
    DOCS="AUTHORS ChangeLog NEWS TODO README"
    PATCHES=( "${FILESDIR}/${P}-automagic.patch"
    -        "${FILESDIR}/${P}-assert.patch" )
    +        "${FILESDIR}/${P}-assert.patch"
    +        "${FILESDIR}/0001-Rewrote-backdrop-AUTO-selection.patch" )
    }
  5. Put your patch file in the files/ directory.

That's it. Emerge and enjoy!

I currently run custom versions (read 1-10 line patches) of 4 packages, and I'm getting less afraid to try to muck with things. The funniest is probably nethack, which has the username for debug mode hard-coded into the source, so you can't access it unless your username is "wizard". I guess nethack dev's make a custom user to do their debugging? I'm not really sure how that one was supposed to work.

Anyway, Happy Hacking!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.