@@ -1,14 +1,20 @@
11{-# LANGUAGE CPP #-}
2−module Util.System(tempfile,environment,getCC) where
2+module Util.System(tempfile,environment,getCC,getLibFlags,getIdrisLibDir,getIncFlags) where
33
44-- System helper functions.
55
6+import System.FilePath ((</>), addTrailingPathSeparator, normalise)
67import System.Environment
78import System.IO
89#if MIN_VERSION_base(4,0,0)
910import Control.Exception as CE
1011#endif
1112
13+-- import Data.List
14+import Data.List.Split(splitOn)
15+
16+import Paths_idris
17+
1218#if MIN_VERSION_base(4,0,0)
1319catchIO :: IO a -> (IOError -> IO a) -> IO a
1420catchIO = CE.catch
@@ -23,13 +29,32 @@ getCC = do env <- environment "IDRIS_CC"
2329 Just cc -> return cc
2430
2531tempfile :: IO (FilePath, Handle)
26−tempfile = do env <- environment "TMPDIR"
32+tempfile = do env <- environment tempDirEnvVar
2733 let dir = case env of
2834 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
38+#else
2939 (Just d) -> d
40+#endif
3041 openTempFile dir "idris"
42+#ifdef mingw32_HOST_OS
43+ where tempDirEnvVar = "TMP"
44+#else
45+ where tempDirEnvVar = "TMPDIR"
46+#endif
3147
3248environment :: String -> IO (Maybe String)
3349environment x = catchIO (do e <- getEnv x
3450 return (Just e))
3551 (\_ -> return Nothing)
52+
53+getLibFlags = do dir <- getDataDir
54+ return $ "-L" ++ (dir </> "rts") ++ " -lidris_rts -lgmp -lpthread"
55+
56+getIdrisLibDir = do dir <- getDataDir
57+ return $ addTrailingPathSeparator dir
58+
59+getIncFlags = do dir <- getDataDir
60+ return $ "-I" ++ dir </> "rts"