xref: /unit/auto/modules/php (revision 1622:773f29e26072)
1
2# Copyright (C) Max Romanov
3# Copyright (C) Igor Sysoev
4# Copyright (C) NGINX, Inc.
5
6
7shift
8
9for nxt_option; do
10
11    case "$nxt_option" in
12        -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
13           *) value="" ;;
14    esac
15
16    case "$nxt_option" in
17        --config=*)    NXT_PHP_CONFIG="$value"                               ;;
18        --module=*)    NXT_PHP_MODULE="$value"                               ;;
19        --lib-path=*)  NXT_PHP_LIB_PATH="$value"                             ;;
20        --lib-static)  NXT_PHP_LIB_STATIC=yes                                ;;
21
22        --help)
23            cat << END
24
25    --config=FILE         set php-config filename
26    --module=NAME         set unit php module name
27    --lib-path=DIRECTORY  set directory path to libphp.so library
28    --lib-static          enable linking with static libphp.a library
29
30END
31            exit 0
32        ;;
33
34        *)
35            echo
36            echo $0: error: invalid PHP option \"$nxt_option\"
37            echo
38            exit 1
39        ;;
40
41    esac
42
43done
44
45
46if [ ! -f $NXT_AUTOCONF_DATA ]; then
47   echo
48   echo Please run common $0 before configuring module \"$nxt_module\".
49   echo
50   exit 1
51fi
52
53. $NXT_AUTOCONF_DATA
54
55
56NXT_PHP_CONFIG=${NXT_PHP_CONFIG=php-config}
57NXT_PHP=${NXT_PHP_CONFIG%-config*}
58NXT_PHP_MODULE=${NXT_PHP_MODULE=${NXT_PHP##*/}}
59NXT_PHP_LIB_PATH=${NXT_PHP_LIB_PATH=}
60NXT_PHP_LIB_STATIC=${NXT_PHP_LIB_STATIC=no}
61NXT_PHP_ADDITIONAL_FLAGS=
62
63
64$echo "configuring PHP module"
65$echo "configuring PHP module ..." >> $NXT_AUTOCONF_ERR
66
67$echo -n "checking for PHP ..."
68$echo "checking for PHP ..." >> $NXT_AUTOCONF_ERR
69
70NXT_PHP_LDFLAGS=
71
72if /bin/sh -c "${NXT_PHP_CONFIG} --version" >> $NXT_AUTOCONF_ERR 2>&1; then
73
74    $echo " found"
75
76    NXT_PHP_VERSION="`${NXT_PHP_CONFIG} --version`"
77    NXT_PHP_EXT_DIR="`${NXT_PHP_CONFIG} --extension-dir`"
78
79    $echo " + PHP SAPI: [`${NXT_PHP_CONFIG} --php-sapis`]"
80
81    NXT_PHP_MAJOR_VERSION=${NXT_PHP_VERSION%%.*}
82    NXT_PHP_MINOR_VERSION=${NXT_PHP_VERSION#*.}
83    NXT_PHP_MINOR_VERSION=${NXT_PHP_MINOR_VERSION%%.*}
84
85    if [ $NXT_PHP_MAJOR_VERSION = 5 -a $NXT_PHP_MINOR_VERSION -lt 4 ]; then
86        NXT_PHP_ADDITIONAL_FLAGS=-Wno-write-strings
87    fi
88
89    NXT_PHP_INCLUDE="`${NXT_PHP_CONFIG} --includes`"
90
91    if [ $NXT_PHP_LIB_STATIC = yes ]; then
92
93        if [ "$NXT_PHP_LIB_PATH" = "" ]; then
94            $echo
95            $echo $0: error: --lib-static option requires --lib-path option.
96            $echo
97            exit 1;
98        fi
99
100        NXT_PHP_LIB="$NXT_PHP_LIB_PATH/libphp${NXT_PHP_VERSION%%.*}.a"
101        NXT_PHP_LDFLAGS="`${NXT_PHP_CONFIG} --ldflags` \
102                         `${NXT_PHP_CONFIG} --libs`"
103
104    else
105        if [ $NXT_PHP_MAJOR_VERSION -ge 8 ]; then
106            NXT_PHP_LIB="-lphp"
107        else
108            NXT_PHP_LIB="-lphp${NXT_PHP_VERSION%%.*}"
109        fi
110
111        if [ "$NXT_PHP_LIB_PATH" != "" ]; then
112            # "php-config --ldflags" does not contain path to libphp, but
113            # contains usually path to libraries required by extensions.
114            NXT_PHP_LDFLAGS="-L${NXT_PHP_LIB_PATH} \
115                             -Wl,-rpath ${NXT_PHP_LIB_PATH}"
116        fi
117    fi
118
119else
120    $echo
121    $echo $0: error: no PHP found.
122    $echo
123    exit 1;
124fi
125
126
127nxt_feature="PHP version"
128nxt_feature_name=""
129nxt_feature_run=value
130nxt_feature_incs="${NXT_PHP_INCLUDE}"
131nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
132nxt_feature_test="
133    #include <php.h>
134
135    int main() {
136        printf(\"%s\", PHP_VERSION);
137        return 0;
138    }"
139
140. auto/feature
141
142
143nxt_feature="PHP embed SAPI"
144nxt_feature_name=""
145nxt_feature_run=no
146nxt_feature_incs="${NXT_PHP_INCLUDE}"
147nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
148nxt_feature_test="
149    #include <php.h>
150    #include <php_main.h>
151
152    int main() {
153        php_module_startup(NULL, NULL, 0);
154        return 0;
155    }"
156
157. auto/feature
158
159if [ $nxt_found = no ]; then
160    $echo
161    $echo $0: error: no PHP embed SAPI found.
162    $echo
163    exit 1;
164fi
165
166
167nxt_feature="PHP Zend Thread Safety"
168nxt_feature_name=""
169nxt_feature_run=no
170nxt_feature_incs="${NXT_PHP_INCLUDE}"
171nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
172nxt_feature_test="
173    #include <php.h>
174    #include <php_main.h>
175
176    int main() {
177        #ifndef ZTS
178        #error ZTS is not defined.
179        #endif
180        return 0;
181    }"
182
183. auto/feature
184
185
186# Bug #71041 (https://bugs.php.net/bug.php?id=71041).
187
188nxt_feature="PHP zend_signal_startup()"
189nxt_feature_name=""
190nxt_feature_run=no
191nxt_feature_incs="${NXT_PHP_INCLUDE}"
192nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
193nxt_feature_test="
194    #include <php.h>
195    #include <php_main.h>
196
197    int main() {
198        zend_signal_startup();
199        return 0;
200    }"
201
202. auto/feature
203
204if [ $nxt_found = yes ]; then
205    NXT_ZEND_SIGNAL_STARTUP=1
206else
207    NXT_ZEND_SIGNAL_STARTUP=0
208fi
209
210
211if grep ^$NXT_PHP_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
212    $echo
213    $echo $0: error: duplicate \"$NXT_PHP_MODULE\" module configured.
214    $echo
215    exit 1;
216fi
217
218
219$echo " + PHP module: ${NXT_PHP_MODULE}.unit.so"
220
221. auto/cc/deps
222
223$echo >> $NXT_MAKEFILE
224
225NXT_PHP_MODULE_SRCS=" \
226    src/nxt_php_sapi.c \
227"
228
229# The php module object files.
230
231nxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
232
233for nxt_src in $NXT_PHP_MODULE_SRCS; do
234
235    nxt_obj=${nxt_src%.c}-$NXT_PHP_MODULE.o
236    nxt_dep=${nxt_src%.c}-$NXT_PHP_MODULE.dep
237    nxt_dep_flags=`nxt_gen_dep_flags`
238    nxt_dep_post=`nxt_gen_dep_post`
239    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
240
241    cat << END >> $NXT_MAKEFILE
242
243$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
244	\$(CC) -c \$(CFLAGS) $NXT_PHP_ADDITIONAL_FLAGS \$(NXT_INCS) \\
245	$NXT_PHP_INCLUDE -DNXT_ZEND_SIGNAL_STARTUP=$NXT_ZEND_SIGNAL_STARTUP \\
246	$nxt_dep_flags \\
247	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
248	$nxt_dep_post
249
250-include $NXT_BUILD_DIR/$nxt_dep
251
252END
253
254done
255
256
257cat << END >> $NXT_MAKEFILE
258
259.PHONY: ${NXT_PHP_MODULE}
260.PHONY: ${NXT_PHP_MODULE}-install
261.PHONY: ${NXT_PHP_MODULE}-uninstall
262
263all: ${NXT_PHP_MODULE}
264
265${NXT_PHP_MODULE}:	$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so
266
267$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so:	$nxt_objs
268	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
269	$nxt_objs ${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS} $NXT_LD_OPT
270
271
272install: ${NXT_PHP_MODULE}-install
273
274${NXT_PHP_MODULE}-install: ${NXT_PHP_MODULE} install-check
275	install -d \$(DESTDIR)$NXT_MODULES
276	install -p $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
277		\$(DESTDIR)$NXT_MODULES/
278
279
280uninstall: ${NXT_PHP_MODULE}-uninstall
281
282${NXT_PHP_MODULE}-uninstall:
283	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_PHP_MODULE}.unit.so
284	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
285
286END
287