first round patches for osx support

Relatively non-intrusive patches cherry-picked from the wip-osx pile. In particular, these are not OSX specific, but rather (1) generally increase portability by using feature tests and (2) fix a build problem with case-insensitive file systems.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>