45 lines
1.4 KiB
Ruby

module Rscons
class Program < Builder
def self.default_variables(env)
{
'LD' => nil,
'OBJSUFFIX' => '.o',
'LIBSUFFIX' => '.a',
'LDFLAGS' => [],
'LIBPATHS' => [],
'LIBS' => [],
'LDCOM' => ['$LD', '-o', '$TARGET', '$LDFLAGS', '$SOURCES', '-L$[LIBPATHS]', '-l$[LIBS]']
}
end
def run(env, target, sources)
sources = [sources] if sources.is_a?(String)
# convert sources to object file names
sources = sources.map do |source|
if source =~ /#{env['OBJSUFFIX']}$/ or source =~ /#{env['LIBSUFFIX']}$/
source
else
o_file = env.stem(source) + env['OBJSUFFIX', :string]
builder_class = env.builders.values.find { |klass| klass.produces?(env, o_file, source) }
if builder_class
builder = builder_class.new
builder.run(env, o_file, source)
else
raise "No builder found to convert input source #{source.inspect} to an object file."
end
end
end
unless Cache.open.up_to_date?(target, sources)
vars = {
'TARGET' => target,
'SOURCES' => sources,
'LD' => env['LD'] || env['CC'], # TODO: figure out whether to use CC or CXX
}
env.execute("LD #{target}", env['LDCOM'], vars)
Cache.open.register_build(target, sources)
end
target
end
end
end