RubySDLインストールする際、sgeていうライブラリがあるとより便利になる。
けど素のHomebrewにはsgeがない。なのでググってsgeのformulaを見つけたけど、/usr/local/以下に直にインストールされたりと出来が良くないので、Homebrewの練習がてら自分でformulaを書いてみた。
libsge.rb
# Documentation: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
# /usr/local/Library/Contributions/example-formula.rb
class Libsge < Formula
desc 'An add-on graphics library for the Simple Direct Media Layer'
homepage 'https://github.com/flibitijibibo/libSGE/'
url 'git://github.com/flibitijibibo/libSGE.git', revision: '1085c4958397b91a42c399bc389e8fddde8f207b'
version '1085c49'
depends_on 'sdl'
def install
args = %W(
PREFIX=#{prefix}
PREFIX_H=#{prefix}/include/SDL
)
system 'make', 'install', *args
end
test do
(testpath / 'test.c').write <<-EOS.undent
#include "sge.h"
int main() {
sge_Random(1,10);
return 0;
}
EOS
system "#{ENV.cc} test.c `sdl-config --cflags --libs` -lsge -otest"
system './test'
end
end
マニュアルとか他のformulaとか--debug --verboseとかを見ながら書いてこんなかんじ。
PREFIXを環境変数で指定して、アンインストールを可能に。あとgitのrevisionしといて安定性向上。雑ながら一応テストも追加。あたりが改善点。
gistにおいたので
brew install https://gist.githubusercontent.com/ymmtmdk/5b15f2b06aef5549eb5a/raw/ebf4c9758b1f772f0f6073e7b2bdbb5e9665ee74/libsge.rb
で使用可能。
Homebrewはmake && make installなプログラムが簡単に管理下におけて便利だなあと思いました。