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 123PHP_ARG_ENABLE($extname, whether to enable $extname support, 124dnl Make sure that the comment is aligned: 125[ --enable-$extname Enable $extname support]) 126 127if test "\$PHP_$EXTNAME" != "no"; then 128 dnl Write more examples of tests here... 129 130 dnl # get library FOO build options from pkg-config output 131 dnl AC_PATH_PROG(PKG_CONFIG, pkg-config, no) 132 dnl AC_MSG_CHECKING(for libfoo) 133 dnl if test -x "\$PKG_CONFIG" && \$PKG_CONFIG --exists foo; then 134 dnl if \$PKG_CONFIG foo --atleast-version 1.2.3; then 135 dnl LIBFOO_CFLAGS=\`\$PKG_CONFIG foo --cflags\` 136 dnl LIBFOO_LIBDIR=\`\$PKG_CONFIG foo --libs\` 137 dnl LIBFOO_VERSON=\`\$PKG_CONFIG foo --modversion\` 138 dnl AC_MSG_RESULT(from pkgconfig: version \$LIBFOO_VERSON) 139 dnl else 140 dnl AC_MSG_ERROR(system libfoo is too old: version 1.2.3 required) 141 dnl fi 142 dnl else 143 dnl AC_MSG_ERROR(pkg-config not found) 144 dnl fi 145 dnl PHP_EVAL_LIBLINE(\$LIBFOO_LIBDIR, ${EXTNAME}_SHARED_LIBADD) 146 dnl PHP_EVAL_INCLINE(\$LIBFOO_CFLAGS) 147 148 dnl # --with-$extname -> check with-path 149 dnl SEARCH_PATH="/usr/local /usr" # you might want to change this 150 dnl SEARCH_FOR="/include/$extname.h" # you most likely want to change this 151 dnl if test -r \$PHP_$EXTNAME/\$SEARCH_FOR; then # path given as parameter 152 dnl ${EXTNAME}_DIR=\$PHP_$EXTNAME 153 dnl else # search default path list 154 dnl AC_MSG_CHECKING([for $extname files in default path]) 155 dnl for i in \$SEARCH_PATH ; do 156 dnl if test -r \$i/\$SEARCH_FOR; then 157 dnl ${EXTNAME}_DIR=\$i 158 dnl AC_MSG_RESULT(found in \$i) 159 dnl fi 160 dnl done 161 dnl fi 162 dnl 163 dnl if test -z "\$${EXTNAME}_DIR"; then 164 dnl AC_MSG_RESULT([not found]) 165 dnl AC_MSG_ERROR([Please reinstall the $extname distribution]) 166 dnl fi 167 168 dnl # --with-$extname -> add include path 169 dnl PHP_ADD_INCLUDE(\$${EXTNAME}_DIR/include) 170 171 dnl # --with-$extname -> check for lib and symbol presence 172 dnl LIBNAME=$extname # you may want to change this 173 dnl LIBSYMBOL=$extname # you most likely want to change this 174 175 dnl PHP_CHECK_LIBRARY(\$LIBNAME,\$LIBSYMBOL, 176 dnl [ 177 dnl PHP_ADD_LIBRARY_WITH_PATH(\$LIBNAME, \$${EXTNAME}_DIR/\$PHP_LIBDIR, ${EXTNAME}_SHARED_LIBADD) 178 dnl AC_DEFINE(HAVE_${EXTNAME}LIB,1,[ ]) 179 dnl ],[ 180 dnl AC_MSG_ERROR([wrong $extname lib version or lib not found]) 181 dnl ],[ 182 dnl -L\$${EXTNAME}_DIR/\$PHP_LIBDIR -lm 183 dnl ]) 184 dnl 185 dnl PHP_SUBST(${EXTNAME}_SHARED_LIBADD) 186 187 PHP_NEW_EXTENSION($extname, $extname.c, \$ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) 188fi 189eof 190 191$ECHO_N " config.w32$ECHO_C" 192cat >config.w32 <<eof 193// \$Id\$ 194// vim:ft=javascript 195 196// If your extension references something external, use ARG_WITH 197// ARG_WITH("$extname", "for $extname support", "no"); 198 199// Otherwise, use ARG_ENABLE 200ARG_ENABLE("$extname", "enable $extname support", "no"); 201 202if (PHP_$EXTNAME != "no") { 203 EXTENSION("$extname", "$extname.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 204} 205 206eof 207 208$ECHO_N " .gitignore$ECHO_C" 209cat >.gitignore <<eof 210*.lo 211*.la 212.libs 213acinclude.m4 214aclocal.m4 215autom4te.cache 216build 217config.guess 218config.h 219config.h.in 220config.log 221config.nice 222config.status 223config.sub 224configure 225configure.ac 226include 227install-sh 228libtool 229ltmain.sh 230Makefile 231Makefile.fragments 232Makefile.global 233Makefile.objects 234missing 235mkinstalldirs 236modules 237run-tests.php 238tests/*/*.diff 239tests/*/*.out 240tests/*/*.php 241tests/*/*.exp 242tests/*/*.log 243tests/*/*.sh 244eof 245 246$ECHO_N " $extname.c$ECHO_C" 247echo "s/extname/$extname/g" > sedscript 248echo "s/EXTNAME/$EXTNAME/g" >> sedscript 249echo '/__function_entries_here__/r function_entries' >> sedscript 250echo '/__function_stubs_here__/r function_stubs' >> sedscript 251echo '/__header_here__/r ../../header' >> sedscript 252echo '/__footer_here__/r ../../footer' >> sedscript 253echo '/__function_entries_here__/D' >> sedscript 254echo '/__function_stubs_here__/D' >> sedscript 255echo '/__header_here__/D' >> sedscript 256echo '/__footer_here__/D' >> sedscript 257if [ ! -z "$no_help" ]; then 258 echo "/confirm_$extname_compiled/D" >> sedscript 259 echo '/Remove the following/,/^\*\//D' >> sedscript 260 echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript 261 echo 's/^\/\*.*\*\/$//' >> sedscript 262 echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript 263fi 264 265sed -f sedscript < $skel_dir/skeleton.c > $extname.c 266 267 268$ECHO_N " php_$extname.h$ECHO_C" 269echo "s/extname/$extname/g" > sedscript 270echo "s/EXTNAME/$EXTNAME/g" >> sedscript 271echo '/__function_declarations_here__/r function_declarations' >> sedscript 272echo '/__header_here__/r ../../header' >> sedscript 273echo '/__footer_here__/r ../../footer' >> sedscript 274echo '/__function_declarations_here__/D' >> sedscript 275echo '/__header_here__/D' >> sedscript 276echo '/__footer_here__/D' >> sedscript 277if [ ! -z "$no_help" ]; then 278 echo "/confirm_$extname_compiled/D" >> sedscript 279 echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript 280 echo 's/^\/\*.*\*\/$//' >> sedscript 281 echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript 282fi 283sed -f sedscript <$skel_dir/php_skeleton.h > php_$extname.h 284 285$ECHO_N " CREDITS$ECHO_C" 286echo "s/extname/$extname/g" > sedscript 287sed -f sedscript <$skel_dir/CREDITS > CREDITS 288 289$ECHO_N " EXPERIMENTAL$ECHO_C" 290echo "s/extname/$extname/g" > sedscript 291sed -f sedscript <$skel_dir/EXPERIMENTAL > EXPERIMENTAL 292 293$ECHO_N " tests/001.phpt$ECHO_C" 294mkdir tests || givup "Cannot create tests directory" 295chmod 755 tests 296sed -f sedscript <$skel_dir/tests/001.phpt > tests/001.phpt 297 298if test -z "$stubs" && test -z "$no_help"; then 299 $ECHO_N " $extname.php$ECHO_C" 300 sed \ 301 -e "s/extname/$extname/g" \ 302 <$skel_dir/skeleton.php \ 303 > $extname.php 304fi 305 306rm sedscript 307 308if test -n "$proto"; then 309 if test -z "$stubs"; then 310 rm function_entries 311 rm function_declarations 312 rm function_stubs 313 fi 314 if test -f function_warning; then 315 rm function_warning 316 warning=" 317NOTE! Because some arguments to functions were resources, the code generated 318cannot yet be compiled without editing. Please consider this to be step 4.5 319in the instructions above. 320" 321 fi 322fi 323 324find . -type f | xargs chmod 644 325find . -type d | xargs chmod 755 326fi 327 328echo " [done]." 329 330if test -z "$no_help" && test -z "$stubs"; then 331 cat <<eof 332 333To use your new extension, you will have to execute the following steps: 334 3351. $ cd .. 3362. $ vi ext/$extname/config.m4 3373. $ ./buildconf 3384. $ ./configure --[with|enable]-$extname 3395. $ make 3406. $ ./sapi/cli/php -f ext/$extname/$extname.php 3417. $ vi ext/$extname/$extname.c 3428. $ make 343 344Repeat steps 3-6 until you are satisfied with ext/$extname/config.m4 and 345step 6 confirms that your module is compiled into PHP. Then, start writing 346code and repeat the last two steps as often as necessary. 347$warning 348eof 349fi 350