[MLton-commit] r7392

Wesley Terpstra wesley at mlton.org
Mon Jan 11 11:01:26 PST 2010


Remove targetmap, insted using a targets folder:
  Move the target directories into a 'targets' sub-folder in mlton lib. 
  The OS and Architecture are listed in the files 'os' and 'arch' respectively.
  Moved c-types.sml into an 'sml' folder for the given target. 

The purpose of this change is to make it possible to package cross-compiler
targets as a simple sub-folder, possibly copied from the target's native MLton.

The directory layout looks now like:
terpstra at orange:~/mlton/build/lib$ find targets/
targets/
targets/self
targets/self/sml
targets/self/sml/c-types.sml
targets/self/include
targets/self/include/c-types.h
targets/self/arch
targets/self/libgdtoa.a
targets/self/libgdtoa-pic.a
targets/self/constants
targets/self/libmlton.a
targets/self/sizes
targets/self/libgdtoa-gdb.a
targets/self/os
targets/self/libmlton-pic.a
targets/self/libmlton-gdb.a

Most of the changes were to the Makefile.


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

U   mlton/trunk/Makefile
U   mlton/trunk/basis-library/build/sources.mlb
U   mlton/trunk/basis-library/c-types.mlb
U   mlton/trunk/basis-library/primitive/primitive.mlb
U   mlton/trunk/mlton/main/main.fun

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

Modified: mlton/trunk/Makefile
===================================================================
--- mlton/trunk/Makefile	2010-01-07 22:14:16 UTC (rev 7391)
+++ mlton/trunk/Makefile	2010-01-11 19:01:24 UTC (rev 7392)
@@ -26,7 +26,6 @@
 EXE :=
 endif
 MLBPATHMAP := $(LIB)/mlb-path-map
-TARGETMAP := $(LIB)/target-map
 SPEC := package/rpm/mlton.spec
 LEX := mllex
 PROF := mlprof
@@ -59,7 +58,7 @@
 
 .PHONY: all-no-docs
 all-no-docs:
-	$(MAKE) dirs runtime compiler basis-no-check script mlbpathmap targetmap constants libraries tools
+	$(MAKE) dirs runtime compiler basis-no-check script mlbpathmap constants libraries tools
 # Remove $(AOUT) so that the $(MAKE) compiler below will remake MLton.
 # We also want to re-run the just-built tools (mllex and mlyacc)
 # because they may be better than those that were used for the first
@@ -109,9 +108,9 @@
 .PHONY: constants
 constants:
 	@echo 'Creating constants file.'
-	"$(BIN)/mlton" -build-constants true >tmp.c
-	"$(BIN)/mlton" -output tmp tmp.c
-	./tmp >"$(LIB)/$(TARGET)/constants"
+	"$(BIN)/mlton" -target "$(TARGET)" -build-constants true >tmp.c
+	"$(BIN)/mlton" -target "$(TARGET)" -output tmp tmp.c
+	./tmp >"$(LIB)/targets/$(TARGET)/constants"
 	rm -f tmp tmp.exe tmp.c
 
 .PHONY: debugged
@@ -123,7 +122,9 @@
 
 .PHONY: dirs
 dirs:
-	mkdir -p "$(BIN)" "$(LIB)/$(TARGET)/include" "$(INC)"
+	mkdir -p "$(BIN)" "$(INC)"
+	mkdir -p "$(LIB)/targets/$(TARGET)/include"
+	mkdir -p "$(LIB)/targets/$(TARGET)/sml"
 
 .PHONY: docs
 docs: dirs
@@ -177,7 +178,7 @@
 	$(MAKE) dirs runtime
 	$(MAKE) -C "$(COMP)" polyml-mlton
 	$(CP) "$(COMP)/mlton-polyml$(EXE)" "$(LIB)/"
-	$(MAKE) script basis-no-check mlbpathmap targetmap constants libraries-no-check
+	$(MAKE) script basis-no-check mlbpathmap constants libraries-no-check
 	@echo 'Build of MLton succeeded.'
 
 .PHONY: profiled
