Index: EcnlProtoTool/trunk/mruby-1.2.0/tasks/mruby_build_commands.rake
===================================================================
--- EcnlProtoTool/trunk/mruby-1.2.0/tasks/mruby_build_commands.rake	(revision 270)
+++ EcnlProtoTool/trunk/mruby-1.2.0/tasks/mruby_build_commands.rake	(revision 281)
@@ -1,3 +1,4 @@
 require 'forwardable'
+require 'digest/md5'
 
 module MRuby
@@ -84,8 +85,10 @@
       if MRUBY_BUILD_HOST_IS_CYGWIN
         _run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags),
-                                :infile => cygwin_filename(infile), :outfile => cygwin_filename(outfile) }
+                                :infile => cygwin_filename(infile), :outfile => cygwin_filename(outfile),
+                                :outdir => File.dirname(outfile), :outfilebase => File.basename(outfile, ".*") }
       else
         _run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags),
-                                :infile => filename(infile), :outfile => filename(outfile) }
+                                :infile => filename(infile), :outfile => filename(outfile),
+                                :outdir => File.dirname(outfile), :outfilebase => File.basename(outfile, ".*") }
       end
     end
@@ -178,5 +181,6 @@
                              :flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
                              :flags_after_libraries => [flags_after_libraries, _flags_after_libraries].flatten.join(' '),
-                             :libs => library_flags.join(' ') }
+                             :libs => library_flags.join(' '),
+                             :outdir => File.dirname(outfile), :outfilebase => File.basename(outfile, ".*") }
       else
         _run link_options, { :flags => all_flags(_library_paths, _flags),
@@ -184,5 +188,6 @@
                              :flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
                              :flags_after_libraries => [flags_after_libraries, _flags_after_libraries].flatten.join(' '),
-                             :libs => library_flags.join(' ') }
+                             :libs => library_flags.join(' '),
+                             :outdir => File.dirname(outfile), :outfilebase => File.basename(outfile, ".*") }
       end
     end
@@ -201,8 +206,37 @@
       FileUtils.mkdir_p File.dirname(outfile)
       _pp "AR", outfile.relative_path
+
+      # reference from emar.py
+      outfilebase = File.dirname(outfile)
+      to_delete = []
+      newargs = []
+      objfiles.each do |orig_name|
+        dir_name = File.dirname(orig_name)
+        dir_name = dir_name.relative_path_from(Dir.pwd)
+        base_name = File.basename(orig_name)
+        parts = base_name.split('.')
+        # h = Digest::MD5.new.update(orig_name).to_s
+        h = Digest::MD5.new.update(orig_name).to_s.slice(0,4)
+        parts[0] += '_' + h
+        newname = parts.join('.')
+        full_newname = File.join(dir_name, newname)
+        if not File.exists?(full_newname)
+          begin # it is ok to fail here, we just don't get hashing
+            FileUtils.cp(orig_name, full_newname)
+            newargs << full_newname
+            to_delete << full_newname
+          rescue
+          end
+        end
+      end
+
       if MRUBY_BUILD_HOST_IS_CYGWIN
-        _run archive_options, { :outfile => cygwin_filename(outfile), :objs => cygwin_filename(objfiles).join(' ') }
-      else
-        _run archive_options, { :outfile => filename(outfile), :objs => filename(objfiles).join(' ') }
+        _run archive_options, { :outfile => cygwin_filename(outfile), :objs => cygwin_filename(newargs).join(' '), :outdir => File.dirname(outfile), :outfilebase => File.basename(outfile, ".*") }
+      else
+        _run archive_options, { :outfile => filename(outfile), :objs => filename(newargs).join(' '), :outdir => File.dirname(outfile), :outfilebase => File.basename(outfile, ".*") }
+      end
+
+      to_delete.each do |d|
+        FileUtils.rm(d)
       end
     end
