Permalink
Browse files

Better detection of MinGW target in Linux/OSX.

  • Loading branch information...
1 parent d4716b9 commit 644524269b07502189dcdd2a9502daed251b27f9 @luislavena luislavena committed Feb 23, 2009
Showing with 69 additions and 16 deletions.
  1. +3 −0 History.txt
  2. +53 −0 lib/rake/extensioncompiler.rb
  3. +13 −16 tasks/bin/cross-ruby.rake
View
@@ -9,6 +9,9 @@
ext.ext_dir = 'custom/location' # look into custom/location
end # instead of ext/my_extension
+ * Better detection of mingw target across Linux/OSX.
+ Exposed it as Rake::ExtensionCompiler
+
=== Bugfixes
* Better output of Rake development tasks (Thanks to Luis Parravicini).
@@ -0,0 +1,53 @@
+#!/usr/bin/env ruby
+
+#
+# HACK: Lousy API design, sue me. At least works ;-)
+#
+# Define a series of helpers to aid in search and usage of MinGW (GCC) Compiler
+# by gem developer/creators.
+#
+
+module Rake
+ module ExtensionCompiler
+ # return the host portion from the installed MinGW
+ def self.mingw_host
+ return @mingw_host if @mingw_host
+
+ # the mingw_gcc_executable is helpful here
+ if target = mingw_gcc_executable then
+ # we only care for the filename
+ target = File.basename(target)
+
+ # now strip the extension (if present)
+ target.sub!(File.extname(target), '')
+
+ # get rid of '-gcc' portion too ;-)
+ target.sub!('-gcc', '')
+ end
+
+ raise "No MinGW tools or unknown setup platform?" unless target
+
+ @mingw_host = target
+ end
+
+ # return the first compiler found that includes both mingw and gcc conditions
+ # (this assumes you have one installed)
+ def self.mingw_gcc_executable
+ return @mingw_gcc_executable if @mingw_gcc_executable
+
+ # grab the paths defined in the environment
+ paths = ENV['PATH'].split(File::PATH_SEPARATOR)
+
+ # the pattern to look into (captures *nix and windows executables)
+ pattern = "*mingw*gcc{,.*}"
+
+ @mingw_gcc_executable = paths.find do |path|
+ # cleanup paths before globbing
+ gcc = Dir.glob("#{File.expand_path(path)}/#{pattern}").first
+ break gcc if gcc
+ end
+
+ @mingw_gcc_executable
+ end
+ end
+end
View
@@ -21,23 +21,21 @@ require 'rake'
require 'rake/clean'
require 'yaml'
+# load compiler helpers
+# add lib directory to the search path
+libdir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
+$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
+
+require 'rake/extensioncompiler'
+
USER_HOME = File.expand_path("~/.rake-compiler")
RUBY_CC_VERSION = "ruby-#{ENV['VERSION'] || '1.8.6-p287'}"
# grab the major "1.8" or "1.9" part of the version number
MAJOR = RUBY_CC_VERSION.match(/.*-(\d.\d).\d/)[1]
-# Sorry!
-# On some systems (linux) you get i586 targets, on others i386 targets, at
-# present, I only know to search for them.
-compilers = %w(i586-mingw32msvc-gcc i386-mingw32-gcc)
-paths = ENV['PATH'].split(File::PATH_SEPARATOR)
-compiler = compilers.find do |comp|
- paths.find do |path|
- File.exist? File.join(path, comp)
- end
-end
-MINGW_HOST = compiler[0..-5]
+# Use Rake::ExtensionCompiler helpers to find the proper host
+MINGW_HOST = Rake::ExtensionCompiler.mingw_host
# define a location where sources will be stored
directory "#{USER_HOME}/sources/#{RUBY_CC_VERSION}"
@@ -96,7 +94,7 @@ end
task :mingw32 do
unless MINGW_HOST then
warn "You need to install mingw32 cross compile functionality to be able to continue."
- warn "Please refer to your distro documentation about installation."
+ warn "Please refer to your distribution/package manager documentation about installation."
fail
end
end
@@ -113,10 +111,9 @@ end
file "#{USER_HOME}/builds/#{RUBY_CC_VERSION}/Makefile" => ["#{USER_HOME}/builds/#{RUBY_CC_VERSION}",
"#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in"] do |t|
- # set the configure options
options = [
- "--host=#{MINGW_HOST}",
'--target=i386-mingw32',
+ "--host=#{MINGW_HOST}",
'--build=i686-linux',
'--enable-shared',
'--disable-install-doc',
@@ -151,10 +148,10 @@ file "#{USER_HOME}/ruby/#{RUBY_CC_VERSION}/lib/ruby/#{MAJOR}/i386-mingw32/rbconf
file :update_config => ["#{USER_HOME}/ruby/#{RUBY_CC_VERSION}/lib/ruby/#{MAJOR}/i386-mingw32/rbconfig.rb"] do |t|
config_file = "#{USER_HOME}/config.yml"
if File.exist?(config_file) then
- puts "Updating #{t.name}"
+ puts "Updating #{config_file}"
config = YAML.load_file(config_file)
else
- puts "Generating #{t.name}"
+ puts "Generating #{config_file}"
config = {}
end

0 comments on commit 6445242

Please sign in to comment.