parent
a655d04541
commit
3b00016278
@ -169,6 +169,7 @@ end
|
|||||||
require_relative "rscons/builders/mixins/depfile"
|
require_relative "rscons/builders/mixins/depfile"
|
||||||
require_relative "rscons/builders/mixins/object"
|
require_relative "rscons/builders/mixins/object"
|
||||||
require_relative "rscons/builders/mixins/object_deps"
|
require_relative "rscons/builders/mixins/object_deps"
|
||||||
|
require_relative "rscons/builders/mixins/program"
|
||||||
|
|
||||||
# default builders
|
# default builders
|
||||||
require_relative "rscons/builders/cfile"
|
require_relative "rscons/builders/cfile"
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
Rscons::Builders::Object.register(command: "${CXXCMD}", suffix: "${CXXSUFFIX}")
|
Rscons::Builders::Object.register(command: "${CXXCMD}", suffix: "${CXXSUFFIX}", preferred_ld: "${CXX}")
|
||||||
Rscons::Builders::SharedObject.register(command: "${SHCXXCMD}", suffix: "${CXXSUFFIX}")
|
Rscons::Builders::SharedObject.register(command: "${SHCXXCMD}", suffix: "${CXXSUFFIX}", preferred_ld: "${SHCXX}")
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
Rscons::Builders::Object.register(command: "${DCCMD}", suffix: "${DSUFFIX}")
|
Rscons::Builders::Object.register(command: "${DCCMD}", suffix: "${DSUFFIX}", preferred_ld: "${DC}")
|
||||||
Rscons::Builders::SharedObject.register(command: "${SHDCCMD}", suffix: "${DSUFFIX}")
|
Rscons::Builders::SharedObject.register(command: "${SHDCCMD}", suffix: "${DSUFFIX}", preferred_ld: "${SHDC}")
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
|
class Builder
|
||||||
|
# @return [String, nil]
|
||||||
|
# Preferred linker for this object file, or a construction variable
|
||||||
|
# reference thereto.
|
||||||
|
attr_reader :preferred_ld
|
||||||
|
end
|
||||||
|
|
||||||
module Builders
|
module Builders
|
||||||
module Mixins
|
module Mixins
|
||||||
module Object
|
module Object
|
||||||
@ -31,6 +38,9 @@ module Rscons
|
|||||||
# @option params [String] :short_description
|
# @option params [String] :short_description
|
||||||
# Short description to be printed when the builder runs (default:
|
# Short description to be printed when the builder runs (default:
|
||||||
# "Compiling")
|
# "Compiling")
|
||||||
|
# @option params [String] :preferred_ld
|
||||||
|
# Preferred linker for this object file, or a construction variable
|
||||||
|
# reference thereto.
|
||||||
def register(params)
|
def register(params)
|
||||||
providers << params
|
providers << params
|
||||||
end
|
end
|
||||||
@ -47,6 +57,7 @@ module Rscons
|
|||||||
end
|
end
|
||||||
@command_template = build_params[:command]
|
@command_template = build_params[:command]
|
||||||
@short_description = build_params[:short_description] || "Compiling"
|
@short_description = build_params[:short_description] || "Compiling"
|
||||||
|
@preferred_ld = build_params[:preferred_ld]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
|
37
lib/rscons/builders/mixins/program.rb
Normal file
37
lib/rscons/builders/mixins/program.rb
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
module Rscons
|
||||||
|
module Builders
|
||||||
|
module Mixins
|
||||||
|
# Mixin providing functionality for a builder that links object files
|
||||||
|
# together into a program.
|
||||||
|
module Program
|
||||||
|
|
||||||
|
# Run the builder to produce a build target.
|
||||||
|
def run(options)
|
||||||
|
if @command
|
||||||
|
finalize_command(sources: @objects)
|
||||||
|
else
|
||||||
|
ld = @env.expand_varref("${#{ld_var}}", @vars)
|
||||||
|
if ld == ""
|
||||||
|
@objects.find do |object|
|
||||||
|
if builder = @env.builder_for(object)
|
||||||
|
if ld = builder.preferred_ld
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if ld.nil? || ld == ""
|
||||||
|
ld = default_ld
|
||||||
|
end
|
||||||
|
@vars["_TARGET"] = @target
|
||||||
|
@vars["_SOURCES"] = @objects
|
||||||
|
@vars["#{ld_var}"] = ld
|
||||||
|
command = @env.build_command("${#{ld_var}CMD}", @vars)
|
||||||
|
standard_command("Linking => #{@target}", command, sources: @objects)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -5,19 +5,9 @@ module Rscons
|
|||||||
class Program < Builder
|
class Program < Builder
|
||||||
|
|
||||||
include Mixins::ObjectDeps
|
include Mixins::ObjectDeps
|
||||||
|
include Mixins::Program
|
||||||
|
|
||||||
# Create an instance of the Builder to build a target.
|
# Create an instance of the Builder to build a target.
|
||||||
#
|
|
||||||
# @param options [Hash]
|
|
||||||
# Options.
|
|
||||||
# @option options [String] :target
|
|
||||||
# Target file name.
|
|
||||||
# @option options [Array<String>] :sources
|
|
||||||
# Source file name(s).
|
|
||||||
# @option options [Environment] :env
|
|
||||||
# The Environment executing the builder.
|
|
||||||
# @option options [Hash,VarSet] :vars
|
|
||||||
# Extra construction variables.
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
super(options)
|
super(options)
|
||||||
unless File.basename(@target)["."]
|
unless File.basename(@target)["."]
|
||||||
@ -26,28 +16,14 @@ module Rscons
|
|||||||
@objects = register_object_deps(Object)
|
@objects = register_object_deps(Object)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
private
|
||||||
def run(options)
|
|
||||||
if @command
|
def default_ld
|
||||||
finalize_command(sources: @objects)
|
"${CC}"
|
||||||
true
|
end
|
||||||
else
|
|
||||||
ld = @env.expand_varref("${LD}", @vars)
|
def ld_var
|
||||||
ld = if ld != ""
|
"LD"
|
||||||
ld
|
|
||||||
elsif @sources.find {|s| s.end_with?(*@env.expand_varref("${DSUFFIX}", @vars))}
|
|
||||||
"${DC}"
|
|
||||||
elsif @sources.find {|s| s.end_with?(*@env.expand_varref("${CXXSUFFIX}", @vars))}
|
|
||||||
"${CXX}"
|
|
||||||
else
|
|
||||||
"${CC}"
|
|
||||||
end
|
|
||||||
@vars["_TARGET"] = @target
|
|
||||||
@vars["_SOURCES"] = @objects
|
|
||||||
@vars["LD"] = ld
|
|
||||||
command = @env.build_command("${LDCMD}", @vars)
|
|
||||||
standard_command("Linking => #{@target}", command, sources: @objects)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,7 @@ module Rscons
|
|||||||
class SharedLibrary < Builder
|
class SharedLibrary < Builder
|
||||||
|
|
||||||
include Mixins::ObjectDeps
|
include Mixins::ObjectDeps
|
||||||
|
include Mixins::Program
|
||||||
|
|
||||||
# Create an instance of the Builder to build a target.
|
# Create an instance of the Builder to build a target.
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@ -19,28 +20,14 @@ module Rscons
|
|||||||
@objects = register_object_deps(SharedObject)
|
@objects = register_object_deps(SharedObject)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
private
|
||||||
def run(options)
|
|
||||||
if @command
|
def default_ld
|
||||||
finalize_command(sources: @objects)
|
"${SHCC}"
|
||||||
true
|
end
|
||||||
else
|
|
||||||
ld = @env.expand_varref("${SHLD}", @vars)
|
def ld_var
|
||||||
ld = if ld != ""
|
"SHLD"
|
||||||
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["_TARGET"] = @target
|
|
||||||
@vars["_SOURCES"] = @objects
|
|
||||||
@vars["SHLD"] = ld
|
|
||||||
command = @env.build_command("${SHLDCMD}", @vars)
|
|
||||||
standard_command("Linking => #{@target}", command, sources: @objects)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -71,6 +71,7 @@ module Rscons
|
|||||||
@registered_build_dependencies = {}
|
@registered_build_dependencies = {}
|
||||||
@side_effects = {}
|
@side_effects = {}
|
||||||
@builder_set = BuilderSet.new(@registered_build_dependencies, @side_effects)
|
@builder_set = BuilderSet.new(@registered_build_dependencies, @side_effects)
|
||||||
|
@build_targets = {}
|
||||||
@user_deps = {}
|
@user_deps = {}
|
||||||
# Hash of builder name (String) => builder class (Class).
|
# Hash of builder name (String) => builder class (Class).
|
||||||
@builders = {}
|
@builders = {}
|
||||||
@ -318,6 +319,7 @@ module Rscons
|
|||||||
env: self,
|
env: self,
|
||||||
vars: vars)
|
vars: vars)
|
||||||
@builder_set << builder
|
@builder_set << builder
|
||||||
|
@build_targets[target] = builder
|
||||||
builder
|
builder
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
@ -517,6 +519,14 @@ module Rscons
|
|||||||
Ansi.write($stdout, :cyan, message, :reset, "\n") if message
|
Ansi.write($stdout, :cyan, message, :reset, "\n") if message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get the Builder for a target.
|
||||||
|
#
|
||||||
|
# @return [Builder, nil]
|
||||||
|
# The {Builder} for target, or +nil+ if none found.
|
||||||
|
def builder_for(target)
|
||||||
|
@build_targets[target]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Run a builder and process its return value.
|
# Run a builder and process its return value.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user