Index: EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/ca850.rake
===================================================================
--- EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/ca850.rake	(revision 281)
+++ EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/ca850.rake	(revision 281)
@@ -0,0 +1,45 @@
+MRuby::Toolchain.new(:ca850) do |conf|
+  [conf.cc, conf.cxx].each do |cc|
+    cc.command = ENV['CC'] || 'ca850.exe'
+    cc.flags = [ENV['CFLAGS'] || %w(-c -g -Xcxxcom -Xdefvar -Xpro_epi_runtime=off)]
+    cc.include_paths = ["#{MRUBY_ROOT}\\include", "#{MRUBY_ROOT}\\..\\csp\\ca850"]
+    cc.defines = %w(DISABLE_GEMS)
+    cc.option_include_path = '-I%s'
+    cc.option_define = '-D%s'
+    cc.compile_options = "-cpu f3783 \"-devpath=#{DEVICE_FILE_PATH}\" %{infile} -o %{outfile} %{flags}"
+  end
+
+  conf.linker do |linker|
+    linker.command = ENV['LD'] || 'ld850.exe'
+    linker.flags = [ENV['LDFLAGS']]
+    linker.flags_before_libraries = '-Xsid=0xffffffffffffffffffff -rc'
+    linker.libraries = %w(m c r)
+    linker.library_paths = ["#{LIBRARIES_PATH}"]
+    linker.option_library = '-l%s'
+    linker.option_library_path = '-L%s'
+    linker.link_options = "-cpu f3783 -F \"#{DEVICE_FILE_PATH}\" %{objs} -o %{outfile} %{flags} %{flags_before_libraries} %{libs} %{flags_after_libraries}"
+  end
+ 
+  conf.archiver do |archiver|
+    archiver.command = ENV['AR'] || 'ar850.exe'
+    archiver.archive_options = 'q %{outfile} %{objs}'
+  end
+ 
+  conf.yacc do |yacc|
+    yacc.command = ENV['YACC'] || 'bison.exe'
+    yacc.compile_options = '-o %{outfile} %{infile}'
+  end
+ 
+  conf.gperf do |gperf|
+    gperf.command = 'gperf.exe'
+    gperf.compile_options = '-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" %{infile} > %{outfile}'
+  end
+
+  conf.exts do |exts|
+    exts.object = '.o'
+    exts.executable = '.out'
+    exts.library = '.a'
+  end
+
+  conf.file_separator = '\\'
+end
Index: EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/ccrx.rake
===================================================================
--- EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/ccrx.rake	(revision 281)
+++ EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/ccrx.rake	(revision 281)
@@ -0,0 +1,44 @@
+MRuby::Toolchain.new(:ccrx) do |conf|
+  [conf.cc, conf.cxx].each do |cc|
+    cc.command = ENV['CC'] || 'ccrx.exe'
+    cc.flags = [ENV['CFLAGS'] || %w(-debug -fpu -nologo)]
+    cc.include_paths = ["#{MRUBY_ROOT}\\include"]
+    cc.defines = %w(DISABLE_GEMS)
+    cc.option_include_path = '-include=%s'
+    cc.option_define = '-define=%s'
+    cc.compile_options = "%{infile} -isa=rxv1 -lang=c99 -output=obj=%{outfile} %{flags}"
+  end
+
+  conf.linker do |linker|
+    linker.command = ENV['LD'] || 'rlink.exe'
+    linker.flags = [ENV['LDFLAGS']]
+    linker.flags_before_libraries = ''
+    linker.libraries = %w(m c r)
+    linker.option_library = '-library=%s'
+    linker.option_library_path = ''
+    linker.link_options = "-nologo -form=Absolute %{flags} %{objs} -output=%{outfile} %{flags_before_libraries} %{libs} %{flags_after_libraries}"
+  end
+
+  conf.archiver do |archiver|
+    archiver.command = ENV['AR'] || 'rlink.exe'
+    archiver.archive_options = '-nologo -form=library -noprelink -nooptimize -output=%{outfile} %{objs}'
+  end
+
+  conf.yacc do |yacc|
+    yacc.command = ENV['YACC'] || 'bison.exe'
+    yacc.compile_options = '-o %{outfile} %{infile}'
+  end
+
+  conf.gperf do |gperf|
+    gperf.command = 'gperf.exe'
+    gperf.compile_options = '-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" %{infile} > %{outfile}'
+  end
+
+  conf.exts do |exts|
+    exts.object = '.obj'
+    exts.executable = '.abs'
+    exts.library = '.lib'
+  end
+
+  conf.file_separator = '\\'
+end
Index: EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/emscripten.rake
===================================================================
--- EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/emscripten.rake	(revision 281)
+++ EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/emscripten.rake	(revision 281)
@@ -0,0 +1,19 @@
+MRuby::Toolchain.new(:emscripten) do |conf|
+  toolchain :gcc
+
+  conf.cc do |cc|
+    cc.command = "emcc"
+    cc.flags.push(%w(-Wall -Werror-implicit-function-declaration -O0))
+    cc.flags[0].delete_at(cc.flags[0].rindex("-Og"))
+  end
+
+  conf.cxx do |cxx| 
+    cxx.command = "emcc"
+    cxx.flags.push(%w(-Wall -Werror-implicit-function-declaration -O0))
+    cxx.flags[0].delete_at(cxx.flags[0].rindex("-Og"))
+  end
+
+  conf.linker.command = "emcc"
+  conf.archiver.command = "emar"
+  conf.exts.executable = '.js'
+end
Index: EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/visualcpp.rake
===================================================================
--- EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/visualcpp.rake	(revision 270)
+++ EcnlProtoTool/trunk/mruby-1.2.0/tasks/toolchains/visualcpp.rake	(revision 281)
@@ -1,7 +1,10 @@
 MRuby::Toolchain.new(:visualcpp) do |conf|
