[MLton] mingwows

Wesley W. Terpstra wesley@terpstra.ca
Thu, 13 Oct 2005 17:17:53 +0200


--Apple-Mail-8-585618511
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

In contrast to the current cygwoes, I am happy to report that
whatever changed lately under MinGW fixed the random VM
crashes that MLton had under MinGW!

The earlier troubles with command-line options turned out
to be a slight bug in MSys when invoking applications in
a pathed directory in the fake root.

A few small tweaks are necessary, and a mlton.bat, but it
is now possible to build native windows apps (and MLton)
with MLton under MinGW.

I've put up a bootstrapped file at
     http://terpstra.ca/MLton-MinGW.tgz
You will need to install
     http://prdownloads.sourceforge.net/mingw/MinGW-4.1.0.exe?download
into C:\MinGW. Then uncompress MLton to C:\MLton.
Finally, add C:\MLton to your path, launch 'cmd.exe' and go!

If you want to rebuild MLton, you will also need
     http://prdownloads.sourceforge.net/mingw/MSYS-1.0.10.exe?download
installed. Finally, you will need to copy sh.exe to bash.exe and copy
the gmp.h and libgmp.a from the pre-built MLton into MinGW.

If the attached patch is applied to your MLton tree, you
can do a 'make all-no-docs' without any problems, afaict.

There are several regressions, and I have not yet managed to
sort out where all of them come from, but at least my project works. :-)

Should mlton.bat be included in the distribution tar.gz?
Should there be an alternate 'install' rule for windows?

--Apple-Mail-8-585618511
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="mlton-mingw.patch"
Content-Disposition: attachment;
	filename=mlton-mingw.patch

Index: mlnlffigen/Makefile
===================================================================
--- mlnlffigen/Makefile	(revision 4105)
+++ mlnlffigen/Makefile	(working copy)
@@ -17,7 +17,7 @@
 
 all:	$(NAME)
 
-$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb)
+$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb | sed 's@\\@/@g')
 	@echo 'Compiling $(NAME)'
 	$(MLTON) $(FLAGS) $(NAME).mlb
 
Index: mllex/Makefile
===================================================================
--- mllex/Makefile	(revision 4105)
+++ mllex/Makefile	(working copy)
@@ -18,11 +18,11 @@
 
 all:	$(NAME)
 
-$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb)
+$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb | sed 's@\\@/@g')
 	@echo 'Compiling $(NAME)'
 	$(MLTON) $(FLAGS) $(NAME).mlb
 
-$(NAME).sml: $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm)
+$(NAME).sml: $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm | sed 's@\\@/@g')
 	mlton -stop sml $(NAME).cm
 
 html/index.html: $(TEX_FILES)
Index: runtime/Posix/Process/nanosleep.c
===================================================================
--- runtime/Posix/Process/nanosleep.c	(revision 4105)
+++ runtime/Posix/Process/nanosleep.c	(working copy)
@@ -1,6 +1,16 @@
 #include "platform.h"
 
+#ifdef _WIN32
 Int Posix_Process_nanosleep (Pointer sec, Pointer nsec) {
+	Int lsec = *(Int*)sec;
+	Int lnsec = *(Int*)nsec;
+	*(Int*)sec = 0;
+	*(Int*)nsec = 0;
+	Sleep((lsec * 1000) + (lnsec + 999) / 1000);
+	return 0;
+}
+#else
+Int Posix_Process_nanosleep (Pointer sec, Pointer nsec) {
         struct timespec rem;
         struct timespec req;
         int res;
@@ -17,3 +27,4 @@
         *(Int*)nsec = rem.tv_nsec;
         return res;
 }
+#endif
Index: mlton/main/main.fun
===================================================================
--- mlton/main/main.fun	(revision 4105)
+++ mlton/main/main.fun	(working copy)
@@ -69,7 +69,7 @@
    Promise.lazy
    (fn () =>
     List.map
-    (File.lines (concat [!Control.libDir, "/target-map"]), fn line =>
+    (File.lines (OS.Path.joinDirFile {dir = !Control.libDir, file = "target-map"}), fn line =>
      case String.tokens (line, Char.isSpace) of
         [target, arch, os] =>
            let
@@ -542,7 +542,7 @@
          case target of
             Cross s => s
           | Self => "self"
-      val _ = libTargetDir := concat [!libDir, "/", targetStr]
+      val _ = libTargetDir := OS.Path.concat (!libDir, targetStr)
       val targetArch = !targetArch
       val archStr = String.toLower (MLton.Platform.Arch.toString targetArch)
       val targetOS = !targetOS
@@ -712,7 +712,7 @@
                      fun temp (suf: string): File.t =
                         let
                            val (f, out) =
-                              File.temp {prefix = concat [tmpDir, "/file"],
+                              File.temp {prefix = OS.Path.concat (tmpDir, "file"),
                                          suffix = suf}
                            val _ = Out.close out
                            val _ = List.push (tempFiles, f)
Index: mlton/Makefile
===================================================================
--- mlton/Makefile	(revision 4105)
+++ mlton/Makefile	(working copy)
@@ -28,11 +28,16 @@
   # fork, and fork doesn't work on Cygwin.  So, make without the stubs.
   FILE = mlton.cm
 else
+ifeq (mingw, $(shell $(SRC)/bin/host-os))
+  # Ditto for MinGW
+  FILE = mlton.cm
+else
   # We're compiling MLton with an older version of itself, so use the stubs for
   # the MLton structure.
   FILE = mlton-stubs.cm
 endif
 endif
+endif
 
 ifeq (new,$(shell PATH=$(BIN):$$PATH; mlton -target self >/dev/null 2>&1 && echo new))
   FLAGS += -target $(TARGET)
@@ -55,7 +60,7 @@
 	front-end/mlb.lex.sml 	\
 	front-end/mlb.grm.sig 	\
 	front-end/mlb.grm.sml	\
-	$(shell if [ -r $(FILE) ]; then mlton -stop f $(FILE); fi)
+	$(shell if [ -r $(FILE) ]; then mlton -stop f $(FILE) | sed 's@\\@/@g'; fi)
 
 .PHONY: all
 all: $(AOUT)
Index: benchmark/Makefile
===================================================================
--- benchmark/Makefile	(revision 4105)
+++ benchmark/Makefile	(working copy)
@@ -20,11 +20,11 @@
 
 all: 	$(NAME)
 
-$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb)
+$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb | sed 's@\\@/@g')
 	@echo 'Compiling $(NAME)'
 	$(MLTON) $(FLAGS) $(NAME).mlb
 
-$(NAME).sml: $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm)
+$(NAME).sml: $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm | sed 's@\\@/@g')
 	mlton -stop sml $(NAME).cm
 
 .PHONY: clean
