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.

274 lines
7.5 KiB

27 years ago
26 years ago
  1. #!/bin/sh
  2. givup() {
  3. echo $*
  4. exit 1
  5. }
  6. usage() {
  7. echo "$0 --extname=module [--proto=file] [--stubs=file] [--xml[=file]]"
  8. echo " [--full-xml] [--no-help]"
  9. echo ""
  10. echo " --extname=module module is the name of your extension"
  11. echo " --proto=file file contains prototypes of functions to create"
  12. echo " --stubs=file generate only function stubs in file"
  13. echo " --xml generate xml documentation to be added to phpdoc-cvs"
  14. echo " --full-xml generate xml documentation for a self-contained extension"
  15. echo " (not yet implemented)"
  16. echo " --no-help don't try to be nice and create comments in the code"
  17. echo " and helper functions to test if the module compiled"
  18. exit 1
  19. }
  20. if test $# = 0; then
  21. usage
  22. fi
  23. while test $# -gt 0; do
  24. case "$1" in
  25. -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  26. *) optarg= ;;
  27. esac
  28. case $1 in
  29. --extname=?*)
  30. extname=$optarg
  31. EXTNAME=`echo $extname | tr [a-z] [A-Z]`
  32. ;;
  33. --proto=?*)
  34. proto=$optarg
  35. ;;
  36. --stubs=*)
  37. stubs=yes
  38. stubfile=$optarg
  39. ;;
  40. --xml)
  41. xml="yes"
  42. ;;
  43. --xml=?*)
  44. xml=$optarg
  45. ;;
  46. --full-xml)
  47. full_xml="yes"
  48. ;;
  49. --no-help)
  50. no_help="yes"
  51. ;;
  52. *)
  53. usage
  54. ;;
  55. esac
  56. shift
  57. done
  58. if test -d "$extname" ; then
  59. givup "Directory $extname already exists."
  60. fi
  61. test -f ext_skel || givup "ext_skel must be in the current directory"
  62. test -d skeleton || givup "subdirectory skeleton does not exist or is not directory"
  63. if echo '\c' | grep -s c >/dev/null 2>&1
  64. then
  65. ECHO_N="echo -n"
  66. ECHO_C=""
  67. else
  68. ECHO_N="echo"
  69. ECHO_C='\c'
  70. fi
  71. if test -z "$stubs"; then
  72. echo "Creating directory $extname"
  73. stubfile=$extname"/function_stubs"
  74. mkdir $extname || givup "Cannot create directory $extname"
  75. fi
  76. if test -n "$proto"; then
  77. cat $proto | awk -v extname=$extname -v stubs=$stubs -v stubfile=$stubfile -v xml=$xml -v full_xml=$full_xml -v i_know_what_to_do_shut_up_i_dont_need_your_help_mode=$no_help -f ./skeleton/create_stubs
  78. fi
  79. if test -z "$stubs"; then
  80. cd $extname
  81. chmod 755 .
  82. $ECHO_N "Creating basic files:$ECHO_C"
  83. $ECHO_N " config.m4$ECHO_C"
  84. cat >config.m4 <<eof
  85. dnl \$Id\$
  86. dnl config.m4 for extension $extname
  87. dnl Comments in this file start with the string 'dnl'.
  88. dnl Remove where necessary. This file will not work
  89. dnl without editing.
  90. dnl If your extension references something external, use with:
  91. dnl PHP_ARG_WITH($extname, for $extname support,
  92. dnl Make sure that the comment is aligned:
  93. dnl [ --with-$extname Include $extname support])
  94. dnl Otherwise use enable:
  95. dnl PHP_ARG_ENABLE($extname, whether to enable $extname support,
  96. dnl Make sure that the comment is aligned:
  97. dnl [ --enable-$extname Enable $extname support])
  98. if test "\$PHP_$EXTNAME" != "no"; then
  99. dnl Write more examples of tests here...
  100. dnl # --with-$extname -> check with-path
  101. dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
  102. dnl SEARCH_FOR="/include/$extname.h" # you most likely want to change this
  103. dnl if test -r \$PHP_$EXTNAME/$SEARCH_FOR; then # path given as parameter
  104. dnl ${EXTNAME}_DIR=\$PHP_$EXTNAME
  105. dnl else # search default path list
  106. dnl AC_MSG_CHECKING([for $extname files in default path])
  107. dnl for i in \$SEARCH_PATH ; do
  108. dnl if test -r \$i/\$SEARCH_FOR; then
  109. dnl ${EXTNAME}_DIR=\$i
  110. dnl AC_MSG_RESULT(found in \$i)
  111. dnl fi
  112. dnl done
  113. dnl fi
  114. dnl
  115. dnl if test -z "\$${EXTNAME}_DIR"; then
  116. dnl AC_MSG_RESULT([not found])
  117. dnl AC_MSG_ERROR([Please reinstall the $extname distribution])
  118. dnl fi
  119. dnl # --with-$extname -> add include path
  120. dnl PHP_ADD_INCLUDE(\$${EXTNAME}_DIR/include)
  121. dnl # --with-$extname -> chech for lib and symbol presence
  122. dnl LIBNAME=$extname # you may want to change this
  123. dnl LIBSYMBOL=$extname # you most likely want to change this
  124. dnl PHP_CHECK_LIBRARY(\$LIBNAME,\$LIBSYMBOL,
  125. dnl [
  126. dnl PHP_ADD_LIBRARY_WITH_PATH(\$LIBNAME, \$${EXTNAME}_DIR/lib, ${EXTNAME}_SHARED_LIBADD)
  127. dnl AC_DEFINE(HAVE_${EXTNAME}LIB,1,[ ])
  128. dnl ],[
  129. dnl AC_MSG_ERROR([wrong $extname lib version or lib not found])
  130. dnl ],[
  131. dnl -L\$${EXTNAME}_DIR/lib -lm -ldl
  132. dnl ])
  133. dnl
  134. dnl PHP_SUBST(${EXTNAME}_SHARED_LIBADD)
  135. PHP_NEW_EXTENSION($extname, $extname.c, \$ext_shared)
  136. fi
  137. eof
  138. $ECHO_N " .cvsignore$ECHO_C"
  139. cat >.cvsignore <<eof
  140. .deps
  141. *.lo
  142. *.la
  143. eof
  144. $ECHO_N " $extname.c$ECHO_C"
  145. echo "s/extname/$extname/g" > sedscript
  146. echo "s/EXTNAME/$EXTNAME/g" >> sedscript
  147. echo '/__function_entries_here__/r function_entries' >> sedscript
  148. echo '/__function_stubs_here__/r function_stubs' >> sedscript
  149. echo '/__header_here__/r ../../header' >> sedscript
  150. echo '/__footer_here__/r ../../footer' >> sedscript
  151. echo '/__function_entries_here__/D' >> sedscript
  152. echo '/__function_stubs_here__/D' >> sedscript
  153. echo '/__header_here__/D' >> sedscript
  154. echo '/__footer_here__/D' >> sedscript
  155. if [ ! -z "$no_help" ]; then
  156. echo "/confirm_$extname_compiled/D" >> sedscript
  157. echo '/Remove the following/,/^\*\//D' >> sedscript
  158. echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript
  159. echo 's/^\/\*.*\*\/$//' >> sedscript
  160. echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript
  161. fi
  162. sed -f sedscript <../skeleton/skeleton.c > $extname.c
  163. $ECHO_N " php_$extname.h$ECHO_C"
  164. echo "s/extname/$extname/g" > sedscript
  165. echo "s/EXTNAME/$EXTNAME/g" >> sedscript
  166. echo '/__function_declarations_here__/r function_declarations' >> sedscript
  167. echo '/__header_here__/r ../../header' >> sedscript
  168. echo '/__footer_here__/r ../../footer' >> sedscript
  169. echo '/__function_declarations_here__/D' >> sedscript
  170. echo '/__header_here__/D' >> sedscript
  171. echo '/__footer_here__/D' >> sedscript
  172. if [ ! -z "$no_help" ]; then
  173. echo "/confirm_$extname_compiled/D" >> sedscript
  174. echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript
  175. echo 's/^\/\*.*\*\/$//' >> sedscript
  176. echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript
  177. fi
  178. sed -f sedscript <../skeleton/php_skeleton.h > php_$extname.h
  179. $ECHO_N " CREDITS$ECHO_C"
  180. echo "s/extname/$extname/g" > sedscript
  181. sed -f sedscript <../skeleton/CREDITS > CREDITS
  182. $ECHO_N " EXPERIMENTAL$ECHO_C"
  183. echo "s/extname/$extname/g" > sedscript
  184. sed -f sedscript <../skeleton/EXPERIMENTAL > EXPERIMENTAL
  185. $ECHO_N " tests/001.phpt$ECHO_C"
  186. mkdir tests || givup "Cannot create tests directory"
  187. chmod 755 tests
  188. sed -f sedscript <../skeleton/tests/001.phpt > tests/001.phpt
  189. if test -z "$stubs" && test -z "$no_help"; then
  190. $ECHO_N " $extname.php$ECHO_C"
  191. sed \
  192. -e "s/extname/$extname/g" \
  193. <../skeleton/skeleton.php \
  194. > $extname.php
  195. fi
  196. rm sedscript
  197. if test -n "$proto"; then
  198. if test -z "$stubs"; then
  199. rm function_entries
  200. rm function_declarations
  201. rm function_stubs
  202. fi
  203. if test -f function_warning; then
  204. rm function_warning
  205. warning="
  206. NOTE! Because some arguments to functions were resources, the code generated
  207. cannot yet be compiled without editing. Please consider this to be step 4.5
  208. in the instructions above.
  209. "
  210. fi
  211. fi
  212. find . -type f | xargs chmod 644
  213. find . -type d | xargs chmod 755
  214. fi
  215. echo " [done]."
  216. if test -z "$no_help" && test -z "$stubs"; then
  217. cat <<eof
  218. To use your new extension, you will have to execute the following steps:
  219. 1. $ cd ..
  220. 2. $ vi ext/$extname/config.m4
  221. 3. $ ./buildconf
  222. 4. $ ./configure --[with|enable]-$extname
  223. 5. $ make
  224. 6. $ ./php -f ext/$extname/$extname.php
  225. 7. $ vi ext/$extname/$extname.c
  226. 8. $ make
  227. Repeat steps 3-6 until you are satisfied with ext/$extname/config.m4 and
  228. step 6 confirms that your module is compiled into PHP. Then, start writing
  229. code and repeat the last two steps as often as necessary.
  230. $warning
  231. eof
  232. fi