This Time Self-Hosted
dark mode light mode Search

Autotools Mythbuster: automagically disabled dependencies

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], [1], [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.

Comments 3
  1. Just a side note: you use PKG_CHECK_MODULES, and there is this blog post by Miguel de Icaza saying that you shouldn’t: http://tirania.org/blog/arc…What’s your opinion on the arguments presented in that post?

  2. That’s not the first public statement of Icaza making you wonder about his sanity.In this case, just look at the example. Somebody runs “autogen.sh” (on a side note, with autoreconf i’d consider “autogen.h” obsolete), so is using autotools himself. Either he has his source tree directly from the VCS, in which case he SHOULD know a little about autotools and m4, or someone thought it would be a good idea to distribute “autogen.sh” (it isn’t, it’s a very bad idea in fact …)So, his example for why he hates pkg.m4 so much is just invalid.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.