I run a forked/patched version of Bozohttpd so I can add Cache-Control headers. I had intended to keep it up to date, but before you know it three years have passed and I’m well behind.

I hit an issue trying to build the new one because of a linker issue to libblocklist. I presume what has happened is that the blacklist library has been renamed blocklist (Probably with NetBSD 9.2? Or maybe just Current?), but I wanted to build on NetBSD 9.1 before upgrading where the library is still called blacklist.

The Makefile has support for compile-time options and avoiding blocklist support:

make COPTS="-DNO_BLOCKLIST_SUPPORT"

But this still tries to link to the blocklist library. Normally this wouldn’t be a problem. I.e. if changed to -lblacklist then it builds fine on 9.1. But in my mind it doesn’t make any sense to (try to) link to something if not compiling that thing.

So I tweaked the Makefile to make more sense:

# If we are setting a compile option of NO_BLOCKLIST_SUPPORT then it makes no
# sense to have a linker for it.
LDADD+=	${"${COPTS:M-DNO_BLOCKLIST_SUPPORT}" == "-DNO_BLOCKLIST_SUPPORT":?:-lblocklist}

This neat trick is actually mentioned in the manpage, but it still took me a bit to get it right.

  1. The M in ${COPTS:M-DNO_BLOCKLIST_SUPPORT}" is a variable modifier and so takes the whole $COPTS variable and tries to match only -DNO_BLOCKLIST_SUPPORT. If $COPTS doesn’t contain that string then it’ll result in an empty string.
  2. It then compares that match to what we are looking for, -DNO_BLOCKLIST_SUPPORT
  3. And if that’s there then it returns “nothing”, i.e. there is nothing between ? and :.
  4. If the match isn’t there (i.e. we are not trying to avoid blocklist support) then it returns -lblocklist

make -d A is helpful as will show stuff like:

Applying[COPTS] :M to "-DNO_BLOCKLIST_SUPPORT"
Pattern[COPTS] for [-DNO_BLOCKLIST_SUPPORT] is [-DNO_BLOCKLIST_SUPPORT]
VarMatch [-DNO_BLOCKLIST_SUPPORT] [-DNO_BLOCKLIST_SUPPORT]
Result[COPTS] of :M is "-DNO_BLOCKLIST_SUPPORT"
Applying["-DNO_BLOCKLIST_SUPPORT" == "-DNO_BLOCKLIST_SUPPORT"] :? to ""
lhs = "-DNO_BLOCKLIST_SUPPORT", rhs = "-DNO_BLOCKLIST_SUPPORT", op = ==
Modifier pattern: "-lpants"
Modifier pattern: "-lblocklist"
Result["-DNO_BLOCKLIST_SUPPORT" == "-DNO_BLOCKLIST_SUPPORT"] of :? is "-lpants"

Here I was just testing (make COPTS="-DNO_BLOCKLIST_SUPPORT" -d A) and so wanted to return something in either case.