Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / third-party / mruby / tasks / mrbgems.rake
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_objs << 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.reverse_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[]
34         f.puts %Q[#include <mruby.h>]
35         f.puts %Q[]
36         f.write gem_func_decls
37         unless gem_final_calls.empty?
38         f.puts %Q[]
39           f.puts %Q[static void]
40           f.puts %Q[mrb_final_mrbgems(mrb_state *mrb) {]
41           f.write gem_final_calls
42           f.puts %Q[}]
43         end
44         f.puts %Q[]
45         f.puts %Q[void]
46         f.puts %Q[mrb_init_mrbgems(mrb_state *mrb) {]
47         f.write gem_init_calls
48         f.puts %Q[  mrb_state_atexit(mrb, mrb_final_mrbgems);] unless gem_final_calls.empty?
49         f.puts %Q[}]
50       end
51     end
52   end
53
54   # legal documents
55   file "#{build_dir}/LEGAL" => [MRUBY_CONFIG, __FILE__] do |t|
56     FileUtils.mkdir_p File.dirname t.name
57     open(t.name, 'w+') do |f|
58      f.puts <<LEGAL
59 Copyright (c) #{Time.now.year} mruby developers
60
61 Permission is hereby granted, free of charge, to any person obtaining a
62 copy of this software and associated documentation files (the "Software"),
63 to deal in the Software without restriction, including without limitation
64 the rights to use, copy, modify, merge, publish, distribute, sublicense,
65 and/or sell copies of the Software, and to permit persons to whom the
66 Software is furnished to do so, subject to the following conditions:
67
68 The above copyright notice and this permission notice shall be included in
69 all copies or substantial portions of the Software.
70
71 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
72 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
73 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
74 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
75 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
76 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
77 DEALINGS IN THE SOFTWARE.
78 LEGAL
79
80       if enable_gems?
81         f.puts <<GEMS_LEGAL
82
83 Additional Licenses
84
85 Due to the reason that you choosed additional mruby packages (GEMS),
86 please check the following additional licenses too:
87 GEMS_LEGAL
88
89         gems.map do |g|
90           authors = [g.authors].flatten.sort.join(", ")
91           f.puts
92           f.puts "GEM: #{g.name}"
93           f.puts "Copyright (c) #{Time.now.year} #{authors}"
94           f.puts "License: #{g.licenses}"
95         end
96       end
97     end
98   end
99 end