+-- Darwin / MacOS X only: load a framework
+-- a framework is a dynamic library packaged inside a directory of the same
+-- name. They are searched for in different paths than normal libraries.
+#ifdef darwin_TARGET_OS
+loadFramework extraPaths rootname
+ = loadFramework' (extraPaths ++ defaultFrameworkPaths) where
+ defaultFrameworkPaths = ["/Library/Frameworks", "/System/Library/Frameworks"]
+
+ loadFramework' (path:paths) = do
+ let dll = path ++ '/' : rootname ++ ".framework/" ++ rootname
+ b <- doesFileExist dll
+ if not b
+ then loadFramework' paths
+ else addDLL dll
+ loadFramework' [] = do
+ -- tried all our known library paths, but dlopen()
+ -- has no built-in paths for frameworks: give up
+ return $ Just $ "not found"
+#endif
+