Herr Bischoff

Dump All Set FreeBSD Port Options

Today I needed to dump all options set or unset for FreeBSD ports on one machine, as part of troubleshooting a build.

The script and command below prints out all previously set options in a make.conf compatible format. This enables you to create pre-configured option setups that can easily be ported from one machine or jail to the next by copying only make.conf instead of the whole /var/db/ports folder structure. Obviously only set the ones you absolutely require, otherwise it will easily break on changes.

# process.sh



NAME=`echo $FILE | sed -E 's#/var/db/ports/(.*)/.*#\1#'`

cat $FILE | \
    sed -E '/^_|^#/d' | \
    sed -E "s/OPTIONS_FILE/$NAME/"
find '/var/db/ports/' -name 'options' -exec ./process.sh '{}' \;

The resulting variables look like this

x11-toolkits_gtk30_UNSET += ATK_BRIDGE

as opposed to the global variable


When you provide a port-specific option variable, you can greatly increase the granularity of port options. To the best of my knowledge, this is not documented in the FreeBSD handbook, the make.conf man page or usr/share/examples/etc/make.conf.

Finally, it is certainly possible to cram all this into a one-liner but having to manually unpack and parse what it does is not worth the effort. I like minimal cognitive overhead at the expense of compactness or cleverness.