前置作業 & 注意事項
- 產生要移植平台相對應的 standalone toolchain ,參考 Android API level (系統版本) 傳送門
- cross compile relative libs. link
- 修正 cross compile 與 auto conf 期間產生的錯誤
- 注意編譯需將 libs 都編譯成 static mode. (non-dynamic mode) 目的是可以方便使用,缺點是檔案大小會較大,不過動態連結,缺點是在入時會呼叫外部的 *.so 檔,Linux 底下的動態連函式庫。(DLL) 但是手機的路徑與 Linux 預設路徑是不同的,所以使用 static mode 不外部呼叫 DLL 是最保險,不然還要去處理載入外部的路徑問題。
- 下載 lighttpd 與 PHP source code,也可以使用 MEGA 載點的,已經修正錯誤。
- 如果使用自行下載的 source 編譯與 auto conf 發生錯誤,可以自行參考MEGA 載點中的 source 裡的檔案,看是如何修改的。
Lighttpd-1.4.33–a lighweight http server
完成前置作業後,開始使用下面的 android-configure 檔,做 auto conf 產生要編譯 Lighttpd 的 Makefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #!/bin/bash export TOOLCHAIN= /home/lab501/android-toolchain export PATH=$TOOLCHAIN /bin :$PATH export CC=$TOOLCHAIN /bin/arm-linux-androideabi-gcc export RANLIB=$TOOLCHAIN /bin/arm-linux-androideabi-ranlib export STRIP=$TOOLCHAIN /bin/arm-linux-androideabi-strip export CROSS_COMPILING= yes export AR=$TOOLCHAIN /bin/arm-linux-androideabi-ar export LDFLAGS= "-L/home/lab501/pcre-8.34/_install/lib -fPIE -pie" export CFLAGS= '-fPIE' #manual copy pcre.h to /path/to/lighttpd-1.4.33/src/pcre.h . /configure \ --prefix= /home/lab501/lighttpd-1 .4.33 /_install \ --disable-shared \ -- enable -static \ --with-openssl= /home/lab501/openssl-1 .0.1f /_install \ --with-pcre= /home/lab501/pcre-8 .34 /_install \ --with-zlib= /home/lab501/zlib-1 .2.8 /_install \ --without- bzip2 \ --without-lua \ --host=arm-linux-androideabi #make and make install |
PHP-5.6.17– a hypertext preprocessor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #!/bin/bash export TOOLCHAIN= /home/lab501/android-toolchain export PATH=$TOOLCHAIN /bin :$PATH export CC=$TOOLCHAIN /bin/arm-linux-androideabi-gcc export CXX=$TOOLCHAIN /bin/arm-linux-androideabi-g ++ export AR=$TOOLCHAIN /bin/arm-linux-androideabi-ar export LD=$TOOLCHAIN /bin/arm-linux-androideabi-ld export RANLIB=$TOOLCHAIN /bin/arm-linux-androideabi-ranlib export CFLAGS= '-fPIE -pie' export LDFLAGS= '-fPIE -pie' . /configure \ --prefix= /home/lab501/php-5 .6.17 /_install \ -- enable -static \ --disable-shared \ --disable-all \ -- enable -filter \ -- enable -calendar \ -- enable -ctype \ -- enable -dom \ -- enable -exif \ -- enable -fileinfo \ -- enable - ftp \ --with-mhash= "/home/lab501/mhash-0.9.9.9/_install" \ --disable-intl \ --disable-phar \ -- enable -posix \ -- enable -shmop \ -- enable -simplexml \ --disable-sysvmsg \ -- enable -sysvsem \ --disable-sysvshm \ -- enable -tokenizer \ --disable-wddx \ -- enable -xmlreader \ -- enable -xmlwriter \ -- enable -pcntl \ -- enable -soap \ -- enable -cgi \ -- enable -json \ --with-zlib \ -- enable -zip \ --with-mysql=mysqlnd \ -- enable -mysqlnd \ --with-mysqli=mysqlnd \ -- enable -pdo \ --with-pdo-mysql=mysqlnd \ -- enable -libxml \ --with-pdo-sqlite \ --with-sqlite3 \ -- enable -sockets \ -- enable -bcmath \ -- enable -mbstring \ -- enable -mbregex \ -- enable -session \ --disable-ipv6 \ -- enable -opcache=no \ --disable-cli \ --without-pear \ -- enable -fpm \ -- enable - hash \ --with-bz2= "/home/lab501/bzip2-1.0.6/_install" \ --with-zlib- dir = "/home/lab501/zlib-1.2.8/_install" \ --with-libxml- dir = "/home/lab501/libxml2-2.7.6/_install" \ --with-curl= "/home/lab501/curl-7.35.0/_install" \ --with-openssl= "/home/lab501/openssl-1.0.1f/_install" \ --with-jpeg- dir = "/home/lab501/jpeg-9/_install" \ --with-png- dir = "/home/lab501/libpng-1.6.9/_install" \ --with-freetype- dir = "/home/lab501/freetype-2.5.3/_install" \ --with-iconv- dir = "/home/lab501/libiconv-1.14/_install" \ --with-mcrypt= "/home/lab501/libmcrypt-2.5.8/_install" \ --with-pcre- dir = "/home/lab501/pcre-8.34/_install" \ --host=arm-linux-androideabi #make and make install |
[參考文章]
編輯 android-configure bash script file 參考:
Cross Compile lighttpd & PHP for ARM based embdedded device
編譯時遇到錯誤解決方法參考:
(OK)port_php-5.6.14_to_Android-(和lighttpd的集成成功) -沒有基於Android 4.4系統的源碼
[ 額外 PHP 的錯誤 ]
因為有一些 source 裡面,Android toolchain 本身並沒有定義,所以導致會出現 XXX undelclared . 類似錯誤如下:
1 2 3 | /home/lab501/android-cross-compile-16/php-5 .6.17 /ext/mysql/php_mysql .c: In function 'php_mysql_do_connect' : /home/lab501/android-cross-compile-16/php-5 .6.17 /ext/mysql/php_mysql .c:757:39: error: 'ushort' undeclared (first use in this function ) MySG(default_port) = (uint) ntohs((ushort) serv_ptr->s_port); |
解決方法:
修改 /path/to/android-toolchain-standalone/sysroot/usr/include/sys 底下的 types.h
最下面新增:
/* Old compatibility names for C types. */
typedef unsigned short int ushort;
這兩行
錯誤:’S_IREAD’ undeclared
因為缺少 S_IREAD 與 S_WRITE 定義,因此在路徑:/home/lab501/android-toolchain-16/sysroot/usr/include/linux/stat.h 這個的 header 檔加入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #define S_IRWXU 00700 #define S_IRUSR 00400 #define S_IREAD 00400 #define S_IWUSR 00200 #define S_IWRITE 00200 #define S_IXUSR 00100 #define S_IEXEC 00100 #define S_IRWXG 00070 #define S_IRGRP 00040 #define S_IWGRP 00020 #define S_IXGRP 00010 #define S_IRWXO 00007 #define S_IROTH 00004 #define S_IWOTH 00002 #define S_IXOTH 00001 |
因為還有一些錯誤,經修正過了,所以 將 MEGA 載點中的 android-toolchain-9.tar.bz2 裡的 android-toolchain下的 sysroot 整個目錄 對應 /path/to/your-android-toolchain/sysroot 做覆蓋,修正其他已經修改過的錯誤。
若是只想更動修改的檔案,善用 grep 指令,把有修正過的檔案做 copy 即可。例如:
1 | grep you- find -key-words *.h |
[ 後記 ]
- 網路上很多文章也是沒有提到錯誤如何修正,就只有參數如何編寫得比較多,遇到錯誤還是需要上網找解法。
- 這篇文章最主要是補上了 MEGA 下載點可以供其他人在編譯 source code 時遇到錯誤可以參考。
- 我是依照網路上文章的版本做編譯的,並非使用最新的版本,如果要使用最新的版本做編譯,則可以到每個官網去做下載。