author | Mahlon E. Smith <mahlon@martini.nu> |
Thu, 25 Dec 2008 07:33:20 +0000 | |
branch | mahlon-misc |
changeset 10 | b1426511fb64 |
parent 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| |
10
b1426511fb64
Merged changes from trunk@4:8.
Mahlon E. Smith <mahlon@martini.nu>
parents:
9
diff
changeset
|
45 |
$stderr.puts " building \#{t.name} from \#{t.source}" |
b1426511fb64
Merged changes from trunk@4:8.
Mahlon E. Smith <mahlon@martini.nu>
parents:
9
diff
changeset
|
46 |
sh "\#{CC} \#{CFLAGS} \#{INCLUDES} -c \#{t.source}" |
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
|
47 |
end |
0 | 48 |
|
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
|
49 |
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
|
50 |
file EXT => OBJ do |
10
b1426511fb64
Merged changes from trunk@4:8.
Mahlon E. Smith <mahlon@martini.nu>
parents:
9
diff
changeset
|
51 |
$stderr.puts " linking \#{OBJ.join(', ')} into \#{EXT}" |
b1426511fb64
Merged changes from trunk@4:8.
Mahlon E. Smith <mahlon@martini.nu>
parents:
9
diff
changeset
|
52 |
sh "\#{LDSHARED} \#{LIBPATH} #{@available.ld_outfile(@extension_name)} \#{OBJ} \#{ADDITIONAL_OBJECTS} \#{LIBS} \#{LIBRUBYARG_SHARED}" |
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
|
53 |
end |
0 | 54 |
|
55 |
||
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
|
56 |
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
|
57 |
|
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 |
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
|
59 |
task :install => [EXT, RUBYARCHDIR] do |
10
b1426511fb64
Merged changes from trunk@4:8.
Mahlon E. Smith <mahlon@martini.nu>
parents:
9
diff
changeset
|
60 |
install EXT, RUBYARCHDIR, :verbose => true |
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
|
61 |
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
|
62 |
|
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 |
#{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
|
64 |
}.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
|
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 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
67 |
|
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 |
module Mkrf |
0 | 69 |
|
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
|
70 |
class Availability |
9
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
71 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
72 |
# Create a new Availability instance. |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
73 |
# |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
74 |
# Valid keys for the options hash include: |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
75 |
# * <tt>:loaded_libs</tt> -- libraries to load by default |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
76 |
# * <tt>:library_paths</tt> -- libraries paths to include by default |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
77 |
# * <tt>:headers</tt> -- headers to load by default |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
78 |
# * <tt>:compiler</tt> -- which compiler to use when determining availability |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
79 |
# * <tt>:includes</tt> -- directories that should be searched for include files |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
80 |
def initialize(options = {}) |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
81 |
@loaded_libs = options[:loaded_libs] || [] |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
82 |
@loaded_libs.flatten! |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
83 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
84 |
@library_paths = [(options[:library_paths] || [])].flatten |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
85 |
# Not sure what COMMON_HEADERS looks like when populated |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
86 |
@headers = options[:headers] || [] # Config::CONFIG["COMMON_HEADERS"] |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
87 |
@compiler = options[:compiler] || Config::CONFIG["CC"] |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
88 |
@includes = [(options[:includes] || DEFAULT_INCLUDES)].flatten |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
89 |
@logger = Logger.new('mkrf.log') |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
90 |
@defines = [] |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
91 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
92 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
93 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
94 |
def can_link?( function_body ) |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
95 |
silence_command_line do |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
96 |
create_source(function_body) |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
97 |
cmd = link_command() |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
98 |
@logger.debug "Running link command: #{cmd}" |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
99 |
system( cmd ) |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
100 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
101 |
ensure |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
102 |
FileUtils.rm_f TEMP_SOURCE_FILE |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
103 |
FileUtils.rm_f TEMP_EXECUTABLE |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
104 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
105 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
106 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
107 |
# Add the LIBRUBYARG_SHARED setting to the library paths for non-windows boxen. This is |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
108 |
# necessary if Ruby is installed in a directory that isn't in the default library |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
109 |
# search path (e.g., on FreeBSD where Ruby is /usr/local/bin/ruby). |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
110 |
def library_paths_compile_string |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
111 |
if RUBY_PLATFORM =~ /mswin/ |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
112 |
@library_paths.collect {|l| "/libpath:#{l}"}.join(' ') |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
113 |
else |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
114 |
Config::CONFIG['LIBRUBYARG_SHARED'] + @library_paths.collect {|l| "-L#{l}"}.join(' ') |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
115 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
116 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
117 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
118 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
119 |
# Separate includes with a newline instead of a literal '\n' |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
120 |
def header_include_string |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
121 |
@headers.collect {|header| "#include <#{header}>"}.join( "\n" ) |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
122 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
123 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
124 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
125 |
# Log the created source to the logfile |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
126 |
def create_source( src ) |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
127 |
@logger.debug "Creating source file:\n#{src}" |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
128 |
File.open( TEMP_SOURCE_FILE, "w+" ) do |f| |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
129 |
f.write( src ) |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
130 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
131 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
132 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
133 |
# Prepend the LIBS string directly to the @loaded_libs, as not all arguments in |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
134 |
# it |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
135 |
def library_compile_string |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
136 |
added_libs = nil |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
137 |
if RUBY_PLATFORM =~ /mswin/ |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
138 |
added_libs = @loaded_libs.join(' ') |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
139 |
else |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
140 |
added_libs = @loaded_libs.collect {|l| "-l#{l}"}.join(' ') |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
141 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
142 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
143 |
return Config::CONFIG["LIBS"] + ' ' + added_libs |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
144 |
end |
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
145 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
146 |
|
4c51ebe6e9b6
* Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
147 |
# Redirect to the mkrf log instead of /dev/null |
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
158 |
class Generator |
0 | 159 |
|
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
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
165 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
166 |
### 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
|
167 |
### +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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
"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
|
172 |
end |
0 | 173 |
|
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
|
174 |
# $stderr.puts ">>> Interpolating '#{self}'..." |
0 | 175 |
|
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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
/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
|
181 |
} |
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
182 |
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
|
183 |
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
|
184 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
185 |
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
|
186 |
|
09d0d209d06d
Added some stuff to the mkrf monkeypatch to log output from the header/library
Michael Granger <ged@FaerieMUD.org>
parents:
0
diff
changeset
|
187 |
end # module Mkrf |