phpize.in 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/bin/sh
  2. # Variable declaration
  3. prefix='@prefix@'
  4. datarootdir='@datarootdir@'
  5. exec_prefix="`eval echo @exec_prefix@`"
  6. phpdir="`eval echo @libdir@`/build"
  7. includedir="`eval echo @includedir@`/php"
  8. builddir="`pwd`"
  9. SED="@SED@"
  10. FILES_BUILD="php.m4 shtool libtool.m4 ax_check_compile_flag.m4 ax_gcc_func_attribute.m4 php_cxx_compile_stdcxx.m4 pkg.m4 \
  11. config.guess config.sub ltmain.sh Makefile.global gen_stub.php"
  12. FILES="run-tests*.php"
  13. CLEAN_FILES="$FILES *.o *.lo *.la .libs/ build/ modules/ \
  14. config.nice configure configure.ac \
  15. config.h config.h.in conftest* libtool config.cache autom4te.cache/ \
  16. config.log config.status Makefile Makefile.fragments Makefile.objects confdefs.h \
  17. run-tests*.php tests/*.diff tests/*.exp tests/*.log tests/*.out tests/*.php"
  18. # function declaration
  19. phpize_usage()
  20. {
  21. echo "Usage: $0 [--clean|--help|--version|-v]"
  22. }
  23. phpize_no_configm4()
  24. {
  25. if test $@ -eq 1; then
  26. clean=" --clean"
  27. fi
  28. echo "Cannot find config.m4. "
  29. echo "Make sure that you run '$0$clean' in the top level source directory of the module"
  30. echo
  31. }
  32. phpize_clean()
  33. {
  34. echo "Cleaning.."
  35. for i in $CLEAN_FILES; do
  36. if test -f "$i"; then
  37. rm -f $i
  38. elif test -d "$i"; then
  39. rm -rf $i
  40. fi
  41. done
  42. }
  43. phpize_check_configm4()
  44. {
  45. if test ! -r config.m4; then
  46. phpize_no_configm4 $@
  47. exit 1
  48. fi
  49. }
  50. phpize_get_api_numbers()
  51. {
  52. # extracting API NOs:
  53. PHP_API_VERSION=`grep '#define PHP_API_VERSION' $includedir/main/php.h|$SED 's/#define PHP_API_VERSION//'`
  54. ZEND_MODULE_API_NO=`grep '#define ZEND_MODULE_API_NO' $includedir/Zend/zend_modules.h|$SED 's/#define ZEND_MODULE_API_NO//'`
  55. ZEND_EXTENSION_API_NO=`grep '#define ZEND_EXTENSION_API_NO' $includedir/Zend/zend_extensions.h|$SED 's/#define ZEND_EXTENSION_API_NO//'`
  56. }
  57. phpize_print_api_numbers()
  58. {
  59. phpize_get_api_numbers
  60. echo "Configuring for:"
  61. echo "PHP Api Version: "$PHP_API_VERSION
  62. echo "Zend Module Api No: "$ZEND_MODULE_API_NO
  63. echo "Zend Extension Api No: "$ZEND_EXTENSION_API_NO
  64. }
  65. phpize_check_build_files()
  66. {
  67. if test ! -d "$phpdir"; then
  68. cat <<EOF
  69. Cannot find build files at '$phpdir'. Please check your PHP installation.
  70. EOF
  71. exit 1
  72. fi
  73. case "$phpdir" in
  74. *\ * | *\ *)
  75. cat <<EOF
  76. Invalid source path '$phpdir'. Whitespace is not allowed in source path.
  77. EOF
  78. exit 1;;
  79. esac
  80. case "$builddir" in
  81. *\ * | *\ *)
  82. cat <<EOF
  83. Invalid build path '$builddir'. Whitespace is not allowed in build path.
  84. EOF
  85. exit 1;;
  86. esac
  87. }
  88. phpize_check_shtool()
  89. {
  90. test -x "$builddir/build/shtool" || chmod +x "$builddir/build/shtool"
  91. if test ! -x "$builddir/build/shtool"; then
  92. cat <<EOF
  93. shtool at '$builddir/build/shtool' does not exist or is not executable.
  94. Make sure that the file exists and is executable and then rerun this script.
  95. EOF
  96. exit 1
  97. else
  98. php_shtool=$builddir/build/shtool
  99. fi
  100. }
  101. phpize_check_autotools()
  102. {
  103. test -z "$PHP_AUTOCONF" && PHP_AUTOCONF=autoconf
  104. test -z "$PHP_AUTOHEADER" && PHP_AUTOHEADER=autoheader
  105. if test ! -x "$PHP_AUTOCONF" && test ! -x "`$php_shtool path $PHP_AUTOCONF`"; then
  106. cat <<EOF
  107. Cannot find autoconf. Please check your autoconf installation and the
  108. \$PHP_AUTOCONF environment variable. Then, rerun this script.
  109. EOF
  110. exit 1
  111. fi
  112. if test ! -x "$PHP_AUTOHEADER" && test ! -x "`$php_shtool path $PHP_AUTOHEADER`"; then
  113. cat <<EOF
  114. Cannot find autoheader. Please check your autoconf installation and the
  115. \$PHP_AUTOHEADER environment variable. Then, rerun this script.
  116. EOF
  117. exit 1
  118. fi
  119. }
  120. phpize_copy_files()
  121. {
  122. test -d build || mkdir build
  123. (cd "$phpdir" && cp $FILES_BUILD "$builddir"/build)
  124. (cd "$phpdir" && cp $FILES "$builddir")
  125. }
  126. phpize_replace_prefix()
  127. {
  128. $SED \
  129. -e "s#@prefix@#$prefix#" \
  130. < "$phpdir/phpize.m4" > configure.ac
  131. }
  132. phpize_autotools()
  133. {
  134. # Remove aclocal.m4 if present. It is automatically included by autoconf but
  135. # not used by the PHP build system since PHP 7.4.
  136. rm -f aclocal.m4
  137. $PHP_AUTOCONF || exit 1
  138. $PHP_AUTOHEADER || exit 1
  139. }
  140. # Main script
  141. case "$1" in
  142. # Cleanup
  143. --clean)
  144. phpize_check_configm4 1
  145. phpize_clean
  146. exit 0
  147. ;;
  148. # Usage
  149. --help)
  150. phpize_usage
  151. exit 0
  152. ;;
  153. # Version
  154. --version|-v)
  155. phpize_print_api_numbers
  156. exit 0
  157. ;;
  158. # Default
  159. *)
  160. phpize_check_configm4 0
  161. phpize_check_build_files
  162. phpize_print_api_numbers
  163. phpize_copy_files
  164. phpize_replace_prefix
  165. phpize_check_shtool
  166. phpize_check_autotools
  167. phpize_autotools
  168. ;;
  169. esac
  170. exit 0