summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-14 16:28:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-14 16:28:05 -0400
commitb52ce804b084b9c182756bb6df944f0604b26f5b (patch)
tree8924988d5f7506639a57d3db300988aca37ded42 /Build
parente6f32bd11c94221f82fe9acf6ecb74be2fab4a76 (diff)
search DYLD_LIBRARY_PATH for libraries
Diffstat (limited to 'Build')
-rw-r--r--Build/OSXMkLibs.hs23
1 files changed, 19 insertions, 4 deletions
diff --git a/Build/OSXMkLibs.hs b/Build/OSXMkLibs.hs
index dae9bc0ae..e3802e58c 100644
--- a/Build/OSXMkLibs.hs
+++ b/Build/OSXMkLibs.hs
@@ -8,13 +8,13 @@
module Main where
import Control.Applicative
-import System.Environment
+import System.Environment (getArgs)
import Data.Maybe
import System.FilePath
import System.Directory
-import System.IO
import Control.Monad
import Data.List
+import Data.String.Utils
import Utility.PartialPrelude
import Utility.Directory
@@ -23,6 +23,7 @@ import Utility.Monad
import Utility.SafeCommand
import Utility.Path
import Utility.Exception
+import Utility.Env
import qualified Data.Map as M
import qualified Data.Set as S
@@ -57,7 +58,12 @@ installLibs appbase replacement_libs libmap = do
)
return (catMaybes libs, replacement_libs', libmap')
-{- Returns libraries to install. -}
+{- Returns libraries to install.
+ -
+ - Note that otool -L ignores DYLD_LIBRARY_PATH. But we do want to honor
+ - that if set, so the library files found by otool are searched for on
+ - that path.
+ -}
otool :: FilePath -> [(FilePath, FilePath)] -> LibMap -> IO ([FilePath], [(FilePath, FilePath)], LibMap)
otool appbase replacement_libs libmap = do
files <- filterM doesFileExist =<< dirContentsRecursive appbase
@@ -69,13 +75,22 @@ otool appbase replacement_libs libmap = do
process c [] rls m = return (nub $ concat c, rls, m)
process c (file:rest) rls m = do
_ <- boolSystem "chmod" [Param "755", File file]
- libs <- filter want . parseOtool
+ libs <- mapM findLibPath
+ =<< filter want . parseOtool
<$> readProcess "otool" ["-L", file]
expanded_libs <- expand_rpath libs replacement_libs file
let rls' = nub $ rls ++ (zip libs expanded_libs)
m' <- install_name_tool file libs expanded_libs m
process (expanded_libs:c) rest rls' m'
+findLibPath :: FilePath -> IO FilePath
+findLibPath l = go =<< getEnv "DYLD_LIBRARY_PATH"
+ where
+ go Nothing = return l
+ go (Just p) = fromMaybe l
+ <$> firstM doesFileExist (map (</> f) (split ":" p))
+ f = takeFileName l
+
{- Expands any @rpath in the list of libraries.
-
- This is done by the nasty method of running the command with a dummy