# -*- ruby -*-

$LOAD_PATH << 'lib'
require 'hdw' # for Version

require 'find'

task :default => [:all]

task :all do
  `exerb.bat hdw.exy`
  `exerb.bat hdw_edit.exy`
end

task :clean do
  rm_f 'hdw.exe'
  rm_f 'hdw_edit.exe'
end

task :dist => [:clean] do
  dist_dir = '../hdw-' + Version
  rm_rf dist_dir
  mkdir dist_dir

  cp_r Dir.glob('*'), dist_dir

  removes = []
  Find.find(dist_dir) do |file|
    removes.push file if file =~ /\/tmp/
    removes.push file if file =~ /\/200/
    removes.push file if file =~ /\/CVS\z/
    removes.push file if file =~ /\/touch\.txt\z/
    removes.push file if file =~ /\/hdw\.conf\z/
    removes.push file if file =~ /\/.*~\z/
  end
  rm_rf removes
  puts `tar -C .. -zcvf #{dist_dir}.tar.gz #{File.basename dist_dir}`
end

task :dist_win32 => [:all] do
  dist_dir = '../hdw_win32-' + Version
  rm_rf dist_dir
  mkdir dist_dir

  ['hdw.exe',
   'hdw_edit.exe',
   'README.txt',
   'README_win.txt'].each do |src|
    cp src, dist_dir
  end

  cp 'hdw.conf.orig', dist_dir
end
