Class: Rscons::Builders::SharedObject
- Inherits:
-
Rscons::Builder
- Object
- Rscons::Builder
- Rscons::Builders::SharedObject
- Defined in:
- lib/rscons/builders/shared_object.rb
Overview
A default Rscons builder which knows how to produce an object file which is capable of being linked into a shared library from various types of source files.
Constant Summary collapse
- KNOWN_SUFFIXES =
Mapping of known sources from which to build object files.
{ "AS" => "ASSUFFIX", "SHCC" => "CSUFFIX", "SHCXX" => "CXXSUFFIX", "SHDC" => "DSUFFIX", }
Instance Method Summary collapse
-
#default_variables(env) ⇒ Hash
Return default construction variables for the builder.
-
#features ⇒ Array<String>
Return a set of build features that this builder provides.
-
#finalize(options) ⇒ String?
Finalize the build operation.
-
#produces?(target, source, env) ⇒ Boolean
Return whether this builder object is capable of producing a given target file name from a given source file name.
-
#run(options) ⇒ String, ThreadedCommand
Run the builder to produce a build target.
Methods inherited from Rscons::Builder
#create_build_target, #name, #setup, #standard_build, #standard_finalize, #standard_threaded_build
Instance Method Details
#default_variables(env) ⇒ Hash
Return default construction variables for the builder.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rscons/builders/shared_object.rb', line 21 def default_variables(env) pic_flags = (RUBY_PLATFORM =~ /mingw/ ? [] : ['-fPIC']) { 'SHCCFLAGS' => ['${CCFLAGS}'] + pic_flags, 'SHCC' => '${CC}', 'SHCFLAGS' => ['${CFLAGS}'], 'SHCCCMD' => ['${SHCC}', '-c', '-o', '${_TARGET}', '${CCDEPGEN}', '${INCPREFIX}${CPPPATH}', '${CPPFLAGS}', '${SHCFLAGS}', '${SHCCFLAGS}', '${_SOURCES}'], 'SHCXX' => '${CXX}', 'SHCXXFLAGS' => ['${CXXFLAGS}'], 'SHCXXCMD' => ['${SHCXX}', '-c', '-o', '${_TARGET}', '${CXXDEPGEN}', '${INCPREFIX}${CPPPATH}', '${CPPFLAGS}', '${SHCXXFLAGS}', '${SHCCFLAGS}', '${_SOURCES}'], 'SHDC' => 'gdc', 'SHDFLAGS' => ['${DFLAGS}'] + pic_flags, 'SHDCCMD' => ['${SHDC}', '-c', '-o', '${_TARGET}', '${INCPREFIX}${D_IMPORT_PATH}', '${SHDFLAGS}', '${_SOURCES}'], } end |
#features ⇒ Array<String>
Return a set of build features that this builder provides.
44 45 46 |
# File 'lib/rscons/builders/shared_object.rb', line 44 def features %w[shared] end |
#finalize(options) ⇒ String?
Finalize the build operation.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rscons/builders/shared_object.rb', line 99 def finalize() if [:command_status] target, deps, cache, env, vars = .values_at(:target, :sources, :cache, :env, :vars) if File.exists?(vars['_DEPFILE']) deps += Environment.parse_makefile_deps(vars['_DEPFILE']) FileUtils.rm_f(vars['_DEPFILE']) end cache.register_build(target, [:tc].command, deps.uniq, env) target end end |
#produces?(target, source, env) ⇒ Boolean
Return whether this builder object is capable of producing a given target file name from a given source file name.
61 62 63 64 65 66 |
# File 'lib/rscons/builders/shared_object.rb', line 61 def produces?(target, source, env) target.end_with?(*env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var| source.end_with?(*env[suffix_var]) end end |
#run(options) ⇒ String, ThreadedCommand
Run the builder to produce a build target.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rscons/builders/shared_object.rb', line 75 def run() target, sources, cache, env, vars = .values_at(:target, :sources, :cache, :env, :vars) vars = vars.merge({ '_TARGET' => target, '_SOURCES' => sources, '_DEPFILE' => Rscons.set_suffix(target, env.("${DEPFILESUFFIX}", vars)), }) com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var| sources.first.end_with?(*env.("${#{suffix_var}}", vars)) end.tap do |v| v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}" end.first command = env.build_command("${#{com_prefix}CMD}", vars) # Store vars back into options so new keys are accessible in #finalize. [:vars] = vars standard_threaded_build("#{com_prefix} #{target}", target, command, sources, env, cache) end |