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