1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution
.Types
.BuildInfo
(
18 import Distribution
.Compat
.Prelude
20 import Distribution
.Types
.Mixin
21 import Distribution
.Types
.Dependency
22 import Distribution
.Types
.ExeDependency
23 import Distribution
.Types
.LegacyExeDependency
24 import Distribution
.Types
.PkgconfigDependency
26 import Distribution
.ModuleName
27 import Distribution
.Compiler
28 import Language
.Haskell
.Extension
30 -- Consider refactoring into executable and library versions.
31 data BuildInfo
= BuildInfo
{
32 buildable
:: Bool, -- ^ component is buildable here
33 -- | Tools needed to build this bit.
35 -- This is a legacy field that "build-tool-depends" larely supersedes.
37 -- Unless use are very sure what you are doing, use the functions in
38 -- `Distribution.Simple.BuildToolDepends` rather than accessing this
40 buildTools
:: [LegacyExeDependency
],
41 -- | Haskell tools needed to build this bit
43 -- This field is better than "build-tools" because it allows one to
44 -- precisely specify an executable in a package.
46 -- Unless use are very sure what you are doing, use the functions in
47 -- `Distribution.Simple.BuildToolDepends` rather than accessing this
49 toolDepends
:: [ExeDependency
],
50 cppOptions
:: [String], -- ^ options for pre-processing Haskell code
51 ccOptions
:: [String], -- ^ options for C compiler
52 ldOptions
:: [String], -- ^ options for linker
53 pkgconfigDepends
:: [PkgconfigDependency
], -- ^ pkg-config packages that are used
54 frameworks
:: [String], -- ^support frameworks for Mac OS X
55 extraFrameworkDirs
:: [String], -- ^ extra locations to find frameworks.
56 cSources
:: [FilePath],
57 jsSources
:: [FilePath],
58 hsSourceDirs
:: [FilePath], -- ^ where to look for the Haskell module hierarchy
59 otherModules
:: [ModuleName
], -- ^ non-exposed or non-main modules
60 autogenModules
:: [ModuleName
], -- ^ not present on sdist, Paths_* or user-generated with a custom Setup.hs
62 defaultLanguage
:: Maybe Language
,-- ^ language used when not explicitly specified
63 otherLanguages
:: [Language
], -- ^ other languages used within the package
64 defaultExtensions
:: [Extension
], -- ^ language extensions used by all modules
65 otherExtensions
:: [Extension
], -- ^ other language extensions used within the package
66 oldExtensions
:: [Extension
], -- ^ the old extensions field, treated same as 'defaultExtensions'
68 extraLibs
:: [String], -- ^ what libraries to link with when compiling a program that uses your package
69 extraGHCiLibs
:: [String], -- ^ if present, overrides extraLibs when package is loaded with GHCi.
70 extraLibDirs
:: [String],
71 includeDirs
:: [FilePath], -- ^directories to find .h files
72 includes
:: [FilePath], -- ^ The .h files to be found in includeDirs
73 installIncludes
:: [FilePath], -- ^ .h files to install with the package
74 options
:: [(CompilerFlavor
,[String])],
75 profOptions
:: [(CompilerFlavor
,[String])],
76 sharedOptions
:: [(CompilerFlavor
,[String])],
77 customFieldsBI
:: [(String,String)], -- ^Custom fields starting
78 -- with x-, stored in a
80 targetBuildDepends
:: [Dependency
], -- ^ Dependencies specific to a library or executable target
83 deriving (Generic
, Show, Read, Eq
, Typeable
, Data
)
85 instance Binary BuildInfo
87 instance Monoid BuildInfo
where
95 pkgconfigDepends
= [],
97 extraFrameworkDirs
= [],
103 defaultLanguage
= Nothing
,
105 defaultExtensions
= [],
106 otherExtensions
= [],
113 installIncludes
= [],
118 targetBuildDepends
= [],
123 instance Semigroup BuildInfo
where
125 buildable
= buildable a
&& buildable b
,
126 buildTools
= combine buildTools
,
127 toolDepends
= combine toolDepends
,
128 cppOptions
= combine cppOptions
,
129 ccOptions
= combine ccOptions
,
130 ldOptions
= combine ldOptions
,
131 pkgconfigDepends
= combine pkgconfigDepends
,
132 frameworks
= combineNub frameworks
,
133 extraFrameworkDirs
= combineNub extraFrameworkDirs
,
134 cSources
= combineNub cSources
,
135 jsSources
= combineNub jsSources
,
136 hsSourceDirs
= combineNub hsSourceDirs
,
137 otherModules
= combineNub otherModules
,
138 autogenModules
= combineNub autogenModules
,
139 defaultLanguage
= combineMby defaultLanguage
,
140 otherLanguages
= combineNub otherLanguages
,
141 defaultExtensions
= combineNub defaultExtensions
,
142 otherExtensions
= combineNub otherExtensions
,
143 oldExtensions
= combineNub oldExtensions
,
144 extraLibs
= combine extraLibs
,
145 extraGHCiLibs
= combine extraGHCiLibs
,
146 extraLibDirs
= combineNub extraLibDirs
,
147 includeDirs
= combineNub includeDirs
,
148 includes
= combineNub includes
,
149 installIncludes
= combineNub installIncludes
,
150 options
= combine options
,
151 profOptions
= combine profOptions
,
152 sharedOptions
= combine sharedOptions
,
153 customFieldsBI
= combine customFieldsBI
,
154 targetBuildDepends
= combineNub targetBuildDepends
,
155 mixins
= combine mixins
158 combine field
= field a `mappend` field b
159 combineNub field
= nub (combine field
)
160 combineMby field
= field b `mplus` field a
162 emptyBuildInfo
:: BuildInfo
163 emptyBuildInfo
= mempty
165 -- | The 'Language's used by this component
167 allLanguages
:: BuildInfo
-> [Language
]
168 allLanguages bi
= maybeToList (defaultLanguage bi
)
171 -- | The 'Extension's that are used somewhere by this component
173 allExtensions
:: BuildInfo
-> [Extension
]
174 allExtensions bi
= usedExtensions bi
175 ++ otherExtensions bi
177 -- | The 'Extensions' that are used by all modules in this component
179 usedExtensions
:: BuildInfo
-> [Extension
]
180 usedExtensions bi
= oldExtensions bi
181 ++ defaultExtensions bi
183 -- |Select options for a particular Haskell compiler.
184 hcOptions
:: CompilerFlavor
-> BuildInfo
-> [String]
185 hcOptions
= lookupHcOptions options
187 hcProfOptions
:: CompilerFlavor
-> BuildInfo
-> [String]
188 hcProfOptions
= lookupHcOptions profOptions
190 hcSharedOptions
:: CompilerFlavor
-> BuildInfo
-> [String]
191 hcSharedOptions
= lookupHcOptions sharedOptions
193 lookupHcOptions
:: (BuildInfo
-> [(CompilerFlavor
,[String])])
194 -> CompilerFlavor
-> BuildInfo
-> [String]
195 lookupHcOptions f hc bi
= [ opt |
(hc
',opts
) <- f bi