check-extensions.sh 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/sh
  2. # Here are 3 steps in configuration of extensions
  3. # before_configure
  4. # in_configure
  5. # after_configure
  6. self_dir=$(cd "$(dirname "$0")";pwd)
  7. php_dir=$(find $self_dir/source -name "php-*" -type d | tail -n1)
  8. function do_xml_compiler() {
  9. cd $self_dir/source/xz-* && \
  10. ./configure --enable-static=yes && \
  11. make -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
  12. make install && \
  13. echo "xz compiled!" && sleep 2s && \
  14. cd ../libxml2-* && \
  15. ./configure --prefix=/usr --with-lzma --without-python && \
  16. make -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
  17. make install && \
  18. echo "libxml2 compiled!" && sleep 2s
  19. }
  20. function do_libzip_compiler() {
  21. cd $self_dir/source/libzip-* && \
  22. mkdir build && \
  23. cd build && \
  24. cmake -DBUILD_SHARED_LIBS=no .. -Wno-dev -DENABLE_BZIP2=no -DENABLE_LZMA=no && \
  25. make LDFLAGS="-llzma -lbz2" -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
  26. make install && \
  27. echo "libzip compiled!" && sleep 2s
  28. }
  29. function do_curl_compiler() {
  30. cd $self_dir/source/curl-* && \
  31. CC=gcc CXX=g++ CFLAGS=-fPIC CPPFLAGS=-fPIC ./configure \
  32. --without-nghttp2 \
  33. --with-ssl=/usr \
  34. --with-pic=pic \
  35. --enable-ipv6 \
  36. --enable-shared=no \
  37. --without-libidn2 \
  38. --disable-ldap \
  39. --without-libpsl \
  40. --without-lber \
  41. --enable-ares && \
  42. make -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
  43. make install && \
  44. echo "curl compiled!" && \
  45. cat "$self_dir/ac_override_1" "$php_dir/ext/curl/config.m4" "$self_dir/ac_override_2" > /tmp/aa && \
  46. mv /tmp/aa "$php_dir/ext/curl/config.m4"
  47. }
  48. function do_copy_extension() {
  49. ext_dir=$(find $self_dir/source -name "*$1-*" -type d | tail -n1)
  50. mv $ext_dir $php_dir/ext/$1
  51. if [ $? != 0 ]; then
  52. echo "Compile error! ext: $1, ext_dir=$ext_dir"
  53. exit 1
  54. fi
  55. }
  56. function check_before_configure() {
  57. list=$(cat "$self_dir/extensions.txt" | grep -v "^#" | grep -v "^$")
  58. xml_sign="no"
  59. for loop in $list
  60. do
  61. case $loop in
  62. bcmath) ;;
  63. calendar) ;;
  64. ctype) ;;
  65. exif) ;;
  66. filter) ;;
  67. fileinfo) ;;
  68. gd) ;;
  69. hash) ;;
  70. iconv) ;;
  71. json) ;;
  72. mbstring) ;;
  73. mysqlnd) ;;
  74. openssl) ;;
  75. pcntl) ;;
  76. pdo) ;;
  77. pdo_mysql) ;;
  78. pdo_sqlite) ;;
  79. phar) ;;
  80. posix) ;;
  81. shmop) ;;
  82. sockets) ;;
  83. sqlite3) ;;
  84. tokenizer) ;;
  85. zlib) ;;
  86. zip)
  87. if [ ! -f "$self_dir/source/.libzip_compiled" ]; then
  88. do_libzip_compiler
  89. touch "$self_dir/source/.libzip_compiled"
  90. fi
  91. if [ $? != 0 ]; then
  92. echo "Compile libzip error!"
  93. exit 1
  94. fi
  95. ;;
  96. curl)
  97. if [ ! -f "$self_dir/source/.curl_compiled" ]; then
  98. do_curl_compiler
  99. touch "$self_dir/source/.curl_compiled"
  100. fi
  101. if [ $? != 0 ]; then
  102. echo "Compile curl error!"
  103. exit 1
  104. fi
  105. ;;
  106. dom|xml|libxml|xmlreader|xmlwriter|simplexml|soap)
  107. if [ "$xml_sign" = "no" ]; then
  108. if [ ! -f "$self_dir/source/.xml_compiled" ]; then
  109. do_xml_compiler
  110. touch "$self_dir/source/.xml_compiled"
  111. fi
  112. if [ $? != 0 ]; then
  113. echo "Compile xml error!"
  114. exit 1
  115. fi
  116. xml_sign="yes"
  117. fi
  118. ;;
  119. inotify) do_copy_extension inotify ;;
  120. redis) do_copy_extension redis ;;
  121. swoole) do_copy_extension swoole ;;
  122. mongodb) do_copy_extension mongodb ;;
  123. event) do_copy_extension event ;;
  124. esac
  125. done
  126. }
  127. function check_in_configure() {
  128. php_configure=""
  129. list=$(cat "$self_dir/extensions.txt" | sed 's/#.*//g' | sed -e 's/[ ]*$//g' | grep -v "^\s*$")
  130. for loop in $list
  131. do
  132. case $loop in
  133. bcmath) php_configure="$php_configure --enable-bcmath" ;;
  134. calendar) php_configure="$php_configure --enable-calendar" ;;
  135. ctype) php_configure="$php_configure --enable-ctype" ;;
  136. curl) php_configure="$php_configure --with-curl" ;;
  137. dom) php_configure="$php_configure --enable-dom" ;;
  138. exif) php_configure="$php_configure --enable-exif" ;;
  139. event) php_configure="$php_configure --with-event-core --with-event-extra --with-event-openssl" ;;
  140. filter) php_configure="$php_configure --enable-filter" ;;
  141. fileinfo) php_configure="$php_configure --enable-fileinfo" ;;
  142. gd)
  143. case $1 in
  144. 7.3.*|7.2.*) php_configure="$php_configure --with-gd" ;;
  145. 7.4.*|8.*) php_configure="$php_configure --enable-gd" ;;
  146. esac
  147. ;;
  148. hash)
  149. case $1 in
  150. 7.3.*|7.2.*) php_configure="$php_configure --enable-hash" ;;
  151. esac
  152. ;;
  153. iconv) php_configure="$php_configure --with-iconv" ;;
  154. inotify) php_configure="$php_configure --enable-inotify" ;;
  155. json)
  156. case $1 in
  157. 7.*) php_configure="$php_configure --enable-json" ;;
  158. esac
  159. ;;
  160. libxml)
  161. case $1 in
  162. 7.3.*|7.2.*) php_configure="$php_configure --enable-libxml" ;;
  163. 7.4.*|8.*) php_configure="$php_configure --with-libxml" ;;
  164. esac
  165. ;;
  166. mbstring) php_configure="$php_configure --enable-mbstring" ;;
  167. mongodb) php_configure="$php_configure --enable-mongodb" ;;
  168. mysqlnd) php_configure="$php_configure --enable-mysqlnd" ;;
  169. openssl) php_configure="$php_configure --with-openssl --with-openssl-dir=/usr" ;;
  170. pcntl) php_configure="$php_configure --enable-pcntl" ;;
  171. pdo) php_configure="$php_configure --enable-pdo" ;;
  172. pdo_mysql) php_configure="$php_configure --with-pdo-mysql=mysqlnd" ;;
  173. phar) php_configure="$php_configure --enable-phar" ;;
  174. posix) php_configure="$php_configure --enable-posix" ;;
  175. redis) php_configure="$php_configure --enable-redis --disable-redis-session" ;;
  176. shmop) php_configure="$php_configure --enable-shmop" ;;
  177. simplexml) php_configure="$php_configure --enable-simplexml" ;;
  178. sockets) php_configure="$php_configure --enable-sockets" ;;
  179. soap) php_configure="$php_configure --enable-soap" ;;
  180. sqlite3) php_configure="$php_configure --with-sqlite3" ;;
  181. pdo_sqlite) php_configure="$php_configure --with-pdo-sqlite" ;;
  182. swoole)
  183. php_configure="$php_configure --enable-swoole"
  184. have_openssl=$(echo $list | grep openssl)
  185. if [ "$have_openssl" != "" ]; then
  186. php_configure="$php_configure --enable-openssl --with-openssl --with-openssl-dir=/usr"
  187. fi
  188. have_hash=$(echo $list | grep hash)
  189. if [ "$have_hash" = "" ]; then
  190. case $1 in
  191. 7.3.*|7.2.*) php_configure="$php_configure --enable-hash" ;;
  192. esac
  193. fi
  194. ;;
  195. tokenizer) php_configure="$php_configure --enable-tokenizer" ;;
  196. xml) php_configure="$php_configure --enable-xml" ;;
  197. xmlreader) php_configure="$php_configure --enable-xmlreader" ;;
  198. xmlwriter) php_configure="$php_configure --enable-xmlwriter" ;;
  199. zlib) php_configure="$php_configure --with-zlib" ;;
  200. zip) php_configure="$php_configure --with-zip" ;;
  201. *)
  202. echo "Unsupported extension '$loop' !" >&2
  203. exit 1
  204. ;;
  205. esac
  206. done
  207. echo $php_configure
  208. }
  209. function check_after_configure() {
  210. list=$(cat "$self_dir/extensions.txt" | grep -v "^#" | grep -v "^$")
  211. for loop in $list
  212. do
  213. case $loop in
  214. swoole)
  215. sed -ie 's/swoole_clock_gettime(CLOCK_REALTIME/clock_gettime(CLOCK_REALTIME/g' "$php_dir/ext/swoole/include/swoole.h"
  216. sed -ie 's/strcmp("cli", sapi_module.name) == 0/strcmp("cli", sapi_module.name) == 0 || strcmp("micro", sapi_module.name) == 0/g' "$php_dir/ext/swoole/ext-src/php_swoole.cc"
  217. ;;
  218. esac
  219. done
  220. }
  221. $1 $2