check-extensions.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. test -f "$self_dir/extensions_install.txt" && EXT_LIST_FILE="$self_dir/extensions_install.txt" || EXT_LIST_FILE="$self_dir/extensions.txt"
  9. function do_copy_extension() {
  10. ext_dir=$(find $self_dir/source -name "*$1-*" -type d | tail -n1)
  11. mv $ext_dir $php_dir/ext/$1
  12. if [ $? != 0 ]; then
  13. echo "Compile error! ext: $1, ext_dir=$ext_dir"
  14. exit 1
  15. fi
  16. }
  17. function check_before_configure() {
  18. list=$(cat "$EXT_LIST_FILE" | grep -v "^#" | grep -v "^$" | grep -v "^\^")
  19. xml_sign="no"
  20. for loop in $list
  21. do
  22. case $loop in
  23. bcmath) ;;
  24. calendar) ;;
  25. ctype) ;;
  26. exif) ;;
  27. filter) ;;
  28. fileinfo) ;;
  29. gd) ;;
  30. hash) ;;
  31. iconv) ;;
  32. json) ;;
  33. mbstring) ;;
  34. mysqlnd) ;;
  35. openssl) ;;
  36. pcntl) ;;
  37. pdo) ;;
  38. pdo_mysql) ;;
  39. pdo_sqlite) ;;
  40. phar) ;;
  41. posix) ;;
  42. protobuf)
  43. do_copy_extension protobuf
  44. echo '#ifndef PHP_PROTOBUF_H' >> $php_dir/ext/protobuf/php_protobuf.h && \
  45. echo '# define PHP_PROTOBUF_H' >> $php_dir/ext/protobuf/php_protobuf.h && \
  46. echo '#ifdef HAVE_CONFIG_H' >> $php_dir/ext/protobuf/php_protobuf.h && \
  47. echo '# include "config.h"' >> $php_dir/ext/protobuf/php_protobuf.h && \
  48. echo '#endif' >> $php_dir/ext/protobuf/php_protobuf.h && \
  49. echo 'extern zend_module_entry protobuf_module_entry;' >> $php_dir/ext/protobuf/php_protobuf.h && \
  50. echo '# define phpext_protobuf_ptr &protobuf_module_entry' >> $php_dir/ext/protobuf/php_protobuf.h && \
  51. echo '#endif' >> $php_dir/ext/protobuf/php_protobuf.h
  52. ;;
  53. readline)
  54. if [ ! -d "/nom" ]; then
  55. mkdir /nom
  56. fi
  57. mv /usr/lib/libreadline.so* /nom/ && \
  58. mv /usr/lib/libncurses*.so* /nom
  59. ;;
  60. shmop) ;;
  61. sockets) ;;
  62. sqlite3) ;;
  63. tokenizer) ;;
  64. zlib) ;;
  65. zip) ;;
  66. curl) cat "$self_dir/ac_override_1" "$php_dir/ext/curl/config.m4" "$self_dir/ac_override_2" > /tmp/aa && mv /tmp/aa "$php_dir/ext/curl/config.m4" ;;
  67. dom|xml|libxml|xmlreader|xmlwriter|simplexml|soap) ;;
  68. inotify) do_copy_extension inotify ;;
  69. redis) do_copy_extension redis ;;
  70. swoole) do_copy_extension swoole ;;
  71. mongodb) do_copy_extension mongodb ;;
  72. event) do_copy_extension event ;;
  73. esac
  74. done
  75. case $1 in
  76. 8.*)
  77. mv $self_dir/source/phpmicro $php_dir/sapi/micro && \
  78. sed -ie 's/#include "php.h"/#include "php.h"\n#define PHP_MICRO_FAKE_CLI 1/g' $php_dir/sapi/micro/php_micro.c
  79. ;;
  80. esac
  81. }
  82. function check_in_configure() {
  83. php_configure=""
  84. list=$(cat "$EXT_LIST_FILE" | sed 's/#.*//g' | sed 's/\^.*//g' | sed -e 's/[ ]*$//g' | grep -v "^\s*$")
  85. for loop in $list
  86. do
  87. case $loop in
  88. bcmath) php_configure="$php_configure --enable-bcmath" ;;
  89. calendar) php_configure="$php_configure --enable-calendar" ;;
  90. ctype) php_configure="$php_configure --enable-ctype" ;;
  91. curl) php_configure="$php_configure --with-curl" ;;
  92. dom) php_configure="$php_configure --enable-dom" ;;
  93. exif) php_configure="$php_configure --enable-exif" ;;
  94. event) php_configure="$php_configure --with-event-libevent-dir=/usr --with-event-core --with-event-extra --with-event-openssl" ;;
  95. filter) php_configure="$php_configure --enable-filter" ;;
  96. fileinfo) php_configure="$php_configure --enable-fileinfo" ;;
  97. gd)
  98. case $1 in
  99. 7.3.*|7.2.*) php_configure="$php_configure --with-gd" ;;
  100. 7.4.*|8.*) php_configure="$php_configure --enable-gd" ;;
  101. esac
  102. ;;
  103. hash)
  104. case $1 in
  105. 7.3.*|7.2.*) php_configure="$php_configure --enable-hash" ;;
  106. esac
  107. ;;
  108. iconv) php_configure="$php_configure --with-iconv=/usr" ;;
  109. inotify) php_configure="$php_configure --enable-inotify" ;;
  110. json)
  111. case $1 in
  112. 7.*) php_configure="$php_configure --enable-json" ;;
  113. esac
  114. ;;
  115. libxml)
  116. case $1 in
  117. 7.3.*|7.2.*) php_configure="$php_configure --enable-libxml" ;;
  118. 7.4.*|8.*) php_configure="$php_configure --with-libxml" ;;
  119. esac
  120. ;;
  121. mbstring) php_configure="$php_configure --enable-mbstring" ;;
  122. mongodb) php_configure="$php_configure --enable-mongodb" ;;
  123. mysqlnd) php_configure="$php_configure --enable-mysqlnd" ;;
  124. openssl) php_configure="$php_configure --with-openssl --with-openssl-dir=/usr" ;;
  125. pcntl) php_configure="$php_configure --enable-pcntl" ;;
  126. pdo) php_configure="$php_configure --enable-pdo" ;;
  127. pdo_mysql) php_configure="$php_configure --with-pdo-mysql=mysqlnd" ;;
  128. phar) php_configure="$php_configure --enable-phar" ;;
  129. posix) php_configure="$php_configure --enable-posix" ;;
  130. protobuf) php_configure="$php_configure --enable-protobuf" ;;
  131. readline) php_configure="$php_configure --with-readline" ;;
  132. redis) php_configure="$php_configure --enable-redis --disable-redis-session" ;;
  133. shmop) php_configure="$php_configure --enable-shmop" ;;
  134. simplexml) php_configure="$php_configure --enable-simplexml" ;;
  135. sockets) php_configure="$php_configure --enable-sockets" ;;
  136. soap) php_configure="$php_configure --enable-soap" ;;
  137. sqlite3) php_configure="$php_configure --with-sqlite3" ;;
  138. pdo_sqlite) php_configure="$php_configure --with-pdo-sqlite" ;;
  139. swoole)
  140. php_configure="$php_configure --enable-swoole"
  141. have_openssl=$(echo $list | grep openssl)
  142. if [ "$have_openssl" != "" ]; then
  143. php_configure="$php_configure --enable-openssl --with-openssl --with-openssl-dir=/usr"
  144. fi
  145. have_hash=$(echo $list | grep hash)
  146. if [ "$have_hash" = "" ]; then
  147. case $1 in
  148. 7.3.*|7.2.*) php_configure="$php_configure --enable-hash" ;;
  149. esac
  150. fi
  151. ;;
  152. tokenizer) php_configure="$php_configure --enable-tokenizer" ;;
  153. xml) php_configure="$php_configure --enable-xml" ;;
  154. xmlreader) php_configure="$php_configure --enable-xmlreader" ;;
  155. xmlwriter) php_configure="$php_configure --enable-xmlwriter" ;;
  156. zlib) php_configure="$php_configure --with-zlib" ;;
  157. zip) php_configure="$php_configure --with-zip" ;;
  158. *)
  159. echo "Unsupported extension '$loop' !" >&2
  160. exit 1
  161. ;;
  162. esac
  163. done
  164. case $1 in
  165. 8.*) php_configure="$php_configure --with-ffi --enable-micro=all-static" ;;
  166. esac
  167. echo $php_configure
  168. }
  169. function check_after_configure() {
  170. list=$(cat "$EXT_LIST_FILE" | grep -v "^#" | grep -v "^$")
  171. for loop in $list
  172. do
  173. case $loop in
  174. swoole)
  175. sed -ie 's/swoole_clock_gettime(CLOCK_REALTIME/clock_gettime(CLOCK_REALTIME/g' "$php_dir/ext/swoole/include/swoole.h"
  176. 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"
  177. ;;
  178. esac
  179. done
  180. case $1 in
  181. 8.*) sed -ie 's/$(EXTRA_LIBS:-lresolv=-Wl,-Bstatic,-lresolv,-Bdynamic)/$(EXTRA_LIBS)/g' "$php_dir/Makefile" ;;
  182. esac
  183. }
  184. function finish_compile() {
  185. if [ -d "/nom" ]; then
  186. mv /nom/* /usr/lib/ || echo "Empty directory"
  187. rm -rf /nom/
  188. fi
  189. }
  190. $1 $2