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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/common/paths_sml.in
ViewVC logotype

View of /branches/vis15/src/compiler/common/paths_sml.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4417 - (download) (annotate)
Wed Aug 17 12:22:45 2016 UTC (2 years, 9 months ago) by jhr
File size: 6361 byte(s)
  working on merge
(* paths.sml
 *
 * Various directory paths required by the compiler.
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *
 * @configure_input@
 *)

structure Paths : sig

  (* functions to get the paths to Diderot headers and libraries *)
    val diderotInclude : unit -> string
    val diderotLib : unit -> string

    val teemBin : unit -> string
    val teemInclude : unit -> string
    val teemLinkFlags : unit -> string list

  (* command to run the C++ compiler *)
    val ccxx : string

  (* command-line flags for the C++ compiler *)
    val cxxFlags : {
            base : string,	(* for all targets *)
            parallel : string,	(* for parallel target *)
            cl : string,	(* for OpenCL target *)
            cuda : string,	(* for CUDA target *)
            debug : string,	(* when '--debug' flag is specified *)
            ndebug : string	(* when '--debug' flag is _not_ specified *)
          }

  (* command to link executables *)
    val ld : string

  (* extra libraries to include in the linking command *)
    val extraLibs : {
            base : string,	(* for all targets *)
            parallel : string,	(* for parallel target *)
            cl : string,	(* for OpenCL target *)
            cuda : string	(* for CUDA target *)
          }

  (* true if the configuration supports the OpenCL target *)
    val clEnabled : bool

  (* true if the configuration supports the CUDA target *)
    val cudaEnabled : bool

  end = struct

    local
      val // = OS.Path.concat
      infixr 4 //
    in

  (* installation directories for Diderot stuff *)
    val installBin = "@prefix@" // "bin"
    val installInclude = "@prefix@" // "include"
    val installLib = "@prefix@" // "lib"

  (* directories for Diderot stuff *)
    local
    (* dynamically determine the installation location based on the path to diderotc.  We assume
     * that the bin, lib, and include directories are siblings in the directory tree.
     *)
      val installLoc : string option ref = ref NONE
      fun installLocation () = (case !installLoc
             of SOME loc => loc
              | NONE => let
                  val cmdPath = OS.Path.dir(CommandLine.name())
                  val binDir = if OS.Path.isAbsolute cmdPath
                        then cmdPath
                        else OS.Path.mkCanonical(OS.Path.concat(OS.FileSys.getDir(), cmdPath))
                  val diderotLoc = OS.Path.getParent binDir
                  in
                    installLoc := SOME diderotLoc;
                    diderotLoc
                  end
            (* end case *))
    in
    fun diderotLib () = installLocation() // "lib"
    fun diderotInclude () = installLocation() // "include"
    end

  (* look for an executable using the user's PATH prepended with a list of
   * additional search directories.
   *)
    fun findExe (searchDirs, name) = let
          val dirs = searchDirs @ String.fields
                (fn #":" => true | _ => false)
                  (case (OS.Process.getEnv "PATH") of (SOME p) => p | _ => "")
          in
            case PathUtil.findExe dirs name
             of SOME p => p
              | NONE => raise Fail(concat[
                    "unable to find ", name, " executable in \"",
                    String.concatWith ":" dirs, "\""
                  ])
          end (* getPath *)

  (* directories for Teem stuff *)
    local
      val teemDir : string option ref = ref NONE
    (* return the path to the teem stuff *)
      fun resolveTeemDir subDir = (case !teemDir
             of SOME dir => dir // subDir
              | NONE => let
                (* extra places to look for unu *)
                  val extraPaths = let
                        val pl = ["@TEEM_DIR@" // "bin"]
                        in
                          case OS.Process.getEnv "DIDEROT_TEEM_DIR"
                           of SOME p => (p // "bin") :: pl
                            | NONE => pl
                          (* end case *)
                        end
                  val unuPath = findExe (extraPaths, "unu")
                  val dir = OS.Path.getParent(OS.Path.dir unuPath)
                  in
                    teemDir := SOME dir;
                    dir // subDir
                  end
            (* end case *))
    in
    fun teemBin () = resolveTeemDir "bin"
    fun teemInclude () = resolveTeemDir "include"
    fun teemLinkFlags () = let
	  val teemLib = resolveTeemDir "lib"
	  in
	    if @LD_NEEDS_RPATH@
	      then ["-Wl,-rpath=" ^ teemLib, "-L" ^ teemLib, "-lteem"]
	      else ["-L" ^ teemLib, "-lteem"]
	  end
    end (* local *)

  (* paths to some useful tools *)
    val ccxx = let
          val (cmd::args) = String.tokens Char.isSpace "@CXX@"
          val cmd = findExe ([], cmd)
          val args = if ("@CXXFLAG_Mxx@" <> "") then "@CXXFLAG_Mxx@" :: args else args
          in
            String.concatWith " " (cmd::args)
          end
    val cxxFlags = {
            base = "@CXXFLAGS_BASE@",
            parallel = "@PTHREAD_CFLAGS@",
            cl = "@CPPFLAGS_CL@",
            cuda = "@CPPFLAGS_CUDA@",
            debug = "-g -O0",
            ndebug = "-march=native -O3 -DNDEBUG"
          }
    val ld = let
          val (cmd::args) = String.tokens Char.isSpace "@LD@"
          val cmd = findExe ([], cmd)
          in
            String.concatWith " " (cmd :: args)
          end
    val extraLibs = {
            base = "@LIBM@",
            parallel = "@PTHREAD_LIBS@",
            cl = "@LIBS_CL@",
            cuda = "@LIBS_CUDA@"
          }

  (* OpenCL configuration *)
    val clEnabled = @CL_ENABLED@
    val (clVersion, clStd) = if clEnabled
          then let
          (* assume a numbering scheme equivalent to __OPENCL_VERSION__ *)
            val major = @CL_VERSION@ div 100
            val minor = (@CL_VERSION@ div 10) mod 10
            val patch = @CL_VERSION@ mod 10
            val vers = if patch > 0 then [major, minor, patch] else [major, minor]
            in
              (vers, String.concat["CL", Int.toString major, ".", Int.toString minor])
            end
          else ([], "")
    val clVersionString = "@CL_VERSION@"

  (* CUDA configuration *)
    val cudaEnabled = @CUDA_ENABLED@
    end (* local *)

  end

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