author | Michael Granger <ged@FaerieMUD.org> |
Fri, 15 Aug 2008 16:23:03 +0000 | |
changeset 1 | 09d0d209d06d |
parent 0 | 92d00ff32c56 |
child 2 | 0c24586f579a |
child 9 | 4c51ebe6e9b6 |
permissions | -rw-r--r-- |
0 | 1 |
### Monkeypatch to work around the broken Rakefile generated by Mkrf <= 0.2.3 |
2 |
||
3 |
# This fixes: |
|
4 |
# * Some weird unnecessary string interpolation |
|
5 |
# * The :install task doesn't work unless you have RUBYARCHDIR in your environment, instead of |
|
6 |
# falling back to CONFIG['sitearchdir']. |
|
7 |
# * The :install task created the target install directory every time instead of just |
|
8 |
# declaring a dependency on a directory task |
|
9 |
||
10 |
require 'mkrf/generator' |
|
11 |
||
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
12 |
RAKEFILE_TEMPLATE = %q{ |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
13 |
# Generated by monkeypatched mkrf |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
14 |
require 'rake/clean' |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
15 |
require 'rbconfig' |
0 | 16 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
17 |
include Config |
0 | 18 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
19 |
SRC = FileList[#{sources.join(',')}] |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
20 |
OBJ = SRC.ext('#{objext}') |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
21 |
CC = '#{@cc}' |
0 | 22 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
23 |
ADDITIONAL_OBJECTS = '#{objects}' |
0 | 24 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
25 |
LDSHARED = "#{@available.ldshared_string} #{ldshared}" |
0 | 26 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
27 |
LIBPATH = "#{library_path(CONFIG['libdir'])} #{@available.library_paths_compile_string}" |
0 | 28 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
29 |
INCLUDES = "#{@available.includes_compile_string}" |
0 | 30 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
31 |
LIBS = "#{@available.library_compile_string}" |
0 | 32 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
33 |
CFLAGS = "#{cflags} #{defines_compile_string}" |
0 | 34 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
35 |
RUBYARCHDIR = ENV["RUBYARCHDIR"] || CONFIG['sitearchdir'] |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
36 |
LIBRUBYARG_SHARED = "#{CONFIG['LIBRUBYARG_SHARED']}" |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
37 |
EXT = '#{@extension_name}' |
0 | 38 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
39 |
CLEAN.include( EXT, '*.#{objext}' ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
40 |
CLOBBER.include( 'mkrf.log' ) |
0 | 41 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
42 |
task :default => EXT |
0 | 43 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
44 |
rule '.#{objext}' => '.#{@source_extension}' do |t| |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
45 |
sh "\#{CC} \#{CFLAGS} \#{INCLUDES} -c \#{t.source}" |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
46 |
end |
0 | 47 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
48 |
desc "Build this extension" |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
49 |
file EXT => OBJ do |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
50 |
sh "\#{LDSHARED} \#{LIBPATH} #{@available.ld_outfile(@extension_name)} \#{OBJ} \#{ADDITIONAL_OBJECTS} \#{LIBS} \#{LIBRUBYARG_SHARED}" |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
51 |
end |
0 | 52 |
|
53 |
||
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
54 |
directory RUBYARCHDIR |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
55 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
56 |
desc "Install this extension" |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
57 |
task :install => [EXT, RUBYARCHDIR] do |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
58 |
install EXT, RUBYARCHDIR, :verbose => true |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
59 |
end |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
60 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
61 |
#{additional_code} |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
62 |
}.gsub( /^\t/m, '' ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
63 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
64 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
65 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
66 |
module Mkrf |
0 | 67 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
68 |
class Availability |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
69 |
# No-op the stupid squashing of output |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
70 |
def silence_stream( stream ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
71 |
old_stream = stream.dup |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
72 |
stream.reopen( @logger.instance_variable_get(:@logdev).dev ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
73 |
stream.sync = true |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
74 |
yield |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
75 |
ensure |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
76 |
stream.reopen( old_stream ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
77 |
end |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
78 |
end |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
79 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
80 |
class Generator |
0 | 81 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
82 |
def rakefile_contents # :nodoc: |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
83 |
objext = CONFIG['OBJEXT'] |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
84 |
return interpolate( RAKEFILE_TEMPLATE, binding() ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
85 |
end |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
86 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
87 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
88 |
### Interpolate any '#{...}' placeholders in the string within the given |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
89 |
### +scope+ (a Binding object). |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
90 |
def interpolate( string, scope ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
91 |
unless scope.is_a?( Binding ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
92 |
raise TypeError, "Argument to interpolate must be a Binding, not "\ |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
93 |
"a #{scope.class.name}" |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
94 |
end |
0 | 95 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
96 |
# $stderr.puts ">>> Interpolating '#{self}'..." |
0 | 97 |
|
1
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
98 |
copy = string.gsub( /"/, %q:\": ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
99 |
eval( '"' + copy + '"', scope ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
100 |
rescue Exception => err |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
101 |
nicetrace = err.backtrace.find_all {|frame| |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
102 |
/in `(interpolate|eval)'/i !~ frame |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
103 |
} |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
104 |
Kernel.raise( err, err.message, nicetrace ) |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
105 |
end |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
106 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
107 |
end # class Generator |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
108 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
109 |
end # module Mkrf |