Added a bunch of missing compile time checks, now builds on NetBSD.