diff options
| author | krasimir <krasimir@chalmers.se> | 2008-02-21 15:56:09 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2008-02-21 15:56:09 +0000 |
| commit | 671b6b4dff42efeef8c1e1471576f06fdcff8f68 (patch) | |
| tree | 8f7e89169d92acbb4ab448745be45e747e66253a /src/GF/Infra/UseIO.hs | |
| parent | c764a758e1a5e0eab346a2c3c88b7e8a9c64e248 (diff) | |
For Windows get the default GF_LIB_PATH from the executable path
Diffstat (limited to 'src/GF/Infra/UseIO.hs')
| -rw-r--r-- | src/GF/Infra/UseIO.hs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/GF/Infra/UseIO.hs b/src/GF/Infra/UseIO.hs index 6c15ee6e5..2680c0327 100644 --- a/src/GF/Infra/UseIO.hs +++ b/src/GF/Infra/UseIO.hs @@ -1,3 +1,4 @@ +{-# OPTIONS -cpp #-} ---------------------------------------------------------------------- -- | -- Module : UseIO @@ -25,6 +26,14 @@ import System.IO.Error import System.Environment import Control.Monad +#ifdef mingw32_HOST_OS +import System.Win32.DLL +import System.FilePath.Windows +import System.Directory +import Foreign.Ptr +#endif + + putShow' :: Show a => (c -> a) -> c -> IO () putShow' f = putStrLn . show . length . show . f @@ -122,11 +131,23 @@ doesFileExistPath paths file = do mpfile <- ioeIO $ getFilePathMsg "" paths file return $ maybe False (const True) mpfile +getLibraryPath :: IO FilePath +getLibraryPath = + catch + (getEnv "GF_LIB_PATH") +#ifdef mingw32_HOST_OS + (\_ -> do exepath <- getModuleFileName nullPtr + let (path,_) = splitFileName exepath + canonicalizePath (combine path "../lib")) +#else + (const (return libdir)) +#endif + -- | first var is lib prefix, second is like class path -- | path in environment variable has lower priority extendPathEnv :: String -> String -> [FilePath] -> IO [FilePath] extendPathEnv lib var ps = do - b <- catch (getEnv lib) (const (return libdir)) -- e.g. GF_LIB_PATH + b <- getLibraryPath -- e.g. GF_LIB_PATH s <- catch (getEnv var) (const (return "")) -- e.g. GF_GRAMMAR_PATH let fs = pFilePaths s let ss = ps ++ fs |
