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
