LoginSignup
5
5

More than 5 years have passed since last update.

StarRubyをHomebrewでMacにインストールする方法

Last updated at Posted at 2013-11-21

Rubyの2DゲームライブラリStarRubyをMacにインストールしたときのメモ:

公式ページの「Mac OS X で動かす」はMacPortsで、Homebrewでインストールする情報が少なかったので;
→・たった200行で作れるテトリス Ruby編 - a newcomer!

上記の記事の方法で、Homebrewを使ってインストール。
(OS X 10.9 Mavericks、Ruby 2.0.0-p247 で実行)

0.準備

Homebrew、必要ならrbenv、ruby-buildでRubyのインストール
参考;
→・Ruby 2.0.0 を Homebrew + rbenv で OS X Mountain Lion にインストール
(Command Line Tools、Xcodeは、なるべく最新のものを選ぶ)

1.SDL関連ライブラリのインストール

$ brew update  #Homebrew 自体と formula を最新版に
$ brew upgrade #更新のあるパッケージを再ビルド
$ brew doctor  #エラーがでなければ OK

$ brew install sdl
$ brew install sdl_mixer
$ brew install sdl_ttf
$ brew install fontconfig
#必要なら、libpng、freetype、libogg なども

$ gem update --system #Rubymsを最新に
$ gem install rsdl 

参考;
→・StarRubyソースコード - hajimehoshi/starruby - GitHub
→・MacにRuby/SDL、rsdl、SGEを入れて、ゲームライブラリMyGameを動かす

2.StarRubyのインストール

$ brew tap homebrew/versions
$ brew install libpng12
$ brew link libpng12
#Starrubyのインストールにはデフォルトのlibpng15ではなく、libpng12が必要なため

$ git clone git://github.com/hajimehoshi/starruby.git
$ cd starruby
$ ruby extconf.rb
$ make
$ make install

(注;OS X 10.7.5 Lion、Ruby 1.8.7では、ruby extconf.rb でエラー)

 
(2014.5.29 追記;
 別の方法でインストールしている記事を見つけました。
→・Star Rubyのインストール - ザリガニが見ていた...。

$ git clone git://github.com/hajimehoshi/starruby.git
$ cd starruby
$ ruby extconf.rb

#makeのエラーを回避する
$ cat Makefile | sed 's/-multiply_definedsuppress//' > Makefile~
$ mv -f Makefile~ Makefile

$ make
$ make install

3.動作確認

注)MacでStarRubyのプログラム(foo.rb)を動かすときは;
$ ruby foo.rb #ではなく
$ rsdl foo.rb

サンプルプログラム;

 
注)
Font.new("fonts/OANGEKI", 12)
などでエラーが出たときは、OS Xのフォントをフルパスで指定する。
Font.new("/Library/Fonts/Arial.ttf", 12)

(2014.5.29 追記;
 または、./ を追加して、カレントディレクトリからの相対パス指定に変えればよい。
Font.new("./fonts/OANGEKI", 12)

 あるいは、Ruby の起動時にコマンドラインオプション -I directory名 を使ってファイルをロードするパスを追加する。カレントディレクトリを追加するには .(ドット)を追加する。
$ rsdl -I. foo.rb
で実行。
→ ・Star Rubyのインストール - ザリガニが見ていた...。

 

StarRubyの開発が止まっているようなのが残念。

 
(→・元記事

5
5
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
5
5