--- bin/mlton	2007-08-30 07:10:03.000000000 +0800
+++ bin/mlton	2023-07-21 01:57:07.000000000 +0800
@@ -5,9 +5,9 @@
 set -e
 
 dir=`dirname "$0"`
-lib='/usr/local/lib/mlton'
+lib='@MLTON@'
 eval `"$lib/platform"`
-gcc='gcc'
+gcc='@CC@'
 case "$HOST_OS" in
 mingw)
 	exe='.exe'

--- bin/mlton	2007-08-30 07:10:03.000000000 +0800
+++ bin/mlton	2023-07-21 18:50:31.000000000 +0800
@@ -70,8 +70,8 @@
 # The darwin linker complains (loudly) about non-existent library
 # search paths.
 darwinLinkOpts=''
-if [ -d '/opt/local/lib' ]; then
-        darwinLinkOpts="$darwinLinkOpts -L/opt/local/lib"
+if [ -d '@PREFIX@/lib' ]; then
+        darwinLinkOpts="$darwinLinkOpts -L@PREFIX@/lib"
 fi
 if [ -d '/sw/lib' ]; then
         darwinLinkOpts="$darwinLinkOpts -L/sw/lib"
@@ -86,8 +86,10 @@
         -mlb-path-map "$lib/mlb-path-map"                        \
         -target-as-opt amd64 '-m64'                              \
         -target-cc-opt amd64 '-m64'                              \
+        -target-cc-opt powerpc64 '-arch ppc64'                   \
+        -target-cc-opt powerpc '-arch ppc'                       \
         -target-cc-opt darwin                                    \
-                '-I/opt/local/include -I/sw/include'             \
+                '-I@PREFIX@/include -I/sw/include'               \
         -target-cc-opt freebsd '-I/usr/local/include'            \
         -target-cc-opt netbsd '-I/usr/pkg/include'               \
         -target-cc-opt openbsd '-I/usr/local/include'            \
@@ -100,7 +102,10 @@
                 -malign-jumps=2
                 -malign-loops=2'                                 \
         -target-link-opt amd64 '-m64'                            \
-        -target-link-opt darwin "$darwinLinkOpts"                \
+        -target-link-opt powerpc64 '-arch ppc64'                 \
+        -target-link-opt powerpc '-arch ppc'                     \
+        -target-link-opt darwin                                  \
+                "$darwinLinkOpts -lSystemStubs"                  \
         -target-link-opt freebsd '-L/usr/local/lib/'             \
         -target-link-opt mingw                                   \
                 '-lws2_32 -lkernel32 -lpsapi -lnetapi32'         \

--- lib/mlton/include/platform/darwin.h	2023-07-21 17:53:21.000000000 +0800
+++ lib/mlton/include/platform/darwin.h	2023-07-21 18:14:52.000000000 +0800
@@ -1,3 +1,7 @@
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <fenv.h>
 #include <inttypes.h>
 #include <stdint.h>
@@ -27,6 +31,11 @@
 #include <sys/wait.h>
 #include <syslog.h>
 #include <termios.h>
+
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE /* In order for <ucontext.h> to work. */
+#endif
+
 #include <ucontext.h>
 #include <utime.h>
 
@@ -48,4 +57,5 @@
 #define SIGPOLL 7
 #endif
 
-extern char **environ; /* for Posix_ProcEnv_environ */
+/* for Posix_ProcEnv_environ */
+#define environ *_NSGetEnviron()

--- lib/mlton/include/cenv.h	2007-08-27 05:03:54.000000000 +0800
+++ lib/mlton/include/cenv.h	2023-07-21 18:33:40.000000000 +0800
@@ -61,7 +61,7 @@
 COMPILE_TIME_ASSERT(sizeof_float__is_four, sizeof(float) == 4);
 COMPILE_TIME_ASSERT(sizeof_double__is_eight, sizeof(double) == 8);
 
-#if (defined (__APPLE_CC__))
+#if (defined (__APPLE_CC__) || defined (__APPLE__))
 #define __Darwin__
 #endif
 
@@ -104,7 +104,7 @@
 #include "platform/m68k.h"
 #elif (defined (__mips__))
 #include "platform/mips.h"
-#elif (defined (__ppc__)) || (defined (__powerpc__))
+#elif (defined (__ppc__)) || (defined (__powerpc__)) || (defined (__POWERPC__))
 #include "platform/powerpc.h"
 #elif (defined (__s390__))
 #include "platform/s390.h"
