Make “sublibrary” standard terminology in docs
[cabal.git] / Cabal / src / Distribution / Simple / Program / Internal.hs
blobadd9dd74d71ca807a8ae59411e3baed20531fb08
1 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Distribution.Simple.Program.Internal
5 --
6 -- Maintainer : cabal-devel@haskell.org
7 -- Portability : portable
8 --
9 -- Internal utilities used by Distribution.Simple.Program.*.
10 module Distribution.Simple.Program.Internal
11 ( stripExtractVersion
12 ) where
14 import Distribution.Compat.Prelude
15 import Distribution.Utils.Generic (safeTail)
16 import Prelude ()
18 -- | Extract the version number from the output of 'strip --version'.
20 -- Invoking "strip --version" gives very inconsistent results. We ignore
21 -- everything in parentheses (see #2497), look for the first word that starts
22 -- with a number, and try parsing out the first two components of it. Non-GNU
23 -- 'strip' doesn't appear to have a version flag.
24 stripExtractVersion :: String -> String
25 stripExtractVersion str =
26 let numeric "" = False
27 numeric (x : _) = isDigit x
29 -- Filter out everything in parentheses.
30 filterPar' :: Int -> [String] -> [String]
31 filterPar' _ [] = []
32 filterPar' n (x : xs)
33 | n >= 0 && "(" `isPrefixOf` x = filterPar' (n + 1) ((safeTail x) : xs)
34 | n > 0 && ")" `isSuffixOf` x = filterPar' (n - 1) xs
35 | n > 0 = filterPar' n xs
36 | otherwise = x : filterPar' n xs
38 filterPar = filterPar' 0
39 in case dropWhile (not . numeric) (filterPar . words $ str) of
40 (ver : _) ->
41 -- take the first two version components
42 let isDot = (== '.')
43 (major, rest) = break isDot ver
44 minor = takeWhile isDigit (dropWhile isDot rest)
45 in major ++ "." ++ minor
46 _ -> ""