misc/monkeypatches.rb
author Mahlon E. Smith <mahlon@martini.nu>
Tue, 14 Oct 2008 16:11:19 +0000
branchmahlon-misc
changeset 9 4c51ebe6e9b6
parent 1 09d0d209d06d
child 10 b1426511fb64
permissions -rw-r--r--
* Add a mkrf monkeypatch so BSD build flags are generated correctly. * Fix typos!
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|
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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    52
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    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
9
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    69
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    70
		# 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
    71
		#
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    72
		# 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
    73
		# * <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
    74
		# * <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
    75
		# * <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
    76
		# * <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
    77
		# * <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
    78
		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
    79
			@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
    80
			@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
    81
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    82
			@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
    83
			# 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
    84
			@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
    85
			@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
    86
			@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
    87
			@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
    88
			@defines = []
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    89
		end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    90
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    91
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    92
		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
    93
			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
    94
				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
    95
				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
    96
				@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
    97
				system( cmd )
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    98
			end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    99
		ensure
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   100
			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
   101
			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
   102
		end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   103
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   104
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   105
		# 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
   106
		# 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
   107
		# 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
   108
		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
   109
			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
   110
				@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
   111
			else
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   112
				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
   113
			end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   114
		end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   115
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   116
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   117
		# 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
   118
		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
   119
			@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
   120
		end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   121
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   122
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   123
		# 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
   124
		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
   125
			@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
   126
			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
   127
				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
   128
			end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   129
		end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   130
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   131
		# 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
   132
		# it 
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   133
		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
   134
			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
   135
			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
   136
				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
   137
			else
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.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
   139
			end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   140
			
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   141
			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
   142
		end
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   143
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   144
4c51ebe6e9b6 * Add a mkrf monkeypatch so BSD build flags are generated correctly.
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   145
		# 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
   146
		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
   147
			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
   148
			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
   149
			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
   150
			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
   151
		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
   152
			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
   153
		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
   154
	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
   155
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
	class Generator
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   157
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
   158
		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
   159
			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
   160
			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
   161
		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
   162
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
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
		### 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
   165
		### +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
   166
	    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
   167
	        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
   168
	            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
   169
	                "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
   170
	        end
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   171
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
   172
			# $stderr.puts ">>> Interpolating '#{self}'..."
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
	        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
   175
	        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
   176
		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
   177
			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
   178
				/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
   179
			}
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
			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
   181
	    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
   182
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 # 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
   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 # module Mkrf