xref: /unit/auto/modules/ruby (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        --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_LIBS="-l$NXT_RUBY_LIBNAME $NXT_RUBY_LIBSCONF"
66
67    nxt_feature="Ruby library"
68    nxt_feature_name=""
69    nxt_feature_run=no
70    nxt_feature_incs="${NXT_RUBY_INCPATH}"
71    nxt_feature_libs="${NXT_RUBY_LIBS}"
72    nxt_feature_test="
73        #include <ruby.h>
74
75        int main() {
76            ruby_init();
77            return ruby_cleanup(0);
78        }"
79
80    . auto/feature
81
82    if [ $nxt_found = no ]; then
83        NXT_RUBY_LIBPATH=`$NXT_RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG["libdir"])'`
84        NXT_RUBY_LIBS="-L$NXT_RUBY_LIBPATH -Wl,-rpath,${NXT_RUBY_LIBPATH} $NXT_RUBY_LIBS"
85
86        nxt_feature="Ruby library in $NXT_RUBY_LIBPATH"
87        nxt_feature_name=""
88        nxt_feature_run=no
89        nxt_feature_incs="${NXT_RUBY_INCPATH}"
90        nxt_feature_libs="${NXT_RUBY_LIBS}"
91        nxt_feature_test="
92            #include <ruby.h>
93
94            int main() {
95                ruby_init();
96                return ruby_cleanup(0);
97            }"
98
99        . auto/feature
100    fi
101
102else
103    $echo "checking for Ruby ... not found"
104fi
105
106if [ $nxt_found = no ]; then
107    $echo
108    $echo $0: error: no Ruby found.
109    $echo
110    exit 1;
111fi
112
113
114nxt_feature="Ruby version"
115nxt_feature_name=""
116nxt_feature_run=value
117nxt_feature_incs="${NXT_RUBY_INCPATH}"
118nxt_feature_libs="${NXT_RUBY_LIBS}"
119nxt_feature_test="
120    #include <ruby.h>
121    #include <ruby/version.h>
122
123    int main() {
124        printf(\"%s\", ruby_version);
125        return 0;
126    }"
127
128. auto/feature
129
130
131if grep ^$NXT_RUBY_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
132    $echo
133    $echo $0: error: duplicate \"$NXT_RUBY_MODULE\" module configured.
134    $echo
135    exit 1;
136fi
137
138$echo " + Ruby module: ${NXT_RUBY_MODULE}.unit.so"
139
140. auto/cc/deps
141
142$echo >> $NXT_MAKEFILE
143
144NXT_RUBY_MODULE_SRCS=" \
145    src/ruby/nxt_ruby.c \
146    src/ruby/nxt_ruby_stream_io.c
147"
148
149# The Ruby module object files.
150
151nxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
152
153for nxt_src in $NXT_RUBY_MODULE_SRCS; do
154
155    nxt_obj=${nxt_src%.c}-$NXT_RUBY_MODULE.o
156    nxt_dep=${nxt_src%.c}-$NXT_RUBY_MODULE.dep
157    nxt_dep_flags=`nxt_gen_dep_flags`
158    nxt_dep_post=`nxt_gen_dep_post`
159    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
160
161    cat << END >> $NXT_MAKEFILE
162
163$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
164	mkdir -p $NXT_BUILD_DIR/src/ruby
165	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_RUBY_INCPATH \\
166	$nxt_dep_flags \\
167	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
168	$nxt_dep_post
169
170-include $NXT_BUILD_DIR/$nxt_dep
171
172END
173
174done
175
176cat << END >> $NXT_MAKEFILE
177
178.PHONY: ${NXT_RUBY_MODULE}
179.PHONY: ${NXT_RUBY_MODULE}-install
180.PHONY: ${NXT_RUBY_MODULE}-uninstall
181
182all: ${NXT_RUBY_MODULE}
183
184${NXT_RUBY_MODULE}:	$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so
185
186$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so:	$nxt_objs
187	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
188	$nxt_objs $NXT_RUBY_LIBS $NXT_LD_OPT
189
190
191install: ${NXT_RUBY_MODULE}-install
192
193${NXT_RUBY_MODULE}-install: ${NXT_RUBY_MODULE} install-check
194	install -d \$(DESTDIR)$NXT_MODULES
195	install -p $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
196		\$(DESTDIR)$NXT_MODULES/
197
198
199uninstall: ${NXT_RUBY_MODULE}-uninstall
200
201${NXT_RUBY_MODULE}-uninstall:
202	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_RUBY_MODULE}.unit.so
203	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
204
205END
206