From 1b38f9548d64cd86eb4626797f55ef2955844a57 Mon Sep 17 00:00:00 2001 From: Luis Lavena Date: Sun, 26 Dec 2010 20:47:54 -0300 Subject: [PATCH] Leverage on rake-compiler for extension compilation Rely on rake-compiler instead of handmade tasks to improve portability and standardization. This will allow in the future rely on the cross-compilation functionality of rake-compiler to generate native gems for other platforms (e.g. Windows) --- .gitignore | 1 + Rakefile | 41 +++++------------------------------------ 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 1860cc7..9d13633 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ tmtags coverage rdoc pkg +tmp ## RUBINIUS *.rbc diff --git a/Rakefile b/Rakefile index 9f64978..e795f79 100644 --- a/Rakefile +++ b/Rakefile @@ -13,6 +13,7 @@ begin gem.authors = ["Tony Arcieri"] gem.add_dependency "iobuffer", ">= 0.1.3" gem.add_development_dependency "rspec", ">= 2.1.0" + gem.add_development_dependency "rake-compiler", "~> 0.7.5" gem.extensions = FileList["ext/**/extconf.rb"].to_a # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings @@ -47,42 +48,14 @@ Rake::RDocTask.new do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end -def make(makedir) - Dir.chdir(makedir) { sh 'make' } +require 'rake/extensiontask' +Rake::ExtensionTask.new('http11_client') do |ext| end -def extconf(dir) - Dir.chdir(dir) { ruby "extconf.rb" } +Rake::ExtensionTask.new('cool.io_ext') do |ext| + ext.ext_dir = 'ext/cool.io' end -def setup_extension(dir, extension) - ext = "ext/#{dir}" - ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}" - ext_files = FileList[ - "#{ext}/*.c", - "#{ext}/*.h", - "#{ext}/extconf.rb", - "#{ext}/Makefile", - ] - - desc "Builds just the #{extension} extension" - task extension.to_sym => ["#{ext}/Makefile", ext_so ] - - file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do - extconf "#{ext}" - end - - file ext_so => ext_files do - make "#{ext}" - cp ext_so, "lib" - end -end - -setup_extension("cool.io", "cool.io_ext") -setup_extension("http11_client", "http11_client") - -task :compile => %w(cool.io_ext http11_client) - # Rebuild parser Ragel task :http11_parser do Dir.chdir "ext/http11_client" do @@ -92,7 +65,3 @@ task :http11_parser do raise "Failed to build C source" unless File.exist? target end end - -CLEAN.include ["build/*", "**/*.o", "**/*.so", "**/*.a", "**/*.log", "pkg"] -CLEAN.include ["ext/**/Makefile", "lib/cool.io_ext.*", "lib/http11_client.*"] -CLEAN.include ["ext/**/*.#{Config::CONFIG["DLEXT"]}"]