Frotz update is coming. Need help

I’m the custodian of Frotz and I’m about to release a radically-updated version with full audio support and optional SDL and dumb interfaces. I released Beta 1 last week. Beta 2 is coming up in a few hours, which should be the last before final release. In that time, I want to make sure that my code plays nicely with Brew. A big complication is that I have no regular access to a MacOS machine. Could I get a Macintosh user who likes interactive fiction to help me out here?

First off, the repository is now at Gitlab – https://gitlab.com/DavidGriffith/frotz/.
Second, while standard Frotz requires no more libraries other than ncurses, a bunch are needed for audio output and more still for the SDL interface.

You could test builds on macOS using travis-ci or some other system. If it works there it should work on any mac.

Starting off with altering the formula for the latest beta, I changed these lines:

  homepage "https://gitlab.com/DavidGriffith/frotz"
  url "https://gitlab.com/DavidGriffith/frotz/-/archive/2.50b2/frotz-2.50b2.tar.gz"
  sha256 "228046edeca45867af312ebffd2e6a83ed8df69dd161fbaf4ea818f789328cba"
  head "https://gitlab.com/DavidGriffith/frotz.git"

Then I changed the def install things to agree with what the Makefile looks like now:

  def install
    inreplace "Makefile" do |s|
      s.remove_make_var! "CC"
      s.change_make_var! "PREFIX", prefix
      s.change_make_var! "SYSCONFIG_DIR", etc
      s.change_make_var! "MANDIR", share
    end

    system "make", "nosound"
    system "make", "install"
  end

So now here’s brew install --build-from-source frotz:

==> Downloading https://gitlab.com/DavidGriffith/frotz/-/archive/2.50b2/frotz-2.50b2.tar.gz
######################################################################## 100.0%
Error: An exception occurred within a child process:
  Utils::InreplaceError: inreplace failed
Makefile:
  expected to remove "CC"
  expected to change "PREFIX" to #<Pathname:/home/linuxbrew/.linuxbrew/Cellar/frotz/2.50b2>
  expected to change "SYSCONFIG_DIR" to #<Pathname:/home/linuxbrew/.linuxbrew/etc>
  expected to change "MANDIR" to #<Pathname:/home/linuxbrew/.linuxbrew/Cellar/frotz/2.50b2/share>

The download went fine, but the build process complains. These error messages aren’t very clear to me what they’re complaining about or how to fix them. The Makefile now calls subordinate Makefiles in the various source directories. For instance, in a standard terminal build, make would be called to build in src/common, src/blorb/, and src/curses. There is also copious use of ?= and += to do conditional assignments, added to ease incorporation into Gentoo’s portage. What else might be causing these error messages?

Why would you alter all those variables? They are set in the environment and you probably need them.

I just left those inreplace things unchanged. I don’t know what was intended for 2.44 because I didn’t originate the formula.

I found that the problem is a deficiency in Library/Homebrew/extend/string.rb. It’s not checking for GNU-make specific assignment operators: ?=, +=, or -=. The solution appears to be this patch:

diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb
index 32588be9a..5000dbb0d 100644
--- a/Library/Homebrew/extend/string.rb
+++ b/Library/Homebrew/extend/string.rb
@@ -41,7 +41,7 @@ module StringInreplaceExtension
   # Looks for Makefile style variable definitions and replaces the
   # value with "new_value", or removes the definition entirely.
   def change_make_var!(flag, new_value)
-    return if gsub!(/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, "#{flag}=#{new_value}", false)
+    return if gsub!(/^#{Regexp.escape(flag)}[ \t\\?\-\+]*=[ \t]*(.*)$/, "#{flag}=#{new_value}", false)
 
     errors << "expected to change #{flag.inspect} to #{new_value.inspect}"
   end
@@ -50,7 +50,7 @@ module StringInreplaceExtension
   def remove_make_var!(flags)
     Array(flags).each do |flag|
       # Also remove trailing \n, if present.
-      errors << "expected to remove #{flag.inspect}" unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=.*$\n?/, "", false)
+      errors << "expected to remove #{flag.inspect}" unless gsub!(/^#{Regexp.escape(flag)}[ \t\\?\-\+]*=.*$\n?/, "", false)
     end
   end

With these changes, Frotz and a few other of my projects I want to put into Brew will build and install just fine. Now I’m working on a pull request for it.