LoginSignup
35
28

More than 5 years have passed since last update.

HomebrewにおけるFormulaの作成方法

Posted at

目標

Emacsを使ったタイピングソフトTRR
をHomebrewで簡単に入れられるようにする。

Homebrewについて

Homebrew は「ユーザが自らパッケージをビルドして使用する」ことのメタファーで
「ビールを自家醸造して保存する・飲む」ことを意味しています。
そのため、独特なキーワードを用いるので下記で表にしておきます。

キーワード 本来の意味 たとえ
Brew ビールを醸造する makeする
Homebrew 自家醸造 ユーザ自らがビルドする
Celler セラー(ワインセラーとかのアレ),ビール貯蔵庫 インストール(保存)先
Keg 樽,醸成用 材料
Formula 調理法、手順 ビルド方法・手順が書かれたスクリプト

Quote: http://qiita.com/b4b4r07/items/6efebc2f3d1cbbd393fc#1-3

作成手順

Formulaのテンプレートの作成

$ # trrという名前で配布するFormulaを作成
$ brew create --set-name trr https://trr22.googlecode.com/files/trr22_0.99-5.tar.g://trr22.googlecode.com/files/trr22_0.99-5.tar.gz

テンプレートの編集

createすると自動的に編集モードになりますが、以下でも編集可能です。

$ # brewのコマンドで
$ brew edit trr

$ # ファイルパスから
$ # $(brew --repository)は基本的には/usr/local
$ vim $(brew --repository)/Library/Formula/trr.rb

テンプレートは以下のように作られます。

require "formula"

# Documentation: https://github.com/Homebrew/homebrew/wiki/Formula-Cookbook
#                /usr/local/Library/Contributions/example-formula.rb
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!

class Trr < Formula
  homepage ""
  url "https://trr22.googlecode.com/files/trr22_0.99-5.tar.gz"
  sha1 ""

  # depends_on "cmake" => :build
  depends_on :x11 # if your formula requires any X11/XQuartz components

  def install
    # ENV.deparallelize  # if your formula fails when building in parallel

    # Remove unrecognized options if warned by configure
    system "./configure", "--disable-debug",
                          "--disable-dependency-tracking",
                          "--disable-silent-rules",
                          "--prefix=#{prefix}"
    # system "cmake", ".", *std_cmake_args
    system "make", "install" # if this fails, try separate make/make install steps
  end

  test do
    # `test do` will create, run in and delete a temporary directory.
    #
    # This test will fail and we won't accept that! It's enough to just replace
    # "false" with the main program this formula installs, but it'd be nice if you
    # were more thorough. Run the test with `brew test trr22_0.99`. Options passed
    # to `brew install` such as `--HEAD` also need to be provided to `brew test`.
    #
    # The installed folder is not in the path, so use the entire path to any
    # executables being tested: `system "#{bin}/program", "do", "something"`.
    system "false"
  end
end

インストールコマンドの追加

以下のようにshellコマンドを追加できます。

system "sed -i -e \"s,old,new,\" Makefile" # ファイルの書き換え
system "make", "all" # make

Homebrew TapsによるFormulaの公開

brew tap [formula-tap-name]でbrewでのインストールができるようにする方法です。

この方法では非公式のものになるので、他の人が普段通りsearchinstallを使ってインストール
をするには、まずbrew tap [formula-tap-name]をする必要があります。

  1. Githubでhomebrew-[作成したFormula名]というリポジトリを作る。 (例: Homebrew/science)
  2. 作成したリポジトリへ[作成したFormula名].rbpush (例: trr.rb)

インストールをしてもらうときは、
brew tap [Githubのユーザ名]/[作成したFormula名]とすることで、brew install [作成したFormula名]などができるようになります。

(例: brew tap homebrew/science)

Homebrew/homebrewリポジトリへのpull request

Tapでの公開だけでなく、公式リポジトリへの反映をリクエストすることができます。

リクエスト方法

  1. Homebrew/homebrewをForkする。
  2. cd $(brew --repository) && git remote add [Githubのユーザ名] https://github.com/[Githubのユーザ名]/homebrew
  3. 変更をローカルリポジトリでコミット。
  4. git push [Githubのユーザ名] masterで変更をForkしたリポジトリへ反映。
  5. Githubでpull requestを送る。

リクエストが受理されるために

Wikiに書かれている事項などを守る必要があります。

例としては以下の様なものがあります。

  • sudoを使わない。
  • インストールの際に追加されるファイルは基本的に/usr/local/Cellar/[作成したFormula名]以下に置く。
35
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
28