phpize.in 4.4 KB

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