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

SCM Repository

[diderot] View of /branches/pure-cfg/src/compiler/c-target/run-cc.sml
ViewVC logotype

View of /branches/pure-cfg/src/compiler/c-target/run-cc.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 998 - (download) (annotate)
Wed Apr 27 17:38:21 2011 UTC (8 years, 4 months ago) by jhr
File size: 1493 byte(s)
  Include extra libs in link command
(* run-cc.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Support for running the C compiler to compile and link the generated code.
 *)

structure RunCC : sig

  (* compile "base" -- compiles the file "base.c" to produce "base.o". *)
    val compile : string -> unit

  (* link "base" -- links base.o with the Diderot runtime to produce the executable
   * "base".
   *)
    val link : string -> unit

  end = struct

  (* FIXME: control flags that should go somewhere else *)
    val debug = ref false
    val verbose = ref true

    fun system cmd = (
	  if !verbose
	    then print(cmd ^ "\n")
	    else ();
	  if OS.Process.isSuccess(OS.Process.system cmd)
	    then ()
	    else raise Fail "error compiling/linking")

    fun compile baseName = let
	  val cFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"c"}
	  val cflags = if !debug
		then Paths.cflags
		else String.concatWith " " ["-DNDEBUG", Paths.cflags]
	  val cmd = String.concatWith " " [
		  Paths.cc, "-c", cflags,
		  "-I" ^ Paths.diderotInclude, "-I" ^ Paths.teemInclude,
		  cFile
		]
	  in
	    system cmd
	  end

    fun link baseName = let
	  val objFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"o"}
	  val exeFile = baseName
	  val cmd = String.concatWith " " ([
		  Paths.cc, "-o", exeFile, objFile,
		  OS.Path.concat(Paths.diderotLib, "diderot-lib.o")
		] @ Paths.teemLinkFlags @ [Paths.extraLibs])
	  in
	    system cmd
	  end

  end

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