Many build fixes.
Fixes for MacOS.