Android版PHPをbuildしてみた
先日のPHP for Android(PFA)から続きますが、CentOS上でAndroid版PHPをbuildし、とりあえずエミュレータと実機(X06HT)で動作するところまで確認できたので、まとめて晒しておきます。
注意
実際は、Android OSにバンドルされているBionic libcとか全然考慮してないので、このままだとダメだと思います。あくまで『とりあえずbuildして動かしてみたレベル』です。
あと、この手順だと、buildされたバイナリがかなり大きい(約11MB)ので、PFAのphpバイナリと差し替えてもOutOfMemoryError("java.lang.OutOfMemoryError: bitmap size exceeds VM budget")が発生します。
環境
手順
1.ARM GNU/Linux用のtoolchainsをダウンロードし、任意のディレクトリに展開
$ wget http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 $ tar jxf arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 $
2.PHPのソースコードをダウンロードし、任意のディレクトリに展開、configure実行
$ tar jxf php-5.3.5.tar.bz2 $ cd php-5.3.5 $ ./configure --disable-all --enable-cli --enable-json --enable-sockets $
3.パッチを当てる。パッチの対象は、Zend/zend_float.hとconfigure後に生成されるMakefile、libtoolの3つ。なお、"/home/shimooka/work/pfa/arm-2010.09"の部分は適宜変更してください。
--- Makefile.orig 2011-02-15 18:58:28.000000000 +0900 +++ Makefile 2011-02-15 19:13:15.000000000 +0900 @@ -17,10 +17,10 @@ SHLIB_SUFFIX_NAME = so SHLIB_DL_SUFFIX_NAME = so SAPI_CLI_PATH = sapi/cli/php -BUILD_CLI = $(LIBTOOL) --mode=link $(CC) -export-dynamic $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS_PROGRAM) $(LDFLAGS) $(PHP_RPATHS) $(PHP_GLOBAL_OBJS) $(PHP_CLI_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $(SAPI_CLI_PATH) +BUILD_CLI = $(LIBTOOL) --mode=link $(CC) -all-static $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS_PROGRAM) $(LDFLAGS) $(PHP_RPATHS) $(PHP_GLOBAL_OBJS) $(PHP_CLI_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $(SAPI_CLI_PATH) INSTALL_CLI = $(mkinstalldirs) $(INSTALL_ROOT)$(bindir); $(INSTALL) -m 0755 $(SAPI_CLI_PATH) $(INSTALL_ROOT)$(bindir)/$(program_prefix)php$(program_suffix)$(EXEEXT) SAPI_CGI_PATH = sapi/cgi/php-cgi -BUILD_CGI = $(LIBTOOL) --mode=link $(CC) -export-dynamic $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS_PROGRAM) $(LDFLAGS) $(PHP_RPATHS) $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $(SAPI_CGI_PATH) +BUILD_CGI = $(LIBTOOL) --mode=link $(CC) -all-static $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS_PROGRAM) $(LDFLAGS) $(PHP_RPATHS) $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $(SAPI_CGI_PATH) PROG_SENDMAIL = /usr/sbin/sendmail JSON_SHARED_LIBADD = PHP_INSTALLED_SAPIS = cli cgi @@ -52,10 +52,10 @@ datarootdir = /usr/local/php sysconfdir = ${prefix}/etc EXEEXT = -CC = gcc +CC = /home/shimooka/work/pfa/arm-2010.09/bin/arm-none-linux-gnueabi-gcc CFLAGS = $(CFLAGS_CLEAN) -prefer-non-pic -static -CFLAGS_CLEAN = -g -O2 -fvisibility=hidden -CPP = gcc -E +CFLAGS_CLEAN = -g -O2 -fvisibility=hidden -mthumb +CPP = /home/shimooka/work/pfa/arm-2010.09/bin/arm-none-linux-gnueabi-gcc -E CPPFLAGS = CXX = CXXFLAGS = -prefer-non-pic -static --- libtool.orig 2011-02-15 18:58:26.000000000 +0900 +++ libtool 2011-02-15 19:09:45.000000000 +0900 @@ -70,9 +70,9 @@ host_os=linux-gnu # The build system. -build_alias=i686-pc-linux-gnu -build=i686-pc-linux-gnu -build_os=linux-gnu +build_alias=arm +build=arm +build_os=arm # An echo program that does not interpret backslashes. echo="echo" @@ -82,13 +82,13 @@ AR_FLAGS="cru" # A C compiler. -LTCC="gcc" +LTCC="/home/shimooka/work/pfa/arm-2010.09/bin/arm-none-linux-gnueabi-gcc" # LTCC compiler flags. LTCFLAGS="-g -O2 -fvisibility=hidden" # A language-specific compiler. -CC="gcc" +CC="/home/shimooka/work/pfa/arm-2010.09/bin/arm-none-linux-gnueabi-gcc" # Is the compiler the GNU C compiler? with_gcc=yes @@ -97,7 +97,7 @@ EGREP="grep -E" # The linker used to build libraries. -LD="/usr/bin/ld" +LD="/home/shimooka/work/pfa/arm-2010.09/bin/arm-none-linux-gnueabi-ld" # Whether we need hard or soft links. LN_S="ln -s" --- Zend/zend_float.h.orig 2010-07-15 09:13:20.000000000 +0900 +++ Zend/zend_float.h 2011-02-15 19:10:28.000000000 +0900 @@ -83,6 +83,11 @@ # endif #endif /* _MSC_VER */ +#undef HAVE__CONTROLFP_S +#undef HAVE__CONTROLFP +#undef HAVE__FPU_SETCW +#undef HAVE_FPU_INLINE_ASM_X86 + #ifdef HAVE__CONTROLFP_S /* float.h defines _controlfp_s */
4.make実行
5.adbを使ってエミュレータにpush
$ adb push sapi/cli/php /data $
6.adb shellから動作確認
$ adb shell # cd /data cd /data # chmod 755 ./php chmod 755 ./php # ./php -v ./php -v PHP 5.3.5 (cli) (built: Feb 15 2011 19:21:17) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies # # ./php -i ./php -i phpinfo() PHP Version => 5.3.5 System => Linux localhost 2.6.29-00177-g24ee4d2 #21 Thu Aug 6 20:39:45 PDT 2009 armv5tejl Build Date => Feb 15 2011 19:17:27 : _ENV["ANDROID_PROPERTY_WORKSPACE"] => 9,32768 PHP License This program is free software; you can redistribute it and/or modify it under the terms of the PHP License as published by the PHP Group and included in the distribution in the file: LICENSE This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. If you did not receive a copy of the PHP license, or have any questions about PHP licensing, please contact license@php.net. # # ./php -ddate.timezone="Asia/Tokyo" -r "echo date('YmdHis') . PHP_EOL;" ./php -ddate.timezone="Asia/Tokyo" -r "echo date('YmdHis') . PHP_EOL;" 20110216121450 #