Haskellメモ: GHC 6.8.1をLeopardにインストール

GHC 6.8.1をLeopardにインストールしてみました。
いくつか罠がありましたので、はまってる人に見つけてもらいやすいように、全試行錯誤の記録を残しておきます。

まず、GHC 6.8.2をダウンロードしてインストールしようとしてみた。

curl -O http://haskell.org/ghc/dist/6.8.2/chakravarty/ghc-6.8.2-i386-apple-darwin.tar.bz2
bzcat ghc-6.8.2-i386-apple-darwin.tar.bz2 | tar xvf -
cd ghc-6.8.2
./configure
make
sudo make install

これでGHCをスタートすると以下のようにエラーになってしまう。

hideaki% ghci
dyld: Library not loaded: /opt/local/lib/libreadline.5.2.dylib
  Referenced from: /usr/local/lib/ghc-6.8.2/ghc-6.8.2
  Reason: image not found
Trace/BPT trap

libreadline(入力ラインライブラリ)が入ってないのが問題。インストールしよう。

curl -O ftp://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz
gzcat readline-5.2.tar.gz | tar xvf -
cd readline-5.2
./configure
make

...でもここでmakeが以下のように失敗してしまう。...

gcc -dynamic -arch_only `/usr/bin/arch` -install_name /usr/local/lib/libreadline.5.2.dylib -current_version 5.2 
-compatibility_version 5 -v -o libreadline.5.2.dylib readline.so vi_mode.so funmap.so keymaps.so parens.so 
search.so rltty.so complete.so bind.so isearch.so display.so signals.so util.so kill.so undo.so macro.so 
input.so callback.so terminal.so text.so nls.so misc.so xmalloc.so history.so histexpand.so histfile.so 
histsearch.so shell.so mbutil.so tilde.so compat.so -lncurses
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man 
--enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 
--with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 
--target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5465)
i686-apple-darwin9-gcc-4.0.1: -compatibility_version only allowed with -dynamiclib
make[1]: *** [libreadline.5.2.dylib] Error 1
make: [shared] Error 2 (ignored)

これを解決するには、まず、readline-5.2/support/shobj-confを編集する。
以下の行を見つけて、

darwin[78]*)	SHOBJ_LDFLAGS=''

以下のように書き換える。

darwin[789]*)	SHOBJ_LDFLAGS=''

そしてもう一度はじめからlibreadlineのインストール。今度はうまくいく。

./configure CFLAGS="-isystem /usr/local/include"
make
sudo make install

もういちどGHCIの起動をためしてみると、新たな問題が浮上。

hideaki% ghci
dyld: Library not loaded: /opt/local/lib/libgmp.3.dylib
  Referenced from: /usr/local/lib/ghc-6.8.2/ghc-6.8.2
  Reason: image not found
Trace/BPT trap

これに対しては、libgmpをインストールする。

curl -O ftp://ftp.gnu.org/gnu/gmp/gmp-4.2.2.tar.bz2
bzcat gmp-4.2.2.tar.bz2 | tar xvf -
./configure
make
make check
sudo make install

すると、今度はGHCのバグらしい。

hideaki% ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help

<interactive>:1:22:
    Failed to load interface for `System.IO':
      Use -v to see a list of the files searched for.

<interactive>:1:22:
    Failed to load interface for `System.IO':
      Use -v to see a list of the files searched for.

<interactive>:1:22:
    Failed to load interface for `System.IO':
      Use -v to see a list of the files searched for.
ghc-6.8.2: panic! (the 'impossible' happened)
  (GHC version 6.8.2 for i386-apple-darwin):
        interactiveUI:setBuffering

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

しかたないので、一つ前のバージョン6.8.1を試すことにする。

curl -O http://haskell.org/ghc/dist/6.8.1/chakravarty/ghc-6.8.1-i386-apple-darwin.tar.bz2

bzcat ghc-6.8.1-i386-apple-darwin.tar.bz2 | tar xvf -
cd ghc-6.8.1
./configure
make
sudo make install

またエラーになる。

nstalling: /usr/local/lib/ghc-6.8.1/lib/readline-1.0.1.0
Registering readline-1.0.1.0...
Reading package info from "dist/installed-pkg-config" ... done.
Saving old package config file... done.
Writing new package config file... done.
if ifBuildable/ifBuildable Cabal; then \
          cd Cabal && \
          ../installPackage/installPackage '/Users/hideaki/sw/ghc-6.8.1/utils/ghc-pkg/ghc-pkg.bin' 
'/usr/local/lib/ghc-6.8.1/package.conf' '' '/usr/local' '/usr/local' '/usr/local/bin' '/usr/local/lib/ghc-6.8.1/lib' 
'/usr/local/lib/ghc-6.8.1/lib' '/usr/local/share/ghc-6.8.1' '/usr/local/share/doc/ghc/libraries/$pkgid' 
'/usr/local/share/doc/ghc/libraries/$pkgid' '/usr/local/share/doc/ghc/libraries/$pkgid' ; \
        fi
installPackage: Multiple files with extension buildinfo
make[1]: *** [install.library.Cabal] Error 1
make: *** [install] Error 2

これは、以下で解決する。._buildinfor.buildinfoというくせ者が潜んでいるので削除。

cd libraries/Cabal
rm ._buildinfo2.buildinfo 

もういちど、sudo make installしてghciを試すと、今度は成功する。

hideaki% ghci
GHCi, version 6.8.1: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> 

参考にしたサイト Thanks a lot !!
http://homepage.mac.com/matsuan_tamachan/software/ReadLine.html
http://www.violentlyhappy.org/kazuya/yanetut/2007/12/installing-ghc-681-on-mac-os-x-leopard.html