# -*- ruby -*- #-- # Copyright (C) 2009 Cathal Mc Ginley # Copyright (C) 2011, 2014 Matijs van Zuijlen # # This file is part of the Alexandria build system. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ load 'tasks/setup.rb' require 'rake/packagetask' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'util/rake')) require 'fileinstall' require 'gettextgenerate' require 'omfgenerate' require_relative 'lib/alexandria/version' stage_dir = ENV['DESTDIR'] || 'tmp' prefix_dir = ENV['PREFIX'] || '/usr' PROJECT = 'alexandria' PREFIX = prefix_dir share_dir = ENV['SHARE'] || "#{PREFIX}/share" SHARE = share_dir GettextGenerateTask.new(PROJECT) do |g| g.generate_po_files('po', 'po/*.po', 'share/locale') g.generate_desktop('alexandria.desktop.in', 'alexandria.desktop') end OmfGenerateTask.new(PROJECT) do |o| o.gnome_helpfiles_dir = "#{SHARE}/gnome/help" o.generate_omf('data/omf/alexandria', 'share/omf/alexandria/*.in') end SHARE_FILE_GLOBS = ['data/alexandria/**/*', 'data/gnome/**/*.*', 'data/locale/**/*.mo', 'data/omf/**/*.omf', 'data/sounds/**/*.ogg'] # , 'data/menu/*'] ICON_FILE_GLOBS = ['data/app-icon/**/*.png', 'data/app-icon/scalable/*.svg'] PIXMAP_GLOBS = 'data/app-icon/32x32/*.xpm' def install_common(install_task) install_task.install_exe('bin', 'bin/*', "#{PREFIX}/bin") install_task.install('lib', 'lib/**/*.rb', install_task.rubylib) install_task.install('data', SHARE_FILE_GLOBS, SHARE) install_task.install_icons(ICON_FILE_GLOBS, "#{SHARE}/icons") install_task.install('data/app-icon/32x32', PIXMAP_GLOBS, "#{SHARE}/pixmaps") install_task.install('', 'schemas/alexandria.schemas', "#{SHARE}/gconf") install_task.install('', 'alexandria.desktop', "#{SHARE}/applications") install_task.install('doc', 'doc/alexandria.1', "#{SHARE}/man/man1") end FileInstallTask.new(:package_staging, stage_dir, true) do |i| install_common(i) end task debian_install: :install_package_staging FileInstallTask.new(:package) do |j| install_common(j) docs = %w(README.rdoc NEWS INSTALL.rdoc COPYING TODO) devel_docs = ['doc/AUTHORS', 'doc/BUGS', 'doc/FAQ', 'doc/cuecat_support.rdoc'] j.install('', docs, "#{SHARE}/doc/#{PROJECT}") j.install('doc', devel_docs, "#{SHARE}/doc/#{PROJECT}") j.uninstall_empty_dirs(["#{SHARE}/**/#{PROJECT}/", "#{j.rubylib}/#{PROJECT}/" ]) end task :clobberp do puts CLOBBER end ## autogenerated files def autogen_comment lines = [ "This file is automatically generated by the #{PROJECT} installer.", 'Do not edit it directly.' ] result = lines.map { |line| "# #{line}" } result.join("\n") + "\n\n" end def generate(filename) File.open(filename, 'w') do |file| puts "Generating #{filename}" file.print autogen_comment file_contents = yield file.print file_contents.to_s end end # generate default_preferences.rb def convert_with_type(value, type) case type when 'int' value.to_i when 'float' value.to_f when 'bool' value == 'true' else value.strip end end SCHEMA_PATH = 'schemas/alexandria.schemas' # This generates default_preferences.rb by copying over values from # providers_priority key in alexandria.schemas (necessary?) file 'lib/alexandria/default_preferences.rb' => [SCHEMA_PATH] do |f| require 'rexml/document' generated_lines = [] doc = REXML::Document.new(IO.read(SCHEMA_PATH)) doc.elements.each('gconfschemafile/schemalist/schema') do |element| default = element.elements['default'].text next unless default varname = File.basename(element.elements['key'].text) type = element.elements['type'].text if type == 'list' or type == 'pair' ary = default[1..-2].split(',') next if ary.empty? if type == 'list' list_type = element.elements['list_type'].text ary.map! { |x| convert_with_type(x, list_type) } elsif type == 'pair' next if ary.length != 2 ary[0] = convert_with_type(ary[0], element.elements['car_type'].text) ary[1] = convert_with_type(ary[1], element.elements['cdr_type'].text) end default = ary.inspect else default = convert_with_type(default, type).inspect.to_s end generated_lines << varname.inspect + ' => ' + default end generate(f.name) do <