require 'rbconfig'

ZKRB_WRAPPER = %w[zkrb_wrapper.c zkrb_wrapper.h]

namespace :zkrb do
  task :clean do
    if File.exist?('Makefile')
      sh 'make clean'
      FileUtils.rm('Makefile') # yep, regenerate this
    else
      $stderr.puts "nothing to clean, no Makefile"
    end
  end

  task :clobber => :clean do
    rm_rf %w[Makefile c lib bin include ._c] + ZKRB_WRAPPER
  end
end

task :clean    => 'zkrb:clean'
task :clobber  => 'zkrb:clobber'
task :wrappers => ZKRB_WRAPPER
task :default  => :build

file 'zkrb_wrapper.c' => 'generate_gvl_code.rb' do
  sh "ruby generate_gvl_code.rb code"
end

file 'zkrb_wrapper.h' => 'generate_gvl_code.rb' do
  sh "ruby generate_gvl_code.rb headers"
end

file 'Makefile' do
  sh "ruby extconf.rb"
end

task :build => [ 'Makefile', :wrappers ] do
  sh 'make'
end


