/[gentoo-x86]/eclass/haskell-cabal.eclass
Gentoo

Diff of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.40 Revision 1.53
1# Copyright 1999-2013 Gentoo Foundation 1# Copyright 1999-2015 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.40 2013/05/11 12:46:32 slyfox Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.53 2015/08/06 08:20:33 slyfox Exp $
4 4
5# @ECLASS: haskell-cabal.eclass 5# @ECLASS: haskell-cabal.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Haskell herd <haskell@gentoo.org> 7# Haskell herd <haskell@gentoo.org>
8# @AUTHOR: 8# @AUTHOR:
29# bin -- the package installs binaries 29# bin -- the package installs binaries
30# lib -- the package installs libraries 30# lib -- the package installs libraries
31# nocabaldep -- don't add dependency on cabal. 31# nocabaldep -- don't add dependency on cabal.
32# only used for packages that _must_ not pull the dependency 32# only used for packages that _must_ not pull the dependency
33# on cabal, but still use this eclass (e.g. haskell-updater). 33# on cabal, but still use this eclass (e.g. haskell-updater).
34# ghcdeps -- constraint dependency on package to ghc onces
35# only used for packages that use libghc internally and _must_
36# not pull upper versions
34# test-suite -- add support for cabal test-suites (introduced in Cabal-1.8) 37# test-suite -- add support for cabal test-suites (introduced in Cabal-1.8)
35 38
36inherit eutils ghc-package multilib 39inherit eutils ghc-package multilib multiprocessing
37 40
38# @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS 41# @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS
39# @DESCRIPTION: 42# @DESCRIPTION:
40# User-specified additional parameters passed to 'setup configure'. 43# User-specified additional parameters passed to 'setup configure'.
41# example: /etc/portage/make.conf: CABAL_EXTRA_CONFIGURE_FLAGS=--enable-shared 44# example: /etc/portage/make.conf:
45# CABAL_EXTRA_CONFIGURE_FLAGS="--enable-shared --enable-executable-dynamic"
42: ${CABAL_EXTRA_CONFIGURE_FLAGS:=} 46: ${CABAL_EXTRA_CONFIGURE_FLAGS:=}
43 47
44# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS 48# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS
45# @DESCRIPTION: 49# @DESCRIPTION:
46# User-specified additional parameters passed to 'setup build'. 50# User-specified additional parameters passed to 'setup build'.
59# @DESCRIPTION: 63# @DESCRIPTION:
60# Show debug output for 'cabal_chdeps' function if set. 64# Show debug output for 'cabal_chdeps' function if set.
61# Needs working 'diff'. 65# Needs working 'diff'.
62: ${CABAL_DEBUG_LOOSENING:=} 66: ${CABAL_DEBUG_LOOSENING:=}
63 67
64HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" 68HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install pkg_postinst pkg_postrm"
69
70# 'dev-haskell/cabal' passes those options with ./configure-based
71# configuration, but most packages don't need/don't accept it:
72# #515362, #515362
73QA_CONFIGURE_OPTIONS+=" --with-compiler --with-hc --with-hc-pkg --with-gcc"
65 74
66case "${EAPI:-0}" in 75case "${EAPI:-0}" in
67 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;; 76 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;;
68 *) ;; 77 *) ;;
69esac 78esac
82 profile) CABAL_USE_PROFILE=yes;; 91 profile) CABAL_USE_PROFILE=yes;;
83 bootstrap) CABAL_BOOTSTRAP=yes;; 92 bootstrap) CABAL_BOOTSTRAP=yes;;
84 bin) CABAL_HAS_BINARIES=yes;; 93 bin) CABAL_HAS_BINARIES=yes;;
85 lib) CABAL_HAS_LIBRARIES=yes;; 94 lib) CABAL_HAS_LIBRARIES=yes;;
86 nocabaldep) CABAL_FROM_GHC=yes;; 95 nocabaldep) CABAL_FROM_GHC=yes;;
96 ghcdeps) CABAL_GHC_CONSTRAINT=yes;;
87 test-suite) CABAL_TEST_SUITE=yes;; 97 test-suite) CABAL_TEST_SUITE=yes;;
88 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";; 98 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
89 esac 99 esac
90done 100done
91 101
99if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then 109if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then
100 IUSE="${IUSE} hscolour" 110 IUSE="${IUSE} hscolour"
101 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )" 111 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )"
102fi 112fi
103 113
114if [[ -n "${CABAL_USE_HOOGLE}" ]]; then
115 # enabled only in ::haskell
116 CABAL_USE_HOOGLE=
117fi
118
104if [[ -n "${CABAL_USE_ALEX}" ]]; then 119if [[ -n "${CABAL_USE_ALEX}" ]]; then
105 DEPEND="${DEPEND} dev-haskell/alex" 120 DEPEND="${DEPEND} dev-haskell/alex"
106fi 121fi
107 122
108if [[ -n "${CABAL_USE_HAPPY}" ]]; then 123if [[ -n "${CABAL_USE_HAPPY}" ]]; then
132fi 147fi
133if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then 148if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
134 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" 149 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
135fi 150fi
136 151
137# returns the version of cabal currently in use 152# returns the version of cabal currently in use.
153# Rarely it's handy to pin cabal version from outside.
138_CABAL_VERSION_CACHE="" 154: ${_CABAL_VERSION_CACHE:=""}
139cabal-version() { 155cabal-version() {
140 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then 156 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
141 if [[ "${CABAL_BOOTSTRAP}" ]]; then 157 if [[ "${CABAL_BOOTSTRAP}" ]]; then
142 # We're bootstrapping cabal, so the cabal version is the version 158 # We're bootstrapping cabal, so the cabal version is the version
143 # of this package itself. 159 # of this package itself.
144 _CABAL_VERSION_CACHE="${PV}" 160 _CABAL_VERSION_CACHE="${PV}"
145 elif [[ "${CABAL_FROM_GHC}" ]]; then 161 elif [[ "${CABAL_FROM_GHC}" ]]; then
146 local cabal_package=$(echo "$(ghc-libdir)"/Cabal-*) 162 _CABAL_VERSION_CACHE="$(ghc-cabal-version)"
147 # /path/to/ghc/Cabal-${VER} -> ${VER}
148 _CABAL_VERSION_CACHE="${cabal_package/*Cabal-/}"
149 else 163 else
150 # We ask portage, not ghc, so that we only pick up 164 # We ask portage, not ghc, so that we only pick up
151 # portage-installed cabal versions. 165 # portage-installed cabal versions.
152 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" 166 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
153 fi 167 fi
156} 170}
157 171
158cabal-bootstrap() { 172cabal-bootstrap() {
159 local setupmodule 173 local setupmodule
160 local cabalpackage 174 local cabalpackage
175 local setup_bootstrap_args=()
176
161 if [[ -f "${S}/Setup.lhs" ]]; then 177 if [[ -f "${S}/Setup.lhs" ]]; then
162 setupmodule="${S}/Setup.lhs" 178 setupmodule="${S}/Setup.lhs"
163 elif [[ -f "${S}/Setup.hs" ]]; then 179 elif [[ -f "${S}/Setup.hs" ]]; then
164 setupmodule="${S}/Setup.hs" 180 setupmodule="${S}/Setup.hs"
165 else 181 else
176 # We build the setup program using the latest version of 192 # We build the setup program using the latest version of
177 # cabal that we have installed 193 # cabal that we have installed
178 cabalpackage=Cabal-$(cabal-version) 194 cabalpackage=Cabal-$(cabal-version)
179 einfo "Using cabal-$(cabal-version)." 195 einfo "Using cabal-$(cabal-version)."
180 196
197 if $(ghc-supports-threaded-runtime); then
198 # Cabal has a bug that deadlocks non-threaded RTS:
199 # https://bugs.gentoo.org/537500
200 # https://github.com/haskell/cabal/issues/2398
201 setup_bootstrap_args+=(-threaded)
202 fi
203
181 make_setup() { 204 make_setup() {
182 set -- -package "${cabalpackage}" --make "${setupmodule}" \ 205 set -- -package "${cabalpackage}" --make "${setupmodule}" \
206 "${setup_bootstrap_args[@]}" \
207 ${HCFLAGS} \
183 ${GHC_BOOTSTRAP_FLAGS} \ 208 ${GHC_BOOTSTRAP_FLAGS} \
184 "$@" \ 209 "$@" \
185 -o setup 210 -o setup
186 echo $(ghc-getghc) ${HCFLAGS} "$@" 211 echo $(ghc-getghc) "$@"
187 $(ghc-getghc) "$@" 212 $(ghc-getghc) "$@"
188 } 213 }
189 if $(ghc-supports-shared-libraries); then 214 if $(ghc-supports-shared-libraries); then
190 # # some custom build systems might use external libraries, 215 # # some custom build systems might use external libraries,
191 # # for which we don't have shared libs, so keep static fallback 216 # # for which we don't have shared libs, so keep static fallback
207 make_setup "$@" || die "compiling ${setupmodule} failed" 232 make_setup "$@" || die "compiling ${setupmodule} failed"
208 fi 233 fi
209} 234}
210 235
211cabal-mksetup() { 236cabal-mksetup() {
212 local setupdir 237 local setupdir=${1:-${S}}
238 local setup_src=${setupdir}/Setup.hs
213 239
214 if [[ -n $1 ]]; then
215 setupdir=$1
216 else
217 setupdir=${S}
218 fi
219
220 rm -f "${setupdir}"/Setup.{lhs,hs} 240 rm -vf "${setupdir}"/Setup.{lhs,hs}
241 elog "Creating 'Setup.hs' for 'Simple' build type."
221 242
222 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \ 243 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
223 > $setupdir/Setup.hs || die "failed to create default Setup.hs" 244 > "${setup_src}" || die "failed to create default Setup.hs"
224} 245}
225 246
226cabal-hscolour() { 247cabal-hscolour() {
227 set -- hscolour "$@" 248 set -- hscolour "$@"
228 echo ./setup "$@" 249 echo ./setup "$@"
231 252
232cabal-haddock() { 253cabal-haddock() {
233 set -- haddock "$@" 254 set -- haddock "$@"
234 echo ./setup "$@" 255 echo ./setup "$@"
235 ./setup "$@" || die "setup haddock failed" 256 ./setup "$@" || die "setup haddock failed"
257}
258
259cabal-hoogle() {
260 ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
236} 261}
237 262
238cabal-hscolour-haddock() { 263cabal-hscolour-haddock() {
239 # --hyperlink-source implies calling 'setup hscolour' 264 # --hyperlink-source implies calling 'setup hscolour'
240 set -- haddock --hyperlink-source 265 set -- haddock --hyperlink-source
241 echo ./setup "$@" 266 echo ./setup "$@"
242 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed" 267 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed"
243} 268}
244 269
270cabal-hoogle-haddock() {
271 set -- haddock --hoogle
272 echo ./setup "$@"
273 ./setup "$@" || die "setup haddock --hoogle failed"
274}
275
276cabal-hoogle-hscolour-haddock() {
277 cabal-hscolour-haddock
278 cabal-hoogle-haddock
279}
280
281cabal-hoogle-hscolour() {
282 ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
283 cabal-hscolour
284}
285
286cabal-die-if-nonempty() {
287 local breakage_type=$1
288 shift
289
290 [[ "${#@}" == 0 ]] && return 0
291 eerror "Detected ${breakage_type} packages: ${@}"
292 die "//==-- Please, run 'haskell-updater' to fix ${breakage_type} packages --==//"
293}
294
245cabal-show-brokens() { 295cabal-show-brokens() {
296 elog "ghc-pkg check: 'checking for other broken packages:'"
246 # pretty-printer 297 # pretty-printer
247 $(ghc-getghcpkg) check 2>&1 \ 298 $(ghc-getghcpkg) check 2>&1 \
248 | egrep -v '^Warning: haddock-(html|interfaces): ' \ 299 | egrep -v '^Warning: haddock-(html|interfaces): ' \
249 | egrep -v '^Warning: include-dirs: ' 300 | egrep -v '^Warning: include-dirs: ' \
301 | head -n 20
250 302
303 cabal-die-if-nonempty 'broken' \
251 set -- $($(ghc-getghcpkg) check --simple-output) 304 $($(ghc-getghcpkg) check --simple-output)
252 [[ "${#@}" == 0 ]] && return 0 305}
253 306
254 eerror "Detected broken packages: ${@}" 307cabal-show-old() {
255 308 cabal-die-if-nonempty 'outdated' \
256 die "//==-- Please, run 'haskell-updater' to fix broken packages --==//" 309 $("${EPREFIX}"/usr/sbin/haskell-updater --quiet --upgrade --list-only)
257} 310}
258 311
259cabal-show-brokens-and-die() { 312cabal-show-brokens-and-die() {
260 cabal-show-brokens 313 cabal-show-brokens
314 cabal-show-old
261 315
262 die "$@" 316 die "$@"
263} 317}
264 318
265cabal-configure() { 319cabal-configure() {
320 local cabalconf=()
266 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= 321 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
267 322
268 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 323 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
324 # We use the bundled with GHC version if exists
325 # Haddock is very picky about index files
326 # it generates for ghc's base and other packages.
327 local p=${EPREFIX}/usr/bin/haddock-ghc-$(ghc-version)
328 if [[ -f $p ]]; then
329 cabalconf+=(--with-haddock="${p}")
330 else
269 cabalconf="${cabalconf} --with-haddock=${EPREFIX}/usr/bin/haddock" 331 cabalconf+=(--with-haddock=${EPREFIX}/usr/bin/haddock)
332 fi
270 fi 333 fi
271 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then 334 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
272 cabalconf="${cabalconf} --enable-library-profiling" 335 cabalconf+=(--enable-library-profiling)
273 fi 336 fi
274 if [[ -n "${CABAL_USE_ALEX}" ]]; then 337 if [[ -n "${CABAL_USE_ALEX}" ]]; then
275 cabalconf="${cabalconf} --with-alex=${EPREFIX}/usr/bin/alex" 338 cabalconf+=(--with-alex=${EPREFIX}/usr/bin/alex)
276 fi 339 fi
277 340
278 if [[ -n "${CABAL_USE_HAPPY}" ]]; then 341 if [[ -n "${CABAL_USE_HAPPY}" ]]; then
279 cabalconf="${cabalconf} --with-happy=${EPREFIX}/usr/bin/happy" 342 cabalconf+=(--with-happy=${EPREFIX}/usr/bin/happy)
280 fi 343 fi
281 344
282 if [[ -n "${CABAL_USE_C2HS}" ]]; then 345 if [[ -n "${CABAL_USE_C2HS}" ]]; then
283 cabalconf="${cabalconf} --with-c2hs=${EPREFIX}/usr/bin/c2hs" 346 cabalconf+=(--with-c2hs=${EPREFIX}/usr/bin/c2hs)
284 fi 347 fi
285 if [[ -n "${CABAL_USE_CPPHS}" ]]; then 348 if [[ -n "${CABAL_USE_CPPHS}" ]]; then
286 cabalconf="${cabalconf} --with-cpphs=${EPREFIX}/usr/bin/cpphs" 349 cabalconf+=(--with-cpphs=${EPREFIX}/usr/bin/cpphs)
287 fi 350 fi
288 if [[ -n "${CABAL_TEST_SUITE}" ]]; then 351 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
289 cabalconf="${cabalconf} $(use_enable test tests)" 352 cabalconf+=($(use_enable test tests))
353 fi
354
355 if [[ -n "${CABAL_GHC_CONSTRAINT}" ]]; then
356 cabalconf+=($(cabal-constraint "ghc"))
290 fi 357 fi
291 358
292 local option 359 local option
293 for option in ${HCFLAGS} 360 for option in ${HCFLAGS}
294 do 361 do
295 cabalconf+=" --ghc-option=$option" 362 cabalconf+=(--ghc-option="$option")
296 done 363 done
364
365 # parallel on all available cores
366 if ghc-supports-parallel-make; then
367 local max_jobs=$(makeopts_jobs)
368
369 # limit to very small value, as parallelism
370 # helps slightly, but makes things severely worse
371 # when amount of threads is Very Large.
372 [[ ${max_jobs} -gt 4 ]] && max_jobs=4
373
374 cabalconf+=(--ghc-option=-j"$max_jobs")
375 fi
297 376
298 # Building GHCi libs on ppc64 causes "TOC overflow". 377 # Building GHCi libs on ppc64 causes "TOC overflow".
299 if use ppc64; then 378 if use ppc64; then
300 cabalconf="${cabalconf} --disable-library-for-ghci" 379 cabalconf+=(--disable-library-for-ghci)
301 fi 380 fi
302 381
303 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217) 382 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
304 # so translate LDFLAGS to ghc parameters (without filtering) 383 # so translate LDFLAGS to ghc parameters (without filtering)
305 local flag 384 local flag
385 for flag in $CFLAGS; do cabalconf+=(--ghc-option="-optc$flag"); done
306 for flag in $LDFLAGS; do cabalconf="${cabalconf} --ghc-option=-optl$flag"; done 386 for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
307 387
308 # disable executable stripping for the executables, as portage will 388 # disable executable stripping for the executables, as portage will
309 # strip by itself, and pre-stripping gives a QA warning. 389 # strip by itself, and pre-stripping gives a QA warning.
310 # cabal versions previous to 1.4 does not strip executables, and does 390 # cabal versions previous to 1.4 does not strip executables, and does
311 # not accept the flag. 391 # not accept the flag.
312 # this fixes numerous bugs, amongst them; 392 # this fixes numerous bugs, amongst them;
313 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494 393 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
314 cabalconf="${cabalconf} --disable-executable-stripping" 394 cabalconf+=(--disable-executable-stripping)
315 395
316 cabalconf="${cabalconf} --docdir=${EPREFIX}/usr/share/doc/${PF}" 396 cabalconf+=(--docdir="${EPREFIX}"/usr/share/doc/${PF})
317 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes 397 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
318 # it's better if the configure chatter is in the build logs: 398 # it's better if the configure chatter is in the build logs:
319 cabalconf="${cabalconf} --verbose" 399 cabalconf+=(--verbose)
320 400
321 # We build shared version of our Cabal where ghc ships it's shared 401 # We build shared version of our Cabal where ghc ships it's shared
322 # version of it. We will link ./setup as dynamic binary againt Cabal later. 402 # version of it. We will link ./setup as dynamic binary againt Cabal later.
323 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \ 403 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
324 $(ghc-supports-shared-libraries) && \ 404 $(ghc-supports-shared-libraries) && \
325 cabalconf="${cabalconf} --enable-shared" 405 cabalconf+=(--enable-shared)
326 406
327 if $(ghc-supports-shared-libraries); then 407 if $(ghc-supports-shared-libraries); then
328 # maybe a bit lower 408 # Experimental support for dynamically linked binaries.
329 if $(ghc-supports-dynamic-by-default); then 409 # We are enabling it since 7.10.1_rc3
410 if version_is_at_least "7.10.0.20150316" "$(ghc-version)"; then
411 # we didn't enable it before as it was not stable on all arches
330 cabalconf="${cabalconf} --enable-shared" 412 cabalconf+=(--enable-shared)
413 # Known to break on ghc-7.8/Cabal-1.18
414 # https://ghc.haskell.org/trac/ghc/ticket/9625
415 cabalconf+=(--enable-executable-dynamic)
331 fi 416 fi
417 fi
418
419 # --sysconfdir appeared in Cabal-1.18+
420 if ./setup configure --help | grep -q -- --sysconfdir; then
421 cabalconf+=(--sysconfdir="${EPREFIX}"/etc)
422 fi
423
424 # appeared in Cabal-1.18+ (see '--disable-executable-stripping')
425 if ./setup configure --help | grep -q -- --disable-library-stripping; then
426 cabalconf+=(--disable-library-stripping)
332 fi 427 fi
333 428
334 set -- configure \ 429 set -- configure \
335 --ghc --prefix="${EPREFIX}"/usr \ 430 --ghc --prefix="${EPREFIX}"/usr \
336 --with-compiler="$(ghc-getghc)" \ 431 --with-compiler="$(ghc-getghc)" \
338 --prefix="${EPREFIX}"/usr \ 433 --prefix="${EPREFIX}"/usr \
339 --libdir="${EPREFIX}"/usr/$(get_libdir) \ 434 --libdir="${EPREFIX}"/usr/$(get_libdir) \
340 --libsubdir=${P}/ghc-$(ghc-version) \ 435 --libsubdir=${P}/ghc-$(ghc-version) \
341 --datadir="${EPREFIX}"/usr/share/ \ 436 --datadir="${EPREFIX}"/usr/share/ \
342 --datasubdir=${P}/ghc-$(ghc-version) \ 437 --datasubdir=${P}/ghc-$(ghc-version) \
343 ${cabalconf} \ 438 "${cabalconf[@]}" \
344 ${CABAL_CONFIGURE_FLAGS} \ 439 ${CABAL_CONFIGURE_FLAGS} \
345 ${CABAL_EXTRA_CONFIGURE_FLAGS} \ 440 ${CABAL_EXTRA_CONFIGURE_FLAGS} \
346 "$@" 441 "$@"
347 echo ./setup "$@" 442 echo ./setup "$@"
348 ./setup "$@" || cabal-show-brokens-and-die "setup configure failed" 443 ./setup "$@" || cabal-show-brokens-and-die "setup configure failed"
349} 444}
350 445
351cabal-build() { 446cabal-build() {
352 unset LANG LC_ALL LC_MESSAGES
353 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@" 447 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@"
354 echo ./setup "$@" 448 echo ./setup "$@"
355 ./setup "$@" \ 449 ./setup "$@" \
356 || die "setup build failed" 450 || die "setup build failed"
357} 451}
374 # register that ourselves (if it exists). 468 # register that ourselves (if it exists).
375 469
376 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then 470 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
377 # Newer cabal can generate a package conf for us: 471 # Newer cabal can generate a package conf for us:
378 ./setup register --gen-pkg-config="${T}/${P}.conf" 472 ./setup register --gen-pkg-config="${T}/${P}.conf"
379 ghc-setup-pkg "${T}/${P}.conf" 473 ghc-install-pkg "${T}/${P}.conf"
380 ghc-install-pkg
381 fi 474 fi
382} 475}
383 476
384# Some cabal libs are bundled along with some versions of ghc 477# Some cabal libs are bundled along with some versions of ghc
385# eg filepath-1.0 comes with ghc-6.6.1 478# eg filepath-1.0 comes with ghc-6.6.1
387# when building with this version of ghc, the ebuild is a dummy that is it will 480# when building with this version of ghc, the ebuild is a dummy that is it will
388# install no files since the package is already included with ghc. 481# install no files since the package is already included with ghc.
389# However portage still records the dependency and we can upgrade the package 482# However portage still records the dependency and we can upgrade the package
390# to a later one that's not included with ghc. 483# to a later one that's not included with ghc.
391# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1". 484# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
485# Those versions are taken as-is from ghc `--numeric-version`.
486# Package manager versions are also supported:
487# CABAL_CORE_LIB_GHC_PV="7.10.* PM:7.8.4-r1".
392cabal-is-dummy-lib() { 488cabal-is-dummy-lib() {
489 local bin_ghc_version=$(ghc-version)
490 local pm_ghc_version=$(ghc-pm-version)
491
393 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do 492 for version in ${CABAL_CORE_LIB_GHC_PV}; do
394 [[ "$(ghc-version)" == ${version} ]] && return 0 493 [[ "${bin_ghc_version}" == ${version} ]] && return 0
494 [[ "${pm_ghc_version}" == ${version} ]] && return 0
395 done 495 done
496
396 return 1 497 return 1
397} 498}
398 499
399# exported function: check if cabal is correctly installed for 500# exported function: check if cabal is correctly installed for
400# the currently active ghc (we cannot guarantee this with portage) 501# the currently active ghc (we cannot guarantee this with portage)
448 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@" 549 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@"
449 cabal-build 550 cabal-build
450 551
451 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 552 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
452 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then 553 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
554 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
453 # hscolour and haddock 555 # hoogle, hscolour and haddock
556 cabal-hoogle-hscolour-haddock
557 else
558 # haddock and hscolour
454 cabal-hscolour-haddock 559 cabal-hscolour-haddock
560 fi
455 else 561 else
562 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
563 # hoogle and haddock
564 cabal-hoogle-haddock
565 else
456 # just haddock 566 # just haddock
457 cabal-haddock 567 cabal-haddock
568 fi
458 fi 569 fi
459 else 570 else
460 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then 571 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
572 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
573 # hoogle and hscolour
574 cabal-hoogle-hscolour
575 else
461 # just hscolour 576 # just hscolour
462 cabal-hscolour 577 cabal-hscolour
578 fi
579 else
580 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
581 # just hoogle
582 cabal-hoogle
583 fi
463 fi 584 fi
464 fi 585 fi
465} 586}
466 587
467haskell-cabal_src_compile() { 588haskell-cabal_src_compile() {
499 # create a dummy local package conf file for haskell-updater 620 # create a dummy local package conf file for haskell-updater
500 # if it does not exist (dummy libraries and binaries w/o libraries) 621 # if it does not exist (dummy libraries and binaries w/o libraries)
501 local ghc_confdir_with_prefix="$(ghc-confdir)" 622 local ghc_confdir_with_prefix="$(ghc-confdir)"
502 # remove EPREFIX 623 # remove EPREFIX
503 dodir ${ghc_confdir_with_prefix#${EPREFIX}} 624 dodir ${ghc_confdir_with_prefix#${EPREFIX}}
504 local conf_file="${D}/$(ghc-confdir)/$(ghc-localpkgconf)" 625 local hint_db="${D}/$(ghc-confdir)"
505 [[ -e $conf_file ]] || echo '[]' > "$conf_file" || die 626 local hint_file="${hint_db}/${PF}.conf"
506 627 mkdir -p "${hint_db}" || die
507 # make sure installed packages do not destroy ghc's 628 touch "${hint_file}" || die
508 # bundled packages
509 local initial_pkg_db=${ROOT}/$(ghc-libdir)/package.conf.d.initial
510 if [[ -e ${initial_pkg_db} ]]; then
511 local checked_pkg
512 for checked_pkg in $(ghc-listpkg "${conf_file}")
513 do
514 local initial_pkg
515 for initial_pkg in $(ghc-listpkg "${initial_pkg_db}"); do
516 if [[ ${checked_pkg} = ${initial_pkg} ]]; then
517 eerror "Package ${checked_pkg} is shipped with $(ghc-version)."
518 eerror "Ebuild author forgot CABAL_CORE_LIB_GHC_PV entry."
519 eerror "Found in ${initial_pkg_db}."
520 die
521 fi
522 done
523 done
524 fi
525} 629}
526 630
527haskell-cabal_src_install() { 631haskell-cabal_src_install() {
528 pushd "${S}" > /dev/null 632 pushd "${S}" > /dev/null
529 633
530 cabal_src_install 634 cabal_src_install
531 635
532 popd > /dev/null 636 popd > /dev/null
637}
638
639haskell-cabal_pkg_postinst() {
640 ghc-package_pkg_postinst
641}
642
643haskell-cabal_pkg_postrm() {
644 ghc-package_pkg_postrm
533} 645}
534 646
535# @FUNCTION: cabal_flag 647# @FUNCTION: cabal_flag
536# @DESCRIPTION: 648# @DESCRIPTION:
537# ebuild.sh:use_enable() taken as base 649# ebuild.sh:use_enable() taken as base
585# CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \ 697# CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \
586# 'base == 3.*' 'base >= 4.2 && < 4.7' 698# 'base == 3.*' 'base >= 4.2 && < 4.7'
587#} 699#}
588# 700#
589cabal_chdeps() { 701cabal_chdeps() {
702 local cabal_fn=${MY_PN:-${PN}}.cabal
590 local cf=${CABAL_FILE:-${S}/${PN}.cabal} 703 local cf=${CABAL_FILE:-${S}/${cabal_fn}}
591 local from_ss # ss - substring 704 local from_ss # ss - substring
592 local to_ss 705 local to_ss
593 local orig_c # c - contents 706 local orig_c # c - contents
594 local new_c 707 local new_c
595 708
625 done 738 done
626 739
627 echo "${new_c}" > "$cf" || 740 echo "${new_c}" > "$cf" ||
628 die "failed to update" 741 die "failed to update"
629} 742}
743
744# @FUNCTION: cabal-constraint
745# @DESCRIPTION:
746# Allowes to set contraint to the libraries that are
747# used by specified package
748cabal-constraint() {
749 while read p v ; do
750 echo "--constraint \"$p == $v\""
751 done < $(ghc-pkgdeps ${1})
752}
753
754# @FUNCTION: replace-hcflags
755# @USAGE: <old> <new>
756# @DESCRIPTION:
757# Replace the <old> flag with <new> in HCFLAGS. Accepts shell globs for <old>.
758# The implementation is picked from flag-o-matic.eclass:replace-flags()
759replace-hcflags() {
760 [[ $# != 2 ]] && die "Usage: replace-hcflags <old flag> <new flag>"
761
762 local f new=()
763 for f in ${HCFLAGS} ; do
764 # Note this should work with globs like -O*
765 if [[ ${f} == ${1} ]]; then
766 einfo "HCFLAGS: replacing '${f}' to '${2}'"
767 f=${2}
768 fi
769 new+=( "${f}" )
770 done
771 export HCFLAGS="${new[*]}"
772
773 return 0
774}

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.53

  ViewVC Help
Powered by ViewVC 1.1.20