osx makefile backport of be34510

Copied changes from commit be34510a9a17b3be83e817d6e58c9023a48e75bc to osx makefile