/[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.32 Revision 1.38
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 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.32 2012/04/19 17:33:19 slyfox Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.38 2013/01/06 13:06:35 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:
17# use of. 17# use of.
18# 18#
19# Currently supported features: 19# Currently supported features:
20# haddock -- for documentation generation 20# haddock -- for documentation generation
21# hscolour -- generation of colourised sources 21# hscolour -- generation of colourised sources
22# hoogle -- generation of documentation search index
22# alex -- lexer/scanner generator 23# alex -- lexer/scanner generator
23# happy -- parser generator 24# happy -- parser generator
24# c2hs -- C interface generator 25# c2hs -- C interface generator
25# cpphs -- C preprocessor clone written in Haskell 26# cpphs -- C preprocessor clone written in Haskell
26# profile -- if package supports to build profiling-enabled libraries 27# profile -- if package supports to build profiling-enabled libraries
52# _only_ 'setup' binary bootstrap. 53# _only_ 'setup' binary bootstrap.
53# example: /etc/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make 54# example: /etc/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make
54# linking 'setup' faster. 55# linking 'setup' faster.
55: ${GHC_BOOTSTRAP_FLAGS:=} 56: ${GHC_BOOTSTRAP_FLAGS:=}
56 57
58# @ECLASS-VARIABLE: CABAL_DEBUG_LOOSENING
59# @DESCRIPTION:
60# Show debug output for 'cabal_chdeps' function if set.
61# Needs working 'diff'.
62: ${CABAL_DEBUG_LOOSENING:=}
63
57HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" 64HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install"
58 65
59case "${EAPI:-0}" in 66case "${EAPI:-0}" in
60 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;; 67 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;;
61 *) ;; 68 *) ;;
62esac 69esac
63 70
64EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF} 71EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF}
65 72
125fi 132fi
126if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then 133if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
127 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" 134 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
128fi 135fi
129 136
130# Libraries require GHC to be installed.
131if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
132 RDEPEND="${RDEPEND} dev-lang/ghc"
133fi
134
135# returns the version of cabal currently in use 137# returns the version of cabal currently in use
136_CABAL_VERSION_CACHE="" 138_CABAL_VERSION_CACHE=""
137cabal-version() { 139cabal-version() {
138 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then 140 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
139 if [[ "${CABAL_BOOTSTRAP}" ]]; then 141 if [[ "${CABAL_BOOTSTRAP}" ]]; then
185 $(ghc-getghc) "$@" 187 $(ghc-getghc) "$@"
186 } 188 }
187 if $(ghc-supports-shared-libraries); then 189 if $(ghc-supports-shared-libraries); then
188 # # some custom build systems might use external libraries, 190 # # some custom build systems might use external libraries,
189 # # for which we don't have shared libs, so keep static fallback 191 # # for which we don't have shared libs, so keep static fallback
190 # Disabled '-dynamic' as ghc does not embed RPATH to used extra-libraries:
191 # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3 192 # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3
192 # make_setup -dynamic "$@" || 193 # http://hackage.haskell.org/trac/ghc/ticket/7062
194 # http://hackage.haskell.org/trac/ghc/ticket/3072
195 # ghc does not set RPATH for extralibs, thus we do it ourselves by hands
196 einfo "Prepending $(ghc-libdir) to LD_LIBRARY_PATH"
197 if [[ ${CHOST} != *-darwin* ]]; then
198 LD_LIBRARY_PATH="$(ghc-libdir)${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
199 export LD_LIBRARY_PATH
200 else
201 DYLD_LIBRARY_PATH="$(ghc-libdir)${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH}"
202 export DYLD_LIBRARY_PATH
203 fi
204 { make_setup -dynamic "$@" && ./setup --help >/dev/null; } ||
193 make_setup "$@" || die "compiling ${setupmodule} failed" 205 make_setup "$@" || die "compiling ${setupmodule} failed"
194 else 206 else
195 make_setup "$@" || die "compiling ${setupmodule} failed" 207 make_setup "$@" || die "compiling ${setupmodule} failed"
196 fi 208 fi
197} 209}
289 # We build shared version of our Cabal where ghc ships it's shared 301 # We build shared version of our Cabal where ghc ships it's shared
290 # version of it. We will link ./setup as dynamic binary againt Cabal later. 302 # version of it. We will link ./setup as dynamic binary againt Cabal later.
291 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \ 303 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
292 $(ghc-supports-shared-libraries) && \ 304 $(ghc-supports-shared-libraries) && \
293 cabalconf="${cabalconf} --enable-shared" 305 cabalconf="${cabalconf} --enable-shared"
306
307 if $(ghc-supports-shared-libraries); then
308 # maybe a bit lower
309 if version_is_at_least "7.7.20121114" "$(ghc-version)"; then
310 cabalconf="${cabalconf} --enable-shared"
311 fi
312 fi
294 313
295 set -- configure \ 314 set -- configure \
296 --ghc --prefix="${EPREFIX}"/usr \ 315 --ghc --prefix="${EPREFIX}"/usr \
297 --with-compiler="$(ghc-getghc)" \ 316 --with-compiler="$(ghc-getghc)" \
298 --with-hc-pkg="$(ghc-getghcpkg)" \ 317 --with-hc-pkg="$(ghc-getghcpkg)" \
350# However portage still records the dependency and we can upgrade the package 369# However portage still records the dependency and we can upgrade the package
351# to a later one that's not included with ghc. 370# to a later one that's not included with ghc.
352# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1". 371# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
353cabal-is-dummy-lib() { 372cabal-is-dummy-lib() {
354 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do 373 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
355 [[ "$(ghc-version)" == "$version" ]] && return 0 374 [[ "$(ghc-version)" == ${version} ]] && return 0
356 done 375 done
357 return 1 376 return 1
358} 377}
359 378
360# exported function: check if cabal is correctly installed for 379# exported function: check if cabal is correctly installed for
361# the currently active ghc (we cannot guarantee this with portage) 380# the currently active ghc (we cannot guarantee this with portage)
362haskell-cabal_pkg_setup() { 381haskell-cabal_pkg_setup() {
382 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
383 [[ ${RDEPEND} == *dev-lang/ghc* ]] || eqawarn "QA Notice: A library does not have runtime dependency on dev-lang/ghc."
384 fi
363 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then 385 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
364 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES." 386 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES."
365 fi 387 fi
366 if [[ -n "${CABAL_UNKNOWN}" ]]; then 388 if [[ -n "${CABAL_UNKNOWN}" ]]; then
367 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" 389 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
459 local ghc_confdir_with_prefix="$(ghc-confdir)" 481 local ghc_confdir_with_prefix="$(ghc-confdir)"
460 # remove EPREFIX 482 # remove EPREFIX
461 dodir ${ghc_confdir_with_prefix#${EPREFIX}} 483 dodir ${ghc_confdir_with_prefix#${EPREFIX}}
462 local conf_file="${D}/$(ghc-confdir)/$(ghc-localpkgconf)" 484 local conf_file="${D}/$(ghc-confdir)/$(ghc-localpkgconf)"
463 [[ -e $conf_file ]] || echo '[]' > "$conf_file" || die 485 [[ -e $conf_file ]] || echo '[]' > "$conf_file" || die
486
487 # make sure installed packages do not destroy ghc's
488 # bundled packages
489 local initial_pkg_db=${ROOT}/$(ghc-libdir)/package.conf.d.initial
490 if [[ -e ${initial_pkg_db} ]]; then
491 local checked_pkg
492 for checked_pkg in $(ghc-listpkg "${conf_file}")
493 do
494 local initial_pkg
495 for initial_pkg in $(ghc-listpkg "${initial_pkg_db}"); do
496 if [[ ${checked_pkg} = ${initial_pkg} ]]; then
497 eerror "Package ${checked_pkg} is shipped with $(ghc-version)."
498 eerror "Ebuild author forgot CABAL_CORE_LIB_GHC_PV entry."
499 eerror "Found in ${initial_pkg_db}."
500 die
501 fi
502 done
503 done
504 fi
464} 505}
465 506
466haskell-cabal_src_install() { 507haskell-cabal_src_install() {
467 pushd "${S}" > /dev/null 508 pushd "${S}" > /dev/null
468 509
469 cabal_src_install 510 cabal_src_install
470 511
471 popd > /dev/null 512 popd > /dev/null
472} 513}
473 514
515# @FUNCTION: cabal_flag
516# @DESCRIPTION:
474# ebuild.sh:use_enable() taken as base 517# ebuild.sh:use_enable() taken as base
475# 518#
476# Usage examples: 519# Usage examples:
477# 520#
478# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui) 521# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
496 echo "--flags=-${UWORD}" 539 echo "--flags=-${UWORD}"
497 fi 540 fi
498 541
499 return 0 542 return 0
500} 543}
544
545# @FUNCTION: cabal_chdeps
546# @DESCRIPTION:
547# Allows easier patching of $CABAL_FILE (${S}/${PN}.cabal by default)
548# depends
549#
550# Accepts argument list as pairs of substitutions: <from-string> <to-string>...
551#
552# Dies on error.
553#
554# Usage examples:
555#
556# src_prepare() {
557# cabal_chdeps \
558# 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7' \
559# 'containers ==0.4.*' 'containers >= 0.4 && < 0.6'
560#}
561# or
562# src_prepare() {
563# CABAL_FILE=${S}/${MY_PN}.cabal cabal_chdeps \
564# 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7'
565# CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \
566# 'base == 3.*' 'base >= 4.2 && < 4.7'
567#}
568#
569cabal_chdeps() {
570 local cf=${CABAL_FILE:-${S}/${PN}.cabal}
571 local from_ss # ss - substring
572 local to_ss
573 local orig_c # c - contents
574 local new_c
575
576 [[ -f $cf ]] || die "cabal file '$cf' does not exist"
577
578 orig_c=$(< "$cf")
579
580 while :; do
581 from_pat=$1
582 to_str=$2
583
584 [[ -n ${from_pat} ]] || break
585 [[ -n ${to_str} ]] || die "'${from_str}' does not have 'to' part"
586
587 einfo "CHDEP: '${from_pat}' -> '${to_str}'"
588
589 # escape pattern-like symbols
590 from_pat=${from_pat//\*/\\*}
591 from_pat=${from_pat//\[/\\[}
592
593 new_c=${orig_c//${from_pat}/${to_str}}
594
595 if [[ -n $CABAL_DEBUG_LOOSENING ]]; then
596 echo "${orig_c}" >"${T}/${cf}".pre
597 echo "${new_c}" >"${T}/${cf}".post
598 diff -u "${T}/${cf}".{pre,post}
599 fi
600
601 [[ "${orig_c}" == "${new_c}" ]] && die "no trigger for '${from_pat}'"
602 orig_c=${new_c}
603 shift
604 shift
605 done
606
607 echo "${new_c}" > "$cf" ||
608 die "failed to update"
609}

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.38

  ViewVC Help
Powered by ViewVC 1.1.20