summaryrefslogtreecommitdiff
path: root/Build/OSXMkLibs.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-12-08 11:07:59 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-12-08 11:07:59 -0400
commitc1552daa3283ba03ef041312036d0e2f56c8fd87 (patch)
treeec8ea7939347c84ae2e5d106f76ff26cc05c7da1 /Build/OSXMkLibs.hs
parent7864e92bdaf01838eab279f79f90015e86b20bb0 (diff)
use install_name_tool to adjust library paths in osx app
Have not yet been able to test this.
Diffstat (limited to 'Build/OSXMkLibs.hs')
-rw-r--r--Build/OSXMkLibs.hs24
1 files changed, 22 insertions, 2 deletions
diff --git a/Build/OSXMkLibs.hs b/Build/OSXMkLibs.hs
index cb8c017ae..fa5178988 100644
--- a/Build/OSXMkLibs.hs
+++ b/Build/OSXMkLibs.hs
@@ -47,11 +47,15 @@ installLibs appbase = do
return $ Just libdir
)
+{- Returns libraries to install. -}
otool :: FilePath -> IO [FilePath]
otool appbase = do
files <- filterM doesFileExist =<< dirContentsRecursive appbase
- s <- readProcess "otool" ("-L" : files)
- return $ nub $ parseOtool s
+ l <- forM files $ \file -> do
+ libs <- parseOtool <$> readProcess "otool" ["-L", file]
+ forM_ libs $ \lib -> install_name_tool file lib
+ return libs
+ return $ nub $ concat l
parseOtool :: String -> [FilePath]
parseOtool = catMaybes . map parse . lines
@@ -60,6 +64,22 @@ parseOtool = catMaybes . map parse . lines
| "\t" `isPrefixOf` l = headMaybe $ words l
| otherwise = Nothing
+{- Adjusts binaries to use libraries in paths relative to the executable.
+ -
+ - Assumes all executables are installed into the same directory, and
+ - the libraries will be installed in subdirectories that match their
+ - absolute paths. -}
+install_name_tool :: FilePath -> FilePath -> IO ()
+install_name_tool binary lib = do
+ ok <- boolSystem "install_name_tool"
+ [ Param "-change"
+ , File lib
+ , Param $ "@executable_path" ++ lib
+ , File binary
+ ]
+ unless ok $
+ hPutStrLn stderr $ "install_name_tool failed for " ++ binary
+
main :: IO ()
main = getArgs >>= go
where