{-# 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 progDb path args =
case lookupProgram stripProgram progDb of
Just strip -> runProgram verbosity strip (args ++ [path])
Nothing -> unless (buildOS == Windows) $
warn verbosity $ "Unable to strip executable or library '"
++ (takeBaseName path)
++ "' (missing the 'strip' program)"
stripExe :: Verbosity -> Platform -> ProgramDb -> FilePath -> IO ()
stripExe verbosity (Platform _arch os) progdb path =
runStrip verbosity progdb path args
where
args = case os of
OSX -> ["-x"]
_ -> []
stripLib :: Verbosity -> Platform -> ProgramDb -> FilePath -> IO ()
stripLib verbosity (Platform arch os) progdb path = do
case os of
OSX ->
return ()
IOS -> return ()
AIX -> return ()
Solaris -> return ()
Windows ->
return()
Linux | arch == I386 ->
let okVersion = orLaterVersion (mkVersion [2,18])
in case programVersion =<< lookupProgram stripProgram progdb of
Just v | withinRange v okVersion ->
runStrip verbosity progdb path args
_ -> warn verbosity $ "Unable to strip library '"
++ (takeBaseName path)
++ "' (version of 'strip' too old; "
++ "requires >= 2.18 on 32-bit Linux)"
_ -> runStrip verbosity progdb path args
where
args = ["--strip-unneeded"]