diff options
author | Joey Hess <joey@kitenet.net> | 2012-12-09 13:29:30 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-12-09 13:29:30 -0400 |
commit | c3451715b90022e898f14bb5d45c8d7db9563929 (patch) | |
tree | 8f0ad99a29da9c597564efae9035debb5e8ba8e2 /Build/OSXMkLibs.hs | |
parent | 8a92fbcc1b6da89082f54ca06b9f237c37633b9f (diff) |
optimisation; only run install_name_tool once per binary
Diffstat (limited to 'Build/OSXMkLibs.hs')
-rw-r--r-- | Build/OSXMkLibs.hs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/Build/OSXMkLibs.hs b/Build/OSXMkLibs.hs index 6462cb14e..18c0e7c8d 100644 --- a/Build/OSXMkLibs.hs +++ b/Build/OSXMkLibs.hs @@ -79,24 +79,30 @@ 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. -} +{- Adjusts binaries to use libraries bundled with it, rather than the + - system libraries. -} install_name_tool :: FilePath -> [FilePath] -> LibMap -> IO LibMap -install_name_tool _ [] libmap = return libmap -install_name_tool binary (lib:rest) libmap = do - let (libname, libmap') = getLibName lib libmap - ok <- boolSystem "install_name_tool" +install_name_tool binary libs libmap = do + let (libnames, libmap') = getLibNames libs libmap + let params = concatMap change $ zip libs libnames + ok <- boolSystem "install_name_tool" $ params ++ [File binary] + unless ok $ + hPutStrLn stderr $ "install_name_tool failed for " ++ binary + return libmap' + where + change (lib, libname) = [ Param "-change" , File lib , Param $ "@executable_path/" ++ libname - , File binary ] - unless ok $ - hPutStrLn stderr $ "install_name_tool failed for " ++ binary - install_name_tool binary rest libmap' + +getLibNames :: [FilePath] -> LibMap -> ([FilePath], LibMap) +getLibNames libs libmap = go [] libs libmap + where + go c [] m = (reverse c, m) + go c (l:rest) m = + let (f, m') = getLibName l m + in go (f:c) rest m' {- Uses really short names for the library files it installs, because - binaries have arbitrarily short RPATH field limits. -} |