|
| 1 | +# Setup the development environment |
| 2 | + |
| 3 | +The first step is to setup a good and viable development environment you'll be able to compile application for Android ARM platform. |
| 4 | + |
| 5 | +## Install ARM Toolchain |
| 6 | + |
| 7 | +I am using CodeSourery toolchain for cross compiling please make sure you have already installed it |
| 8 | +Run to make sure it is properly configured |
| 9 | + |
| 10 | +``` |
| 11 | +arm-none-linux-gnueabi-gcc -v |
| 12 | +``` |
| 13 | +## Compiling GLibc |
| 14 | + |
| 15 | +Download and extract Glibc and open `./glibc-2.19/resolv/resolv.h` and change `#define _PATH_RESCONF "/etc/resolv.cof"` to `#define _PATH_RESCONF "/data/data/org.opendroidphp/etc/resolv.conf"` and run the follwing command to cross compile glibc |
| 16 | + |
| 17 | +> mkdir glibc_build && cd glibc_build |
| 18 | +>../glibc-2.19/configure \ |
| 19 | +> --host=arm-none-linux-gnueabi \ |
| 20 | +> --disable-build-nscd --enable-add-ons \ |
| 21 | +> --prefix=$HOME/droidphp/glibc/usr \ |
| 22 | +> --enable-static-nss --with-tls \ |
| 23 | +> --with-ports="nptl, ports" |
| 24 | +> make && make install |
| 25 | +
|
| 26 | +## Setup toolchain |
| 27 | +Use to following configuration when you are cross compiling |
| 28 | +Create a filename `crosstool.sh` and include it before whenever you need to cross compile for ARM |
| 29 | + |
| 30 | + |
| 31 | +``` |
| 32 | +#!/bin/bash |
| 33 | +PROJECT_BASE=$(pwd); |
| 34 | +REPOSITORY=$PROJECT_BASE/download |
| 35 | +ROOTFS=$PROJECT_BASE/compiled/usr |
| 36 | +## edit this |
| 37 | +export SYSROOT_SYS="$HOME/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/arm-none-linux-gnueabi/libc" |
| 38 | +export SYSROOT_GLIBC="$HOME/droidphp/glibc" |
| 39 | +export CC="arm-none-linux-gnueabi-gcc" |
| 40 | +export CXX="arm-none-linux-gnueabi-g++" |
| 41 | +export RANLIB="arm-none-linux-gnueabi-ranlib" |
| 42 | +export STRIP='arm-none-linux-gnueabi-strip' |
| 43 | +export LD='arm-none-linux-gnueabi-ld' |
| 44 | +export AR='arm-none-linux-gnueabi-ar' |
| 45 | +export HOST="arm-none-linux-gnueabi" |
| 46 | +export CPPFLAGS="-I${ROOTFS}/include" |
| 47 | +export LDFLAGS="-L${ROOFTS}/lib" |
| 48 | +``` |
| 49 | + |
| 50 | + |
| 51 | +## Compiling Zlib |
| 52 | + |
| 53 | +``` |
| 54 | +cd $REPOSITORY && wget http://zlib.net/zlib-1.2.8.tar.gz |
| 55 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/zlib-1.2.8.tar.gz && cd ./zlib-1.2.8 |
| 56 | +CFLAGS="--sysroot=$SYSROOT_SYS" ./configure \ |
| 57 | +--prefix="$ROOTFS" \ |
| 58 | +--static |
| 59 | +make && make install |
| 60 | +``` |
| 61 | + |
| 62 | +## Compiling Bz2 |
| 63 | + |
| 64 | +``` |
| 65 | +cd $REPOSITORY && wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz |
| 66 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/bzip2-1.0.6.tar.gz && cd ./bzip2-1.0.6 |
| 67 | +make install PREFIX=$ROOTFS |
| 68 | +``` |
| 69 | + |
| 70 | +## Compiling OpenSSL |
| 71 | + |
| 72 | +``` |
| 73 | +cd $REPOSITORY && wget https://www.openssl.org/source/openssl-1.0.1f.tar.gz |
| 74 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/openssl-1.0.1f.tar.gz && cd ./openssl-1.0.1f |
| 75 | +OPENSSL_TARGET="linux-armv4" |
| 76 | +CFLAGS="--sysroot=$SYSROOT_GLIBC -static" ./Configure \ |
| 77 | +$OPENSSL_TARGET no-shared \ |
| 78 | +--prefix="/usr" \ |
| 79 | +--openssldir="$ROOTFS" \ |
| 80 | +--with-zlib-lib="$ROOTFS/lib" \ |
| 81 | +--with-zlib-include="$ROOTFS/include" make && make INSTALL_PREFIX=$ROOTFS install |
| 82 | +``` |
| 83 | + |
| 84 | +## Compiling CURL |
| 85 | + |
| 86 | +``` |
| 87 | +cd $REPOSITORY && wget http://curl.haxx.se/download/curl-7.35.0.tar.gz |
| 88 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/curl-7.35.0.tar.gz && cd ./curl-7.35.0 |
| 89 | +CC="arm-none-linux-gnueabi-gcc --sysroot=$SYSROOT_GLIBC" \ |
| 90 | +CXX="arm-none-linux-gnueabi-g++ --sysroot=$SYSROOT_GLIBC" \ |
| 91 | +CPPFLAGS="-I$ROOTFS/include" \ |
| 92 | +LDFLAGS="-L$ROOTFS/lib --static" \ |
| 93 | +./configure --prefix="$ROOTFS" \ |
| 94 | +--enable-zlib \ |
| 95 | +--disable-shared \ |
| 96 | +--without-ssl \ |
| 97 | +--enable-static \ |
| 98 | +--host=x86_64 |
| 99 | +make && make install |
| 100 | +``` |
| 101 | + |
| 102 | +## Compiling Iconv |
| 103 | + |
| 104 | +``` |
| 105 | +cd $REPOSITORY && wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz |
| 106 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/libiconv-1.14.tar.gz && cd ./libiconv-1.14 |
| 107 | +./configure \ |
| 108 | +--prefix="$ROOTFS" \ |
| 109 | +--enable-static \ |
| 110 | +--disable-shared \ |
| 111 | +--host=$HOST |
| 112 | +make && make install |
| 113 | +``` |
| 114 | + |
| 115 | +## Compiling ncurses |
| 116 | + |
| 117 | +``` |
| 118 | +cd $REPOSITORY && wget ftp://invisible-island.net/ncurses/ncurses-5.9.tar.gz |
| 119 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/ncurses-5.9.tar.gz && cd ./ncurses-5.9 |
| 120 | +./configure \ |
| 121 | +--prefix="$ROOTFS" \ |
| 122 | +--disable-widec \ |
| 123 | +--disable-ext-funcs \ |
| 124 | +--without-cxx-binding \ |
| 125 | +--without-cxx \ |
| 126 | +--without-shared \ |
| 127 | +--without-ada \ |
| 128 | +--without-tests \ |
| 129 | +--without-debug \ |
| 130 | +--host=$HOST && make && make install |
| 131 | +``` |
| 132 | + |
| 133 | +## Compiling mhash |
| 134 | + |
| 135 | +``` |
| 136 | +cd $REPOSITORY && wget ftp://invisible-island.net/ncurses/ncurses-5.9.tar.gz |
| 137 | +cd $PROJECT_BASE/build && tar -xjvf $REPOSITORY/mhash-0.9.9.9.tar.bz2 && cd ./mhash-0.9.9.9 |
| 138 | +ac_cv_func_malloc_0_nonnull=yes \ |
| 139 | +CPPFLAGS="-I$ROOTFS/include" LDFLAGS="-L$ROOTFS/lib" \ |
| 140 | +./configure --prefix=$ROOTFS \ |
| 141 | +--disable-shared \ |
| 142 | +--enable-static --host=$HOST && make && make install |
| 143 | +``` |
| 144 | + |
| 145 | +## Compiling libmcrypt |
| 146 | + |
| 147 | +``` |
| 148 | +cd $PROJECT_BASE/build && tar -xjvf $REPOSITORY/libmcrypt-2.5.8.tar.bz2 && cd ./libmcrypt-2.5.8 |
| 149 | +ac_cv_type_unsigned_long_int=no ac_cv_sizeof_unsigned_int=no \ |
| 150 | +ac_cv_sizeof_unsigned_short_int=no ac_cv_sizeof_unsigned_char=no \ |
| 151 | +ac_cv_func_malloc_0_nonnull=yes \ |
| 152 | +ac_cv_func_realloc_0_nonnull=yes \ |
| 153 | +CPPFLAGS="-I$ROOTFS/include" LDFLAGS="-L$ROOTFS/lib" \ |
| 154 | +./configure \ |
| 155 | +--prefix=$ROOTFS \ |
| 156 | +--host=$HOST \ |
| 157 | +--with-mhash \ |
| 158 | +--enable-static \ |
| 159 | +--disable-shared |
| 160 | +# hack to bypass Cannot find a 32,16 bit integer in your system |
| 161 | +sed -i "s{SIZEOF_UNSIGNED_CHAR no{SIZEOF_UNSIGNED_CHAR 1{" config.h |
| 162 | +sed -i "s{SIZEOF_UNSIGNED_INT no{SIZEOF_UNSIGNED_INT 4{" config.h |
| 163 | +sed -i "s{SIZEOF_UNSIGNED_LONG_INT 0{SIZEOF_UNSIGNED_LONG_INT 4{" config.h |
| 164 | +sed -i "s{SIZEOF_UNSIGNED_SHORT_INT no{SIZEOF_UNSIGNED_SHORT_INT 2{" config.h |
| 165 | +#make clean |
| 166 | +make && make install |
| 167 | +``` |
| 168 | + |
| 169 | +## Compiling PCRE |
| 170 | + |
| 171 | +``` |
| 172 | +cd $REPOSITORY && wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz |
| 173 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/pcre-8.34.tar.gz && cd ./pcre-8.34 |
| 174 | +./configure \ |
| 175 | +--prefix="$ROOTFS" \ |
| 176 | +--disable-cpp \ |
| 177 | +--host=$HOST |
| 178 | +make && make install |
| 179 | +``` |
| 180 | + |
| 181 | +## Compiling libpng |
| 182 | + |
| 183 | +``` |
| 184 | +cd $REPOSITORY && wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.9.tar.gz?download |
| 185 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/libpng-1.6.9.tar.gz && cd ./libpng-1.6.9 |
| 186 | +./configure \ |
| 187 | +CPPFLAGS="-mfpu=neon -I$ROOTFS/include" \ |
| 188 | +LDFLAGS="-L$ROOTFS/lib" \ |
| 189 | +--prefix=$ROOTFS \ |
| 190 | +--host=$HOST |
| 191 | +make && make install |
| 192 | +``` |
| 193 | + |
| 194 | +## Compiling libjpeg |
| 195 | + |
| 196 | +``` |
| 197 | +cd $REPOSITORY && wget http://www.ijg.org/files/jpegsrc.v9.tar.gz |
| 198 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/jpegsrc.v9.tar.gz && cd ./jpeg-9 |
| 199 | +./configure \ |
| 200 | +--prefix=$ROOTFS \ |
| 201 | +--host=$HOST |
| 202 | +make && make install |
| 203 | +``` |
| 204 | + |
| 205 | +## Compiling readline |
| 206 | + |
| 207 | +``` |
| 208 | +cd $REPOSITORY && wget http://ftp.gnu.org/gnu/readline/readline-6.2.tar.gz |
| 209 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/readline-6.2.tar.gz && cd ./readline-6.2 |
| 210 | +./configure --prefix="$ROOTFS" \ |
| 211 | +--with-curses="$ROOTFS" \ |
| 212 | +--host=$HOST |
| 213 | +make && make install |
| 214 | +``` |
| 215 | + |
| 216 | +## Compiling libxml2 |
| 217 | + |
| 218 | +``` |
| 219 | +cd $REPOSITORY && wget ftp://xmlsoft.org/libxml2/libxml2-git-snapshot.tar.gz |
| 220 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/libxml2-git-snapshot.tar.gz && cd ./libxml2-2.9.1 |
| 221 | +./configure --prefix="$ROOTFS" \ |
| 222 | +--with-readline="$ROOTFS" \ |
| 223 | +--with-iconv="$ROOTFS" \ |
| 224 | +--with-zlib="$ROOTFS" \ |
| 225 | +--without-python \ |
| 226 | +--host=$HOST |
| 227 | +make && make install |
| 228 | +``` |
| 229 | + |
| 230 | +## Compiling freetype |
| 231 | + |
| 232 | +``` |
| 233 | +cd $REPOSITORY && wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz |
| 234 | +cd $PROJECT_BASE/build && tar -xzvf $REPOSITORY/freetype-2.5.2.tar.gz && cd ./freetype-2.5.2 |
| 235 | +LIBPNG_CFLAGS="-L$ROOTFS/include" \ |
| 236 | +LIBPNG_LDFLAGS="-L$ROOTFS/lib" \ |
| 237 | +CPPFLAGS="-I$ROOTFS/include" \ |
| 238 | +LDFLAGS="-L$ROOTFS/lib" \ |
| 239 | +./configure \ |
| 240 | +--prefix=$ROOTFS \ |
| 241 | +--host=$HOST && make && make install |
| 242 | +``` |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | +## Compiling LIGHTTPD |
| 247 | + |
| 248 | +``` |
| 249 | +cd $REPOSITORY && wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.34.tar.gz |
| 250 | +cd $PROJECT_BASE/build && lighttpd-1.4.34.tar.gz && cd ./lighttpd-1.4.34 |
| 251 | +export CROSS_COMPILING=yes |
| 252 | +export PCRECONFIG=$ROOTFS/bin/pcre-config |
| 253 | +export CFLAGS="-DLIGHTTPD_STATIC -I$ROOTFS/include " |
| 254 | +export LDFLAGS="-L$ROOTFS/lib" |
| 255 | +#export LUA_LIBS="-L$ROOTFS/lib" |
| 256 | +#export LUA_CFLAGS="-I$ROOTFS/include" |
| 257 | +## hack the lighttpd build system |
| 258 | +## manually copy `droidphp/diffs/lighttpd_embedded_arm_support.diff` to `lighttpd-1.4.xx/` |
| 259 | +patch -p1 < lighttpd_embedded_arm_support.diff |
| 260 | +LIBS="-lpcre -lz -ldl" \ |
| 261 | +CC="arm-none-linux-gnueabi-gcc -static --sysroot=$SYSROOT_GLIBC" ./configure \ |
| 262 | +--prefix="$ROOTFS/lighttpd" \ |
| 263 | +--disable-shared \ |
| 264 | +--enable-static \ |
| 265 | +--with-openssl="$ROOTFS/usr" \ |
| 266 | +--with-libiconv=$ROOTFS \ |
| 267 | +--disable-rpath \ |
| 268 | +--with-pcre \ |
| 269 | +--with-sysroot=$SYSROOT_GLIBC \ |
| 270 | +--with-zlib \ |
| 271 | +--without-bzip2 \ |
| 272 | +--without-lua \ |
| 273 | +--host=$HOST |
| 274 | +make CC="arm-none-linux-gnueabi-gcc -static --sysroot=$SYSROOT_GLIBC" \ |
| 275 | +CXX="arm-none-linux-gnueabi-g++ -static --sysroot=$SYSROOT_GLIBC" |
| 276 | +make install |
| 277 | +``` |
| 278 | + |
| 279 | + |
| 280 | +## Compiling PHP |
| 281 | + |
| 282 | +``` |
| 283 | +cd $REPOSITORY && wget http://www.php.net/get/php-5.5.9.tar.bz2/from/a/mirror |
| 284 | +cd $PROJECT_BASE/build && tar -xjvf $REPOSITORY/php-5.5.9.tar.bz2 && cd ./php-5.5.9 |
| 285 | +# make clean |
| 286 | +CC="arm-none-linux-gnueabi-gcc --sysroot=$SYSROOT_GLIBC" \ |
| 287 | +CXX="arm-none-linux-gnueabi-g++ --sysroot=$SYSROOT_GLIBC" \ |
| 288 | +LDFLAGS="-static -I$ROOTFS/lib -L$ROOTFS/usr/lib" \ |
| 289 | +CFLAGS="-I$ROOTFS/include -I$ROOTFS/usr/include" ./configure \ |
| 290 | +--prefix=$ROOTFS/php \ |
| 291 | +--enable-static \ |
| 292 | +--disable-all \ |
| 293 | +--enable-filter \ |
| 294 | +--enable-calendar \ |
| 295 | +--enable-ctype \ |
| 296 | +--enable-dom \ |
| 297 | +--enable-exif \ |
| 298 | +--enable-fileinfo \ |
| 299 | +--enable-ftp \ |
| 300 | +--with-mhash="$ROOTFS/usr" \ |
| 301 | +--disable-intl \ |
| 302 | +--disable-phar \ |
| 303 | +--enable-posix \ |
| 304 | +--enable-shmop \ |
| 305 | +--enable-simplexml \ |
| 306 | +--enable-sysvmsg \ |
| 307 | +--enable-sysvsem \ |
| 308 | +--enable-tokenizer \ |
| 309 | +--disable-wddx \ |
| 310 | +--enable-xmlreader \ |
| 311 | +--enable-xmlwriter \ |
| 312 | +--enable-opcache=no \ |
| 313 | +--enable-pcntl \ |
| 314 | +--enable-soap \ |
| 315 | +--enable-cgi \ |
| 316 | +--enable-json \ |
| 317 | +--with-zlib \ |
| 318 | +--enable-zip \ |
| 319 | +--with-mysql \ |
| 320 | +--enable-mysqlnd \ |
| 321 | +--with-mysqli=mysqlnd \ |
| 322 | +--enable-pdo \ |
| 323 | +--with-pdo-mysql=mysqlnd \ |
| 324 | +--enable-libxml \ |
| 325 | +--with-pdo-sqlite \ |
| 326 | +--with-sqlite3 \ |
| 327 | +--enable-sockets \ |
| 328 | +--enable-bcmath \ |
| 329 | +--enable-mbstring \ |
| 330 | +--enable-mbregex \ |
| 331 | +--enable-session \ |
| 332 | +--with-zlib-dir="$ROOTFS" \ |
| 333 | +--with-libxml-dir="$ROOTFS" \ |
| 334 | +--with-curl="$ROOTFS" \ |
| 335 | +--with-openssl="$ROOTFS/usr" \ |
| 336 | +--with-jpeg-dir="$ROOTFS" \ |
| 337 | +--with-png-dir="$ROOTFS" \ |
| 338 | +--with-freetype-dir="$ROOTFS" \ |
| 339 | +--with-iconv-dir="$ROOTFS" \ |
| 340 | +--with-mcrypt="$ROOTFS" \ |
| 341 | +--host=$HOST |
| 342 | +## hack |
| 343 | +sed -ie "s{ext/mysqlnd/php_mysqlnd_config.h{config.h{" ext/mysqlnd/mysqlnd_portability.h |
| 344 | +sed -i "s{-export-dynamic{-all-static{" Makefile |
| 345 | +sed -i "s{-I/usr/include{ {" Makefile |
| 346 | +make && make install |
| 347 | +``` |
| 348 | + |
| 349 | +## Compiling MSMTP |
| 350 | + |
| 351 | +``` |
| 352 | +cd $REPOSITORY && wget http://www.php.net/get/php-5.5.9.tar.bz2/from/a/mirror |
| 353 | +cd $PROJECT_BASE/build && tar -xjvf $REPOSITORY/msmtp-1.4.31.tar.bz2 &&cd ./msmtp-1.4.31 |
| 354 | +ac_cv_sys_file_offset_bits=unknown \ |
| 355 | +libssl_CFLAGS="-I$ROOTFS/usr/include" \ |
| 356 | +libssl_LDFLAGS="-L$ROOTFS/usr/lib" \ |
| 357 | +libssl_LIBS="-lssl -lcrypto" \ |
| 358 | +CPPFLAGS="-I$ROOTFS/include -I$ROOTFS/usr/include" \ |
| 359 | +LDFLAGS="-L$ROOTFS/lib -L$ROOTFS/usr/lib" LIBS="-ldl" ./configure \ |
| 360 | +--prefix=$ROOTFS/msmstp \ |
| 361 | +--host=$HOST \ |
| 362 | +--with-libiconv-prefix="$ROOTFS" \ |
| 363 | +--with-ssl=openssl |
| 364 | +make CFLAGS="-static" \ |
| 365 | +CC="arm-none-linux-gnueabi-gcc --sysroot=$SYSROOT_GLIBC" \ |
| 366 | +CPP="arm-none-linux-gnueabi-g++ --sysroot=$SYSROOT_GLIBC" && make install |
| 367 | +``` |
| 368 | + |
| 369 | +## Author |
| 370 | + |
| 371 | +* [Shushant Kumar](http://github.com/shushant) |
| 372 | + |
| 373 | +## License |
| 374 | + |
| 375 | +* [Apache Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) |
| 376 | + |
| 377 | +## Contributing |
| 378 | + |
| 379 | +Please fork this repository and contribute back using |
| 380 | +[pull requests](https://github.com/droidphp/droidphp/pulls). |
| 381 | + |
| 382 | +Any contributions, large or small, major features, bug fixes, additional |
| 383 | +language translations, unit/integration tests are welcomed and appreciated |
| 384 | +but will be thoroughly reviewed and discussed. |
0 commit comments