@@ -197,11 +198,11 @@
 	@echo 'Compiling MLton runtime system for $(TARGET).'
 	$(MAKE) -C runtime
 	$(CP) include/*.h "$(INC)/"
-	$(CP) runtime/*.a "$(LIB)/$(TARGET)/"
-	$(CP) runtime/gen/sizes "$(LIB)/$(TARGET)/"
-	mkdir -p "$(SRC)/basis-library/config/c/$(TARGET_ARCH)-$(TARGET_OS)"
-	$(CP) runtime/gen/c-types.sml \
-		basis-library/config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
+	$(CP) runtime/*.a "$(LIB)/targets/$(TARGET)/"
+	$(CP) runtime/gen/sizes "$(LIB)/targets/$(TARGET)/"
+	$(CP) runtime/gen/c-types.sml "$(LIB)/targets/$(TARGET)/sml/"
+	echo "$(TARGET_OS)" > "$(LIB)/targets/$(TARGET)/os"
+	echo "$(TARGET_ARCH)" > "$(LIB)/targets/$(TARGET)/arch"
 	$(CP) runtime/gen/basis-ffi.sml \
 		basis-library/primitive/basis-ffi.sml
 ifeq ($(OMIT_BYTECODE), yes)
@@ -209,7 +210,7 @@
 	$(CP) runtime/bytecode/opcodes "$(LIB)/"
 endif
 	$(CP) runtime/*.h "$(INC)/"
-	mv "$(INC)/c-types.h" "$(LIB)/$(TARGET)/include"
+	mv "$(INC)/c-types.h" "$(LIB)/targets/$(TARGET)/include"
 	for d in basis basis/Real basis/Word gc platform util; do	\
 		mkdir -p "$(INC)/$$d";					\
 		$(CP) runtime/$$d/*.h "$(INC)/$$d";			\
@@ -218,7 +219,7 @@
 else
 	$(CP) runtime/bytecode/interpret.h "$(INC)"
 endif
-	for x in "$(LIB)"/"$(TARGET)"/*.a; do $(RANLIB) "$$x"; done
+	for x in "$(LIB)/targets/$(TARGET)"/*.a; do $(RANLIB) "$$x"; done
 
 .PHONY: script
 script:
@@ -235,7 +236,7 @@
 	$(MAKE) dirs runtime
 	$(MAKE) -C "$(COMP)" smlnj-mlton
 	smlnj_heap_suffix=`echo 'TextIO.output (TextIO.stdErr, SMLofNJ.SysInfo.getHeapSuffix ());' | sml 2>&1 1> /dev/null` && $(CP) "$(COMP)/mlton-smlnj.$$smlnj_heap_suffix" "$(LIB)/"
-	$(MAKE) script basis-no-check mlbpathmap targetmap constants libraries-no-check
+	$(MAKE) script basis-no-check mlbpathmap constants libraries-no-check
 	@echo 'Build of MLton succeeded.'
 
 .PHONY: smlnj-mlton-dual
@@ -246,14 +247,6 @@
 smlnj-mlton-quad:
 	$(MAKE) SMLNJ_CM_SERVERS_NUM=4 smlnj-mlton
 
-.PHONY: targetmap
-targetmap:
-	touch "$(TARGETMAP)"
-	( echo '$(TARGET) $(TARGET_ARCH) $(TARGET_OS)';		\
-          sed '/$(TARGET)/d' <"$(TARGETMAP)" )			\
-		>>"$(TARGETMAP).tmp"
-	mv "$(TARGETMAP).tmp" "$(TARGETMAP)"
-
 .PHONY: traced
 traced:
 	$(MAKE) -C "$(COMP)" "AOUT=$(AOUT).trace" COMPILE_ARGS="-const 'Exn.keepHistory true' -profile-val true -const 'MLton.debug true' -drop-pass 'deepFlatten'"

Modified: mlton/trunk/basis-library/build/sources.mlb
===================================================================
--- mlton/trunk/basis-library/build/sources.mlb	2010-01-07 22:14:16 UTC (rev 7391)
+++ mlton/trunk/basis-library/build/sources.mlb	2010-01-11 19:01:24 UTC (rev 7392)
@@ -29,7 +29,7 @@
       ../config/objptr/objptr-$(OBJPTR_REP).sml
       ../config/header/header-$(HEADER_WORD).sml
       ../config/seqindex/seqindex-$(SEQINDEX_INT).sml
-      ../config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
+      $(LIB_MLTON_DIR)/targets/$(TARGET)/sml/c-types.sml
    end end
    ../integer/int-inf0.sml
    local
@@ -123,7 +123,7 @@
    in ann "forceUsed" in
       ../config/header/header-$(HEADER_WORD).sml
       ../config/objptr/objptr-$(OBJPTR_REP).sml
-      ../config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
+      $(LIB_MLTON_DIR)/targets/$(TARGET)/sml/c-types.sml
       ../config/c/position.sml
       ../config/c/sys-word.sml
    end end
@@ -156,7 +156,7 @@
    in ann "forceUsed" in
       ../config/header/header-$(HEADER_WORD).sml
       ../config/objptr/objptr-$(OBJPTR_REP).sml
-      ../config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
+      $(LIB_MLTON_DIR)/targets/$(TARGET)/sml/c-types.sml
       ../config/c/position.sml
       ../config/c/sys-word.sml
    end end
@@ -217,7 +217,7 @@
    in ann "forceUsed" in
       ../config/header/header-$(HEADER_WORD).sml
       ../config/objptr/objptr-$(OBJPTR_REP).sml
-      ../config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
+      $(LIB_MLTON_DIR)/targets/$(TARGET)/sml/c-types.sml
       ../config/c/position.sml
       ../config/c/sys-word.sml
    end end

Modified: mlton/trunk/basis-library/c-types.mlb
===================================================================
--- mlton/trunk/basis-library/c-types.mlb	2010-01-07 22:14:16 UTC (rev 7391)
+++ mlton/trunk/basis-library/c-types.mlb	2010-01-11 19:01:24 UTC (rev 7392)
@@ -22,7 +22,7 @@
          config/bind/real-top.sml 
          config/bind/word-top.sml 
       in ann "forceUsed" in
-         config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
+         $(LIB_MLTON_DIR)/targets/$(TARGET)/sml/c-types.sml
       end end
    in
       structure C_Char

Modified: mlton/trunk/basis-library/primitive/primitive.mlb
===================================================================
--- mlton/trunk/basis-library/primitive/primitive.mlb	2010-01-07 22:14:16 UTC (rev 7391)
+++ mlton/trunk/basis-library/primitive/primitive.mlb	2010-01-11 19:01:24 UTC (rev 7392)
@@ -51,7 +51,7 @@
       ../config/objptr/objptr-$(OBJPTR_REP).sml
       ../config/header/header-$(HEADER_WORD).sml
       ../config/seqindex/seqindex-$(SEQINDEX_INT).sml
-      ../config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
+      $(LIB_MLTON_DIR)/targets/$(TARGET)/sml/c-types.sml
       ../config/c/errno.sml
       ../config/c/position.sml
       ../config/c/sys-word.sml

Modified: mlton/trunk/mlton/main/main.fun
===================================================================
--- mlton/trunk/mlton/main/main.fun	2010-01-07 22:14:16 UTC (rev 7391)
+++ mlton/trunk/mlton/main/main.fun	2010-01-11 19:01:24 UTC (rev 7392)
@@ -100,25 +100,41 @@
                         target: string} list =
    Promise.lazy
    (fn () =>
-    List.map
-    (File.lines (OS.Path.joinDirFile {dir = !Control.libDir,
-                                      file = "target-map"}),
-     fn line =>
-     case String.tokens (line, Char.isSpace) of
-        [target, arch, os] =>
-           let
-              val arch =
-                 case MLton.Platform.Arch.fromString arch of
-                    NONE => Error.bug (concat ["strange arch: ", arch])
-                  | SOME a => a
-              val os =
-                 case MLton.Platform.OS.fromString os of
-                    NONE => Error.bug (concat ["strange os: ", os])
-                  | SOME os => os
-           in
-              {arch = arch, os = os, target = target}
-           end
-      | _ => Error.bug (concat ["strange target mapping: ", line])))
+    let
+       val targetsDir =
+          OS.Path.mkAbsolute { path = "targets",
+                               relativeTo = !Control.libDir }
+       val potentialTargets = Dir.lsDirs targetsDir
+       fun targetMap target =
+          let
+             val targetDir =
+                OS.Path.mkAbsolute { path = target,
+                                     relativeTo = targetsDir }
+             val osFile =
+                OS.Path.joinDirFile { dir = targetDir,
+                                      file = "os" }
+             val archFile =
+                OS.Path.joinDirFile { dir = targetDir,
+                                      file = "arch" }
+             val os   = File.contents osFile
+             val arch = File.contents archFile
+             val os   = List.first (String.tokens (os,   Char.isSpace))
+             val arch = List.first (String.tokens (arch, Char.isSpace))
+             val os =
+                case MLton.Platform.OS.fromString os of
+                   NONE => Error.bug (concat ["strange os: ", os])
+                 | SOME os => os
+             val arch =
+                case MLton.Platform.Arch.fromString arch of
+                   NONE => Error.bug (concat ["strange arch: ", arch])
+                 | SOME a => a
+          in
+             SOME { arch = arch, os = os, target = target }
+          end
+          handle _ => NONE
+    in
+       List.keepAllMap (potentialTargets, targetMap)
+    end)
 
 fun setTargetType (target: string, usage): unit =
    case List.peek (targetMap (), fn {target = t, ...} => target = t) of
@@ -832,7 +848,13 @@
          case target of
             Cross s => s
           | Self => "self"
-      val _ = libTargetDir := OS.Path.concat (!libDir, targetStr)
+      val targetsDir =
+         OS.Path.mkAbsolute { path = "targets",
+                              relativeTo = !libDir }
+      val targetDir =
+         OS.Path.mkAbsolute { path = targetStr,
+                              relativeTo = targetsDir }
+      val () = libTargetDir := targetDir
       val targetArch = !Target.arch
       val archStr = String.toLower (MLton.Platform.Arch.toString targetArch)
       val targetOS = !Target.os




More information about the MLton-commit mailing list