Skip to content
Browse files

Added Windows support from Ronald Pijnacker's patch to the ML

git-svn-id: http://mkrf.rubyforge.org/svn/trunk@56 6e48df83-f314-0410-b1e7-e69642b30866
  • Loading branch information...
1 parent f30dae3 commit dd78a2d1de490121f01fd57bf1547708ab5d1943 hoanga committed Apr 6, 2007
Showing with 49 additions and 14 deletions.
  1. +1 −1 lib/mkrf.rb
  2. +29 −5 lib/mkrf/availability.rb
  3. +19 −8 lib/mkrf/generator.rb
View
2 lib/mkrf.rb
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/mkrf/availability'
require File.dirname(__FILE__) + '/mkrf/generator'
-Mkrf::VERSION = "0.2.0"
+Mkrf::VERSION = "0.2.1"
View
34 lib/mkrf/availability.rb
@@ -26,8 +26,7 @@ class Availability
# * <tt>:headers</tt> -- headers to load by default
# * <tt>:compiler</tt> -- which compiler to use when determining availability
# * <tt>:includes</tt> -- directories that should be searched for include files
- def initialize(options = {})
-
+ def initialize(options = {})
@loaded_libs = (options[:loaded_libs] || Config::CONFIG["LIBS"].gsub('-l', '').split).to_a
@library_paths = (options[:library_paths] || "").to_a
# Not sure what COMMON_HEADERS looks like when populated
@@ -74,6 +73,7 @@ def include_header(header, *paths)
def has_library?(library, function = "main", *paths)
logger.info "Checking for library: #{library}"
return true if library_already_loaded?(library)
+ return true if RUBY_PLATFORM =~ /mswin/ # TODO: find a way on windows
# Should this be only found_library? or a specialized version with
# path searching?
found_library?(library, function)
@@ -139,12 +139,36 @@ def with_includes(*args, &b)
# Returns a string of libraries formatted for compilation
def library_compile_string
- @loaded_libs.collect {|l| "-l#{l}"}.join(' ')
+ if RUBY_PLATFORM =~ /mswin/
+ @loaded_libs.join(' ')
+ else
+ @loaded_libs.collect {|l| "-l#{l}"}.join(' ')
+ end
end
# Returns a string of libraries directories formatted for compilation
def library_paths_compile_string
- @library_paths.collect {|l| "-L#{l}"}.join(' ')
+ if RUBY_PLATFORM =~ /mswin/
+ @library_paths.collect {|l| "/libpath:#{l}"}.join(' ')
+ else
+ @library_paths.collect {|l| "-L#{l}"}.join(' ')
+ end
+ end
+
+ def ldshared_string
+ if RUBY_PLATFORM =~ /mswin/
+ "link -nologo -incremental:no -debug -opt:ref -opt:icf -dll"
+ else
+ CONFIG['LDSHARED']
+ end
+ end
+
+ def ld_outfile(filename) # :nodoc:
+ if RUBY_PLATFORM =~ /mswin/
+ "-out:#{filename}"
+ else
+ "-o #{filename}"
+ end
end
# Returns a string of include directories formatted for compilation
@@ -243,7 +267,7 @@ def with_stackable_attribute(attribute, *args)
def header_include_string
@headers.collect {|header| "#include <#{header}>"}.join('\n')
end
-
+
def link_command
# This current implementation just splats the library_paths in
# unconditionally. Is this problematic?
View
27 lib/mkrf/generator.rb
@@ -153,24 +153,34 @@ def write_rakefile(filename = "Rakefile") # :nodoc:
def defines_compile_string # :nodoc:
@available.defines.collect {|define| "-D#{define}"}.join(' ')
end
-
+
+ def library_path(path) # :nodoc:
+ if RUBY_PLATFORM =~ /mswin/
+ "-libpath:#{path}"
+ else
+ "-L#{path}"
+ end
+ end
+
def rakefile_contents # :nodoc:
+ objext = CONFIG['OBJEXT']
+
<<-END_RAKEFILE
# Generated by mkrf
require 'rake/clean'
-CLEAN.include('*.o')
+CLEAN.include('*.#{objext}')
CLOBBER.include('#{@extension_name}', 'mkrf.log')
SRC = FileList[#{sources.join(',')}]
-OBJ = SRC.ext('o')
+OBJ = SRC.ext('#{objext}')
CC = '#{@cc}'
ADDITIONAL_OBJECTS = '#{objects}'
-LDSHARED = "#{CONFIG['LDSHARED']} #{ldshared}"
+LDSHARED = "#{@available.ldshared_string} #{ldshared}"
-LIBPATH = "-L#{CONFIG['rubylibdir']} #{@available.library_paths_compile_string}"
+LIBPATH = "#{library_path(CONFIG['libdir'])} #{@available.library_paths_compile_string}"
INCLUDES = "#{@available.includes_compile_string}"
@@ -179,16 +189,17 @@ def rakefile_contents # :nodoc:
CFLAGS = "#{cflags} #{defines_compile_string}"
RUBYARCHDIR = "\#{ENV["RUBYARCHDIR"]}"
+LIBRUBYARG_SHARED = "#{CONFIG['LIBRUBYARG_SHARED']}"
task :default => ['#{@extension_name}']
-rule '.o' => '.c' do |t|
- sh "\#{CC} \#{CFLAGS} \#{INCLUDES} -c -o \#{t.name} \#{t.source}"
+rule '.#{objext}' => '.c' do |t|
+ sh "\#{CC} \#{CFLAGS} \#{INCLUDES} -c \#{t.source}"
end
desc "Build this extension"
file '#{@extension_name}' => OBJ do
- sh "\#{LDSHARED} \#{LIBPATH} -o #{@extension_name} \#{OBJ} \#{ADDITIONAL_OBJECTS} \#{LIBS}"
+ sh "\#{LDSHARED} \#{LIBPATH} #{@available.ld_outfile(@extension_name)} \#{OBJ} \#{ADDITIONAL_OBJECTS} \#{LIBS} \#{LIBRUBYARG_SHARED}"
end
desc "Install this extension"

0 comments on commit dd78a2d

Please sign in to comment.
Something went wrong with that request. Please try again.