※やたらぐだぐだですが1.8は動きました。。
むだに1.9試してみる。
$ wget http://ftp.iij.ad.jp/pub/lang/ruby/1.9/ruby-1.9.0-5.tar.bz2 $ cd ruby-1.9.0-5/ $ CC=arm-linux-gnueabi-gcc CFLAGS=--static LDFLAGS=--static ./configure --with-static-linked-ext --host=arm-linux --build=i686-gnu-linux
こんな感じ?? でも途中まで行って
checking whether setpgrp takes no argument... configure: error: cannot check setpgrp when cross compiling
うーむ。
とりあえず1.8で。。
$ wget http://ftp.iij.ad.jp/pub/lang/ruby/1.8/ruby-1.8.7-p72.tar.bz2 $ cd ruby-1.8.7-p72/ $ CC=arm-linux-gnueabi-gcc CFLAGS=--static LDFLAGS=--static ./configure --with-static-linked-ext --host=arm-linux --build=i686-gnu-linux
checking whether setpgrp takes no argument... configure: error: cannot check setpgrp when cross compiling
うぐぐ><
ここでぐぐる。
このエラーの原因は、configure.inでかかれている、autoconfのAC_FUNC_SETPGRPマクロというのが原因です。configure実行中に、プログラムをコンパイルし実行しようとするのですが、今は玄箱用にクロスコンパイルしようとしているので、コンパイルされたプログラムはFreeBSD上で実行できません。
おそらく礼儀正しい訂正方法としては、configure.inのなかのAC_FUNC_SETPGRPをコメントアウトして、autoconfを実行し、configureを生成しなおす、ということになると思いますが、多くの人にとって、その作業はかえって
めんどくさいので
configureを直接書き換えます。乱暴なやりかたですね。実は、別の理由があったりします。それはあとで。
ttt: FreeBSD上で玄箱用tcshをクロスコンパイル
なるほどなるほど。
とりあえず1.9のほうで configure 削ってみた。
$ diff -c configure.bk configure *** configure.bk 2008-12-20 13:38:18.000000000 +0900 --- configure 2008-12-20 13:41:27.000000000 +0900 *************** *** 19238,19308 **** fi - { $as_echo "$as_me:$LINENO: checking whether setpgrp takes no argument" >&5 - $as_echo_n "checking whether setpgrp takes no argument... " >&6; } - if test "${ac_cv_func_setpgrp_void+set}" = set; then - $as_echo_n "(cached) " >&6 - else - if test "$cross_compiling" = yes; then - { { $as_echo "$as_me:$LINENO: error: cannot check setpgrp when cross compiling" >&5 - $as_echo "$as_me: error: cannot check setpgrp when cross compiling" >&2;} - { (exit 1); exit 1; }; } - else - cat >conftest.$ac_ext <<_ACEOF - /* confdefs.h. */ - _ACEOF - cat confdefs.h >>conftest.$ac_ext - cat >>conftest.$ac_ext <<_ACEOF - /* end confdefs.h. */ - $ac_includes_default - int - main () - { - /* If this system has a BSD-style setpgrp which takes arguments, - setpgrp(1, 1) will fail with ESRCH and return -1, in that case - exit successfully. */ - return setpgrp (1,1) != -1; - ; - return 0; - } - _ACEOF - rm -f conftest$ac_exeext - if { (ac_try="$ac_link" - case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; - esac - eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" - $as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; - esac - eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" - $as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_setpgrp_void=no - else - $as_echo "$as_me: program exited with status $ac_status" >&5 - $as_echo "$as_me: failed program was:" >&5 - sed 's/^/| /' conftest.$ac_ext >&5 - - ( exit $ac_status ) - ac_cv_func_setpgrp_void=yes - fi - rm -rf conftest.dSYM - rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext - fi - - - fi { $as_echo "$as_me:$LINENO: result: $ac_cv_func_setpgrp_void" >&5 $as_echo "$ac_cv_func_setpgrp_void" >&6; } if test $ac_cv_func_setpgrp_void = yes; then --- 19238,19243 ----
で、これで configure 通ったっぽい。
$ make GNUmakefile:2: uncommon.mk: そのようなファイルやディレクトリはありません sed 's/{\$([^(){}]*)[^{}]*}//g' common.mk > uncommon.mk ruby -I/home/mori/ruby-1.9.0-5 -rfake ./enc/make_encdb.rb encdb.h.new ./enc enc make: ruby: コマンドが見つかりませんでした make: *** [encdb.h] エラー 127
ちょww ruby入ってないw (Ruby1.9はRubyのビルドにRubyが必要なのです。1.8でOK) apt-get install rubyして気をとりなおしてもう一度。
$ make ... ./ext/extmk.rb:338: undefined method `<<' for nil:NilClass (NoMethodError) make: *** [all] エラー 1
あれ。。該当個所
EXEEXT = CONFIG['EXEEXT'] if CROSS_COMPILING $ruby = $mflags.defined?("MINIRUBY") || CONFIG['MINIRUBY'] elsif sep = config_string('BUILD_FILE_SEPARATOR') $ruby = "$(topdir:/=#{sep})#{sep}miniruby" + EXEEXT else $ruby = '$(topdir)/miniruby' + EXEEXT end $ruby << " -I'$(topdir)'"
どうやら CROSS_COMPILING が "i486-linux" とか入ってて、 そのあとの行が、nil になってるっぽい。
$ruby = $mflags.defined?("MINIRUBY") || CONFIG['MINIRUBY'] || ''
とかやってみたけど、そのあとグダグダなので、やめる。。また1.8で同じようにconfigureを削る。
$ diff -c configure.bk configure *** configure.bk 2008-12-20 14:12:46.000000000 +0900 --- configure 2008-12-20 14:13:49.000000000 +0900 *************** *** 14840,14918 **** fi - { echo "$as_me:$LINENO: checking whether setpgrp takes no argument" >&5 - echo $ECHO_N "checking whether setpgrp takes no argument... $ECHO_C" >&6; } - if test "${ac_cv_func_setpgrp_void+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 - else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot check setpgrp when cross compiling" >&5 - echo "$as_me: error: cannot check setpgrp when cross compiling" >&2;} - { (exit 1); exit 1; }; } - else - cat >conftest.$ac_ext <<_ACEOF - /* confdefs.h. */ - _ACEOF - cat confdefs.h >>conftest.$ac_ext - cat >>conftest.$ac_ext <<_ACEOF - /* end confdefs.h. */ - $ac_includes_default - int - main () - { - /* If this system has a BSD-style setpgrp which takes arguments, - setpgrp(1, 1) will fail with ESRCH and return -1, in that case - exit successfully. */ - return setpgrp (1,1) != -1; - ; - return 0; - } - _ACEOF - rm -f conftest$ac_exeext - if { (ac_try="$ac_link" - case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; - esac - eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; - esac - eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_setpgrp_void=no - else - echo "$as_me: program exited with status $ac_status" >&5 - echo "$as_me: failed program was:" >&5 - sed 's/^/| /' conftest.$ac_ext >&5 - - ( exit $ac_status ) - ac_cv_func_setpgrp_void=yes - fi - rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext - fi - - - fi - { echo "$as_me:$LINENO: result: $ac_cv_func_setpgrp_void" >&5 - echo "${ECHO_T}$ac_cv_func_setpgrp_void" >&6; } - if test $ac_cv_func_setpgrp_void = yes; then - - cat >>confdefs.h <<\_ACEOF - #define SETPGRP_VOID 1 - _ACEOF - - fi - - { echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5 echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6; } if test "${ac_cv_c_bigendian+set}" = set; then --- 14840,14845 ----
make. っとおもったらoops.
./ext/extmk.rb:357: undefined method `<<' for nil:NilClass (NoMethodError)
まーたこれだ。根本的に何か間違ってるっぽいw
またここでぐぐる。
— ruby_comp.sh —
export CC=/usr/local/arm-linux/bin/arm-linux-gcc
export LD=/usr/local/arm-linux/bin/arm-linux-gcc
export AR=/usr/local/arm-linux/bin/arm-linux-ar
export RANLIB=/usr/local/arm-linux/bin/arm-linux-ranlib
export ac_cv_func_getpgrp_void=yes
export ac_cv_func_setpgrp_void=yes
./configure –target=arm-linux –host=arm-linux –enable-wide-getaddrinfo –with-openssl-dir=/PATH/TO/OPENSSL/STATIC/INSTALLATION/usr
— end —
Cross compiling ruby to arm processors – the not so zen way « the zen machine
を参考に、こんなかんじでやってみた。ac_cv_func_setpgrp_void とかあるんじゃん! (これ使うと上記のconfigureの変更は要らない)
$ export CC=/usr/bin/arm-linux-gnueabi-gcc $ export LD=/usr/bin/arm-linux-gnueabi-gcc $ export AR=/usr/bin/arm-linux-gnueabi-ar $ export RANLIB=/usr/bin/arm-linux-gnueabi-ranlib $ export ac_cv_func_getpgrp_void=yes $ export ac_cv_func_setpgrp_void=yes $ ./configure --target=arm-linux --host=arm-linux --enable-wide-getaddrinfo --with-static-linked-ext
でもエラーは同じ。。。もういいやと、351行目を
$ruby = CONFIG['MINIRUBY'] || ''
とかしてみた。すると、こっち(1.8)は通った! (いいのか。。
実機転送してやってみると
$ ./ruby -e'puts "Hello Android."' ./ruby: not found
なんでー;; と思ったら、
$ file ruby ruby: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
ななんと。。dynamically linked。。
正解は、
$ export CC=/usr/bin/arm-linux-gnueabi-gcc $ export LD=/usr/bin/arm-linux-gnueabi-gcc $ export AR=/usr/bin/arm-linux-gnueabi-ar $ export RANLIB=/usr/bin/arm-linux-gnueabi-ranlib $ export CFLAGS=--static $ export LDFLAGS=--static $ export ac_cv_func_getpgrp_void=yes $ export ac_cv_func_setpgrp_void=yes $ ./configure --target=arm-linux --host=arm-linux --enable-wide-getaddrinfo --with-static-linked-ext
のようでした。
実機で実行するとこんな感じ。 AndroidでC言語で書いたネイティブアプリを動かしてみる - daily gimite を全部やってみました。getaddress取れないのはエミュレータと同じっぽいです。
$ ./ruby -e'puts "Hello Android."' Hello Android. $ ./ruby -r socket -e'p IPSocket.getaddress("www.google.co.jp")' -e:1:in `getaddress': getaddrinfo: Name or service not known (SocketError) from -e:1 $ ./ruby -r socket -e'sock= TCPSocket.open("66.249.89.104", 80); sock.write("GET / HTTP/1.0\n\n"); sock.flush; sock.each_line(){ |s| puts s }' HTTP/1.0 302 Found Location: http://www.google.co.jp/ Cache-Control: private Content-Type: text/html; charset=UTF-8 Set-Cookie: PREF=ID=e22fe8a4dcd68ca5:TM=1229721343:LM=1229721343:S=R96CllLWCVRuAiiA; expires=Sun, 19-Dec-2010 21:15:43 GMT; path=/; domain=.google.com Date: Fri, 19 Dec 2008 21:15:43 GMT Server: gws Content-Length: 221 Connection: Close <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.co.jp/">here</A>. </BODY></HTML>
http://typex2.wordpress.com/2009/02/24/android%EF%BC%88htc-dreamtmobile-g1%EF%BC%89%E7%AB%AF%E6%9C%AB%E3%81%A7%E7%84%A1%E9%80%A0%E4%BD%9C%E3%81%ABdmesg%E3%81%AE%E5%87%BA%E5%8A%9B%E7%B5%90%E6%9E%9C%E3%82%92%E3%83%96%E3%83%AD%E3%82%B0/