#/usr/bin/env ruby ########################## # FILL-IN THESE SETTINGS # ######################################################################## PROJECT_NAME = "my_project" RDOC_DIR = 'doc/rdoc' RDOC_TITLE = "#{PROJECT_NAME.capitalize} API" RDOC_MAIN = "README" RDOC_FILES = ['A-Z*', 'lib', 'ext'] ######################################################################## # Requirements --------------------------------------------------------- require 'rake/clean' require 'rake/testtask' require 'rake/rdoctask' # Default Tasks --------------------------------------------------------- desc "Default task (compile and test)" task :default => [:compile, :test] # Clean Tasks --------------------------------------------------------- CLEAN.include '**/*.o' CLEAN.include '**/*.so' # Clobber Tasks --------------------------------------------------------- CLOBBER.include 'doc/rdoc' CLOBBER.include '**/*.log' CLOBBER.include '**/Makefile' CLOBBER.include '**/extconf.h' # RDoc Tasks --------------------------------------------------------- desc "Create the RDOC documentation" rd = Rake::RDocTask.new(:doc) do |rdoc| rdoc.rdoc_dir = RDOC_DIR rdoc.title = RDOC_TITLE rdoc.options << '--main' << RDOC_MAIN rdoc.rdoc_files.include(*RDOC_FILES) end # Test Tasks --------------------------------------------------------- Rake::TestTask.new(:test) do |t| t.test_files = FileList[ 'tests/**/test_*.rb', 'tests/**/tc_*.rb', ] t.warning = false t.verbose = true end task :test => :compile # Install Tasks ------------------------------------------------------ desc "Install to local site directory." task :install do cmd = File.glob('{setup.rb,install.rb,task/setup,task/install}').first if cmd system cmd else abort "No install/setup script found." end end # Make tasks ----------------------------------------------------- MAKECMD = ENV['MAKE_CMD'] || 'make' MAKEOPTS = ENV['MAKE_OPTS'] || '' exts = File.glob('ext/*/extconf.rb') dirs = exts.collect{ |e| File.dirname(e) } maks = dirs.collect{ |d| File.join(d, 'Makefile' } unless exts.empty? dirs.each do |dir| file File.join(dir,'Makefile') => File.join(dir,'extconf.rb') do Dir.chdir(dir) do ruby 'extconf.rb' end end end desc "Compile the shared object" task :compile => maks do dirs.each do |dir| m = make(dir) fail "Make failed (status #{m})" unless m == 0 end end #desc "Install to your site_ruby directory" #task :install => :compile do # m = make 'install' # fail "Make install failed (status #{m})" unless m == 0 #end end def make(dir, target = '') Dir.chdir(dir) do pid = fork { exec "#{MAKECMD} #{MAKEOPTS} #{target}" } Process.waitpid pid end $?.exitstatus end =begin # Packaging / Version number tasks ----------------------------------- # Used during release packaging if a REL is supplied task :update_version do unless PKG_VERSION == CURRENT_VERSION pkg_vernum = PKG_VERSION.tr('.','').sub(/^0*/,'') pkg_vernum << '0' until pkg_vernum.length > 2 File.open('ext/xml/libxml.h.new','w+') do |f| maj, min, mic, patch = /(\d+)\.(\d+)(?:\.(\d+))?(?:\.(\d+))?/.match(PKG_VERSION).captures f << File.read('ext/xml/libxml.h'). gsub(/RUBY_LIBXML_VERSION\s+"(\d.+)"/) { "RUBY_LIBXML_VERSION \"#{PKG_VERSION}\"" }. gsub(/RUBY_LIBXML_VERNUM\s+\d+/) { "RUBY_LIBXML_VERNUM #{pkg_vernum}" }. gsub(/RUBY_LIBXML_VER_MAJ\s+\d+/) { "RUBY_LIBXML_VER_MAJ #{maj}" }. gsub(/RUBY_LIBXML_VER_MIN\s+\d+/) { "RUBY_LIBXML_VER_MIN #{min}" }. gsub(/RUBY_LIBXML_VER_MIC\s+\d+/) { "RUBY_LIBXML_VER_MIC #{mic || 0}" }. gsub(/RUBY_LIBXML_VER_PATCH\s+\d+/) { "RUBY_LIBXML_VER_PATCH #{patch || 0}" } end mv('ext/xml/libxml.h.new', 'ext/xml/libxml.h') end end =end