40 lines
1.2 KiB
Ruby

module Rscons
class CC < Builder
def self.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 self.produces?(env, target, source)
(env['OBJSUFFIX', :array].find {|os| target =~ /#{os}$/} and
env['CSUFFIX', :array].find {|cs| source =~ /#{cs}$/})
end
def run(env, target, source)
raise "String expected, not #{source.inspect}" unless source.is_a?(String)
unless Cache.open.up_to_date?(target, [source])
vars = {
'TARGET' => target,
'SOURCES' => source,
'DEPFILE' => env.stem(target) + '.mf',
}
env.execute("CC #{target}", env['CCCOM'], vars)
deps = [source]
if File.exists?(vars['DEPFILE'])
deps += env.parse_makefile_deps(vars['DEPFILE'], target)
FileUtils.rm_f(vars['DEPFILE'])
end
Cache.open.register_build(target, deps.uniq)
end
target
end
end
end