xref: /unit/auto/modules/php (revision 265:864835cbba67)
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
21        --help)
22            cat << END
23
24    --config=FILE         set php-config filename
25    --module=NAME         set unit php module name
26    --lib-path=DIRECTORY  set directory path to libphp.so library
27
28END
29            exit 0
30        ;;
31
32        *)
33            echo
34            echo $0: error: invalid PHP option \"$nxt_option\"
35            echo
36            exit 1
37        ;;
38
39    esac
40
41done
42
43
44if [ ! -f $NXT_AUTOCONF_DATA ]; then
45   echo
46   echo Please run common $0 before configuring module \"$nxt_module\".
47   echo
48   exit 1
49fi
50
51. $NXT_AUTOCONF_DATA
52
53
54NXT_PHP_CONFIG=${NXT_PHP_CONFIG=php-config}
55NXT_PHP=${NXT_PHP_CONFIG%-config*}
56NXT_PHP_MODULE=${NXT_PHP_MODULE=${NXT_PHP##*/}}
57NXT_PHP_LIB_PATH=${NXT_PHP_LIB_PATH=}
58
59
60$echo "configuring PHP module"
61$echo "configuring PHP module ..." >> $NXT_AUTOCONF_ERR
62
63$echo -n "checking for PHP ..."
64$echo "checking for PHP ..." >> $NXT_AUTOCONF_ERR
65
66NXT_PHP_LDFLAGS=
67
68if /bin/sh -c "${NXT_PHP_CONFIG} --version"  >> $NXT_AUTOCONF_ERR 2>&1; then
69
70    $echo " found"
71
72    NXT_PHP_VERSION="`${NXT_PHP_CONFIG} --version`"
73    $echo " + PHP version: ${NXT_PHP_VERSION}"
74    $echo " + PHP SAPI: [`${NXT_PHP_CONFIG} --php-sapis`]"
75
76    NXT_PHP_INCLUDE="`${NXT_PHP_CONFIG} --includes`"
77    NXT_PHP_LIB="-lphp${NXT_PHP_VERSION%%.*}"
78
79    if [ "$NXT_PHP_LIB_PATH" != "" ]; then
80        # "php-config --ldflags" does not contain path to libphp.
81        NXT_PHP_LDFLAGS="-L${NXT_PHP_LIB_PATH} -Wl,-rpath ${NXT_PHP_LIB_PATH}"
82    fi
83
84    nxt_feature="PHP embed SAPI"
85    nxt_feature_name=NXT_HAVE_PHP
86    nxt_feature_run=no
87    nxt_feature_incs="${NXT_PHP_INCLUDE}"
88    nxt_feature_libs="${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}"
89    nxt_feature_test="
90        #include <php.h>
91        #include <php_main.h>
92
93        int main() {
94            php_request_startup();
95            return 0;
96        }"
97
98    . auto/feature
99
100    if [ $nxt_found = no ]; then
101        $echo
102        $echo $0: error: no PHP embed SAPI found.
103        $echo
104        exit 1;
105    fi
106
107else
108    $echo
109    $echo $0: error: no PHP found.
110    $echo
111    exit 1;
112fi
113
114if grep ^$NXT_PHP_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
115    $echo
116    $echo $0: error: duplicate \"$NXT_PHP_MODULE\" module configured.
117    $echo
118    exit 1;
119fi
120
121$echo " + PHP module: ${NXT_PHP_MODULE}.unit.so"
122
123
124$echo >> $NXT_MAKEFILE
125
126NXT_PHP_MODULE_SRCS=" \
127    src/nxt_php_sapi.c \
128"
129
130# The php module object files.
131
132nxt_objs=
133
134for nxt_src in $NXT_PHP_MODULE_SRCS; do
135
136    nxt_obj=`$echo $nxt_src | sed -e "s/\.c$/-$NXT_PHP_MODULE.o/"`
137    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
138
139    cat << END >> $NXT_MAKEFILE
140
141$NXT_BUILD_DIR/$nxt_obj:	$nxt_src
142	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_PHP_INCLUDE \\
143	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
144END
145
146done
147
148
149cat << END >> $NXT_MAKEFILE
150
151.PHONY: ${NXT_PHP_MODULE}
152.PHONY: ${NXT_PHP_MODULE}-install
153.PHONY: ${NXT_PHP_MODULE}-uninstall
154
155all: ${NXT_PHP_MODULE}
156
157${NXT_PHP_MODULE}:	$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so
158
159$NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so:	$nxt_objs
160	$NXT_MODULE_LINK -o $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
161	$nxt_objs ${NXT_PHP_LIB} ${NXT_PHP_LDFLAGS}
162
163
164install: ${NXT_PHP_MODULE}-install
165
166${NXT_PHP_MODULE}-install: ${NXT_PHP_MODULE}
167	install -d \$(DESTDIR)$NXT_MODULES
168	install -p $NXT_BUILD_DIR/${NXT_PHP_MODULE}.unit.so \\
169		\$(DESTDIR)$NXT_MODULES/
170
171
172uninstall: ${NXT_PHP_MODULE}-uninstall
173
174${NXT_PHP_MODULE}-uninstall:
175	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_PHP_MODULE}.unit.so
176	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
177
178END
179