xref: /unit/auto/modules/ruby (revision 605:ab74cec14032)
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        --ruby=*)    NXT_RUBY="$value"                                    ;;
17        --module=*)  NXT_RUBY_MODULE="$value"                             ;;
18
19        --help)
20            cat << END
21
22    --ruby=FILE    set ruby executable, default: ruby
23    --module=NAME  set unit ruby module name
24
25END
26            exit 0
27        ;;
28
29        *)
30            echo
31            echo $0: error: invalid Ruby 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 Ruby module"
50$echo "configuring Ruby module ..." >> $NXT_AUTOCONF_ERR
51
52NXT_RUBY=${NXT_RUBY=ruby}
53NXT_RUBY_MODULE=${NXT_RUBY_MODULE=${NXT_RUBY}}
54
55nxt_found=no
56
57if /bin/sh -c "$NXT_RUBY -v" >> $NXT_AUTOCONF_ERR 2>&1; then
58
59    NXT_RUBY_RUBYHDRDIR=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["rubyhdrdir"])'`
60    NXT_RUBY_ARCHHDRDIR=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["rubyarchhdrdir"])'`
61    NXT_RUBY_INCPATH="-I$NXT_RUBY_ARCHHDRDIR -I$NXT_RUBY_RUBYHDRDIR"
62
63    NXT_RUBY_LIBNAME=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["RUBY_SO_NAME"])'`
64    NXT_RUBY_LIBSCONF=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["LIBS"])'`
65    NXT_RUBY_LIBPATH=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["libdir"])'`
66    NXT_RUBY_LIBS="-L$NXT_RUBY_LIBPATH -Wl,-rpath,${NXT_RUBY_LIBPATH} -l$NXT_RUBY_LIBNAME $NXT_RUBY_LIBSCONF"
67
68    nxt_feature="Ruby"
69    nxt_feature_name=""
70    nxt_feature_run=no
71    nxt_feature_incs="${NXT_RUBY_INCPATH}"
72    nxt_feature_libs="${NXT_RUBY_LIBS}"
73    nxt_feature_test="
74        #include <ruby.h>
75
76        int main() {
77            ruby_init();
78            return ruby_cleanup(0);
79        }"
80
81    . auto/feature
82
83else
84    $echo "checking for Ruby ... not found"
85fi
86
87if [ $nxt_found = no ]; then
88    $echo
89    $echo $0: error: no Ruby found.
90    $echo
91    exit 1;
92fi
93
94NXT_RUBY_VERSION=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["RUBY_PROGRAM_VERSION"])'`
95$echo " + Ruby version: ${NXT_RUBY_VERSION}"
96
97if grep ^$NXT_RUBY_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
98    $echo
99    $echo $0: error: duplicate \"$NXT_RUBY_MODULE\" module configured.
100    $echo
101    exit 1;
102fi
103
104$echo " + Ruby module: ${NXT_RUBY_MODULE}.unit.so"
105
106. auto/cc/deps
107
108$echo >> $NXT_MAKEFILE
109
110NXT_RUBY_MODULE_SRCS=" \
111    src/ruby/nxt_ruby.c \
112    src/ruby/nxt_ruby_stream_io.c
113"
114
115# The Ruby module object files.
116
117nxt_objs=
118
119for nxt_src in $NXT_RUBY_MODULE_SRCS; do
120
121    nxt_obj=${nxt_src%.c}-$NXT_RUBY_MODULE.o
122    nxt_dep=${nxt_src%.c}-$NXT_RUBY_MODULE.dep
123    nxt_dep_flags=`nxt_gen_dep_flags`
124    nxt_dep_post=`nxt_gen_dep_post`
125    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
126
127    cat << END >> $NXT_MAKEFILE
128
129$NXT_BUILD_DIR/$nxt_obj:	$nxt_src
130	mkdir -p $NXT_BUILD_DIR/src/ruby
131	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_RUBY_INCPATH \\
132	$nxt_dep_flags \\
133	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
134	$nxt_dep_post
135
136-include $NXT_BUILD_DIR/$nxt_dep
137
138END
139
140done
141
142cat << END >> $NXT_MAKEFILE
143
144.PHONY: ${NXT_RUBY_MODULE}
145.PHONY: ${NXT_RUBY_MODULE}-install
146.PHONY: ${NXT_RUBY_MODULE}-uninstall
147
148all: ${NXT_RUBY_MODULE}
149
150${NXT_RUBY_MODULE}:	$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so
151
152$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so:	$nxt_objs
153	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
154	$nxt_objs $NXT_RUBY_LIBS $NXT_LD_OPT
155
156
157install: ${NXT_RUBY_MODULE}-install
158
159${NXT_RUBY_MODULE}-install: ${NXT_RUBY_MODULE}
160	install -d \$(DESTDIR)$NXT_MODULES
161	install -p $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
162		\$(DESTDIR)$NXT_MODULES/
163
164
165uninstall: ${NXT_RUBY_MODULE}-uninstall
166
167${NXT_RUBY_MODULE}-uninstall:
168	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_RUBY_MODULE}.unit.so
169	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
170
171END
172