on 496cf41 help sign in
Idris-dev/src/Util/System.hs
53 lines 1.6 kB history raw
1{-# LANGUAGE CPP #-}
2module Util.System(tempfile,environment,getCC,
3 getLibFlags,getIdrisLibDir,getIncFlags,rmFile) where
5-- System helper functions.
7import System.Directory (getTemporaryDirectory, removeFile)
8import System.FilePath ((</>), addTrailingPathSeparator, normalise)
9import System.Environment
10import System.IO
11#if MIN_VERSION_base(4,0,0)
12import Control.Exception as CE
13#endif
15import Paths_idris
17#if MIN_VERSION_base(4,0,0)
18catchIO :: IO a -> (IOError -> IO a) -> IO a
19catchIO = CE.catch
20#else
21catchIO = catch
22#endif
24getCC :: IO String
25getCC = do env <- environment "IDRIS_CC"
26 case env of
27 Nothing -> return "gcc"
28 Just cc -> return cc
30tempfile :: IO (FilePath, Handle)
31tempfile = do dir <- getTemporaryDirectory
32 openTempFile (normalise dir) "idris"
34environment :: String -> IO (Maybe String)
35environment x = catchIO (do e <- getEnv x
36 return (Just e))
37 (\_ -> return Nothing)
39rmFile :: FilePath -> IO ()
40rmFile f = do putStrLn $ "Removing " ++ f
41 catchIO (removeFile f)
42 (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
43 ++ f ++ ", Error msg:" ++ show ioerr)
46getLibFlags = do dir <- getDataDir
47 return $ "-L" ++ (dir </> "rts") ++ " -lidris_rts -lgmp -lpthread"
49getIdrisLibDir = do dir <- getDataDir
50 return $ addTrailingPathSeparator dir
52getIncFlags = do dir <- getDataDir
53 return $ "-I" ++ dir </> "rts"