Partial merge of mingw

Up to 879b678ab3e2f8b0df0874e6fc447f3838658865