2 require 'rake/testtask'
3 require 'rake/rdoctask'
4 require 'rake/gempackagetask'
8 desc "Remove build products"
10 rm Dir.glob( "lib/**/*.jar" )
11 rm Dir.glob( "lib/**/*.#{ Config::CONFIG['DLEXT'] }" )
12 rm Dir.glob( "ext/**/Makefile" )
13 rm Dir.glob( "ext/**/*.{o,#{ Config::CONFIG['DLEXT'] }}" )
14 rm Dir.glob( "ext/**/mkmf.log" )
15 rm Dir.glob( "java/**/*.{class,jar}" )
18 Rake::RDocTask.new do |task|
19 task.rdoc_files.add [ 'README', 'LICENSE', 'lib/**/*.rb', 'stubs/**/*.rb' ]
22 task :clobber => [ :clean ]
24 def setup_extension( dir, lib_dir, extension )
25 ext = File.join( "ext", dir )
26 so_name = "#{ extension }.#{ Config::CONFIG['DLEXT'] }"
27 ext_so = File.join( ext, so_name )
28 lib_so = File.join( "lib", lib_dir, so_name )
29 ext_files = FileList[ File.join( ext, "*.{c,h}" ) ]
30 ext_makefile = File.join( ext, "Makefile" )
31 extconf_rb = File.join( ext, "extconf.rb" )
33 file ext_makefile => [ extconf_rb ] do
39 file ext_so => ext_files + [ ext_makefile ] do
50 file lib_so => [ ext_so ] do
54 task :compile => [ lib_so ]
57 def setup_jar( dir, lib_dir, extension )
58 ext = File.join( "java", dir )
59 jar_name = "#{ extension }.jar"
60 ext_jar = File.join( ext, lib_dir, jar_name )
61 lib_jar = File.join( "lib", lib_dir, jar_name )
62 ext_files = FileList[ File.join( ext, "**", "*.java" ) ]
63 main_source = File.join( lib_dir, "#{ extension.capitalize }Service.java" )
65 file ext_jar => [ ext_files ] do
67 sh 'javac', '-classpath', File.join( ENV['JRUBY_HOME'], 'lib/jruby.jar' ), main_source
68 sh 'jar', 'cf', File.join( lib_dir, jar_name ), *Dir.glob( '**/*.class' )
72 file lib_jar => ext_jar do
76 task :compile => [ lib_jar ]
81 setup_jar( 'timebase_ext', '', 'timebase_ext' )
83 setup_extension( 'timebase_ext', '', 'timebase_ext' )
86 desc "Compile extensions"
89 task :test => [ :compile ]
90 Rake::TestTask.new do |task|
91 task.ruby_opts << '-rrubygems'
94 task.test_files = [ "test/test_all.rb" ]
98 desc "Loads the library into IRB"
99 task :console => [ :compile ] do
100 sh "irb -Ilib -rirb/completion -rtimebase"
103 gemspec = Gem::Specification.new do |gemspec|
104 gemspec.name = "timebase"
105 gemspec.version = GEM_VERSION
106 gemspec.author = "Jonas Pfenniger <zimbatm@oree.ch>"
107 gemspec.summary = "Provides access to low-level system clocks"
108 gemspec.test_file = 'test/test_all.rb'
109 gemspec.files = FileList[ 'Rakefile', 'test/*.rb', 'ext/**/*.{c,h,rb}',
110 'stubs/**/*.rb', 'java/**/*.java',
111 "lib/**/*.{rb,jar,#{ Config::CONFIG['DLEXT'] }}" ]
112 gemspec.require_paths = [ 'lib' ]
113 gemspec.has_rdoc = true
114 gemspec.extra_rdoc_files = FileList[ 'stubs/**/*.rb' ]
118 gemspec.platform = 'jruby'
120 gemspec.platform = Gem::Platform::WIN32
122 gemspec.platform = Gem::Platform::RUBY
123 gemspec.extensions = FileList[ 'ext/**/extconf.rb' ]
127 task :package => [ :clean, :test ]
128 Rake::GemPackageTask.new( gemspec ) do |task|
129 task.gem_spec = gemspec
133 task :default => [ :clean, :test ]