-  [conf.cc].each do |cc|
+  conf.cc do |cc|
     cc.command = ENV['CC'] || 'cl.exe'
-    # C4013: implicit function declaration
-    cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /we4013 /Zi /MD /O2 /D_CRT_SECURE_NO_WARNINGS)]
+    cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W4 /GS /analyze- /Zc:wchar_t /ZI /Gm /Od /Zc:inline /fp:precise /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /EHsc /DWIN32 /D_DEBUG /D_CONSOLE /D_CRT_SECURE_NO_WARNINGS)]
+    cc.flags << %w(/we4002 /we4003 /we4005 /we4007 /we4010 /we4013 /we4015 /we4020 /we4022 /we4024 /we4028 /we4029 /we4031 /we4033 /we4034 /we4042 /we4047 /we4048 /we4049 /we4056 /we4067 /we4074 /we4079 /we4083 /we4088 /we4089 /we4090 /we4091 /we4094 /we4096 /we4098 /we4099 /we4113 /we4133 /we4715 /we4716)
+    cc.flags << %w(/wd4214 /wd4100 /wd4996)
+    cc.flags << "/Fd\"#{conf.build_dir}\\vc140.pdb\""
+    cc.flags << "/Fp\"%{outdir}\\%{outfilebase}.pch\""
     cc.defines = %w(DISABLE_GEMS MRB_STACK_EXTEND_DOUBLING)
     cc.option_include_path = '/I%s'
@@ -10,7 +13,11 @@
   end
 
-  [conf.cxx].each do |cxx|
+  conf.cxx do |cxx|
     cxx.command = ENV['CXX'] || 'cl.exe'
-    cxx.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || %w(/c /nologo /W3 /Zi /MD /O2 /EHs /D_CRT_SECURE_NO_WARNINGS)]
+    cxx.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || %w(/c /nologo /W4 /GS /analyze- /Zc:wchar_t /ZI /Gm /Od /Zc:inline /fp:precise /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /EHsc /DWIN32 /D_DEBUG /D_CONSOLE /D_CRT_SECURE_NO_WARNINGS)]
+    cxx.flags << %w(/we4002 /we4003 /we4005 /we4007 /we4010 /we4013 /we4015 /we4020 /we4022 /we4024 /we4028 /we4029 /we4031 /we4033 /we4034 /we4042 /we4047 /we4048 /we4049 /we4056 /we4067 /we4074 /we4079 /we4083 /we4088 /we4089 /we4090 /we4091 /we4094 /we4096 /we4098 /we4099 /we4113 /we4133 /we4715 /we4716)
+    cxx.flags << %w(/wd4214 /wd4100 /wd4996)
+    cxx.flags << "/Fd\"#{conf.build_dir}\\vc140.pdb\""
+    cxx.flags << "/Fp\"%{outdir}\\%{outfilebase}.pch\""
     cxx.defines = %w(DISABLE_GEMS MRB_STACK_EXTEND_DOUBLING)
     cxx.option_include_path = '/I%s'
@@ -21,5 +28,8 @@
   conf.linker do |linker|
     linker.command = ENV['LD'] || 'link.exe'
-    linker.flags = [ENV['LDFLAGS'] || %w(/NOLOGO /DEBUG /INCREMENTAL:NO /OPT:ICF /OPT:REF)]
+    linker.flags = [ENV['LDFLAGS'] || %w(/MANIFEST /NXCOMPAT /DYNAMICBASE /MACHINE:X86 /INCREMENTAL /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1)]
+    linker.flags << "/PDB:\"#{conf.build_dir}\\vc140.pdb\""
+    #linker.flags << "/PGD:\"%{outdir}\\%{outfilebase}.pgd\""
+    linker.flags << "/ManifestFile:\"%{outdir}\\%{outfilebase}.exe.intermediate.manifest\""
     linker.libraries = %w()
     linker.library_paths = %w()
