xref: /unit/auto/modules/php (revision 466:8e31d63208f2)
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}
61
62
63$echo "configuring PHP module"
64$echo "configuring PHP module ..." >> $NXT_AUTOCONF_ERR
65
66$echo -n "checking for PHP ..."
67$echo "checking for PHP ..." >> $NXT_AUTOCONF_ERR
68
69NXT_PHP_LDFLAGS=
70
71if /bin/sh -c "${NXT_PHP_CONFIG} --version" >> $NXT_AUTOCONF_ERR 2>&1; then
72
73    $echo " found"
74
75    NXT_PHP_VERSION="`${NXT_PHP_CONFIG} --version`"
76    $echo " + PHP version: ${NXT_PHP_VERSION}"
77    $echo " + PHP SAPI: [`${NXT_PHP_CONFIG} --php-sapis`]"
78
79    NXT_PHP_INCLUDE="`${NXT_PHP_CONFIG} --includes`"
80    NXT_PHP_LIB="-lphp${NXT_PHP_VERSION%%.*}"
81
82    if [ $NXT_PHP_LIB_STATIC = yes ]; then
83        NXT_PHP_LIB="${NXT_PHP_LIB} `${NXT_PHP_CONFIG} --libs`"
84    fi
85
86    if [ "$NXT_PHP_LIB_PATH" != "" ]; then
87        # "php-config --ldflags" does not contain path to libphp.
88        NXT_PHP_LDFLAGS="-L${NXT_PHP_LIB_PATH} -Wl,-rpath ${NXT_PHP_LIB_PATH}"
89    fi
90
91    nxt_feature="PHP embed SAPI"
92    nxt_feature_name=""
93    nxt_feature_run=no
94    nxt_feature_incs="${NXT_PHP_INCLUDE}"
95    nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
96    nxt_feature_test="
97        #include <php.h>
98        #include <php_main.h>
99
100        int main() {
101            php_request_startup();
102            return 0;
103        }"
104
105    . auto/feature
106
107    if [ $nxt_found = no ]; then
108        $echo
109        $echo $0: error: no PHP embed SAPI found.
110        $echo
111        exit 1;
112    fi
113
114else
115    $echo
116    $echo $0: error: no PHP found.
117    $echo
118    exit 1;
119fi
120
121if grep ^$NXT_PHP_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
122    $echo
123    $echo $0: error: duplicate \"$NXT_PHP_MODULE\" module configured.
124    $echo
125    exit 1;
126fi
127
128$echo " + PHP module: ${NXT_PHP_MODULE}.unit.so"
129
130. auto/cc/deps
131
132$echo >> $NXT_MAKEFILE
133
134NXT_PHP_MODULE_SRCS=" \
135    src/nxt_php_sapi.c \
136"
137
138# The php module object files.
139
140nxt_objs=
141
142for nxt_src in $NXT_PHP_MODULE_SRCS; do
143
144    nxt_obj=${nxt_src%.c}-$NXT_PHP_MODULE.o
145    nxt_dep=${nxt_src%.c}-$NXT_PHP_MODULE.dep
146    nxt_dep_flags=`nxt_gen_dep_flags`
147    nxt_dep_post=`nxt_gen_dep_post`
148    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
149
150    cat << END >> $NXT_MAKEFILE
151
152$NXT_BUILD_DIR/$nxt_obj:	$nxt_src
153	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_PHP_INCLUDE \\
154	$nxt_dep_flags \\
155	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
156	$nxt_dep_post
157END
158
159done
160
161
162cat << END >> $NXT_MAKEFILE
163
164.PHONY: ${NXT_PHP_MODULE}
165.PHONY: ${NXT_PHP_MODULE}-install
166.PHONY: ${NXT_PHP_MODULE}-uninstall
167
168all: ${NXT_PHP_MODULE}
169
170${NXT_PHP_MODULE}:	$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so
171
172$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so:	$nxt_objs
173	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
174	$nxt_objs ${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS} $NXT_LD_OPT
175
176
177install: ${NXT_PHP_MODULE}-install
178
179${NXT_PHP_MODULE}-install: ${NXT_PHP_MODULE}
180	install -d \$(DESTDIR)$NXT_MODULES
181	install -p $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
182		\$(DESTDIR)$NXT_MODULES/
183
184
185uninstall: ${NXT_PHP_MODULE}-uninstall
186
187${NXT_PHP_MODULE}-uninstall:
188	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_PHP_MODULE}.unit.so
189	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
190
191END
192