summaryrefslogtreecommitdiffhomepage
path: root/Utility
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-05-05 14:27:39 -0400
committerJoey Hess <joeyh@joeyh.name>2017-05-05 14:30:46 -0400
commit2f5315b3c32fbd23ebce05da80712183dc259b7c (patch)
tree48de39738910859cb0eaaf15cbfe9529b44e4272 /Utility
parent4a2a01a7eaa8945d063468d7d1c24f095a3ae2a4 (diff)
downloaddebug-me-2f5315b3c32fbd23ebce05da80712183dc259b7c.tar.gz
standalone tarball
Adapted the standalone tarball building code from git-annex.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/LinuxMkLibs.hs60
1 files changed, 60 insertions, 0 deletions
diff --git a/Utility/LinuxMkLibs.hs b/Utility/LinuxMkLibs.hs
new file mode 100644
index 0000000..5851ed1
--- /dev/null
+++ b/Utility/LinuxMkLibs.hs
@@ -0,0 +1,60 @@
+{- Linux library copier and binary shimmer
+ -
+ - Copyright 2013 Joey Hess <id@joeyh.name>
+ -
+ - License: BSD-2-clause
+ -}
+
+module Utility.LinuxMkLibs where
+
+import System.IO
+import System.Directory (doesFileExist)
+import Data.Maybe
+import System.FilePath
+import Data.List.Utils
+import System.Posix.Files
+import Data.Char
+import Control.Monad.IfElse
+import Control.Applicative
+import System.Process
+import Prelude
+
+{- Installs a library. If the library is a symlink to another file,
+ - install the file it links to, and update the symlink to be relative. -}
+installLib :: (FilePath -> FilePath -> IO ()) -> FilePath -> FilePath -> IO (Maybe FilePath)
+installLib installfile top lib = go =<< doesFileExist lib
+ where
+ go False = return Nothing
+ go True = do
+ installfile top lib
+ checksymlink lib
+ return $ Just $ takeDirectory lib
+
+ checksymlink f = whenM (isSymbolicLink <$> getSymbolicLinkStatus (inTop top f)) $ do
+ l <- readSymbolicLink (inTop top f)
+ let absl = takeDirectory f </> l
+ --target <- relPathDirToFile (takeDirectory f) absl
+ installfile top absl
+ --removeLink (top ++ f)
+ --createSymbolicLink target (inTop top f)
+ checksymlink absl
+
+-- Note that f is not relative, so cannot use </>
+inTop :: FilePath -> FilePath -> FilePath
+inTop top f = top ++ f
+
+{- Parse ldd output, getting all the libraries that the input files
+ - link to. Note that some of the libraries may not exist
+ - (eg, linux-vdso.so) -}
+parseLdd :: String -> [FilePath]
+parseLdd = concatMap (getlib . dropWhile isSpace) . lines
+ where
+ getlib = concatMap (take 1) . map words . take 1 . reverse . split " => "
+
+{- Get all glibc libs and other support files, including gconv files
+ -
+ - XXX Debian specific. -}
+glibcLibs :: IO [FilePath]
+glibcLibs = lines <$> readProcess "sh"
+ ["-c", "dpkg -L libc6:$(dpkg --print-architecture) libgcc1:$(dpkg --print-architecture) | egrep '\\.so|gconv'"]
+ mempty