Copy header files to the build directory

This is so that the build directory can be regarded as a temporary installation directory to work in.

Directories set in `MRuby::Gem::Specification#export_include_paths` are used as they are if they are subdirectories placed under `gem.dir`.
Files are placed under `<build-dir>/include/mruby/gems/<gem-name>/<gem-include_paths>` to separate each GEM.

When GEM is compiled by building `libmruby.a`, the same `include_paths` will be set as before, so it is expected that no unintended references will be made.
This commit is contained in:
dearblue
2023-02-12 21:02:28 +09:00
parent c020d8507e
commit aac2fd7055
4 changed files with 73 additions and 0 deletions
+24
View File
@@ -8,9 +8,33 @@ MRuby.each_target do
next unless libmruby_enabled?
file libmruby_static => libmruby_objs.flatten do |t|
Rake::Task["expose_header_files"].invoke
archiver.run t.name, t.prerequisites
end
task "expose_header_files" do |t|
# Since header files may be generated dynamically and it is hard to know all of them,
# the task is executed depending on when libmruby.a is generated.
gemsbasedir = File.join(build_dir, "include/mruby/gems")
dirmap = {
MRUBY_ROOT => build_dir
}
gems.each { |g|
dirmap[g.dir] = File.join(gemsbasedir, g.name)
dirmap[g.build_dir] = File.join(gemsbasedir, g.name)
}
dirs = each_header_files.to_a
dirs.uniq!
dirs.replace_prefix_by(dirmap).zip(dirs).each do |dest, src|
if File.mtime(src).to_i > (File.mtime(dest).to_i rescue 0)
mkpath File.dirname(dest)
cp src, dest
end
end
end
file "#{build_dir}/lib/libmruby.flags.mak" => [__FILE__, libmruby_static] do |t|
mkdir_p File.dirname t.name
open(t.name, 'w') do |f|