1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE DeriveGeneric #-}
5 module Distribution
.Types
.BuildInfo
11 , usesTemplateHaskellOrQQ
19 import Distribution
.Compat
.Prelude
22 import Distribution
.Types
.Dependency
23 import Distribution
.Types
.ExeDependency
24 import Distribution
.Types
.LegacyExeDependency
25 import Distribution
.Types
.Mixin
26 import Distribution
.Types
.PkgconfigDependency
27 import Distribution
.Utils
.Path
29 import Distribution
.Compiler
30 import Distribution
.ModuleName
31 import Language
.Haskell
.Extension
33 -- Consider refactoring into executable and library versions.
34 data BuildInfo
= BuildInfo
36 -- ^ component is buildable here
37 , buildTools
:: [LegacyExeDependency
]
38 -- ^ Tools needed to build this bit.
40 -- This is a legacy field that 'buildToolDepends' largely supersedes.
42 -- Unless use are very sure what you are doing, use the functions in
43 -- "Distribution.Simple.BuildToolDepends" rather than accessing this
45 , buildToolDepends
:: [ExeDependency
]
46 -- ^ Haskell tools needed to build this bit
48 -- This field is better than 'buildTools' because it allows one to
49 -- precisely specify an executable in a package.
51 -- Unless use are very sure what you are doing, use the functions in
52 -- "Distribution.Simple.BuildToolDepends" rather than accessing this
54 , cppOptions
:: [String]
55 -- ^ options for pre-processing Haskell code
56 , asmOptions
:: [String]
57 -- ^ options for assembler
58 , cmmOptions
:: [String]
59 -- ^ options for C-- compiler
60 , ccOptions
:: [String]
61 -- ^ options for C compiler
62 , cxxOptions
:: [String]
63 -- ^ options for C++ compiler
64 , ldOptions
:: [String]
65 -- ^ options for linker
66 , hsc2hsOptions
:: [String]
67 -- ^ options for hsc2hs
68 , pkgconfigDepends
:: [PkgconfigDependency
]
69 -- ^ pkg-config packages that are used
70 , frameworks
:: [RelativePath Framework File
]
71 -- ^ support frameworks for Mac OS X
72 , extraFrameworkDirs
:: [SymbolicPath Pkg
(Dir Framework
)]
73 -- ^ extra locations to find frameworks.
74 , asmSources
:: [SymbolicPath Pkg File
]
76 , cmmSources
:: [SymbolicPath Pkg File
]
78 , cSources
:: [SymbolicPath Pkg File
]
79 , cxxSources
:: [SymbolicPath Pkg File
]
80 , jsSources
:: [SymbolicPath Pkg File
]
81 , hsSourceDirs
:: [SymbolicPath Pkg
(Dir Source
)]
82 -- ^ where to look for the Haskell module hierarchy
83 , -- NB: these are symbolic paths are not relative paths,
84 -- because autogenerated modules might end up in an absolute path
85 otherModules
:: [ModuleName
]
86 -- ^ non-exposed or non-main modules
87 , virtualModules
:: [ModuleName
]
88 -- ^ exposed modules that do not have a source file (e.g. @GHC.Prim@ from @ghc-prim@ package)
89 , autogenModules
:: [ModuleName
]
90 -- ^ not present on sdist, Paths_* or user-generated with a custom Setup.hs
91 , defaultLanguage
:: Maybe Language
92 -- ^ language used when not explicitly specified
93 , otherLanguages
:: [Language
]
94 -- ^ other languages used within the package
95 , defaultExtensions
:: [Extension
]
96 -- ^ language extensions used by all modules
97 , otherExtensions
:: [Extension
]
98 -- ^ other language extensions used within the package
99 , oldExtensions
:: [Extension
]
100 -- ^ the old extensions field, treated same as 'defaultExtensions'
101 , extraLibs
:: [String]
102 -- ^ what libraries to link with when compiling a program that uses your package
103 , extraLibsStatic
:: [String]
104 -- ^ what libraries to link with when compiling a program fully statically that uses your package
105 , extraGHCiLibs
:: [String]
106 -- ^ if present, overrides extraLibs when package is loaded with GHCi.
107 , extraBundledLibs
:: [String]
108 -- ^ if present, adds libs to hs-libraries, which become part of the package.
109 -- Example 1: the Cffi library shipping with the rts, alongside the HSrts-1.0.a,.o,...
110 -- Example 2: a library that is being built by a foreign tool (e.g. rust)
111 -- and copied and registered together with this library. The
112 -- logic on how this library is built will have to be encoded in a
113 -- custom Setup for now. Otherwise cabal would need to learn how to
114 -- call arbitrary library builders.
115 , extraLibFlavours
:: [String]
116 -- ^ Hidden Flag. This set of strings, will be appended to all libraries when
117 -- copying. E.g. [libHS<name>_<flavour> | flavour <- extraLibFlavours]. This
118 -- should only be needed in very specific cases, e.g. the `rts` package, where
119 -- there are multiple copies of slightly differently built libs.
120 , extraDynLibFlavours
:: [String]
121 -- ^ Hidden Flag. This set of strings will be appended to all /dynamic/
122 -- libraries when copying. This is particularly useful with the `rts` package,
123 -- where we want different dynamic flavours of the RTS library to be installed.
124 , extraLibDirs
:: [SymbolicPath Pkg
(Dir Lib
)]
125 , extraLibDirsStatic
:: [SymbolicPath Pkg
(Dir Lib
)]
126 , includeDirs
:: [SymbolicPath Pkg
(Dir Include
)]
127 -- ^ directories to find .h files
128 , includes
:: [SymbolicPath Include File
]
129 -- ^ The .h files to be found in includeDirs
130 , autogenIncludes
:: [RelativePath Include File
]
131 -- ^ The .h files to be generated (e.g. by @autoconf@)
132 , installIncludes
:: [RelativePath Include File
]
133 -- ^ .h files to install with the package
134 , options
:: PerCompilerFlavor
[String]
135 , profOptions
:: PerCompilerFlavor
[String]
136 , sharedOptions
:: PerCompilerFlavor
[String]
137 , profSharedOptions
:: PerCompilerFlavor
[String]
138 , staticOptions
:: PerCompilerFlavor
[String]
139 , customFieldsBI
:: [(String, String)]
140 -- ^ Custom fields starting
141 -- with x-, stored in a
142 -- simple assoc-list.
143 , targetBuildDepends
:: [Dependency
]
144 -- ^ Dependencies specific to a library or executable target
147 deriving (Generic
, Show, Read, Eq
, Ord
, Typeable
, Data
)
149 instance Binary BuildInfo
150 instance Structured BuildInfo
151 instance NFData BuildInfo
where rnf
= genericRnf
153 instance Monoid BuildInfo
where
158 , buildToolDepends
= []
166 , pkgconfigDepends
= []
168 , extraFrameworkDirs
= []
176 , virtualModules
= []
177 , autogenModules
= []
178 , defaultLanguage
= Nothing
179 , otherLanguages
= []
180 , defaultExtensions
= []
181 , otherExtensions
= []
184 , extraLibsStatic
= []
186 , extraBundledLibs
= []
187 , extraLibFlavours
= []
188 , extraDynLibFlavours
= []
190 , extraLibDirsStatic
= []
193 , autogenIncludes
= []
194 , installIncludes
= []
196 , profOptions
= mempty
197 , sharedOptions
= mempty
198 , profSharedOptions
= mempty
199 , staticOptions
= mempty
200 , customFieldsBI
= []
201 , targetBuildDepends
= []
206 instance Semigroup BuildInfo
where
209 { buildable
= buildable a
&& buildable b
210 , buildTools
= combine buildTools
211 , buildToolDepends
= combine buildToolDepends
212 , cppOptions
= combine cppOptions
213 , asmOptions
= combine asmOptions
214 , cmmOptions
= combine cmmOptions
215 , ccOptions
= combine ccOptions
216 , cxxOptions
= combine cxxOptions
217 , ldOptions
= combine ldOptions
218 , hsc2hsOptions
= combine hsc2hsOptions
219 , pkgconfigDepends
= combine pkgconfigDepends
220 , frameworks
= combineNub frameworks
221 , extraFrameworkDirs
= combineNub extraFrameworkDirs
222 , asmSources
= combineNub asmSources
223 , cmmSources
= combineNub cmmSources
224 , cSources
= combineNub cSources
225 , cxxSources
= combineNub cxxSources
226 , jsSources
= combineNub jsSources
227 , hsSourceDirs
= combineNub hsSourceDirs
228 , otherModules
= combineNub otherModules
229 , virtualModules
= combineNub virtualModules
230 , autogenModules
= combineNub autogenModules
231 , defaultLanguage
= combineMby defaultLanguage
232 , otherLanguages
= combineNub otherLanguages
233 , defaultExtensions
= combineNub defaultExtensions
234 , otherExtensions
= combineNub otherExtensions
235 , oldExtensions
= combineNub oldExtensions
236 , extraLibs
= combine extraLibs
237 , extraLibsStatic
= combine extraLibsStatic
238 , extraGHCiLibs
= combine extraGHCiLibs
239 , extraBundledLibs
= combine extraBundledLibs
240 , extraLibFlavours
= combine extraLibFlavours
241 , extraDynLibFlavours
= combine extraDynLibFlavours
242 , extraLibDirs
= combineNub extraLibDirs
243 , extraLibDirsStatic
= combineNub extraLibDirsStatic
244 , includeDirs
= combineNub includeDirs
245 , includes
= combineNub includes
246 , autogenIncludes
= combineNub autogenIncludes
247 , installIncludes
= combineNub installIncludes
248 , options
= combine options
249 , profOptions
= combine profOptions
250 , sharedOptions
= combine sharedOptions
251 , profSharedOptions
= combine profSharedOptions
252 , staticOptions
= combine staticOptions
253 , customFieldsBI
= combine customFieldsBI
254 , targetBuildDepends
= combineNub targetBuildDepends
255 , mixins
= combine mixins
258 combine field
= field a `mappend` field b
259 combineNub field
= nub (combine field
)
260 combineMby field
= field b `mplus` field a
262 emptyBuildInfo
:: BuildInfo
263 emptyBuildInfo
= mempty
265 -- | The 'Language's used by this component
266 allLanguages
:: BuildInfo
-> [Language
]
268 maybeToList (defaultLanguage bi
)
271 -- | The 'Extension's that are used somewhere by this component
272 allExtensions
:: BuildInfo
-> [Extension
]
275 ++ otherExtensions bi
277 -- | The 'Extensions' that are used by all modules in this component
278 usedExtensions
:: BuildInfo
-> [Extension
]
281 ++ defaultExtensions bi
283 -- | Whether any modules in this component use Template Haskell or
285 usesTemplateHaskellOrQQ
:: BuildInfo
-> Bool
286 usesTemplateHaskellOrQQ bi
= any p
(allExtensions bi
)
290 `
elem`
[EnableExtension TemplateHaskell
, EnableExtension QuasiQuotes
]
292 -- | Select options for a particular Haskell compiler.
293 hcOptions
:: CompilerFlavor
-> BuildInfo
-> [String]
294 hcOptions
= lookupHcOptions options
296 hcProfOptions
:: CompilerFlavor
-> BuildInfo
-> [String]
297 hcProfOptions
= lookupHcOptions profOptions
299 hcSharedOptions
:: CompilerFlavor
-> BuildInfo
-> [String]
300 hcSharedOptions
= lookupHcOptions sharedOptions
302 hcProfSharedOptions
:: CompilerFlavor
-> BuildInfo
-> [String]
303 hcProfSharedOptions
= lookupHcOptions profSharedOptions
305 hcStaticOptions
:: CompilerFlavor
-> BuildInfo
-> [String]
306 hcStaticOptions
= lookupHcOptions staticOptions
309 :: (BuildInfo
-> PerCompilerFlavor
[String])
313 lookupHcOptions f hc bi
= case f bi
of
314 PerCompilerFlavor ghc ghcjs
316 | hc
== GHCJS
-> ghcjs
317 |
otherwise -> mempty