xref: /unit/auto/modules/php (revision 1382:6c8b10bbb4e8)
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    $echo " + PHP SAPI: [`${NXT_PHP_CONFIG} --php-sapis`]"
78
79    NXT_PHP_MAJOR_VERSION=${NXT_PHP_VERSION%%.*}
80    NXT_PHP_MINOR_VERSION=${NXT_PHP_VERSION#??}
81    NXT_PHP_MINOR_VERSION=${NXT_PHP_MINOR_VERSION%.*}
82
83    if [ $NXT_PHP_MAJOR_VERSION = 5 -a $NXT_PHP_MINOR_VERSION -lt 4 ]; then
84        NXT_PHP_ADDITIONAL_FLAGS=-Wno-write-strings
85    fi
86
87    NXT_PHP_INCLUDE="`${NXT_PHP_CONFIG} --includes`"
88
89    if [ $NXT_PHP_LIB_STATIC = yes ]; then
90
91        if [ "$NXT_PHP_LIB_PATH" = "" ]; then
92            $echo
93            $echo $0: error: --lib-static option requires --lib-path option.
94            $echo
95            exit 1;
96        fi
97
98        NXT_PHP_LIB="$NXT_PHP_LIB_PATH/libphp${NXT_PHP_VERSION%%.*}.a"
99        NXT_PHP_LDFLAGS="`${NXT_PHP_CONFIG} --ldflags` \
100                         `${NXT_PHP_CONFIG} --libs`"
101
102    else
103        NXT_PHP_LIB="-lphp${NXT_PHP_VERSION%%.*}"
104
105        if [ "$NXT_PHP_LIB_PATH" != "" ]; then
106            # "php-config --ldflags" does not contain path to libphp, but
107            # contains usually path to libraries required by extensions.
108            NXT_PHP_LDFLAGS="-L${NXT_PHP_LIB_PATH} \
109                             -Wl,-rpath ${NXT_PHP_LIB_PATH}"
110        fi
111    fi
112
113else
114    $echo
115    $echo $0: error: no PHP found.
116    $echo
117    exit 1;
118fi
119
120
121nxt_feature="PHP version"
122nxt_feature_name=""
123nxt_feature_run=value
124nxt_feature_incs="${NXT_PHP_INCLUDE}"
125nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
126nxt_feature_test="
127    #include <php.h>
128
129    int main() {
130        printf(\"%s\", PHP_VERSION);
131        return 0;
132    }"
133
134. auto/feature
135
136
137nxt_feature="PHP embed SAPI"
138nxt_feature_name=""
139nxt_feature_run=no
140nxt_feature_incs="${NXT_PHP_INCLUDE}"
141nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
142nxt_feature_test="
143    #include <php.h>
144    #include <php_main.h>
145
146    int main() {
147        php_module_startup(NULL, NULL, 0);
148        return 0;
149    }"
150
151. auto/feature
152
153if [ $nxt_found = no ]; then
154    $echo
155    $echo $0: error: no PHP embed SAPI found.
156    $echo
157    exit 1;
158fi
159
160
161# Bug #71041 (https://bugs.php.net/bug.php?id=71041).
162
163nxt_feature="PHP zend_signal_startup()"
164nxt_feature_name=""
165nxt_feature_run=no
166nxt_feature_incs="${NXT_PHP_INCLUDE}"
167nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
168nxt_feature_test="
169    #include <php.h>
170    #include <php_main.h>
171
172    int main() {
173        zend_signal_startup();
174        return 0;
175    }"
176
177. auto/feature
178
179if [ $nxt_found = yes ]; then
180    NXT_ZEND_SIGNAL_STARTUP=1
181else
182    NXT_ZEND_SIGNAL_STARTUP=0
183fi
184
185
186if grep ^$NXT_PHP_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
187    $echo
188    $echo $0: error: duplicate \"$NXT_PHP_MODULE\" module configured.
189    $echo
190    exit 1;
191fi
192
193$echo " + PHP module: ${NXT_PHP_MODULE}.unit.so"
194
195. auto/cc/deps
196
197$echo >> $NXT_MAKEFILE
198
199NXT_PHP_MODULE_SRCS=" \
200    src/nxt_php_sapi.c \
201"
202
203# The php module object files.
204
205nxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
206
207for nxt_src in $NXT_PHP_MODULE_SRCS; do
208
209    nxt_obj=${nxt_src%.c}-$NXT_PHP_MODULE.o
210    nxt_dep=${nxt_src%.c}-$NXT_PHP_MODULE.dep
211    nxt_dep_flags=`nxt_gen_dep_flags`
212    nxt_dep_post=`nxt_gen_dep_post`
213    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
214
215    cat << END >> $NXT_MAKEFILE
216
217$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
218	\$(CC) -c \$(CFLAGS) $NXT_PHP_ADDITIONAL_FLAGS \$(NXT_INCS) \\
219	$NXT_PHP_INCLUDE -DNXT_ZEND_SIGNAL_STARTUP=$NXT_ZEND_SIGNAL_STARTUP \\
220	$nxt_dep_flags \\
221	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
222	$nxt_dep_post
223
224-include $NXT_BUILD_DIR/$nxt_dep
225
226END
227
228done
229
230
231cat << END >> $NXT_MAKEFILE
232
233.PHONY: ${NXT_PHP_MODULE}
234.PHONY: ${NXT_PHP_MODULE}-install
235.PHONY: ${NXT_PHP_MODULE}-uninstall
236
237all: ${NXT_PHP_MODULE}
238
239${NXT_PHP_MODULE}:	$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so
240
241$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so:	$nxt_objs
242	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
243	$nxt_objs ${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS} $NXT_LD_OPT
244
245
246install: ${NXT_PHP_MODULE}-install
247
248${NXT_PHP_MODULE}-install: ${NXT_PHP_MODULE} install-check
249	install -d \$(DESTDIR)$NXT_MODULES
250	install -p $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
251		\$(DESTDIR)$NXT_MODULES/
252
253
254uninstall: ${NXT_PHP_MODULE}-uninstall
255
256${NXT_PHP_MODULE}-uninstall:
257	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_PHP_MODULE}.unit.so
258	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
259
260END
261