Multi platform; Add OS X support.

@ljos: Can you check if this works on OSX?  Preferably without compilation warnings.  And merge it when you like it.