[MLton-commit] r4149

Stephen Weeks MLton@mlton.org
Fri, 4 Nov 2005 11:52:18 -0800


Progress towards a MinGW package.  Includes Wesley's patch from a
couple of weeks back, except for all the slash<->backslash changes in
Makefiles.  I guess those should be kept as a separate patch, perhaps
in package/mingw/, that can be applied to switch to Makefiles usable
on MinGW.


----------------------------------------------------------------------

U   mlton/trunk/Makefile
U   mlton/trunk/bin/add-cross
U   mlton/trunk/mlton/Makefile
U   mlton/trunk/mlton/main/main.fun
U   mlton/trunk/runtime/platform/mingw.c
U   mlton/trunk/runtime/platform/mingw.h

----------------------------------------------------------------------

Modified: mlton/trunk/Makefile
===================================================================
--- mlton/trunk/Makefile	2005-11-04 17:45:17 UTC (rev 4148)
+++ mlton/trunk/Makefile	2005-11-04 19:52:16 UTC (rev 4149)
@@ -19,6 +19,11 @@
 RUN = $(SRC)/runtime
 MLTON = $(BIN)/mlton
 AOUT = mlton-compile
+ifeq (mingw, $(TARGET_OS))
+EXE = .exe
+else
+EXE =
+endif
 MLBPATHMAP = $(LIB)/mlb-path-map
 TARGETMAP = $(LIB)/target-map
 SPEC = package/rpm/mlton.spec
@@ -46,7 +51,7 @@
 # stubs.  Remove $(AOUT) so that the $(MAKE) compiler below will
 # remake MLton.
 ifeq (other, $(shell if [ ! -x $(BIN)/mlton ]; then echo other; fi))
-	rm -f $(COMP)/$(AOUT)
+	rm -f $(COMP)/$(AOUT)$(EXE)
 endif
 	$(MAKE) script mlbpathmap targetmap constants compiler world libraries tools
 	@echo 'Build of MLton succeeded.'
@@ -92,7 +97,7 @@
 .PHONY: compiler
 compiler:
 	$(MAKE) -C $(COMP)
-	$(CP) $(COMP)/$(AOUT) $(LIB)/
+	$(CP) $(COMP)/$(AOUT)$(EXE) $(LIB)/
 
 .PHONY: constants
 constants:
@@ -300,7 +305,11 @@
 	$(MAKE) -C $(NLFFIGEN)
 	$(MAKE) -C $(PROF)
 	$(MAKE) -C $(YACC)
-	$(CP) $(LEX)/$(LEX) $(NLFFIGEN)/$(NLFFIGEN) $(PROF)/$(PROF) $(YACC)/$(YACC) $(BIN)/
+	$(CP) $(LEX)/$(LEX)$(EXE) 		\
+		$(NLFFIGEN)/$(NLFFIGEN)$(EXE)	\
+		$(PROF)/$(PROF)$(EXE)		\
+		$(YACC)/$(YACC)$(EXE)		\
+		$(BIN)/
 
 .PHONY: version
 version:
@@ -321,7 +330,7 @@
 world-no-check: 
 	@echo 'Making world.'
 	$(MAKE) basis-no-check
-	$(LIB)/$(AOUT) @MLton -- $(LIB)/world
+	$(LIB)/$(AOUT)$(EXE) @MLton -- $(LIB)/world
 
 .PHONY: world
 world: 

Modified: mlton/trunk/bin/add-cross
===================================================================
--- mlton/trunk/bin/add-cross	2005-11-04 17:45:17 UTC (rev 4148)
+++ mlton/trunk/bin/add-cross	2005-11-04 19:52:16 UTC (rev 4149)
@@ -89,8 +89,19 @@
         mmake TARGET=$crossTarget TARGET_ARCH=$crossArch TARGET_OS=$crossOS \
                 mlbpathmap targetmap )
 
+case "$crossOS" in
+mingw)
+	suf='.exe'
+;;
+*)
+	suf=''
+;;
+esac
 
 case "$crossOS" in
+mingw)
+	libs='-lws2_32 -lkernel32 -lpsapi -lnetapi32'
+;;
 solaris)
         libs='-lrt -lnsl -lsocket'
 ;;
@@ -103,5 +114,5 @@
         ssh $machine "cd $tmp/runtime &&
                         cat >$exe.c && 
                         gcc -I. -o $exe $exe.c libmlton.a -lgmp -lm $libs"
-ssh $machine "$tmp/runtime/$exe" >"$lib/$crossTarget/constants"
+ssh $machine "$tmp/runtime/$exe$suf" >"$lib/$crossTarget/constants"
 ssh $machine "rm -rf $tmp"

Modified: mlton/trunk/mlton/Makefile
===================================================================
--- mlton/trunk/mlton/Makefile	2005-11-04 17:45:17 UTC (rev 4148)
+++ mlton/trunk/mlton/Makefile	2005-11-04 19:52:16 UTC (rev 4149)
@@ -9,6 +9,7 @@
 SRC = $(shell cd .. && pwd)
 BUILD = $(SRC)/build
 BIN = $(BUILD)/bin
+HOST_OS = $(shell $(SRC)/bin/host-os)
 LIB = $(BUILD)/lib
 MLTON = mlton
 TARGET = self
@@ -23,16 +24,21 @@
   FILE = mlton.mlb
   FLAGS += -default-ann 'sequenceNonUnit warn'
 else
-ifeq (cygwin, $(shell $(SRC)/bin/host-os))
+ifeq (cygwin, $(HOST_OS))
   # The stubs don't work on Cygwin, since they define spawn in terms of
   # fork, and fork doesn't work on Cygwin.  So, make without the stubs.
   FILE = mlton.cm
 else
+ifeq (mingw, $(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)

Modified: mlton/trunk/mlton/main/main.fun
===================================================================
--- mlton/trunk/mlton/main/main.fun	2005-11-04 17:45:17 UTC (rev 4148)
+++ mlton/trunk/mlton/main/main.fun	2005-11-04 19:52:16 UTC (rev 4149)
@@ -69,7 +69,9 @@
    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 +544,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 +714,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)

Modified: mlton/trunk/runtime/platform/mingw.c
===================================================================
--- mlton/trunk/runtime/platform/mingw.c	2005-11-04 17:45:17 UTC (rev 4148)
+++ mlton/trunk/runtime/platform/mingw.c	2005-11-04 19:52:16 UTC (rev 4149)
@@ -489,6 +489,13 @@
         die ("kill not implemented");
 }
 
+int nanosleep (const struct timespec *req, struct timespec *rem) {
+        Sleep (req->tv_sec * 1000 + (req->tv_nsec + 999) / 1000);
+        rem->tv_nsec = 0;
+        rem->tv_sec = 0;
+        return 0;
+}
+
 int pause (void) {
         die ("pause not implemented");
 }

Modified: mlton/trunk/runtime/platform/mingw.h
===================================================================
--- mlton/trunk/runtime/platform/mingw.h	2005-11-04 17:45:17 UTC (rev 4148)
+++ mlton/trunk/runtime/platform/mingw.h	2005-11-04 19:52:16 UTC (rev 4149)
@@ -302,6 +302,11 @@
 pid_t fork (void);
 int kill (pid_t pid, int sig);
 int pause (void);
+struct timespec {
+ time_t tv_sec;
+ long tv_nsec;
+};
+int nanosleep (const struct timespec *req, struct timespec *rem);
 unsigned int sleep (unsigned int seconds);
 pid_t wait (int *status);
 pid_t waitpid (pid_t pid, int *status, int options);