# rakefile
#   Copyright 2004-2005 by Kevin Smith
#   released under the MIT-style wxruby2 license

require "rake/rakeutil"
require "rake/rakewx"

#############################
# auto-detected settings that can be
# overridden by platform-specific rake files
$dl_ext = Config::CONFIG["DLEXT"]
$obj_ext = Config::CONFIG["OBJEXT"]
$ruby_cppflags = Config::CONFIG["CFLAGS"]
$ruby_includes = " -I " + $:.join(' -I ')
$ruby_ldflags = Config::CONFIG["LDFLAGS"]
$ruby_libs  = Config::CONFIG["LIBS"]
$extra_cppflags = ""
$extra_ldflags = ""
$extra_objs = ""
$extra_libs = ""
$link_output_flag = "-o "

#############################
# platform-specific
if($macosx) then    require "rake/rakemacosx"
elsif($mswin) then  require "rake/rakemswin"
elsif($mingw) then  require "rake/rakemingw"
elsif($cygwin) then require "rake/rakecygwin"
elsif($bccwin) then require "rake/rakebccwin"
elsif($netbsd) then require "rake/rakenetbsd"
else                require "rake/rakelinux"
end


#############################
# put it all together
$cppflags = [$wx_cppflags, $ruby_cppflags, $extra_cppflags, $ruby_includes].join(' ')
$ldflags = [$wx_ldflags, $ruby_ldflags, $extra_ldflags].join(' ')
$libs = [$wx_libs, $ruby_libs, $extra_libs].join(' ')
$extra_objs = $extra_objs
$dl_lib = "wxruby2.#{$dl_ext}"

#used for :install
$ruby = "#{Config::CONFIG['bindir']}/#{Config::CONFIG['ruby_install_name']}"
$install_prog = "#$ruby -run -e install -- -vpm 0755"
$install_site_dir = "#{Config::CONFIG['sitedir']}/#{Config::CONFIG['MAJOR']}.#{Config::CONFIG['MINOR']}"
$install_lib_dir = "#$install_site_dir/#{Config::CONFIG['sitearch']}"

#############################
# later, support static linking
$target_lib = File.join($dest_dir, $dl_lib)


#############################
# public tasks
begin
    create_internal_non_swig_tasks
    create_internal_swig_tasks
    
    task :default => :link
    task :link => $target_lib
    task :compile => all_obj_files
    task :recompile => [:clean, :compile]
    
    task :clean_src do
        delete_files_in_with_ext($src_dir,"cpp")
		delete_files_in_with_ext($src_dir,"h")
    end
    
    task :clean do
        force_delete($target_lib)
        #force_rmdir($dest_dir)
        delete_files_in($obj_dir)
        #force_rmdir($obj_dir)
    end
    
rescue Exception => e
    puts(e.message)
    puts(e.backtrace.join("\n"))
end
