Browse files

adding extension tasks

  • Loading branch information...
1 parent 1fa4b60 commit cfda4986bbd29d92232042568f55f38ac0dd25bc @copiousfreetime committed Feb 9, 2013
Showing with 26 additions and 103 deletions.
  1. +26 −103 tasks/extension.rake
View
129 tasks/extension.rake
@@ -1,109 +1,32 @@
-
-# Extensions
-#-----------------------------------------------------------------------
-require 'pathname'
-
-namespace :ext do
- desc "Build the extension(s)"
- task :build => :clobber do
- with_each_extension do |extension|
- path = Pathname.new(extension)
- parts = path.split
- conf = parts.last
- Dir.chdir(path.dirname) do |d|
- ruby conf.to_s
- sh "make"
-
- mkdir_p ext_dest_dir, :verbose => true
- cp "hitimes_ext.#{RbConfig::CONFIG['DLEXT']}", ext_dest_dir, :verbose => true
- end
- end
- end
-
- if RUBY_PLATFORM == "java" then
- desc "Build the jruby extension"
- task :build_java => [ :clobber, "lib/hitimes/hitimes.jar" ]
-
- file "lib/hitimes/hitimes.jar" => FileList["ext/java/src/hitimes/*.java"] do |t|
- jruby_home = RbConfig::CONFIG['prefix']
- jruby_jar = File.join( jruby_home, 'lib', 'jruby.jar' )
-
- mkdir_p 'pkg/classes'
- sh "javac -classpath #{jruby_jar} -d pkg/classes #{t.prerequisites.join(' ')}"
-
- dest_dir = File.dirname(t.name)
- sh "jar cf #{t.name} -C pkg/classes ."
- end
+# To be used if the gem has extensions.
+# If this task set is inclueded then you will need to also have
+#
+# spec.add_development_dependency( 'rake-compiler', '~> 0.8.1' )
+#
+# in your top level rakefile
+require 'rake/extensiontask'
+require 'rake/javaextensiontask'
+
+if RUBY_PLATFORM == "java" then
+
+ Rake::JavaExtensionTask.new( This.name) do |ext|
+ ext.ext_dir = File.join( 'ext', This.name, "java" )
+ ext.lib_dir = File.join( 'lib', This.name )
+ ext.gem_spec = This.java_gemspec
end
- def ext_dest_dir
- version_sub = RUBY_VERSION.sub(/\.\d$/,'')
- This.project_path( 'lib', 'hitimes', version_sub )
- end
-
- def with_each_extension
- This.platform_gemspec.extensions.each do |ext|
- yield ext
- end
- end
-
- def build_win( version = "1.8.7" )
- ext_config = This.platform_gemspec.extensions.frist
- return nil unless ext_config.cross_rbconfig
- rbconfig = ext_config.cross_rbconfig["rbconfig-#{version}"]
- raise ArgumentError, "No cross compiler for version #{version}, we have #{ext_config.cross_rbconfig.keys.join(",")}" unless rbconfig
- with_each_extension do |extension|
- path = Pathname.new(extension)
- rvm = File.expand_path( "~/.rvm/bin/rvm" )
- Dir.chdir(path.dirname) do |d|
- if File.exist?( "Makefile" ) then
- sh "make clean distclean"
- end
- cp "#{rbconfig}", "rbconfig.rb"
- rubylib = ENV['RUBYLIB']
- ENV['RUBYLIB'] = "."
- sh %[#{rvm} #{version} -S extconf.rb]
- ENV['RUBYLIB'] = rubylib
- sh "make"
- end
- end
- end
-
- win_builds = []
- # ext_config.cross_rbconfig.keys.each do |v|
- # s = v.split("-").last
- # desc "Build the extension for windows version #{s}"
- # win_bname = "build_win-#{s}"
- # win_builds << win_bname
- # task win_bname => :clean do
- # build_win( s )
- # end
- # end
+else
- task :clean do
- with_each_extension do |extension|
- path = Pathname.new(extension)
- Dir.chdir(path.dirname) do |d|
- if File.exist?( "Makefile" ) then
- sh "make clean"
- end
- rm_f "rbconfig.rb"
- end
- end
+ Rake::ExtensionTask.new( This.name ) do |ext|
+ ext.ext_dir = File.join( 'ext', This.name, "c" )
+ ext.lib_dir = File.join( 'lib', This.name )
+ ext.gem_spec = This.ruby_gemspec
+
+ ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
+ ext.cross_platform = 'i386-mswin32' # forces the Windows platform instead of the default one
+ # configure options only for cross compile
end
- task :clobber do
- with_each_extension do |extension|
- path = Pathname.new(extension)
- Dir.chdir(path.dirname) do |d|
- if File.exist?( "Makefile" ) then
- sh "make distclean"
- end
- rm_f "rbconfig.rb"
- end
- end
- end
end
-task :clobber => 'ext:clobber'
-task :clean => 'ext:clean'
-task :test => 'ext:build'
+
+task :test_requirements => :compile

0 comments on commit cfda498

Please sign in to comment.