Class: Rscons::Builders::CFile

Inherits:
Rscons::Builder show all
Defined in:
lib/rscons/builders/cfile.rb

Overview

Build a C or C++ source file given a lex (.l, .ll) or yacc (.y, .yy) input file.

Examples

env.CFile(“parser.tab.cc”, “parser.yy”) env.CFile(“lex.yy.cc”, “parser.ll”)

Instance Method Summary collapse

Methods inherited from Rscons::Builder

#create_build_target, #features, #name, #produces?, #setup, #standard_build, #standard_finalize, #standard_threaded_build

Instance Method Details

#default_variables(env) ⇒ Hash

Return default construction variables for the builder.

Parameters:

  • env (Environment)

    The Environment using the builder.

Returns:

  • (Hash)

    Default construction variables for the builder.


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rscons/builders/cfile.rb', line 16

def default_variables(env)
  {
    "YACC" => "bison",
    "YACC_FLAGS" => ["-d"],
    "YACC_CMD" => ["${YACC}", "${YACC_FLAGS}", "-o", "${_TARGET}", "${_SOURCES}"],
    "YACCSUFFIX" => [".y", ".yy"],
    "LEX" => "flex",
    "LEX_FLAGS" => [],
    "LEX_CMD" => ["${LEX}", "${LEX_FLAGS}", "-o", "${_TARGET}", "${_SOURCES}"],
    "LEXSUFFIX" => [".l", ".ll"],
  }
end

#finalize(options) ⇒ String?

Finalize a build.

Parameters:

  • options (Hash)

    Finalize options.

Returns:

  • (String, nil)

    The target name on success or nil on failure.


64
65
66
# File 'lib/rscons/builders/cfile.rb', line 64

def finalize(options)
  standard_finalize(options)
end

#run(target, sources, cache, env, vars) ⇒ String, false

Run the builder to produce a build target.

Parameters:

  • target (String)

    Target file name.

  • sources (Array<String>)

    Source file name(s).

  • cache (Cache)

    The Cache object.

  • env (Environment)

    The Environment executing the builder.

  • vars (Hash, VarSet)

    Extra construction variables.

Returns:

  • (String, false)

    Name of the target file on success or false on failure.


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rscons/builders/cfile.rb', line 39

def run(target, sources, cache, env, vars)
  vars = vars.merge({
    "_TARGET" => target,
    "_SOURCES" => sources,
  })
  cmd =
    case
    when sources.first.end_with?(*env.expand_varref("${LEXSUFFIX}"))
      "LEX"
    when sources.first.end_with?(*env.expand_varref("${YACCSUFFIX}"))
      "YACC"
    else
      raise "Unknown source file #{sources.first.inspect} for CFile builder"
    end
  command = env.build_command("${#{cmd}_CMD}", vars)
  standard_threaded_build("#{cmd} #{target}", target, command, sources, env, cache)
end