Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/c-util/run-cc.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/c-util/run-cc.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2489, Mon Oct 21 19:43:32 2013 UTC revision 2490, Mon Oct 21 21:17:25 2013 UTC
# Line 11  Line 11 
11    (* compile ("base", cflags) -- compiles the file "base.c" to produce "base.o". *)    (* compile ("base", cflags) -- compiles the file "base.c" to produce "base.o". *)
12      val compile : string * string list -> unit      val compile : string * string list -> unit
13    
14    (* link ("base", opts) -- links base.o using the given options (libraries, etc.) *)    (* linkExec ("base", opts) -- links base.o to create an executable using the
15      val link : string * string list -> unit     * given options (libraries, etc.)
16       *)
17        val linkExec : string * string list -> unit
18    
19      (* linkLib ("base", opts) -- links base.o to create using the given options (libraries, etc.) *)
20        val linkLib : string * string list -> unit
21    
22    end = struct    end = struct
23    
# Line 29  Line 34 
34              PhaseTimer.withTimer Timers.timeCC system cmd              PhaseTimer.withTimer Timers.timeCC system cmd
35            end            end
36    
37      fun link (baseName, ldOpts) = let      fun linkExec (baseName, ldOpts) = let
38            val objFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"o"}            val objFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"o"}
39            val exeFile = baseName            val exeFile = baseName
40            val cmd = String.concatWith " " ([Paths.cc, "-o", exeFile, objFile] @ ldOpts)            val cmd = String.concatWith " " ([Paths.cc, "-o", exeFile, objFile] @ ldOpts)
# Line 37  Line 42 
42              PhaseTimer.withTimer Timers.timeCC system cmd              PhaseTimer.withTimer Timers.timeCC system cmd
43            end            end
44    
45        fun linkLib (baseName, ldOpts) = let
46              val objFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"o"}
47              val tmpFile = let
48                  (* on Linux systems, the rename fails if the src and dst are on
49                   * different devices, so we create the temp file in the same
50                   * directory as the final target.
51                   *)
52                    val {file, ...} = OS.Path.splitDirFile(OS.FileSys.tmpName())
53                    val {dir, ...} = OS.Path.splitDirFile baseName
54                    in
55                      OS.Path.joinDirFile{
56                          dir = dir,
57                          file = OS.Path.joinBaseExt{
58                              base = file,
59                              ext = SOME "o"
60                            }
61                        }
62                    end
63              val cmd = String.concatWith " " ([Paths.ld, "-r", "-o", tmpFile, objFile] @ ldOpts)
64              fun link () = (
65                    system cmd;
66                    Log.msg(concat["rename ", tmpFile, " to ", objFile, "\n"]);
67                    OS.FileSys.rename{old=tmpFile, new=objFile}
68                      handle ex => (OS.FileSys.remove tmpFile; raise ex))
69              in
70                PhaseTimer.withTimer Timers.timeCC link ()
71              end
72    
73    end    end

Legend:
Removed from v.2489  
changed lines
  Added in v.2490

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0