@@ -1,14 +1,20 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2−module Util.System(tempfile,environment,getCC) where
2+module Util.System(tempfile,environment,getCC,getLibFlags,getIdrisLibDir,getIncFlags) where
4-- System helper functions.
4-- System helper functions.
6+import System.FilePath ((</>), addTrailingPathSeparator, normalise)
6import System.Environment
7import System.Environment
7import System.IO
8import System.IO
8#if MIN_VERSION_base(4,0,0)
9#if MIN_VERSION_base(4,0,0)
9import Control.Exception as CE
10import Control.Exception as CE
14+import Data.List.Split(splitOn)
12#if MIN_VERSION_base(4,0,0)
18#if MIN_VERSION_base(4,0,0)
13catchIO :: IO a -> (IOError -> IO a) -> IO a
19catchIO :: IO a -> (IOError -> IO a) -> IO a
14catchIO = CE.catch
20catchIO = CE.catch
@@ -23,13 +29,32 @@ getCC = do env <- environment "IDRIS_CC"
23 Just cc -> return cc
29 Just cc -> return cc
25tempfile :: IO (FilePath, Handle)
31tempfile :: IO (FilePath, Handle)
26−tempfile = do env <- environment "TMPDIR"
32+tempfile = do env <- environment tempDirEnvVar
27 let dir = case env of
33 let dir = case env of
28 Nothing -> "/tmp"
34 Nothing -> "/tmp"
35+#ifdef mingw32_HOST_OS
36+ -- ghc changes the path separators if we start program in a *nix shell
37+ (Just d) -> normalise d
29 (Just d) -> d
39 (Just d) -> d
30 openTempFile dir "idris"
41 openTempFile dir "idris"
42+#ifdef mingw32_HOST_OS
43+ where tempDirEnvVar = "TMP"
45+ where tempDirEnvVar = "TMPDIR"
32environment :: String -> IO (Maybe String)
48environment :: String -> IO (Maybe String)
33environment x = catchIO (do e <- getEnv x
49environment x = catchIO (do e <- getEnv x
34 return (Just e))
50 return (Just e))
35 (\_ -> return Nothing)
51 (\_ -> return Nothing)
53+getLibFlags = do dir <- getDataDir
54+ return $ "-L" ++ (dir </> "rts") ++ " -lidris_rts -lgmp -lpthread"
56+getIdrisLibDir = do dir <- getDataDir
57+ return $ addTrailingPathSeparator dir
59+getIncFlags = do dir <- getDataDir
60+ return $ "-I" ++ dir </> "rts"