Fix MinGW compilation by splitting source files.  Addresses gh-2709.

Still needs testing on Windows, since after the fix I'm now hitting a Wine bug as discussed on £2709.