fix build for osx with some real ugly hacks