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