summaryrefslogtreecommitdiffhomepage
path: root/tasks/mrbgems.rake
blob: 07e412b53cbf8173e4b4acc84341e65bc1d282b5 (plain)
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
dir = File.dirname(__FILE__).sub(%r|^\./|, '')

MRuby.each_target do
  if enable_gems?
    self.libmruby << "#{build_dir}/mrbgems/gem_init.o"

    file "#{build_dir}/mrbgems/gem_init.o" => "#{build_dir}/mrbgems/gem_init.c"
    file "#{build_dir}/mrbgems/gem_init.c" do |t|
      FileUtils.mkdir_p "#{build_dir}/mrbgems"
      open(t.name, 'w') do |f|
        f.puts <<__EOF__
/*
 * This file contains a list of all
 * initializing methods which are
 * necessary to bootstrap all gems.
 *
 * IMPORTANT:
 *   This file was generated!
 *   All manual changes will get lost.
 */

#include "mruby.h"

#{gems.map{|gem| "void GENERATED_TMP_mrb_%s_gem_init(mrb_state* mrb);" % [gem.funcname]}.join("\n")}
void
mrb_init_mrbgems(mrb_state *mrb) {
#{gems.map{|gem| "GENERATED_TMP_mrb_%s_gem_init(mrb);" % [gem.funcname]}.join("\n")}
}
__EOF__
      end
    end

    file "#{build_dir}/mrbgems/gem_init.c" => MRUBY_CONFIG
  end
end