From c3451715b90022e898f14bb5d45c8d7db9563929 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 9 Dec 2012 13:29:30 -0400 Subject: optimisation; only run install_name_tool once per binary --- Build/OSXMkLibs.hs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'Build') 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. -} -- cgit v1.2.3