Better document "build-tools" and "build-tool-depends"
[cabal.git] / Cabal / Distribution / Types / BuildInfo.hs
blob59bc8f5f422d5553e8ae0bf87b3202ece8a54889
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution.Types.BuildInfo (
5 BuildInfo(..),
7 emptyBuildInfo,
8 allLanguages,
9 allExtensions,
10 usedExtensions,
12 hcOptions,
13 hcProfOptions,
14 hcSharedOptions,
15 ) where
17 import Prelude ()
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
39 -- field directly.
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
48 -- field directly.
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
79 -- simple assoc-list.
80 targetBuildDepends :: [Dependency], -- ^ Dependencies specific to a library or executable target
81 mixins :: [Mixin]
83 deriving (Generic, Show, Read, Eq, Typeable, Data)
85 instance Binary BuildInfo
87 instance Monoid BuildInfo where
88 mempty = BuildInfo {
89 buildable = True,
90 buildTools = [],
91 toolDepends = [],
92 cppOptions = [],
93 ccOptions = [],
94 ldOptions = [],
95 pkgconfigDepends = [],
96 frameworks = [],
97 extraFrameworkDirs = [],
98 cSources = [],
99 jsSources = [],
100 hsSourceDirs = [],
101 otherModules = [],
102 autogenModules = [],
103 defaultLanguage = Nothing,
104 otherLanguages = [],
105 defaultExtensions = [],
106 otherExtensions = [],
107 oldExtensions = [],
108 extraLibs = [],
109 extraGHCiLibs = [],
110 extraLibDirs = [],
111 includeDirs = [],
112 includes = [],
113 installIncludes = [],
114 options = [],
115 profOptions = [],
116 sharedOptions = [],
117 customFieldsBI = [],
118 targetBuildDepends = [],
119 mixins = []
121 mappend = (<>)
123 instance Semigroup BuildInfo where
124 a <> b = BuildInfo {
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
157 where
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)
169 ++ otherLanguages 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
196 , hc' == hc
197 , opt <- opts ]