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)'
37 s.executables = ['rbot', 'rbot-remote']
38 s.default_executable = 'rbot'
39 s.extensions = 'Rakefile'
41 # s.autorequire = 'rbot/ircbot'
43 s.rdoc_options = ['--exclude', 'post-install.rb',
44 '--title', 'rbot API Documentation', '--main', 'README', 'README']
46 s.author = 'Tom Gilbert'
47 s.email = 'tom@linuxbrit.co.uk'
48 s.homepage = 'http://ruby-rbot.org'
49 s.rubyforge_project = 'rbot'
52 Rake::GemPackageTask.new(spec) do |pkg|
57 # normalize a po/pot file
59 content = File.read(fn)
61 # sort the messages by file location
63 sorted = `#{MSGCAT} --width=79 --sort-by-file #{fn}`
70 # replace project-id-version placholder
71 modified |= content.sub!(/^("Project-Id-Version: )PACKAGE VERSION(\\n")$/) {
76 File.open(fn, 'w') {|f| f.write content}
80 PLUGIN_FILES = FileList['data/rbot/plugins/**/*.rb']
81 NON_PLUGIN_FILES = FileList["{lib,bin,data}/**/*.{rb,rhtml}"] - PLUGIN_FILES
83 # this task defines how po files and pot files are made. those rules are not defined
84 # normally because po and pot files should be only updated in the updatepo task,
85 # but po files are also prereqs for makemo
86 task :define_po_rules do
87 # generate pot file from rb files
88 rgettext_proc = proc do |t|
89 require 'gettext/utils'
90 source_files, pot_file = t.prerequisites, t.name
91 new_pot_file = "#{pot_file}.new"
92 puts "#{source_files.join(', ')} => #{pot_file}"
93 GetText.rgettext(source_files, new_pot_file)
95 # only use the new pot file if it contains unique messages
96 if File.exists?(pot_file) && MSGCOMM && `#{MSGCOMM} --unique #{pot_file} #{new_pot_file}`.empty?
99 mv new_pot_file, pot_file
102 normalize_po(pot_file)
104 # save all this work until rb files are updated again
108 # generate pot file for non-plugin files
109 file('po/rbot.pot' => NON_PLUGIN_FILES, &rgettext_proc)
111 # generate pot files for plugin files
112 rule(%r'^po/.+\.pot$' => proc {|fn|
113 PLUGIN_FILES.select {|f| f.pathmap('rbot-%n') == fn.pathmap('%n')}
116 # map the po file to its source pot file
117 pot_for_po = proc {|fn| fn.pathmap '%{^po/.+/,po/}X.pot'}
119 # update po file from pot file
120 msgmerge_proc = proc do |t|
121 require 'gettext/utils'
122 po_file, pot_file = t.name, t.source
123 puts "#{pot_file} => #{po_file}"
124 if File.exists? po_file
125 sh "#{MSGMERGE} --backup=off --update #{po_file} #{pot_file}"
127 locale = po_file[%r'^po/(.+)/.+\.po$', 1]
128 sh "#{MSGINIT} --locale=#{locale} --no-translator --input=#{pot_file} --output-file=#{po_file}"
130 warn "#{po_file} is missing and cannot be generated without msginit"
133 normalize_po(po_file)
137 # generate English po files
138 file(%r'^po/en_US/.+\.po$' => pot_for_po) do |t|
139 po_file, pot_file = t.name, t.source
141 sh "#{MSGEN} --output-file=#{po_file} #{pot_file}"
142 normalize_po(po_file)
150 rule(%r'^po/.+/.+\.po$' => pot_for_po, &msgmerge_proc)
154 rule(%r'^data/locale/.+/LC_MESSAGES/.+\.mo$' => proc {|fn|
155 [ fn.pathmap('%{^data/locale,po;LC_MESSAGES/,}X.po'),
156 # the directory is created if not existing
159 po_file, mo_file = t.source, t.name
160 puts "#{po_file} => #{mo_file}"
161 require 'gettext/utils'
162 GetText.rmsgfmt po_file, mo_file
165 task :check_po_tools do
170 :options => %w[--backup= --update],
171 :message => 'Cannot update po files' },
173 :options => %w[--locale= --no-translator --input= --output-file=],
174 :message => 'Cannot generate missing po files' },
176 :options => %w[--unique],
177 :message => 'Pot files may be modified even without message change' },
179 :options => %w[--output-file],
180 :message => 'English po files will not be generated' },
182 :options => %w[--width= --sort-by-file],
183 :message => 'Pot files will not be normalized' }
186 po_tools.each_pair do |command, value|
187 path = ENV["#{command.upcase}_PATH"] || command
188 have_it = have[command] = value[:options].all? do |option|
189 `#{path} --help`.include? option
191 Object.const_set(command.upcase, have_it ? path : false)
192 warn "#{command} not found. #{value[:message]}" unless have_it
194 abort unless MSGMERGE
197 PLUGIN_BASENAMES = PLUGIN_FILES.map {|f| f.pathmap('%n')}
198 LOCALES = FileList['po/*/'].map {|d| d.pathmap('%n')}
201 directory "data/locale/#{l}/LC_MESSAGES"
204 desc 'Update po files'
205 task :updatepo => [:define_po_rules, :check_po_tools] + LOCALES.map {|l|
206 ["po/#{l}/rbot.po"] +
207 PLUGIN_BASENAMES.map {|n| "po/#{l}/rbot-#{n}.po"}
210 desc 'Normalize po files'
211 task :normalizepo => :check_po_tools do
212 FileList['po/*/*.po'].each {|fn| normalize_po(fn)}
215 # this task invokes makemo if ruby-gettext is available, but otherwise succeeds
216 # with a warning instead of failing. it is to be used by Gem's extension builder
217 # to make installation not fail because of lack of ruby-gettext
220 require 'gettext/utils'
221 Rake::Task[:makemo].invoke
223 warn 'Ruby-gettext cannot be located, so mo files cannot be built and installed'
227 desc 'Generate mo files'
229 FileList['po/*/*.po'].pathmap('%{^po,data/locale}d/LC_MESSAGES/%n.mo')