@@ -1,18 +1,27 @@
1-- | Platform-specific dynamic linking support. Add new platforms to this file
1-- | Platform-specific dynamic linking support. Add new platforms to this file
2-- through conditional compilation.
2-- through conditional compilation.
3−{-# LANGUAGE ExistentialQuantification #-}
3+{-# LANGUAGE ExistentialQuantification, CPP #-}
4module Util.DynamicLinker where
4module Util.DynamicLinker where
6import Foreign.LibFFI
6import Foreign.LibFFI
7import Foreign.Ptr (nullPtr, FunPtr, nullFunPtr)
7import Foreign.Ptr (nullPtr, FunPtr, nullFunPtr)
8import System.Posix.DynamicLinker
8import System.Posix.DynamicLinker
10+hostDynamicLibExt :: String
12+hostDynamicLibExt = "so"
14+hostDynamicLibExt = "dylib"
16+hostDynamicLibExt = "dll"
10data DynamicLib = Lib { lib_name :: String
19data DynamicLib = Lib { lib_name :: String
11 , lib_handle :: DL
20 , lib_handle :: DL
14tryLoadLib :: String -> IO (Maybe DynamicLib)
23tryLoadLib :: String -> IO (Maybe DynamicLib)
15−tryLoadLib lib = do handle <- dlopen lib [RTLD_NOW]
24+tryLoadLib lib = do handle <- dlopen (lib ++ "." ++ hostDynamicLibExt) [RTLD_NOW]
16 if undl handle == nullPtr
25 if undl handle == nullPtr
17 then return Nothing
26 then return Nothing
18 else return . Just $ Lib lib handle
27 else return . Just $ Lib lib handle