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