Permalink
Browse files

Make dynamic library extension platform-dependent

New syntax is %dynamic "libm" instead of %dynamic "libm.so".
  • Loading branch information...
david-christiansen committed Mar 22, 2013
1 parent 8435ba9 commit 90f661beded96d725a8a315afd7577f02444f62e
Showing with 18 additions and 3 deletions.
  1. +6 −0 idris.cabal
  2. +11 −2 src/Util/DynamicLinker.hs
  3. +1 −1 test/test022/test022.idr
View
@@ -114,3 +114,9 @@ Executable idris
FlexibleInstances, TemplateHaskell
ghc-prof-options: -auto-all -caf-all
ghc-options: -rtsopts
+ if os(linux)
+ cpp-options: -DLINUX
+ if os(darwin)
+ cpp-options: -DMACOSX
+ if os(windows)
+ cpp-options: -DWINDOWS
View
@@ -1,18 +1,27 @@
-- | Platform-specific dynamic linking support. Add new platforms to this file
-- through conditional compilation.
-{-# LANGUAGE ExistentialQuantification #-}
+{-# LANGUAGE ExistentialQuantification, CPP #-}
module Util.DynamicLinker where
import Foreign.LibFFI
import Foreign.Ptr (nullPtr, FunPtr, nullFunPtr)
import System.Posix.DynamicLinker
+hostDynamicLibExt :: String
+#ifdef LINUX
+hostDynamicLibExt = "so"
+#elif MACOSX
+hostDynamicLibExt = "dylib"
+#elif WINDOWS
+hostDynamicLibExt = "dll"
+#endif
+
data DynamicLib = Lib { lib_name :: String
, lib_handle :: DL
}
tryLoadLib :: String -> IO (Maybe DynamicLib)
-tryLoadLib lib = do handle <- dlopen lib [RTLD_NOW]
+tryLoadLib lib = do handle <- dlopen (lib ++ "." ++ hostDynamicLibExt) [RTLD_NOW]
if undl handle == nullPtr
then return Nothing
else return . Just $ Lib lib handle
View
@@ -1,6 +1,6 @@
module Main
-%dynamic "libm.so"
+%dynamic "libm"
x : Float
x = unsafePerformIO (mkForeign (FFun "sin" [FFloat] FFloat) 1.6)

0 comments on commit 90f661b

Please sign in to comment.