- -> do maybe_errmsg <- addDLL dll_unadorned
- if maybe_errmsg == nullPtr
- then putStr "done.\n"
- else do str <- peekCString maybe_errmsg
- putStr ("failed (" ++ str ++ ")\n")
- croak
-
- croak = throwDyn (CmdLineError "user specified .o/.so/.DLL could not be loaded.")
+ -> do b <- preload_dynamic lib_paths dll_unadorned
+ when (not b) (cantFind lib_paths lib_spec)
+ putStrLn "done"
+
+ cantFind :: [String] -> LibrarySpec -> IO ()
+ cantFind paths spec
+ = do putStr ("failed.\nCan't find " ++ showLS spec
+ ++ " in directories:\n"
+ ++ unlines (map (" "++) paths) )
+ give_up
+
+ -- not interested in the paths in the static case.
+ preload_static paths name
+ = do b <- doesFileExist name
+ if not b then return False
+ else loadObj name >> return True
+
+ preload_dynamic [] name
+ = return False
+ preload_dynamic (path:paths) rootname
+ = do maybe_errmsg <- addDLL path rootname
+ if maybe_errmsg /= nullPtr
+ then preload_dynamic paths rootname
+ else return True
+
+ give_up
+ = (throwDyn . CmdLineError)
+ "user specified .o/.so/.DLL could not be loaded."