{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
module Distribution.Simple.Program.Strip (stripLib, stripExe)
where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Simple.Program
import Distribution.Simple.Utils
import Distribution.System
import Distribution.Verbosity
import Distribution.Version
import System.FilePath (takeBaseName)
runStrip :: Verbosity -> ProgramDb -> FilePath -> [String] -> IO ()
runStrip :: Verbosity -> ProgramDb -> FilePath -> [FilePath] -> IO ()
runStrip Verbosity
verbosity ProgramDb
progDb FilePath
path [FilePath]
args =
case Program -> ProgramDb -> Maybe ConfiguredProgram
lookupProgram Program
stripProgram ProgramDb
progDb of
Just ConfiguredProgram
strip -> Verbosity -> ConfiguredProgram -> [FilePath] -> IO ()
runProgram Verbosity
verbosity ConfiguredProgram
strip ([FilePath]
args [FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++ [FilePath
path])
Maybe ConfiguredProgram
Nothing -> Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (OS
buildOS OS -> OS -> Bool
forall a. Eq a => a -> a -> Bool
== OS
Windows) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
Verbosity -> FilePath -> IO ()
warn Verbosity
verbosity (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath
"Unable to strip executable or library '"
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ (FilePath -> FilePath
takeBaseName FilePath
path)
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"' (missing the 'strip' program)"
stripExe :: Verbosity -> Platform -> ProgramDb -> FilePath -> IO ()
stripExe :: Verbosity -> Platform -> ProgramDb -> FilePath -> IO ()
stripExe Verbosity
verbosity (Platform Arch
_arch OS
os) ProgramDb
progdb FilePath
path =
Verbosity -> ProgramDb -> FilePath -> [FilePath] -> IO ()
runStrip Verbosity
verbosity ProgramDb
progdb FilePath
path [FilePath]
args
where
args :: [FilePath]
args = case OS
os of
OS
OSX -> [FilePath
"-x"]
OS
_ -> []
stripLib :: Verbosity -> Platform -> ProgramDb -> FilePath -> IO ()
stripLib :: Verbosity -> Platform -> ProgramDb -> FilePath -> IO ()
stripLib Verbosity
verbosity (Platform Arch
arch OS
os) ProgramDb
progdb FilePath
path = do
case OS
os of
OS
OSX ->
() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
OS
IOS -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
OS
AIX -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
OS
Solaris -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
OS
Windows ->
() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return()
OS
Linux | Arch
arch Arch -> Arch -> Bool
forall a. Eq a => a -> a -> Bool
== Arch
I386 ->
let okVersion :: VersionRange
okVersion = Version -> VersionRange
orLaterVersion ([Int] -> Version
mkVersion [Int
2,Int
18])
in case ConfiguredProgram -> Maybe Version
programVersion (ConfiguredProgram -> Maybe Version)
-> Maybe ConfiguredProgram -> Maybe Version
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Program -> ProgramDb -> Maybe ConfiguredProgram
lookupProgram Program
stripProgram ProgramDb
progdb of
Just Version
v | Version -> VersionRange -> Bool
withinRange Version
v VersionRange
okVersion ->
Verbosity -> ProgramDb -> FilePath -> [FilePath] -> IO ()
runStrip Verbosity
verbosity ProgramDb
progdb FilePath
path [FilePath]
args
Maybe Version
_ -> Verbosity -> FilePath -> IO ()
warn Verbosity
verbosity (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath
"Unable to strip library '"
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ (FilePath -> FilePath
takeBaseName FilePath
path)
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"' (version of 'strip' too old; "
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"requires >= 2.18 on 32-bit Linux)"
OS
_ -> Verbosity -> ProgramDb -> FilePath -> [FilePath] -> IO ()
runStrip Verbosity
verbosity ProgramDb
progdb FilePath
path [FilePath]
args
where
args :: [FilePath]
args = [FilePath
"--strip-unneeded"]