$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'fileutils'
require 'ffi'
require 'ffi/platform'
require 'ffi/tools/types_generator'
types_conf = File.expand_path(File.join(FFI::Platform::CONF_DIR, 'types.conf'))

logfile = File.join(File.dirname(__FILE__), 'log')

file types_conf do |task|
  options = {}
  FileUtils.mkdir_p(File.dirname(task.name), { :mode => 0755 })
  File.open(task.name, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
    f.puts FFI::TypesGenerator.generate(options)
  end
  File.open(logfile, 'w') do |log|
    log.puts(types_conf)
  end
end

task :default => types_conf do
end

task :clean do
  File.readlines(logfile).each do |file|
    file.strip!
    rm_f file
  end
  rm_f logfile
end
