~ubuntu-branches/ubuntu/precise/nodejs/precise

« back to all changes in this revision

Viewing changes to tools/wafadmin/Tools/ruby.py

  • Committer: Bazaar Package Importer
  • Author(s): Jérémy Lal
  • Date: 2010-08-20 11:49:04 UTC
  • mfrom: (7.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100820114904-lz22w6fkth7yh179
Tags: 0.2.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# encoding: utf-8
3
 
# daniel.svensson at purplescout.se 2008
4
 
 
5
 
import os
6
 
import Task, Options, Utils
7
 
from TaskGen import before, feature, after
8
 
from Configure import conf
9
 
 
10
 
@feature('rubyext')
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')
20
 
 
21
 
@feature('rubyext')
22
 
@before('apply_link')
23
 
def apply_ruby_so_name(self):
24
 
        self.env['shlib_PATTERN'] = self.env['rubyext_PATTERN']
25
 
 
26
 
@conf
27
 
def check_ruby_version(conf, minver=()):
28
 
        """
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
32
 
        """
33
 
 
34
 
        if Options.options.rubybinary:
35
 
                conf.env.RUBY = Options.options.rubybinary
36
 
        else:
37
 
                conf.find_program("ruby", var="RUBY", mandatory=True)
38
 
 
39
 
        ruby = conf.env.RUBY
40
 
 
41
 
        try:
42
 
                version = Utils.cmd_output([ruby, '-e', 'puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
43
 
        except:
44
 
                conf.fatal('could not determine ruby version')
45
 
        conf.env.RUBY_VERSION = version
46
 
 
47
 
        try:
48
 
                ver = tuple(map(int, version.split(".")))
49
 
        except:
50
 
                conf.fatal('unsupported ruby version %r' % version)
51
 
 
52
 
        cver = ''
53
 
        if minver:
54
 
                if ver < minver:
55
 
                        conf.fatal('ruby is too old')
56
 
                cver = ".".join(str(x) for x in minver)
57
 
 
58
 
        conf.check_message('ruby', cver, True, version)
59
 
 
60
 
@conf
61
 
def check_ruby_ext_devel(conf):
62
 
        if not conf.env.RUBY:
63
 
                conf.fatal('ruby detection is required first')
64
 
 
65
 
        if not conf.env.CC_NAME and not conf.env.CXX_NAME:
66
 
                conf.fatal('load a c/c++ compiler first')
67
 
 
68
 
        version = tuple(map(int, conf.env.RUBY_VERSION.split(".")))
69
 
 
70
 
        def read_out(cmd):
71
 
                return Utils.to_list(Utils.cmd_output([conf.env.RUBY, '-rrbconfig', '-e', cmd]))
72
 
 
73
 
        def read_config(key):
74
 
                return read_out('puts Config::CONFIG[%r]' % key)
75
 
 
76
 
        ruby = conf.env['RUBY']
77
 
        archdir = read_config('archdir')
78
 
        cpppath = 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])]
83
 
 
84
 
        conf.check(header_name='ruby.h', includes=cpppath, mandatory=True, errmsg='could not find ruby header file')
85
 
 
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]
91
 
 
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] != '-':
96
 
                flags = flags[1:]
97
 
 
98
 
        # we also want to strip out the deprecated ppc flags
99
 
        if len(flags) > 1 and flags[1] == "ppc":
100
 
                flags = flags[2:]
101
 
 
102
 
        conf.env.LINKFLAGS_RUBYEXT = flags
103
 
        conf.env.LINKFLAGS_RUBYEXT += read_config("LIBS")
104
 
        conf.env.LINKFLAGS_RUBYEXT += read_config("LIBRUBYARG_SHARED")
105
 
 
106
 
        if Options.options.rubyarchdir:
107
 
                conf.env.ARCHDIR_RUBY = Options.options.rubyarchdir
108
 
        else:
109
 
                conf.env.ARCHDIR_RUBY = read_config('sitearchdir')[0]
110
 
 
111
 
        if Options.options.rubylibdir:
112
 
                conf.env.LIBDIR_RUBY = Options.options.rubylibdir
113
 
        else:
114
 
                conf.env.LIBDIR_RUBY = read_config('sitelibdir')[0]
115
 
 
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')
120