module Rscons class Program < Builder VARIABLE_DEFAULTS = { 'LD' => nil, 'OBJSUFFIX' => '.o', 'LIBSUFFIX' => '.a', 'LDFLAGS' => [], 'LIBPATHS' => [], 'LIBS' => [], } def run(env, target, sources) sources = [sources] if sources.is_a?(String) sources = sources.map do |source| if source =~ /#{env['OBJSUFFIX']}$/ or source =~ /#{env['LIBSUFFIX']}$/ source else builder_class = env.builders.values.find { |klass| klass.makes_object_file?(env, source) } if builder_class builder = builder_class.new builder.run(env, env.stem(source) + env['OBJSUFFIX'], source) else raise "No builder found to convert input source #{source.inspect} to an object file." end end end command = [ env['LD'] || env['CC'], '-o', target, *env['LDFLAGS'], *sources, *env['LIBPATHS'].map {|lp| "-L#{lp}"}, *env['LIBS'].map {|lib| "-l#{lib}"} ] env.execute("LINK #{target}", command) target end end end