--- a/mlton/Makefile
+++ b/mlton/Makefile
@@ -187,31 +208,31 @@ smlnj-mlton: mlton-smlnj.cm control/version.sml $(FRONT_END_SOURCES)
 # MLton.
 #
 POLYML := poly
+CAT := cat
 
 .PHONY: polyml-mlton
-polyml-mlton: mlton-polyml.use $(shell [ -e mlton-polyml.use ] && cat mlton-polyml.use | $(SED) 's/use "\(.*\)";/\1/') control/version.sml $(FRONT_END_SOURCES)
-	(									\
-		echo 'use "mlton-polyml.use";';					\
-		echo 'PolyML.export("$(MLTON_OUTPUT)-polyml", Main.mainWrapped);'; \
-	) | "$(POLYML)"
-	$(CC) -o $(MLTON_OUTPUT)-polyml $(MLTON_OUTPUT)-polyml.o -lpolymain -lpolyml
-	$(RM) $(MLTON_OUTPUT)-polyml.o
+polyml-mlton: $(MLTON_OUTPUT)-polyml
+
+$(MLTON_OUTPUT)-polyml: mlton-polyml.sml $(shell [ -e mlton-polyml.sml ] && $(CAT) mlton-polyml.sml | $(GREP) 'use ".*";' | $(SED) 's/use "\(.*\)";/\1/') control/version.sml $(FRONT_END_SOURCES)
+	polyc -o $@ mlton-polyml.sml
 
-mlton-polyml.use: ../lib/stubs/basis-stubs-for-polyml/sources.use ../lib/stubs/mlton-stubs-for-polyml/sources.use $(shell "$(RUN_MLTON_DEPS)" -stop f ../lib/stubs/mlton-stubs/sources.mlb | $(GREP) 'mlb$$') $(shell "$(RUN_MLTON_DEPS)" -stop f mlton.mlb | $(GREP) 'mlb$$')
+mlton-polyml.sml: ../lib/stubs/basis-stubs-for-polyml/sources.use ../lib/stubs/mlton-stubs-for-polyml/sources.use $(shell "$(RUN_MLTON_DEPS)" -stop f ../lib/stubs/mlton-stubs/sources.mlb | $(GREP) 'mlb$$') $(shell "$(RUN_MLTON_DEPS)" -stop f mlton.mlb | $(GREP) 'mlb$$')
+	chmod +x $(SRC)/bin/mlbdeps
 	(									\
-		cat ../lib/stubs/basis-stubs-for-polyml/sources.use |		\
+		$(CAT) ../lib/stubs/basis-stubs-for-polyml/sources.use |		\
 			$(SED) 's|use "\(.*\)";|../lib/stubs/basis-stubs-for-polyml/\1|'; \
-		"$(RUN_MLTON)" -stop f mlton.mlb | $(GREP) -v 'mlb$$' | $(GREP) 'mlyacc'; \
-		cat ../lib/stubs/mlton-stubs-for-polyml/sources.use |		\
+		$(SRC)/bin/mlbdeps mlton.mlb | $(GREP) -v 'mlb$$' | $(GREP) 'mlyacc'; \
+		$(CAT) ../lib/stubs/mlton-stubs-for-polyml/sources.use |		\
 			$(SED) 's|use "\(.*\)";|../lib/stubs/mlton-stubs-for-polyml/\1|'; \
-		"$(RUN_MLTON)" -stop f ../lib/stubs/mlton-stubs/sources.mlb |	\
+		$(SRC)/bin/mlbdeps ../lib/stubs/mlton-stubs/sources.mlb |	\
 			$(GREP) -v 'mlb$$' |					\
 			$(GREP) 'mlton-stubs';					\
-		"$(RUN_MLTON)" -stop f mlton.mlb |				\
+		$(SRC)/bin/mlbdeps mlton.mlb |				\
 			$(GREP) -v 'mlb$$' |					\
 			$(GREP) -v 'sml/basis' |				\
 			$(GREP) -v 'targets' |					\
 			$(GREP) -v 'mlton-stubs' |				\
 			$(GREP) -v 'mlyacc' |					\
 			$(GREP) -v 'call-main.sml';				\
-	) | $(SED) 's|\(.*\)|use "\1";|' > mlton-polyml.use
+	) | $(SED) 's|\(.*\)|use "\1";|' > $@
+	echo "val main = Main.mainWrapped;" >> $@
