| 1 | # Copyright 1999-2006 Gentoo Foundation |
1 | # Copyright 1999-2006 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.11 2007/07/25 18:07:02 dcoutts Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.15 2009/07/27 19:03:20 kolmodin Exp $ |
| 4 | # |
4 | # |
| 5 | # Original authors: Andres Loeh <kosmikus@gentoo.org> |
5 | # Original authors: Andres Loeh <kosmikus@gentoo.org> |
| 6 | # Duncan Coutts <dcoutts@gentoo.org> |
6 | # Duncan Coutts <dcoutts@gentoo.org> |
| 7 | # Maintained by: Haskell herd <haskell@gentoo.org> |
7 | # Maintained by: Haskell herd <haskell@gentoo.org> |
| 8 | # |
8 | # |
| … | |
… | |
| 59 | done |
59 | done |
| 60 | |
60 | |
| 61 | if [[ -n "${CABAL_USE_HADDOCK}" ]]; then |
61 | if [[ -n "${CABAL_USE_HADDOCK}" ]]; then |
| 62 | IUSE="${IUSE} doc" |
62 | IUSE="${IUSE} doc" |
| 63 | DEPEND="${DEPEND} doc? ( dev-haskell/haddock )" |
63 | DEPEND="${DEPEND} doc? ( dev-haskell/haddock )" |
| 64 | cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock" |
|
|
| 65 | fi |
64 | fi |
| 66 | |
65 | |
| 67 | if [[ -n "${CABAL_USE_ALEX}" ]]; then |
66 | if [[ -n "${CABAL_USE_ALEX}" ]]; then |
| 68 | DEPEND="${DEPEND} dev-haskell/alex" |
67 | DEPEND="${DEPEND} dev-haskell/alex" |
| 69 | cabalconf="${cabalconf} --with-alex=/usr/bin/alex" |
68 | cabalconf="${cabalconf} --with-alex=/usr/bin/alex" |
| … | |
… | |
| 88 | IUSE="${IUSE} profile" |
87 | IUSE="${IUSE} profile" |
| 89 | fi |
88 | fi |
| 90 | |
89 | |
| 91 | # We always use a standalone version of Cabal, rather than the one that comes |
90 | # We always use a standalone version of Cabal, rather than the one that comes |
| 92 | # with GHC. But of course we can't depend on cabal when building cabal itself. |
91 | # with GHC. But of course we can't depend on cabal when building cabal itself. |
|
|
92 | if [[ -z ${CABAL_MIN_VERSION} ]]; then |
| 93 | CABAL_MIN_VERSION=1.1.4 |
93 | CABAL_MIN_VERSION=1.1.4 |
|
|
94 | fi |
| 94 | if [[ -z "${CABAL_BOOTSTRAP}" ]]; then |
95 | if [[ -z "${CABAL_BOOTSTRAP}" ]]; then |
| 95 | DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" |
96 | DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" |
| 96 | fi |
97 | fi |
| 97 | |
98 | |
| 98 | # Libraries require GHC to be installed. |
99 | # Libraries require GHC to be installed. |
| 99 | if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then |
100 | if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then |
| 100 | RDEPEND="${RDEPEND} dev-lang/ghc" |
101 | RDEPEND="${RDEPEND} dev-lang/ghc" |
| 101 | fi |
102 | fi |
| 102 | |
103 | |
|
|
104 | # returns the version of cabal currently in use |
|
|
105 | _CABAL_VERSION_CACHE="" |
|
|
106 | cabal-version() { |
|
|
107 | if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then |
|
|
108 | if [[ "${CABAL_BOOTSTRAP}" ]]; then |
|
|
109 | # We're bootstrapping cabal, so the cabal version is the version |
|
|
110 | # of this package itself. |
|
|
111 | _CABAL_VERSION_CACHE="${PV}" |
|
|
112 | else |
|
|
113 | # We ask portage, not ghc, so that we only pick up |
|
|
114 | # portage-installed cabal versions. |
|
|
115 | _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" |
|
|
116 | fi |
|
|
117 | fi |
|
|
118 | echo "${_CABAL_VERSION_CACHE}" |
|
|
119 | } |
|
|
120 | |
| 103 | cabal-bootstrap() { |
121 | cabal-bootstrap() { |
| 104 | local setupmodule |
122 | local setupmodule |
| 105 | local cabalversion |
123 | local cabalpackage |
| 106 | if [[ -f "${S}/Setup.lhs" ]]; then |
124 | if [[ -f "${S}/Setup.lhs" ]]; then |
| 107 | setupmodule="${S}/Setup.lhs" |
125 | setupmodule="${S}/Setup.lhs" |
| 108 | else |
126 | else |
| 109 | if [[ -f "${S}/Setup.hs" ]]; then |
127 | if [[ -f "${S}/Setup.hs" ]]; then |
| 110 | setupmodule="${S}/Setup.hs" |
128 | setupmodule="${S}/Setup.hs" |
| … | |
… | |
| 113 | fi |
131 | fi |
| 114 | fi |
132 | fi |
| 115 | |
133 | |
| 116 | # We build the setup program using the latest version of |
134 | # We build the setup program using the latest version of |
| 117 | # cabal that we have installed |
135 | # cabal that we have installed |
| 118 | cabalversion=$(ghc-bestcabalversion) |
136 | if version_is_at_least "6.4" "$(ghc-version)"; then |
|
|
137 | cabalpackage=Cabal-$(cabal-version) |
|
|
138 | else |
|
|
139 | # older ghc's don't support package versioning |
|
|
140 | cabalpackage=Cabal |
|
|
141 | fi |
| 119 | einfo "Using ${cabalversion}." |
142 | einfo "Using cabal-$(cabal-version)." |
| 120 | $(ghc-getghc) -package "${cabalversion}" --make "${setupmodule}" -o setup \ |
143 | $(ghc-getghc) -package "${cabalpackage}" --make "${setupmodule}" -o setup \ |
| 121 | || die "compiling ${setupmodule} failed" |
144 | || die "compiling ${setupmodule} failed" |
|
|
145 | } |
|
|
146 | |
|
|
147 | cabal-mksetup() { |
|
|
148 | local setupdir |
|
|
149 | |
|
|
150 | if [[ -n $1 ]]; then |
|
|
151 | setupdir=$1 |
|
|
152 | else |
|
|
153 | setupdir=${S} |
|
|
154 | fi |
|
|
155 | |
|
|
156 | rm -f "${setupdir}"/Setup.{lhs,hs} |
|
|
157 | |
|
|
158 | echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \ |
|
|
159 | > $setupdir/Setup.hs |
| 122 | } |
160 | } |
| 123 | |
161 | |
| 124 | cabal-haddock() { |
162 | cabal-haddock() { |
| 125 | ./setup haddock || die "setup haddock failed" |
163 | ./setup haddock || die "setup haddock failed" |
| 126 | } |
164 | } |
| 127 | |
165 | |
| 128 | cabal-configure() { |
166 | cabal-configure() { |
|
|
167 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
|
|
168 | cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock" |
|
|
169 | fi |
| 129 | if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then |
170 | if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then |
| 130 | cabalconf="${cabalconf} --enable-executable-profiling"; |
|
|
| 131 | cabalconf="${cabalconf} --enable-library-profiling" |
171 | cabalconf="${cabalconf} --enable-library-profiling" |
| 132 | fi |
172 | fi |
| 133 | # Building GHCi libs on ppc64 causes "TOC overflow". |
173 | # Building GHCi libs on ppc64 causes "TOC overflow". |
| 134 | if use ppc64; then |
174 | if use ppc64; then |
| 135 | cabalconf="${cabalconf} --disable-library-for-ghci" |
175 | cabalconf="${cabalconf} --disable-library-for-ghci" |
| 136 | fi |
176 | fi |
| 137 | |
177 | |
|
|
178 | if version_is_at_least "1.2.0" "$(cabal-version)"; then |
|
|
179 | cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}" |
|
|
180 | # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes |
|
|
181 | # it's better if the configure chatter is in the build logs: |
|
|
182 | cabalconf="${cabalconf} --verbose" |
|
|
183 | fi |
| 138 | # Note: with Cabal-1.1.6.x we still do not have enough control |
184 | # Note: with Cabal-1.1.6.x we do not have enough control |
| 139 | # to put the docs into the right place. They're currently going |
185 | # to put the docs into the right place. They're currently going |
| 140 | # into /usr/share/${P}/ghc-x.y/doc/ |
186 | # into /usr/share/${P}/ghc-x.y/doc/ |
| 141 | # rather than /usr/share/doc/${PF}/ |
187 | # rather than /usr/share/doc/${PF}/ |
| 142 | # Because we can only set the datadir, not the docdir. |
188 | # Because we can only set the datadir, not the docdir. |
| 143 | |
189 | |
| … | |
… | |
| 154 | ${CABAL_CONFIGURE_FLAGS} \ |
200 | ${CABAL_CONFIGURE_FLAGS} \ |
| 155 | "$@" || die "setup configure failed" |
201 | "$@" || die "setup configure failed" |
| 156 | } |
202 | } |
| 157 | |
203 | |
| 158 | cabal-build() { |
204 | cabal-build() { |
|
|
205 | unset LANG LC_ALL LC_MESSAGES |
| 159 | ./setup build \ |
206 | ./setup build \ |
| 160 | || die "setup build failed" |
207 | || die "setup build failed" |
| 161 | } |
208 | } |
| 162 | |
209 | |
| 163 | cabal-copy() { |
210 | cabal-copy() { |
| … | |
… | |
| 184 | # register that ourselves (if it exists). |
231 | # register that ourselves (if it exists). |
| 185 | local result |
232 | local result |
| 186 | local err |
233 | local err |
| 187 | |
234 | |
| 188 | if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then |
235 | if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then |
| 189 | sed -i "s|$(ghc-getghcpkg)|$(which true)|" .setup-config |
236 | if version_is_at_least "1.2.0" "$(cabal-version)"; then |
| 190 | ./setup register || die "setup register failed" |
237 | # Newer cabal can generate a package conf for us: |
| 191 | if [[ -f .installed-pkg-config ]]; then |
238 | ./setup register --gen-pkg-config="${T}/${P}.conf" |
| 192 | ghc-setup-pkg .installed-pkg-config |
239 | ghc-setup-pkg "${T}/${P}.conf" |
| 193 | ghc-install-pkg |
240 | ghc-install-pkg |
| 194 | else |
241 | else |
|
|
242 | # With older cabal we have to hack it by replacing its ghc-pkg |
|
|
243 | # with true and then just picking up the .installed-pkg-config |
|
|
244 | # file and registering that ourselves (if it exists). |
|
|
245 | sed -i "s|$(ghc-getghcpkg)|$(type -P true)|" .setup-config |
|
|
246 | ./setup register || die "setup register failed" |
|
|
247 | if [[ -f .installed-pkg-config ]]; then |
|
|
248 | ghc-setup-pkg .installed-pkg-config |
|
|
249 | ghc-install-pkg |
|
|
250 | else |
| 195 | die "setup register has not generated a package configuration file" |
251 | die "setup register has not generated a package configuration file" |
| 196 | fi |
252 | fi |
| 197 | fi |
253 | fi |
|
|
254 | fi |
|
|
255 | } |
|
|
256 | |
|
|
257 | # Some cabal libs are bundled along with some versions of ghc |
|
|
258 | # eg filepath-1.0 comes with ghc-6.6.1 |
|
|
259 | # by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that |
|
|
260 | # when building with this version of ghc, the ebuild is a dummy that is it will |
|
|
261 | # install no files since the package is already included with ghc. |
|
|
262 | # However portage still records the dependency and we can upgrade the package |
|
|
263 | # to a later one that's not included with ghc. |
|
|
264 | # You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1". |
|
|
265 | cabal-is-dummy-lib() { |
|
|
266 | for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do |
|
|
267 | [[ "$(ghc-version)" == "$version" ]] && return 0 |
|
|
268 | done |
|
|
269 | return 1 |
| 198 | } |
270 | } |
| 199 | |
271 | |
| 200 | # exported function: check if cabal is correctly installed for |
272 | # exported function: check if cabal is correctly installed for |
| 201 | # the currently active ghc (we cannot guarantee this with portage) |
273 | # the currently active ghc (we cannot guarantee this with portage) |
| 202 | haskell-cabal_pkg_setup() { |
274 | haskell-cabal_pkg_setup() { |
| … | |
… | |
| 209 | fi |
281 | fi |
| 210 | if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then |
282 | if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then |
| 211 | eerror "QA: Neither bin nor lib are in CABAL_FEATURES." |
283 | eerror "QA: Neither bin nor lib are in CABAL_FEATURES." |
| 212 | fi |
284 | fi |
| 213 | if [[ -n "${CABAL_UNKNOWN}" ]]; then |
285 | if [[ -n "${CABAL_UNKNOWN}" ]]; then |
| 214 | ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}" |
286 | ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" |
|
|
287 | fi |
|
|
288 | if cabal-is-dummy-lib; then |
|
|
289 | einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install." |
| 215 | fi |
290 | fi |
| 216 | } |
291 | } |
| 217 | |
292 | |
| 218 | # exported function: cabal-style bootstrap configure and compile |
293 | # exported function: cabal-style bootstrap configure and compile |
| 219 | cabal_src_compile() { |
294 | cabal_src_compile() { |
|
|
295 | if ! cabal-is-dummy-lib; then |
| 220 | cabal-bootstrap |
296 | cabal-bootstrap |
| 221 | cabal-configure |
297 | cabal-configure |
| 222 | cabal-build |
298 | cabal-build |
| 223 | |
299 | |
| 224 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
300 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
| 225 | cabal-haddock |
301 | cabal-haddock |
|
|
302 | fi |
| 226 | fi |
303 | fi |
| 227 | } |
304 | } |
| 228 | haskell-cabal_src_compile() { |
305 | haskell-cabal_src_compile() { |
| 229 | cabal_src_compile |
306 | cabal_src_compile |
| 230 | } |
307 | } |
| 231 | |
308 | |
| 232 | # exported function: cabal-style copy and register |
309 | # exported function: cabal-style copy and register |
| 233 | cabal_src_install() { |
310 | cabal_src_install() { |
|
|
311 | if cabal-is-dummy-lib; then |
|
|
312 | # create a dummy local package conf file for the sake of ghc-updater |
|
|
313 | dodir "$(ghc-confdir)" |
|
|
314 | echo '[]' > "${D}/$(ghc-confdir)/$(ghc-localpkgconf)" |
|
|
315 | else |
| 234 | cabal-copy |
316 | cabal-copy |
| 235 | cabal-pkg |
317 | cabal-pkg |
| 236 | |
318 | |
| 237 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
319 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
| 238 | local cabalversion=$(ghc-extractportageversion dev-haskell/cabal) |
|
|
| 239 | if ! version_is_at_least "1.1.6" "${cabalversion}"; then |
320 | if ! version_is_at_least "1.1.6" "$(cabal-version)"; then |
| 240 | dohtml -r dist/doc/html/* |
321 | dohtml -r dist/doc/html/* |
|
|
322 | fi |
| 241 | fi |
323 | fi |
| 242 | fi |
324 | fi |
| 243 | } |
325 | } |
| 244 | haskell-cabal_src_install() { |
326 | haskell-cabal_src_install() { |
| 245 | cabal_src_install |
327 | cabal_src_install |