Useflags

From Gnuffy

Jump to: navigation, search

Spaceman supports useflags. If you ever used gentoo, you already know, what useflags are, if not: basically, a useflag controls an optional build feature a source-code supports. If the useflag is set, the support will be included, if it is not set, the support will be left out. It is that easy.

Most software packages offer such optional features, and without useflags, the package maintainer of your distribution decides which features to use or not. Most maintainers seem to think, it is a good thing to have as much features as possible in a package, and this is not completely wrong, but it often pulls in a lot of dependencies not needed if a certain feature is left out. So even if you don't want this feature, you get packages installed you are not going to use. This is why you want useflags.

How to use useflags in PKGBUILDs

A PKGBUILD using useflags has to include an array variable useflags that contains the list of useflags used in the PKGBUILD.

 useflags=('alsa' 'jack' 'oss')

would define three useflags. To make your PKGBUILD do specific things when a useflag is set, there is new command called use which expects the name of a useflag as parameter and returns true if the useflag is set, otherwise it returns false. For example:

 use jack && depends+=(jack-audio-connection-kit)
 use alsa && _options+=" --enable-alsa" || _options+=" --disable-alsa"
 use jack && _options+=" --enable-jack" || _options+=" --disable-jack"
 use oss  && _options+=" --enable-oss"  || _options+=" --disable-oss"
 ./configure $_options

would call configure with the appropriate options depending on the three useflags being set or unset.

A binary of a PKGBUILD using useflags contains information about the useflags used when building it, and also gets a unique pkgname, that reflects its useflags, so you can offer different binary versions to only one PKGBUILD (build with different useflag-combinations)


How to use useflags when building packages

To set a useflag you have to put it in space separated list of flags in variable USE. Same procedure as in gentoo, so

 USE="jack" spaceman -b

would build the PKGBUILD in the current work directory with useflag jack set (and -- if it is the example of above -- with "alsa" and "oss" not set)

Actually the use() function does nothing else than

  grep -q -i -w "$1" <<< "$USE"

but I thought this would look ugly to be found in many PKGBUILDs, so that's why we have a command "use" for it.