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 # sort the messages by file location
47 sorted = `#{MSGCAT} --width=79 --sort-by-file #{fn}`
54 # replace project-id-version placholder
55 modified |= content.sub!(/^("Project-Id-Version: )PACKAGE VERSION(\\n")$/) {
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}"
111 locale = po_file[%r'^po/(.+)/.+\.po$', 1]
112 sh "#{MSGINIT} --locale=#{locale} --no-translator --input=#{pot_file} --output-file=#{po_file}"
114 warn "#{po_file} is missing and cannot be generated without msginit"
117 normalize_po(po_file)
121 # generate English po files
122 file(%r'^po/en_US/.+\.po$' => pot_for_po) do |t|
123 po_file, pot_file = t.name, t.source
125 sh "#{MSGEN} --output-file=#{po_file} #{pot_file}"
126 normalize_po(po_file)
134 rule(%r'^po/.+/.+\.po$' => pot_for_po, &msgmerge_proc)
138 rule(%r'^data/locale/.+/LC_MESSAGES/.+\.mo$' => proc {|fn|
139 [ fn.pathmap('%{^data/locale,po;LC_MESSAGES/,}X.po'),
140 # the directory is created if not existing
143 po_file, mo_file = t.source, t.name
144 puts "#{po_file} => #{mo_file}"
145 require 'gettext/utils'
146 GetText.rmsgfmt po_file, mo_file
149 task :check_po_tools do
154 :options => %w[--backup= --update],
155 :message => 'Cannot update po files' },
157 :options => %w[--locale= --no-translator --input= --output-file=],
158 :message => 'Cannot generate missing po files' },
160 :options => %w[--unique],
161 :message => 'Pot files may be modified even without message change' },
163 :options => %w[--output-file],
164 :message => 'English po files will not be generated' },
166 :options => %w[--width= --sort-by-file],
167 :message => 'Pot files will not be normalized' }
170 po_tools.each_pair do |command, value|
171 path = ENV["#{command.upcase}_PATH"] || command
172 have_it = have[command] = value[:options].all? do |option|
173 `#{path} --help`.include? option
175 Object.const_set(command.upcase, have_it ? path : false)
176 warn "#{command} not found. #{value[:message]}" unless have_it
178 abort unless MSGMERGE
181 PLUGIN_BASENAMES = PLUGIN_FILES.map {|f| f.pathmap('%n')}
182 LOCALES = FileList['po/*/'].map {|d| d.pathmap('%n')}
185 directory "data/locale/#{l}/LC_MESSAGES"
188 desc 'Update po files'
189 task :updatepo => [:define_po_rules, :check_po_tools] + LOCALES.map {|l|
190 ["po/#{l}/rbot.po"] +
191 PLUGIN_BASENAMES.map {|n| "po/#{l}/rbot-#{n}.po"}
194 desc 'Normalize po files'
195 task :normalizepo => :check_po_tools do
196 FileList['po/*/*.po'].each {|fn| normalize_po(fn)}
199 # this task invokes makemo if ruby-gettext is available, but otherwise succeeds
200 # with a warning instead of failing. it is to be used by Gem's extension builder
201 # to make installation not fail because of lack of ruby-gettext
204 require 'gettext/utils'
205 Rake::Task[:makemo].invoke
207 warn 'Ruby-gettext cannot be located, so mo files cannot be built and installed'
211 desc 'Generate mo files'
213 FileList['po/*/*.po'].pathmap('%{^po,data/locale}d/LC_MESSAGES/%n.mo')