Sync'ed with upstream, added support for Windows, and our previous Debian/Ubuntu changes.