xref: /unit/auto/modules/perl (revision 1217:ed8c4e263152)
1510Salexander.borisov@nginx.com
2510Salexander.borisov@nginx.com# Copyright (C) Alexander Borisov
3510Salexander.borisov@nginx.com# Copyright (C) NGINX, Inc.
4510Salexander.borisov@nginx.com
5510Salexander.borisov@nginx.com
6510Salexander.borisov@nginx.comshift
7510Salexander.borisov@nginx.com
8510Salexander.borisov@nginx.comfor nxt_option; do
9510Salexander.borisov@nginx.com
10510Salexander.borisov@nginx.com    case "$nxt_option" in
11510Salexander.borisov@nginx.com        -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
12510Salexander.borisov@nginx.com           *) value="" ;;
13510Salexander.borisov@nginx.com    esac
14510Salexander.borisov@nginx.com
15510Salexander.borisov@nginx.com    case "$nxt_option" in
16510Salexander.borisov@nginx.com        --perl=*)      NXT_PERL="$value"                                ;;
17510Salexander.borisov@nginx.com        --module=*)    NXT_PERL_MODULE="$value"                         ;;
18510Salexander.borisov@nginx.com
19510Salexander.borisov@nginx.com        --help)
20510Salexander.borisov@nginx.com            cat << END
21510Salexander.borisov@nginx.com
22510Salexander.borisov@nginx.com    --perl=FILE           set perl executable, default: perl
23510Salexander.borisov@nginx.com    --module=NAME         set unit perl module name
24510Salexander.borisov@nginx.com
25510Salexander.borisov@nginx.comEND
26510Salexander.borisov@nginx.com            exit 0
27510Salexander.borisov@nginx.com        ;;
28510Salexander.borisov@nginx.com
29510Salexander.borisov@nginx.com        *)
30510Salexander.borisov@nginx.com            echo
31510Salexander.borisov@nginx.com            echo $0: error: invalid Perl option \"$nxt_option\"
32510Salexander.borisov@nginx.com            echo
33510Salexander.borisov@nginx.com            exit 1
34510Salexander.borisov@nginx.com        ;;
35510Salexander.borisov@nginx.com    esac
36510Salexander.borisov@nginx.com
37510Salexander.borisov@nginx.comdone
38510Salexander.borisov@nginx.com
39510Salexander.borisov@nginx.com
40510Salexander.borisov@nginx.comif [ ! -f $NXT_AUTOCONF_DATA ]; then
41510Salexander.borisov@nginx.com   echo
42510Salexander.borisov@nginx.com   echo Please run common $0 before configuring module \"$nxt_module\".
43510Salexander.borisov@nginx.com   echo
44510Salexander.borisov@nginx.com   exit 1
45510Salexander.borisov@nginx.comfi
46510Salexander.borisov@nginx.com
47510Salexander.borisov@nginx.com. $NXT_AUTOCONF_DATA
48510Salexander.borisov@nginx.com
49510Salexander.borisov@nginx.com$echo "configuring Perl module"
50510Salexander.borisov@nginx.com$echo "configuring Perl module ..." >> $NXT_AUTOCONF_ERR
51510Salexander.borisov@nginx.com
52510Salexander.borisov@nginx.comNXT_PERL=${NXT_PERL=perl}
53510Salexander.borisov@nginx.comNXT_PERL_MODULE=${NXT_PERL_MODULE=${NXT_PERL##*/}}
54510Salexander.borisov@nginx.com
55510Salexander.borisov@nginx.comnxt_found=no
56510Salexander.borisov@nginx.com
57510Salexander.borisov@nginx.comif /bin/sh -c "$NXT_PERL -MConfig -e 'print \"Perl version: \",
58510Salexander.borisov@nginx.com    \$Config{version}, \"\\n\"'" >> $NXT_AUTOCONF_ERR 2>&1; then
59510Salexander.borisov@nginx.com
601108Svbart@nginx.com    NXT_PERL_CFLAGS=`$NXT_PERL -MExtUtils::Embed -e ccflags | sed -e 's/^ //;s/ $//'`
611107Svbart@nginx.com    NXT_PERL_INCLUDE=`$NXT_PERL -MExtUtils::Embed -e perl_inc | sed -e 's/^ //;s/ $//'`
621107Svbart@nginx.com    NXT_PERL_LDOPTS=`$NXT_PERL -MExtUtils::Embed -e ldopts | sed -e 's/^ //;s/ $//'`
63510Salexander.borisov@nginx.com
64523Sdefan@nginx.com    if [ "$NXT_SYSTEM" = "Darwin" ]; then
65523Sdefan@nginx.com        # OS X system perl wants to link universal binaries
66523Sdefan@nginx.com        NXT_PERL_LDOPTS=`echo $NXT_PERL_LDOPTS \
67523Sdefan@nginx.com                         | sed -e 's/-arch i386//' -e 's/-arch x86_64//'`
68523Sdefan@nginx.com    fi
69523Sdefan@nginx.com
70510Salexander.borisov@nginx.com    nxt_feature="Perl"
71510Salexander.borisov@nginx.com    nxt_feature_name=""
72510Salexander.borisov@nginx.com    nxt_feature_run=no
73510Salexander.borisov@nginx.com    nxt_feature_incs="${NXT_PERL_INCLUDE}"
741107Svbart@nginx.com    nxt_feature_libs="${NXT_PERL_LDOPTS}"
75510Salexander.borisov@nginx.com    nxt_feature_test="
76780Spluknet@nginx.com        #define _GNU_SOURCE
77510Salexander.borisov@nginx.com        #include <EXTERN.h>
78510Salexander.borisov@nginx.com        #include <perl.h>
79510Salexander.borisov@nginx.com
80510Salexander.borisov@nginx.com        static PerlInterpreter *my_perl;
81510Salexander.borisov@nginx.com
82510Salexander.borisov@nginx.com        int main() {
83510Salexander.borisov@nginx.com            char argv[] = \"\\0-e\\00\";
84510Salexander.borisov@nginx.com            char *embedding[] = { &argv[0], &argv[1], &argv[4] };
85510Salexander.borisov@nginx.com
86510Salexander.borisov@nginx.com            int pargc = 0;
87510Salexander.borisov@nginx.com            char **pargv = NULL, **penv = NULL;
88510Salexander.borisov@nginx.com            PERL_SYS_INIT3(&pargc, &pargv, &penv);
89510Salexander.borisov@nginx.com
90510Salexander.borisov@nginx.com            my_perl = perl_alloc();
91510Salexander.borisov@nginx.com            perl_construct(my_perl);
92510Salexander.borisov@nginx.com            perl_parse(my_perl, NULL, 3, embedding, NULL);
93510Salexander.borisov@nginx.com            PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
94510Salexander.borisov@nginx.com            perl_run(my_perl);
95510Salexander.borisov@nginx.com
96510Salexander.borisov@nginx.com            perl_destruct(my_perl);
97510Salexander.borisov@nginx.com            perl_free(my_perl);
98510Salexander.borisov@nginx.com            PERL_SYS_TERM();
99510Salexander.borisov@nginx.com
100510Salexander.borisov@nginx.com            return 0;
101510Salexander.borisov@nginx.com        }"
102510Salexander.borisov@nginx.com
103510Salexander.borisov@nginx.com    . auto/feature
104510Salexander.borisov@nginx.com
105510Salexander.borisov@nginx.comelse
106510Salexander.borisov@nginx.com    $echo "checking for Perl ... not found"
107510Salexander.borisov@nginx.comfi
108510Salexander.borisov@nginx.com
109510Salexander.borisov@nginx.comif [ $nxt_found = no ]; then
110510Salexander.borisov@nginx.com    $echo
111510Salexander.borisov@nginx.com    $echo $0: error: no Perl found.
112510Salexander.borisov@nginx.com    $echo
113510Salexander.borisov@nginx.com    exit 1;
114510Salexander.borisov@nginx.comfi
115510Salexander.borisov@nginx.com
116612Salexander.borisov@nginx.com
117612Salexander.borisov@nginx.comnxt_feature="Perl version"
118612Salexander.borisov@nginx.comnxt_feature_name=""
119612Salexander.borisov@nginx.comnxt_feature_run=value
120612Salexander.borisov@nginx.comnxt_feature_incs="${NXT_PERL_INCLUDE}"
1211107Svbart@nginx.comnxt_feature_libs="${NXT_PERL_LDOPTS}"
122612Salexander.borisov@nginx.comnxt_feature_test="
123780Spluknet@nginx.com    #define _GNU_SOURCE
124612Salexander.borisov@nginx.com    #include <EXTERN.h>
125612Salexander.borisov@nginx.com    #include <perl.h>
126612Salexander.borisov@nginx.com
127612Salexander.borisov@nginx.com    int main() {
128612Salexander.borisov@nginx.com        printf(\"%s\", PERL_VERSION_STRING);
129612Salexander.borisov@nginx.com        return 0;
130612Salexander.borisov@nginx.com    }"
131612Salexander.borisov@nginx.com
132612Salexander.borisov@nginx.com. auto/feature
133612Salexander.borisov@nginx.com
134510Salexander.borisov@nginx.com
135510Salexander.borisov@nginx.comif grep ^$NXT_PERL_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
136510Salexander.borisov@nginx.com    $echo
137510Salexander.borisov@nginx.com    $echo $0: error: duplicate \"$NXT_PERL_MODULE\" module configured.
138510Salexander.borisov@nginx.com    $echo
139510Salexander.borisov@nginx.com    exit 1;
140510Salexander.borisov@nginx.comfi
141510Salexander.borisov@nginx.com
142510Salexander.borisov@nginx.com$echo " + Perl module: ${NXT_PERL_MODULE}.unit.so"
143510Salexander.borisov@nginx.com
144510Salexander.borisov@nginx.com. auto/cc/deps
145510Salexander.borisov@nginx.com
146510Salexander.borisov@nginx.com$echo >> $NXT_MAKEFILE
147510Salexander.borisov@nginx.com
148510Salexander.borisov@nginx.comNXT_PERL_MODULE_SRCS=" \
149510Salexander.borisov@nginx.com    src/perl/nxt_perl_psgi.c \
150510Salexander.borisov@nginx.com    src/perl/nxt_perl_psgi_layer.c
151510Salexander.borisov@nginx.com"
152510Salexander.borisov@nginx.com
153510Salexander.borisov@nginx.com# The Perl module object files.
154510Salexander.borisov@nginx.com
155743Smax.romanov@nginx.comnxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
156510Salexander.borisov@nginx.com
157510Salexander.borisov@nginx.comfor nxt_src in $NXT_PERL_MODULE_SRCS; do
158510Salexander.borisov@nginx.com
159510Salexander.borisov@nginx.com    nxt_obj=${nxt_src%.c}-$NXT_PERL_MODULE.o
160510Salexander.borisov@nginx.com    nxt_dep=${nxt_src%.c}-$NXT_PERL_MODULE.dep
161510Salexander.borisov@nginx.com    nxt_dep_flags=`nxt_gen_dep_flags`
162510Salexander.borisov@nginx.com    nxt_dep_post=`nxt_gen_dep_post`
163510Salexander.borisov@nginx.com    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
164510Salexander.borisov@nginx.com
165510Salexander.borisov@nginx.com    cat << END >> $NXT_MAKEFILE
166510Salexander.borisov@nginx.com
167*1217Smax.romanov@nginx.com$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
168510Salexander.borisov@nginx.com	mkdir -p $NXT_BUILD_DIR/src/perl
1691108Svbart@nginx.com	\$(CC) -c \$(CFLAGS) $NXT_PERL_CFLAGS \$(NXT_INCS) $NXT_PERL_INCLUDE \\
170510Salexander.borisov@nginx.com	$nxt_dep_flags \\
171510Salexander.borisov@nginx.com	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
172510Salexander.borisov@nginx.com	$nxt_dep_post
173510Salexander.borisov@nginx.com
174510Salexander.borisov@nginx.com-include $NXT_BUILD_DIR/$nxt_dep
175510Salexander.borisov@nginx.com
176510Salexander.borisov@nginx.comEND
177510Salexander.borisov@nginx.com
178510Salexander.borisov@nginx.comdone
179510Salexander.borisov@nginx.com
180510Salexander.borisov@nginx.comcat << END >> $NXT_MAKEFILE
181510Salexander.borisov@nginx.com
182510Salexander.borisov@nginx.com.PHONY: ${NXT_PERL_MODULE}
183510Salexander.borisov@nginx.com.PHONY: ${NXT_PERL_MODULE}-install
184510Salexander.borisov@nginx.com.PHONY: ${NXT_PERL_MODULE}-uninstall
185510Salexander.borisov@nginx.com
186510Salexander.borisov@nginx.comall: ${NXT_PERL_MODULE}
187510Salexander.borisov@nginx.com
188510Salexander.borisov@nginx.com${NXT_PERL_MODULE}:	$NXT_BUILD_DIR/${NXT_PERL_MODULE}.unit.so
189510Salexander.borisov@nginx.com
190510Salexander.borisov@nginx.com$NXT_BUILD_DIR/${NXT_PERL_MODULE}.unit.so:	$nxt_objs
191510Salexander.borisov@nginx.com	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_PERL_MODULE}.unit.so \\
1921107Svbart@nginx.com	$nxt_objs $NXT_PERL_LDOPTS $NXT_LD_OPT
193510Salexander.borisov@nginx.com
194510Salexander.borisov@nginx.com
195510Salexander.borisov@nginx.cominstall: ${NXT_PERL_MODULE}-install
196510Salexander.borisov@nginx.com
197706Sigor@sysoev.ru${NXT_PERL_MODULE}-install: ${NXT_PERL_MODULE} install-check
198510Salexander.borisov@nginx.com	install -d \$(DESTDIR)$NXT_MODULES
199510Salexander.borisov@nginx.com	install -p $NXT_BUILD_DIR/${NXT_PERL_MODULE}.unit.so \\
200510Salexander.borisov@nginx.com		\$(DESTDIR)$NXT_MODULES/
201510Salexander.borisov@nginx.com
202510Salexander.borisov@nginx.com
203510Salexander.borisov@nginx.comuninstall: ${NXT_PERL_MODULE}-uninstall
204510Salexander.borisov@nginx.com
205510Salexander.borisov@nginx.com${NXT_PERL_MODULE}-uninstall:
206510Salexander.borisov@nginx.com	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_PERL_MODULE}.unit.so
207510Salexander.borisov@nginx.com	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
208510Salexander.borisov@nginx.com
209510Salexander.borisov@nginx.comEND
210