OSX build support

I haven't tested this on Linux to see if it breaks anything, but now it builds fine on my Mac.