#
# 'rake' to generate 'opengl_command.rb', etc.
#
require 'rake/clean'
require_relative 'get_gl_xml'
require_relative 'generate_enum'
require_relative 'generate_command'
require_relative 'generate_ext_enum'
require_relative 'generate_ext_command'
require_relative 'generate_es_enum'
require_relative 'generate_es_command'
require_relative 'generate_es_ext_enum'
require_relative 'generate_es_ext_command'

CLEAN.include( FileList['../lib/opengl_enum.rb',
                        '../lib/opengl_command.rb',
                        '../lib/opengl_ext_enum.rb',
                        '../lib/opengl_ext_command.rb',
                        '../lib/opengl_es_enum.rb',
                        '../lib/opengl_es_command.rb',
                        '../lib/opengl_es_ext_enum.rb',
                        '../lib/opengl_es_ext_command.rb'] )


task 'default' => 'wrapper'

task 'wrapper' => ['enum', 'command', 'ext_enum', 'ext_command', 'es_enum', 'es_command', 'es_ext_enum', 'es_ext_command']

task 'enum' => '../lib/opengl_enum.rb'
task 'command' => '../lib/opengl_command.rb'
task 'ext_enum' => '../lib/opengl_ext_enum.rb'
task 'ext_command' => '../lib/opengl_ext_command.rb'
task 'es_enum' => '../lib/opengl_es_enum.rb'
task 'es_command' => '../lib/opengl_es_command.rb'
task 'es_ext_enum' => '../lib/opengl_es_ext_enum.rb'
task 'es_ext_command' => '../lib/opengl_es_ext_command.rb'

file '../lib/opengl_enum.rb' => './gl.xml' do |t|
  open('../lib/opengl_enum.rb', 'wb') do |file|
    GLEnumCodeGenerator.generate_enum(file)
  end
end

file '../lib/opengl_command.rb' => './gl.xml' do |t|
  open('../lib/opengl_command.rb', 'wb') do |file|
    GLCommandCodeGenerator.generate_command(file)
  end
end

file '../lib/opengl_ext_enum.rb' => './gl.xml' do |t|
  open('../lib/opengl_ext_enum.rb', 'wb') do |file|
    GLExtEnumCodeGenerator.generate_enum(file)
  end
end

file '../lib/opengl_ext_command.rb' => './gl.xml' do |t|
  open('../lib/opengl_ext_command.rb', 'wb') do |file|
    GLExtCommandCodeGenerator.generate_command(file)
  end
end

file '../lib/opengl_es_enum.rb' => './gl.xml' do |t|
  open('../lib/opengl_es_enum.rb', 'wb') do |file|
    GLESEnumCodeGenerator.generate_enum(file)
  end
end

file '../lib/opengl_es_command.rb' => './gl.xml' do |t|
  open('../lib/opengl_es_command.rb', 'wb') do |file|
    GLESCommandCodeGenerator.generate_command(file)
  end
end

file '../lib/opengl_es_ext_enum.rb' => './gl.xml' do |t|
  open('../lib/opengl_es_ext_enum.rb', 'wb') do |file|
    GLESExtEnumCodeGenerator.generate_enum(file)
  end
end

file '../lib/opengl_es_ext_command.rb' => './gl.xml' do |t|
  open('../lib/opengl_es_ext_command.rb', 'wb') do |file|
    GLESExtCommandCodeGenerator.generate_command(file)
  end
end

file './gl.xml' do
  get_gl_xml()
end
