填一个坑。关于把ruby编译到android上的一个遗留问题。

恩。如果没记错的话。是好多年前。想把ruby编译到android上运行的问题。我记得那个时候是纠结了一通宵,最后是总算把他跑在了android上。

今天整理一下。


首先 这个教程只限于 ruby1.9.2,为什么?

因为我是过2.1.2。失败!。


首先 先把ruby1.9.2安装上。

./configure

make

sudo make install

一般来讲 = =是没问题的。如果有问题。逐步解决把。这个不在内容内;


首先,重头来看。 其实感觉只要把 gcc 的sysroot 改成NDK中的路径,就应该可以的了。不过事情从是没有那么理想。

./configure 

make

出错!。

但是结果是有问题的。 goolge半天,找到了答案。

先做以下变量定义


export NDK_ROOT=~/android-ndk-r9d
export CFLAGS="-march=armv5te -msoft-float " 
export SYSROOT=$NDK_ROOT/platforms/android-4/arch-arm
export CC="$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -mandroid --sysroot=$SYSROOT"




然后有2个补丁文件。


这个是ruby.patch

diff -u -r ruby-1.9.2-p0/configure ruby-1.9.2-p0.android/configure
--- ruby-1.9.2-p0/configure	2010-08-18 14:56:27.000000000 +0900
+++ ruby-1.9.2-p0.android/configure	2010-08-19 11:36:01.000000000 +0900
@@ -13525,7 +13525,9 @@
   $as_echo_n "(cached) " >&6
 else
   if test "$cross_compiling" = yes; then :
-  as_fn_error "cannot check setpgrp when cross compiling" "$LINENO" 5
+  #as_fn_error "cannot check setpgrp when cross compiling" "$LINENO" 5
+  # hack for Android
+  ac_cv_func_setpgrp_void=yes
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -15046,7 +15048,10 @@
     	LDFLAGS="$LDFLAGS -Zomf"
 			 ;; #(
   *) :
-     	: ${LDSHARED='ld'} ;;
+#     	: ${LDSHARED='ld'} ;;
+# hack for Android
+     	: ${LDSHARED='$(CC) -shared'} ;;
+
 esac
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $rb_cv_dlopen" >&5
 $as_echo "$rb_cv_dlopen" >&6; }
diff -u -r ruby-1.9.2-p0/dir.c ruby-1.9.2-p0.android/dir.c
--- ruby-1.9.2-p0/dir.c	2010-08-09 13:39:57.000000000 +0900
+++ ruby-1.9.2-p0.android/dir.c	2010-08-19 13:17:16.000000000 +0900
@@ -700,8 +700,14 @@
 static VALUE
 dir_set_pos(VALUE dir, VALUE pos)
 {
+/* hack for Android*/
+#ifdef HAVE_SEEKDIR
     dir_seek(dir, pos);
     return pos;
+#else
+    rb_notimplement();
+#endif
+
 }
 
 /*
diff -u -r ruby-1.9.2-p0/eval_intern.h ruby-1.9.2-p0.android/eval_intern.h
--- ruby-1.9.2-p0/eval_intern.h	2010-06-03 18:58:32.000000000 +0900
+++ ruby-1.9.2-p0.android/eval_intern.h	2010-08-19 11:45:39.000000000 +0900
@@ -214,8 +214,12 @@
 void rb_trap_restore_mask(void);
 
 #ifndef CharNext		/* defined as CharNext[AW] on Windows. */
+#ifdef __ANDROID__
+#define CharNext(p) ((p) + 1)
+#else
 #define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE))
 #endif
+#endif
 
 #if defined DOSISH || defined __CYGWIN__
 static inline void
diff -u -r ruby-1.9.2-p0/ext/nkf/nkf-utf8/nkf.h ruby-1.9.2-p0.android/ext/nkf/nkf-utf8/nkf.h
--- ruby-1.9.2-p0/ext/nkf/nkf-utf8/nkf.h	2010-04-22 17:04:13.000000000 +0900
+++ ruby-1.9.2-p0.android/ext/nkf/nkf-utf8/nkf.h	2010-08-19 11:41:13.000000000 +0900
@@ -164,6 +164,10 @@
 # ifndef HAVE_LOCALE_H
 #  define HAVE_LOCALE_H
 # endif
+#elif defined(__ANDROID__)
+# ifndef HAVE_LOCALE_H
+#  define HAVE_LOCALE_H
+# endif
 #else
 # ifndef HAVE_LANGINFO_H
 #  define HAVE_LANGINFO_H
diff -u -r ruby-1.9.2-p0/include/ruby/intern.h ruby-1.9.2-p0.android/include/ruby/intern.h
--- ruby-1.9.2-p0/include/ruby/intern.h	2010-05-01 02:56:23.000000000 +0900
+++ ruby-1.9.2-p0.android/include/ruby/intern.h	2010-08-19 11:02:12.000000000 +0900
@@ -28,6 +28,9 @@
 #endif
 #include "ruby/st.h"
 
+#ifdef __ANDROID__
+#include <sys/select.h>
+#endif
 /*
  * Functions and variables that are used by more than one source file of
  * the kernel.


然后是

ndk.patch

diff -u pthread.h.org pthread.h
--- pthread.h.org	2010-08-16 17:00:54.000000000 +0900
+++ pthread.h	2010-08-16 17:01:25.000000000 +0900
@@ -87,6 +87,7 @@
  */
 #define PTHREAD_COND_INITIALIZER  {0}
 
+#define PAGE_SIZE 0x400
 #define PTHREAD_STACK_MIN (2 * PAGE_SIZE)
 
 #define PTHREAD_CREATE_DETACHED  0x00000001
diff -u linux/in.h.org linux/in.h
--- linux/in.h.org	2010-08-20 10:53:29.000000000 +0900
+++ linux/in.h	2010-08-20 10:53:45.000000000 +0900
@@ -29,7 +29,7 @@
  IPPROTO_RSVP = 46,
  IPPROTO_GRE = 47,
 
- IPPROTO_IPV6 = 41,
+ /*IPPROTO_IPV6 = 41,*/
 
  IPPROTO_ESP = 50,
  IPPROTO_AH = 51,


这2个是补丁文件。


用patch 命令


patch -p0 < ruby.patch


把ndk.patch 放到你的sysroot目录中。

patch -p0 < ndk.patch

然后把ruby.patch放到ruby源文件目录的外面。(记得文件夹名字

执行

patch -p0 < ruby.patch

如果替换出现异常,手动修补一下。


然后。执行。

./configure --host=arm-eabi --disable-ipv6 --prefix=/system/local --enable-shared

make


XDDDDDDDDandroid的ruby.so文件就出来啦。。。。。。。。。。耶!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值