--- runtime/Makefile.orig	2010-06-11 06:35:14.000000000 -0700
+++ runtime/Makefile	2013-03-06 19:55:56.000000000 -0800
@@ -23,6 +23,19 @@
 
 TARGET_ARCH := $(shell ../bin/host-arch)
 TARGET_OS := $(shell ../bin/host-os)
+
+ifeq ($(TARGET), self)
+GCC := gcc
+else
+GCC := $(TARGET)-gcc
+endif
+
+ifeq ($(TARGET_OS), mingw)
+RUN := wine
+else
+RUN :=
+endif
+
 GCC_MAJOR_VERSION :=						\
 	$(shell $(CC) -v 2>&1 | grep 'gcc version' | 		\
 		sed 's/.*gcc version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1/')
@@ -292,7 +305,7 @@
 	cd gdtoa && $(CC) $(OPTCFLAGS) $(OPTWARNCFLAGS) -w -O1 -o arithchk.out arithchk.c
 
 gdtoa/arith.h: gdtoa/arithchk.out
-	cd gdtoa && ./arithchk.out >arith.h
+	cd gdtoa && $(RUN) ./arithchk.out >arith.h
 
 gdtoa/%-pic.o: gdtoa/%.c gdtoa/arith.h
 	$(CC) $(PICCFLAGS) $(PICWARNCFLAGS) -w -DINFNAN_CHECK -c -o $@ $<
@@ -322,7 +335,7 @@
 gen/gen-types.stamp: gen/gen-types.c util.h util.o
 	$(CC) $(OPTCFLAGS) $(WARNCFLAGS) -o gen/gen-types gen/gen-types.c util.o
 	rm -f gen/c-types.h gen/c-types.sml gen/ml-types.h gen/gen-types.stamp
-	cd gen && ./gen-types
+	cd gen && $(RUN) ./gen-types
 	rm -f gen/gen-types$(EXE) gen/gen-types
 	touch $@
 
@@ -333,7 +346,7 @@
 gen/gen-basis-ffi.stamp: gen/gen-basis-ffi.sml gen/basis-ffi.def
 	mlton -output gen/gen-basis-ffi gen/gen-basis-ffi.sml
 	rm -f gen/basis-ffi.h gen/basis-ffi.sml gen/gen-basis-ffi.stamp
-	cd gen && ./gen-basis-ffi
+	cd gen && $(RUN) ./gen-basis-ffi
 	rm -f gen/gen-basis-ffi
 	touch $@
 
@@ -342,7 +355,7 @@
 gen/gen-sizes.stamp: gen/gen-sizes.c libmlton.a $(HFILES)
 	$(CC) $(OPTCFLAGS) $(WARNCFLAGS) -I. -o gen/gen-sizes gen/gen-sizes.c -L. -lmlton
 	rm -f gen/sizes
-	cd gen && ./gen-sizes
+	cd gen && $(RUN) ./gen-sizes
 	rm -f gen/gen-sizes$(EXE) gen/gen-sizes
 	touch $@
 
@@ -370,7 +383,7 @@
 bytecode/print-opcodes: bytecode/print-opcodes.c bytecode/opcode.h $(HFILES)
 	$(CC) $(OPTCFLAGS) $(WARNCFLAGS) -o bytecode/print-opcodes bytecode/print-opcodes.c
 	rm -f bytecode/opcodes
-	cd bytecode && ./print-opcodes > opcodes
+	cd bytecode && $(RUN) ./print-opcodes > opcodes
 
 basis.c: $(BASISCFILES)
 	rm -f basis.c