Make “sublibrary” standard terminology in docs
[cabal.git] / Cabal / src / Distribution / Simple / Program / Strip.hs
blobbb43e5ed47d89544f44e5fa8490e757d1fd4c637
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE RankNTypes #-}
4 -----------------------------------------------------------------------------
6 -- |
7 -- Module : Distribution.Simple.Program.Strip
8 --
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)
14 where
16 import Distribution.Compat.Prelude
17 import 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])
31 Nothing ->
32 unless (buildOS == Windows) $
33 -- Don't bother warning on windows, we don't expect them to
34 -- have the strip program anyway.
35 warn verbosity $
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
43 where
44 args = case os of
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.
49 _ -> []
51 stripLib :: Verbosity -> Platform -> ProgramDb -> FilePath -> IO ()
52 stripLib verbosity (Platform arch os) progdb path = do
53 case os of
54 OSX ->
55 -- '--strip-unneeded' is not supported on OS X, iOS, AIX, or
56 -- Solaris. See #1630.
57 return ()
58 IOS -> return ()
59 AIX -> return ()
60 Solaris -> return ()
61 Windows ->
62 -- Stripping triggers a bug in 'strip.exe' for
63 -- libraries with lots identically named modules. See
64 -- #1784.
65 return ()
66 Linux
67 | arch == I386 ->
68 -- Versions of 'strip' on 32-bit Linux older than 2.18 are
69 -- broken. See #2339.
70 let okVersion = orLaterVersion (mkVersion [2, 18])
71 in case programVersion =<< lookupProgram stripProgram progdb of
72 Just v
73 | withinRange v okVersion ->
74 runStrip verbosity progdb path args
75 _ ->
76 warn verbosity $
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
82 where
83 args = ["--strip-unneeded"]