require 'rake/testtask' require 'rake/rdoctask' require 'rake/contrib/sshpublisher' require 'rake/gempackagetask' require 'platform' task :default => :build_all OGRE_RB_VERSION = "0.1" ########################### # Project Managment tasks # ########################### RDOC_INCLUDES = %w( README doc_src/**/*.rb lib/application.rb lib/application_frame_listener.rb lib/application_loading_bar.rb lib/constants.rb lib/method_fixes.rb ) RDOC_OPTIONS = ['-S', '-t Ogre.rb Documentation'] Rake::RDocTask.new do |t| t.main = "README" t.rdoc_files.include(RDOC_INCLUDES) t.options += RDOC_OPTIONS end RUBYFORGE_USERNAME = "jameskilton" PROJECT_WEB_PATH = "/var/www/gforge-projects/ogrerb" desc "Update the website" task :upload_web => :rdoc do |t| unless File.directory?("publish") mkdir "publish" mkdir "publish/docs" end sh "svn export --force website publish/" sh "cp -r html/* publish/docs/" Rake::SshDirPublisher.new("#{RUBYFORGE_USERNAME}@rubyforge.org", PROJECT_WEB_PATH, "publish").upload rm_rf "publish" end ## Gem Compilation ## ogre_rb_spec = Gem::Specification.new do |s| s.platform = Gem::Platform::CURRENT lib_files = "" if Platform.windows? lib_files = %w(lib/ogre.dll lib/ruby_ois.dll) elsif Platform.mac? lib_files = %w(lib/ogre.bundle lib/ruby_ois.bundle) else # Posix environment lib_files = %w(lib/ogre.so lib/ruby_ois.so) end s.name = 'ogre.rb' s.version = OGRE_RB_VERSION s.summary = "Ruby wrapper for Ogre 3D" s.description = %q{Ogre.rb is a SWIG wrapper to allow access to the Ogre 3D API from Ruby.} s.author = "Jason Roelofs" s.email = "jameskilton@gmail.com" s.rubyforge_project = 'ogrerb' s.homepage = 'http://ogrerb.rubyforge.org' s.require_path = '.' s.required_ruby_version = '>= 1.8.4' # Inform of the need to have Ogre installed and OGRE_HOME set s.requirements << "Ogre Einhort (1.4)" s.requirements << "Environment variable OGRE_HOME set" #s.has_rdoc = false #s.extra_rdoc_files += RDOC_INCLUDES #s.rdoc_options += RDOC_OPTIONS files = FileList.new %w( README platform.rb ogre.rb Rakefile lib/*.rb samples/**/* doc_src/**/* ) do |fl| fl.exclude(/navi/) end files += lib_files s.files = files end desc 'Package as gem & zip' Rake::GemPackageTask.new(ogre_rb_spec) do |p| p.gem_spec = ogre_rb_spec end ############################# # Project compilation tasks # ############################# desc "Rebuild the OGRE and OIS wrappers. Does not work on Windows." task :build_all => ["ogre:build", "ois:build"] desc "Clean everything" task :clean_all => ["ogre:clean", "ois:clean"] desc "Build rubyw on the mac platform, needed for ogrerb to run properly." task :build_mac_rubyw do if Platform.mac? sh "ruby=`which ruby`; rubyw=${ruby}w; sudo cp $ruby $rubyw; sudo /Developer/Tools/Rez -t APPL Carbon.r -o $rubyw" else puts "This is only to be run on Mac OS X" end end namespace :ois do desc "Rebuild all of the OIS wrapper. Does not work on Windows." task :build => [:swig, :compile] desc "Run swig on the interface files" task :swig do includes = %w(-I./src_headers/OIS -I./src_headers/wrappers) sh "swig -ruby -minherit -c++ -autorename #{includes.join(' ')} -o build/ois/ois_wrap.cpp ois/ois.i" if Platform.windows? insert_headers("build/ois/ois_wrap.cpp") do <<-EOF #include "OIS.h" EOF end end end desc "Compile the extension and move the resulting library into lib/" task :compile do resulting_file = "ruby_ois.so" build_file = resulting_file cd "build/ois" do ruby "extconf.rb" if Platform.linux? sh "make all" elsif Platform.windows? sh "nmake" # Create our manifest (see http://www.codeproject.com/cpp/vcredists_x86.asp) sh "mt.exe /manifest #{resulting_file}.manifest /outputresource:#{resulting_file};#2" resulting_file = "ruby_ois.dll" build_file = "ruby_ois.so" elsif Platform.mac? sh "make all" resulting_file = "ruby_ois.bundle" build_file = "ruby_ois.bundle" else raise "Error: Unsupported platform " + PLATFORM end cp build_file, File.join("..", "..", "lib", resulting_file) end end desc "Clean up the build environment" task :clean do cd "build/ois" do ruby "extconf.rb" sh "make clean" rm "mkmf.log" rescue nil end end end namespace :ogre do desc "Rebuild all of ogre.rb. Does not work on Windows." task :build => [:swig, :compile] desc "Run swig on the interface files" task :swig do includes = %w(-I./src_headers/OGRE -I./src_headers/ExampleApplication -I./src_headers/wrappers -I./src_headers/OIS) sh "swig -ruby -minherit -c++ -autorename #{includes.join(' ')} -o build/ogre/ogre_rb_wrap.cpp ogre/ogre_rb.i" if Platform.windows? # compensate for windows stl. Uses wrong version when ruby is first. insert_headers("build/ogre/ogre_rb_wrap.cpp") do <<-EOF #include "Ogre.h" #{Platform.windows? ? "#include " : ""} EOF end end end desc "Compile the extension and move the resulting library into lib/" task :compile do resulting_file = "ogre.so" build_file = resulting_file cd "build/ogre" do ruby "extconf.rb" if Platform.linux? sh "make clean all" elsif Platform.windows? sh "nmake" # Create our manifest (see http://www.codeproject.com/cpp/vcredists_x86.asp) sh "mt.exe /manifest ogre.so.manifest /outputresource:ogre.so;#2" resulting_file = "ogre.dll" elsif Platform.mac? sh "make clean all" resulting_file = "ogre.bundle" build_file = "ogre.bundle" else raise "Error: Unsupported platform " + PLATFORM end cp build_file, File.join("..", "..", "lib", resulting_file) end end desc "Clean up the build environment" task :clean do cd "build/ogre" do ruby "extconf.rb" sh "make clean" rm "mkmf.log" rescue nil end end desc "Copy over the ogre header files from an ogre installation. Expects OGRE_HOME to be set." task :update_headers do raise "Unable to find Ogre headers, please set OGRE_HOME to the distribution path" if ENV['OGRE_HOME'].nil? File.cp_r "#{ENV['OGRE_HOME']}/include/OGRE/", "#{File.dirname(__FILE__)}/src_headers" end desc "Create default interface files for each of the ogre headers" task :create_interfaces do headers_match = File.join("src_headers", "OGRE", "Ogre*.h") ogre_headers = Dir[headers_match] ogre_headers.each do |header| filename = File.basename(header, ".h") interface_file_name = File.join("ogre", File.basename(header, ".h") + ".i") raise "Interface file for #{filename} already exists" if File.exists?(interface_file_name) File.open(interface_file_name, "w+") do |file| file.write < [:swig, :compile] desc "Run swig on the interface files" task :swig do includes = %w(-I./src_headers/navi -I./src_headers/wrappers) sh "swig -autorename -ruby -minherit -c++ #{includes.join(' ')} -o build/navi/navi_rb_wrap.cpp navi/navi_rb.i" if Platform.windows? # compensate for windows stl. Uses wrong version when ruby is first. insert_headers("build/navi/navi_rb_wrap.cpp") do <<-EOF #include "Ogre.h" #{Platform.windows? ? "#include " : ""} EOF end end end desc "Compile the extension and move the resulting library into lib/" task :compile do resulting_file = "navi.dll" cd "build/navi" do ruby "extconf.rb" if Platform.windows? sh "nmake" # Create our manifest (see http://www.codeproject.com/cpp/vcredists_x86.asp) sh "mt.exe /manifest navi.so.manifest /outputresource:navi.so;#2" else raise "Error: Unsupported platform " + PLATFORM end cp "navi.so", File.join("..", "..", "lib", resulting_file) end end desc "Clean up the build environment" task :clean do cd "build" do ruby "extconf.rb" sh "make clean" rm "mkmf.log" rescue nil end end end