Initial commit.
[ruby-discid.git] / Rakefile
1 require "rake/clean"
2 require "rake/testtask"
3 require "spec/rake/spectask"
4 require "rake/rdoctask"
5 require "rake/packagetask"
6 require "rake/contrib/compositepublisher"
7 require "rake/contrib/sshpublisher"
8
9 require "rake/configuretask"
10 require "rake/extensiontask"
11
12 PKG_NAME = "ruby-discid"
13 PKG_VERSION = File.read("lib/discid.rb").
14               match(/^\s*VERSION = \"(.*)\"$/).captures.first
15 PKG_FILES = FileList[
16         "AUTHORS", "COPYING", "README", "Rakefile",
17         "rake/configuretask.rb", "rake/extensiontask.rb",
18         "ext/ext.c", "lib/discid.rb"
19 ]
20
21 ext_objs = [:ext]
22
23 task :default => [:ext]
24 task :extension => [:install, :clobber]
25
26 config = Rake::ConfigureTask.new do |t|
27         t.tests << Rake::ConfigureTask::
28                    PkgConfigTest.new("libdiscid", :is_critical => true)
29 end
30
31 task :ext => [:pre_ext]
32
33 ext = Rake::ExtensionTask.new :ext => ext_objs do |t|
34         t.dir = "ext"
35         t.lib_name = "#{t.dir}/discid_ext.so"
36 end
37
38 task :pre_ext => [:configure] do
39         ext.link_libs << config.libdiscid.libs
40
41         cflags = [
42                 ext.env[:cflags],
43                 config.libdiscid.cflags
44         ]
45
46         ext.env.update(:cflags => cflags)
47 end
48
49 task :install => [:ext] do |t|
50         destdir = ENV["DESTDIR"] || ""
51
52         tmp = ENV["RUBYARCHDIR"] || Config::CONFIG["sitearchdir"]
53         ddir = File.join(destdir, tmp)
54
55         unless File.expand_path(ext.lib_name) ==
56                File.join(ddir, File.basename(ext.lib_name))
57                 FileUtils::Verbose.mkdir_p(ddir) unless File.directory?(ddir)
58                 FileUtils::Verbose.install(ext.lib_name, ddir, :mode => 0755)
59         end
60
61         tmp = ENV["RUBYLIBDIR"] || Config::CONFIG["sitelibdir"]
62         ddir = File.join(destdir, tmp)
63
64         PKG_FILES.each do |file|
65                 next unless file.pathmap("%1d") == "lib"
66
67                 dest_file = file.pathmap("%{^lib,#{ddir}}p")
68
69                 next if File.expand_path(file) == dest_file
70
71                 FileUtils::Verbose.mkdir_p(File.dirname(dest_file))
72                 FileUtils::Verbose.install(file, dest_file, :mode => 0644)
73         end
74 end
75
76 task :test => [:ext]
77
78 test = Rake::TestTask.new do |t|
79         t.libs = ["lib", "ext"]
80         t.warning = true
81 end
82
83 rdoc = Rake::RDocTask.new do |t|
84         t.rdoc_dir = "doc"
85         t.title = PKG_NAME
86         t.options = ["--line-numbers", "--inline-source", "--main", "README"]
87         t.rdoc_files = FileList[
88                 "README", "COPYING", "AUTHORS",
89                 "ext/ext.c", "lib/discid.rb"
90         ]
91 end
92
93 Rake::PackageTask.new(PKG_NAME, PKG_VERSION) do |t|
94         t.need_tar_gz = true
95         t.package_files = PKG_FILES
96 end
97
98 task :publish => [:rdoc, :package] do
99         p = Rake::CompositePublisher.new
100         p.add(Rake::SshFreshDirPublisher.new("code-monkey.de",
101                                              "public_docs/" +
102                                              PKG_NAME, "doc"))
103
104         p.add(Rake::SshFilePublisher.new("code-monkey.de",
105                                          ".", "pkg",
106                                          "#{PKG_NAME}-#{PKG_VERSION}.tar.gz"))
107         p.upload
108 end
109