require 'rubygems' Gem::manage_gems require 'rake/gempackagetask' require 'rake/clean' require 'rake/rdoctask' NAME = 'libnet4r' VERS = '0.1' GEM_NAME = "#{NAME}-#{VERS}.gem" RDOC_MAIN = "README" libnet_files = Dir.glob("libnet/**/*") - Dir.glob("libnet/**/*.o") - ["libnet/src/libnet.a"] spec = Gem::Specification.new do |s| s.name = NAME s.version = VERS s.author = "Corey Burrows" s.email = "corey.burrows@gmail.com" s.platform = Gem::Platform::RUBY s.summary = "Packet builder and injection library." s.files = %w{README CHANGELOG LICENSE Rakefile} + Dir.glob("ext/**/*.{h,c}") + Dir.glob("lib/**/*.{rb}") + Dir.glob("test/**/*.rb") + Dir.glob("libnet/**/*") s.require_path = "lib" s.extensions = ["ext/extconf.rb"] #s.test_file = "test/test_libnet.rb" s.has_rdoc = true s.extra_rdoc_files = [RDOC_MAIN, "CHANGELOG", "LICENSE"] s.add_dependency('activesupport') end Rake::GemPackageTask.new(spec) do |pkg| pkg.need_tar = true end Rake::RDocTask.new do |rd| rd.main = RDOC_MAIN rd.rdoc_files.include(RDOC_MAIN, "CHANGELOG", "LICENSE", "lib/**/*.rb", "ext/**/*.c") rd.options << "--all" end CLEAN.include FileList[ "libnet/**/*.o", "libnet/**/*.a", "lib/**/*.o", "lib/**/*.so", "lib/**/*.bundle", "lib/mkmf.log", "lib/Makefile", "ext/Makefile", "pkg/*.gem", "html/", ] task :realclean => :clean do if File.exists?('libnet/Makefile') Dir.chdir('libnet') sh('make distclean') end end task :build do Dir.chdir('lib') case RUBY_PLATFORM when /darwin/ sh('ARCHFLAGS="-arch ppc" ruby ../ext/extconf.rb') else sh('ruby ../ext/extconf.rb') end sh('make') Dir.chdir('..') end task :test do puts "********************************" puts "running tests as regular user..." puts "********************************" sh("ruby -rrubygems test/ts_all.rb") puts "********************************" puts "running tests as root user..." puts "********************************" sh("sudo ruby -rrubygems test/ts_all.rb") end task :gem do sh %{rake pkg/#{GEM_NAME}} end task :install => :gem do case RUBY_PLATFORM when /^sparc/ sh %{sudo gem install pkg/#{GEM_NAME} -- --with-libnet-dir=/usr/local} when /darwin/ sh %{sudo env ARCHFLAGS="-arch ppc" gem install pkg/#{GEM_NAME} -- --with-libnet-dir=/sw} else sh %{sudo gem install pkg/#{GEM_NAME}} end end task :uninstall do sh %{sudo gem uninstall #{NAME}} end task :default => :build