xref: /unit/auto/modules/php (revision 1622)
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`"
771583St.nateldemoura@f5.com    NXT_PHP_EXT_DIR="`${NXT_PHP_CONFIG} --extension-dir`"
781583St.nateldemoura@f5.com
79216Sigor@sysoev.ru    $echo " + PHP SAPI: [`${NXT_PHP_CONFIG} --php-sapis`]"
80216Sigor@sysoev.ru
811376St.nateldemoura@f5.com    NXT_PHP_MAJOR_VERSION=${NXT_PHP_VERSION%%.*}
821531St.nateldemoura@f5.com    NXT_PHP_MINOR_VERSION=${NXT_PHP_VERSION#*.}
831531St.nateldemoura@f5.com    NXT_PHP_MINOR_VERSION=${NXT_PHP_MINOR_VERSION%%.*}
841376St.nateldemoura@f5.com
851376St.nateldemoura@f5.com    if [ $NXT_PHP_MAJOR_VERSION = 5 -a $NXT_PHP_MINOR_VERSION -lt 4 ]; then
861376St.nateldemoura@f5.com        NXT_PHP_ADDITIONAL_FLAGS=-Wno-write-strings
871376St.nateldemoura@f5.com    fi
881376St.nateldemoura@f5.com
89216Sigor@sysoev.ru    NXT_PHP_INCLUDE="`${NXT_PHP_CONFIG} --includes`"
90216Sigor@sysoev.ru
91466Sigor@sysoev.ru    if [ $NXT_PHP_LIB_STATIC = yes ]; then
92468Sigor@sysoev.ru
93468Sigor@sysoev.ru        if [ "$NXT_PHP_LIB_PATH" = "" ]; then
94468Sigor@sysoev.ru            $echo
95468Sigor@sysoev.ru            $echo $0: error: --lib-static option requires --lib-path option.
96468Sigor@sysoev.ru            $echo
97468Sigor@sysoev.ru            exit 1;
98468Sigor@sysoev.ru        fi
99466Sigor@sysoev.ru
100468Sigor@sysoev.ru        NXT_PHP_LIB="$NXT_PHP_LIB_PATH/libphp${NXT_PHP_VERSION%%.*}.a"
101682Sigor@sysoev.ru        NXT_PHP_LDFLAGS="`${NXT_PHP_CONFIG} --ldflags` \
102682Sigor@sysoev.ru                         `${NXT_PHP_CONFIG} --libs`"
103468Sigor@sysoev.ru
104468Sigor@sysoev.ru    else
1051482Sremi@remirepo.net        if [ $NXT_PHP_MAJOR_VERSION -ge 8 ]; then
1061482Sremi@remirepo.net            NXT_PHP_LIB="-lphp"
1071482Sremi@remirepo.net        else
1081482Sremi@remirepo.net            NXT_PHP_LIB="-lphp${NXT_PHP_VERSION%%.*}"
1091482Sremi@remirepo.net        fi
110468Sigor@sysoev.ru
111468Sigor@sysoev.ru        if [ "$NXT_PHP_LIB_PATH" != "" ]; then
112682Sigor@sysoev.ru            # "php-config --ldflags" does not contain path to libphp, but
113682Sigor@sysoev.ru            # contains usually path to libraries required by extensions.
114468Sigor@sysoev.ru            NXT_PHP_LDFLAGS="-L${NXT_PHP_LIB_PATH} \
115468Sigor@sysoev.ru                             -Wl,-rpath ${NXT_PHP_LIB_PATH}"
116468Sigor@sysoev.ru        fi
117216Sigor@sysoev.ru    fi
118216Sigor@sysoev.ru
119216Sigor@sysoev.ruelse
120216Sigor@sysoev.ru    $echo
121216Sigor@sysoev.ru    $echo $0: error: no PHP found.
122216Sigor@sysoev.ru    $echo
123216Sigor@sysoev.ru    exit 1;
124216Sigor@sysoev.rufi
125216Sigor@sysoev.ru
126612Salexander.borisov@nginx.com
127612Salexander.borisov@nginx.comnxt_feature="PHP version"
128612Salexander.borisov@nginx.comnxt_feature_name=""
129612Salexander.borisov@nginx.comnxt_feature_run=value
130612Salexander.borisov@nginx.comnxt_feature_incs="${NXT_PHP_INCLUDE}"
131612Salexander.borisov@nginx.comnxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
132612Salexander.borisov@nginx.comnxt_feature_test="
133612Salexander.borisov@nginx.com    #include <php.h>
134612Salexander.borisov@nginx.com
135612Salexander.borisov@nginx.com    int main() {
136612Salexander.borisov@nginx.com        printf(\"%s\", PHP_VERSION);
137612Salexander.borisov@nginx.com        return 0;
138612Salexander.borisov@nginx.com    }"
139612Salexander.borisov@nginx.com
140612Salexander.borisov@nginx.com. auto/feature
141612Salexander.borisov@nginx.com
142612Salexander.borisov@nginx.com
1431382Svbart@nginx.comnxt_feature="PHP embed SAPI"
1441382Svbart@nginx.comnxt_feature_name=""
1451382Svbart@nginx.comnxt_feature_run=no
1461382Svbart@nginx.comnxt_feature_incs="${NXT_PHP_INCLUDE}"
1471382Svbart@nginx.comnxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
1481382Svbart@nginx.comnxt_feature_test="
1491382Svbart@nginx.com    #include <php.h>
1501382Svbart@nginx.com    #include <php_main.h>
1511382Svbart@nginx.com
1521382Svbart@nginx.com    int main() {
1531382Svbart@nginx.com        php_module_startup(NULL, NULL, 0);
1541382Svbart@nginx.com        return 0;
1551382Svbart@nginx.com    }"
1561382Svbart@nginx.com
1571382Svbart@nginx.com. auto/feature
1581382Svbart@nginx.com
1591382Svbart@nginx.comif [ $nxt_found = no ]; then
1601382Svbart@nginx.com    $echo
1611382Svbart@nginx.com    $echo $0: error: no PHP embed SAPI found.
1621382Svbart@nginx.com    $echo
1631382Svbart@nginx.com    exit 1;
1641382Svbart@nginx.comfi
1651382Svbart@nginx.com
1661382Svbart@nginx.com
1671383Svbart@nginx.comnxt_feature="PHP Zend Thread Safety"
1681383Svbart@nginx.comnxt_feature_name=""
1691383Svbart@nginx.comnxt_feature_run=no
1701383Svbart@nginx.comnxt_feature_incs="${NXT_PHP_INCLUDE}"
1711383Svbart@nginx.comnxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
1721383Svbart@nginx.comnxt_feature_test="
1731383Svbart@nginx.com    #include <php.h>
1741383Svbart@nginx.com    #include <php_main.h>
1751383Svbart@nginx.com
1761383Svbart@nginx.com    int main() {
1771383Svbart@nginx.com        #ifndef ZTS
1781383Svbart@nginx.com        #error ZTS is not defined.
1791383Svbart@nginx.com        #endif
1801383Svbart@nginx.com        return 0;
1811383Svbart@nginx.com    }"
1821383Svbart@nginx.com
1831383Svbart@nginx.com. auto/feature
1841383Svbart@nginx.com
1851383Svbart@nginx.com
1861382Svbart@nginx.com# Bug #71041 (https://bugs.php.net/bug.php?id=71041).
1871382Svbart@nginx.com
1881382Svbart@nginx.comnxt_feature="PHP zend_signal_startup()"
1891382Svbart@nginx.comnxt_feature_name=""
1901382Svbart@nginx.comnxt_feature_run=no
1911382Svbart@nginx.comnxt_feature_incs="${NXT_PHP_INCLUDE}"
1921382Svbart@nginx.comnxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
1931382Svbart@nginx.comnxt_feature_test="
1941382Svbart@nginx.com    #include <php.h>
1951382Svbart@nginx.com    #include <php_main.h>
1961382Svbart@nginx.com
1971382Svbart@nginx.com    int main() {
1981382Svbart@nginx.com        zend_signal_startup();
1991382Svbart@nginx.com        return 0;
2001382Svbart@nginx.com    }"
2011382Svbart@nginx.com
2021382Svbart@nginx.com. auto/feature
2031382Svbart@nginx.com
2041382Svbart@nginx.comif [ $nxt_found = yes ]; then
2051382Svbart@nginx.com    NXT_ZEND_SIGNAL_STARTUP=1
2061382Svbart@nginx.comelse
2071382Svbart@nginx.com    NXT_ZEND_SIGNAL_STARTUP=0
2081382Svbart@nginx.comfi
2091382Svbart@nginx.com
2101382Svbart@nginx.com
211216Sigor@sysoev.ruif grep ^$NXT_PHP_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
212216Sigor@sysoev.ru    $echo
213216Sigor@sysoev.ru    $echo $0: error: duplicate \"$NXT_PHP_MODULE\" module configured.
214216Sigor@sysoev.ru    $echo
215216Sigor@sysoev.ru    exit 1;
216216Sigor@sysoev.rufi
217216Sigor@sysoev.ru
2181583St.nateldemoura@f5.com
219260Sigor@sysoev.ru$echo " + PHP module: ${NXT_PHP_MODULE}.unit.so"
220216Sigor@sysoev.ru
221396Smax.romanov@nginx.com. auto/cc/deps
222216Sigor@sysoev.ru
223216Sigor@sysoev.ru$echo >> $NXT_MAKEFILE
224216Sigor@sysoev.ru
225216Sigor@sysoev.ruNXT_PHP_MODULE_SRCS=" \
226216Sigor@sysoev.ru    src/nxt_php_sapi.c \
227216Sigor@sysoev.ru"
228216Sigor@sysoev.ru
229216Sigor@sysoev.ru# The php module object files.
230216Sigor@sysoev.ru
231743Smax.romanov@nginx.comnxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
232216Sigor@sysoev.ru
233216Sigor@sysoev.rufor nxt_src in $NXT_PHP_MODULE_SRCS; do
234216Sigor@sysoev.ru
235396Smax.romanov@nginx.com    nxt_obj=${nxt_src%.c}-$NXT_PHP_MODULE.o
236396Smax.romanov@nginx.com    nxt_dep=${nxt_src%.c}-$NXT_PHP_MODULE.dep
237396Smax.romanov@nginx.com    nxt_dep_flags=`nxt_gen_dep_flags`
238396Smax.romanov@nginx.com    nxt_dep_post=`nxt_gen_dep_post`
239216Sigor@sysoev.ru    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
240216Sigor@sysoev.ru
241216Sigor@sysoev.ru    cat << END >> $NXT_MAKEFILE
242216Sigor@sysoev.ru
2431217Smax.romanov@nginx.com$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
244*1622St.nateldemoura@f5.com	\$(CC) -c \$(CFLAGS) $NXT_PHP_ADDITIONAL_FLAGS \$(NXT_INCS) \\
2451376St.nateldemoura@f5.com	$NXT_PHP_INCLUDE -DNXT_ZEND_SIGNAL_STARTUP=$NXT_ZEND_SIGNAL_STARTUP \\
246396Smax.romanov@nginx.com	$nxt_dep_flags \\
247216Sigor@sysoev.ru	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
248396Smax.romanov@nginx.com	$nxt_dep_post
249681Smax.romanov@nginx.com
250681Smax.romanov@nginx.com-include $NXT_BUILD_DIR/$nxt_dep
251681Smax.romanov@nginx.com
252216Sigor@sysoev.ruEND
253216Sigor@sysoev.ru
254216Sigor@sysoev.rudone
255216Sigor@sysoev.ru
256858Svbart@nginx.com
257216Sigor@sysoev.rucat << END >> $NXT_MAKEFILE
258216Sigor@sysoev.ru
259265Smax.romanov@nginx.com.PHONY: ${NXT_PHP_MODULE}
260265Smax.romanov@nginx.com.PHONY: ${NXT_PHP_MODULE}-install
261265Smax.romanov@nginx.com.PHONY: ${NXT_PHP_MODULE}-uninstall
262216Sigor@sysoev.ru
263241Smax.romanov@nginx.comall: ${NXT_PHP_MODULE}
264241Smax.romanov@nginx.com
265260Sigor@sysoev.ru${NXT_PHP_MODULE}:	$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so
266216Sigor@sysoev.ru
267260Sigor@sysoev.ru$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so:	$nxt_objs
268395Smax.romanov@nginx.com	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
269395Smax.romanov@nginx.com	$nxt_objs ${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS} $NXT_LD_OPT
270216Sigor@sysoev.ru
271265Smax.romanov@nginx.com
272265Smax.romanov@nginx.cominstall: ${NXT_PHP_MODULE}-install
273265Smax.romanov@nginx.com
274706Sigor@sysoev.ru${NXT_PHP_MODULE}-install: ${NXT_PHP_MODULE} install-check
275265Smax.romanov@nginx.com	install -d \$(DESTDIR)$NXT_MODULES
276265Smax.romanov@nginx.com	install -p $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
277265Smax.romanov@nginx.com		\$(DESTDIR)$NXT_MODULES/
278265Smax.romanov@nginx.com
279265Smax.romanov@nginx.com
280265Smax.romanov@nginx.comuninstall: ${NXT_PHP_MODULE}-uninstall
281265Smax.romanov@nginx.com
282265Smax.romanov@nginx.com${NXT_PHP_MODULE}-uninstall:
283265Smax.romanov@nginx.com	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_PHP_MODULE}.unit.so
284265Smax.romanov@nginx.com	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
285265Smax.romanov@nginx.com
286216Sigor@sysoev.ruEND
287