6551765
Index: Rakefile
6551765
===================================================================
6551765
--- Rakefile	(revision 1111)
6551765
+++ Rakefile	(revision 1116)
6551765
@@ -1,4 +1,28 @@
6551765
 # -*- ruby -*-
6551765
+#--
6551765
+# Copyright (C) 2009 Cathal Mc Ginley
6551765
+#
6551765
+# This file is part of the Alexandria build system.
6551765
+#
6551765
+# Permission is hereby granted, free of charge, to any person obtaining
6551765
+# a copy of this software and associated documentation files (the
6551765
+# "Software"), to deal in the Software without restriction, including
6551765
+# without limitation the rights to use, copy, modify, merge, publish,
6551765
+# distribute, sublicense, and/or sell copies of the Software, and to
6551765
+# permit persons to whom the Software is furnished to do so, subject to
6551765
+# the following conditions:
6551765
+#
6551765
+# The above copyright notice and this permission notice shall be
6551765
+# included in all copies or substantial portions of the Software.
6551765
+#
6551765
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
6551765
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
6551765
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
6551765
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
6551765
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
6551765
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
6551765
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6551765
+#++
6551765
 
6551765
 begin
6551765
   require 'rake'
6551765
@@ -38,46 +62,44 @@
6551765
   o.generate_omf('data/omf/alexandria', 'data/omf/alexandria/*.in') 
6551765
 end
6551765
 
6551765
-debinstall = FileInstallTask.new(:debian_install, stage_dir, true) do |i|
6551765
+def install_common(install_task)
6551765
+  install_task.install_exe('bin', 'bin/*', "#{PREFIX}/bin")
6551765
+  install_task.install('lib', 'lib/**/*.rb', install_task.rubylib)
6551765
 
6551765
-  i.install_exe('bin', 'bin/*', "#{PREFIX}/bin")
6551765
-  i.install('lib', 'lib/**/*.rb', i.rubylib)
6551765
-
6551765
   share_files = ['data/alexandria/**/*', 'data/gnome/**/*.*',
6551765
                  'data/locale/**/*.mo', 'data/omf/**/*.omf', 
6551765
                  'data/sounds/**/*.wav'] #, 'data/menu/*']
6551765
-  i.install('data', share_files, SHARE)
6551765
+  install_task.install('data', share_files, SHARE)
6551765
 
6551765
   icon_files = ['data/app-icon/**/*.png', 'data/app-icon/scalable/*.svg']
6551765
-  i.install_icons(icon_files, "#{SHARE}/icons")
6551765
-  i.install('data/app-icon/32x32', 'data/app-icon/32x32/*.xpm', "#{SHARE}/pixmaps")
6551765
+  install_task.install_icons(icon_files, "#{SHARE}/icons")
6551765
+  install_task.install('data/app-icon/32x32', 'data/app-icon/32x32/*.xpm', "#{SHARE}/pixmaps")
6551765
 
6551765
-  i.install('','schemas/alexandria.schemas', "#{SHARE}/gconf")
6551765
-  i.install('', 'alexandria.desktop', "#{SHARE}/applications")
6551765
-  i.install('doc','doc/alexandria.1', "#{SHARE}/man/man1")
6551765
+  install_task.install('','schemas/alexandria.schemas', "#{SHARE}/gconf")
6551765
+  install_task.install('', 'alexandria.desktop', "#{SHARE}/applications")
6551765
+  install_task.install('doc','doc/alexandria.1', "#{SHARE}/man/man1")
6551765
 
6551765
+end
6551765
 
6551765
+debinstall = FileInstallTask.new(:package_staging, stage_dir, true) do |i|
6551765
+  install_common(i)
6551765
+
6551765
 end
6551765
 
6551765
-debinstall.similar(:install_files) do |j|
6551765
+task :debian_install => :install_package_staging
6551765
+
6551765
+packageinstall = FileInstallTask.new(:package) do |j|
6551765
+  install_common(j)
6551765
+
6551765
   docs = ['README', 'NEWS', 'INSTALL', 'COPYING', 'TODO']
6551765
   devel_docs = ['doc/AUTHORS', 'doc/BUGS', 'doc/FAQ', 
6551765
                 'doc/cuecat_support.rdoc']
6551765
   j.install('', docs, "#{SHARE}/doc/#{PROJECT}") 
6551765
   j.install('doc', devel_docs, "#{SHARE}/doc/#{PROJECT}")
6551765
 
