3
# daniel.svensson at purplescout.se 2008
6
import Task, Options, Utils
7
from TaskGen import before, feature, after
8
from Configure import conf
11
@before('apply_incpaths', 'apply_type_vars', 'apply_lib_vars', 'apply_bundle')
12
@after('default_cc', 'vars_target_cshlib')
13
def init_rubyext(self):
14
self.default_install_path = '${ARCHDIR_RUBY}'
15
self.uselib = self.to_list(getattr(self, 'uselib', ''))
16
if not 'RUBY' in self.uselib:
17
self.uselib.append('RUBY')
18
if not 'RUBYEXT' in self.uselib:
19
self.uselib.append('RUBYEXT')
23
def apply_ruby_so_name(self):
24
self.env['shlib_PATTERN'] = self.env['rubyext_PATTERN']
27
def check_ruby_version(conf, minver=()):
29
Checks if ruby is installed.
30
If installed the variable RUBY will be set in environment.
31
Ruby binary can be overridden by --with-ruby-binary config variable
34
if Options.options.rubybinary:
35
conf.env.RUBY = Options.options.rubybinary
37
conf.find_program("ruby", var="RUBY", mandatory=True)
42
version = Utils.cmd_output([ruby, '-e', 'puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
44
conf.fatal('could not determine ruby version')
45
conf.env.RUBY_VERSION = version
48
ver = tuple(map(int, version.split(".")))
50
conf.fatal('unsupported ruby version %r' % version)
55
conf.fatal('ruby is too old')
56
cver = ".".join([str(x) for x in minver])
58
conf.check_message('ruby', cver, True, version)
61
def check_ruby_ext_devel(conf):
63
conf.fatal('ruby detection is required first')
65
if not conf.env.CC_NAME and not conf.env.CXX_NAME:
66
conf.fatal('load a c/c++ compiler first')
68
version = tuple(map(int, conf.env.RUBY_VERSION.split(".")))
71
return Utils.to_list(Utils.cmd_output([conf.env.RUBY, '-rrbconfig', '-e', cmd]))
74
return read_out('puts Config::CONFIG[%r]' % key)
76
ruby = conf.env['RUBY']
77
archdir = read_config('archdir')
79
if version >= (1, 9, 0):
80
ruby_hdrdir = read_config('rubyhdrdir')
81
cpppath += ruby_hdrdir
82
cpppath += [os.path.join(ruby_hdrdir[0], read_config('arch')[0])]
84
conf.check(header_name='ruby.h', includes=cpppath, mandatory=True, errmsg='could not find ruby header file')
86
conf.env.LIBPATH_RUBYEXT = read_config('libdir')
87
conf.env.LIBPATH_RUBYEXT += archdir
88
conf.env.CPPPATH_RUBYEXT = cpppath
89
conf.env.CCFLAGS_RUBYEXT = read_config("CCDLFLAGS")
90
conf.env.rubyext_PATTERN = '%s.' + read_config('DLEXT')[0]
92
# ok this is really stupid, but the command and flags are combined.
93
# so we try to find the first argument...
94
flags = read_config('LDSHARED')
95
while flags and flags[0][0] != '-':
98
# we also want to strip out the deprecated ppc flags
99
if len(flags) > 1 and flags[1] == "ppc":
102
conf.env.LINKFLAGS_RUBYEXT = flags
103
conf.env.LINKFLAGS_RUBYEXT += read_config("LIBS")
104
conf.env.LINKFLAGS_RUBYEXT += read_config("LIBRUBYARG_SHARED")
106
if Options.options.rubyarchdir:
107
conf.env.ARCHDIR_RUBY = Options.options.rubyarchdir
109
conf.env.ARCHDIR_RUBY = read_config('sitearchdir')[0]
111
if Options.options.rubylibdir:
112
conf.env.LIBDIR_RUBY = Options.options.rubylibdir
114
conf.env.LIBDIR_RUBY = read_config('sitelibdir')[0]
116
def set_options(opt):
117
opt.add_option('--with-ruby-archdir', type='string', dest='rubyarchdir', help='Specify directory where to install arch specific files')
118
opt.add_option('--with-ruby-libdir', type='string', dest='rubylibdir', help='Specify alternate ruby library path')
119
opt.add_option('--with-ruby-binary', type='string', dest='rubybinary', help='Specify alternate ruby binary')