begin
  require 'debian/xftools_conf.rb'
rescue LoadError
end
require 'ftools'
require 'rbconfig'
require 'mkmf'

class << File
  def __translate_path(path)
    path = path.sub(/^#{Regexp.quote(Config::CONFIG['sitedir'])}/,
		    File.join(Config::CONFIG['libdir'], 'ruby'))
    if defined?(XFtools) &&
	defined?(XFtools::DEST_DIR) &&
	! path.index(XFtools::DEST_DIR)
      path = File.join(XFtools::DEST_DIR, path)
    end
    path
  end
  private :__translate_path

  alias real_makedirs makedirs
  undef makedirs
  undef mkpath
  def makedirs(*dirs)
    dirs = dirs.collect do |x|
      if x.is_a?(String)
	x = __translate_path(x)
      end
      x
    end

    real_makedirs(*dirs)
  end
  alias mkpath makedirs

  alias real_install install
  undef install
  def install(from, to, mode = nil, verbose = false)
    to = __translate_path(to)
    real_install(from, to, mode, verbose)
  end
end
