mosh on FreeBSD


Shibuya.lisp#2 に参加した時、いい話を聞いてきたので、FreeBSDでもmoshを
使えないか試してみる。

FreeBSDは、実機にも入っているけど、on VMWARE の方が新しいBSDなので、まず
こちら(FreeBSD 7.1-stable)でやって感触を掴む事にする。

何はなくとも、svn と言う事で、portsから入れる。
次は、moshのソースを頂いてくる。

http://code.google.com/p/mosh-scheme/source/checkout

ここの説明では、格納先が mosh-scheme-read-only となっているが、長い名前
が嫌いな私は、mosh-dev と、大胆(何が?)な場所にしておいた。

で、早速コンパイルに取り掛かるのだが、とりあえず、自分の$home_dir内を、
出力先にしておいた。

[sakae@nil ~/mosh-dev]$ ./configure --prefix=/home/sakae/mine
  :
checking for ranlib... ranlib
checking for gosh... gosh
checking for __gmpz_init in -lgmp... no
configure: error: GNU MP not found, see http://gmplib.org/."For OSX, install GNU MP with "CFLAGS+=-m32 ./configure ABI=32 && make"

あらら、早速足りないものを指摘されちゃったよ。かろうじて gosh は、入って
いたけど、GNU MPとは、何ものぞ?
調べてみたら、ports/math/libgmp4 にある事が分かったので、入れる。
そして、再び configure してみると、やはり同じ所で引っかかる。
これは、きっと入れた場所が見つからないのね、と想像する。

ならば、小手先だけど、

[sakae@nil ~/mosh-dev]$ CPPFLAGS='-I/usr/local/include' LDFLAGS='-L/usr/local/lib' ./configure --prefix=/home/sakae/mine
 :
config.status: executing libtool commands
config.status: executing default commands
[sakae@nil ~/mosh-dev]$

一歩前進したわい。Makefile もめでたく出来たので、コンパイル開始。
随分と時間がかかるので、放置しておいたら、エラーで止まってた。

g++ -DHAVE_CONFIG_H -I. -I ./gc-7.1alpha3/include -I ./onig-5.7.0  -I/usr/local/include -D MONA_SCHEME -D USE_BOEHM_GC -Wall -D MOSH_LIB_PATH="\"/home/sakae/mine/share/mosh/0.0.8\"" -I /home/sakae/mine/include  -g -D_FILE_OFFSET_BITS=64 -Wall -pipe -O3 -momit-leaf-frame-pointer -fomit-frame-pointer -march=i386 -DDEBUG_VERSION -D MONA_SCHEME -D USE_BOEHM_GC -Wall -D MOSH_LIB_PATH="\"/home/sakae/mine/share/mosh/0.0.8\"" -I /home/sakae/mine/include -Igtest-1.2.1 -Igtest-1.2.1/include  -MT libmosh_a-ProcessProcedures.o -MD -MP -MF .deps/libmosh_a-ProcessProcedures.Tpo -c -o libmosh_a-ProcessProcedures.o `test -f 'ProcessProcedures.cpp' || echo './'`ProcessProcedures.cpp
ProcessProcedures.cpp: In function 'scheme::Object scheme::internalForkEx(scheme::VM*, int, const scheme::Object*)':
ProcessProcedures.cpp:93: error: 'SIGINT' was not declared in this scope
ProcessProcedures.cpp:93: error: 'SIG_DFL' was not declared in this scope
ProcessProcedures.cpp:93: error: 'signal' was not declared in this scope
*** Error code 1

Stop in /usr/home/sakae/mosh-dev.
*** Error code 1

これは、svnしたタイミングが悪かったかな?
ひげぽんさんの行動が読めないけど、平日の早朝ならきっと、一区切りついて
いるに違いない。
で、平日の早朝に再び、svn up && make。

やはり、同じ所でエラーが出るなあ。今度はエラーをじっと見る。ソースも見る。
ついでに、man siganal もしてみる。
そうだ、signal.h を追加しよう。

これで、エラーしてた箇所は無事に通過。VM-RUn.cppの所で、時間が止まって
しまったと思うぐらい待たされたけど、先に進んでる。

だけど、やっぱり(?)エラーが出たよ。今度は、
g++ -D MONA_SCHEME -D USE_BOEHM_GC -Wall -D MOSH_LIB_PATH="\"/home/sakae/mine/share/mosh/0.0.8\"" -I /home/sakae/mine/include  -g -D_FILE_OFFSET_BITS=64 -Wall -pipe -O3 -momit-leaf-frame-pointer -fomit-frame-pointer -march=i386 -DDEBUG_VERSION    -L/usr/local/lib -o mosh mosh-main.o libmosh.a ./gc-7.1alpha3/.libs/libgc.a ./onig-5.7.0/.libs/libonig.a -ldl -lgmp
/usr/bin/ld: cannot find -ldl
*** Error code 1

Stop in /usr/home/sakae/mosh-dev.
*** Error code 1

おしい所でエラーだなぁ。 libdl なんて、FreeBSDには、必要無いぽい。
多分、このライブラリーは、dlopen とかで必要なんだろうけど、FreeBSDでは
標準ライブラリーで賄えるようになっている。(man dlopen)

Makefile に定義されてた、-ldl (2箇所)を削除して、先に進もう。
どうでもいいけど、2784行あるMakefileなんて、久しぶりに見ました。
貫禄ある、Makefileだなあ!

これで、どうやら出来たっぽい。
早速、チェックしてみよう。

[sakae@nil ~/mosh-dev]$ make check
 :
make  check-TESTS
Switched to incremental mode
Emulating dirty bits with mprotect/signals
Segfault at 0x8182cd4
Unexpected bus error or segmentation fault
Abort trap (core dumped)
FAIL: gctest
PASS: leaktest
Final heap size is 262144
PASS: middletest
GC_check_heap_block: found smashed heap objects:
0x8180fb8 in or near object at 0x8180f90(tests/smash_test.c:21, sz=40)
        Caller at allocation:
                ##PC##= 0x8048569
GC_check_heap_block: found smashed heap objects:
0x81e6988 in or near object at 0x81e6960(tests/smash_test.c:21, sz=40)
        Caller at allocation:
                ##PC##= 0x8048569
0x8180fb8 in or near object at 0x8180f90(tests/smash_test.c:21, sz=40)
        Caller at allocation:
                ##PC##= 0x8048569
PASS: smashtest
==================================
1 of 4 tests failed
Please report to Hans.Boehm@hp.com
==================================
*** Error code 1

Stop in /usr/home/sakae/mosh-dev/gc-7.1alpha3.
*** Error code 1

あらら、困ったわい。こちらは、どうだ
[sakae@nil ~/mosh-dev]$ make test
 :
Test Running 5/6
** Error(s)
  (begin (cd) (current-directory)) got /usr/home/sakae but /home/sakae expected
*** Error code 255

Stop in /usr/home/sakae/mosh-dev.
[sakae@nil ~/mosh-dev]$

これは微妙だなあ。
[sakae@nil ~/mosh-dev]$ cd /
[sakae@nil /]$ ls -ld home
lrwxr-xr-x  1 root  wheel  8 10 19  2007 home@ -> usr/home

取りあえず、installして試運転
[sakae@nil ~/mine/bin]$ cd
[sakae@nil ~]$ mine/bin/mosh
mosh>(cons 1 '())
(1)
mosh>

一応、動いてるっぽい。