add Library default builder
This commit is contained in:
parent
e04e67698a
commit
64d15602cc
4
build_tests/library/build.rb
Normal file
4
build_tests/library/build.rb
Normal file
@ -0,0 +1,4 @@
|
||||
Rscons::Environment.new(echo: :command) do |env|
|
||||
env.Program('library', ['lib.a', 'three.c'])
|
||||
env.Library("lib.a", ['one.c', 'two.c'], 'CPPFLAGS' => ['-Dmake_lib'])
|
||||
end
|
8
build_tests/library/one.c
Normal file
8
build_tests/library/one.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef make_lib
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("Library\n");
|
||||
}
|
||||
#endif
|
0
build_tests/library/three.c
Normal file
0
build_tests/library/three.c
Normal file
0
build_tests/library/two.c
Normal file
0
build_tests/library/two.c
Normal file
@ -8,12 +8,14 @@ require "rscons/monkey/module"
|
||||
require "rscons/monkey/string"
|
||||
|
||||
# default builders
|
||||
require "rscons/builders/library"
|
||||
require "rscons/builders/object"
|
||||
require "rscons/builders/program"
|
||||
|
||||
# Namespace module for rscons classes
|
||||
module Rscons
|
||||
DEFAULT_BUILDERS = [
|
||||
Library,
|
||||
Object,
|
||||
Program,
|
||||
]
|
||||
|
33
lib/rscons/builders/library.rb
Normal file
33
lib/rscons/builders/library.rb
Normal file
@ -0,0 +1,33 @@
|
||||
require 'fileutils'
|
||||
|
||||
module Rscons
|
||||
# A default RScons builder that produces a static library archive.
|
||||
class Library < Builder
|
||||
def default_variables(env)
|
||||
{
|
||||
'AR' => 'ar',
|
||||
'LIBSUFFIX' => '.a',
|
||||
'ARFLAGS' => [],
|
||||
'ARCOM' => ['$AR', 'rcs', '$ARFLAGS', '$TARGET', '$SOURCES']
|
||||
}
|
||||
end
|
||||
|
||||
def run(target, sources, cache, env, vars = {})
|
||||
# build sources to linkable objects
|
||||
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
|
||||
if objects
|
||||
vars = vars.merge({
|
||||
'TARGET' => target,
|
||||
'SOURCES' => objects,
|
||||
})
|
||||
command = env.build_command(env['ARCOM'], vars)
|
||||
unless cache.up_to_date?(target, command, objects)
|
||||
FileUtils.rm_f(target)
|
||||
return false unless env.execute("AR #{target}", command)
|
||||
cache.register_build(target, command, objects)
|
||||
end
|
||||
target
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -194,6 +194,9 @@ module Rscons
|
||||
def method_missing(method, *args)
|
||||
if @builders.has_key?(method.to_s)
|
||||
target, source, vars, *rest = args
|
||||
unless vars.nil? or vars.is_a?(Hash) or vars.is_a?(VarSet)
|
||||
raise "Unexpected construction variable set: #{vars.inspect}"
|
||||
end
|
||||
source = [source] unless source.is_a?(Array)
|
||||
@targets[target] = {
|
||||
builder: @builders[method.to_s],
|
||||
|
@ -153,4 +153,17 @@ describe Rscons do
|
||||
File.exists?('two_sources').should be_true
|
||||
`./two_sources`.should == "This is a C program with two sources.\n"
|
||||
end
|
||||
|
||||
it 'builds a static library archive' do
|
||||
lines = test_dir('library')
|
||||
lines.should == [
|
||||
'gcc -c -o one.o -MMD -MF one.mf -Dmake_lib one.c',
|
||||
'gcc -c -o two.o -MMD -MF two.mf -Dmake_lib two.c',
|
||||
'ar rcs lib.a one.o two.o',
|
||||
'gcc -c -o three.o -MMD -MF three.mf three.c',
|
||||
'gcc -o library lib.a three.o',
|
||||
]
|
||||
File.exists?('library').should be_true
|
||||
`ar t lib.a`.should == "one.o\ntwo.o\n"
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user