3 require 'rake/gempackagetask'
5 task :default => [:buildext]
7 spec = Gem::Specification.new do |s|
11 A modular ruby IRC bot.
13 s.description = <<-EOF
14 A modular ruby IRC bot specifically designed for ease of extension via plugins.
16 s.requirements << 'Ruby, version 1.8.0 (or newer)'
18 # s.files = Dir.glob("**/*").delete_if { |item| item.include?(".svn") }
19 s.files = FileList['lib/**/*.rb', 'bin/*', 'data/rbot/**/*', 'AUTHORS', 'COPYING', 'README', 'REQUIREMENTS', 'TODO', 'ChangeLog', 'INSTALL', 'Usage_en.txt', 'setup.rb', 'po/*.pot', 'po/**/*.po'].to_a.delete_if {|item| item == ".svn"}
21 s.executables = ['rbot', 'rbot-remote']
22 s.default_executable = 'rbot'
23 s.extensions = 'Rakefile'
25 # s.autorequire = 'rbot/ircbot'
27 s.rdoc_options = ['--exclude', 'post-install.rb',
28 '--title', 'rbot API Documentation', '--main', 'README', 'README']
30 s.author = 'Tom Gilbert'
31 s.email = 'tom@linuxbrit.co.uk'
32 s.homepage = 'http://ruby-rbot.org'
33 s.rubyforge_project = 'rbot'
36 Rake::GemPackageTask.new(spec) do |pkg|
41 # normalize a po/pot file
43 content = File.read(fn)
45 # replace project-id-version placholder
46 modified = content.sub!(/^("Project-Id-Version: )PACKAGE VERSION(\\n")$/) {
50 # sort the messages by file location
52 sorted = `#{MSGCAT} --width=79 --sort-by-file #{fn}`
60 File.open(fn, 'w') {|f| f.write content}
64 PLUGIN_FILES = FileList['data/rbot/plugins/**/*.rb']
65 NON_PLUGIN_FILES = FileList["{lib,bin,data}/**/*.{rb,rhtml}"] - PLUGIN_FILES
67 # this task defines how po files and pot files are made. those rules are not defined
68 # normally because po and pot files should be only updated in the updatepo task,
69 # but po files are also prereqs for makemo
70 task :define_po_rules do
71 # generate pot file from rb files
72 rgettext_proc = proc do |t|
73 require 'gettext/utils'
74 source_files, pot_file = t.prerequisites, t.name
75 new_pot_file = "#{pot_file}.new"
76 puts "#{source_files.join(', ')} => #{pot_file}"
77 GetText.rgettext(source_files, new_pot_file)
79 # only use the new pot file if it contains unique messages
80 if File.exists?(pot_file) && MSGCOMM && `#{MSGCOMM} --unique #{pot_file} #{new_pot_file}`.empty?
83 mv new_pot_file, pot_file
86 normalize_po(pot_file)
88 # save all this work until rb files are updated again
92 # generate pot file for non-plugin files
93 file('po/rbot.pot' => NON_PLUGIN_FILES, &rgettext_proc)
95 # generate pot files for plugin files
96 rule(%r'^po/.+\.pot$' => proc {|fn|
97 PLUGIN_FILES.select {|f| f.pathmap('rbot-%n') == fn.pathmap('%n')}
100 # map the po file to its source pot file
101 pot_for_po = proc {|fn| fn.pathmap '%{^po/.+/,po/}X.pot'}
103 # update po file from pot file
104 msgmerge_proc = proc do |t|
105 require 'gettext/utils'
106 po_file, pot_file = t.name, t.source
107 puts "#{pot_file} => #{po_file}"
108 if File.exists? po_file
109 sh "#{MSGMERGE} --backup=off --update #{po_file} #{pot_file}"
113 normalize_po(po_file)
117 # generate English po files
118 file(%r'^po/en_US/.+\.po$' => pot_for_po) do |t|
119 po_file, pot_file = t.name, t.source
121 sh "#{MSGEN} --output-file=#{po_file} #{pot_file}"
122 normalize_po(po_file)
130 rule(%r'^po/.+/.+\.po$' => pot_for_po, &msgmerge_proc)
134 rule(%r'^data/locale/.+/LC_MESSAGES/.+\.mo$' => proc {|fn|
135 [ fn.pathmap('%{^data/locale,po;LC_MESSAGES/,}X.po'),
136 # the directory is created if not existing
139 po_file, mo_file = t.source, t.name
140 puts "#{po_file} => #{mo_file}"
141 require 'gettext/utils'
142 GetText.rmsgfmt po_file, mo_file
145 task :check_po_tools do
150 :options => %w[--backup= --update],
151 :message => 'Cannot update po files' },
153 :options => %w[--unique],
154 :message => 'Pot files may be modified even without message change' },
156 :options => %w[--output-file],
157 :message => 'English po files will not be generated' },
159 :options => %w[--width= --sort-by-file],
160 :message => 'Pot files will not be normalized' }
163 po_tools.each_pair do |command, value|
164 path = ENV["#{command.upcase}_PATH"] || command
165 have_it = have[command] = value[:options].all? do |option|
166 `#{path} --help`.include? option
168 Object.const_set(command.upcase, have_it ? path : false)
169 warn "#{command} not found. #{value[:message]}" unless have_it
171 abort unless MSGMERGE
174 PLUGIN_BASENAMES = PLUGIN_FILES.map {|f| f.pathmap('%n')}
175 LOCALES = FileList['po/*/'].map {|d| d.pathmap('%n')}
178 directory "data/locale/#{l}/LC_MESSAGES"
181 desc 'Update po files'
182 task :updatepo => [:define_po_rules, :check_po_tools] + LOCALES.map {|l|
183 ["po/#{l}/rbot.po"] +
184 PLUGIN_BASENAMES.map {|n| "po/#{l}/rbot-#{n}.po"}
187 desc 'Normalize po files'
188 task :normalizepo => :check_po_tools do
189 FileList['po/*/*.po'].each {|fn| normalize_po(fn)}
192 # this task invokes makemo if ruby-gettext is available, but otherwise succeeds
193 # with a warning instead of failing. it is to be used by Gem's extension builder
194 # to make installation not fail because of lack of ruby-gettext
197 require 'gettext/utils'
198 Rake::Task[:makemo].invoke
200 warn 'Ruby-gettext cannot be located, so mo files cannot be built and installed'
204 desc 'Generate mo files'
205 task :makemo => LOCALES.map {|l|
206 ["data/locale/#{l}/LC_MESSAGES/rbot.mo"] +
207 PLUGIN_BASENAMES.map {|n| "data/locale/#{l}/LC_MESSAGES/rbot-#{n}.mo"}