前回までのあらすじ
Haskell - GHC for iOS : iOSアプリをHaskellで開発する - euphonictechnologies’s diary
前回はデバッグアウトプットに丸を表示するアプリケーションをHaskellで記述して、真っ白なiPhone画面と"o"が増えていくデバッグコンソールというアプリケーションを実行しました。とりあえず、Haskellで記述したコードを含むバイナリをiPhoneにデプロイできるところまで確認しました。
今回は
次への準備としてcabal-iosを使えるようにしておきます。cabal-iosはシミュレータ用・実機用ghcのcabalラッパです。
cabal-iosしてみる
cabal-iosはそれぞれのプラットフォームごとにcabalコマンドを実行する単なるラッパです。
# Simply multiplexes arguments over both simulator and device cabals i386-apple-darwin11-cabal $@ arm-apple-darwin10-cabal $@
となっていて、それぞれのcabalを単に順番に実行します。
例えばtextパッケージをインストールしてみます。
そのままcabal-ios install text
とするとまた通らなかったので、エラーメッセージをよく見ると
$ cabal-ios install text cabal: Cannot find the program 'gcc'. User-specified path 'i386-apple-darwin11-clang' does not refer to an executable and the program is not on the system path.
なんか前回見たようなエラーメッセージです。ghcのsettings(普通は/usr/local/lib/arm-apple-darwin10-ghc-7.8.3/settings)を見てみると
("GCC extra via C opts", " -fwrapv"), ("C compiler command", "/Users/<user name>/bin/ghc-ios-scripts/arm-apple-darwin10-clang"), ("C compiler flags", " -fno-stack-protector"), ("C compiler link flags", ""), ("Haskell CPP command","arm-apple-darwin10-clang"), ("Haskell CPP flags","-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs "), ("ld command", "arm-apple-darwin10-ld"),
と、Haskell CPP commandがフルパスになっていないようです。なのでarm/i386両方フルパスに書き換えます。本当はパスを通すのが良いのだと思うのですが、なんかうまく通らない、残念。さらにcabal-iosが使うi386-apple-darwin11-cabal/arm-apple-darwin11-cabalのgcc/ldもフルパスに書き換えておきます。。
$ git diff *cabal diff --git a/arm-apple-darwin10-cabal b/arm-apple-darwin10-cabal index d7dec93..b0eb2f9 100755 --- a/arm-apple-darwin10-cabal +++ b/arm-apple-darwin10-cabal @@ -2,8 +2,8 @@ export COMMON=--builddir=dist/arm export COMPILE="--with-ghc=arm-apple-darwin10-ghc --with-ghc-pkg=arm-apple-darwin10-ghc-pkg - --with-gcc=arm-apple-darwin10-clang - --with-ld=arm-apple-darwin10-ld + --with-gcc=/Users/<user name>/bin/ghc-ios-scripts/arm-apple-darwin10-clang + --with-ld=/Users/<user name>/bin/ghc-ios-scripts/arm-apple-darwin10-ld --hsc2hs-options=--cross-compile" export CONFIG="--configure-option=--host=arm-apple-darwin10 --disable-shared" exec "`dirname $0`/common-cross-cabal" "$@" diff --git a/i386-apple-darwin11-cabal b/i386-apple-darwin11-cabal index 95741d9..1ecf880 100755 --- a/i386-apple-darwin11-cabal +++ b/i386-apple-darwin11-cabal @@ -2,8 +2,8 @@ export COMMON="--builddir=dist/i386" export COMPILE="--with-ghc=i386-apple-darwin11-ghc --with-ghc-pkg=i386-apple-darwin11-ghc-pkg - --with-gcc=i386-apple-darwin11-clang - --with-ld=i386-apple-darwin11-ld + --with-gcc=/Users/<user name>/bin/ghc-ios-scripts/i386-apple-darwin11-clang + --with-ld=/Users/<user name>/bin/ghc-ios-scripts/i386-apple-darwin11-ld --hsc2hs-options=--cross-compile" export CONFIG="--configure-option=--host=i386-apple-darwin11 --disable-shared" exec "`dirname $0`/common-cross-cabal" "$@"
もう一度cabal-ios install -v text
してみます。
ldがうまく動かない
どうもシミュレータ用のcabal-iosがうまく動いていない様子。execのオプションに-Lがないとか頓珍漢なことを言うので調べてみるとどうも不完全なシェルスクリプトなように見えます。
問題があるのはi386用だけなので修正します。execを使わないように書き換えましょう。
$ git diff i386-apple-darwin11-ld diff --git a/i386-apple-darwin11-ld b/i386-apple-darwin11-ld index 2d18814..507898f 100755 --- a/i386-apple-darwin11-ld +++ b/i386-apple-darwin11-ld @@ -2,6 +2,8 @@ TARGET_PLATFORM=`xcrun --show-sdk-platform-path --sdk iphonesimulator` TARGET_BIN=`xcrun --show-sdk-platform-path --sdk iphonesimulator`/Developer/usr/bin + +TARGET_LD=$TARGET_BIN/ld TARGET_LDFLAGS="-L$TARGET_PLATFORM/usr/lib/ -arch i386" -exec $TARGET_LD $TARGET_LDFLAGS "$@" \ No newline at end of file +$TARGET_LD $TARGET_LDFLAGS "$@"
こんな感じ。
で、再度textをインストールしてみます。
$ cabal-ios install -v text ... Registering text-1.2.0.4... /usr/local/bin/arm-apple-darwin10-ghc-pkg update - --global --user Installed text-1.2.0.4 World file is already up to date.
とインストールが出来ました。
まとめ
今回はさらっと準備だけしておきます。ここからどういう方向に使っていこうかな。