2010-08-11 15:40:55 +00:00
|
|
|
gem 'rake-compiler', '~> 0.7.1'
|
|
|
|
require "rake/extensiontask"
|
|
|
|
|
2010-09-26 20:09:25 +00:00
|
|
|
MYSQL_VERSION = "5.1.51"
|
|
|
|
MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.he.net/"
|
2010-09-09 14:35:31 +00:00
|
|
|
|
|
|
|
def gemspec
|
|
|
|
@clean_gemspec ||= eval(File.read(File.expand_path('../../mysql2.gemspec', __FILE__)))
|
|
|
|
end
|
|
|
|
|
|
|
|
Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
|
2010-08-11 15:40:55 +00:00
|
|
|
# reference where the vendored MySQL got extracted
|
|
|
|
mysql_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-#{MYSQL_VERSION}-win32"))
|
|
|
|
|
2010-09-26 20:25:23 +00:00
|
|
|
# DRY options feed into compile or cross-compile process
|
|
|
|
windows_options = [
|
|
|
|
"--with-mysql-include=#{mysql_lib}/include",
|
|
|
|
"--with-mysql-lib=#{mysql_lib}/lib/opt"
|
|
|
|
]
|
|
|
|
|
2010-08-11 15:40:55 +00:00
|
|
|
# automatically add build options to avoid need of manual input
|
|
|
|
if RUBY_PLATFORM =~ /mswin|mingw/ then
|
2010-09-26 20:25:23 +00:00
|
|
|
ext.config_options = windows_options
|
2010-09-09 14:35:31 +00:00
|
|
|
else
|
|
|
|
ext.cross_compile = true
|
|
|
|
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
|
2010-09-26 20:25:23 +00:00
|
|
|
ext.cross_config_options = windows_options
|
2010-09-26 20:14:52 +00:00
|
|
|
|
|
|
|
# inject 1.8/1.9 pure-ruby entry point when cross compiling only
|
|
|
|
ext.cross_compiling do |spec|
|
|
|
|
spec.files << 'lib/mysql2/mysql2.rb'
|
|
|
|
end
|
2010-08-11 15:40:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
ext.lib_dir = File.join 'lib', 'mysql2'
|
2010-08-22 01:38:21 +00:00
|
|
|
|
|
|
|
# clean compiled extension
|
|
|
|
CLEAN.include "#{ext.lib_dir}/*.#{RbConfig::CONFIG['DLEXT']}"
|
2010-08-11 15:40:55 +00:00
|
|
|
end
|
|
|
|
Rake::Task[:spec].prerequisites << :compile
|
2010-09-18 20:36:39 +00:00
|
|
|
|
2010-09-26 20:14:52 +00:00
|
|
|
file 'lib/mysql2/mysql2.rb' do |t|
|
2010-09-18 20:36:39 +00:00
|
|
|
name = gemspec.name
|
2010-09-26 20:14:52 +00:00
|
|
|
File.open(t.name, 'wb') do |f|
|
2010-09-18 20:36:39 +00:00
|
|
|
f.write <<-eoruby
|
2010-09-26 20:14:52 +00:00
|
|
|
RUBY_VERSION =~ /(\\d+.\\d+)/
|
|
|
|
require "#{name}/\#{$1}/#{name}"
|
2010-09-18 20:36:39 +00:00
|
|
|
eoruby
|
|
|
|
end
|
|
|
|
end
|
2010-09-19 06:50:05 +00:00
|
|
|
|
|
|
|
if Rake::Task.task_defined?(:cross)
|
|
|
|
Rake::Task[:cross].prerequisites << "lib/mysql2/mysql2.rb"
|
|
|
|
end
|