Mac OS X build support + some minor refactoring on build scripts