+rule '.1' => ['.xml'] do |t|
+ sh "xsltproc -nonet -o #{t.name} /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl #{t.source}"
+end
+
+task :manpages => ['man/rbot.1', 'man/rbot-remote.1']
+
+SPECFILE = 'rbot.gemspec'
+# The Rakefile is also used after installing the gem, to build
+# the .mo files. Since in this case the SPECFILE is not available,
+# we must (and can) skip defining the gem packaging tasks.
+if File.exist? SPECFILE
+ spec = eval(File.read(SPECFILE), nil, SPECFILE)
+ Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_zip = true
+ pkg.need_tar = true
+ end
+end
+
+# normalize a po/pot file
+def normalize_po(fn)
+ content = File.read(fn)
+
+ # sort the messages by file location
+ if MSGCAT
+ sorted = `#{MSGCAT} --width=79 --sort-by-file #{fn}`
+ if sorted != content
+ content = sorted
+ modified = true
+ end
+ end
+
+ # replace project-id-version placholder
+ modified |= content.sub!(/^("Project-Id-Version: )PACKAGE VERSION(\\n")$/) {
+ "#{$1}rbot#{$2}"
+ }
+
+ if modified
+ File.open(fn, 'w') {|f| f.write content}
+ end
+end
+
+PLUGIN_FILES = FileList['data/rbot/plugins/**/*.rb']
+NON_PLUGIN_FILES = FileList["{lib,bin,data}/**/*.{rb,rhtml}"] - PLUGIN_FILES
+
+# this task defines how po files and pot files are made. those rules are not defined
+# normally because po and pot files should be only updated in the updatepo task,
+# but po files are also prereqs for makemo
+task :define_po_rules do
+ # generate pot file from rb files
+ rgettext_proc = proc do |t|
+ require 'gettext/utils'
+ source_files, pot_file = t.prerequisites, t.name
+ new_pot_file = "#{pot_file}.new"
+ puts "#{source_files.join(', ')} => #{pot_file}"
+ GetText.rgettext(source_files, new_pot_file)
+
+ # only use the new pot file if it contains unique messages
+ if File.exists?(pot_file) && MSGCOMM && `#{MSGCOMM} --unique #{pot_file} #{new_pot_file}`.empty?
+ rm new_pot_file
+ else
+ mv new_pot_file, pot_file
+ end
+
+ normalize_po(pot_file)
+
+ # save all this work until rb files are updated again
+ touch pot_file
+ end
+
+ # generate pot file for non-plugin files
+ file('po/rbot.pot' => NON_PLUGIN_FILES, &rgettext_proc)
+
+ # generate pot files for plugin files
+ rule(%r'^po/.+\.pot$' => proc {|fn|
+ PLUGIN_FILES.select {|f| f.pathmap('rbot-%n') == fn.pathmap('%n')}
+ }, &rgettext_proc)