Home > Backend Development > PHP Tutorial > 64位Ubuntu 14.04上使用musleabi最小化交叉编译Android版PHP7

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

WBOY
Release: 2016-06-23 13:05:23
Original
1769 people have browsed it

https://bitbucket.org/GregorR/musl-cross/downloads
crossx86-arm-linux-musleabi-0.9.11.tar.xz (20MB)

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-7.0.6-arm-linux.xz(1.1MB)

./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'));"

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template