misc/monkeypatches.rb
author Michael Granger <ged@FaerieMUD.org>
Thu, 20 Nov 2008 16:43:02 +0000
changeset 3 7f6da371e2ce
parent 2 0c24586f579a
permissions -rw-r--r--
* Converted from Mkrf-based build back to mkmf. * Updated the build system.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     1
### Monkeypatch to work around the broken Rakefile generated by Mkrf <= 0.2.3
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     2
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     3
# This fixes:
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     4
# * Some weird unnecessary string interpolation
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     5
# * The :install task doesn't work unless you have RUBYARCHDIR in your environment, instead of
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     6
#   falling back to CONFIG['sitearchdir'].
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     7
# * The :install task created the target install directory every time instead of just
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     8
#   declaring a dependency on a directory task
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     9
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    10
require 'mkrf/generator'
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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|
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    45
		$stderr.puts "  building \#{t.name} from \#{t.source}"
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    51
		$stderr.puts "  linking \#{OBJ.join(', ')} into \#{EXT}"
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    54
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    71
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    72
		# Create a new Availability instance.
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    73
		#
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    74
		# Valid keys for the options hash include:
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    75
		# * <tt>:loaded_libs</tt> -- libraries to load by default
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    76
		# * <tt>:library_paths</tt> -- libraries paths to include by default
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    77
		# * <tt>:headers</tt> -- headers to load by default
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    78
		# * <tt>:compiler</tt> -- which compiler to use when determining availability
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    79
		# * <tt>:includes</tt> -- directories that should be searched for include files
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    80
		def initialize(options = {})      
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    81
			@loaded_libs = options[:loaded_libs] || []
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    82
			@loaded_libs.flatten!
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    83
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    84
			@library_paths = [(options[:library_paths] || [])].flatten
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    85
			# Not sure what COMMON_HEADERS looks like when populated
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    86
			@headers = options[:headers] || [] # Config::CONFIG["COMMON_HEADERS"]
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    87
			@compiler = options[:compiler] || Config::CONFIG["CC"]
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    88
			@includes = [(options[:includes] || DEFAULT_INCLUDES)].flatten
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    89
			@logger = Logger.new('mkrf.log')
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    90
			@defines = []
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    91
		end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    92
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    93
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    94
		def can_link?( function_body )
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    95
			silence_command_line do
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    96
				create_source(function_body)
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    97
				cmd = link_command()
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    98
				@logger.debug "Running link command: #{cmd}"
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
    99
				system( cmd )
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   100
			end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   101
		ensure
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   102
			FileUtils.rm_f TEMP_SOURCE_FILE
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   103
			FileUtils.rm_f TEMP_EXECUTABLE
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   104
		end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   105
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   106
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   107
		# Add the LIBRUBYARG_SHARED setting to the library paths for non-windows boxen. This is
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   108
		# necessary if Ruby is installed in a directory that isn't in the default library
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   109
		# search path (e.g., on FreeBSD where Ruby is /usr/local/bin/ruby).
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   110
		def library_paths_compile_string
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   111
			if RUBY_PLATFORM =~ /mswin/
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   112
				@library_paths.collect {|l| "/libpath:#{l}"}.join(' ')
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   113
			else
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   114
				Config::CONFIG['LIBRUBYARG_SHARED'] + @library_paths.collect {|l| "-L#{l}"}.join(' ')
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   115
			end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   116
		end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   117
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   118
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   119
		# Separate includes with a newline instead of a literal '\n'
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   120
		def header_include_string
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   121
			@headers.collect {|header| "#include <#{header}>"}.join( "\n" )
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   122
		end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   123
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   124
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   125
		# Log the created source to the logfile
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   126
		def create_source( src )
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   127
			@logger.debug "Creating source file:\n#{src}"
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   128
			File.open( TEMP_SOURCE_FILE, "w+" ) do |f|
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   129
				f.write( src )
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   130
			end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   131
		end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   132
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   133
		# Prepend the LIBS string directly to the @loaded_libs, as not all arguments in
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   134
		# it 
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   135
		def library_compile_string
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   136
			added_libs = nil
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   137
			if RUBY_PLATFORM =~ /mswin/
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   138
				added_libs = @loaded_libs.join(' ')
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   139
			else
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   140
				added_libs = @loaded_libs.collect {|l| "-l#{l}"}.join(' ')
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   141
			end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   142
			
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   143
			return Config::CONFIG["LIBS"] + ' ' + added_libs
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   144
		end
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   145
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 1
diff changeset
   146
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   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