fill in CC, Program, Environment.process() to get simple builds working

This commit is contained in:
josh committed 2013-07-07 17:17:46 -04:00
1 parent 5634b8856d
commit 760f698963
6 files changed
+151 -10

No files matched your search

+33
View File
@@ -1,4 +1,37 @@
module Rscons
class CC < Builder
def default_variables(env)
{
'CC' => 'gcc',
'CFLAGS' => [],
'CPPFLAGS' => [],
'OBJSUFFIX' => '.o',
'CSUFFIX' => '.c',
'CCDEPGEN' => ['-MMD', '-MF', '$DEPFILE'],
'CCCOM' => ['$CC', '-c', '-o', '$TARGET', '$CCDEPGEN', '$CPPFLAGS', '$CFLAGS', '$SOURCES']
}
end
def produces?(target, source)
target.has_suffix?(@env['OBJSUFFIX']) and source.has_suffix?(@env['CSUFFIX'])
end
def run(target, sources, cache)
unless cache.up_to_date?(target, sources)
vars = {
'TARGET' => target,
'SOURCES' => sources,
'DEPFILE' => target.set_suffix('.mf'),
}
@env.execute("CC #{target}", @env['CCCOM'], vars)
deps = sources
if File.exists?(vars['DEPFILE'])
deps += @env.parse_makefile_deps(vars['DEPFILE'], target)
FileUtils.rm_f(vars['DEPFILE'])
end
cache.register_build(target, deps.uniq)
end
target
end
end
end
+28 -9
View File
@@ -1,19 +1,38 @@
module Rscons
class Program < Builder
def default_variables
def default_variables(env)
{
'CC' => 'gcc',
'CFLAGS' => [],
'CPPFLAGS' => [],
'LD' => nil,
'OBJSUFFIX' => '.o',
'CSUFFIX' => '.c',
'CCDEPGEN' => ['-MMD', '-MF', '$DEPFILE'],
'CCCOM' => ['$CC', '-c', '-o', '$TARGET', '$CCDEPGEN', '$CPPFLAGS', '$CFLAGS', '$SOURCES']
'LIBSUFFIX' => '.a',
'LDFLAGS' => [],
'LIBPATHS' => [],
'LIBS' => [],
'LDCOM' => ['$LD', '-o', '$TARGET', '$LDFLAGS', '$SOURCES', '-L$[LIBPATHS]', '-l$[LIBS]']
}
end
def produces?(target, source)
target.has_suffix?(@env['OBJSUFFIX']) and source.has_suffix?(@env['CSUFFIX'])
def run(target, sources, cache)
# convert sources to object file names
sources = sources.map do |source|
if source.has_suffix?([@env['OBJSUFFIX'], @env['LIBSUFFIX']])
source
else
o_file = source.set_suffix(@env['OBJSUFFIX', :string])
builder = @env.builders.values.find { |b| b.produces?(o_file, source) }
builder or raise "No builder found to convert input source #{source.inspect} to an object file."
builder.run(o_file, [source], cache)
end
end
unless cache.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)
end
target
end
end
end