Add Mac OSX compatibility

Make cv works on OSX and off course keep it compatible with Linux.

Could you merge my changes?
Thanks
BestPig