1999-04-21 18:24:41 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
1999-09-27 22:05:18 +08:00
|
|
|
givup() {
|
1999-04-21 18:24:41 +08:00
|
|
|
echo $*
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2000-06-15 09:57:23 +08:00
|
|
|
usage() {
|
|
|
|
echo "$0 --extname=module [--proto=file] [--stubs=file] [--xml[=file]]"
|
2002-07-31 03:02:23 +08:00
|
|
|
echo " [--skel=dir] [--full-xml] [--no-help]"
|
2000-06-15 09:57:23 +08:00
|
|
|
echo ""
|
|
|
|
echo " --extname=module module is the name of your extension"
|
|
|
|
echo " --proto=file file contains prototypes of functions to create"
|
|
|
|
echo " --stubs=file generate only function stubs in file"
|
|
|
|
echo " --xml generate xml documentation to be added to phpdoc-cvs"
|
2002-07-31 03:02:23 +08:00
|
|
|
echo " --skel=dir path to the skeleton directory"
|
2000-06-15 09:57:23 +08:00
|
|
|
echo " --full-xml generate xml documentation for a self-contained extension"
|
|
|
|
echo " (not yet implemented)"
|
|
|
|
echo " --no-help don't try to be nice and create comments in the code"
|
|
|
|
echo " and helper functions to test if the module compiled"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2000-07-04 13:15:33 +08:00
|
|
|
if test $# = 0; then
|
2000-06-15 09:57:23 +08:00
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
while test $# -gt 0; do
|
|
|
|
case "$1" in
|
|
|
|
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
|
|
|
|
*) optarg= ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
--extname=?*)
|
|
|
|
extname=$optarg
|
2002-07-31 03:02:23 +08:00
|
|
|
EXTNAME=`echo $extname | tr "[:lower:]" "[:upper:]"`
|
2000-06-15 09:57:23 +08:00
|
|
|
;;
|
|
|
|
--proto=?*)
|
|
|
|
proto=$optarg
|
|
|
|
;;
|
|
|
|
--stubs=*)
|
|
|
|
stubs=yes
|
|
|
|
stubfile=$optarg
|
|
|
|
;;
|
|
|
|
--xml)
|
|
|
|
xml="yes"
|
|
|
|
;;
|
|
|
|
--xml=?*)
|
|
|
|
xml=$optarg
|
|
|
|
;;
|
|
|
|
--full-xml)
|
|
|
|
full_xml="yes"
|
|
|
|
;;
|
|
|
|
--no-help)
|
|
|
|
no_help="yes"
|
|
|
|
;;
|
2002-07-31 03:02:23 +08:00
|
|
|
--skel=?*)
|
|
|
|
skel_dir=$optarg
|
|
|
|
;;
|
2000-06-15 09:57:23 +08:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
1999-04-22 00:23:47 +08:00
|
|
|
if test -d "$extname" ; then
|
2000-07-04 13:15:33 +08:00
|
|
|
givup "Directory $extname already exists."
|
1999-04-21 18:24:41 +08:00
|
|
|
fi
|
|
|
|
|
2002-07-31 03:02:23 +08:00
|
|
|
if test -z "$skel_dir"; then
|
|
|
|
skel_dir="skeleton"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## convert skel_dir to full path
|
|
|
|
skel_dir=`cd $skel_dir && pwd`
|
|
|
|
|
|
|
|
test -d $skel_dir || givup "directory $skel_dir does not exist or is not directory"
|
1999-10-08 03:53:20 +08:00
|
|
|
|
1999-09-27 22:15:15 +08:00
|
|
|
if echo '\c' | grep -s c >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
ECHO_N="echo -n"
|
|
|
|
ECHO_C=""
|
|
|
|
else
|
|
|
|
ECHO_N="echo"
|
|
|
|
ECHO_C='\c'
|
|
|
|
fi
|
|
|
|
|
2000-07-04 13:15:33 +08:00
|
|
|
if test -z "$stubs"; then
|
|
|
|
echo "Creating directory $extname"
|
|
|
|
stubfile=$extname"/function_stubs"
|
|
|
|
mkdir $extname || givup "Cannot create directory $extname"
|
2000-06-15 09:57:23 +08:00
|
|
|
fi
|
1999-04-21 18:24:41 +08:00
|
|
|
|
2000-07-04 13:15:33 +08:00
|
|
|
if test -n "$proto"; then
|
2002-07-31 03:02:23 +08:00
|
|
|
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 $skel_dir/create_stubs
|
2000-06-10 02:04:17 +08:00
|
|
|
fi
|
|
|
|
|
2000-07-04 13:15:33 +08:00
|
|
|
if test -z "$stubs"; then
|
|
|
|
cd $extname
|
|
|
|
chmod 755 .
|
2000-06-10 13:47:22 +08:00
|
|
|
|
1999-09-27 22:15:15 +08:00
|
|
|
$ECHO_N "Creating basic files:$ECHO_C"
|
1999-04-21 18:24:41 +08:00
|
|
|
|
1999-09-27 22:15:15 +08:00
|
|
|
$ECHO_N " config.m4$ECHO_C"
|
1999-04-21 18:24:41 +08:00
|
|
|
cat >config.m4 <<eof
|
|
|
|
dnl \$Id\$
|
1999-04-22 00:23:47 +08:00
|
|
|
dnl config.m4 for extension $extname
|
1999-04-21 18:24:41 +08:00
|
|
|
|
2000-06-09 11:38:37 +08:00
|
|
|
dnl Comments in this file start with the string 'dnl'.
|
|
|
|
dnl Remove where necessary. This file will not work
|
|
|
|
dnl without editing.
|
|
|
|
|
2000-03-28 06:52:48 +08:00
|
|
|
dnl If your extension references something external, use with:
|
|
|
|
|
2000-06-09 11:38:37 +08:00
|
|
|
dnl PHP_ARG_WITH($extname, for $extname support,
|
2000-03-28 06:52:48 +08:00
|
|
|
dnl Make sure that the comment is aligned:
|
2000-06-09 11:38:37 +08:00
|
|
|
dnl [ --with-$extname Include $extname support])
|
2000-03-28 06:52:48 +08:00
|
|
|
|
|
|
|
dnl Otherwise use enable:
|
|
|
|
|
2000-06-09 11:38:37 +08:00
|
|
|
dnl PHP_ARG_ENABLE($extname, whether to enable $extname support,
|
2000-03-28 06:52:48 +08:00
|
|
|
dnl Make sure that the comment is aligned:
|
2000-06-09 11:38:37 +08:00
|
|
|
dnl [ --enable-$extname Enable $extname support])
|
2000-03-28 06:52:48 +08:00
|
|
|
|
|
|
|
if test "\$PHP_$EXTNAME" != "no"; then
|
2000-06-09 11:38:37 +08:00
|
|
|
dnl Write more examples of tests here...
|
2001-05-01 03:06:26 +08:00
|
|
|
|
|
|
|
dnl # --with-$extname -> check with-path
|
2002-01-09 01:51:08 +08:00
|
|
|
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
|
2001-05-01 03:06:26 +08:00
|
|
|
dnl SEARCH_FOR="/include/$extname.h" # you most likely want to change this
|
|
|
|
dnl if test -r \$PHP_$EXTNAME/$SEARCH_FOR; then # path given as parameter
|
|
|
|
dnl ${EXTNAME}_DIR=\$PHP_$EXTNAME
|
|
|
|
dnl else # search default path list
|
2001-09-07 05:05:57 +08:00
|
|
|
dnl AC_MSG_CHECKING([for $extname files in default path])
|
2001-05-01 03:06:26 +08:00
|
|
|
dnl for i in \$SEARCH_PATH ; do
|
|
|
|
dnl if test -r \$i/\$SEARCH_FOR; then
|
|
|
|
dnl ${EXTNAME}_DIR=\$i
|
|
|
|
dnl AC_MSG_RESULT(found in \$i)
|
|
|
|
dnl fi
|
|
|
|
dnl done
|
|
|
|
dnl fi
|
|
|
|
dnl
|
|
|
|
dnl if test -z "\$${EXTNAME}_DIR"; then
|
2001-09-07 05:05:57 +08:00
|
|
|
dnl AC_MSG_RESULT([not found])
|
|
|
|
dnl AC_MSG_ERROR([Please reinstall the $extname distribution])
|
2001-05-01 03:06:26 +08:00
|
|
|
dnl fi
|
|
|
|
|
|
|
|
dnl # --with-$extname -> add include path
|
2001-05-02 03:15:43 +08:00
|
|
|
dnl PHP_ADD_INCLUDE(\$${EXTNAME}_DIR/include)
|
2001-05-01 03:06:26 +08:00
|
|
|
|
|
|
|
dnl # --with-$extname -> chech for lib and symbol presence
|
2001-07-20 07:36:37 +08:00
|
|
|
dnl LIBNAME=$extname # you may want to change this
|
2001-05-01 03:06:26 +08:00
|
|
|
dnl LIBSYMBOL=$extname # you most likely want to change this
|
2002-01-09 01:51:08 +08:00
|
|
|
|
|
|
|
dnl PHP_CHECK_LIBRARY(\$LIBNAME,\$LIBSYMBOL,
|
|
|
|
dnl [
|
|
|
|
dnl PHP_ADD_LIBRARY_WITH_PATH(\$LIBNAME, \$${EXTNAME}_DIR/lib, ${EXTNAME}_SHARED_LIBADD)
|
|
|
|
dnl AC_DEFINE(HAVE_${EXTNAME}LIB,1,[ ])
|
|
|
|
dnl ],[
|
|
|
|
dnl AC_MSG_ERROR([wrong $extname lib version or lib not found])
|
|
|
|
dnl ],[
|
|
|
|
dnl -L\$${EXTNAME}_DIR/lib -lm -ldl
|
|
|
|
dnl ])
|
2001-05-01 03:06:26 +08:00
|
|
|
dnl
|
|
|
|
dnl PHP_SUBST(${EXTNAME}_SHARED_LIBADD)
|
|
|
|
|
2002-03-07 22:20:02 +08:00
|
|
|
PHP_NEW_EXTENSION($extname, $extname.c, \$ext_shared)
|
2000-03-28 06:52:48 +08:00
|
|
|
fi
|
1999-04-21 18:24:41 +08:00
|
|
|
eof
|
|
|
|
|
|
|
|
|
1999-09-27 22:15:15 +08:00
|
|
|
$ECHO_N " .cvsignore$ECHO_C"
|
1999-04-21 18:24:41 +08:00
|
|
|
cat >.cvsignore <<eof
|
|
|
|
.deps
|
1999-10-07 21:53:35 +08:00
|
|
|
*.lo
|
|
|
|
*.la
|
1999-04-21 18:24:41 +08:00
|
|
|
eof
|
|
|
|
|
2000-06-09 11:38:37 +08:00
|
|
|
$ECHO_N " $extname.c$ECHO_C"
|
2000-06-15 09:57:23 +08:00
|
|
|
echo "s/extname/$extname/g" > sedscript
|
|
|
|
echo "s/EXTNAME/$EXTNAME/g" >> sedscript
|
|
|
|
echo '/__function_entries_here__/r function_entries' >> sedscript
|
|
|
|
echo '/__function_stubs_here__/r function_stubs' >> sedscript
|
|
|
|
echo '/__header_here__/r ../../header' >> sedscript
|
|
|
|
echo '/__footer_here__/r ../../footer' >> sedscript
|
|
|
|
echo '/__function_entries_here__/D' >> sedscript
|
|
|
|
echo '/__function_stubs_here__/D' >> sedscript
|
|
|
|
echo '/__header_here__/D' >> sedscript
|
|
|
|
echo '/__footer_here__/D' >> sedscript
|
2000-12-07 18:03:21 +08:00
|
|
|
if [ ! -z "$no_help" ]; then
|
2000-06-15 09:57:23 +08:00
|
|
|
echo "/confirm_$extname_compiled/D" >> sedscript
|
|
|
|
echo '/Remove the following/,/^\*\//D' >> sedscript
|
|
|
|
echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript
|
|
|
|
echo 's/^\/\*.*\*\/$//' >> sedscript
|
|
|
|
echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript
|
|
|
|
fi
|
|
|
|
|
2002-07-31 03:02:23 +08:00
|
|
|
sed -f sedscript < $skel_dir/skeleton.c > $extname.c
|
2000-06-15 09:57:23 +08:00
|
|
|
|
2000-06-09 11:38:37 +08:00
|
|
|
|
|
|
|
$ECHO_N " php_$extname.h$ECHO_C"
|
2000-06-15 09:57:23 +08:00
|
|
|
echo "s/extname/$extname/g" > sedscript
|
|
|
|
echo "s/EXTNAME/$EXTNAME/g" >> sedscript
|
|
|
|
echo '/__function_declarations_here__/r function_declarations' >> sedscript
|
|
|
|
echo '/__header_here__/r ../../header' >> sedscript
|
|
|
|
echo '/__footer_here__/r ../../footer' >> sedscript
|
|
|
|
echo '/__function_declarations_here__/D' >> sedscript
|
|
|
|
echo '/__header_here__/D' >> sedscript
|
|
|
|
echo '/__footer_here__/D' >> sedscript
|
2000-12-07 18:03:21 +08:00
|
|
|
if [ ! -z "$no_help" ]; then
|
2000-06-15 09:57:23 +08:00
|
|
|
echo "/confirm_$extname_compiled/D" >> sedscript
|
|
|
|
echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript
|
|
|
|
echo 's/^\/\*.*\*\/$//' >> sedscript
|
|
|
|
echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript
|
|
|
|
fi
|
2002-07-31 03:02:23 +08:00
|
|
|
sed -f sedscript <$skel_dir/php_skeleton.h > php_$extname.h
|
2000-06-15 09:57:23 +08:00
|
|
|
|
2001-05-03 07:33:21 +08:00
|
|
|
$ECHO_N " CREDITS$ECHO_C"
|
|
|
|
echo "s/extname/$extname/g" > sedscript
|
2002-07-31 03:02:23 +08:00
|
|
|
sed -f sedscript <$skel_dir/CREDITS > CREDITS
|
2001-05-03 07:33:21 +08:00
|
|
|
|
|
|
|
$ECHO_N " EXPERIMENTAL$ECHO_C"
|
|
|
|
echo "s/extname/$extname/g" > sedscript
|
2002-07-31 03:02:23 +08:00
|
|
|
sed -f sedscript <$skel_dir/EXPERIMENTAL > EXPERIMENTAL
|
2001-05-03 07:33:21 +08:00
|
|
|
|
2000-10-23 15:31:31 +08:00
|
|
|
$ECHO_N " tests/001.phpt$ECHO_C"
|
|
|
|
mkdir tests || givup "Cannot create tests directory"
|
|
|
|
chmod 755 tests
|
2002-07-31 03:02:23 +08:00
|
|
|
sed -f sedscript <$skel_dir/tests/001.phpt > tests/001.phpt
|
2000-06-09 11:38:37 +08:00
|
|
|
|
2000-07-04 13:15:33 +08:00
|
|
|
if test -z "$stubs" && test -z "$no_help"; then
|
|
|
|
$ECHO_N " $extname.php$ECHO_C"
|
|
|
|
sed \
|
|
|
|
-e "s/extname/$extname/g" \
|
2002-07-31 03:02:23 +08:00
|
|
|
<$skel_dir/skeleton.php \
|
2000-07-04 13:15:33 +08:00
|
|
|
> $extname.php
|
2000-06-15 09:57:23 +08:00
|
|
|
fi
|
2000-06-10 02:04:17 +08:00
|
|
|
|
2000-10-23 15:31:31 +08:00
|
|
|
rm sedscript
|
|
|
|
|
2000-07-04 13:15:33 +08:00
|
|
|
if test -n "$proto"; then
|
|
|
|
if test -z "$stubs"; then
|
|
|
|
rm function_entries
|
|
|
|
rm function_declarations
|
|
|
|
rm function_stubs
|
|
|
|
fi
|
|
|
|
if test -f function_warning; then
|
|
|
|
rm function_warning
|
|
|
|
warning="
|
2000-06-10 13:47:22 +08:00
|
|
|
NOTE! Because some arguments to functions were resources, the code generated
|
|
|
|
cannot yet be compiled without editing. Please consider this to be step 4.5
|
|
|
|
in the instructions above.
|
|
|
|
"
|
2000-07-04 13:15:33 +08:00
|
|
|
fi
|
2000-06-10 11:53:11 +08:00
|
|
|
fi
|
2000-06-09 11:38:37 +08:00
|
|
|
|
2000-10-23 15:31:31 +08:00
|
|
|
find . -type f | xargs chmod 644
|
|
|
|
find . -type d | xargs chmod 755
|
2000-06-15 09:57:23 +08:00
|
|
|
fi
|
1999-04-21 18:24:41 +08:00
|
|
|
|
|
|
|
echo " [done]."
|
1999-04-22 04:39:22 +08:00
|
|
|
|
2000-07-04 13:15:33 +08:00
|
|
|
if test -z "$no_help" && test -z "$stubs"; then
|
|
|
|
cat <<eof
|
1999-10-08 03:53:20 +08:00
|
|
|
|
|
|
|
To use your new extension, you will have to execute the following steps:
|
|
|
|
|
2000-06-09 22:46:15 +08:00
|
|
|
1. $ cd ..
|
|
|
|
2. $ vi ext/$extname/config.m4
|
|
|
|
3. $ ./buildconf
|
|
|
|
4. $ ./configure --[with|enable]-$extname
|
|
|
|
5. $ make
|
|
|
|
6. $ ./php -f ext/$extname/$extname.php
|
|
|
|
7. $ vi ext/$extname/$extname.c
|
|
|
|
8. $ make
|
|
|
|
|
|
|
|
Repeat steps 3-6 until you are satisfied with ext/$extname/config.m4 and
|
2000-07-17 02:51:00 +08:00
|
|
|
step 6 confirms that your module is compiled into PHP. Then, start writing
|
2000-06-09 22:46:15 +08:00
|
|
|
code and repeat the last two steps as often as necessary.
|
2000-06-10 13:47:22 +08:00
|
|
|
$warning
|
1999-10-08 03:53:20 +08:00
|
|
|
eof
|
2000-06-15 09:57:23 +08:00
|
|
|
fi
|