Various build system fixes for Windows (and particularly MingW cross-compiling to Windows). Fixes Bug #1179683.