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"}
21 s.executables = ['rbot', 'rbot-remote']
22 s.default_executable = 'rbot'
24 # s.autorequire = 'rbot/ircbot'
26 s.rdoc_options = ['--exclude', 'post-install.rb',
27 '--title', 'rbot API Documentation', '--main', 'README', 'README']
29 s.author = 'Tom Gilbert'
30 s.email = 'tom@linuxbrit.co.uk'
31 s.homepage = 'http://ruby-rbot.org'
32 s.rubyforge_project = 'rbot'
35 Rake::GemPackageTask.new(spec) do |pkg|
40 # normalize a po/pot file
42 content = File.read(fn)
44 # replace project-id-version placholder
45 modified = content.sub!(/^("Project-Id-Version: )PACKAGE VERSION(\\n")$/) {
49 # sort the messages by file location
51 sorted = `#{MSGCAT} --width=79 --sort-by-file #{fn}`
59 File.open(fn, 'w') {|f| f.write content}
63 PLUGIN_FILES = FileList['data/rbot/plugins/**/*.rb']
64 NON_PLUGIN_FILES = FileList["{lib,bin,data}/**/*.{rb,rhtml}"] - PLUGIN_FILES
66 # this task defines how po files and pot files are made. those rules are not defined
67 # normally because po and pot files should be only updated in the updatepo task,
68 # but po files are also prereqs for makemo
69 task :define_po_rules do
70 # generate pot file from rb files
71 rgettext_proc = proc do |t|
72 require 'gettext/utils'
73 source_files, pot_file = t.prerequisites, t.name
74 new_pot_file = "#{pot_file}.new"
75 puts "#{source_files.join(', ')} => #{pot_file}"
76 GetText.rgettext(source_files, new_pot_file)
78 # only use the new pot file if it contains unique messages
79 if MSGCOMM && `#{MSGCOMM} --unique #{pot_file} #{new_pot_file}`.empty?
82 mv new_pot_file, pot_file
85 normalize_po(pot_file)
87 # save all this work until rb files are updated again
91 # generate pot file for non-plugin files
92 file('po/rbot.pot' => NON_PLUGIN_FILES, &rgettext_proc)
94 # generate pot files for plugin files
95 rule(%r'^po/.+\.pot$' => proc {|fn|
96 PLUGIN_FILES.select {|f| f.pathmap('rbot-%n') == fn.pathmap('%n')}
99 # map the po file to its source pot file
100 pot_for_po = proc {|fn| fn.pathmap '%{^po/.+/,po/}X.pot'}
102 # update po file from pot file
103 msgmerge_proc = proc do |t|
104 require 'gettext/utils'
105 po_file, pot_file = t.name, t.source
106 puts "#{pot_file} => #{po_file}"
107 sh "#{MSGMERGE} --backup=off --update #{po_file} #{pot_file}"
108 normalize_po(po_file)
112 # generate English po files
113 file(%r'^po/en_US/.+\.po$' => pot_for_po) do |t|
114 po_file, pot_file = t.name, t.source
116 sh "#{MSGEN} --output-file=#{po_file} #{pot_file}"
117 normalize_po(po_file)
125 rule(%r'^po/.+/.+\.po$' => pot_for_po, &msgmerge_proc)
129 rule(%r'^data/locale/.+/LC_MESSAGES/.+\.mo$' => proc {|fn|
130 [ fn.pathmap('%{^data/locale,po;LC_MESSAGES/,}X.po'),
131 # the directory is created if not existing
134 po_file, mo_file = t.source, t.name
135 puts "#{po_file} => #{mo_file}"
136 require 'gettext/utils'
137 GetText.rmsgfmt po_file, mo_file
140 task :check_po_tools do
145 :options => %w[--backup= --update],
146 :message => 'Cannot update po files' },
148 :options => %w[--unique],
149 :message => 'Pot files may be modified even without message change' },
151 :options => %w[--output-file],
152 :message => 'English po files will not be generated' },
154 :options => %w[--width= --sort-by-file],
155 :message => 'Pot files will not be normalized' }
158 po_tools.each_pair do |command, value|
159 path = ENV["#{command.upcase}_PATH"] || command
160 have_it = have[command] = value[:options].all? do |option|
161 `#{path} --help`.include? option
163 Object.const_set(command.upcase, have_it ? path : false)
164 warn "#{command} not found. #{value[:message]}" unless have_it
166 abort unless MSGMERGE
169 PLUGIN_BASENAMES = PLUGIN_FILES.map {|f| f.pathmap('%n')}
170 LOCALES = FileList['po/*/'].map {|d| d.pathmap('%n')}
173 directory "data/locale/#{l}/LC_MESSAGES"
176 desc 'Update po files'
177 task :updatepo => [:define_po_rules, :check_po_tools] + LOCALES.map {|l|
178 ["po/#{l}/rbot.po"] +
179 PLUGIN_BASENAMES.map {|n| "po/#{l}/rbot-#{n}.po"}
182 desc 'Normalize po files'
183 task :normalizepo => :check_po_tools do
184 FileList['po/*/*.po'].each {|fn| normalize_po(fn)}
187 desc 'Generate mo files'
188 task :makemo => LOCALES.map {|l|
189 ["data/locale/#{l}/LC_MESSAGES/rbot.mo"] +
190 PLUGIN_BASENAMES.map {|n| "data/locale/#{l}/LC_MESSAGES/rbot-#{n}.mo"}