- -> do dll_ok <- addDLL dll_unadorned
- if dll_ok
- then putStr "done.\n"
- else do putStr "not found.\n"
- croak
-
- croak = throwDyn (OtherError "user specified .o/.so/.DLL cannot be found.")
-
- classify a_lib
- = let a_libr = reverse a_lib
- in
- case map toLower a_libr of
- ('o':'.':_)
- -> Left a_lib
- ('o':'s':'.':_)
- -> (Right . zap_leading_lib
- . reverse . drop 3 . reverse) a_lib
- ('l':'l':'d':'.':_)
- -> (Right . reverse . drop 4 . reverse) a_lib
- other
- -> -- Main.beginInteractive should not have let this through
- pprPanic "linkPackages" (text (show a_lib))
-
- zap_leading_lib str
- = if take 3 str == "lib" then drop 3 str else str
-
-
-linkPackage :: Package -> IO ()
+ -> -- We add "" to the set of paths to try, so that
+ -- if none of the real paths match, we force addDLL
+ -- to look in the default dynamic-link search paths.
+ 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."
+
+
+linkPackage :: Bool -> PackageConfig -> IO ()