Project

General

Profile

Feature #5658 ยป mkmf.rb.in_a_module.no_whitespace.patch

svn diff -x -w lib/mkmf.rb - drbrain (Eric Hodel), 11/23/2011 07:48 AM

View differences:

lib/mkmf.rb (working copy)
6 6
require 'fileutils'
7 7
require 'shellwords'
8 8

  
9
# :stopdoc:
10
class String
11
  # Wraps a string in escaped quotes if it contains whitespace.
12
  def quote
13
    /\s/ =~ self ? "\"#{self}\"" : "#{self}"
14
  end
15

  
16
  # Generates a string used as cpp macro name.
17
  def tr_cpp
18
    strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P")
19
  end
20

  
21
  def funcall_style
22
    /\)\z/ =~ self ? dup : "#{self}()"
23
  end
24

  
25
  def sans_arguments
26
    self[/\A[^()]+/]
27
  end
28
end
29

  
30
class Array
31
  # Wraps all strings in escaped quotes if they contain whitespace.
32
  def quote
33
    map {|s| s.quote}
34
  end
35
end
36
# :startdoc:
37

  
38
module MakeMakefile
39

  
9 40
CONFIG = RbConfig::MAKEFILE_CONFIG
10 41
ORIG_LIBPATH = ENV['LIB']
11 42

  
......
75 106
def config_string(key, config = CONFIG)
76 107
  s = config[key] and !s.empty? and block_given? ? yield(s) : s
77 108
end
109
  module_function :config_string
78 110

  
79 111
def dir_re(dir)
80 112
  Regexp.new('\$(?:\('+dir+'\)|\{'+dir+'\})(?:\$(?:\(target_prefix\)|\{target_prefix\}))?')
81 113
end
114
  module_function :dir_re
82 115

  
83 116
def relative_from(path, base)
84 117
  dir = File.join(path, "")
......
176 209

  
177 210
CONFTEST_C = "conftest.c".freeze
178 211

  
179
class String
180
  # Wraps a string in escaped quotes if it contains whitespace.
181
  def quote
182
    /\s/ =~ self ? "\"#{self}\"" : "#{self}"
183
  end
184

  
185
  # Generates a string used as cpp macro name.
186
  def tr_cpp
187
    strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P")
188
  end
189

  
190
  def funcall_style
191
    /\)\z/ =~ self ? dup : "#{self}()"
192
  end
193

  
194
  def sans_arguments
195
    self[/\A[^()]+/]
196
  end
197
end
198
class Array
199
  # Wraps all strings in escaped quotes if they contain whitespace.
200
  def quote
201
    map {|s| s.quote}
202
  end
203
end
204

  
205 212
def rm_f(*files)
206 213
  opt = (Hash === files.last ? [files.pop] : [])
207 214
  FileUtils.rm_f(Dir[*files.flatten], *opt)
......
519 526
  rm_f "conftest*"
520 527
end
521 528

  
522
class Object
523 529
  alias_method :try_header, (config_string('try_header') || :try_cpp)
524
end
525 530

  
526 531
def cpp_include(header)
527 532
  if header
......
2244 2249

  
2245 2250
# :startdoc:
2246 2251

  
2252
  def make_makefile
2247 2253
init_mkmf
2248 2254

  
2249 2255
$make = with_config("make-prog", ENV["MAKE"] || "make")
......
2272 2278
$configure_args["--topdir"] ||= $curdir
2273 2279
$ruby = arg_config("--ruby", File.join(RbConfig::CONFIG["bindir"], CONFIG["ruby_install_name"]))
2274 2280

  
2281
  end
2275 2282
split = Shellwords.method(:shellwords).to_proc
2276 2283

  
2277 2284
EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip}
......
2330 2337

  
2331 2338
realclean: distclean
2332 2339
"
2340
end
2341

  
2342
include MakeMakefile
2333 2343

  
2334 2344
if not $extmk and /\A(extconf|makefile).rb\z/ =~ File.basename($0)
2335 2345
  END {mkmf_failed($0)}
2336 2346
end
2347

  
2348
make_makefile
2349