compat: enable building on OS X

OS X lacks some Linux (and recent POSIX) specific functionality; implement
the required OS X equivalents in compat.h and add OS X Makefile rules in
compat.mk.

In the Python CFFI wrapper, load the .dylib module on darwin.