Support building tools on Windows, more MinGW

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