/[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.46 Revision 1.49
1# Copyright 1999-2014 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.46 2014/06/27 07:26:18 slyfox Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.49 2015/03/15 17:03:27 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 multiprocessing 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"
65 69
66# 'dev-haskell/cabal' passes those options with ./configure-based 70# 'dev-haskell/cabal' passes those options with ./configure-based
67# configuration, but most packages don't need/don't accept it: 71# configuration, but most packages don't need/don't accept it:
68# #515362, #515362 72# #515362, #515362
69QA_CONFIGURE_OPTIONS+=" --with-compiler --with-hc --with-hc-pkg --with-gcc" 73QA_CONFIGURE_OPTIONS+=" --with-compiler --with-hc --with-hc-pkg --with-gcc"
87 profile) CABAL_USE_PROFILE=yes;; 91 profile) CABAL_USE_PROFILE=yes;;
88 bootstrap) CABAL_BOOTSTRAP=yes;; 92 bootstrap) CABAL_BOOTSTRAP=yes;;
89 bin) CABAL_HAS_BINARIES=yes;; 93 bin) CABAL_HAS_BINARIES=yes;;
90 lib) CABAL_HAS_LIBRARIES=yes;; 94 lib) CABAL_HAS_LIBRARIES=yes;;
91 nocabaldep) CABAL_FROM_GHC=yes;; 95 nocabaldep) CABAL_FROM_GHC=yes;;
96 ghcdeps) CABAL_GHC_CONSTRAINT=yes;;
92 test-suite) CABAL_TEST_SUITE=yes;; 97 test-suite) CABAL_TEST_SUITE=yes;;
93 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";; 98 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
94 esac 99 esac
95done 100done
96 101
104if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then 109if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then
105 IUSE="${IUSE} hscolour" 110 IUSE="${IUSE} hscolour"
106 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )" 111 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )"
107fi 112fi
108 113
114if [[ -n "${CABAL_USE_HOOGLE}" ]]; then
115 # enabled only in ::haskell
116 CABAL_USE_HOOGLE=
117fi
118
109if [[ -n "${CABAL_USE_ALEX}" ]]; then 119if [[ -n "${CABAL_USE_ALEX}" ]]; then
110 DEPEND="${DEPEND} dev-haskell/alex" 120 DEPEND="${DEPEND} dev-haskell/alex"
111fi 121fi
112 122
113if [[ -n "${CABAL_USE_HAPPY}" ]]; then 123if [[ -n "${CABAL_USE_HAPPY}" ]]; then
137fi 147fi
138if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then 148if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
139 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" 149 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
140fi 150fi
141 151
142# 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.
143_CABAL_VERSION_CACHE="" 154: ${_CABAL_VERSION_CACHE:=""}
144cabal-version() { 155cabal-version() {
145 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then 156 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
146 if [[ "${CABAL_BOOTSTRAP}" ]]; then 157 if [[ "${CABAL_BOOTSTRAP}" ]]; then
147 # We're bootstrapping cabal, so the cabal version is the version 158 # We're bootstrapping cabal, so the cabal version is the version
148 # of this package itself. 159 # of this package itself.
149 _CABAL_VERSION_CACHE="${PV}" 160 _CABAL_VERSION_CACHE="${PV}"
150 elif [[ "${CABAL_FROM_GHC}" ]]; then 161 elif [[ "${CABAL_FROM_GHC}" ]]; then
151 local cabal_package=$(echo "$(ghc-libdir)"/Cabal-*) 162 _CABAL_VERSION_CACHE="$(ghc-cabal-version)"
152 # /path/to/ghc/Cabal-${VER} -> ${VER}
153 _CABAL_VERSION_CACHE="${cabal_package/*Cabal-/}"
154 else 163 else
155 # We ask portage, not ghc, so that we only pick up 164 # We ask portage, not ghc, so that we only pick up
156 # portage-installed cabal versions. 165 # portage-installed cabal versions.
157 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" 166 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
158 fi 167 fi
235 set -- haddock "$@" 244 set -- haddock "$@"
236 echo ./setup "$@" 245 echo ./setup "$@"
237 ./setup "$@" || die "setup haddock failed" 246 ./setup "$@" || die "setup haddock failed"
238} 247}
239 248
249cabal-hoogle() {
250 ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
251}
252
240cabal-hscolour-haddock() { 253cabal-hscolour-haddock() {
241 # --hyperlink-source implies calling 'setup hscolour' 254 # --hyperlink-source implies calling 'setup hscolour'
242 set -- haddock --hyperlink-source 255 set -- haddock --hyperlink-source
243 echo ./setup "$@" 256 echo ./setup "$@"
244 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed" 257 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed"
258}
259
260cabal-hoogle-haddock() {
261 set -- haddock --hoogle
262 echo ./setup "$@"
263 ./setup "$@" || die "setup haddock --hoogle failed"
264}
265
266cabal-hoogle-hscolour-haddock() {
267 cabal-hscolour-haddock
268 cabal-hoogle-haddock
269}
270
271cabal-hoogle-hscolour() {
272 ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
273 cabal-hscolour
245} 274}
246 275
247cabal-die-if-nonempty() { 276cabal-die-if-nonempty() {
248 local breakage_type=$1 277 local breakage_type=$1
249 shift 278 shift
303 fi 332 fi
304 if [[ -n "${CABAL_TEST_SUITE}" ]]; then 333 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
305 cabalconf+=($(use_enable test tests)) 334 cabalconf+=($(use_enable test tests))
306 fi 335 fi
307 336
337 if [[ -n "${CABAL_GHC_CONSTRAINT}" ]]; then
338 cabalconf+=($(cabal-constraint "ghc"))
339 fi
340
308 local option 341 local option
309 for option in ${HCFLAGS} 342 for option in ${HCFLAGS}
310 do 343 do
311 cabalconf+=(--ghc-option="$option") 344 cabalconf+=(--ghc-option="$option")
312 done 345 done
329 fi 362 fi
330 363
331 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217) 364 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
332 # so translate LDFLAGS to ghc parameters (without filtering) 365 # so translate LDFLAGS to ghc parameters (without filtering)
333 local flag 366 local flag
367 for flag in $CFLAGS; do cabalconf+=(--ghc-option="-optc$flag"); done
334 for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done 368 for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
335 369
336 # disable executable stripping for the executables, as portage will 370 # disable executable stripping for the executables, as portage will
337 # strip by itself, and pre-stripping gives a QA warning. 371 # strip by itself, and pre-stripping gives a QA warning.
338 # cabal versions previous to 1.4 does not strip executables, and does 372 # cabal versions previous to 1.4 does not strip executables, and does
339 # not accept the flag. 373 # not accept the flag.
411 # register that ourselves (if it exists). 445 # register that ourselves (if it exists).
412 446
413 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then 447 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
414 # Newer cabal can generate a package conf for us: 448 # Newer cabal can generate a package conf for us:
415 ./setup register --gen-pkg-config="${T}/${P}.conf" 449 ./setup register --gen-pkg-config="${T}/${P}.conf"
416 ghc-setup-pkg "${T}/${P}.conf" 450 ghc-install-pkg "${T}/${P}.conf"
417 ghc-install-pkg
418 fi 451 fi
419} 452}
420 453
421# Some cabal libs are bundled along with some versions of ghc 454# Some cabal libs are bundled along with some versions of ghc
422# eg filepath-1.0 comes with ghc-6.6.1 455# eg filepath-1.0 comes with ghc-6.6.1
424# when building with this version of ghc, the ebuild is a dummy that is it will 457# when building with this version of ghc, the ebuild is a dummy that is it will
425# install no files since the package is already included with ghc. 458# install no files since the package is already included with ghc.
426# However portage still records the dependency and we can upgrade the package 459# However portage still records the dependency and we can upgrade the package
427# to a later one that's not included with ghc. 460# to a later one that's not included with ghc.
428# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1". 461# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
462# Those versions are taken as-is from ghc `--numeric-version`.
463# Package manager versions are also supported:
464# CABAL_CORE_LIB_GHC_PV="7.10.* PM:7.8.4-r1".
429cabal-is-dummy-lib() { 465cabal-is-dummy-lib() {
466 local bin_ghc_version=$(ghc-version)
467 local pm_ghc_p=$(best_version dev-lang/ghc)
468 local pm_ghc_version version
469
470 pm_ghc_version=PM:${pm_ghc_p#dev-lang/ghc-}
471
430 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do 472 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
431 [[ "$(ghc-version)" == ${version} ]] && return 0 473 [[ "${bin_ghc_version}" == ${version} ]] && return 0
474 [[ "${pm_ghc_version}" == ${version} ]] && return 0
432 done 475 done
476
433 return 1 477 return 1
434} 478}
435 479
436# exported function: check if cabal is correctly installed for 480# exported function: check if cabal is correctly installed for
437# the currently active ghc (we cannot guarantee this with portage) 481# the currently active ghc (we cannot guarantee this with portage)
485 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@" 529 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@"
486 cabal-build 530 cabal-build
487 531
488 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 532 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
489 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then 533 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
534 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
490 # hscolour and haddock 535 # hoogle, hscolour and haddock
536 cabal-hoogle-hscolour-haddock
537 else
538 # haddock and hscolour
491 cabal-hscolour-haddock 539 cabal-hscolour-haddock
540 fi
492 else 541 else
542 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
543 # hoogle and haddock
544 cabal-hoogle-haddock
545 else
493 # just haddock 546 # just haddock
494 cabal-haddock 547 cabal-haddock
548 fi
495 fi 549 fi
496 else 550 else
497 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then 551 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
552 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
553 # hoogle and hscolour
554 cabal-hoogle-hscolour
555 else
498 # just hscolour 556 # just hscolour
499 cabal-hscolour 557 cabal-hscolour
558 fi
559 else
560 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
561 # just hoogle
562 cabal-hoogle
563 fi
500 fi 564 fi
501 fi 565 fi
502} 566}
503 567
504haskell-cabal_src_compile() { 568haskell-cabal_src_compile() {
536 # create a dummy local package conf file for haskell-updater 600 # create a dummy local package conf file for haskell-updater
537 # if it does not exist (dummy libraries and binaries w/o libraries) 601 # if it does not exist (dummy libraries and binaries w/o libraries)
538 local ghc_confdir_with_prefix="$(ghc-confdir)" 602 local ghc_confdir_with_prefix="$(ghc-confdir)"
539 # remove EPREFIX 603 # remove EPREFIX
540 dodir ${ghc_confdir_with_prefix#${EPREFIX}} 604 dodir ${ghc_confdir_with_prefix#${EPREFIX}}
541 local conf_file="${D}/$(ghc-confdir)/$(ghc-localpkgconf)" 605 local hint_db="${D}/$(ghc-confdir)"
542 [[ -e $conf_file ]] || echo '[]' > "$conf_file" || die 606 local hint_file="${hint_db}/${PF}.conf"
543 607 mkdir -p "${hint_db}" || die
544 # make sure installed packages do not destroy ghc's 608 touch "${hint_file}" || die
545 # bundled packages
546 local initial_pkg_db=${ROOT}/$(ghc-libdir)/package.conf.d.initial
547 if [[ -e ${initial_pkg_db} ]]; then
548 local checked_pkg
549 for checked_pkg in $(ghc-listpkg "${conf_file}")
550 do
551 local initial_pkg
552 for initial_pkg in $(ghc-listpkg "${initial_pkg_db}"); do
553 if [[ ${checked_pkg} = ${initial_pkg} ]]; then
554 eerror "Package ${checked_pkg} is shipped with $(ghc-version)."
555 eerror "Ebuild author forgot CABAL_CORE_LIB_GHC_PV entry."
556 eerror "Found in ${initial_pkg_db}."
557 die
558 fi
559 done
560 done
561 fi
562} 609}
563 610
564haskell-cabal_src_install() { 611haskell-cabal_src_install() {
565 pushd "${S}" > /dev/null 612 pushd "${S}" > /dev/null
566 613
567 cabal_src_install 614 cabal_src_install
568 615
569 popd > /dev/null 616 popd > /dev/null
617}
618
619haskell-cabal_pkg_postinst() {
620 ghc-package_pkg_postinst
621}
622
623haskell-cabal_pkg_postrm() {
624 ghc-package_pkg_postrm
570} 625}
571 626
572# @FUNCTION: cabal_flag 627# @FUNCTION: cabal_flag
573# @DESCRIPTION: 628# @DESCRIPTION:
574# ebuild.sh:use_enable() taken as base 629# ebuild.sh:use_enable() taken as base
664 719
665 echo "${new_c}" > "$cf" || 720 echo "${new_c}" > "$cf" ||
666 die "failed to update" 721 die "failed to update"
667} 722}
668 723
724# @FUNCTION: cabal-constraint
725# @DESCRIPTION:
726# Allowes to set contraint to the libraries that are
727# used by specified package
728cabal-constraint() {
729 while read p v ; do
730 echo "--constraint \"$p == $v\""
731 done < $(ghc-pkgdeps ${1})
732}
733
669# @FUNCTION: replace-hcflags 734# @FUNCTION: replace-hcflags
670# @USAGE: <old> <new> 735# @USAGE: <old> <new>
671# @DESCRIPTION: 736# @DESCRIPTION:
672# Replace the <old> flag with <new> in HCFLAGS. Accepts shell globs for <old>. 737# Replace the <old> flag with <new> in HCFLAGS. Accepts shell globs for <old>.
673# The implementation is picked from flag-o-matic.eclass:replace-flags() 738# The implementation is picked from flag-o-matic.eclass:replace-flags()

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.49

  ViewVC Help
Powered by ViewVC 1.1.20