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).