Install OpenBSD packages to alternate directories

I run OpenBSD on a few Soekris 4801s. To get an image “prepped” for the Soekris, I use the directions on the Installing OpenBSD on Flash website. Periodically I need to apply patches to the images, which requires me to adjust the “make install” process to install the package to an alternative location. To apply a patch to a package and install it to an alternate location, I first apply the patch to the package that contains the errata:

$ cd /usr/src/usr.sbin/dhcpd

$ patch -p0 < 006_dhcpd.patch

After the patch is applied, I use the build procedure outlined in the patch header to create the binaries and supporting infrastructure:

$ make obj && make

/usr/src/usr.sbin/dhcpd/obj -> /usr/obj/usr.sbin/dhcpd
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/bootp.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/confpars.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/db.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/dhcp.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/dhcpd.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/bpf.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/packet.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/errwarn.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/dispatch.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/print.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/memory.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/options.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/inet.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/conflex.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/parse.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/alloc.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/tables.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/tree.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/hash.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/convert.c
cc -O2 -pipe  -Wall   -c /usr/src/usr.sbin/dhcpd/icmp.c
cc   -o dhcpd bootp.o confpars.o db.o dhcp.o dhcpd.o bpf.o packet.o errwarn.o dispatch.o print.o memory.o options.o inet.o conflex.o parse.o alloc.o tables.o tree.o hash.o convert.o icmp.o 

Once the package is built, I use the DESTDIR variable to control where the package is installed:

$ DESTDIR=/usr/images/img make install

install -c -s -o root -g bin  -m 555 dhcpd /usr/images/img/usr/sbin/dhcpd
install -c -o root -g bin -m 444 dhcpd.cat8 /usr/images/img/usr/share/man/cat8/dhcpd.0
install -c -o root -g bin -m 444 dhcpd.conf.cat5 /usr/images/img/usr/share/man/cat5/dhcpd.conf.0
install -c -o root -g bin -m 444 dhcpd.leases.cat5 /usr/images/img/usr/share/man/cat5/dhcpd.leases.0
install -c -o root -g bin -m 444 dhcp-options.cat5 /usr/images/img/usr/share/man/cat5/dhcp-options.0

I poked around on google to see which variables are available to control the build process, but was unable to find a complete list. There is a ton of cool stuff in /usr/ports/infrastructure/mk/, and I plan to cover some on the niftier variables in a future post.


The OpenBSD ports tree comes with 1000s of packages in source form, and allows each port to be compiled and installed by executing “make install” in the application port directory (e.g., /usr/ports/net/mtr ) . Since individual ports can be built different ways, OpenBSD provides different “FLAVORS” to control the package build process. To view the FLAVORS offered by a specific port, the make utility can be invoked with the ‘show’ option:

$ cd xmms

$ make show=FLAVORS
no_esd no_vorbis no_mikmod no_mp3

To build a package with a specific FLAVOR, the FLAVOR environment variable can be set prior to building the package:

$ export FLAVOR=”no_esd”

$ make install

Now if they only offered 21 flavors of ice cream (as my friend Clay once said)!

Searching the OpenBSD ports tree

The OpenBSD ports collection comes with 1000s of software packages, and is organized as a hierarchical directory structure. Locating specific ports can sometimes be tricky, especially when the port name doesn’t contain a descriptive name. To deal with these situations, the global Makefile supports a serach keyword:

$ cd /usr/ports

$ make search key=”debug” 2>&1 |more
Port: electricfence-2.0.5
Path: devel/ElectricFence
Info: library providing malloc debugging via VM protection
Maint: Niklas Hallqvist
Index: devel
Archs: any

Port: ald-0.1.5a
Path: devel/ald
Info: Assembly Language Debugger
Maint: Patrick Alken
Index: devel
Archs: i386

This is super useful for locating all ports that match a specific purpose (e.g., all debugging utilities).