1#!/bin/sh 2 3givup() { 4 echo $* 5 exit 1 6} 7 8usage() { 9echo "$0 --extname=module [--proto=file] [--stubs=file] [--xml[=file]]" 10echo " [--skel=dir] [--full-xml] [--no-help]" 11echo "" 12echo " --extname=module module is the name of your extension" 13echo " --proto=file file contains prototypes of functions to create" 14echo " --stubs=file generate only function stubs in file" 15echo " --xml generate xml documentation to be added to phpdoc-svn" 16echo " --skel=dir path to the skeleton directory" 17echo " --full-xml generate xml documentation for a self-contained extension" 18echo " (not yet implemented)" 19echo " --no-help don't try to be nice and create comments in the code" 20echo " and helper functions to test if the module compiled" 21exit 1 22} 23 24if test $# = 0; then 25 usage 26fi 27 28while 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 66done 67 68if test -d "$extname" ; then 69 givup "Directory $extname already exists." 70fi 71 72if test -z "$skel_dir"; then 73 skel_dir="skeleton" 74fi 75 76## convert skel_dir to full path 77skel_dir=`cd $skel_dir && pwd` 78 79test -d $skel_dir || givup "directory $skel_dir does not exist or is not directory" 80 81if echo '\c' | grep -s c >/dev/null 2>&1 82then 83 ECHO_N="echo -n" 84 ECHO_C="" 85else 86 ECHO_N="echo" 87 ECHO_C='\c' 88fi 89 90if test -z "$stubs"; then 91 echo "Creating directory $extname" 92 stubfile=$extname"/function_stubs" 93 mkdir $extname || givup "Cannot create directory $extname" 94fi 95 96if 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 98fi 99 100if 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" 107cat >config.m4 <<eof 108dnl \$Id\$ 109dnl config.m4 for extension $extname 110 111dnl Comments in this file start with the string 'dnl'. 112dnl Remove where necessary. This file will not work 113dnl without editing. 114 115dnl If your extension references something external, use with: 116 117dnl PHP_ARG_WITH($extname, for $extname support, 118dnl Make sure that the comment is aligned: 119dnl [ --with-$extname Include $extname support]) 120 121dnl Otherwise use enable: 122 123dnl PHP_ARG_ENABLE($extname, whether to enable $extname support, 124dnl Make sure that the comment is aligned: 125dnl [ --enable-$extname Enable $extname support]) 126 127if 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/\$PHP_LIBDIR, ${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/\$PHP_LIBDIR -lm 165 dnl ]) 166 dnl 167 dnl PHP_SUBST(${EXTNAME}_SHARED_LIBADD) 168 169 PHP_NEW_EXTENSION($extname, $extname.c, \$ext_shared) 170fi 171eof 172 173$ECHO_N " config.w32$ECHO_C" 174cat >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 184if (PHP_$EXTNAME != "no") { 185 EXTENSION("$extname", "$extname.c"); 186} 187 188eof 189 190$ECHO_N " .gitignore$ECHO_C" 191cat >.gitignore <<eof 192.deps 193*.lo 194*.la 195.libs 196acinclude.m4 197aclocal.m4 198autom4te.cache 199build 200config.guess 201config.h 202config.h.in 203config.log 204config.nice 205config.status 206config.sub 207configure 208configure.in 209include 210install-sh 211libtool 212ltmain.sh 213Makefile 214Makefile.fragments 215Makefile.global 216Makefile.objects 217missing 218mkinstalldirs 219modules 220run-tests.php 221tests/*/*.diff 222tests/*/*.out 223tests/*/*.php 224tests/*/*.exp 225tests/*/*.log 226tests/*/*.sh 227eof 228 229$ECHO_N " $extname.c$ECHO_C" 230echo "s/extname/$extname/g" > sedscript 231echo "s/EXTNAME/$EXTNAME/g" >> sedscript 232echo '/__function_entries_here__/r function_entries' >> sedscript 233echo '/__function_stubs_here__/r function_stubs' >> sedscript 234echo '/__header_here__/r ../../header' >> sedscript 235echo '/__footer_here__/r ../../footer' >> sedscript 236echo '/__function_entries_here__/D' >> sedscript 237echo '/__function_stubs_here__/D' >> sedscript 238echo '/__header_here__/D' >> sedscript 239echo '/__footer_here__/D' >> sedscript 240if [ ! -z "$no_help" ]; then 241 echo "/confirm_$extname_compiled/D" >> sedscript 242 echo '/Remove the following/,/^\*\//D' >> sedscript 243 echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript 244 echo 's/^\/\*.*\*\/$//' >> sedscript 245 echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript 246fi 247 248sed -f sedscript < $skel_dir/skeleton.c > $extname.c 249 250 251$ECHO_N " php_$extname.h$ECHO_C" 252echo "s/extname/$extname/g" > sedscript 253echo "s/EXTNAME/$EXTNAME/g" >> sedscript 254echo '/__function_declarations_here__/r function_declarations' >> sedscript 255echo '/__header_here__/r ../../header' >> sedscript 256echo '/__footer_here__/r ../../footer' >> sedscript 257echo '/__function_declarations_here__/D' >> sedscript 258echo '/__header_here__/D' >> sedscript 259echo '/__footer_here__/D' >> sedscript 260if [ ! -z "$no_help" ]; then 261 echo "/confirm_$extname_compiled/D" >> sedscript 262 echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript 263 echo 's/^\/\*.*\*\/$//' >> sedscript 264 echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript 265fi 266sed -f sedscript <$skel_dir/php_skeleton.h > php_$extname.h 267 268$ECHO_N " CREDITS$ECHO_C" 269echo "s/extname/$extname/g" > sedscript 270sed -f sedscript <$skel_dir/CREDITS > CREDITS 271 272$ECHO_N " EXPERIMENTAL$ECHO_C" 273echo "s/extname/$extname/g" > sedscript 274sed -f sedscript <$skel_dir/EXPERIMENTAL > EXPERIMENTAL 275 276$ECHO_N " tests/001.phpt$ECHO_C" 277mkdir tests || givup "Cannot create tests directory" 278chmod 755 tests 279sed -f sedscript <$skel_dir/tests/001.phpt > tests/001.phpt 280 281if test -z "$stubs" && test -z "$no_help"; then 282 $ECHO_N " $extname.php$ECHO_C" 283 sed \ 284 -e "s/extname/$extname/g" \ 285 <$skel_dir/skeleton.php \ 286 > $extname.php 287fi 288 289rm sedscript 290 291if test -n "$proto"; then 292 if test -z "$stubs"; then 293 rm function_entries 294 rm function_declarations 295 rm function_stubs 296 fi 297 if test -f function_warning; then 298 rm function_warning 299 warning=" 300NOTE! Because some arguments to functions were resources, the code generated 301cannot yet be compiled without editing. Please consider this to be step 4.5 302in the instructions above. 303" 304 fi 305fi 306 307find . -type f | xargs chmod 644 308find . -type d | xargs chmod 755 309fi 310 311echo " [done]." 312 313if test -z "$no_help" && test -z "$stubs"; then 314 cat <<eof 315 316To use your new extension, you will have to execute the following steps: 317 3181. $ cd .. 3192. $ vi ext/$extname/config.m4 3203. $ ./buildconf 3214. $ ./configure --[with|enable]-$extname 3225. $ make 3236. $ ./sapi/cli/php -f ext/$extname/$extname.php 3247. $ vi ext/$extname/$extname.c 3258. $ make 326 327Repeat steps 3-6 until you are satisfied with ext/$extname/config.m4 and 328step 6 confirms that your module is compiled into PHP. Then, start writing 329code and repeat the last two steps as often as necessary. 330$warning 331eof 332fi 333