More MinGW fixes

While setting up MSYS2/MinGW build I have noticed some incomaptibilities, mostly in building Tools.
Here are the minimal changes.