Repository navigation
Expand file tree
/
Copy pathlibmruby.rake
More file actions
91 lines (78 loc) · 3.43 KB
/
Copy pathlibmruby.rake
File metadata and controls
91 lines (78 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
MRuby.each_target do
next unless libmruby_enabled?
copy_headers_task = "expose_header_files:#{self.name}"
file libmruby_static => libmruby_objs.flatten do |t|
Rake::Task[copy_headers_task].invoke
archiver.run t.name, t.prerequisites
end
task copy_headers_task 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}/#{libdir_name}/libmruby.flags.mak" => [__FILE__, libmruby_static] do |t|
mkdir_p File.dirname t.name
open(t.name, 'w') do |f|
f.puts <<~FLAGS_MAKE
# GNU make is required to use this file.
MRUBY_PACKAGE_DIR_GNU := $(shell dirname "$(lastword $(MAKEFILE_LIST))")
MRUBY_PACKAGE_DIR != dirname "$(MRUBY_PACKAGE_DIR_GNU)"
FLAGS_MAKE
[
[cc, "MRUBY_CC", "MRUBY_CFLAGS"],
[cxx, "MRUBY_CXX", "MRUBY_CXXFLAGS"],
[asm, "MRUBY_AS", "MRUBY_ASFLAGS"],
[objc, "MRUBY_OBJC", "MRUBY_OBJCFLAGS"]
].each do |cc, cmd, flags|
incpaths = cc.include_paths.dup
dirmaps = {
MRUBY_ROOT => "$(MRUBY_PACKAGE_DIR)",
build_dir => "$(MRUBY_PACKAGE_DIR)"
}
gems.each do |g|
incpaths.concat g.export_include_paths
dirmaps[g.dir] = "$(MRUBY_PACKAGE_DIR)/include/mruby/gems/#{g.name}"
dirmaps[g.build_dir] = "$(MRUBY_PACKAGE_DIR)/include/mruby/gems/#{g.name}"
end
modcc = cc.clone
modcc.include_paths = incpaths.replace_prefix_by(dirmaps).uniq
# The file prefix maps name directories of the machine that built the
# package, and nothing the package is compiled with from here sits
# under them.
modcc.file_prefix_maps = {}
f.puts "#{cmd} = #{cc.command}"
f.puts "#{flags} = #{modcc.all_flags}"
end
f.puts "MRUBY_LD = #{linker.command}"
libgems = gems.reject{|g| g.bin?}
gem_flags = libgems.map {|g| g.linker.flags }
gem_library_paths = libgems.map {|g| g.linker.library_paths }
f.puts "MRUBY_LDFLAGS = #{linker.all_flags(gem_library_paths, gem_flags)} #{linker.option_library_path % "$(MRUBY_PACKAGE_DIR)/#{libdir_name}"}"
gem_flags_before_libraries = libgems.map {|g| g.linker.flags_before_libraries }
f.puts "MRUBY_LDFLAGS_BEFORE_LIBS = #{[linker.flags_before_libraries, gem_flags_before_libraries].flatten.join(' ')}"
gem_libraries = libgems.map {|g| g.linker.libraries }
libmruby = (toolchains.find { |e| e == "visualcpp" }) ? "libmruby" : "mruby"
f.puts "MRUBY_LIBS = #{linker.option_library % libmruby} #{linker.library_flags(gem_libraries)}"
f.puts "MRUBY_LIBMRUBY_PATH = #{libmruby_static.replace_prefix_by(build_dir => "$(MRUBY_PACKAGE_DIR)")}"
end
end
products << libmruby_static
# The license text of the gems in the archive is a product beside it, not
# a member of it.
products << "#{build_dir}/LEGAL"
end