6551765
-  j.uninstall_empty_dirs(["#{SHARE}/**/#{PROJECT}",
6551765
-                          "#{j.rubylib}/#{PROJECT}"
6551765
+  j.uninstall_empty_dirs(["#{SHARE}/**/#{PROJECT}/",
6551765
+                          "#{j.rubylib}/#{PROJECT}/"
6551765
                          ])
6551765
-=begin
6551765
-  j.uninstall_empty_dirs(["#{SHARE}/sounds/#{PROJECT}",
6551765
-                          "#{SHARE}/gnome/help/#{PROJECT}",
6551765
-                          "#{SHARE}/omf/#{PROJECT}",
6551765
-                          "#{SHARE}/doc/#{PROJECT}",
6551765
-                          "#{SHARE}/#{PROJECT}",
6551765
-                          "#{j.rubylib}/#{PROJECT}"
6551765
-                         ])
6551765
-=end
6551765
 end
6551765
 
6551765
 
6551765
@@ -296,7 +318,7 @@
6551765
 task :post_install => [:scrollkeeper, :gconf, :update_icon_cache]
6551765
 
6551765
 desc "Install Alexandria"
6551765
-task :install => [:pre_install, :install_files, :post_install]
6551765
+task :install => [:pre_install, :install_package, :post_install]
6551765
 
6551765
 desc "Uninstall Alexandria"
6551765
-task :uninstall => [:un_install_files, :un_install_files_empty_dirs]
6551765
+task :uninstall => [:uninstall_package] # TODO gconf etc...
6551765
Index: util/rake/gettextgenerate.rb
6551765
===================================================================
6551765
--- util/rake/gettextgenerate.rb	(revision 1111)
6551765
+++ util/rake/gettextgenerate.rb	(revision 1116)
6551765
@@ -2,7 +2,7 @@
6551765
 #--
6551765
 # Copyright (C) 2009 Cathal Mc Ginley
6551765
 #
6551765
-# This file is part of the Palatina build system.
6551765
+# This file is part of the Alexandria build system.
6551765
 #
6551765
 # Permission is hereby granted, free of charge, to any person obtaining
6551765
 # a copy of this software and associated documentation files (the
6551765
Index: util/rake/fileinstall.rb
6551765
===================================================================
6551765
--- util/rake/fileinstall.rb	(revision 1111)
6551765
+++ util/rake/fileinstall.rb	(revision 1116)
6551765
@@ -2,7 +2,7 @@
6551765
 #--
6551765
 # Copyright (C) 2009 Cathal Mc Ginley
6551765
 #
6551765
-# This file is part of the Palatina build system.
6551765
+# This file is part of the Alexandria build system.
6551765
 #
6551765
 # Permission is hereby granted, free of charge, to any person obtaining
6551765
 # a copy of this software and associated documentation files (the
6551765
@@ -58,21 +58,17 @@
6551765
   # Debian, set +dirname+ to 'debian/packagename' and
6551765
   # +install_to_rubylibdir+ to true so that files are stage-installed
6551765
   # to 'debian/packagename/usr/lib/ruby/1.8'
6551765
-  def initialize(taskname=nil, dirname=nil, install_to_rubylibdir=false)
6551765
+  def initialize(taskname, dirname=nil, install_to_rubylibdir=false)
6551765
     @taskname = taskname
6551765
     @install_to_rubylibdir = install_to_rubylibdir
6551765
     calculate_ruby_dir
6551765
     @stage_dir = dirname # || @prefix
6551765
     @file_groups = []
6551765
+    @dirs_to_remove_globs
6551765
     if block_given?
6551765
       yield self
6551765
     end
6551765
-    if taskname
6551765
-      # taskname will be nil for newly cloned tasked (c.f. #similar)
6551765
-      # so we don't make the new task yet...
6551765
-      make_tasks
6551765
-    end
6551765
-
6551765
+    make_tasks
6551765
   end
6551765
 
6551765
   protected
6551765
@@ -80,47 +76,71 @@
6551765
   # Creates the install and uninstall tasks based on the contents
6551765
   # of the @file_groups list
6551765
   def make_tasks
6551765
+    tasknames = {}
6551765
+    tasknames[:install] = "install_#{@taskname}".intern
6551765
+    tasknames[:uninstall] = "uninstall_#{@taskname}".intern
6551765
+    tasknames[:uninstall_files] = "uninstall_#{@taskname}_files".intern
6551765
+    tasknames[:uninstall_dirs] = "uninstall_#{@taskname}_dirs".intern
6551765
+
6551765
+    # INSTALL TASK
6551765
+
6551765
     description = "Install package files"
6551765
     if @stage_dir
6551765
       description += " to staging directory"
6551765
     end
6551765
     desc description
6551765
-    task @taskname do
6551765
+    task tasknames[:install] do
6551765
       @file_groups.each {|g| g.install(@stage_dir) }
6551765
     end    
6551765
 
6551765
+    # UNINSTALL TASKS
6551765
+
6551765
+    task tasknames[:uninstall_files] do
6551765
+      @file_groups.each {|g| g.uninstall(@stage_dir) }
6551765
+    end    
6551765
+
6551765
+    task tasknames[:uninstall_dirs] => tasknames[:uninstall_files] do
6551765
+      all_dirs = Set.new
6551765
+      @file_groups.each {|g| g.get_installation_dirs(@stage_dir, all_dirs) }
6551765
+      
6551765
+
6551765
+      #all_dirs.sort.each {|dir| puts dir }
6551765
+      to_delete = Set.new
6551765
+      @dirs_to_remove_globs.each do |glob|
6551765
+        regex = glob2regex(glob)
6551765
+        all_dirs.each do |dir|
6551765
+          unless dir =~ /\/$/
6551765
+            dir += '/'
6551765
+          end
6551765
+          if regex =~ dir            
6551765
+            #puts "SHOULD DELETE #{dir} #{$1} ; "             
6551765
+            to_delete << $1
6551765
+          end
6551765
+        end
6551765
+      end
6551765
+      to_delete.each do |dirname|
6551765
+        dir = dirname
6551765
+        if @stage_dir
6551765
+          dir = File.join(@stage_dir, dirname)
6551765
+        end
6551765
+        delete_empty(dir)
6551765
+      end
6551765
+    end
6551765
+
6551765
     uninstall_description = "Uninstall package files"
6551765
     if @stage_dir
6551765
-      description += " from staging directory"
6551765
-    end
6551765
-    
6551765
-    #desc uninstall_description
6551765
-    task "un_#{@taskname}".intern do
6551765
-      @dirs = Set.new
6551765
-      @file_groups.each {|g| g.uninstall(@stage_dir, @dirs) }
6551765
-    end    
6551765
+      uninstall_description += " from staging directory"
6551765
+    end   
6551765
+    desc uninstall_description
6551765
+    task tasknames[:uninstall] => [tasknames[:uninstall_files], 
6551765
+                                   tasknames[:uninstall_dirs]]
6551765
+
6551765
   end
6551765
+  
6551765
 
6551765
-  attr_accessor :file_groups, :stage_dir, :taskname
6551765
 
6551765
   public
6551765
 
6551765
-
6551765
-  # Makes a copy of this install task, with the same file groups
6551765
-  # already set, but to which more file groups can be added without
6551765
-  # interference.
6551765
-  def similar(taskname, dirname=nil, install_to_rubylibdir=false)
6551765
-    newtask = self.dup
6551765
-    newtask.taskname = taskname
6551765
-    newtask.stage_dir = dirname
6551765
-    if block_given?
6551765
-      yield newtask 
6551765
-    end   
6551765
-    newtask.make_tasks
6551765
-    newtask
6551765
-  end
6551765
-    
6551765
-  
6551765
   # Include the files specified in the +file_glob+ to be installed in
6551765
   # +dest_dir+, but noting that the prefix +src_dir+ is to be
6551765
   # disregarded in the installation.
6551765
@@ -151,7 +171,9 @@
6551765
         icon_dir = icon_file.dirname
6551765
         icon_size = Pathname.new(icon_dir).basename
6551765
         icon_dest_dir = "#{dest_dir}/#{theme}/#{icon_size}/#{icon_type}"
6551765
-        @file_groups << FileGroup.new(icon_dir, f, icon_dest_dir)
6551765
+        group = FileGroup.new(icon_dir, f, icon_dest_dir)
6551765
+        group.description = "icons"
6551765
+        @file_groups << group
6551765
       end
6551765
     end
6551765
   end
6551765
@@ -159,12 +181,7 @@
6551765
   # Specify which directories should be deleted by the uninstall task
6551765
   # if they are empty (or only contain more empty directories).
6551765
   def uninstall_empty_dirs(dir_globs)
6551765
-    task "un_#{@taskname}_empty_dirs".intern => "un_#{@taskname}".intern do
6551765
-      puts "TODO implement uninstall_empty_dirs"
6551765
-      #FileList.new(dir_globs).each do |f|
6551765
-      #  puts f
6551765
-      #end
6551765
-    end
6551765
+    @dirs_to_remove_globs = dir_globs
6551765
   end
6551765
 
6551765
   private
6551765
@@ -190,14 +207,53 @@
6551765
     end
6551765
   end
6551765
 
6551765
+  def glob2regex(pathglob)
6551765
+    if pathglob =~ /\*\*$/
6551765
+      pathglob += "/"
6551765
+    end
6551765
+    real_parts = pathglob.split("**/")
6551765
+    real_parts.each do |part|
6551765
+      part.gsub!(".", "\\.")
6551765
+      part.gsub!("*", "[^\\/]*")
6551765
+      part.gsub!("?", "[^\\/]")
6551765
+      #puts part
6551765
+    end
6551765
+    pattern = real_parts.join("([^\/]+\/)*")
6551765
+    return /(#{pattern})/
6551765
+  end
6551765
 
6551765
+  # For each of the directories named in the list +dirs+, delete the
6551765
+  # tree if is empty except for further empty directories.
6551765
+  def delete_empty(dirs)
6551765
+    dirs.each do |d|
6551765
+      p = Pathname.new(d)
6551765
+      if p.exist?
6551765
+        delete_if_empty(p.realpath)
6551765
+      end
6551765
+    end
6551765
+  end
6551765
+
6551765
+  
6551765
+  # Delete the directory at the given Pathname +p+ if all its children
6551765
+  # can be similarly deleted, and if it is then empty.
6551765
+  def delete_if_empty(p)
6551765
+    p.children.each do |c|
6551765
+      delete_if_empty(c)
6551765
+    end
6551765
+    if p.children.empty?
6551765
+      p.delete # TODO optional verbose output here
6551765
+    end
6551765
+  end
6551765
+
6551765
   class FileGroup
6551765
     attr_reader :mode
6551765
+    attr_accessor :description
6551765
     def initialize(src_dir, file_glob, dest_dir, mode=0644)
6551765
       @src_dir = src_dir
6551765
       @file_glob = file_glob
6551765
       @dest_dir = dest_dir
6551765
       @mode = mode
6551765
+      @description = "files"
6551765
     end
6551765
     def to_s
6551765
       "FileGroup[#{@src_dir}]"
6551765
@@ -224,27 +280,37 @@
6551765
     end
6551765
 
6551765
     def install(base_dir)
6551765
+      puts "Installing #{@description} to #{@dest_dir}"
6551765
       files.each do |f|
6551765
         dest = self.dest_dir(f, base_dir)
6551765
         FileUtils.mkdir_p(dest) unless test(?d, dest)
6551765
         if test(?f, f)
6551765
-          FileUtils::Verbose.install(f, dest, :mode => self.mode)
6551765
+          FileUtils.install(f, dest, :mode => self.mode)
6551765
         end
6551765
       end
6551765
     end
6551765
 
6551765
-    def uninstall(base_dir, dirs)
6551765
+    def uninstall(base_dir)
6551765
       files.each do |f|
6551765
         dest = self.dest_dir(f, base_dir)
6551765
         filename = File.basename(f)
6551765
         file = File.join(dest, filename)
6551765
         if test(?f, file)
6551765
-          FileUtils::Verbose.rm_f(file) #, :noop => true)
6551765
-          dirs << File.dirname(file)
6551765
+          FileUtils.rm_f(file) #, :noop => true)
6551765
         end
6551765
       end
6551765
     end
6551765
 
6551765
+    def get_installation_dirs(base_dir, all_dirs_set)
6551765
+      files.each do |f|
6551765
+        dest = self.dest_dir(f, base_dir)
6551765
+        filename = File.basename(f)
6551765
+        file = File.join(dest, filename)
6551765
+        all_dirs_set << File.dirname(file)
6551765
+      end
6551765
+    end
6551765
+      
6551765
+
6551765
   end # class FileGroup
6551765
 
6551765
 end # class FileInstallTask
6551765
Index: util/rake/omfgenerate.rb
6551765
===================================================================
6551765
--- util/rake/omfgenerate.rb	(revision 1111)
6551765
+++ util/rake/omfgenerate.rb	(revision 1116)
6551765
@@ -2,7 +2,7 @@
6551765
 #--
6551765
 # Copyright (C) 2009 Cathal Mc Ginley
6551765
 #
6551765
-# This file is part of the Palatina build system.
6551765
+# This file is part of the Alexandria build system.
6551765
 #
6551765
 # Permission is hereby granted, free of charge, to any person obtaining
6551765
 # a copy of this software and associated documentation files (the