[MLton-commit] r6403

Matthew Fluet fluet at mlton.org
Thu Feb 14 09:04:57 PST 2008


Integrate Wesley Teprstra's cross compiler option changed patch:

 I earlier had people add the '-b' flag as gcc needed it for cross compiling. Newer gcc
 no longer accepts this option. Instead, the platform prefixs the gcc executable. This
 patch corrects this. If the old behaviour is needed for old gcc, a simple shell
 wrapper works.

 Also, when cross compiling, not only gcc, but also ar and ranlib need the executable
 prefix. The runtime/Makefile also presumed CC=gcc at one point.

Some changes from the original patch:
 * the "-cc <gcc>" expert option is documented to accept a path to the
   gcc executable; only prefix the target to the file portion of the
   path.


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

U   mlton/trunk/mlton/main/main.fun
U   mlton/trunk/runtime/Makefile

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

Modified: mlton/trunk/mlton/main/main.fun
===================================================================
--- mlton/trunk/mlton/main/main.fun	2008-02-14 16:15:52 UTC (rev 6402)
+++ mlton/trunk/mlton/main/main.fun	2008-02-14 17:04:57 UTC (rev 6403)
@@ -851,7 +851,23 @@
       fun tokenize l =
          String.tokens (concat (List.separate (l, " ")), Char.isSpace)
 
-      val gcc = !gcc
+      (* When cross-compiling, use the named cross compiler.
+       * Older gcc versions used -b for multiple targets.
+       * If this is still needed, a shell script wrapper can hide this.
+       *)
+      val gcc = 
+         case target of 
+            Cross s => 
+               let
+                  val {dir = gccDir, file = gccFile} =
+                     OS.Path.splitDirFile (!gcc)
+               in 
+                  OS.Path.joinDirFile
+                  {dir = gccDir,
+                   file = s ^ "-" ^ gccFile}
+               end 
+          | Self => !gcc
+
       fun addTargetOpts opts =
          List.fold
          (!opts, [], fn ({opt, pred}, ac) =>
@@ -872,15 +888,6 @@
          List.concat [[concat ["-L", !libTargetDir],
                        if !debugRuntime then "-lmlton-gdb" else "-lmlton"],
                       addTargetOpts linkOpts]
-      (* With gcc 3.4, the '-b <arch>' must be the first argument. *)
-      val targetOpts =
-         case target of
-            Cross s =>
-               if Cygwin = MLton.Platform.OS.host
-                  andalso String.hasSubstring (s, {substring = "mingw"})
-                  then ["-mno-cygwin"]
-               else ["-b", s]
-          | Self => []
       val _ =
          if not (hasCodegen (!codegen))
             then usage (concat ["can't use ",
@@ -1079,8 +1086,7 @@
                                System.system
                                 (gcc,
                                  List.concat
-                                  [targetOpts,
-                                   ["-o", output],
+                                  [["-o", output],
                                    if !debug then gccDebug else [],
                                    inputs,
                                    linkOpts]))
@@ -1128,8 +1134,7 @@
                            System.system
                             (gcc,
                              List.concat
-                             [targetOpts,
-                              [ "-std=gnu99", "-c" ],
+                             [[ "-std=gnu99", "-c" ],
                               if !debug then debugSwitches else [],
                               ccOpts,
                               ["-o", output],
@@ -1144,8 +1149,7 @@
                            System.system
                            (gcc,
                             List.concat
-                            [targetOpts,
-                             ["-c"],
+                            [["-c"],
                              if !debug then [asDebug] else [],
                              asOpts,
                              ["-o", output],

Modified: mlton/trunk/runtime/Makefile
===================================================================
--- mlton/trunk/runtime/Makefile	2008-02-14 16:15:52 UTC (rev 6402)
+++ mlton/trunk/runtime/Makefile	2008-02-14 17:04:57 UTC (rev 6403)
@@ -9,13 +9,24 @@
 PATH := ../bin:$(shell echo $$PATH)
 
 TARGET := self
+
+ifeq ($(TARGET), self)
+CC := gcc -std=gnu99
+AR := ar rc
+RANLIB := ranlib
+else
+CC := $(TARGET)-gcc -std=gnu99
+AR := $(TARGET)-ar rc
+RANLIB := $(TARGET)-ranlib
+endif
+
 TARGET_ARCH := $(shell ../bin/host-arch)
 TARGET_OS := $(shell ../bin/host-os)
 GCC_MAJOR_VERSION :=						\
-	$(shell gcc -v 2>&1 | grep 'gcc version' | 		\
+	$(shell $(CC) -v 2>&1 | grep 'gcc version' | 		\
 		sed 's/.*gcc version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1/')
 GCC_MINOR_VERSION :=						\
-	$(shell gcc -v 2>&1 | grep 'gcc version' | 		\
+	$(shell $(CC) -v 2>&1 | grep 'gcc version' | 		\
 		sed 's/.*gcc version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\2/')
 GCC_VERSION := $(GCC_MAJOR_VERSION).$(GCC_MINOR_VERSION)
 
@@ -94,16 +105,6 @@
 FLAGS += -funroll-all-loops
 endif
 
-ifeq ($(TARGET), self)
-AR := ar rc
-RANLIB := ranlib
-else
-AR := $(TARGET)-ar rc
-RANLIB := $(TARGET)-ranlib
-FLAGS += -b $(TARGET)
-endif
-
-CC := gcc -std=gnu99
 CPPFLAGS :=
 CFLAGS := -I. -Iplatform $(FLAGS)
 OPTCFLAGS := $(CFLAGS) $(CPPFLAGS) $(OPTFLAGS)




More information about the MLton-commit mailing list