refactoring to support building on MacOSX

first pass, doesn’t quite work yet…