64位Ubuntu 14.04上使用musleabi最小化交叉编译Android版PHP7

原创
2016/05/22 15:26
阅读数 3.1K

musl-cross-compilers(25MB)
https://bitbucket.org/GregorR/musl-cross/downloads

下载: php-7.0.6-arm-linux.xz(1.1MB)

CC=arm-linux-musleabi-gcc \
CXX=arm-linux-musleabi-g++ \
AR=arm-linux-musleabi-ar \
LD=arm-linux-musleabi-ld \
RANLIB=arm-linux-musleabi-ranlib \
STRIP=arm-linux-musleabi-strip \
CFLAGS="-Os" \
CXXFLAGS="-Os" \
./configure \
--host=arm-linux-musleabi \
--prefix=/opt/phpdroid/php \
--disable-all \
--enable-json \
--enable-pdo \
--with-sqlite3 \
--with-pdo-sqlite

PHP源代码自带PCRE库,编译时不依赖外部PCRE库,所以不需要额外编译PCRE库和配置CPPFLAGS和LDFLAGS参数:
CPPFLAGS="-I/png/dev/android/compiled/usr/include -I/png/dev/android/compiled/usr/usr/include" \
LDFLAGS="-static -L/png/dev/android/compiled/usr/lib -L/png/dev/android/compiled/usr/usr/lib" \

sed -i "s{/bin/sh{/system/bin/sh{" ext/standard/proc_open.c
sed -i "s{-export-dynamic{-all-static{" Makefile

缺 sed -i "s{-export-dynamic{-all-static{" Makefile 编译后:
./php -v 返回 -bash: ./php: No such file or directory
file ./php 返回 php: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
正常应该返回 php: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped

time nice -20 make -j2
make install

arm-linux-musleabi-strip /opt/phpdroid/php/bin/php
xz -z -k -9 /opt/phpdroid/php/bin/php
strip后不到4MB,xz压缩后约1MB.
比现在php.xz的3.7MB小了2.7MB, PHPDroid APK包能从5.7MB缩小到3MB.

./php -m
[PHP Modules]
Core
date
json
pcre
PDO
pdo_sqlite
Reflection
SPL
sqlite3
standard

./php -r 'print_r(get_defined_functions());' > func.txt
./php -r 'print_r(get_declared_classes());' > class.txt
可见包含了下面常用到的一些功能:
pdo_sqlite
json_encode/json_decode
file_get_contents/file_put_contents
注意:没有OpenSSL支持,file_put_contents是不支持HTTPS协议的.
./php -r "file_put_contents('logo.gif',file_get_contents('https://www.baidu.com/img/bdlogo.gif'));"

展开阅读全文
加载中
点击加入讨论🔥(2) 发布并加入讨论🔥
2 评论
10 收藏
4
分享
返回顶部
顶部