Gentoo Protip: Clean orphaned .la files.

If you've been using the "lafilefixer"1 to tweak "broken" .la files, you may have discovered a negative side effect of its use.

Primarily, that lafilefixer breaks the MD5/SHA sums of the various .la files, so when somebody removes that package later, or upgrades to a package with a differently named .la file, it leaves behind this .la cruft.2

The effect of this, is that subsequent builds can die in mysterious ways trying to find stuff, as stupid code tries to use the old and outdated .la files.

The solution is reasonably simple, all you need is a little help from a few good Unix commands.

You'll need 2 basic packages installed:

  1. GNU findutils "xargs" and "find", provided in sys-apps/findutils. You should already have these, because they are after all part of the "system" set.
  2. Gentoo's Portage-Utils'  "qfile", provided in app-portage/portage-utils.

Firstly, we generate a list of all the .la files.

kent@ember$ find -O3 /usr/lib64  -type f  -name "*.la"

We then pipe this list null-delimited to xargs ( for safety ) and ask "qfile" to tell us if they are orphans.

kent@ember$ find -O3 ./  -type f -name "*.la"  -print0 | xargs -0 qfile -o

We can then review this list, make a few "ahh!, so that explains that problem" statements, and then proceed to remove the listed files using our mechanism of choice. xargs + rm is good enough for me.

kent@ember$ find -O3 ./  -type f -name "*.la"  -print0 | xargs -0 qfile -o | xargs rm

And as if by magic, things that no longer wanted to compile resume compiling!.

For me, this cleaned up most of the residual problems I had after the whole libpng12 debacle.

Important: You should read the man pages for xargs and find to make sure you're not just cargoculting bad code. i.e: that -O3 thing can be dangerous.
1:  ( dev-util/lafilefixer )

2: Perhaps portage has a workaround for this, but I'm using Paludis, so don't know, sorry. Complaints to: /dev/null.


  1. Hi Kent,

    just have this a careful try, noticing that passing multiple files to "qfile -o" will echo a lot of stuff which is not actually orphaned. You thus might want to use "xargs -0 -n1" instead, perhaps with a -Pnum_parallel thrown in to make use of multiple CPU cores.

    Kind regards,

  2. `qfile` does emit output that is "noise" sometimes, but its to `STDERR`. In my experience, `qfile -o` only emits files to `STDOUT` that are not owned by a package.

    Sure, this may include files users have added/edited themselves for whatever reason, but if you have `.la` files lying around in `/usr/lib` you have a polluted system to start with and are likely to have a lot of headaches.

    Incidentally, your advice about using xargs I generally recommend not doing as your approach will in theory require more cpu utilisation, spawning a separate instance if `qfile` for each file you want to check, which will in turn then iterate the entire contents of `/var/db/pkg/*` for each and every `qfile` call.

    Instead, I'd advise
    find -O3 ./ -type f -name "*.la" | qfile -o -f - | xargs rm

    Which will handle the theoretical scenario you'll hit when find produces too many variables to argumentize.

    `qfile` will then handle all that input nicely and efficiently.