module L::LD::Linker
An abstraction for a linker.
Public Class Methods
Is this linker available on this system?
@return [true,false] true if the linker is available.
# File lib/rub/l/ld.rb, line 107 def self.available? false end
Return the linker’s builtin library path.
@return [Array<Pathname>]
# 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
Perform a link.
@param (see link_command
) @return [R::Command] the process that linked the file.
# 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
Locate a library.
Locates the library that would be used with when linking.
@param name [String] The basename of the library. @param options [Options] The options to use when linking. @return [Pathname] The path to the library.
# 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
Generate an appropriate name.
@param base [String] The basename. @param type [Symbol] The output format. @return [String] A suitable name for the output type on the
current machine.
# File lib/rub/l/ld.rb, line 180 def self.full_name(base, type) @@name_map[type] % base end
Return the path which to search for libraries.
@return [Array<Pathname>]
# File lib/rub/l/ld.rb, line 128 def self.library_path(opt) opt.library_dirs + builtin_library_path end
Generate a command to perform the link.
@param files [Set<Pathname,String>,Array<Pathname,String>,Pathname,String]
The object files to link.
@param libs [Set<String>,Array<String>,String] Libraries to link with. @param out [Pathname,String] The output file. @param format [Symbol] The type of output to produce.
One of: [+:exe+] An executable binary. [+:shared+] A shared library.
@param opt [Options] An options object. @return [Set<Pathname>] The output file.
# File lib/rub/l/ld.rb, line 144 def self.link_command(opt, files, libs, out, format) raise NotImplementedError end
The name of the linker. @return [Symbol]
# File lib/rub/l/ld.rb, line 100 def self.name :default end
Peform a test link.
@param (see link_command
) @return [true,false] true if the link succeeded.
# 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