[270] | 1 | MRuby.each_target do
|
---|
| 2 | if enable_gems?
|
---|
| 3 | # set up all gems
|
---|
| 4 | gems.each(&:setup)
|
---|
| 5 | gems.check self
|
---|
| 6 |
|
---|
| 7 | # loader all gems
|
---|
| 8 | self.libmruby << objfile("#{build_dir}/mrbgems/gem_init")
|
---|
| 9 | file objfile("#{build_dir}/mrbgems/gem_init") => ["#{build_dir}/mrbgems/gem_init.c", "#{build_dir}/LEGAL"]
|
---|
| 10 | file "#{build_dir}/mrbgems/gem_init.c" => [MRUBY_CONFIG, __FILE__] do |t|
|
---|
| 11 | FileUtils.mkdir_p "#{build_dir}/mrbgems"
|
---|
| 12 | open(t.name, 'w') do |f|
|
---|
| 13 | gem_func_gems = gems.select { |g| g.generate_functions }
|
---|
| 14 | gem_func_decls = gem_func_gems.each_with_object('') do |g, s|
|
---|
| 15 | s << "void GENERATED_TMP_mrb_#{g.funcname}_gem_init(mrb_state*);\n" \
|
---|
| 16 | "void GENERATED_TMP_mrb_#{g.funcname}_gem_final(mrb_state*);\n"
|
---|
| 17 | end
|
---|
| 18 | gem_init_calls = gem_func_gems.each_with_object('') do |g, s|
|
---|
| 19 | s << " GENERATED_TMP_mrb_#{g.funcname}_gem_init(mrb);\n"
|
---|
| 20 | end
|
---|
| 21 | gem_final_calls = gem_func_gems.each_with_object('') do |g, s|
|
---|
| 22 | s << " GENERATED_TMP_mrb_#{g.funcname}_gem_final(mrb);\n"
|
---|
| 23 | end
|
---|
| 24 | f.puts %Q[/*]
|
---|
| 25 | f.puts %Q[ * This file contains a list of all]
|
---|
| 26 | f.puts %Q[ * initializing methods which are]
|
---|
| 27 | f.puts %Q[ * necessary to bootstrap all gems.]
|
---|
| 28 | f.puts %Q[ *]
|
---|
| 29 | f.puts %Q[ * IMPORTANT:]
|
---|
| 30 | f.puts %Q[ * This file was generated!]
|
---|
| 31 | f.puts %Q[ * All manual changes will get lost.]
|
---|
| 32 | f.puts %Q[ */]
|
---|
| 33 | f.puts %Q[]
|
---|
[331] | 34 | f.puts %Q[#include <mruby.h>]
|
---|
[270] | 35 | f.puts %Q[]
|
---|
| 36 | f.write gem_func_decls
|
---|
| 37 | f.puts %Q[]
|
---|
| 38 | f.puts %Q[static void]
|
---|
| 39 | f.puts %Q[mrb_final_mrbgems(mrb_state *mrb) {]
|
---|
| 40 | f.write gem_final_calls
|
---|
| 41 | f.puts %Q[}]
|
---|
| 42 | f.puts %Q[]
|
---|
| 43 | f.puts %Q[void]
|
---|
| 44 | f.puts %Q[mrb_init_mrbgems(mrb_state *mrb) {]
|
---|
| 45 | f.write gem_init_calls
|
---|
| 46 | f.puts %Q[ mrb_state_atexit(mrb, mrb_final_mrbgems);] unless gem_final_calls.empty?
|
---|
| 47 | f.puts %Q[}]
|
---|
| 48 | end
|
---|
| 49 | end
|
---|
| 50 | end
|
---|
| 51 |
|
---|
| 52 | # legal documents
|
---|
| 53 | file "#{build_dir}/LEGAL" => [MRUBY_CONFIG, __FILE__] do |t|
|
---|
| 54 | open(t.name, 'w+') do |f|
|
---|
| 55 | f.puts <<LEGAL
|
---|
| 56 | Copyright (c) #{Time.now.year} mruby developers
|
---|
| 57 |
|
---|
| 58 | Permission is hereby granted, free of charge, to any person obtaining a
|
---|
| 59 | copy of this software and associated documentation files (the "Software"),
|
---|
| 60 | to deal in the Software without restriction, including without limitation
|
---|
| 61 | the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
| 62 | and/or sell copies of the Software, and to permit persons to whom the
|
---|
| 63 | Software is furnished to do so, subject to the following conditions:
|
---|
| 64 |
|
---|
| 65 | The above copyright notice and this permission notice shall be included in
|
---|
| 66 | all copies or substantial portions of the Software.
|
---|
| 67 |
|
---|
| 68 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
| 69 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
| 70 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
---|
| 71 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
| 72 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
| 73 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
---|
| 74 | DEALINGS IN THE SOFTWARE.
|
---|
| 75 | LEGAL
|
---|
| 76 |
|
---|
| 77 | if enable_gems?
|
---|
| 78 | f.puts <<GEMS_LEGAL
|
---|
| 79 |
|
---|
| 80 | Additional Licenses
|
---|
| 81 |
|
---|
| 82 | Due to the reason that you choosed additional mruby packages (GEMS),
|
---|
| 83 | please check the following additional licenses too:
|
---|
| 84 | GEMS_LEGAL
|
---|
| 85 |
|
---|
| 86 | gems.map do |g|
|
---|
| 87 | authors = [g.authors].flatten.sort.join(", ")
|
---|
| 88 | f.puts
|
---|
| 89 | f.puts "GEM: #{g.name}"
|
---|
| 90 | f.puts "Copyright (c) #{Time.now.year} #{authors}"
|
---|
| 91 | f.puts "License: #{g.licenses}"
|
---|
| 92 | end
|
---|
| 93 | end
|
---|
| 94 | end
|
---|
| 95 | end
|
---|
| 96 | end
|
---|