xref: /unit/auto/modules/ruby (revision 584)
1*584Salexander.borisov@nginx.com
2*584Salexander.borisov@nginx.com# Copyright (C) Alexander Borisov
3*584Salexander.borisov@nginx.com# Copyright (C) NGINX, Inc.
4*584Salexander.borisov@nginx.com
5*584Salexander.borisov@nginx.com
6*584Salexander.borisov@nginx.comshift
7*584Salexander.borisov@nginx.com
8*584Salexander.borisov@nginx.comfor nxt_option; do
9*584Salexander.borisov@nginx.com
10*584Salexander.borisov@nginx.com    case "$nxt_option" in
11*584Salexander.borisov@nginx.com        -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
12*584Salexander.borisov@nginx.com           *) value="" ;;
13*584Salexander.borisov@nginx.com    esac
14*584Salexander.borisov@nginx.com
15*584Salexander.borisov@nginx.com    case "$nxt_option" in
16*584Salexander.borisov@nginx.com        --ruby=*)    NXT_RUBY="$value"                                    ;;
17*584Salexander.borisov@nginx.com        --module=*)  NXT_RUBY_MODULE="$value"                             ;;
18*584Salexander.borisov@nginx.com
19*584Salexander.borisov@nginx.com        --help)
20*584Salexander.borisov@nginx.com            cat << END
21*584Salexander.borisov@nginx.com
22*584Salexander.borisov@nginx.com    --ruby=FILE    set ruby executable, default: ruby
23*584Salexander.borisov@nginx.com    --module=NAME  set unit ruby module name
24*584Salexander.borisov@nginx.com
25*584Salexander.borisov@nginx.comEND
26*584Salexander.borisov@nginx.com            exit 0
27*584Salexander.borisov@nginx.com        ;;
28*584Salexander.borisov@nginx.com
29*584Salexander.borisov@nginx.com        *)
30*584Salexander.borisov@nginx.com            echo
31*584Salexander.borisov@nginx.com            echo $0: error: invalid Ruby option \"$nxt_option\"
32*584Salexander.borisov@nginx.com            echo
33*584Salexander.borisov@nginx.com            exit 1
34*584Salexander.borisov@nginx.com        ;;
35*584Salexander.borisov@nginx.com    esac
36*584Salexander.borisov@nginx.com
37*584Salexander.borisov@nginx.comdone
38*584Salexander.borisov@nginx.com
39*584Salexander.borisov@nginx.com
40*584Salexander.borisov@nginx.comif [ ! -f $NXT_AUTOCONF_DATA ]; then
41*584Salexander.borisov@nginx.com   echo
42*584Salexander.borisov@nginx.com   echo Please run common $0 before configuring module \"$nxt_module\".
43*584Salexander.borisov@nginx.com   echo
44*584Salexander.borisov@nginx.com   exit 1
45*584Salexander.borisov@nginx.comfi
46*584Salexander.borisov@nginx.com
47*584Salexander.borisov@nginx.com. $NXT_AUTOCONF_DATA
48*584Salexander.borisov@nginx.com
49*584Salexander.borisov@nginx.com$echo "configuring Ruby module"
50*584Salexander.borisov@nginx.com$echo "configuring Ruby module ..." >> $NXT_AUTOCONF_ERR
51*584Salexander.borisov@nginx.com
52*584Salexander.borisov@nginx.comNXT_RUBY=${NXT_RUBY=ruby}
53*584Salexander.borisov@nginx.comNXT_RUBY_MODULE=${NXT_RUBY_MODULE=${NXT_RUBY}}
54*584Salexander.borisov@nginx.com
55*584Salexander.borisov@nginx.comnxt_found=no
56*584Salexander.borisov@nginx.com
57*584Salexander.borisov@nginx.comif /bin/sh -c "$NXT_RUBY -v" >> $NXT_AUTOCONF_ERR 2>&1; then
58*584Salexander.borisov@nginx.com
59*584Salexander.borisov@nginx.com    NXT_RUBY_RUBYHDRDIR=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["rubyhdrdir"])'`
60*584Salexander.borisov@nginx.com    NXT_RUBY_ARCHHDRDIR=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["rubyarchhdrdir"])'`
61*584Salexander.borisov@nginx.com    NXT_RUBY_INCPATH="-I$NXT_RUBY_ARCHHDRDIR -I$NXT_RUBY_RUBYHDRDIR"
62*584Salexander.borisov@nginx.com
63*584Salexander.borisov@nginx.com    NXT_RUBY_LIBNAME=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["RUBY_SO_NAME"])'`
64*584Salexander.borisov@nginx.com    NXT_RUBY_LIBSCONF=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["LIBS"])'`
65*584Salexander.borisov@nginx.com    NXT_RUBY_LIBPATH=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["libdir"])'`
66*584Salexander.borisov@nginx.com    NXT_RUBY_LIBS="-L$NXT_RUBY_LIBPATH -Wl,-rpath,${NXT_RUBY_LIBPATH} -l$NXT_RUBY_LIBNAME $NXT_RUBY_LIBSCONF"
67*584Salexander.borisov@nginx.com
68*584Salexander.borisov@nginx.com    nxt_feature="Ruby"
69*584Salexander.borisov@nginx.com    nxt_feature_name=""
70*584Salexander.borisov@nginx.com    nxt_feature_run=no
71*584Salexander.borisov@nginx.com    nxt_feature_incs="${NXT_RUBY_INCPATH}"
72*584Salexander.borisov@nginx.com    nxt_feature_libs="${NXT_RUBY_LIBS}"
73*584Salexander.borisov@nginx.com    nxt_feature_test="
74*584Salexander.borisov@nginx.com        #include <ruby.h>
75*584Salexander.borisov@nginx.com
76*584Salexander.borisov@nginx.com        int main() {
77*584Salexander.borisov@nginx.com            ruby_init();
78*584Salexander.borisov@nginx.com            return ruby_cleanup(0);
79*584Salexander.borisov@nginx.com        }"
80*584Salexander.borisov@nginx.com
81*584Salexander.borisov@nginx.com    . auto/feature
82*584Salexander.borisov@nginx.com
83*584Salexander.borisov@nginx.comelse
84*584Salexander.borisov@nginx.com    $echo "checking for Ruby ... not found"
85*584Salexander.borisov@nginx.comfi
86*584Salexander.borisov@nginx.com
87*584Salexander.borisov@nginx.comif [ $nxt_found = no ]; then
88*584Salexander.borisov@nginx.com    $echo
89*584Salexander.borisov@nginx.com    $echo $0: error: no Ruby found.
90*584Salexander.borisov@nginx.com    $echo
91*584Salexander.borisov@nginx.com    exit 1;
92*584Salexander.borisov@nginx.comfi
93*584Salexander.borisov@nginx.com
94*584Salexander.borisov@nginx.comNXT_RUBY_VERSION=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["ruby_version"])'`
95*584Salexander.borisov@nginx.com$echo " + Ruby version: ${NXT_RUBY_VERSION}"
96*584Salexander.borisov@nginx.com
97*584Salexander.borisov@nginx.comif grep ^$NXT_RUBY_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
98*584Salexander.borisov@nginx.com    $echo
99*584Salexander.borisov@nginx.com    $echo $0: error: duplicate \"$NXT_RUBY_MODULE\" module configured.
100*584Salexander.borisov@nginx.com    $echo
101*584Salexander.borisov@nginx.com    exit 1;
102*584Salexander.borisov@nginx.comfi
103*584Salexander.borisov@nginx.com
104*584Salexander.borisov@nginx.com$echo " + Ruby module: ${NXT_RUBY_MODULE}.unit.so"
105*584Salexander.borisov@nginx.com
106*584Salexander.borisov@nginx.com. auto/cc/deps
107*584Salexander.borisov@nginx.com
108*584Salexander.borisov@nginx.com$echo >> $NXT_MAKEFILE
109*584Salexander.borisov@nginx.com
110*584Salexander.borisov@nginx.comNXT_RUBY_MODULE_SRCS=" \
111*584Salexander.borisov@nginx.com    src/ruby/nxt_ruby.c \
112*584Salexander.borisov@nginx.com    src/ruby/nxt_ruby_stream_io.c
113*584Salexander.borisov@nginx.com"
114*584Salexander.borisov@nginx.com
115*584Salexander.borisov@nginx.com# The Ruby module object files.
116*584Salexander.borisov@nginx.com
117*584Salexander.borisov@nginx.comnxt_objs=
118*584Salexander.borisov@nginx.com
119*584Salexander.borisov@nginx.comfor nxt_src in $NXT_RUBY_MODULE_SRCS; do
120*584Salexander.borisov@nginx.com
121*584Salexander.borisov@nginx.com    nxt_obj=${nxt_src%.c}-$NXT_RUBY_MODULE.o
122*584Salexander.borisov@nginx.com    nxt_dep=${nxt_src%.c}-$NXT_RUBY_MODULE.dep
123*584Salexander.borisov@nginx.com    nxt_dep_flags=`nxt_gen_dep_flags`
124*584Salexander.borisov@nginx.com    nxt_dep_post=`nxt_gen_dep_post`
125*584Salexander.borisov@nginx.com    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
126*584Salexander.borisov@nginx.com
127*584Salexander.borisov@nginx.com    cat << END >> $NXT_MAKEFILE
128*584Salexander.borisov@nginx.com
129*584Salexander.borisov@nginx.com$NXT_BUILD_DIR/$nxt_obj:	$nxt_src
130*584Salexander.borisov@nginx.com	mkdir -p $NXT_BUILD_DIR/src/ruby
131*584Salexander.borisov@nginx.com	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_RUBY_INCPATH \\
132*584Salexander.borisov@nginx.com	$nxt_dep_flags \\
133*584Salexander.borisov@nginx.com	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
134*584Salexander.borisov@nginx.com	$nxt_dep_post
135*584Salexander.borisov@nginx.com
136*584Salexander.borisov@nginx.com-include $NXT_BUILD_DIR/$nxt_dep
137*584Salexander.borisov@nginx.com
138*584Salexander.borisov@nginx.comEND
139*584Salexander.borisov@nginx.com
140*584Salexander.borisov@nginx.comdone
141*584Salexander.borisov@nginx.com
142*584Salexander.borisov@nginx.comcat << END >> $NXT_MAKEFILE
143*584Salexander.borisov@nginx.com
144*584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE}
145*584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE}-install
146*584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE}-uninstall
147*584Salexander.borisov@nginx.com
148*584Salexander.borisov@nginx.comall: ${NXT_RUBY_MODULE}
149*584Salexander.borisov@nginx.com
150*584Salexander.borisov@nginx.com${NXT_RUBY_MODULE}:	$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so
151*584Salexander.borisov@nginx.com
152*584Salexander.borisov@nginx.com$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so:	$nxt_objs
153*584Salexander.borisov@nginx.com	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
154*584Salexander.borisov@nginx.com	$nxt_objs $NXT_RUBY_LIBS $NXT_LD_OPT
155*584Salexander.borisov@nginx.com
156*584Salexander.borisov@nginx.com
157*584Salexander.borisov@nginx.cominstall: ${NXT_RUBY_MODULE}-install
158*584Salexander.borisov@nginx.com
159*584Salexander.borisov@nginx.com${NXT_RUBY_MODULE}-install: ${NXT_RUBY_MODULE}
160*584Salexander.borisov@nginx.com	install -d \$(DESTDIR)$NXT_MODULES
161*584Salexander.borisov@nginx.com	install -p $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
162*584Salexander.borisov@nginx.com		\$(DESTDIR)$NXT_MODULES/
163*584Salexander.borisov@nginx.com
164*584Salexander.borisov@nginx.com
165*584Salexander.borisov@nginx.comuninstall: ${NXT_RUBY_MODULE}-uninstall
166*584Salexander.borisov@nginx.com
167*584Salexander.borisov@nginx.com${NXT_RUBY_MODULE}-uninstall:
168*584Salexander.borisov@nginx.com	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_RUBY_MODULE}.unit.so
169*584Salexander.borisov@nginx.com	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
170*584Salexander.borisov@nginx.com
171*584Salexander.borisov@nginx.comEND
172