Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: php-4.0.5RC6
Fetching contributors…

Cannot retrieve contributors at this time

executable file 257 lines (218 sloc) 6.81 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
#!/bin/sh

givup() {
echo $*
exit 1
}

usage() {
echo "$0 --extname=module [--proto=file] [--stubs=file] [--xml[=file]]"
echo " [--full-xml] [--no-help] [--assign-params [--string-lens]]"
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"
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"
echo " --assign-params"
echo " --string-lens"
exit 1
}

if test $# = 0; then
  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
EXTNAME=`echo $extname | tr [a-z] [A-Z]`
;;
    --proto=?*)
proto=$optarg
;;
    --stubs=*)
stubs=yes
stubfile=$optarg
;;
    --xml)
xml="yes"
;;
    --xml=?*)
xml=$optarg
;;
    --full-xml)
full_xml="yes"
;;
    --no-help)
no_help="yes"
;;
    --assign-params)
assign_params="yes"
;;
    --string-lens)
string_lens="yes"
;;
    *)
usage
;;
  esac
  shift
done

if test -z "$assign_params" && test -n "$string_lens"; then
  usage
fi

if test -d "$extname" ; then
  givup "Directory $extname already exists."
fi

test -f ext_skel || givup "ext_skel must be in the current directory"
test -d skeleton || givup "subdirectory skeleton does not exist or is not directory"

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

if test -z "$stubs"; then
  echo "Creating directory $extname"
  stubfile=$extname"/function_stubs"
  mkdir $extname || givup "Cannot create directory $extname"
fi

if test -n "$proto"; then
  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 -v assign_params=$assign_params -v string_lens=$string_lens -f ./skeleton/create_stubs
fi

if test -z "$stubs"; then
  cd $extname
  chmod 755 .

$ECHO_N "Creating basic files:$ECHO_C"

$ECHO_N " config.m4$ECHO_C"
cat >config.m4 <<eof
dnl \$Id\$
dnl config.m4 for extension $extname
dnl don't forget to call PHP_EXTENSION($extname)

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.

dnl If your extension references something external, use with:

dnl PHP_ARG_WITH($extname, for $extname support,
dnl Make sure that the comment is aligned:
dnl [ --with-$extname Include $extname support])

dnl Otherwise use enable:

dnl PHP_ARG_ENABLE($extname, whether to enable $extname support,
dnl Make sure that the comment is aligned:
dnl [ --enable-$extname Enable $extname support])

if test "\$PHP_$EXTNAME" != "no"; then
dnl If you will not be testing anything external, like existence of
dnl headers, libraries or functions in them, just uncomment the
dnl following line and you are ready to go.
dnl Write more examples of tests here...
PHP_EXTENSION($extname, \$ext_shared)
fi
eof

$ECHO_N " Makefile.in$ECHO_C"
cat >Makefile.in <<eof
# \$Id\$

LTLIBRARY_NAME = lib$extname.la
LTLIBRARY_SOURCES = $extname.c
LTLIBRARY_SHARED_NAME = $extname.la
LTLIBRARY_SHARED_LIBADD = \$(${EXTNAME}_SHARED_LIBADD)

include \$(top_srcdir)/build/dynlib.mk
eof


$ECHO_N " .cvsignore$ECHO_C"
cat >.cvsignore <<eof
.deps
Makefile
*.lo
*.la
.libs
libs.mk
eof

$ECHO_N " $extname.c$ECHO_C"
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
if [ ! -z "$no_help" ]; then
    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

sed -f sedscript <../skeleton/skeleton.c > $extname.c


$ECHO_N " php_$extname.h$ECHO_C"
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
if [ ! -z "$no_help" ]; then
    echo "/confirm_$extname_compiled/D" >> sedscript
    echo 's/[[:space:]]\/\*.\+\*\///' >> sedscript
    echo 's/^\/\*.*\*\/$//' >> sedscript
    echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D' >> sedscript
fi
sed -f sedscript <../skeleton/php_skeleton.h > php_$extname.h

$ECHO_N " tests/001.phpt$ECHO_C"
mkdir tests || givup "Cannot create tests directory"
chmod 755 tests
sed -f sedscript <../skeleton/tests/001.phpt > tests/001.phpt

if test -z "$stubs" && test -z "$no_help"; then
  $ECHO_N " $extname.php$ECHO_C"
  sed \
    -e "s/extname/$extname/g" \
    <../skeleton/skeleton.php \
    > $extname.php
fi

rm sedscript

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="
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.
"
  fi
fi

find . -type f | xargs chmod 644
find . -type d | xargs chmod 755
fi

echo " [done]."

if test -z "$no_help" && test -z "$stubs"; then
  cat <<eof

To use your new extension, you will have to execute the following steps:

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
step 6 confirms that your module is compiled into PHP. Then, start writing
code and repeat the last two steps as often as necessary.
$warning
eof
fi
Something went wrong with that request. Please try again.