Class: Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/makeconf/installer.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInstaller

Returns a new instance of Installer.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/makeconf/installer.rb', line 7

def initialize
  @items = []         # Items to be installed
  @project = nil
  @path = nil

  # 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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



4
5
6
# File 'lib/makeconf/installer.rb', line 4

def dir
  @dir
end

#packageObject

Returns the value of attribute package.



5
6
7
# File 'lib/makeconf/installer.rb', line 5

def package
  @package
end

Instance Method Details

#configure(project) ⇒ Object

Examine the operating environment and set configuration options



45
46
47
48
49
50
51
52
53
54
# File 'lib/makeconf/installer.rb', line 45

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) ⇒ Object

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

Raises:

  • (ArgumentError)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/makeconf/installer.rb', line 75

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

#parse_options(opts) ⇒ Object

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/makeconf/installer.rb', line 58

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_makeObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/makeconf/installer.rb', line 92

def to_make
  mkdir_list = []   # all directories that have been created so far

  m = Makefile.new
  m.define_variable('INSTALL', '?=', @path) unless @path.nil?

  # 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

  return m
end