add support for OS X in the build script

This was based on suggestions/feedback by @mn4367 and @npinchot
and fixes #1545