3

I'm trying to create a homebrew formula for an application that doesn't need to be compiled. I've tried looking through the formula cookbook, but I'm missing something to make things properly work. Below is my use-case with more generic filenames.

Inside the container is two files: one is the script for the application, the other being a file for man pages. We'll use the following filenames to keep things generic:

  • myapp.py (executable script)
  • resource.txt (a resource file that the script needs)
  • myapp.1 (man page)

What are the best ways to get these into the correct locations? Presume I have the ability to modify the code in the script for choosing the location to load the resource.

Thanks.

AdmiralJonB
  • 2,038
  • 3
  • 23
  • 27

1 Answers1

2

You can either modify your script at install time to use the correct location of the resource or just assume it’s in the same directory and let Homebrew do the magic for you. I wrote an example formula for the latter case in another answer.

Here’s how it looks like for your needs:

class Foo < Formula
  desc "Blah blah"
  url "https://github.com/foo/foo/archive/master.zip"
  version "1.2.3"

  def install
    man1.install "myapp.1"
    libexec.install Dir["*"]
    bin.write_exec_script (libexec/"myapp.py")
  end
end

It installs myapp.1 in the correct directory. You can also use man2, man3, etc for other man directories.

It then installs all the remaining files under libexec then create an exec script in bin/myapp.py. This will be a simple shell script that execs your script in libexec. That way, your script will executes from libexec and thus will be able to find resource.txt that’s located in the same directory.

If you’d like to call it myapp and not myapp.py it’d look like that:

  def install
    man1.install "myapp.1"
    libexec.install "resource.txt"
    libexec.install "myapp.py" => "myapp"
    bin.write_exec_script (libexec/"myapp")
  end
bfontaine
  • 18,169
  • 13
  • 73
  • 107