Clean up cross-platform compatibility.

- Move compatibility macros to a new header file.
- Sort system include files in alphabetical order.
- Clean up signal handling (thanks to Adam).
Merge pull request #515 from SaberUK/master+compat-cleanup

Clean up cross-platform compatibility.