mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
a3ec6ede76
I sometimes see Bison related problems in setting up build environments. Therefore to remove Bison from build time dependencies, add `y.tab.c` generated by Bison to the repository. The reduction of dependency at build time also reduces the labor and time for setup and installation in CI. In addition, a path in `#line` directive is converted to a relative path so that its path is constant regardless of development environments.
39 lines
1.3 KiB
Ruby
39 lines
1.3 KiB
Ruby
MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
|
|
spec.license = 'MIT'
|
|
spec.author = 'mruby developers'
|
|
spec.summary = 'mruby compiler library'
|
|
|
|
lex_def = "#{dir}/core/lex.def"
|
|
core_objs = Dir.glob("#{dir}/core/*.c").map { |f|
|
|
next nil if build.cxx_exception_enabled? and f =~ /(codegen).c$/
|
|
objfile(f.pathmap("#{build_dir}/core/%n"))
|
|
}.compact
|
|
|
|
if build.cxx_exception_enabled?
|
|
core_objs <<
|
|
build.compile_as_cxx("#{dir}/core/y.tab.c", "#{build_dir}/core/y.tab.cxx",
|
|
objfile("#{build_dir}/y.tab"), ["#{dir}/core"]) <<
|
|
build.compile_as_cxx("#{dir}/core/codegen.c", "#{build_dir}/core/codegen.cxx")
|
|
else
|
|
core_objs << objfile("#{build_dir}/core/y.tab")
|
|
file objfile("#{build_dir}/core/y.tab") => "#{dir}/core/y.tab.c" do |t|
|
|
cc.run t.name, t.prerequisites.first, [], ["#{dir}/core"]
|
|
end
|
|
end
|
|
|
|
# Parser
|
|
file "#{dir}/core/y.tab.c" => ["#{dir}/core/parse.y", lex_def] do |t|
|
|
yacc.run t.name, t.prerequisites.first
|
|
content = File.read(t.name).gsub(/^#line +\d+ +"\K.*$/){$&.relative_path}
|
|
File.write(t.name, content)
|
|
end
|
|
|
|
# Lexical analyzer
|
|
file lex_def => "#{dir}/core/keywords" do |t|
|
|
gperf.run t.name, t.prerequisites.first
|
|
end
|
|
|
|
file build.libmruby_core_static => core_objs
|
|
build.libmruby << core_objs
|
|
end
|