]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - Rakefile
Rakefile: update list of binaries
[user/henk/code/ruby/rbot.git] / Rakefile
1 require 'rubygems'
2 require 'rake'
3 require 'rake/gempackagetask'
4
5 task :default => [:repackage]
6
7 spec = Gem::Specification.new do |s|
8   s.name = 'rbot'
9   s.version = '0.9.11'
10   s.summary = <<-EOF
11     A modular ruby IRC bot.
12   EOF
13   s.description = <<-EOF
14     A modular ruby IRC bot specifically designed for ease of extension via plugins.
15   EOF
16   s.requirements << 'Ruby, version 1.8.0 (or newer)'
17
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.bindir = 'bin'
21   s.executables = ['rbot', 'rbot-remote']
22   s.default_executable = 'rbot'
23
24 #  s.autorequire = 'rbot/ircbot'
25   s.has_rdoc = true
26   s.rdoc_options = ['--exclude', 'post-install.rb',
27   '--title', 'rbot API Documentation', '--main', 'README', 'README']
28
29   s.author = 'Tom Gilbert'
30   s.email = 'tom@linuxbrit.co.uk'
31   s.homepage = 'http://ruby-rbot.org'
32   s.rubyforge_project = 'rbot'
33 end
34
35 Rake::GemPackageTask.new(spec) do |pkg|
36   pkg.need_zip = true
37   pkg.need_tar = true
38 end
39
40 # normalize a po/pot file
41 def normalize_po(fn)
42   content = File.read(fn)
43
44   # replace project-id-version placholder
45   modified = content.sub!(/^("Project-Id-Version: )PACKAGE VERSION(\\n")$/) {
46     "#{$1}rbot#{$2}"
47   }
48
49   # sort the messages by file location
50   if MSGCAT
51     sorted = `#{MSGCAT} --width=79 --sort-by-file #{fn}`
52     if sorted != content
53       content = sorted
54       modified = true
55     end
56   end
57
58   if modified
59     File.open(fn, 'w') {|f| f.write content}
60   end
61 end
62
63 PLUGIN_FILES = FileList['data/rbot/plugins/**/*.rb']
64 NON_PLUGIN_FILES = FileList["{lib,bin,data}/**/*.{rb,rhtml}"] - PLUGIN_FILES
65
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)
77
78     # only use the new pot file if it contains unique messages
79     if MSGCOMM && `#{MSGCOMM} --unique #{pot_file} #{new_pot_file}`.empty?
80       rm new_pot_file
81     else
82       mv new_pot_file, pot_file
83     end
84
85     normalize_po(pot_file)
86     
87     # save all this work until rb files are updated again
88     touch pot_file
89   end
90
91   # generate pot file for non-plugin files
92   file('po/rbot.pot' => NON_PLUGIN_FILES, &rgettext_proc)
93
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')}
97   }, &rgettext_proc)
98
99   # map the po file to its source pot file
100   pot_for_po = proc {|fn| fn.pathmap '%{^po/.+/,po/}X.pot'}
101
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)
109     touch po_file
110   end
111
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
115     if MSGEN
116       sh "#{MSGEN} --output-file=#{po_file} #{pot_file}"
117       normalize_po(po_file)
118       touch po_file
119     else
120       msgmerge_proc.call t
121     end
122   end
123
124   # update po files
125   rule(%r'^po/.+/.+\.po$' => pot_for_po, &msgmerge_proc)
126 end
127
128 # generate mo files
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
132     fn.pathmap('%d') ]
133 }) do |t|
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
138 end
139
140 task :check_po_tools do
141   have = {}
142
143   po_tools = {
144     'msgmerge' => {
145       :options => %w[--backup= --update],
146       :message => 'Cannot update po files' },
147     'msgcomm' => {
148       :options => %w[--unique],
149       :message => 'Pot files may be modified even without message change' },
150     'msgen' => {
151       :options => %w[--output-file],
152       :message => 'English po files will not be generated' },
153     'msgcat' => {
154       :options => %w[--width= --sort-by-file],
155       :message => 'Pot files will not be normalized' }
156   }
157
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
162     end
163     Object.const_set(command.upcase, have_it ? path : false)
164     warn "#{command} not found. #{value[:message]}" unless have_it
165   end
166   abort unless MSGMERGE
167 end
168
169 PLUGIN_BASENAMES = PLUGIN_FILES.map {|f| f.pathmap('%n')}
170 LOCALES = FileList['po/*/'].map {|d| d.pathmap('%n')}
171
172 LOCALES.each do |l|
173   directory "data/locale/#{l}/LC_MESSAGES"
174 end
175
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"}
180 }.flatten
181
182 desc 'Normalize po files'
183 task :normalizepo => :check_po_tools do
184   FileList['po/*/*.po'].each {|fn| normalize_po(fn)}
185 end
186
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"}
191 }.flatten
192