summaryrefslogtreecommitdiff
path: root/ext/ext_skel
blob: b6235469bba7035e0b5b1645b581b6c866515e64 (plain)
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
#!/bin/sh

extname="$1"
EXTNAME=`echo $1|tr a-z A-Z`
if [ ! -z $2 -a -r $2 ]; then
    functions=$2
    echo=$2
fi

givup() {
	echo $*
	exit 1
}

if test "$extname" = ""; then
	givup "usage: $0 extension-name [function-list]"
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

echo "Creating directory"

mkdir $extname || givup "Cannot create directory $extname"

if [ ! -z $functions ]; then
    echo $functions
    cat $functions | awk -v extname=$extname -f ./skeleton/create_stubs
fi

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 AC_DEFINE(HAVE_$EXTNAME, 1, [ ])
  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

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


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

$ECHO_N " $extname.c$ECHO_C"
cat ../skeleton/skeleton.c | sed \
-e "s/extname/$extname/g" \
-e "s/EXTNAME/$EXTNAME/g" \
-e '/__function_entries_here__/r function_entries' \
-e '/__function_stubs_here__/r function_stubs' \
-e '/__function_entries_here__/D' \
-e '/__function_stubs_here__/D' \
> $extname.c

$ECHO_N " php_$extname.h$ECHO_C"
cat ../skeleton/php_skeleton.h | sed \
-e "s/extname/$extname/g" \
-e "s/EXTNAME/$EXTNAME/g" \
-e '/__function_declarations_here__/r function_declarations' \
-e '/__function_declarations_here__/D' \
> php_$extname.h

$ECHO_N " $extname.php$ECHO_C"
cat ../skeleton/skeleton.php | sed \
-e "s/extname/$extname/g" \
> $extname.php

if [ ! -z $functions ]; then
    rm function_entries
    rm function_declarations
    rm function_stubs
    if [ -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

chmod 644 *

echo " [done]."

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 in PHP. Then, start writing
code and repeat the last two steps as often as necessary.
$warning
eof