--- bin/mlton	2007-08-30 07:10:03.000000000 +0800
+++ bin/mlton	2024-12-31 03:19:24.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'
@@ -70,11 +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"
-fi
-if [ -d '/sw/lib' ]; then
-        darwinLinkOpts="$darwinLinkOpts -L/sw/lib"
+if [ -d '@PREFIX@/lib' ]; then
+        darwinLinkOpts="$darwinLinkOpts -L@PREFIX@/lib"
 fi
 
 doit "$lib" \
@@ -82,12 +79,15 @@
         -cc-opt-quote "-I$lib/include"                           \
         -cc-opt '-O1'                                            \
         -cc-opt '-fno-strict-aliasing -fomit-frame-pointer -w'   \
+        -cc-opt '-Wno-error=int-conversion'                      \
+        -cc-opt '-Wno-error=incompatible-pointer-types'          \
         -link-opt '-lgdtoa -lm -lgmp'                            \
         -mlb-path-map "$lib/mlb-path-map"                        \
         -target-as-opt amd64 '-m64'                              \
         -target-cc-opt amd64 '-m64'                              \
-        -target-cc-opt darwin                                    \
-                '-I/opt/local/include -I/sw/include'             \
+        -target-cc-opt powerpc64 '-arch ppc64'                   \
+        -target-cc-opt powerpc '-arch ppc'                       \
+        -target-cc-opt darwin '-I@PREFIX@/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 +100,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	2007-08-27 05:03:52.000000000 +0800
+++ lib/mlton/include/platform/darwin.h	2024-12-31 03:14:08.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,8 +31,14 @@
 #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>
+#include <crt_externs.h> /* for environ */
 
 #define HAS_FEROUND TRUE
 #define HAS_FPCLASSIFY TRUE
@@ -48,4 +58,4 @@
 #define SIGPOLL 7
 #endif
 
-extern char **environ; /* for Posix_ProcEnv_environ */
+#define environ *_NSGetEnviron() /* for Posix_ProcEnv_environ */

--- 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"

--- lib/mlton/include/basis/coerce.h	2007-08-27 05:03:53.000000000 +0800
+++ lib/mlton/include/basis/coerce.h	2024-12-31 03:02:54.000000000 +0800
@@ -1,3 +1,4 @@
+#include <string.h>
 
 #define coerce(n, f, t)                         \
   MLTON_CODEGEN_STATIC_INLINE                   \
