xref: /unit/auto/modules/php (revision 1531)
1216Sigor@sysoev.ru
2216Sigor@sysoev.ru# Copyright (C) Max Romanov
3216Sigor@sysoev.ru# Copyright (C) Igor Sysoev
4216Sigor@sysoev.ru# Copyright (C) NGINX, Inc.
5216Sigor@sysoev.ru
6216Sigor@sysoev.ru
7216Sigor@sysoev.rushift
8216Sigor@sysoev.ru
9216Sigor@sysoev.rufor nxt_option; do
10216Sigor@sysoev.ru
11216Sigor@sysoev.ru    case "$nxt_option" in
12235Sigor@sysoev.ru        -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
13216Sigor@sysoev.ru           *) value="" ;;
14216Sigor@sysoev.ru    esac
15216Sigor@sysoev.ru
16216Sigor@sysoev.ru    case "$nxt_option" in
17216Sigor@sysoev.ru        --config=*)    NXT_PHP_CONFIG="$value"                               ;;
18216Sigor@sysoev.ru        --module=*)    NXT_PHP_MODULE="$value"                               ;;
19216Sigor@sysoev.ru        --lib-path=*)  NXT_PHP_LIB_PATH="$value"                             ;;
20466Sigor@sysoev.ru        --lib-static)  NXT_PHP_LIB_STATIC=yes                                ;;
21216Sigor@sysoev.ru
22216Sigor@sysoev.ru        --help)
23216Sigor@sysoev.ru            cat << END
24216Sigor@sysoev.ru
25235Sigor@sysoev.ru    --config=FILE         set php-config filename
26235Sigor@sysoev.ru    --module=NAME         set unit php module name
27235Sigor@sysoev.ru    --lib-path=DIRECTORY  set directory path to libphp.so library
28466Sigor@sysoev.ru    --lib-static          enable linking with static libphp.a library
29216Sigor@sysoev.ru
30216Sigor@sysoev.ruEND
31216Sigor@sysoev.ru            exit 0
32216Sigor@sysoev.ru        ;;
33216Sigor@sysoev.ru
34216Sigor@sysoev.ru        *)
35235Sigor@sysoev.ru            echo
36235Sigor@sysoev.ru            echo $0: error: invalid PHP option \"$nxt_option\"
37235Sigor@sysoev.ru            echo
38216Sigor@sysoev.ru            exit 1
39216Sigor@sysoev.ru        ;;
40216Sigor@sysoev.ru
41216Sigor@sysoev.ru    esac
42216Sigor@sysoev.ru
43235Sigor@sysoev.rudone
44216Sigor@sysoev.ru
45235Sigor@sysoev.ru
46235Sigor@sysoev.ruif [ ! -f $NXT_AUTOCONF_DATA ]; then
47235Sigor@sysoev.ru   echo
48235Sigor@sysoev.ru   echo Please run common $0 before configuring module \"$nxt_module\".
49235Sigor@sysoev.ru   echo
50235Sigor@sysoev.ru   exit 1
51235Sigor@sysoev.rufi
52235Sigor@sysoev.ru
53235Sigor@sysoev.ru. $NXT_AUTOCONF_DATA
54216Sigor@sysoev.ru
55216Sigor@sysoev.ru
56216Sigor@sysoev.ruNXT_PHP_CONFIG=${NXT_PHP_CONFIG=php-config}
57216Sigor@sysoev.ruNXT_PHP=${NXT_PHP_CONFIG%-config*}
58216Sigor@sysoev.ruNXT_PHP_MODULE=${NXT_PHP_MODULE=${NXT_PHP##*/}}
59216Sigor@sysoev.ruNXT_PHP_LIB_PATH=${NXT_PHP_LIB_PATH=}
60466Sigor@sysoev.ruNXT_PHP_LIB_STATIC=${NXT_PHP_LIB_STATIC=no}
611376St.nateldemoura@f5.comNXT_PHP_ADDITIONAL_FLAGS=
62216Sigor@sysoev.ru
63216Sigor@sysoev.ru
64216Sigor@sysoev.ru$echo "configuring PHP module"
65216Sigor@sysoev.ru$echo "configuring PHP module ..." >> $NXT_AUTOCONF_ERR
66216Sigor@sysoev.ru
67216Sigor@sysoev.ru$echo -n "checking for PHP ..."
68216Sigor@sysoev.ru$echo "checking for PHP ..." >> $NXT_AUTOCONF_ERR
69216Sigor@sysoev.ru
70216Sigor@sysoev.ruNXT_PHP_LDFLAGS=
71216Sigor@sysoev.ru
72277Sigor@sysoev.ruif /bin/sh -c "${NXT_PHP_CONFIG} --version" >> $NXT_AUTOCONF_ERR 2>&1; then
73216Sigor@sysoev.ru
74216Sigor@sysoev.ru    $echo " found"
75216Sigor@sysoev.ru
76216Sigor@sysoev.ru    NXT_PHP_VERSION="`${NXT_PHP_CONFIG} --version`"
77216Sigor@sysoev.ru    $echo " + PHP SAPI: [`${NXT_PHP_CONFIG} --php-sapis`]"
78216Sigor@sysoev.ru
791376St.nateldemoura@f5.com    NXT_PHP_MAJOR_VERSION=${NXT_PHP_VERSION%%.*}
80*1531St.nateldemoura@f5.com    NXT_PHP_MINOR_VERSION=${NXT_PHP_VERSION#*.}
81*1531St.nateldemoura@f5.com    NXT_PHP_MINOR_VERSION=${NXT_PHP_MINOR_VERSION%%.*}
821376St.nateldemoura@f5.com
831376St.nateldemoura@f5.com    if [ $NXT_PHP_MAJOR_VERSION = 5 -a $NXT_PHP_MINOR_VERSION -lt 4 ]; then
841376St.nateldemoura@f5.com        NXT_PHP_ADDITIONAL_FLAGS=-Wno-write-strings
851376St.nateldemoura@f5.com    fi
861376St.nateldemoura@f5.com
87216Sigor@sysoev.ru    NXT_PHP_INCLUDE="`${NXT_PHP_CONFIG} --includes`"
88216Sigor@sysoev.ru
89466Sigor@sysoev.ru    if [ $NXT_PHP_LIB_STATIC = yes ]; then
90468Sigor@sysoev.ru
91468Sigor@sysoev.ru        if [ "$NXT_PHP_LIB_PATH" = "" ]; then
92468Sigor@sysoev.ru            $echo
93468Sigor@sysoev.ru            $echo $0: error: --lib-static option requires --lib-path option.
94468Sigor@sysoev.ru            $echo
95468Sigor@sysoev.ru            exit 1;
96468Sigor@sysoev.ru        fi
97466Sigor@sysoev.ru
98468Sigor@sysoev.ru        NXT_PHP_LIB="$NXT_PHP_LIB_PATH/libphp${NXT_PHP_VERSION%%.*}.a"
99682Sigor@sysoev.ru        NXT_PHP_LDFLAGS="`${NXT_PHP_CONFIG} --ldflags` \
100682Sigor@sysoev.ru                         `${NXT_PHP_CONFIG} --libs`"
101468Sigor@sysoev.ru
102468Sigor@sysoev.ru    else
1031482Sremi@remirepo.net        if [ $NXT_PHP_MAJOR_VERSION -ge 8 ]; then
1041482Sremi@remirepo.net            NXT_PHP_LIB="-lphp"
1051482Sremi@remirepo.net        else
1061482Sremi@remirepo.net            NXT_PHP_LIB="-lphp${NXT_PHP_VERSION%%.*}"
1071482Sremi@remirepo.net        fi
108468Sigor@sysoev.ru
109468Sigor@sysoev.ru        if [ "$NXT_PHP_LIB_PATH" != "" ]; then
110682Sigor@sysoev.ru            # "php-config --ldflags" does not contain path to libphp, but
111682Sigor@sysoev.ru            # contains usually path to libraries required by extensions.
112468Sigor@sysoev.ru            NXT_PHP_LDFLAGS="-L${NXT_PHP_LIB_PATH} \
113468Sigor@sysoev.ru                             -Wl,-rpath ${NXT_PHP_LIB_PATH}"
114468Sigor@sysoev.ru        fi
115216Sigor@sysoev.ru    fi
116216Sigor@sysoev.ru
117216Sigor@sysoev.ruelse
118216Sigor@sysoev.ru    $echo
119216Sigor@sysoev.ru    $echo $0: error: no PHP found.
120216Sigor@sysoev.ru    $echo
121216Sigor@sysoev.ru    exit 1;
122216Sigor@sysoev.rufi
123216Sigor@sysoev.ru
124612Salexander.borisov@nginx.com
125612Salexander.borisov@nginx.comnxt_feature="PHP version"
126612Salexander.borisov@nginx.comnxt_feature_name=""
127612Salexander.borisov@nginx.comnxt_feature_run=value
128612Salexander.borisov@nginx.comnxt_feature_incs="${NXT_PHP_INCLUDE}"
129612Salexander.borisov@nginx.comnxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
130612Salexander.borisov@nginx.comnxt_feature_test="
131612Salexander.borisov@nginx.com    #include <php.h>
132612Salexander.borisov@nginx.com
133612Salexander.borisov@nginx.com    int main() {
134612Salexander.borisov@nginx.com        printf(\"%s\", PHP_VERSION);
135612Salexander.borisov@nginx.com        return 0;
136612Salexander.borisov@nginx.com    }"
137612Salexander.borisov@nginx.com
138612Salexander.borisov@nginx.com. auto/feature
139612Salexander.borisov@nginx.com
140612Salexander.borisov@nginx.com
1411382Svbart@nginx.comnxt_feature="PHP embed SAPI"
1421382Svbart@nginx.comnxt_feature_name=""
1431382Svbart@nginx.comnxt_feature_run=no
1441382Svbart@nginx.comnxt_feature_incs="${NXT_PHP_INCLUDE}"
1451382Svbart@nginx.comnxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
1461382Svbart@nginx.comnxt_feature_test="
1471382Svbart@nginx.com    #include <php.h>
1481382Svbart@nginx.com    #include <php_main.h>
1491382Svbart@nginx.com
1501382Svbart@nginx.com    int main() {
1511382Svbart@nginx.com        php_module_startup(NULL, NULL, 0);
1521382Svbart@nginx.com        return 0;
1531382Svbart@nginx.com    }"
1541382Svbart@nginx.com
1551382Svbart@nginx.com. auto/feature
1561382Svbart@nginx.com
1571382Svbart@nginx.comif [ $nxt_found = no ]; then
1581382Svbart@nginx.com    $echo
1591382Svbart@nginx.com    $echo $0: error: no PHP embed SAPI found.
1601382Svbart@nginx.com    $echo
1611382Svbart@nginx.com    exit 1;
1621382Svbart@nginx.comfi
1631382Svbart@nginx.com
1641382Svbart@nginx.com
1651383Svbart@nginx.comnxt_feature="PHP Zend Thread Safety"
1661383Svbart@nginx.comnxt_feature_name=""
1671383Svbart@nginx.comnxt_feature_run=no
1681383Svbart@nginx.comnxt_feature_incs="${NXT_PHP_INCLUDE}"
1691383Svbart@nginx.comnxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
1701383Svbart@nginx.comnxt_feature_test="
1711383Svbart@nginx.com    #include <php.h>
1721383Svbart@nginx.com    #include <php_main.h>
1731383Svbart@nginx.com
1741383Svbart@nginx.com    int main() {
1751383Svbart@nginx.com        #ifndef ZTS
1761383Svbart@nginx.com        #error ZTS is not defined.
1771383Svbart@nginx.com        #endif
1781383Svbart@nginx.com        return 0;
1791383Svbart@nginx.com    }"
1801383Svbart@nginx.com
1811383Svbart@nginx.com. auto/feature
1821383Svbart@nginx.com
1831383Svbart@nginx.com
1841382Svbart@nginx.com# Bug #71041 (https://bugs.php.net/bug.php?id=71041).
1851382Svbart@nginx.com
1861382Svbart@nginx.comnxt_feature="PHP zend_signal_startup()"
1871382Svbart@nginx.comnxt_feature_name=""
1881382Svbart@nginx.comnxt_feature_run=no
1891382Svbart@nginx.comnxt_feature_incs="${NXT_PHP_INCLUDE}"
1901382Svbart@nginx.comnxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
1911382Svbart@nginx.comnxt_feature_test="
1921382Svbart@nginx.com    #include <php.h>
1931382Svbart@nginx.com    #include <php_main.h>
1941382Svbart@nginx.com
1951382Svbart@nginx.com    int main() {
1961382Svbart@nginx.com        zend_signal_startup();
1971382Svbart@nginx.com        return 0;
1981382Svbart@nginx.com    }"
1991382Svbart@nginx.com
2001382Svbart@nginx.com. auto/feature
2011382Svbart@nginx.com
2021382Svbart@nginx.comif [ $nxt_found = yes ]; then
2031382Svbart@nginx.com    NXT_ZEND_SIGNAL_STARTUP=1
2041382Svbart@nginx.comelse
2051382Svbart@nginx.com    NXT_ZEND_SIGNAL_STARTUP=0
2061382Svbart@nginx.comfi
2071382Svbart@nginx.com
2081382Svbart@nginx.com
209216Sigor@sysoev.ruif grep ^$NXT_PHP_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
210216Sigor@sysoev.ru    $echo
211216Sigor@sysoev.ru    $echo $0: error: duplicate \"$NXT_PHP_MODULE\" module configured.
212216Sigor@sysoev.ru    $echo
213216Sigor@sysoev.ru    exit 1;
214216Sigor@sysoev.rufi
215216Sigor@sysoev.ru
216260Sigor@sysoev.ru$echo " + PHP module: ${NXT_PHP_MODULE}.unit.so"
217216Sigor@sysoev.ru
218396Smax.romanov@nginx.com. auto/cc/deps
219216Sigor@sysoev.ru
220216Sigor@sysoev.ru$echo >> $NXT_MAKEFILE
221216Sigor@sysoev.ru
222216Sigor@sysoev.ruNXT_PHP_MODULE_SRCS=" \
223216Sigor@sysoev.ru    src/nxt_php_sapi.c \
224216Sigor@sysoev.ru"
225216Sigor@sysoev.ru
226216Sigor@sysoev.ru# The php module object files.
227216Sigor@sysoev.ru
228743Smax.romanov@nginx.comnxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
229216Sigor@sysoev.ru
230216Sigor@sysoev.rufor nxt_src in $NXT_PHP_MODULE_SRCS; do
231216Sigor@sysoev.ru
232396Smax.romanov@nginx.com    nxt_obj=${nxt_src%.c}-$NXT_PHP_MODULE.o
233396Smax.romanov@nginx.com    nxt_dep=${nxt_src%.c}-$NXT_PHP_MODULE.dep
234396Smax.romanov@nginx.com    nxt_dep_flags=`nxt_gen_dep_flags`
235396Smax.romanov@nginx.com    nxt_dep_post=`nxt_gen_dep_post`
236216Sigor@sysoev.ru    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
237216Sigor@sysoev.ru
238216Sigor@sysoev.ru    cat << END >> $NXT_MAKEFILE
239216Sigor@sysoev.ru
2401217Smax.romanov@nginx.com$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
2411376St.nateldemoura@f5.com	\$(CC) -c \$(CFLAGS) $NXT_PHP_ADDITIONAL_FLAGS \$(NXT_INCS) \\
2421376St.nateldemoura@f5.com	$NXT_PHP_INCLUDE -DNXT_ZEND_SIGNAL_STARTUP=$NXT_ZEND_SIGNAL_STARTUP \\
243396Smax.romanov@nginx.com	$nxt_dep_flags \\
244216Sigor@sysoev.ru	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
245396Smax.romanov@nginx.com	$nxt_dep_post
246681Smax.romanov@nginx.com
247681Smax.romanov@nginx.com-include $NXT_BUILD_DIR/$nxt_dep
248681Smax.romanov@nginx.com
249216Sigor@sysoev.ruEND
250216Sigor@sysoev.ru
251216Sigor@sysoev.rudone
252216Sigor@sysoev.ru
253858Svbart@nginx.com
254216Sigor@sysoev.rucat << END >> $NXT_MAKEFILE
255216Sigor@sysoev.ru
256265Smax.romanov@nginx.com.PHONY: ${NXT_PHP_MODULE}
257265Smax.romanov@nginx.com.PHONY: ${NXT_PHP_MODULE}-install
258265Smax.romanov@nginx.com.PHONY: ${NXT_PHP_MODULE}-uninstall
259216Sigor@sysoev.ru
260241Smax.romanov@nginx.comall: ${NXT_PHP_MODULE}
261241Smax.romanov@nginx.com
262260Sigor@sysoev.ru${NXT_PHP_MODULE}:	$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so
263216Sigor@sysoev.ru
264260Sigor@sysoev.ru$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so:	$nxt_objs
265395Smax.romanov@nginx.com	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
266395Smax.romanov@nginx.com	$nxt_objs ${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS} $NXT_LD_OPT
267216Sigor@sysoev.ru
268265Smax.romanov@nginx.com
269265Smax.romanov@nginx.cominstall: ${NXT_PHP_MODULE}-install
270265Smax.romanov@nginx.com
271706Sigor@sysoev.ru${NXT_PHP_MODULE}-install: ${NXT_PHP_MODULE} install-check
272265Smax.romanov@nginx.com	install -d \$(DESTDIR)$NXT_MODULES
273265Smax.romanov@nginx.com	install -p $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
274265Smax.romanov@nginx.com		\$(DESTDIR)$NXT_MODULES/
275265Smax.romanov@nginx.com
276265Smax.romanov@nginx.com
277265Smax.romanov@nginx.comuninstall: ${NXT_PHP_MODULE}-uninstall
278265Smax.romanov@nginx.com
279265Smax.romanov@nginx.com${NXT_PHP_MODULE}-uninstall:
280265Smax.romanov@nginx.com	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_PHP_MODULE}.unit.so
281265Smax.romanov@nginx.com	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
282265Smax.romanov@nginx.com
283216Sigor@sysoev.ruEND
284