xref: /unit/auto/modules/perl (revision 1217:ed8c4e263152)
1
2# Copyright (C) Alexander Borisov
3# Copyright (C) NGINX, Inc.
4
5
6shift
7
8for nxt_option; do
9
10    case "$nxt_option" in
11        -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
12           *) value="" ;;
13    esac
14
15    case "$nxt_option" in
16        --perl=*)      NXT_PERL="$value"                                ;;
17        --module=*)    NXT_PERL_MODULE="$value"                         ;;
18
19        --help)
20            cat << END
21
22    --perl=FILE           set perl executable, default: perl
23    --module=NAME         set unit perl module name
24
25END
26            exit 0
27        ;;
28
29        *)
30            echo
31            echo $0: error: invalid Perl option \"$nxt_option\"
32            echo
33            exit 1
34        ;;
35    esac
36
37done
38
39
40if [ ! -f $NXT_AUTOCONF_DATA ]; then
41   echo
42   echo Please run common $0 before configuring module \"$nxt_module\".
43   echo
44   exit 1
45fi
46
47. $NXT_AUTOCONF_DATA
48
49$echo "configuring Perl module"
50$echo "configuring Perl module ..." >> $NXT_AUTOCONF_ERR
51
52NXT_PERL=${NXT_PERL=perl}
53NXT_PERL_MODULE=${NXT_PERL_MODULE=${NXT_PERL##*/}}
54
55nxt_found=no
56
57if /bin/sh -c "$NXT_PERL -MConfig -e 'print \"Perl version: \",
58    \$Config{version}, \"\\n\"'" >> $NXT_AUTOCONF_ERR 2>&1; then
59
60    NXT_PERL_CFLAGS=`$NXT_PERL -MExtUtils::Embed -e ccflags | sed -e 's/^ //;s/ $//'`
61    NXT_PERL_INCLUDE=`$NXT_PERL -MExtUtils::Embed -e perl_inc | sed -e 's/^ //;s/ $//'`
62    NXT_PERL_LDOPTS=`$NXT_PERL -MExtUtils::Embed -e ldopts | sed -e 's/^ //;s/ $//'`
63
64    if [ "$NXT_SYSTEM" = "Darwin" ]; then
65        # OS X system perl wants to link universal binaries
66        NXT_PERL_LDOPTS=`echo $NXT_PERL_LDOPTS \
67                         | sed -e 's/-arch i386//' -e 's/-arch x86_64//'`
68    fi
69
70    nxt_feature="Perl"
71    nxt_feature_name=""
72    nxt_feature_run=no
73    nxt_feature_incs="${NXT_PERL_INCLUDE}"
74    nxt_feature_libs="${NXT_PERL_LDOPTS}"
75    nxt_feature_test="
76        #define _GNU_SOURCE
77        #include <EXTERN.h>
78        #include <perl.h>
79
80        static PerlInterpreter *my_perl;
81
82        int main() {
83            char argv[] = \"\\0-e\\00\";
84            char *embedding[] = { &argv[0], &argv[1], &argv[4] };
85
86            int pargc = 0;
87            char **pargv = NULL, **penv = NULL;
88            PERL_SYS_INIT3(&pargc, &pargv, &penv);
89
90            my_perl = perl_alloc();
91            perl_construct(my_perl);
92            perl_parse(my_perl, NULL, 3, embedding, NULL);
93            PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
94            perl_run(my_perl);
95
96            perl_destruct(my_perl);
97            perl_free(my_perl);
98            PERL_SYS_TERM();
99
100            return 0;
101        }"
102
103    . auto/feature
104
105else
106    $echo "checking for Perl ... not found"
107fi
108
109if [ $nxt_found = no ]; then
110    $echo
111    $echo $0: error: no Perl found.
112    $echo
113    exit 1;
114fi
115
116
117nxt_feature="Perl version"
118nxt_feature_name=""
119nxt_feature_run=value
120nxt_feature_incs="${NXT_PERL_INCLUDE}"
121nxt_feature_libs="${NXT_PERL_LDOPTS}"
122nxt_feature_test="
123    #define _GNU_SOURCE
124    #include <EXTERN.h>
125    #include <perl.h>
126
127    int main() {
128        printf(\"%s\", PERL_VERSION_STRING);
129        return 0;
130    }"
131
132. auto/feature
133
134
135if grep ^$NXT_PERL_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
136    $echo
137    $echo $0: error: duplicate \"$NXT_PERL_MODULE\" module configured.
138    $echo
139    exit 1;
140fi
141
142$echo " + Perl module: ${NXT_PERL_MODULE}.unit.so"
143
144. auto/cc/deps
145
146$echo >> $NXT_MAKEFILE
147
148NXT_PERL_MODULE_SRCS=" \
149    src/perl/nxt_perl_psgi.c \
150    src/perl/nxt_perl_psgi_layer.c
151"
152
153# The Perl module object files.
154
155nxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
156
157for nxt_src in $NXT_PERL_MODULE_SRCS; do
158
159    nxt_obj=${nxt_src%.c}-$NXT_PERL_MODULE.o
160    nxt_dep=${nxt_src%.c}-$NXT_PERL_MODULE.dep
161    nxt_dep_flags=`nxt_gen_dep_flags`
162    nxt_dep_post=`nxt_gen_dep_post`
163    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
164
165    cat << END >> $NXT_MAKEFILE
166
167$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
168	mkdir -p $NXT_BUILD_DIR/src/perl
169	\$(CC) -c \$(CFLAGS) $NXT_PERL_CFLAGS \$(NXT_INCS) $NXT_PERL_INCLUDE \\
170	$nxt_dep_flags \\
171	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
172	$nxt_dep_post
173
174-include $NXT_BUILD_DIR/$nxt_dep
175
176END
177
178done
179
180cat << END >> $NXT_MAKEFILE
181
182.PHONY: ${NXT_PERL_MODULE}
183.PHONY: ${NXT_PERL_MODULE}-install
184.PHONY: ${NXT_PERL_MODULE}-uninstall
185
186all: ${NXT_PERL_MODULE}
187
188${NXT_PERL_MODULE}:	$NXT_BUILD_DIR/${NXT_PERL_MODULE}.unit.so
189
190$NXT_BUILD_DIR/${NXT_PERL_MODULE}.unit.so:	$nxt_objs
191	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_PERL_MODULE}.unit.so \\
192	$nxt_objs $NXT_PERL_LDOPTS $NXT_LD_OPT
193
194
195install: ${NXT_PERL_MODULE}-install
196
197${NXT_PERL_MODULE}-install: ${NXT_PERL_MODULE} install-check
198	install -d \$(DESTDIR)$NXT_MODULES
199	install -p $NXT_BUILD_DIR/${NXT_PERL_MODULE}.unit.so \\
200		\$(DESTDIR)$NXT_MODULES/
201
202
203uninstall: ${NXT_PERL_MODULE}-uninstall
204
205${NXT_PERL_MODULE}-uninstall:
206	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_PERL_MODULE}.unit.so
207	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
208
209END
210