Module: L::LD::Linker
- Defined in:
- lib/rub/l/ld.rb
Overview
An abstraction for a linker.
Constant Summary collapse
- @@name_map =
{ exe: '%s', shared: 'lib%s.so', static: 'lib%s.a', }
Class Method Summary collapse
-
.available? ⇒ true, false
Is this linker available on this system?.
-
.builtin_library_path ⇒ Array<Pathname>
Return the linker’s builtin library path.
-
.do_link(opt, files, libs, out, format) ⇒ R::Command
Perform a link.
-
.find_lib(opt, name) ⇒ Pathname
Locate a library.
-
.full_name(base, type) ⇒ String
Generate an appropriate name.
-
.library_path(opt) ⇒ Array<Pathname>
Return the path which to search for libraries.
-
.link_command(opt, files, libs, out, format) ⇒ Set<Pathname>
Generate a command to perform the link.
-
.name ⇒ Symbol
The name of the linker.
-
.test_link(opt, files, libs, format) ⇒ true, false
Peform a test link.
Class Method Details
.available? ⇒ true, false
Is this linker available on this system?
107 108 109 |
# File 'lib/rub/l/ld.rb', line 107 def self.available? false end |
.builtin_library_path ⇒ Array<Pathname>
Return the linker’s builtin library path.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rub/l/ld.rb', line 114 def self.builtin_library_path @builtin_library_path ||= [ '/lib/', '/usr/lib/', '/usr/local/lib/', '~/.local/lib/', ].map do |l| C.path(l) end.uniq end |
.do_link(opt, files, libs, out, format) ⇒ R::Command
Perform a link.
152 153 154 155 156 |
# File 'lib/rub/l/ld.rb', line 152 def self.do_link(opt, files, libs, out, format) c = R::Command.new(link_command(opt, files, libs, out, format)) c.run c end |
.find_lib(opt, name) ⇒ Pathname
Locate a library.
Locates the library that would be used with when linking.
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/rub/l/ld.rb', line 191 def self.find_lib(opt, name) sp = library_path(opt) if name.to_s.include? '/' return C.path name end name = full_name name, (opt.static ? :static : :shared) sp.each do |d| l = d + name l.exist? and return l end end |
.full_name(base, type) ⇒ String
Generate an appropriate name.
180 181 182 |
# File 'lib/rub/l/ld.rb', line 180 def self.full_name(base, type) @@name_map[type] % base end |
.library_path(opt) ⇒ Array<Pathname>
Return the path which to search for libraries.
128 129 130 |
# File 'lib/rub/l/ld.rb', line 128 def self.library_path(opt) opt.library_dirs + builtin_library_path end |
.link_command(opt, files, libs, out, format) ⇒ Set<Pathname>
Generate a command to perform the link.
144 145 146 |
# File 'lib/rub/l/ld.rb', line 144 def self.link_command(opt, files, libs, out, format) raise NotImplementedError end |
.name ⇒ Symbol
The name of the linker.
100 101 102 |
# File 'lib/rub/l/ld.rb', line 100 def self.name :default end |
.test_link(opt, files, libs, format) ⇒ true, false
Peform a test link.
162 163 164 165 166 |
# File 'lib/rub/l/ld.rb', line 162 def self.test_link(opt, files, libs, format) c = do_link(opt, files, libs, File::NULL, format) #p c.success?, c.stdin, c.stdout, c.stderr c.success? end |