Index: mlprof/Makefile
===================================================================
--- mlprof/Makefile	(revision 4105)
+++ mlprof/Makefile	(working copy)
@@ -18,11 +18,11 @@
 
 all:	$(NAME)
 
-$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb)
+$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb | sed 's@\\@/@g')
 	@echo 'Compiling $(NAME)'
 	$(MLTON) $(FLAGS) $(NAME).mlb
 
-$(NAME).sml: $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm)
+$(NAME).sml: $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm | sed 's@\\@/@g')
 	mlton -stop sml $(NAME).cm
 
 .PHONY: clean
Index: lib/opengl/Makefile
===================================================================
--- lib/opengl/Makefile	(revision 4105)
+++ lib/opengl/Makefile	(working copy)
@@ -15,7 +15,7 @@
 %_c.o: %_c.c %_h.h
 	gcc -c $<
 
-%: %.cm $(mlton -stop f %.cm) $(GL_OBJS)
+%: %.cm $(mlton -stop f %.cm | sed 's@\\@/@g') $(GL_OBJS)
 	$(mlton) $(MLTON_FLAGS) $< $(GL_OBJS)
 
 .PHONY: all
Index: lib/mlnlffi/memory/platform/memory.x86-mingw.mlb
===================================================================
--- lib/mlnlffi/memory/platform/memory.x86-mingw.mlb	(revision 0)
+++ lib/mlnlffi/memory/platform/memory.x86-mingw.mlb	(revision 0)
@@ -0,0 +1 @@
+../memory.32bit-unix.mlb
Index: mlyacc/Makefile
===================================================================
--- mlyacc/Makefile	(revision 4105)
+++ mlyacc/Makefile	(working copy)
@@ -18,11 +18,11 @@
 
 all:	$(NAME)
 
-$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb)
+$(NAME): $(NAME).mlb $(shell PATH=$(BIN):$$PATH && $(MLTON) -stop f $(NAME).mlb | sed 's@\\@/@g')
 	@echo 'Compiling $(NAME)'
 	$(MLTON) $(FLAGS) $(NAME).mlb
 
-$(NAME).sml: $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm)
+$(NAME).sml: $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm | sed 's@\\@/@g')
 	mlton -stop sml $(NAME).cm
 
 src/yacc.lex.sml: src/yacc.lex
Index: Makefile
===================================================================
--- Makefile	(revision 4105)
+++ Makefile	(working copy)
@@ -46,8 +46,12 @@
 # stubs.  Remove $(AOUT) so that the $(MAKE) compiler below will
 # remake MLton.
 ifeq (other, $(shell if [ ! -x $(BIN)/mlton ]; then echo other; fi))
+ifeq (mingw, $(TARGET_OS))
+	rm -f $(COMP)/$(AOUT).exe
+else
 	rm -f $(COMP)/$(AOUT)
 endif
+endif
 	$(MAKE) script mlbpathmap targetmap constants compiler world libraries tools
 	@echo 'Build of MLton succeeded.'
 
@@ -92,7 +96,11 @@
 .PHONY: compiler
 compiler:
 	$(MAKE) -C $(COMP)
+ifeq (mingw, $(TARGET_OS))
+	$(CP) $(COMP)/$(AOUT).exe $(LIB)/
+else
 	$(CP) $(COMP)/$(AOUT) $(LIB)/
+endif
 
 .PHONY: constants
 constants:
@@ -307,7 +315,11 @@
 	$(MAKE) -C $(NLFFIGEN)
 	$(MAKE) -C $(PROF)
 	$(MAKE) -C $(YACC)
+ifeq (mingw, $(TARGET_OS))
+	$(CP) $(LEX)/$(LEX).exe $(NLFFIGEN)/$(NLFFIGEN).exe $(PROF)/$(PROF).exe $(YACC)/$(YACC).exe $(BIN)/
+else
 	$(CP) $(LEX)/$(LEX) $(NLFFIGEN)/$(NLFFIGEN) $(PROF)/$(PROF) $(YACC)/$(YACC) $(BIN)/
+endif
 
 .PHONY: version
 version:

--Apple-Mail-8-585618511--