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 4307 - (download) (annotate)
Fri Jul 29 19:29:48 2016 UTC (3 years ago) by jhr
File size: 4994 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 =
  struct

    local
      val // = OS.Path.concat
      infixr 4 //
    in
  (* 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 teemLib () = resolveTeemDir "lib"
    fun teemLinkFlags () = if @LD_NEEDS_RPATH@
          then ["-Wl,-rpath=" ^ teemLib(), "-L" ^ teemLib(), "-lteem"]
          else ["-L" ^ teemLib(), "-lteem"]
    end (* local *)

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

  (* 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@",
            pthread = "@PTHREAD_CFLAGS@",
            cl = "@CPPFLAGS_CL@",
            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@",
            pthread = "@PTHREAD_LIBS@",
            cl = "@LIBS_CL@"
          }

  (* 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