Class: Rscons::Builders::SharedLibrary

Inherits:
Rscons::Builder show all
Defined in:
lib/rscons/builders/shared_library.rb

Overview

A default Rscons builder that knows how to link object files into a shared library.

Instance Method Summary collapse

Methods inherited from Rscons::Builder

#name, #produces?, #standard_build, #standard_finalize, #standard_threaded_build

Instance Method Details

#create_build_target(options) ⇒ BuildTarget

Create a BuildTarget object for this build target.

The build target filename is given a platform-dependent suffix if no other suffix is given.

Parameters:

  • options (Hash)

    Options to create the BuildTarget with.

Options Hash (options):

  • :env (Environment)

    The Environment.

  • :target (String)

    The user-supplied target name.

  • :sources (Array<String>)

    The user-supplied source file name(s).

Returns:

[View source]

47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rscons/builders/shared_library.rb', line 47

def create_build_target(options)
  env, target, vars = options.values_at(:env, :target, :vars)
  my_options = options.dup
  libprefix = env.expand_varref("${SHLIBPREFIX}", vars)
  unless File.basename(target).start_with?(libprefix)
    my_options[:target].sub!(%r{^(.*/)?([^/]+)$}, "\\1#{libprefix}\\2")
  end
  unless File.basename(target)["."]
    my_options[:target] += env.expand_varref("${SHLIBSUFFIX}", vars)
  end
  super(my_options)
end

#default_variables(env) ⇒ Hash

Return default construction variables for the builder.

Parameters:

  • env (Environment)

    The Environment using the builder.

Returns:

  • (Hash)

    Default construction variables for the builder.

[View source]

12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rscons/builders/shared_library.rb', line 12

def default_variables(env)
  {
    'SHLIBPREFIX' => (RUBY_PLATFORM =~ /mingw/ ? '' : 'lib'),
    'SHLIBSUFFIX' => (RUBY_PLATFORM =~ /mingw/ ? '.dll' : '.so'),
    'SHLDFLAGS' => ['${LDFLAGS}', '-shared'],
    'SHLD' => nil,
    'SHLIBDIRPREFIX' => '-L',
    'SHLIBLINKPREFIX' => '-l',
    'SHLDCMD' => ['${SHLD}', '-o', '${_TARGET}', '${SHLDFLAGS}', '${_SOURCES}', '${SHLIBDIRPREFIX}${LIBPATH}', '${SHLIBLINKPREFIX}${LIBS}']
  }
end

#featuresArray<String>

Return a set of build features that this builder provides.

Returns:

  • (Array<String>)

    Set of build features that this builder provides.

[View source]

28
29
30
# File 'lib/rscons/builders/shared_library.rb', line 28

def features
  %w[shared]
end

#finalize(options) ⇒ String?

Finalize a build.

Parameters:

  • options (Hash)

    Finalize options.

Returns:

  • (String, nil)

    The target name on success or nil on failure.

[View source]

110
111
112
# File 'lib/rscons/builders/shared_library.rb', line 110

def finalize(options)
  standard_finalize(options)
end

#run(options) ⇒ String, false

Run the builder to produce a build target.

Parameters:

  • options (Hash)

    Builder run options.

Returns:

  • (String, false)

    Name of the target file on success or false on failure.

[View source]

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rscons/builders/shared_library.rb', line 81

def run(options)
  target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
  ld = env.expand_varref("${SHLD}", vars)
  ld = if ld != ""
         ld
       elsif sources.find {|s| s.end_with?(*env.expand_varref("${DSUFFIX}", vars))}
         "${SHDC}"
       elsif sources.find {|s| s.end_with?(*env.expand_varref("${CXXSUFFIX}", vars))}
         "${SHCXX}"
       else
         "${SHCC}"
       end
  vars = vars.merge({
    '_TARGET' => target,
    '_SOURCES' => objects,
    'SHLD' => ld,
  })
  options[:sources] = objects
  command = env.build_command("${SHLDCMD}", vars)
  standard_threaded_build("SHLD #{target}", target, command, objects, env, cache)
end

#setup(options) ⇒ Object

Set up a build operation using this builder.

Parameters:

  • options (Hash)

    Builder setup options.

Returns:

  • (Object)

    Any object that the builder author wishes to be saved and passed back in to the #run method.

[View source]

67
68
69
70
71
72
73
# File 'lib/rscons/builders/shared_library.rb', line 67

def setup(options)
  target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
  suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
  # Register builders to build each source to an object file or library.
  env.register_builds(target, sources, suffixes, vars,
                      features: %w[shared])
end