You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
2.9 KiB

2 years ago
  1. #!/bin/sh
  2. set -e
  3. # prefer user supplied CFLAGS, but default to our PHP_CFLAGS
  4. : ${CFLAGS:=$PHP_CFLAGS}
  5. : ${CPPFLAGS:=$PHP_CPPFLAGS}
  6. : ${LDFLAGS:=$PHP_LDFLAGS}
  7. export CFLAGS CPPFLAGS LDFLAGS
  8. srcExists=
  9. if [ -d /usr/src/php ]; then
  10. srcExists=1
  11. fi
  12. docker-php-source extract
  13. if [ -z "$srcExists" ]; then
  14. touch /usr/src/php/.docker-delete-me
  15. fi
  16. cd /usr/src/php/ext
  17. usage() {
  18. echo "usage: $0 [-jN] [--ini-name file.ini] ext-name [ext-name ...]"
  19. echo " ie: $0 gd mysqli"
  20. echo " $0 pdo pdo_mysql"
  21. echo " $0 -j5 gd mbstring mysqli pdo pdo_mysql shmop"
  22. echo
  23. echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure'
  24. echo
  25. echo 'Possible values for ext-name:'
  26. find . \
  27. -mindepth 2 \
  28. -maxdepth 2 \
  29. -type f \
  30. -name 'config.m4' \
  31. | xargs -n1 dirname \
  32. | xargs -n1 basename \
  33. | sort \
  34. | xargs
  35. echo
  36. echo 'Some of the above modules are already compiled into PHP; please check'
  37. echo 'the output of "php -i" to see which modules are already loaded.'
  38. }
  39. opts="$(getopt -o 'h?j:' --long 'help,ini-name:,jobs:' -- "$@" || { usage >&2 && false; })"
  40. eval set -- "$opts"
  41. j=1
  42. iniName=
  43. while true; do
  44. flag="$1"
  45. shift
  46. case "$flag" in
  47. --help|-h|'-?') usage && exit 0 ;;
  48. --ini-name) iniName="$1" && shift ;;
  49. --jobs|-j) j="$1" && shift ;;
  50. --) break ;;
  51. *)
  52. {
  53. echo "error: unknown flag: $flag"
  54. usage
  55. } >&2
  56. exit 1
  57. ;;
  58. esac
  59. done
  60. exts=
  61. for ext; do
  62. if [ -z "$ext" ]; then
  63. continue
  64. fi
  65. if [ ! -d "$ext" ]; then
  66. echo >&2 "error: $PWD/$ext does not exist"
  67. echo >&2
  68. usage >&2
  69. exit 1
  70. fi
  71. exts="$exts $ext"
  72. done
  73. if [ -z "$exts" ]; then
  74. usage >&2
  75. exit 1
  76. fi
  77. pm='unknown'
  78. if [ -e /lib/apk/db/installed ]; then
  79. pm='apk'
  80. fi
  81. apkDel=
  82. if [ "$pm" = 'apk' ]; then
  83. if [ -n "$PHPIZE_DEPS" ]; then
  84. if apk info --installed .phpize-deps-configure > /dev/null; then
  85. apkDel='.phpize-deps-configure'
  86. elif ! apk info --installed .phpize-deps > /dev/null; then
  87. apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS
  88. apkDel='.phpize-deps'
  89. fi
  90. fi
  91. fi
  92. popDir="$PWD"
  93. for ext in $exts; do
  94. cd "$ext"
  95. [ -e Makefile ] || docker-php-ext-configure "$ext"
  96. make -j"$j"
  97. if ! php -n -d 'display_errors=stderr' -r 'exit(ZEND_DEBUG_BUILD ? 0 : 1);' > /dev/null; then
  98. # only "strip" modules if we aren't using a debug build of PHP
  99. # (none of our builds are debug builds, but PHP might be recompiled with "--enable-debug" configure option)
  100. # https://github.com/docker-library/php/issues/1268
  101. find modules \
  102. -maxdepth 1 \
  103. -name '*.so' \
  104. -exec sh -euxc ' \
  105. strip --strip-all "$@" || :
  106. ' -- '{}' +
  107. fi
  108. make -j"$j" install
  109. find modules \
  110. -maxdepth 1 \
  111. -name '*.so' \
  112. -exec basename '{}' ';' \
  113. | xargs -r docker-php-ext-enable ${iniName:+--ini-name "$iniName"}
  114. make -j"$j" clean
  115. cd "$popDir"
  116. done
  117. if [ "$pm" = 'apk' ] && [ -n "$apkDel" ]; then
  118. apk del --no-network $apkDel
  119. fi
  120. if [ -e /usr/src/php/.docker-delete-me ]; then
  121. docker-php-source delete
  122. fi