Annotation of embedaddon/php/ext/ext_skel, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>