Parent

Installer

An installer copies files from the current directory to an OS-wide location

Attributes

dir[R]
package[RW]

Public Class Methods

new() click to toggle source
# File lib/makeconf/installer.rb, line 7
def initialize
  @items = []         # Items to be installed
  @project = nil
  @path = nil
  @custom_rule = []       # Custom rules to run at the end

  # Set default installation paths
  @dir = {
      :prefix => Platform.is_superuser? ? '/usr' : '/usr/local',
      :eprefix => '$(PREFIX)',    # this is --exec-prefix
      :bindir => '$(EPREFIX)/bin',
      :datarootdir => '$(PREFIX)/share',
      :datadir => '$(DATAROOTDIR)',
      :docdir => '$(DATAROOTDIR)/doc/$(PACKAGE)',
      :includedir => '$(PREFIX)/include',
      :infodir => '$(DATAROOTDIR)/info',
      :libdir => '$(EPREFIX)/lib',
      :libexecdir => '$(EPREFIX)/libexec',
      :localedir => '$(DATAROOTDIR)/locale',
      :localstatedir => '$(PREFIX)/var',
      :mandir => '$(DATAROOTDIR)/man',
      :oldincludedir => '/usr/include',
      :sbindir => '$(EPREFIX)/sbin',
      :sysconfdir => '$(PREFIX)/etc',
      :sharedstatedir => '$(PREFIX)/com',

      # Package-specific directories
      :pkgincludedir => '$(INCLUDEDIR)/$(PACKAGE)',
      :pkgdatadir => '$(DATADIR)/$(PACKAGE)',
      :pkglibdir => '$(LIBDIR)/$(PACKAGE)',
      
      #TODO: document this
      #DEPRECATED: htmldir, dvidir, pdfdir, psdir
  }

  @dir[:prefix] = ENV['SystemDrive'] + @dir[:prefix] if Platform.is_windows?
end

Public Instance Methods

add_rule(rule) click to toggle source

Add a custom rule to run at the end of the `install' target.

# File lib/makeconf/installer.rb, line 150
def add_rule(rule)
  @custom_rule.push rule
end
configure(project) click to toggle source

Examine the operating environment and set configuration options

# File lib/makeconf/installer.rb, line 46
def configure(project)
  @project = project
  printf 'checking for a BSD-compatible install.. '
  if Platform.is_windows?
     puts 'not found'
  else
     @path = search() or throw 'No installer found'
     printf @path + "\n"
  end
end
install(src) click to toggle source

Register a file to be copied during the 'make install' phase.

# File lib/makeconf/installer.rb, line 76
  def install(src)
    buf = {
        :sources => nil,
        :dest => nil,
        :rename => nil,
        :directory? => false,
        :group => nil,
        :user => nil,
        :mode => '0755',
    }
#TODO: check for leading '/': raise ArgumentError, 'absolute path is required' unless src[:dest].index(0) == '/'
    raise ArgumentError, ':dest is require' if src[:dest].nil?
    raise ArgumentError, 'Cannot specify both directory and sources'         if buf[:directory] == true and not buf[:sources].nil
    @items.push buf.merge(src)
  end
package_manifest() click to toggle source

Return a list of files that will be installed

# File lib/makeconf/installer.rb, line 122
def package_manifest()
  res = []
  @items.each do |item|
    sources = item[:sources]
    sources = [ sources ] unless sources.kind_of?(Array)
    sources.each do |src|
      # TODO - want to split into multiple packages
      #if pkg == :main
      #  next unless item[:dest] =~ /(LIB|BIN)DIR/
      #elsif pkg == :devel
      #  next unless item[:dest] =~ /(INCLUDE|MAN)DIR/
      #else
      #  throw "bad pkg type"
      #end
      dst = expand_dir(item[:dest])
      if item[:rename].nil?
        dst += '/' + src
      else
        dst += '/' + item[:rename]
      end
      dst.gsub!(/^\/usr\/local\//, '/usr/')  # KLUDGE: only true when making an RPM or DEB
      res.push dst
    end
  end
  res.join "\n"
end
parse_options(opts) click to toggle source

Parse command line options. Should only be called from Makeconf.parse_options()

# File lib/makeconf/installer.rb, line 59
def parse_options(opts)
  opts.separator ""
  opts.separator "Installation options:"

  # Convert symbols to strings
  tmp = {}
  @dir.each { |k,v| tmp[k.to_s] = v }

  tmp.sort.each do |k, v|
     opts.on('--' + k + ' [DIRECTORY]', "TODO describe this [#{v}]") do |arg|
        @dir[k.to_sym] = arg
     end
  end

end
to_make() click to toggle source
# File lib/makeconf/installer.rb, line 93
def to_make
  mkdir_list = []   # all directories that have been created so far

  m = Makefile.new
  m.define_variable('INSTALL', '?=', @path) unless @path.nil?
  @dir.keys.each { |d| m.define_variable(d.to_s.upcase, '=', @dir[d]) }

  # Add 'make install' rules
  @items.each do |i| 
    # Automatically create the destination directory, if needed
    destdir = expand_dir(i[:dest])
    unless mkdir_list.include?(destdir)
     m.add_rule('install', Platform.is_windows? ?
             "dir $(DESTDIR)#{destdir} >NUL 2>NUL || mkdir $(DESTDIR)#{destdir}" : 
             "/usr/bin/test -e $(DESTDIR)#{destdir} || $(INSTALL) -d -m 755 $(DESTDIR)#{destdir}")
     mkdir_list.push(destdir)
    end

    m.add_rule('install', install_command(i)) 
    m.add_rule('uninstall', uninstall_command(i)) 
  end

  # Add any custom rules at the end
  @custom_rule.each { |rule| m.add_rule('install', rule) }

  return m
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.