Debian Codegraph @

vendor/mruby-source/mrbgems/mruby-compiler/mrbgem.rake

raw
1 MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
2 spec.license = 'MIT'
3 spec.author = 'mruby developers'
4 spec.summary = 'mruby compiler library'
5
6 objs = %w[codegen y.tab].map do |name|
7 src = "#{dir}/core/#{name}.c"
8 if build.cxx_exception_enabled?
9 build.compile_as_cxx(src)
10 else
11 objfile(src.pathmap("#{build_dir}/core/%n"))
12 end
13 end
14 build.libmruby_core_objs << objs
15 end
16
17 if MRuby::Build.current.name == "host"
18 dir = __dir__
19 lex_def = "#{dir}/core/lex.def"
20
21 # Parser
22 file "#{dir}/core/y.tab.c" => ["#{dir}/core/parse.y", lex_def] do |t|
23 MRuby.targets["host"].yacc.run t.name, t.prerequisites.first
24 replace_line_directive(t.name)
25 end
26
27 # Lexical analyzer
28 file lex_def => "#{dir}/core/keywords" do |t|
29 MRuby.targets["host"].gperf.run t.name, t.prerequisites.first
30 replace_line_directive(t.name)
31 end
32
33 def replace_line_directive(path)
34 content = File.read(path).gsub(%r{
35 ^\#line\s+\d+\s+"\K.*(?="$) | # #line directive
36 ^/\*\s+Command-line:.*\s\K\S+(?=\s+\*/$) # header comment in lex.def
37 }x, &:relative_path)
38 File.write(path, content)
39 end
40 end