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 591539Svbart@nginx.com NXT_RUBY_RUBYHDRDIR=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["rubyhdrdir"]'` 601539Svbart@nginx.com NXT_RUBY_ARCHHDRDIR=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["rubyarchhdrdir"]'` 611539Svbart@nginx.com NXT_RUBY_SITEDIR=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["sitedir"]'` 621539Svbart@nginx.com NXT_RUBY_LIBDIR=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["rubylibdir"]'` 631539Svbart@nginx.com NXT_RUBY_TOPDIR=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["topdir"]'` 641539Svbart@nginx.com NXT_RUBY_PREFIXDIR=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["rubylibprefix"]'` 65*1540Svbart@nginx.com 66*1540Svbart@nginx.com NXT_RUBY_GEMPATH=`$NXT_RUBY -rrubygems -e 'print Gem.default_path().join(":")'` 671489St.nateldemoura@f5.com 68584Salexander.borisov@nginx.com NXT_RUBY_INCPATH="-I$NXT_RUBY_ARCHHDRDIR -I$NXT_RUBY_RUBYHDRDIR" 69584Salexander.borisov@nginx.com 701539Svbart@nginx.com NXT_RUBY_LIBNAME=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["RUBY_SO_NAME"]'` 711539Svbart@nginx.com NXT_RUBY_LIBSCONF=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["LIBS"]'` 721539Svbart@nginx.com NXT_RUBY_LIBPATH=`$NXT_RUBY -rrbconfig -e 'print RbConfig::CONFIG["libdir"]'` 73863Svbart@nginx.com NXT_RUBY_LIBS="-l$NXT_RUBY_LIBNAME $NXT_RUBY_LIBSCONF" 74584Salexander.borisov@nginx.com 75863Svbart@nginx.com nxt_feature="Ruby library" 76584Salexander.borisov@nginx.com nxt_feature_name="" 771537Svbart@nginx.com nxt_feature_run=value 78584Salexander.borisov@nginx.com nxt_feature_incs="${NXT_RUBY_INCPATH}" 79584Salexander.borisov@nginx.com nxt_feature_libs="${NXT_RUBY_LIBS}" 80584Salexander.borisov@nginx.com nxt_feature_test=" 81584Salexander.borisov@nginx.com #include <ruby.h> 82584Salexander.borisov@nginx.com 83584Salexander.borisov@nginx.com int main() { 841537Svbart@nginx.com static const char *argv[3] = { 851537Svbart@nginx.com \"NGINX_Unit\", \"-rrbconfig\", 861537Svbart@nginx.com \"-eprint RbConfig::CONFIG['libdir']\" 871537Svbart@nginx.com }; 881537Svbart@nginx.com 891537Svbart@nginx.com RUBY_INIT_STACK; 90584Salexander.borisov@nginx.com ruby_init(); 911537Svbart@nginx.com return ruby_run_node(ruby_options(3, (char **) argv)); 92584Salexander.borisov@nginx.com }" 93584Salexander.borisov@nginx.com 94584Salexander.borisov@nginx.com . auto/feature 95584Salexander.borisov@nginx.com 961537Svbart@nginx.com if [ "$nxt_feature_value" != "$NXT_RUBY_LIBPATH" ]; then 97863Svbart@nginx.com NXT_RUBY_LIBS="-L$NXT_RUBY_LIBPATH -Wl,-rpath,${NXT_RUBY_LIBPATH} $NXT_RUBY_LIBS" 98863Svbart@nginx.com 99863Svbart@nginx.com nxt_feature="Ruby library in $NXT_RUBY_LIBPATH" 100863Svbart@nginx.com nxt_feature_name="" 101863Svbart@nginx.com nxt_feature_run=no 102863Svbart@nginx.com nxt_feature_incs="${NXT_RUBY_INCPATH}" 103863Svbart@nginx.com nxt_feature_libs="${NXT_RUBY_LIBS}" 104863Svbart@nginx.com nxt_feature_test=" 105863Svbart@nginx.com #include <ruby.h> 106863Svbart@nginx.com 107863Svbart@nginx.com int main() { 108863Svbart@nginx.com ruby_init(); 109863Svbart@nginx.com return ruby_cleanup(0); 110863Svbart@nginx.com }" 111863Svbart@nginx.com 112863Svbart@nginx.com . auto/feature 113863Svbart@nginx.com fi 114863Svbart@nginx.com 115584Salexander.borisov@nginx.comelse 116584Salexander.borisov@nginx.com $echo "checking for Ruby ... not found" 117584Salexander.borisov@nginx.comfi 118584Salexander.borisov@nginx.com 119584Salexander.borisov@nginx.comif [ $nxt_found = no ]; then 120584Salexander.borisov@nginx.com $echo 121584Salexander.borisov@nginx.com $echo $0: error: no Ruby found. 122584Salexander.borisov@nginx.com $echo 123584Salexander.borisov@nginx.com exit 1; 124584Salexander.borisov@nginx.comfi 125584Salexander.borisov@nginx.com 126612Salexander.borisov@nginx.com 127612Salexander.borisov@nginx.comnxt_feature="Ruby version" 128612Salexander.borisov@nginx.comnxt_feature_name="" 129612Salexander.borisov@nginx.comnxt_feature_run=value 130612Salexander.borisov@nginx.comnxt_feature_incs="${NXT_RUBY_INCPATH}" 131612Salexander.borisov@nginx.comnxt_feature_libs="${NXT_RUBY_LIBS}" 132612Salexander.borisov@nginx.comnxt_feature_test=" 133612Salexander.borisov@nginx.com #include <ruby.h> 134612Salexander.borisov@nginx.com #include <ruby/version.h> 135612Salexander.borisov@nginx.com 136612Salexander.borisov@nginx.com int main() { 137612Salexander.borisov@nginx.com printf(\"%s\", ruby_version); 138612Salexander.borisov@nginx.com return 0; 139612Salexander.borisov@nginx.com }" 140612Salexander.borisov@nginx.com 141612Salexander.borisov@nginx.com. auto/feature 142612Salexander.borisov@nginx.com 143584Salexander.borisov@nginx.com 144584Salexander.borisov@nginx.comif grep ^$NXT_RUBY_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then 145584Salexander.borisov@nginx.com $echo 146584Salexander.borisov@nginx.com $echo $0: error: duplicate \"$NXT_RUBY_MODULE\" module configured. 147584Salexander.borisov@nginx.com $echo 148584Salexander.borisov@nginx.com exit 1; 149584Salexander.borisov@nginx.comfi 150584Salexander.borisov@nginx.com 1511489St.nateldemoura@f5.com 1521532St.nateldemoura@f5.comNXT_RUBY_MOUNTS_HEADER=nxt_${NXT_RUBY_MODULE}_mounts.h 1531532St.nateldemoura@f5.comNXT_RUBY_MOUNTS_PATH=$NXT_BUILD_DIR/$NXT_RUBY_MOUNTS_HEADER 1541532St.nateldemoura@f5.com 1551532St.nateldemoura@f5.comcat << END > $NXT_RUBY_MOUNTS_PATH 1561489St.nateldemoura@f5.com 1571489St.nateldemoura@f5.comstatic const nxt_fs_mount_t nxt_ruby_mounts[] = { 1581489St.nateldemoura@f5.com {(u_char *) "$NXT_RUBY_RUBYHDRDIR", (u_char *) "$NXT_RUBY_RUBYHDRDIR", 1591489St.nateldemoura@f5.com (u_char *) "bind", NXT_MS_BIND | NXT_MS_REC, NULL}, 1601489St.nateldemoura@f5.com {(u_char *) "$NXT_RUBY_ARCHHDRDIR", (u_char *) "$NXT_RUBY_ARCHHDRDIR", 1611489St.nateldemoura@f5.com (u_char *) "bind", NXT_MS_BIND | NXT_MS_REC, NULL}, 1621489St.nateldemoura@f5.com {(u_char *) "$NXT_RUBY_SITEDIR", (u_char *) "$NXT_RUBY_SITEDIR", 1631489St.nateldemoura@f5.com (u_char *) "bind", NXT_MS_BIND | NXT_MS_REC, NULL}, 1641489St.nateldemoura@f5.com {(u_char *) "$NXT_RUBY_LIBDIR", (u_char *) "$NXT_RUBY_LIBDIR", 1651489St.nateldemoura@f5.com (u_char *) "bind", NXT_MS_BIND | NXT_MS_REC, NULL}, 1661489St.nateldemoura@f5.com {(u_char *) "$NXT_RUBY_TOPDIR", (u_char *) "$NXT_RUBY_TOPDIR", 1671489St.nateldemoura@f5.com (u_char *) "bind", NXT_MS_BIND | NXT_MS_REC, NULL}, 1681489St.nateldemoura@f5.com {(u_char *) "$NXT_RUBY_PREFIXDIR", (u_char *) "$NXT_RUBY_PREFIXDIR", 1691489St.nateldemoura@f5.com (u_char *) "bind", NXT_MS_BIND | NXT_MS_REC, NULL}, 1701489St.nateldemoura@f5.com 1711489St.nateldemoura@f5.comEND 1721489St.nateldemoura@f5.com 1731489St.nateldemoura@f5.comfor path in `echo $NXT_RUBY_GEMPATH | tr ':' '\n'`; do 1741532St.nateldemoura@f5.com $echo "{(u_char *) \"$path\", (u_char *) \"$path\"," >> $NXT_RUBY_MOUNTS_PATH 1751532St.nateldemoura@f5.com $echo "(u_char *) \"bind\", NXT_MS_BIND | NXT_MS_REC, NULL}," >> $NXT_RUBY_MOUNTS_PATH 1761489St.nateldemoura@f5.comdone 1771489St.nateldemoura@f5.com 1781532St.nateldemoura@f5.com$echo "};" >> $NXT_RUBY_MOUNTS_PATH 1791489St.nateldemoura@f5.com 1801489St.nateldemoura@f5.com 181584Salexander.borisov@nginx.com$echo " + Ruby module: ${NXT_RUBY_MODULE}.unit.so" 182584Salexander.borisov@nginx.com 183584Salexander.borisov@nginx.com. auto/cc/deps 184584Salexander.borisov@nginx.com 185584Salexander.borisov@nginx.com$echo >> $NXT_MAKEFILE 186584Salexander.borisov@nginx.com 187584Salexander.borisov@nginx.comNXT_RUBY_MODULE_SRCS=" \ 188584Salexander.borisov@nginx.com src/ruby/nxt_ruby.c \ 189584Salexander.borisov@nginx.com src/ruby/nxt_ruby_stream_io.c 190584Salexander.borisov@nginx.com" 191584Salexander.borisov@nginx.com 192584Salexander.borisov@nginx.com# The Ruby module object files. 193584Salexander.borisov@nginx.com 194743Smax.romanov@nginx.comnxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o 195584Salexander.borisov@nginx.com 196584Salexander.borisov@nginx.comfor nxt_src in $NXT_RUBY_MODULE_SRCS; do 197584Salexander.borisov@nginx.com 198584Salexander.borisov@nginx.com nxt_obj=${nxt_src%.c}-$NXT_RUBY_MODULE.o 199584Salexander.borisov@nginx.com nxt_dep=${nxt_src%.c}-$NXT_RUBY_MODULE.dep 200584Salexander.borisov@nginx.com nxt_dep_flags=`nxt_gen_dep_flags` 201584Salexander.borisov@nginx.com nxt_dep_post=`nxt_gen_dep_post` 202584Salexander.borisov@nginx.com nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj" 203584Salexander.borisov@nginx.com 204584Salexander.borisov@nginx.com cat << END >> $NXT_MAKEFILE 205584Salexander.borisov@nginx.com 2061217Smax.romanov@nginx.com$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H 207584Salexander.borisov@nginx.com mkdir -p $NXT_BUILD_DIR/src/ruby 2081532St.nateldemoura@f5.com \$(CC) -c \$(CFLAGS) -DNXT_RUBY_MOUNTS_H=\"$NXT_RUBY_MOUNTS_HEADER\" \\ 2091532St.nateldemoura@f5.com \$(NXT_INCS) $NXT_RUBY_INCPATH \\ 210584Salexander.borisov@nginx.com $nxt_dep_flags \\ 211584Salexander.borisov@nginx.com -o $NXT_BUILD_DIR/$nxt_obj $nxt_src 212584Salexander.borisov@nginx.com $nxt_dep_post 213584Salexander.borisov@nginx.com 214584Salexander.borisov@nginx.com-include $NXT_BUILD_DIR/$nxt_dep 215584Salexander.borisov@nginx.com 216584Salexander.borisov@nginx.comEND 217584Salexander.borisov@nginx.com 218584Salexander.borisov@nginx.comdone 219584Salexander.borisov@nginx.com 220584Salexander.borisov@nginx.comcat << END >> $NXT_MAKEFILE 221584Salexander.borisov@nginx.com 222584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE} 223584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE}-install 224584Salexander.borisov@nginx.com.PHONY: ${NXT_RUBY_MODULE}-uninstall 225584Salexander.borisov@nginx.com 226584Salexander.borisov@nginx.comall: ${NXT_RUBY_MODULE} 227584Salexander.borisov@nginx.com 228584Salexander.borisov@nginx.com${NXT_RUBY_MODULE}: $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so 229584Salexander.borisov@nginx.com 230584Salexander.borisov@nginx.com$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so: $nxt_objs 231584Salexander.borisov@nginx.com \$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\ 232584Salexander.borisov@nginx.com $nxt_objs $NXT_RUBY_LIBS $NXT_LD_OPT 233584Salexander.borisov@nginx.com 234584Salexander.borisov@nginx.com 235584Salexander.borisov@nginx.cominstall: ${NXT_RUBY_MODULE}-install 236584Salexander.borisov@nginx.com 237706Sigor@sysoev.ru${NXT_RUBY_MODULE}-install: ${NXT_RUBY_MODULE} install-check 238584Salexander.borisov@nginx.com install -d \$(DESTDIR)$NXT_MODULES 239584Salexander.borisov@nginx.com install -p $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\ 240584Salexander.borisov@nginx.com \$(DESTDIR)$NXT_MODULES/ 241584Salexander.borisov@nginx.com 242584Salexander.borisov@nginx.com 243584Salexander.borisov@nginx.comuninstall: ${NXT_RUBY_MODULE}-uninstall 244584Salexander.borisov@nginx.com 245584Salexander.borisov@nginx.com${NXT_RUBY_MODULE}-uninstall: 246584Salexander.borisov@nginx.com rm -f \$(DESTDIR)$NXT_MODULES/${NXT_RUBY_MODULE}.unit.so 247584Salexander.borisov@nginx.com @rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true 248584Salexander.borisov@nginx.com 249584Salexander.borisov@nginx.comEND 250