One question that I’ve been asked before, and to which I didn’t really have a good answer up to now is: should configure scripts fail, when a dependency is enabled explicitly, but it can’t be found? This is the automagic dependency problem, but on the other branch.
With proper automatic dependencies, if the user does not request explicitly whether to enable something or not, it’s customary that the dependency is checked for, and if found, the feature that it’s connected to is enabled. When the user has no way to opt out from it (which is bad), we call it an automagic dependency. But what happens if the user has requested it and the feature is not available?
Unfortunately, there is no standard for this, and myself I used both the “fail if asked and not found” and “warn if asked and not found” approaches. But the recent trouble between ncurses and freetype made me think that it’s important to actually make a point that there is a correct way to deal with this.
Indeed what happens is that right now, I have no way to tell you all that the tinderbox has found every single failure caused by
sys-libs/ncurses[tinfo] even after the whole build completed: it might well be that a particular package, unable to link to ncurses, decided to disable it altogether. The same goes for freetype. Checking for all of that would be nice, but I have honestly no way to do it.
So to make sure that the user gets really what they want, please always make sure that you do verify that you’re proceeding how the user wanted. This makes sure that even in packaging, there won’t be any difference when a dependency is updated, or changed. In particular, with
pkg-config, the kind of setup you should have is the following:
AC_ARG_WITH([foobar], AS_HELP_STRING([--with-foobar], [Enable the features needing foobar library])) AS_IF([test "x$with_foobar" != "xno"], [ PKG_CHECK_MODULES([FOOBAR], [foobar >= 123], [ AC_DEFINE([HAVE_FOOBAR], , [Found foobar library]) ], [ AS_IF([test "x$with_foobar" = "xyes"], [ AC_MSG_ERROR([$FOOBAR_PKG_ERRORS]) ]) ]) ])
I’ll be discussing this and proposing this solution in the next update to Autotools Mythbuster (which is due anytime soon, including the usual eBook update for Kindle users). This would hopefully make sure that in the future, most configure scripts will follow this approach.