Everything was going well until scriptbuilder.cpp threw a compilation error: down on line 866 it complained that getcwd was an undeclared identifier. The fix was to just make sure that unistd.h was #included:
@@ -11,5 +11,5
#endif
-#if defined(AS_MARMALADE)
+#if defined(AS_MARMALADE) || defined(__APPLE__)
#include <unistd.h>
#endif