1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE RankNTypes #-}
4 -----------------------------------------------------------------------------
7 -- Module : Distribution.Simple.Program.Strip
9 -- Maintainer : cabal-devel@haskell.org
10 -- Portability : portable
12 -- This module provides an library interface to the @strip@ program.
13 module Distribution
.Simple
.Program
.Strip
(stripLib
, stripExe
)
16 import Distribution
.Compat
.Prelude
19 import Distribution
.Simple
.Program
20 import Distribution
.Simple
.Utils
21 import Distribution
.System
22 import Distribution
.Verbosity
23 import Distribution
.Version
25 import System
.FilePath (takeBaseName
)
27 runStrip
:: Verbosity
-> ProgramDb
-> FilePath -> [String] -> IO ()
28 runStrip verbosity progDb path args
=
29 case lookupProgram stripProgram progDb
of
30 Just strip
-> runProgram verbosity strip
(args
++ [path
])
32 unless (buildOS
== Windows
) $
33 -- Don't bother warning on windows, we don't expect them to
34 -- have the strip program anyway.
36 "Unable to strip executable or library '"
37 ++ (takeBaseName path
)
38 ++ "' (missing the 'strip' program)"
40 stripExe
:: Verbosity
-> Platform
-> ProgramDb
-> FilePath -> IO ()
41 stripExe verbosity
(Platform _arch os
) progdb path
=
42 runStrip verbosity progdb path args
45 OSX
-> ["-x"] -- By default, stripping the ghc binary on at least
46 -- some OS X installations causes:
47 -- HSbase-3.0.o: unknown symbol `_environ'"
48 -- The -x flag fixes that.
51 stripLib
:: Verbosity
-> Platform
-> ProgramDb
-> FilePath -> IO ()
52 stripLib verbosity
(Platform arch os
) progdb path
= do
55 -- '--strip-unneeded' is not supported on OS X, iOS, AIX, or
56 -- Solaris. See #1630.
62 -- Stripping triggers a bug in 'strip.exe' for
63 -- libraries with lots identically named modules. See
68 -- Versions of 'strip' on 32-bit Linux older than 2.18 are
70 let okVersion
= orLaterVersion
(mkVersion
[2, 18])
71 in case programVersion
=<< lookupProgram stripProgram progdb
of
73 | withinRange v okVersion
->
74 runStrip verbosity progdb path args
77 "Unable to strip library '"
78 ++ (takeBaseName path
)
79 ++ "' (version of 'strip' too old; "
80 ++ "requires >= 2.18 on 32-bit Linux)"
81 _
-> runStrip verbosity progdb path args
83 args
= ["--strip-unneeded"]