Fix whitespace
[ghc-hetmet.git] / compiler / main / DynFlags.hs
index 2afa91d..97cbfc8 100644 (file)
@@ -29,6 +29,7 @@ module DynFlags (
        GhcLink(..), isNoLink,
        PackageFlag(..),
        Option(..),
+       DynLibLoader(..),
         fFlags, xFlags,
 
        -- Configuration of the core-to-core and stg-to-stg phases
@@ -93,6 +94,7 @@ import Util           ( split )
 #endif
 
 import Data.Char
+import System.FilePath
 import System.IO        ( hPutStrLn, stderr )
 
 -- -----------------------------------------------------------------------------
@@ -195,6 +197,7 @@ data DynFlag
    | Opt_PArr                          -- Syntactic support for parallel arrays
    | Opt_Arrows                                -- Arrow-notation syntax
    | Opt_TemplateHaskell
+   | Opt_QuasiQuotes
    | Opt_ImplicitParams
    | Opt_Generics
    | Opt_ImplicitPrelude 
@@ -332,6 +335,7 @@ data DynFlags = DynFlags {
 
   outputFile           :: Maybe String,
   outputHi             :: Maybe String,
+  dynLibLoader         :: DynLibLoader,
 
   -- | This is set by DriverPipeline.runPipeline based on where
   --   its output is going.
@@ -458,6 +462,12 @@ defaultObjectTarget
   | cGhcWithNativeCodeGen == "YES"     =  HscAsm
   | otherwise                          =  HscC
 
+data DynLibLoader
+  = Deployable
+  | Wrapped (Maybe String)
+  | SystemDependent
+  deriving Eq
+
 initDynFlags dflags = do
  -- someday these will be dynamic flags
  ways <- readIORef v_Ways
@@ -504,6 +514,7 @@ defaultDynFlags =
 
        outputFile              = Nothing,
        outputHi                = Nothing,
+       dynLibLoader            = Deployable,
        dumpPrefix              = Nothing,
        dumpPrefixForce         = Nothing,
        includePaths            = [],
@@ -600,6 +611,15 @@ setHcSuf      f d = d{ hcSuf      = f}
 setOutputFile f d = d{ outputFile = f}
 setOutputHi   f d = d{ outputHi   = f}
 
+parseDynLibLoaderMode f d =
+ case splitAt 8 f of
+   ("deploy", "")       -> d{ dynLibLoader = Deployable }
+   ("sysdep", "")       -> d{ dynLibLoader = SystemDependent }
+   ("wrapped", "")      -> d{ dynLibLoader = Wrapped Nothing }
+   ("wrapped:", "hard") -> d{ dynLibLoader = Wrapped Nothing }
+   ("wrapped:", flex)   -> d{ dynLibLoader = Wrapped (Just flex) }
+   (_,_)                -> error "Unknown dynlib loader"
+
 setDumpPrefixForce f d = d { dumpPrefixForce = f}
 
 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
@@ -992,6 +1012,7 @@ dynamic_flags = [
   ,  ( "c"             , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
   ,  ( "no-link"       , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
   ,  ( "shared"                , NoArg (upd $ \d -> d{ ghcLink=LinkDynLib } ))
+  ,  ( "dynload"       , HasArg (upd . parseDynLibLoaderMode))
 
        ------- Libraries ---------------------------------------------------
   ,  ( "L"             , Prefix addLibraryPath )
@@ -1299,6 +1320,7 @@ xFlags = [
   ( "Arrows",                           Opt_Arrows ),
   ( "PArr",                             Opt_PArr ),
   ( "TemplateHaskell",                  Opt_TemplateHaskell ),
+  ( "QuasiQuotes",                      Opt_QuasiQuotes ),
   ( "Generics",                         Opt_Generics ),
   -- On by default:
   ( "ImplicitPrelude",                  Opt_ImplicitPrelude ),
@@ -1573,32 +1595,28 @@ setTmpDir :: FilePath -> DynFlags -> DynFlags
 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
   where
 #if !defined(mingw32_HOST_OS)
-     canonicalise p = normalisePath p
+     canonicalise p = normalise p
 #else
-       -- Canonicalisation of temp path under win32 is a bit more
-       -- involved: (a) strip trailing slash, 
-       --           (b) normalise slashes
-       --           (c) just in case, if there is a prefix /cygdrive/x/, change to x:
-       -- 
-     canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
-
-        -- if we're operating under cygwin, and TMP/TEMP is of
-       -- the form "/cygdrive/drive/path", translate this to
-       -- "drive:/path" (as GHC isn't a cygwin app and doesn't
-       -- understand /cygdrive paths.)
-     xltCygdrive path
-      | "/cygdrive/" `isPrefixOf` path = 
-         case drop (length "/cygdrive/") path of
-           drive:xs@('/':_) -> drive:':':xs
-           _ -> path
-      | otherwise = path
-
-        -- strip the trailing backslash (awful, but we only do this once).
-     removeTrailingSlash path = 
-       case last path of
-         '/'  -> init path
-         '\\' -> init path
-         _    -> path
+     -- Canonicalisation of temp path under win32 is a bit more
+     -- involved: (a) strip trailing slash,
+     --      (b) normalise slashes
+     --     (c) just in case, if there is a prefix /cygdrive/x/, change to x:
+     canonicalise path = removeTrailingSlash $ normalise $ xltCygdrive path
+
+     -- if we're operating under cygwin, and TMP/TEMP is of
+     -- the form "/cygdrive/drive/path", translate this to
+     -- "drive:/path" (as GHC isn't a cygwin app and doesn't
+     -- understand /cygdrive paths.)
+     cygdrivePrefix = [pathSeparator] ++ "/cygdrive/" ++ [pathSeparator]
+     xltCygdrive path = case maybePrefixMatch cygdrivePrefix path of
+                        Just (drive:sep:xs)
+                         | isPathSeparator sep -> drive:':':pathSeparator:xs
+                        _ -> path
+
+     -- strip the trailing backslash (awful, but we only do this once).
+     removeTrailingSlash path
+      | isPathSeparator (last path) = init path
+      | otherwise                   = path
 #endif
 
 -----------------------------------------------------------------------------