# Ruby Treasures 0.1
# Copyright (C) 2001 Paul Brannan <paul@atdesk.com>
# 
# You may distribute this software under the same terms as Ruby (see the file
# COPYING that was distributed with this library).
# 
# Run this Ruby script to prepare the RubyTreasures distribution for
# publication.

require 'find'
require 'ftools'

system("ruby extconf.rb --norecurse")
system("make docs")
puts "Removing Makefile"
File.rm_f('Makefile')

license = IO.readlines('LICENSE')

ruby_license_comment = license.map { |i| i.sub(/^/, '# ') }
c_license_comment = ["/*\n"] + license.map { |i| i.sub(/^/, ' * ') } + [" */\n"]

Find.find('.') do |file|
  case file
    when /\.rb$/
      puts "Adding license to #{file}"
      lines = ruby_license_comment + IO.readlines(file)
      File.open(file, 'w') do |out|
        lines.each do |line|
          out.puts line
        end
      end
    when /\.c$/
      puts "Adding license to #{file}"
      lines = c_license_comment + IO.readlines(file)
      File.open(file, 'w') do |out|
        lines.each do |line|
          out.puts line
        end
      end
  end
end

