diff options
author | Joey Hess <joey@kitenet.net> | 2012-11-26 14:09:40 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-11-26 14:09:40 -0400 |
commit | dd19a319cb8cddd0a476f58d0a73e181e71aeac7 (patch) | |
tree | 05693bc500b9acd5180dc28fc719cc53cce603c6 | |
parent | 620941d8430013547dfc4ccfc5c5e20e9d4baa19 (diff) |
rewrote OSX library copier in Haskell, now with recursive copying of library deps
-rw-r--r-- | Build/OSXMkLibs.hs | 69 | ||||
-rw-r--r-- | Makefile | 10 |
2 files changed, 70 insertions, 9 deletions
diff --git a/Build/OSXMkLibs.hs b/Build/OSXMkLibs.hs new file mode 100644 index 000000000..7423e4ce7 --- /dev/null +++ b/Build/OSXMkLibs.hs @@ -0,0 +1,69 @@ +{- OSX library copier + - + - Copyright 2012 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Build.OSXMkLibs where + +import Control.Applicative +import System.Environment +import Data.Maybe +import System.FilePath +import System.Directory +import System.IO +import Control.Monad +import Data.List + +import Utility.PartialPrelude +import Utility.Directory +import Utility.Process +import Utility.Monad +import Utility.SafeCommand +import Utility.Path + +{- Recursively find and install libs, until nothing new to install is found. -} +mklibs :: FilePath -> [FilePath] -> IO [FilePath] +mklibs appbase libdirs = do + new <- catMaybes <$> installLibs appbase + if null new + then return (libdirs++new) + else mklibs appbase (libdirs++new) + +{- Returns directories into which new libs were installed. -} +installLibs :: FilePath -> IO [Maybe FilePath] +installLibs appbase = do + needlibs <- otool appbase + forM needlibs $ \lib -> do + let libdir = parentDir lib + let dest = appbase </> lib + ifM (doesFileExist dest) + ( return Nothing + , do + createDirectoryIfMissing True (appbase </> libdir) + _ <- boolSystem "cp" [File lib, File dest] + return $ Just libdir + ) + +otool :: FilePath -> IO [FilePath] +otool appbase = do + files <- filterM doesFileExist =<< dirContentsRecursive appbase + s <- readProcess "otool" ("-L" : files) + return $ nub $ parseOtool s + +parseOtool :: String -> [FilePath] +parseOtool = catMaybes . map parse . lines + where + parse l + | "\t" `isPrefixOf` l = headMaybe $ words l + | otherwise = Nothing + +main :: IO () +main = getArgs >>= go + where + go [] = error "specify OSXAPP_BASE" + go (appbase:_) = do + libdirs <- mklibs appbase [] + writeFile (appbase </> "libdirs") $ + unlines $ nub libdirs @@ -206,15 +206,7 @@ osxapp: install -d "$(OSXAPP_BASE)/git-core" (cd "$(shell git --exec-path)" && tar c .) | (cd "$(OSXAPP_BASE)"/git-core && tar x) - touch "$(OSXAPP_BASE)/libdirs.tmp" - for lib in $$(otool -L "$(OSXAPP_BASE)"/bin/* "$(OSXAPP_BASE)"/git-core/* | egrep '^ ' | cut -d ' ' -f 1 | sed 's/^ //' | sort | uniq); do \ - dir=$$(dirname "$$lib"); \ - install -d "$(OSXAPP_BASE)/$$dir"; \ - echo "$$dir" >> "$(OSXAPP_BASE)/libdirs.tmp"; \ - cp "$$lib" "$(OSXAPP_BASE)/$$dir"; \ - done - sort "$(OSXAPP_BASE)/libdirs.tmp" | uniq > "$(OSXAPP_BASE)/libdirs" - rm -f "$(OSXAPP_BASE)/libdirs.tmp" + runghc Build/OSXMkLibs.hs $(OSXAPP_BASE) rm -f tmp/git-annex.dmg hdiutil create -size 640m -format UDRW -srcfolder $(GIT_ANNEX_TMP_BUILD_DIR)/build-dmg \ -volname git-annex -o tmp/git-annex.dmg |