Re: target-map considered harmful

"Wesley W. Terpstra" <[email protected]>
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <[email protected]>
On Wed, Jan 6, 2010 at 3:50 PM, Matthew Fluet <[email protected]> wrote:
> That seems like a fine solution.  I would suggest that we put all of
> the targets within a single "target" directory of the lib directory.
> That would make it easy to find all the targets.
>
> It might also be good to move the c-types.sml file into the
> target-specific directory.  Then a target would be entirely self
> contained.

I've attached a patch which does this and committed two orthogonal
(but necessary) changes to svn/HEAD.

As you can see in the patch, I've moved the target directories into a
'targets' sub-folder in the mlton lib directory. The OS and
Architecture are listed in the files 'os' and 'arch' respectively in
the appropriate target folder. Finally, I moved c-types.sml into an
'sml' folder for the given target. The directory layout looks now
like:

terpstra@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.

_______________________________________________
MLton mailing list
[email protected]
http://mlton.org/mailman/listinfo/mlton
targets.patch (text/x-diff, 9.7 KB)
Index: mlton/main/main.fun
===================================================================
--- mlton/main/main.fun	(revision 7389)
+++ mlton/main/main.fun	(working copy)
@@ -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
Index: basis-library/c-types.mlb
===================================================================
--- basis-library/c-types.mlb	(revision 7389)
+++ basis-library/c-types.mlb	(working copy)
@@ -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
+         ../../targets/$(TARGET)/sml/c-types.sml
       end end
    in
       structure C_Char
Index: basis-library/build/sources.mlb
===================================================================
--- basis-library/build/sources.mlb	(revision 7389)
+++ basis-library/build/sources.mlb	(working copy)
@@ -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
+      ../../../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
+      ../../../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
+      ../../../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
+      ../../../targets/$(TARGET)/sml/c-types.sml
       ../config/c/position.sml
       ../config/c/sys-word.sml
    end end
Index: basis-library/primitive/primitive.mlb
===================================================================
--- basis-library/primitive/primitive.mlb	(revision 7389)
+++ basis-library/primitive/primitive.mlb	(working copy)
@@ -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
+      ../../../targets/$(TARGET)/sml/c-types.sml
       ../config/c/errno.sml
       ../config/c/position.sml
       ../config/c/sys-word.sml
Index: Makefile
===================================================================
--- Makefile	(revision 7389)
+++ Makefile	(working copy)
@@ -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'"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.