xref: /unit/auto/modules/ruby (revision 743:e0f0cd7d244a)
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
94
95nxt_feature="Ruby version"
96nxt_feature_name=""
97nxt_feature_run=value
98nxt_feature_incs="${NXT_RUBY_INCPATH}"
99nxt_feature_libs="${NXT_RUBY_LIBS}"
100nxt_feature_test="
101    #include <ruby.h>
102    #include <ruby/version.h>
103
104    int main() {
105        printf(\"%s\", ruby_version);
106        return 0;
107    }"
108
109. auto/feature
110
111
112if grep ^$NXT_RUBY_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
113    $echo
114    $echo $0: error: duplicate \"$NXT_RUBY_MODULE\" module configured.
115    $echo
116    exit 1;
117fi
118
119$echo " + Ruby module: ${NXT_RUBY_MODULE}.unit.so"
120
121. auto/cc/deps
122
123$echo >> $NXT_MAKEFILE
124
125NXT_RUBY_MODULE_SRCS=" \
126    src/ruby/nxt_ruby.c \
127    src/ruby/nxt_ruby_stream_io.c
128"
129
130# The Ruby module object files.
131
132nxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
133
134for nxt_src in $NXT_RUBY_MODULE_SRCS; do
135
136    nxt_obj=${nxt_src%.c}-$NXT_RUBY_MODULE.o
137    nxt_dep=${nxt_src%.c}-$NXT_RUBY_MODULE.dep
138    nxt_dep_flags=`nxt_gen_dep_flags`
139    nxt_dep_post=`nxt_gen_dep_post`
140    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
141
142    cat << END >> $NXT_MAKEFILE
143
144$NXT_BUILD_DIR/$nxt_obj:	$nxt_src
145	mkdir -p $NXT_BUILD_DIR/src/ruby
146	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_RUBY_INCPATH \\
147	$nxt_dep_flags \\
148	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
149	$nxt_dep_post
150
151-include $NXT_BUILD_DIR/$nxt_dep
152
153END
154
155done
156
157cat << END >> $NXT_MAKEFILE
158
159.PHONY: ${NXT_RUBY_MODULE}
160.PHONY: ${NXT_RUBY_MODULE}-install
161.PHONY: ${NXT_RUBY_MODULE}-uninstall
162
163all: ${NXT_RUBY_MODULE}
164
165${NXT_RUBY_MODULE}:	$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so
166
167$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so:	$nxt_objs
168	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
169	$nxt_objs $NXT_RUBY_LIBS $NXT_LD_OPT
170
171
172install: ${NXT_RUBY_MODULE}-install
173
174${NXT_RUBY_MODULE}-install: ${NXT_RUBY_MODULE} install-check
175	install -d \$(DESTDIR)$NXT_MODULES
176	install -p $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
177		\$(DESTDIR)$NXT_MODULES/
178
179
180uninstall: ${NXT_RUBY_MODULE}-uninstall
181
182${NXT_RUBY_MODULE}-uninstall:
183	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_RUBY_MODULE}.unit.so
184	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
185
186END
187