Fixing Profanity builds on Homebrew with non-default home

TL;DR: brew install https://guro.paulsnar.lv/x/2020/08/profanity-0.9.5-readlinepatch.rb, or apply the following patch to the stock recipe via patch -p 1:

--- a/profanity.rb
+++ b/profanity.rb
@@ -37,2 +37,3 @@
     system "./bootstrap.sh" if build.head?
+    inreplace "configure", "/usr/local/opt/readline", Formula["readline"].opt_prefix
     system "./configure", "--disable-dependency-tracking",

Note: The recipe provided herein is for Profanity v0.9.5 and must be adapted for any other release, though the same steps apply.


As far as software goes, I’m one of the weirder users you’ll find around. For instance, I deliberately don’t use the default directory (/usr/local) for Homebrew because I don’t want to install stuff globally – instead I use the less supported but still legitimate approach of just putting it anywhere.

While it comes with its downsides (because some pre-built bottles assume that the installation directory is /usr/local and therefore must be re-built from source if they’re to be installed elsewhere), for most cases it’s not a problem. That is, until I tried installing Profanity for some testing recently.

The configure script fails thusly:

Last 15 lines from /Users/paulsnar/Library/Logs/Homebrew/profanity/01.configure:
checking pkg-config is at least version 0.9.0... yes
checking for libmesode... no
checking for libstrophe... yes
checking whether libstrophe works... yes
checking for ncursesw... yes
checking for wget_wch support in ncursesw... yes
checking for glib... yes
checking for gio... yes
checking for library containing fmod... none required
checking for curl... yes
checking for SQLITE... yes
checking for GTK... no
configure: gtk+-2.0 not found, icons and clipboard not enabled
checking for /usr/local/opt/readline/lib... no
configure: error: libreadline is required for profanity

Indeed, the last two lines might seem suspicious: why is configure looking for libreadline in /usr/local/opt? That seems like a bad assumption on their part.

And, indeed, they do look for readline wrongly on macOS. The proper fix would be to just use the readline provided by the environment while also allowing to specify other locations, and Homebrew could just do that, like they already do for, e.g., PHP.

I wanted to wrap up this change for upstream but I couldn’t manage to get Autoconf working after spending about four hours on it. [1] Hence, there’s an alternative dirty fix—within the Homebrew build recipe, just replace the offending location with the correct one right before running ./configure:

  def install
    system "./bootstrap.sh" if build.head?
    inreplace "configure", "/usr/local/opt/readline", Formula["readline"].opt_prefix
    system "./configure", "--disable-dependency-tracking",
                          "--disable-silent-rules",
                          "--prefix=#{prefix}"
    system "make", "install"
  end

The significant change here is the addition of the inreplace line.

After configure is prepared, we just go in and outright replace the hardcoded reference to /usr/local/opt/readline with the one that Homebrew has set. And that works!

It’s a dirty fix, and it definitely doesn’t belong within Homebrew/core, but I’d appreciate if anybody let Profanity folk know that their Autoconf setup could use some improvement.