Import r39590 from ruby trunk

It is impossible to predict which file will be installed to where, by
the arguments, so use intermediate destination directory always.

Patch by nobu