Initial re-write for OS X

Here is the beginning of the re-write for adding OS X support.

Any additional changes will most likely come from branches with the osx prefix.