Osx fixes

It builds on my Mavericks machine. However, some of these changes probably won't work generally.. it's feels like biting the CMake or automake bullet is coming soon. :)

No idea if this stuff'll work on Linux. I can try it out, but it's probably easier for you.