Fixed OS-specific bits of build system and made a bit more modular