require 'rake'
require 'rake/clean'
require 'rake/testtask'

desc "Clean the build files from the pathname2 source"
task :clean do
   Dir.chdir('ext') do
      if RUBY_PLATFORM.match('mswin')
         sh 'nmake distclean' if File.exists?('pathname2.so')
      else
         sh 'make distclean' if File.exists?('pathname2.so')
      end
   end
end

desc "Build the pathname2 package on UNIX systems (but don't install it)"
task :build => [:clean] do
   Dir.chdir('ext') do
      ruby 'extconf.rb'
      if RUBY_PLATFORM.match('mswin')
         sh 'nmake'
      else
         sh 'make'
      end
   end
end

desc "Install the pure Ruby version of the pathname2 package"
task :install do
   cp 'lib/pathname2.rb', Config::CONFIG['sitelibdir']
end

desc "Install the C version of the pathname2 package"
task :install_c => [:build] do
   Dir.chdir('ext') do
      if RUBY_PLATFORM.match('mswin')
         sh 'nmake install'
      else
         sh 'make install'
      end
   end
end

desc "Run the test suite for the pure Ruby version"
Rake::TestTask.new('test') do |t|
   t.libs << 'lib'
   if RUBY_PLATFORM.match('mswin')
      t.test_files = FileList['test/tc_pathname_win.rb']
   else
      t.test_files = FileList['test/tc_pathname.rb']
   end
end

desc "Run the test suite for the C version."
Rake::TestTask.new('test_c') do |t|
   task :test_c => :build
   t.libs << 'ext'
   t.libs.delete('lib')
   if RUBY_PLATFORM.match('mswin')
      t.test_files = FileList['test/tc_pathname_win.rb']
   else
      t.test_files = FileList['test/tc_pathname.rb']
   end
end

desc "Run the benchmark suite for the pure Ruby version"
task :benchmark do
   sh 'ruby -Ilib examples/bench_pathname.rb'
end

desc "Run the benchmark suite for the C version"
task :benchmark_c => [:build] do
   sh 'ruby -Iext examples/bench_pathname.rb c'
end
