PageRenderTime 26ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/Compiling.md

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