xref: /unit/auto/modules/ruby (revision 1217)
1584Salexander.borisov@nginx.com
2584Salexander.borisov@nginx.com# Copyright (C) Alexander Borisov
3584Salexander.borisov@nginx.com# Copyright (C) NGINX, Inc.
4584Salexander.borisov@nginx.com
5584Salexander.borisov@nginx.com
6584Salexander.borisov@nginx.comshift
7584Salexander.borisov@nginx.com
8584Salexander.borisov@nginx.comfor nxt_option; do
9584Salexander.borisov@nginx.com
10584Salexander.borisov@nginx.com    case "$nxt_option" in
11584Salexander.borisov@nginx.com        -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
12584Salexander.borisov@nginx.com           *) value="" ;;
13584Salexander.borisov@nginx.com    esac
14584Salexander.borisov@nginx.com
15584Salexander.borisov@nginx.com    case "$nxt_option" in
16584Salexander.borisov@nginx.com        --ruby=*)    NXT_RUBY="$value"                                    ;;
17584Salexander.borisov@nginx.com        --module=*)  NXT_RUBY_MODULE="$value"                             ;;
18584Salexander.borisov@nginx.com
19584Salexander.borisov@nginx.com        --help)
20584Salexander.borisov@nginx.com            cat << END
21584Salexander.borisov@nginx.com
22584Salexander.borisov@nginx.com    --ruby=FILE    set ruby executable, default: ruby
23584Salexander.borisov@nginx.com    --module=NAME  set unit ruby module name
24584Salexander.borisov@nginx.com
25584Salexander.borisov@nginx.comEND
26584Salexander.borisov@nginx.com            exit 0
27584Salexander.borisov@nginx.com        ;;
28584Salexander.borisov@nginx.com
29584Salexander.borisov@nginx.com        *)
30584Salexander.borisov@nginx.com            echo
31584Salexander.borisov@nginx.com            echo $0: error: invalid Ruby option \"$nxt_option\"
32584Salexander.borisov@nginx.com            echo
33584Salexander.borisov@nginx.com            exit 1
34584Salexander.borisov@nginx.com        ;;
35584Salexander.borisov@nginx.com    esac
36584Salexander.borisov@nginx.com
37584Salexander.borisov@nginx.comdone
38584Salexander.borisov@nginx.com
39584Salexander.borisov@nginx.com
40584Salexander.borisov@nginx.comif [ ! -f $NXT_AUTOCONF_DATA ]; then
41584Salexander.borisov@nginx.com   echo
42584Salexander.borisov@nginx.com   echo Please run common $0 before configuring module \"$nxt_module\".
43584Salexander.borisov@nginx.com   echo
44584Salexander.borisov@nginx.com   exit 1
45584Salexander.borisov@nginx.comfi
46584Salexander.borisov@nginx.com
47584Salexander.borisov@nginx.com. $NXT_AUTOCONF_DATA
48584Salexander.borisov@nginx.com
49584Salexander.borisov@nginx.com$echo "configuring Ruby module"
50584Salexander.borisov@nginx.com$echo "configuring Ruby module ..." >> $NXT_AUTOCONF_ERR
51584Salexander.borisov@nginx.com
52584Salexander.borisov@nginx.comNXT_RUBY=${NXT_RUBY=ruby}
53584Salexander.borisov@nginx.comNXT_RUBY_MODULE=${NXT_RUBY_MODULE=${NXT_RUBY}}
54584Salexander.borisov@nginx.com
55584Salexander.borisov@nginx.comnxt_found=no
56584Salexander.borisov@nginx.com
57584Salexander.borisov@nginx.comif /bin/sh -c "$NXT_RUBY -v" >> $NXT_AUTOCONF_ERR 2>&1; then
58584Salexander.borisov@nginx.com
59584Salexander.borisov@nginx.com    NXT_RUBY_RUBYHDRDIR=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["rubyhdrdir"])'`
60584Salexander.borisov@nginx.com    NXT_RUBY_ARCHHDRDIR=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["rubyarchhdrdir"])'`
61584Salexander.borisov@nginx.com    NXT_RUBY_INCPATH="-I$NXT_RUBY_ARCHHDRDIR -I$NXT_RUBY_RUBYHDRDIR"
62584Salexander.borisov@nginx.com
63584Salexander.borisov@nginx.com    NXT_RUBY_LIBNAME=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["RUBY_SO_NAME"])'`
64584Salexander.borisov@nginx.com    NXT_RUBY_LIBSCONF=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["LIBS"])'`
65863Svbart@nginx.com    NXT_RUBY_LIBS="-l$NXT_RUBY_LIBNAME $NXT_RUBY_LIBSCONF"
66584Salexander.borisov@nginx.com
67863Svbart@nginx.com    nxt_feature="Ruby library"
68584Salexander.borisov@nginx.com    nxt_feature_name=""
69584Salexander.borisov@nginx.com    nxt_feature_run=no
70584Salexander.borisov@nginx.com    nxt_feature_incs="${NXT_RUBY_INCPATH}"
71584Salexander.borisov@nginx.com    nxt_feature_libs="${NXT_RUBY_LIBS}"
72584Salexander.borisov@nginx.com    nxt_feature_test="
73584Salexander.borisov@nginx.com        #include <ruby.h>
74584Salexander.borisov@nginx.com
75584Salexander.borisov@nginx.com        int main() {
76584Salexander.borisov@nginx.com            ruby_init();
77584Salexander.borisov@nginx.com            return ruby_cleanup(0);
78584Salexander.borisov@nginx.com        }"
79584Salexander.borisov@nginx.com
80584Salexander.borisov@nginx.com    . auto/feature
81584Salexander.borisov@nginx.com
82863Svbart@nginx.com    if [ $nxt_found = no ]; then
83863Svbart@nginx.com        NXT_RUBY_LIBPATH=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["libdir"])'`
84863Svbart@nginx.com        NXT_RUBY_LIBS="-L$NXT_RUBY_LIBPATH -Wl,-rpath,${NXT_RUBY_LIBPATH} $NXT_RUBY_LIBS"
85863Svbart@nginx.com
86863Svbart@nginx.com        nxt_feature="Ruby library in $NXT_RUBY_LIBPATH"
87863Svbart@nginx.com        nxt_feature_name=""
88863Svbart@nginx.com        nxt_feature_run=no
89863Svbart@nginx.com        nxt_feature_incs="${NXT_RUBY_INCPATH}"
90863Svbart@nginx.com        nxt_feature_libs="${NXT_RUBY_LIBS}"
91863Svbart@nginx.com        nxt_feature_test="
92863Svbart@nginx.com            #include <ruby.h>
93863Svbart@nginx.com
94863Svbart@nginx.com            int main() {
95863Svbart@nginx.com                ruby_init();
96863Svbart@nginx.com                return ruby_cleanup(0);
97863Svbart@nginx.com            }"
98863Svbart@nginx.com
99863Svbart@nginx.com        . auto/feature
100863Svbart@nginx.com    fi
101863Svbart@nginx.com
102584Salexander.borisov@nginx.comelse
103584Salexander.borisov@nginx.com    $echo "checking for Ruby ... not found"
104584Salexander.borisov@nginx.comfi
105584Salexander.borisov@nginx.com
106584Salexander.borisov@nginx.comif [ $nxt_found = no ]; then
107584Salexander.borisov@nginx.com    $echo
108584Salexander.borisov@nginx.com    $echo $0: error: no Ruby found.
109584Salexander.borisov@nginx.com    $echo
110584Salexander.borisov@nginx.com    exit 1;
111584Salexander.borisov@nginx.comfi
112584Salexander.borisov@nginx.com
113612Salexander.borisov@nginx.com
114612Salexander.borisov@nginx.comnxt_feature="Ruby version"
115612Salexander.borisov@nginx.comnxt_feature_name=""
116612Salexander.borisov@nginx.comnxt_feature_run=value
117612Salexander.borisov@nginx.comnxt_feature_incs="${NXT_RUBY_INCPATH}"
118612Salexander.borisov@nginx.comnxt_feature_libs="${NXT_RUBY_LIBS}"
119612Salexander.borisov@nginx.comnxt_feature_test="
120612Salexander.borisov@nginx.com    #include <ruby.h>
121612Salexander.borisov@nginx.com    #include <ruby/version.h>
122612Salexander.borisov@nginx.com
123612Salexander.borisov@nginx.com    int main() {
124612Salexander.borisov@nginx.com        printf(\"%s\", ruby_version);
125612Salexander.borisov@nginx.com        return 0;
126612Salexander.borisov@nginx.com    }"
127612Salexander.borisov@nginx.com
128612Salexander.borisov@nginx.com. auto/feature
129612Salexander.borisov@nginx.com
130584Salexander.borisov@nginx.com
131584Salexander.borisov@nginx.comif grep ^$NXT_RUBY_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
132584Salexander.borisov@nginx.com    $echo
133584Salexander.borisov@nginx.com    $echo $0: error: duplicate \"$NXT_RUBY_MODULE\" module configured.
134584Salexander.borisov@nginx.com    $echo
135584Salexander.borisov@nginx.com    exit 1;
136584Salexander.borisov@nginx.comfi
137584Salexander.borisov@nginx.com
138584Salexander.borisov@nginx.com$echo " + Ruby module: ${NXT_RUBY_MODULE}.unit.so"
139584Salexander.borisov@nginx.com
140584Salexander.borisov@nginx.com. auto/cc/deps
141584Salexander.borisov@nginx.com
142584Salexander.borisov@nginx.com$echo >> $NXT_MAKEFILE
143584Salexander.borisov@nginx.com
144584Salexander.borisov@nginx.comNXT_RUBY_MODULE_SRCS=" \
145584Salexander.borisov@nginx.com    src/ruby/nxt_ruby.c \
146584Salexander.borisov@nginx.com    src/ruby/nxt_ruby_stream_io.c
147584Salexander.borisov@nginx.com"
148584Salexander.borisov@nginx.com
149584Salexander.borisov@nginx.com# The Ruby module object files.
150584Salexander.borisov@nginx.com
151743Smax.romanov@nginx.comnxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
152584Salexander.borisov@nginx.com
153584Salexander.borisov@nginx.comfor nxt_src in $NXT_RUBY_MODULE_SRCS; do
154584Salexander.borisov@nginx.com
155584Salexander.borisov@nginx.com    nxt_obj=${nxt_src%.c}-$NXT_RUBY_MODULE.o
156584Salexander.borisov@nginx.com    nxt_dep=${nxt_src%.c}-$NXT_RUBY_MODULE.dep
157584Salexander.borisov@nginx.com    nxt_dep_flags=`nxt_gen_dep_flags`
158584Salexander.borisov@nginx.com    nxt_dep_post=`nxt_gen_dep_post`
159584Salexander.borisov@nginx.com    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
160584Salexander.borisov@nginx.com
161584Salexander.borisov@nginx.com    cat << END >> $NXT_MAKEFILE
162584Salexander.borisov@nginx.com
163*1217Smax.romanov@nginx.com$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
164584Salexander.borisov@nginx.com	mkdir -p $NXT_BUILD_DIR/src/ruby
165584Salexander.borisov@nginx.com	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_RUBY_INCPATH \\
166584Salexander.borisov@nginx.com	$nxt_dep_flags \\
167584Salexander.borisov@nginx.com	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
168584Salexander.borisov@nginx.com	$nxt_dep_post
169584Salexander.borisov@nginx.com
170584Salexander.borisov@nginx.com-include $NXT_BUILD_DIR/$nxt_dep
171584Salexander.borisov@nginx.com
172584Salexander.borisov@nginx.comEND
173584Salexander.borisov@nginx.com
174584Salexander.borisov@nginx.comdone
175584Salexander.borisov@nginx.com
176584Salexander.borisov@nginx.comcat << END >> $NXT_MAKEFILE
177584Salexander.borisov@nginx.com
178584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE}
179584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE}-install
180584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE}-uninstall
181584Salexander.borisov@nginx.com
182584Salexander.borisov@nginx.comall: ${NXT_RUBY_MODULE}
183584Salexander.borisov@nginx.com
184584Salexander.borisov@nginx.com${NXT_RUBY_MODULE}:	$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so
185584Salexander.borisov@nginx.com
186584Salexander.borisov@nginx.com$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so:	$nxt_objs
187584Salexander.borisov@nginx.com	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
188584Salexander.borisov@nginx.com	$nxt_objs $NXT_RUBY_LIBS $NXT_LD_OPT
189584Salexander.borisov@nginx.com
190584Salexander.borisov@nginx.com
191584Salexander.borisov@nginx.cominstall: ${NXT_RUBY_MODULE}-install
192584Salexander.borisov@nginx.com
193706Sigor@sysoev.ru${NXT_RUBY_MODULE}-install: ${NXT_RUBY_MODULE} install-check
194584Salexander.borisov@nginx.com	install -d \$(DESTDIR)$NXT_MODULES
195584Salexander.borisov@nginx.com	install -p $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
196584Salexander.borisov@nginx.com		\$(DESTDIR)$NXT_MODULES/
197584Salexander.borisov@nginx.com
198584Salexander.borisov@nginx.com
199584Salexander.borisov@nginx.comuninstall: ${NXT_RUBY_MODULE}-uninstall
200584Salexander.borisov@nginx.com
201584Salexander.borisov@nginx.com${NXT_RUBY_MODULE}-uninstall:
202584Salexander.borisov@nginx.com	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_RUBY_MODULE}.unit.so
203584Salexander.borisov@nginx.com	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
204584Salexander.borisov@nginx.com
205584Salexander.borisov@nginx.comEND
206