merge with google svn patch

there are 5 another commits at all.
I make patches and apply they.
Only makefiles generate conflicts.