1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 module Distribution
.Types
.PkgconfigName
11 import Distribution
.Compat
.Prelude
12 import Distribution
.Utils
.ShortText
15 import Distribution
.Parsec
16 import Distribution
.Pretty
18 import qualified Distribution
.Compat
.CharParsing
as P
19 import qualified Text
.PrettyPrint
as Disp
21 -- | A pkg-config library name
23 -- This is parsed as any valid argument to the pkg-config utility.
26 newtype PkgconfigName
= PkgconfigName ShortText
27 deriving (Generic
, Read, Show, Eq
, Ord
, Typeable
, Data
)
29 -- | Convert 'PkgconfigName' to 'String'
32 unPkgconfigName
:: PkgconfigName
-> String
33 unPkgconfigName
(PkgconfigName s
) = fromShortText s
35 -- | Construct a 'PkgconfigName' from a 'String'
37 -- 'mkPkgconfigName' is the inverse to 'unPkgconfigName'
39 -- Note: No validations are performed to ensure that the resulting
40 -- 'PkgconfigName' is valid
43 mkPkgconfigName
:: String -> PkgconfigName
44 mkPkgconfigName
= PkgconfigName
. toShortText
46 -- | 'mkPkgconfigName'
49 instance IsString PkgconfigName
where
50 fromString
= mkPkgconfigName
52 instance Binary PkgconfigName
53 instance Structured PkgconfigName
55 -- pkg-config allows versions and other letters in package names, eg
56 -- "gtk+-2.0" is a valid pkg-config package _name_. It then has a package
57 -- version number like 2.10.13
58 instance Pretty PkgconfigName
where
59 pretty
= Disp
.text
. unPkgconfigName
61 instance Parsec PkgconfigName
where
62 parsec
= mkPkgconfigName
<$> P
.munch1 isNameChar
64 -- https://gitlab.haskell.org/ghc/ghc/issues/17752
69 isNameChar c
= isAlphaNum c
71 instance NFData PkgconfigName
where
72 rnf
(PkgconfigName pkg
) = rnf pkg