Prefer rb_funcall2() over rb_funcall().
[ruby-vorbistagger.git] / Rakefile
index 4cb775c19318cbf5f44484bb9624e9c448bce5dd..7a34bbb60dbcaecde22a8cda90b0733a87c3302a 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -9,13 +9,30 @@ require "rake/configuretask"
 require "rake/gcc4test"
 require "rake/extensiontask"
 
+begin
+       require "rubygems"
+       require "rake/gempackagetask"
+rescue LoadError
+end
+
 PKG_NAME = "ruby-vorbistagger"
 PKG_VERSION = File.read("lib/ogg/vorbis/tagger.rb").
               match(/^\s*VERSION = \"(.*)\"$/).captures.first
+PKG_FILES = FileList[
+       "AUTHORS", "COPYING", "README", "Rakefile",
+       "gemspec.rb",
+       "rake/configuretask.rb", "rake/extensiontask.rb",
+       "rake/gcc4test.rb",
+       "ext/comments.c", "ext/comments.h", "ext/ext.c",
+       "ext/vcedit.c", "ext/vcedit.h",
+       "lib/ogg/vorbis/tagger.rb",
+       "test/test_main.rb"
+]
 
 ext_objs = [:ext, :comments, :vcedit]
 
 task :default => [:ext]
+task :extension => [:install, :clobber]
 
 config = Rake::ConfigureTask.new do |t|
        t.tests << Rake::ConfigureTask::
@@ -55,35 +72,59 @@ end
 task :install => [:ext] do |t|
        destdir = ENV["DESTDIR"] || ""
 
-       ddir = destdir + Config::CONFIG["sitearchdir"]
-       FileUtils::Verbose.mkdir_p(ddir) unless File.directory?(ddir)
-       FileUtils::Verbose.install(ext.lib_name, ddir, :mode => 0755)
+       tmp = ENV["RUBYARCHDIR"] || Config::CONFIG["sitearchdir"]
+       ddir = File.join(destdir, tmp)
+
+       unless File.expand_path(ext.lib_name) ==
+              File.join(ddir, File.basename(ext.lib_name))
+               FileUtils::Verbose.mkdir_p(ddir) unless File.directory?(ddir)
+               FileUtils::Verbose.install(ext.lib_name, ddir, :mode => 0755)
+       end
+
+       tmp = ENV["RUBYLIBDIR"] || Config::CONFIG["sitelibdir"]
+       ddir = File.join(destdir, tmp)
+
+       PKG_FILES.each do |file|
+               next unless file.pathmap("%1d") == "lib"
+
+               dest_file = file.pathmap("%{^lib,#{ddir}}p")
+
+               next if File.expand_path(file) == dest_file
 
-       ddir = destdir + Config::CONFIG["sitelibdir"] + "ogg/vorbis"
-       FileUtils::Verbose.mkdir_p(ddir) unless File.directory?(ddir)
-       FileUtils::Verbose.install("lib/**/*.rb", ddir, :mode => 0644)
+               FileUtils::Verbose.mkdir_p(File.dirname(dest_file))
+               FileUtils::Verbose.install(file, dest_file, :mode => 0644)
+       end
 end
 
 task :test => [:ext]
 
-Rake::TestTask.new do |t|
-       t.libs = ["lib", "ext", "test"]
-       t.test_files = FileList["test/test_*.rb"]
+test = Rake::TestTask.new do |t|
+       t.libs = ["lib", "ext"]
        t.warning = true
 end
 
-Rake::RDocTask.new do |t|
+rdoc = Rake::RDocTask.new do |t|
        t.rdoc_dir = "doc"
        t.title = PKG_NAME
        t.options = ["--line-numbers", "--inline-source", "--main", "README"]
-       t.rdoc_files.include("README", "COPYING", "AUTHORS",
-                            "ext/ext.c", "ext/comments.c", "lib/**/*.rb")
+       t.rdoc_files = FileList[
+               "README", "COPYING", "AUTHORS",
+               "ext/ext.c", "ext/comments.c", "lib/ogg/vorbis/tagger.rb"
+       ]
 end
 
-Rake::PackageTask.new(PKG_NAME, PKG_VERSION) do |t|
-       t.need_tar_gz = true
-       t.package_files.include("[A-Z]*", "rake/*rb", "ext/*.[ch]",
-                               "lib/**/*.rb", "test/*.rb")
+if defined?(Gem)
+       s = Gem::Specification.new
+       eval(File.read("gemspec.rb"))
+
+       Rake::GemPackageTask.new(s) do |t|
+               t.need_tar_gz = true
+       end
+else
+       Rake::PackageTask.new(PKG_NAME, PKG_VERSION) do |t|
+               t.need_tar_gz = true
+               t.package_files = PKG_FILES
+       end
 end
 
 task :publish => [:rdoc, :package] do
@@ -91,9 +132,13 @@ task :publish => [:rdoc, :package] do
        p.add(Rake::SshFreshDirPublisher.new("code-monkey.de",
                                             "public_docs/" +
                                             PKG_NAME, "doc"))
-       p.add(Rake::SshFilePublisher.new("code-monkey.de",
-                                        ".", "pkg",
-                                        "#{PKG_NAME}-#{PKG_VERSION}.tar.gz"))
+
+       files = ["tar.gz"]
+       files << "gem" if defined?(Gem)
+
+       files.map! { |f| "#{PKG_NAME}-#{PKG_VERSION}.#{f}" }
+
+       p.add(Rake::SshFilePublisher.new("code-monkey.de", ".", "pkg", *files))
        p.upload
 end