3 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
6 from waflib import Task,Options,Utils
7 from waflib.TaskGen import before_method,feature,after_method,Task,extension
8 from waflib.Configure import conf
10 @before_method('apply_incpaths','apply_lib_vars','apply_bundle','apply_link')
11 def init_rubyext(self):
12 self.install_path='${ARCHDIR_RUBY}'
13 self.uselib=self.to_list(getattr(self,'uselib',''))
14 if not'RUBY'in self.uselib:
15 self.uselib.append('RUBY')
16 if not'RUBYEXT'in self.uselib:
17 self.uselib.append('RUBYEXT')
19 @before_method('apply_link','propagate_uselib')
20 def apply_ruby_so_name(self):
21 self.env['cshlib_PATTERN']=self.env['cxxshlib_PATTERN']=self.env['rubyext_PATTERN']
23 def check_ruby_version(self,minver=()):
24 if Options.options.rubybinary:
25 self.env.RUBY=Options.options.rubybinary
27 self.find_program('ruby',var='RUBY')
30 version=self.cmd_and_log([ruby,'-e','puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
32 self.fatal('could not determine ruby version')
33 self.env.RUBY_VERSION=version
35 ver=tuple(map(int,version.split(".")))
37 self.fatal('unsupported ruby version %r'%version)
41 self.fatal('ruby is too old %r'%ver)
42 cver='.'.join([str(x)for x in minver])
45 self.msg('Checking for ruby version %s'%str(minver or''),cver)
47 def check_ruby_ext_devel(self):
49 self.fatal('ruby detection is required first')
50 if not self.env.CC_NAME and not self.env.CXX_NAME:
51 self.fatal('load a c/c++ compiler first')
52 version=tuple(map(int,self.env.RUBY_VERSION.split(".")))
54 return Utils.to_list(self.cmd_and_log([self.env.RUBY,'-rrbconfig','-e',cmd]))
56 return read_out('puts Config::CONFIG[%r]'%key)
58 archdir=read_config('archdir')
61 ruby_hdrdir=read_config('rubyhdrdir')
63 cpppath+=[os.path.join(ruby_hdrdir[0],read_config('arch')[0])]
64 self.check(header_name='ruby.h',includes=cpppath,errmsg='could not find ruby header file')
65 self.env.LIBPATH_RUBYEXT=read_config('libdir')
66 self.env.LIBPATH_RUBYEXT+=archdir
67 self.env.INCLUDES_RUBYEXT=cpppath
68 self.env.CFLAGS_RUBYEXT=read_config('CCDLFLAGS')
69 self.env.rubyext_PATTERN='%s.'+read_config('DLEXT')[0]
70 flags=read_config('LDSHARED')
71 while flags and flags[0][0]!='-':
73 if len(flags)>1 and flags[1]=="ppc":
75 self.env.LINKFLAGS_RUBYEXT=flags
76 self.env.LINKFLAGS_RUBYEXT+=read_config('LIBS')
77 self.env.LINKFLAGS_RUBYEXT+=read_config('LIBRUBYARG_SHARED')
78 if Options.options.rubyarchdir:
79 self.env.ARCHDIR_RUBY=Options.options.rubyarchdir
81 self.env.ARCHDIR_RUBY=read_config('sitearchdir')[0]
82 if Options.options.rubylibdir:
83 self.env.LIBDIR_RUBY=Options.options.rubylibdir
85 self.env.LIBDIR_RUBY=read_config('sitelibdir')[0]
87 def check_ruby_module(self,module_name):
88 self.start_msg('Ruby module %s'%module_name)
90 self.cmd_and_log([self.env['RUBY'],'-e','require \'%s\';puts 1'%module_name])
93 self.fatal('Could not find the ruby module %r'%module_name)
96 def process(self,node):
97 tsk=self.create_task('run_ruby',node)
98 class run_ruby(Task.Task):
99 run_str='${RUBY} ${RBFLAGS} -I ${SRC[0].parent.abspath()} ${SRC}'
101 opt.add_option('--with-ruby-archdir',type='string',dest='rubyarchdir',help='Specify directory where to install arch specific files')
102 opt.add_option('--with-ruby-libdir',type='string',dest='rubylibdir',help='Specify alternate ruby library path')
103 opt.add_option('--with-ruby-binary',type='string',dest='rubybinary',help='Specify alternate ruby binary')