3 require 'rake/gempackagetask'
5 task :default => [:repackage]
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/**/*', 'AUTHORS', 'COPYING', 'README', 'REQUIREMENTS', 'TODO', 'ChangeLog', 'INSTALL', 'Usage_en.txt', 'setup.rb'].to_a.delete_if {|item| item == ".svn"}
20 s.executables << 'rbot'
22 # s.autorequire = 'rbot/ircbot'
24 s.rdoc_options = ['--exclude', 'post-install.rb',
25 '--title', 'rbot API Documentation', '--main', 'README', 'README']
27 s.author = 'Tom Gilbert'
28 s.email = 'tom@linuxbrit.co.uk'
29 s.homepage = 'http://ruby-rbot.org'
30 s.rubyforge_project = 'rbot'
33 Rake::GemPackageTask.new(spec) do |pkg|
38 # normalize a po/pot file
40 content = File.read(fn)
42 # replace project-id-version placholder
43 modified = content.sub!(/^("Project-Id-Version: )PACKAGE VERSION(\\n")$/) {
47 # sort the messages by file location
49 sorted = `#{MSGCAT} --width=79 --sort-by-file #{fn}`
57 File.open(fn, 'w') {|f| f.write content}
61 PLUGIN_FILES = FileList['data/rbot/plugins/**/*.rb']
62 NON_PLUGIN_FILES = FileList["{lib,bin,data}/**/*.{rb,rhtml}"] - PLUGIN_FILES
64 # this task defines how po files and pot files are made. those rules are not defined
65 # normally because po and pot files should be only updated in the updatepo task,
66 # but po files are also prereqs for makemo
67 task :define_po_rules do
68 # generate pot file from rb files
69 rgettext_proc = proc do |t|
70 require 'gettext/utils'
71 source_files, pot_file = t.prerequisites, t.name
72 new_pot_file = "#{pot_file}.new"
73 puts "#{source_files.join(', ')} => #{pot_file}"
74 GetText.rgettext(source_files, new_pot_file)
76 # only use the new pot file if it contains unique messages
77 if MSGCOMM && `#{MSGCOMM} --unique #{pot_file} #{new_pot_file}`.empty?
80 mv new_pot_file, pot_file
83 normalize_po(pot_file)
85 # save all this work until rb files are updated again
89 # generate pot file for non-plugin files
90 file('po/rbot.pot' => NON_PLUGIN_FILES, &rgettext_proc)
92 # generate pot files for plugin files
93 rule(%r'^po/.+\.pot$' => proc {|fn|
94 PLUGIN_FILES.select {|f| f.pathmap('rbot-%n') == fn.pathmap('%n')}
97 # map the po file to its source pot file
98 pot_for_po = proc {|fn| fn.pathmap '%{^po/.+/,po/}X.pot'}
100 # update po file from pot file
101 msgmerge_proc = proc do |t|
102 require 'gettext/utils'
103 po_file, pot_file = t.name, t.source
104 puts "#{pot_file} => #{po_file}"
105 sh "#{MSGMERGE} --backup=off --update #{po_file} #{pot_file}"
106 normalize_po(po_file)
110 # generate English po files
111 file(%r'^po/en_US/.+\.po$' => pot_for_po) do |t|
112 po_file, pot_file = t.name, t.source
114 sh "#{MSGEN} --output-file=#{po_file} #{pot_file}"
115 normalize_po(po_file)
123 rule(%r'^po/.+/.+\.po$' => pot_for_po, &msgmerge_proc)
127 rule(%r'^data/locale/.+/LC_MESSAGES/.+\.mo$' => proc {|fn|
128 [ fn.pathmap('%{^data/locale,po;LC_MESSAGES/,}X.po'),
129 # the directory is created if not existing
132 po_file, mo_file = t.source, t.name
133 puts "#{po_file} => #{mo_file}"
134 require 'gettext/utils'
135 GetText.rmsgfmt po_file, mo_file
138 task :check_po_tools do
143 :options => %w[--backup= --update],
144 :message => 'Cannot update po files' },
146 :options => %w[--unique],
147 :message => 'Pot files may be modified even without message change' },
149 :options => %w[--output-file],
150 :message => 'English po files will not be generated' },
152 :options => %w[--width= --sort-by-file],
153 :message => 'Pot files will not be normalized' }
156 po_tools.each_pair do |command, value|
157 path = ENV["#{command.upcase}_PATH"] || command
158 have_it = have[command] = value[:options].all? do |option|
159 `#{path} --help`.include? option
161 Object.const_set(command.upcase, have_it ? path : false)
162 warn "#{command} not found. #{value[:message]}" unless have_it
164 abort unless MSGMERGE
167 PLUGIN_BASENAMES = PLUGIN_FILES.map {|f| f.pathmap('%n')}
168 LOCALES = FileList['po/*/'].map {|d| d.pathmap('%n')}
171 directory "data/locale/#{l}/LC_MESSAGES"
174 desc 'Update po files'
175 task :updatepo => [:define_po_rules, :check_po_tools] + LOCALES.map {|l|
176 ["po/#{l}/rbot.po"] +
177 PLUGIN_BASENAMES.map {|n| "po/#{l}/rbot-#{n}.po"}
180 desc 'Normalize po files'
181 task :normalizepo => :check_po_tools do
182 FileList['po/*/*.po'].each {|fn| normalize_po(fn)}
185 desc 'Generate mo files'
186 task :makemo => LOCALES.map {|l|
187 ["data/locale/#{l}/LC_MESSAGES/rbot.mo"] +
188 PLUGIN_BASENAMES.map {|n| "data/locale/#{l}/LC_MESSAGES/rbot-#{n}.mo"}